2 # SPDX-License-Identifier: BSD-3-Clause
3 # Copyright 2016 6WIND S.A.
5 # Check commit logs (headlines and references)
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>
12 usage: $(basename $0) [-h] [-nX|-r range]
14 Check commit log formatting.
15 The git commits to be checked can be specified as a "git log" option,
16 by latest git commits limited with -n option, or commits in the git
17 range specified with -r option.
18 e.g. To check only the last commit, ‘-n1’ or ‘-r@~..’ is used.
19 If no range provided, default is origin/main..HEAD.
23 selfdir=$(dirname $(readlink -f $0))
24 # The script caters for two formats, the new preferred format, and the old
25 # format to ensure backward compatibility.
26 # The new format is aligned with the format of the checkpatches script,
27 # and allows for specifying the patches to check by passing -nX or -r range.
28 # The old format allows for specifying patches by passing -X or range
29 # as the first argument.
30 range=${1:-origin/main..}
32 if [ "$range" = '--help' ] ; then
35 # convert -N to HEAD~N.. in order to comply with git-log-fixes.sh getopts
36 elif printf -- "$range" | grep -q '^-[0-9]\+' ; then
37 range="HEAD$(printf -- "$range" | sed 's,^-,~,').."
39 while getopts hr:n: ARG ; do
41 n ) range="HEAD~$OPTARG.." ;;
43 h ) print_usage ; exit 0 ;;
44 ? ) print_usage ; exit 1 ;;
47 shift $(($OPTIND - 1))
50 commits=$(git log --format='%h' --reverse $range)
51 headlines=$(git log --format='%s' --reverse $range)
52 bodylines=$(git log --format='%b' --reverse $range)
53 fixes=$(git log --format='%h %s' --reverse $range | grep -i ': *fix' | cut -d' ' -f1)
54 stablefixes=$($selfdir/git-log-fixes.sh $range | sed '/(N\/A)$/d' | cut -d' ' -f2)
55 tags=$(git log --format='%b' --reverse $range | grep -i -e 'by *:' -e 'fix.*:')
56 bytag='\(Reported\|Suggested\|Signed-off\|Acked\|Reviewed\|Tested\)-by:'
60 # check headline format (spacing, no punctuation, no code)
61 bad=$(echo "$headlines" | grep --color=always \
72 [ -z "$bad" ] || { printf "Wrong headline format:\n$bad\n" && failure=true;}
74 # check headline prefix when touching only drivers, e.g. net/<driver name>
75 bad=$(for commit in $commits ; do
76 headline=$(git log --format='%s' -1 $commit)
77 files=$(git diff-tree --no-commit-id --name-only -r $commit)
78 [ -z "$(echo "$files" | grep -v '^\(drivers\|doc\|config\)/')" ] ||
80 drv=$(echo "$files" | grep '^drivers/' | cut -d "/" -f 2,3 | sort -u)
81 drvgrp=$(echo "$drv" | cut -d "/" -f 1 | uniq)
82 if [ $(echo "$drvgrp" | wc -l) -gt 1 ] ; then
83 echo "$headline" | grep -v '^drivers:'
84 elif [ $(echo "$drv" | wc -l) -gt 1 ] ; then
85 echo "$headline" | grep -v "^drivers/$drvgrp"
87 echo "$headline" | grep -v "^$drv"
90 [ -z "$bad" ] || { printf "Wrong headline prefix:\n$bad\n" && failure=true;}
92 # check headline label for common typos
93 bad=$(echo "$headlines" | grep --color=always \
100 [ -z "$bad" ] || { printf "Wrong headline label:\n$bad\n" && failure=true;}
102 # check headline lowercase for first words
103 bad=$(echo "$headlines" | grep --color=always \
104 -e '^.*[[:upper:]].*:' \
105 -e ': *[[:upper:]]' \
107 [ -z "$bad" ] || { printf "Wrong headline uppercase:\n$bad\n" && failure=true;}
109 # check headline case (Rx/Tx, VF, L2, MAC, Linux ...)
112 words="$selfdir/words-case.txt"
113 for word in $(cat $words); do
114 bad=$(echo "$headlines" | grep -iw $word | grep -vw $word)
115 if [ "$word" = "Tx" ]; then
116 bad=$(echo $bad | grep -v 'OCTEON\ TX')
118 for bad_line in $bad; do
119 bad_word=$(echo $bad_line | cut -d":" -f2 | grep -iwo $word)
120 [ -z "$bad_word" ] || { printf "Wrong headline case:\n\
121 \"$bad_line\": $bad_word --> $word\n" && failure=true;}
125 # check headline length (60 max)
126 bad=$(echo "$headlines" |
127 awk 'length>60 {print}' |
129 [ -z "$bad" ] || { printf "Headline too long:\n$bad\n" && failure=true;}
131 # check body lines length (75 max)
132 bad=$(echo "$bodylines" | grep -v '^Fixes:' |
133 awk 'length>75 {print}' |
135 [ -z "$bad" ] || { printf "Line too long:\n$bad\n" && failure=true;}
137 # check starting commit message with "It"
138 bad=$(for commit in $commits ; do
139 firstbodyline=$(git log --format='%b' -1 $commit | head -n1)
140 echo "$firstbodyline" | grep --color=always -ie '^It '
141 done | sed 's,^,\t,')
142 [ -z "$bad" ] || { printf "Wrong beginning of commit message:\n$bad\n"\
145 # check tags spelling
147 grep -v "^$bytag [^,]* <.*@.*>$" |
148 grep -v '^Fixes: [0-9a-f]\{7\}[0-9a-f]* (".*")$' |
150 [ -z "$bad" ] || { printf "Wrong tag:\n$bad\n" && failure=true;}
152 # check missing Coverity issue: tag
153 bad=$(for commit in $commits; do
154 body=$(git log --format='%b' -1 $commit)
155 echo "$body" | grep -qi coverity || continue
156 echo "$body" | grep -q '^Coverity issue:' && continue
157 git log --format='\t%s' -1 $commit
159 [ -z "$bad" ] || { printf "Missing 'Coverity issue:' tag:\n$bad\n"\
162 # check missing Bugzilla ID: tag
163 bad=$(for commit in $commits; do
164 body=$(git log --format='%b' -1 $commit)
165 echo "$body" | grep -qi bugzilla || continue
166 echo "$body" | grep -q '^Bugzilla ID:' && continue
167 git log --format='\t%s' -1 $commit
169 [ -z "$bad" ] || { printf "Missing 'Bugzilla ID:' tag:\n$bad\n"\
172 # check missing Fixes: tag
173 bad=$(for fix in $fixes ; do
174 git log --format='%b' -1 $fix | grep -q '^Fixes: ' ||
175 git log --format='\t%s' -1 $fix
177 [ -z "$bad" ] || { printf "Missing 'Fixes' tag:\n$bad\n" && failure=true;}
179 # check Fixes: reference
180 fixtags=$(echo "$tags" | grep '^Fixes: ')
181 bad=$(for fixtag in $fixtags ; do
182 hash=$(echo "$fixtag" | sed 's,^Fixes: \([0-9a-f]*\).*,\1,')
183 if git branch --contains $hash 2>&- | grep -q '^\*' ; then
184 good="Fixes: $hash "$(git log --format='("%s")' -1 $hash 2>&-)
186 good="reference not in current branch"
188 printf "$fixtag" | grep -v "^$good$"
189 done | sed 's,^,\t,')
190 [ -z "$bad" ] || { printf "Wrong 'Fixes' reference:\n$bad\n" && failure=true;}
192 # check Cc: stable@dpdk.org for fixes
193 bad=$(for fix in $stablefixes ; do
194 git log --format='%b' -1 $fix | grep -qi '^Cc: *stable@dpdk.org' ||
195 git log --format='\t%s' -1 $fix
197 [ -z "$bad" ] || { printf "Is it candidate for Cc: stable@dpdk.org backport?\n$bad\n"\
200 total=$(echo "$commits" | wc -l)
202 printf "\nInvalid patch(es) found - checked $total patch"
204 printf "\n$total/$total valid patch"
206 [ $total -le 1 ] || printf 'es'
208 $failure && exit 1 || exit 0