]>
git.proxmox.com Git - mirror_frr.git/blob - tools/checkpatch.sh
2 # Check a patch for style errors.
3 usage
="./checkpatch.sh <patch> <tree>"
6 checkpatch
="$tree/tools/checkpatch.pl --no-tree -f"
12 if [[ -z "$1" ||
-z "$2" ]]; then
17 # remove temp directories
18 rm -rf /tmp
/f1
/tmp
/f2
21 if git
-C $tree status
--porcelain |
egrep --silent '^(\?\?|.[DM])'; then
22 echo "Detected dirty tree, caching state..."
24 git
-C $tree config gc.auto
0;
25 td
=$
(git
-C $tree status
-z |
grep -z "^[ARM]D" | cut
-z -d' ' -f2- |
tr '\0' '\n')
26 INDEX
=$
(git
-C $tree write-tree
)
28 WORKTREE
=$
(git
-C $tree write-tree
)
29 echo "Saved index to $INDEX"
30 echo "Saved working tree to $WORKTREE"
34 if git
-C $tree status
--porcelain |
egrep --silent '^(\?\?|.[DM])'; then
35 echo "[!] git working directory must be clean."
39 git
-C $tree reset --hard
40 git
-C $tree apply
< $patch
41 mkdir
-p /tmp
/f1
/tmp
/f2
42 mod
=$
(git
-C $tree ls-files
-m |
grep ".*\.[ch]" |
grep -v $ignore)
43 mod
+=" $(git -C $tree ls-files --others --exclude-standard | grep '.*\.[ch]' | grep -v $ignore)"
45 if [ -z "$mod" ]; then
46 echo "There doesn't seem to be any changes."
48 echo "Copying source to temp directory..."
50 echo "$tree/$file --> /tmp/f1/$file"
51 cp $tree/$file /tmp
/f
1/
53 git
-C $tree reset --hard
54 git
-C $tree clean
-fd
56 if [ -f $tree/$file ]; then
57 echo "$tree/$file --> /tmp/f2/$file"
58 cp $tree/$file /tmp
/f
2/
61 echo "Running style checks..."
62 for file in /tmp
/f
1/*; do
63 echo "$checkpatch $file > $file _cp"
64 $checkpatch $file > "$file"_cp
2> /dev
/null
66 for file in /tmp
/f
2/*; do
67 echo "$checkpatch $file > $file _cp"
68 $checkpatch $file > "$file"_cp
2> /dev
/null
71 for file in /tmp
/f
1/*_cp
; do
72 if [ -a /tmp
/f
2/$
(basename $file) ]; then
73 result
=$
(diff $file /tmp
/f
2/$
(basename $file) |
grep -A3 "ERROR\|WARNING" |
grep -A2 -B2 '/tmp/f1')
75 result
=$
(cat $file |
grep -A3 "ERROR\|WARNING" |
grep -A2 -B2 '/tmp/f1')
77 if [ "$?" -eq "0" ]; then
78 echo "Report for $(basename $file _cp)" 1>&2
79 echo "===============================================" 1>&2
81 if echo $result |
grep -q "ERROR"; then
83 elif [ "$stat" -eq "0" ]; then
90 # restore working tree
91 if [ $dirty -eq 1 ]; then
92 git
-C $tree read-tree
$WORKTREE;
93 git
-C $tree checkout-index
-af;
94 git
-C $tree read-tree
$INDEX;
98 git
-C $tree config
--unset gc.auto
;