File: clang-format.sh

package info (click to toggle)
php-mongodb 1.15.0%2B1.11.1%2B1.9.2%2B1.7.5-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 63,984 kB
  • sloc: ansic: 328,429; xml: 10,797; php: 4,235; sh: 179; python: 47; pascal: 36; makefile: 3
file content (39 lines) | stat: -rwxr-xr-x 1,067 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/bin/sh

if test x"$1" = x; then 
	FILES1=`git ls-files | grep -v "src/contrib" | grep '\.[ch]$'`
	FILES2=`git ls-files --others --exclude-standard | grep -v "src/contrib" | grep '\.[ch]$'`
	FILES="$FILES1 $FILES2"
fi
if test x"$1" = xchanged; then 
	FILES1=`git diff --name-only | grep -v "src/contrib" | grep '\.[ch]$'`
	FILES2=`git diff --cached --name-only | grep -v "src/contrib" | grep '\.[ch]$'`
	FILES3=`git ls-files --others --exclude-standard | grep '\.[ch]$'`
	FILES="$FILES1 $FILES2 $FILES3"
fi

# Find clang-format, we prefer -6.0, but also allow binaries without -suffix as
# long as they're >= 6.0.0
CLANG_FORMAT=`which clang-format-6.0`

if [ -z "$CLANG_FORMAT" ]; then
	CLANG_FORMAT=`which clang-format`
fi

if [ -z "$CLANG_FORMAT" ]; then
	echo "Couldn't find clang-format"
	exit
fi

VERSION=`$CLANG_FORMAT -version | cut -d " " -f 3`
VERSION_MAJOR=`echo $VERSION | cut -d "." -f 1`

if [ $VERSION_MAJOR -lt 6 ]; then
	echo "Found clang-format $VERSION but we need >= 6.0.0"
	exit
fi

# Run formatter
for i in $FILES; do
	$CLANG_FORMAT -i $i
done