4e65be0e4b486893aab043de094d8aa7eabecc6e
[dpdk.git] / devtools / check-git-log.sh
1 #! /bin/sh
2 # SPDX-License-Identifier: BSD-3-Clause
3 # Copyright 2016 6WIND S.A.
4
5 # Check commit logs (headlines and references)
6 #
7 # If any doubt about the formatting, please check in the most recent history:
8 #       git log --format='%>|(15)%cr   %s' --reverse | grep -i <pattern>
9
10 if [ "$1" = '-h' -o "$1" = '--help' ] ; then
11         cat <<- END_OF_HELP
12         usage: $(basename $0) [-h] [range]
13
14         Check commit log formatting.
15         The git range can be specified as a "git log" option,
16         e.g. -1 to check only the latest commit.
17         The default range starts from origin/master to HEAD.
18         END_OF_HELP
19         exit
20 fi
21
22 selfdir=$(dirname $(readlink -f $0))
23 range=${1:-origin/master..}
24 # convert -N to HEAD~N.. in order to comply with git-log-fixes.sh getopts
25 if printf -- $range | grep -q '^-[0-9]\+' ; then
26         range="HEAD$(printf -- $range | sed 's,^-,~,').."
27 fi
28
29 commits=$(git log --format='%h' --reverse $range)
30 headlines=$(git log --format='%s' --reverse $range)
31 bodylines=$(git log --format='%b' --reverse $range)
32 fixes=$(git log --format='%h %s' --reverse $range | grep -i ': *fix' | cut -d' ' -f1)
33 stablefixes=$($selfdir/git-log-fixes.sh $range | sed '/(N\/A)$/d'  | cut -d' ' -f2)
34 tags=$(git log --format='%b' --reverse $range | grep -i -e 'by *:' -e 'fix.*:')
35 bytag='\(Reported\|Suggested\|Signed-off\|Acked\|Reviewed\|Tested\)-by:'
36
37 # check headline format (spacing, no punctuation, no code)
38 bad=$(echo "$headlines" | grep --color=always \
39         -e '    ' \
40         -e '^ ' \
41         -e ' $' \
42         -e '\.$' \
43         -e '[,;!?&|]' \
44         -e ':.*_' \
45         -e '^[^:]\+$' \
46         -e ':[^ ]' \
47         -e ' :' \
48         | sed 's,^,\t,')
49 [ -z "$bad" ] || printf "Wrong headline format:\n$bad\n"
50
51 # check headline prefix when touching only drivers, e.g. net/<driver name>
52 bad=$(for commit in $commits ; do
53         headline=$(git log --format='%s' -1 $commit)
54         files=$(git diff-tree --no-commit-id --name-only -r $commit)
55         [ -z "$(echo "$files" | grep -v '^\(drivers\|doc\|config\)/')" ] ||
56                 continue
57         drv=$(echo "$files" | grep '^drivers/' | cut -d "/" -f 2,3 | sort -u)
58         drvgrp=$(echo "$drv" | cut -d "/" -f 1 | uniq)
59         if [ $(echo "$drvgrp" | wc -l) -gt 1 ] ; then
60                 echo "$headline" | grep -v '^drivers:'
61         elif [ $(echo "$drv" | wc -l) -gt 1 ] ; then
62                 echo "$headline" | grep -v "^drivers/$drvgrp"
63         else
64                 echo "$headline" | grep -v "^$drv"
65         fi
66 done | sed 's,^,\t,')
67 [ -z "$bad" ] || printf "Wrong headline prefix:\n$bad\n"
68
69 # check headline label for common typos
70 bad=$(echo "$headlines" | grep --color=always \
71         -e '^example[:/]' \
72         -e '^apps/' \
73         -e '^testpmd' \
74         -e 'test-pmd' \
75         -e '^bond:' \
76         | sed 's,^,\t,')
77 [ -z "$bad" ] || printf "Wrong headline label:\n$bad\n"
78
79 # check headline lowercase for first words
80 bad=$(echo "$headlines" | grep --color=always \
81         -e '^.*[[:upper:]].*:' \
82         -e ': *[[:upper:]]' \
83         | sed 's,^,\t,')
84 [ -z "$bad" ] || printf "Wrong headline uppercase:\n$bad\n"
85
86 # check headline case (Rx/Tx, VF, L2, MAC, Linux ...)
87 IFS='
88 '
89 words="$selfdir/words-case.txt"
90 for word in $(cat $words); do
91         bad=$(echo "$headlines" | grep -iw $word | grep -v $word)
92         if [ "$word" = "Tx" ]; then
93                 bad=$(echo $bad | grep -v 'OCTEON\ TX')
94         fi
95         for bad_line in $bad; do
96                 bad_word=$(echo $bad_line | cut -d":" -f2 | grep -io $word)
97                 if [ -n "$bad_word" ]; then
98                         printf "Wrong headline case:\n\"$bad_line\": $bad_word --> $word\n"
99                 fi
100         done
101 done
102
103 # check headline length (60 max)
104 bad=$(echo "$headlines" |
105         awk 'length>60 {print}' |
106         sed 's,^,\t,')
107 [ -z "$bad" ] || printf "Headline too long:\n$bad\n"
108
109 # check body lines length (75 max)
110 bad=$(echo "$bodylines" | grep -v '^Fixes:' |
111         awk 'length>75 {print}' |
112         sed 's,^,\t,')
113 [ -z "$bad" ] || printf "Line too long:\n$bad\n"
114
115 # check starting commit message with "It"
116 bad=$(for commit in $commits ; do
117         firstbodyline=$(git log --format='%b' -1 $commit | head -n1)
118         echo "$firstbodyline" | grep --color=always -ie '^It '
119 done | sed 's,^,\t,')
120 [ -z "$bad" ] || printf "Wrong beginning of commit message:\n$bad\n"
121
122 # check tags spelling
123 bad=$(echo "$tags" |
124         grep -v "^$bytag [^,]* <.*@.*>$" |
125         grep -v '^Fixes: [0-9a-f]\{7\}[0-9a-f]* (".*")$' |
126         sed 's,^.,\t&,')
127 [ -z "$bad" ] || printf "Wrong tag:\n$bad\n"
128
129 # check missing Coverity issue: tag
130 bad=$(for commit in $commits; do
131         body=$(git log --format='%b' -1 $commit)
132         echo "$body" | grep -qi coverity || continue
133         echo "$body" | grep -q '^Coverity issue:' && continue
134         git log --format='\t%s' -1 $commit
135 done)
136 [ -z "$bad" ] || printf "Missing 'Coverity issue:' tag:\n$bad\n"
137
138 # check missing Bugzilla ID: tag
139 bad=$(for commit in $commits; do
140         body=$(git log --format='%b' -1 $commit)
141         echo "$body" | grep -qi bugzilla || continue
142         echo "$body" | grep -q '^Bugzilla ID:' && continue
143         git log --format='\t%s' -1 $commit
144 done)
145 [ -z "$bad" ] || printf "Missing 'Bugzilla ID:' tag:\n$bad\n"
146
147 # check missing Fixes: tag
148 bad=$(for fix in $fixes ; do
149         git log --format='%b' -1 $fix | grep -q '^Fixes: ' ||
150                 git log --format='\t%s' -1 $fix
151 done)
152 [ -z "$bad" ] || printf "Missing 'Fixes' tag:\n$bad\n"
153
154 # check Fixes: reference
155 fixtags=$(echo "$tags" | grep '^Fixes: ')
156 bad=$(for fixtag in $fixtags ; do
157         hash=$(echo "$fixtag" | sed 's,^Fixes: \([0-9a-f]*\).*,\1,')
158         if git branch --contains $hash 2>&- | grep -q '^\*' ; then
159                 good="Fixes: $hash "$(git log --format='("%s")' -1 $hash 2>&-)
160         else
161                 good="reference not in current branch"
162         fi
163         printf "$fixtag" | grep -v "^$good$"
164 done | sed 's,^,\t,')
165 [ -z "$bad" ] || printf "Wrong 'Fixes' reference:\n$bad\n"
166
167 # check Cc: stable@dpdk.org for fixes
168 bad=$(for fix in $stablefixes ; do
169         git log --format='%b' -1 $fix | grep -qi '^Cc: *stable@dpdk.org' ||
170                 git log --format='\t%s' -1 $fix
171 done)
172 [ -z "$bad" ] || printf "Is it candidate for Cc: stable@dpdk.org backport?\n$bad\n"