5 # Copyright 2016 6WIND S.A.
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
11 # * Redistributions of source code must retain the above copyright
12 # notice, this list of conditions and the following disclaimer.
13 # * Redistributions in binary form must reproduce the above copyright
14 # notice, this list of conditions and the following disclaimer in
15 # the documentation and/or other materials provided with the
17 # * Neither the name of 6WIND S.A. nor the names of its
18 # contributors may be used to endorse or promote products derived
19 # from this software without specific prior written permission.
21 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 # Check commit logs (headlines and references)
35 # If any doubt about the formatting, please check in the most recent history:
36 # git log --format='%>|(15)%cr %s' --reverse | grep -i <pattern>
38 if [ "$1" = '-h' -o "$1" = '--help' ] ; then
40 usage: $(basename $0) [-h] [range]
42 Check commit log formatting.
43 The git range can be specified as a "git log" option,
44 e.g. -1 to check only the latest commit.
45 The default range starts from origin/master to HEAD.
50 selfdir=$(dirname $(readlink -f $0))
51 range=${1:-origin/master..}
52 # convert -N to HEAD~N.. in order to comply with git-log-fixes.sh getopts
53 if printf -- $range | grep -q '^-[0-9]\+' ; then
54 range="HEAD$(printf -- $range | sed 's,^-,~,').."
57 commits=$(git log --format='%h' --reverse $range)
58 headlines=$(git log --format='%s' --reverse $range)
59 bodylines=$(git log --format='%b' --reverse $range)
60 fixes=$(git log --format='%h %s' --reverse $range | grep -i ': *fix' | cut -d' ' -f1)
61 stablefixes=$($selfdir/git-log-fixes.sh $range | sed '/(N\/A)$/d' | cut -d' ' -f2)
62 tags=$(git log --format='%b' --reverse $range | grep -i -e 'by *:' -e 'fix.*:')
63 bytag='\(Reported\|Suggested\|Signed-off\|Acked\|Reviewed\|Tested\)-by:'
65 # check headline format (spacing, no punctuation, no code)
66 bad=$(echo "$headlines" | grep --color=always \
77 [ -z "$bad" ] || printf "Wrong headline format:\n$bad\n"
79 # check headline prefix when touching only drivers, e.g. net/<driver name>
80 bad=$(for commit in $commits ; do
81 headline=$(git log --format='%s' -1 $commit)
82 files=$(git diff-tree --no-commit-id --name-only -r $commit)
83 [ -z "$(echo "$files" | grep -v '^\(drivers\|doc\|config\)/')" ] ||
85 drv=$(echo "$files" | grep '^drivers/' | cut -d "/" -f 2,3 | sort -u)
86 drvgrp=$(echo "$drv" | cut -d "/" -f 1 | uniq)
87 if [ $(echo "$drvgrp" | wc -l) -gt 1 ] ; then
88 echo "$headline" | grep -v '^drivers:'
89 elif [ $(echo "$drv" | wc -l) -gt 1 ] ; then
90 echo "$headline" | grep -v "^drivers/$drvgrp"
92 echo "$headline" | grep -v "^$drv"
95 [ -z "$bad" ] || printf "Wrong headline prefix:\n$bad\n"
97 # check headline label for common typos
98 bad=$(echo "$headlines" | grep --color=always \
105 [ -z "$bad" ] || printf "Wrong headline label:\n$bad\n"
107 # check headline lowercase for first words
108 bad=$(echo "$headlines" | grep --color=always \
112 [ -z "$bad" ] || printf "Wrong headline uppercase:\n$bad\n"
114 # check headline uppercase (Rx/Tx, VF, L2, MAC, Linux, ARM...)
115 bad=$(echo "$headlines" | grep -E --color=always \
116 -e ':.*\<(rx|tx|RX|TX)\>' \
126 -e ':.*\<freebsd\>' \
139 -e ':.*\<[Vv]lan\>' \
142 [ -z "$bad" ] || printf "Wrong headline lowercase:\n$bad\n"
144 # special case check for VMDq to give good error message
145 bad=$(echo "$headlines" | grep -E --color=always \
146 -e '\<(vmdq|VMDQ)\>' \
148 [ -z "$bad" ] || printf "Wrong headline capitalization, use 'VMDq':\n$bad\n"
150 # check headline length (60 max)
151 bad=$(echo "$headlines" |
152 awk 'length>60 {print}' |
154 [ -z "$bad" ] || printf "Headline too long:\n$bad\n"
156 # check body lines length (75 max)
157 bad=$(echo "$bodylines" | grep -v '^Fixes:' |
158 awk 'length>75 {print}' |
160 [ -z "$bad" ] || printf "Line too long:\n$bad\n"
162 # check starting commit message with "It"
163 bad=$(for commit in $commits ; do
164 firstbodyline=$(git log --format='%b' -1 $commit | head -n1)
165 echo "$firstbodyline" | grep --color=always -ie '^It '
166 done | sed 's,^,\t,')
167 [ -z "$bad" ] || printf "Wrong beginning of commit message:\n$bad\n"
169 # check tags spelling
171 grep -v "^$bytag [^,]* <.*@.*>$" |
172 grep -v '^Fixes: [0-9a-f]\{7\}[0-9a-f]* (".*")$' |
174 [ -z "$bad" ] || printf "Wrong tag:\n$bad\n"
176 # check missing Fixes: tag
177 bad=$(for fix in $fixes ; do
178 git log --format='%b' -1 $fix | grep -q '^Fixes: ' ||
179 git log --format='\t%s' -1 $fix
181 [ -z "$bad" ] || printf "Missing 'Fixes' tag:\n$bad\n"
183 # check Fixes: reference
186 fixtags=$(echo "$tags" | grep '^Fixes: ')
187 bad=$(for fixtag in $fixtags ; do
188 hash=$(echo "$fixtag" | sed 's,^Fixes: \([0-9a-f]*\).*,\1,')
189 if git branch --contains $hash 2>&- | grep -q '^\*' ; then
190 good="Fixes: $hash "$(git log --format='("%s")' -1 $hash 2>&-)
192 good="reference not in current branch"
194 printf "$fixtag" | grep -v "^$good$"
195 done | sed 's,^,\t,')
196 [ -z "$bad" ] || printf "Wrong 'Fixes' reference:\n$bad\n"
198 # check Cc: stable@dpdk.org for fixes
199 bad=$(for fix in $stablefixes ; do
200 git log --format='%b' -1 $fix | grep -qi '^Cc: *stable@dpdk.org' ||
201 git log --format='\t%s' -1 $fix
203 [ -z "$bad" ] || printf "Is it candidate for Cc: stable@dpdk.org backport?\n$bad\n"