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>
10 if [ "$1" = '-h' -o "$1" = '--help' ] ; then
12 usage: $(basename $0) [-h] [range]
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.
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,^-,~,').."
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:'
37 # check headline format (spacing, no punctuation, no code)
38 bad=$(echo "$headlines" | grep --color=always \
49 [ -z "$bad" ] || printf "Wrong headline format:\n$bad\n"
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\)/')" ] ||
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"
64 echo "$headline" | grep -v "^$drv"
67 [ -z "$bad" ] || printf "Wrong headline prefix:\n$bad\n"
69 # check headline label for common typos
70 bad=$(echo "$headlines" | grep --color=always \
77 [ -z "$bad" ] || printf "Wrong headline label:\n$bad\n"
79 # check headline lowercase for first words
80 bad=$(echo "$headlines" | grep --color=always \
81 -e '^.*[[:upper:]].*:' \
84 [ -z "$bad" ] || printf "Wrong headline uppercase:\n$bad\n"
86 # check headline uppercase (Rx/Tx, VF, L2, MAC, Linux, ARM...)
87 bad=$(echo "$headlines" | grep -E --color=always \
88 -e ':.*\<(rx|tx|RX|TX)\>' \
94 -e ':.*\<(Aarch64|AArch64|AARCH64|Aarch32|AArch32|AARCH32)\>' \
95 -e ':.*\<(Armv7|ARMv7|ArmV7|armV7|ARMV7)\>' \
96 -e ':.*\<(Armv8|ARMv8|ArmV8|armV8|ARMV8)\>' \
101 -e ':.*\<freebsd\>' \
124 -e ':.*\<[Vv]lan\>' \
128 -v ':.*\<OCTEON\ TX\>' \
130 [ -z "$bad" ] || printf "Wrong headline lowercase:\n$bad\n"
132 # special case check for VMDq to give good error message
133 bad=$(echo "$headlines" | grep -E --color=always \
134 -e '\<(vmdq|VMDQ)\>' \
136 [ -z "$bad" ] || printf "Wrong headline capitalization, use 'VMDq':\n$bad\n"
138 # check headline length (60 max)
139 bad=$(echo "$headlines" |
140 awk 'length>60 {print}' |
142 [ -z "$bad" ] || printf "Headline too long:\n$bad\n"
144 # check body lines length (75 max)
145 bad=$(echo "$bodylines" | grep -v '^Fixes:' |
146 awk 'length>75 {print}' |
148 [ -z "$bad" ] || printf "Line too long:\n$bad\n"
150 # check starting commit message with "It"
151 bad=$(for commit in $commits ; do
152 firstbodyline=$(git log --format='%b' -1 $commit | head -n1)
153 echo "$firstbodyline" | grep --color=always -ie '^It '
154 done | sed 's,^,\t,')
155 [ -z "$bad" ] || printf "Wrong beginning of commit message:\n$bad\n"
157 # check tags spelling
159 grep -v "^$bytag [^,]* <.*@.*>$" |
160 grep -v '^Fixes: [0-9a-f]\{7\}[0-9a-f]* (".*")$' |
162 [ -z "$bad" ] || printf "Wrong tag:\n$bad\n"
164 # check missing Fixes: tag
165 bad=$(for fix in $fixes ; do
166 git log --format='%b' -1 $fix | grep -q '^Fixes: ' ||
167 git log --format='\t%s' -1 $fix
169 [ -z "$bad" ] || printf "Missing 'Fixes' tag:\n$bad\n"
171 # check Fixes: reference
174 fixtags=$(echo "$tags" | grep '^Fixes: ')
175 bad=$(for fixtag in $fixtags ; do
176 hash=$(echo "$fixtag" | sed 's,^Fixes: \([0-9a-f]*\).*,\1,')
177 if git branch --contains $hash 2>&- | grep -q '^\*' ; then
178 good="Fixes: $hash "$(git log --format='("%s")' -1 $hash 2>&-)
180 good="reference not in current branch"
182 printf "$fixtag" | grep -v "^$good$"
183 done | sed 's,^,\t,')
184 [ -z "$bad" ] || printf "Wrong 'Fixes' reference:\n$bad\n"
186 # check Cc: stable@dpdk.org for fixes
187 bad=$(for fix in $stablefixes ; do
188 git log --format='%b' -1 $fix | grep -qi '^Cc: *stable@dpdk.org' ||
189 git log --format='\t%s' -1 $fix
191 [ -z "$bad" ] || printf "Is it candidate for Cc: stable@dpdk.org backport?\n$bad\n"