]>
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"
14 if [[ -z "$1" ||
-z "$2" ]]; then
19 # remove temp directories
20 rm -rf ${tmp1} ${tmp2}
23 if git
-C $tree status
--porcelain |
egrep --silent '^(\?\?|.[DM])'; then
24 echo "Detected dirty tree, caching state..."
26 git
-C $tree config gc.auto
0;
27 td
=$
(git
-C $tree status
-z |
grep -z "^[ARM]D" | cut
-z -d' ' -f2- |
tr '\0' '\n')
28 INDEX
=$
(git
-C $tree write-tree
)
30 WORKTREE
=$
(git
-C $tree write-tree
)
31 echo "Saved index to $INDEX"
32 echo "Saved working tree to $WORKTREE"
36 if git
-C $tree status
--porcelain |
egrep --silent '^(\?\?|.[DM])'; then
37 echo "[!] git working directory must be clean."
41 git
-C $tree reset --hard
42 git
-C $tree apply
< $patch
43 mkdir
-p ${tmp1} ${tmp2}
44 mod
=$
(git
-C $tree ls-files
-m |
grep ".*\.[ch]" |
grep -v $ignore)
45 mod
+=" $(git -C $tree ls-files --others --exclude-standard | grep '.*\.[ch]' | grep -v $ignore)"
47 if [ -z "$mod" ]; then
48 echo "There doesn't seem to be any changes."
50 echo "Copying source to temp directory..."
52 echo "$tree/$file --> ${tmp1}/$file"
53 cp $tree/$file ${tmp1}/
55 git
-C $tree reset --hard
56 git
-C $tree clean
-fd
58 if [ -f $tree/$file ]; then
59 echo "$tree/$file --> ${tmp2}/$file"
60 cp $tree/$file ${tmp2}/
63 echo "Running style checks..."
64 for file in ${tmp1}/*; do
65 echo "$checkpatch $file > $file _cp"
66 $checkpatch $file > "$file"_cp
2> /dev
/null
68 for file in ${tmp2}/*; do
69 echo "$checkpatch $file > $file _cp"
70 $checkpatch $file > "$file"_cp
2> /dev
/null
73 for file in ${tmp1}/*_cp
; do
74 if [ -a ${tmp2}/$
(basename $file) ]; then
75 result
=$
(diff $file ${tmp2}/$
(basename $file) |
awk '/< ERROR|< WARNING/,/^< $|^< #|^<[^ ]/ { print $0; ++n }; END { exit n }')
77 result
=$
(cat $file |
awk '/ERROR|WARNING/,/^$/ { print $0; ++n }; END { exit n }')
80 if [ "$ni" -ne "0" ]; then
81 echo "Report for $(basename $file _cp) | $ni issues" 1>&2
82 echo "===============================================" 1>&2
84 if echo $result |
grep -q "ERROR"; then
86 elif [ "$stat" -eq "0" ]; then
93 # restore working tree
94 if [ $dirty -eq 1 ]; then
95 git
-C $tree read-tree
$WORKTREE;
96 git
-C $tree checkout-index
-af;
97 git
-C $tree read-tree
$INDEX;
101 git
-C $tree config
--unset gc.auto
;
104 # remove temp directories
105 rm -rf ${tmp1} ${tmp2}