xref: /dpdk/devtools/check-git-log.sh (revision c18feafa193c0d816eae3a4861b1f9016cf236d7)
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
10if [ "$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
20fi
21
22selfdir=$(dirname $(readlink -f $0))
23range=${1:-origin/master..}
24# convert -N to HEAD~N.. in order to comply with git-log-fixes.sh getopts
25if printf -- $range | grep -q '^-[0-9]\+' ; then
26	range="HEAD$(printf -- $range | sed 's,^-,~,').."
27fi
28
29commits=$(git log --format='%h' --reverse $range)
30headlines=$(git log --format='%s' --reverse $range)
31bodylines=$(git log --format='%b' --reverse $range)
32fixes=$(git log --format='%h %s' --reverse $range | grep -i ': *fix' | cut -d' ' -f1)
33stablefixes=$($selfdir/git-log-fixes.sh $range | sed '/(N\/A)$/d'  | cut -d' ' -f2)
34tags=$(git log --format='%b' --reverse $range | grep -i -e 'by *:' -e 'fix.*:')
35bytag='\(Reported\|Suggested\|Signed-off\|Acked\|Reviewed\|Tested\)-by:'
36
37# check headline format (spacing, no punctuation, no code)
38bad=$(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>
52bad=$(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
66done | sed 's,^,\t,')
67[ -z "$bad" ] || printf "Wrong headline prefix:\n$bad\n"
68
69# check headline label for common typos
70bad=$(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
80bad=$(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 uppercase (Rx/Tx, VF, L2, MAC, Linux, ARM...)
87bad=$(echo "$headlines" | grep -E --color=always \
88	-e ':.*\<(rx|tx|RX|TX)\>' \
89	-e ':.*\<[pv]f\>' \
90	-e ':.*\<[hsf]w\>' \
91	-e ':.*\<l[234]\>' \
92	-e ':.*\<api\>' \
93	-e ':.*\<arm\>' \
94	-e ':.*\<armv7\>' \
95	-e ':.*\<armv8\>' \
96	-e ':.*\<crc\>' \
97	-e ':.*\<dma\>' \
98	-e ':.*\<eeprom\>' \
99	-e ':.*\<freebsd\>' \
100	-e ':.*\<iova\>' \
101	-e ':.*\<linux\>' \
102	-e ':.*\<lro\>' \
103	-e ':.*\<lsc\>' \
104	-e ':.*\<mac\>' \
105	-e ':.*\<mss\>' \
106	-e ':.*\<mtu\>' \
107	-e ':.*\<nic\>' \
108	-e ':.*\<nvm\>' \
109	-e ':.*\<numa\>' \
110	-e ':.*\<pci\>' \
111	-e ':.*\<phy\>' \
112	-e ':.*\<pmd\>' \
113	-e ':.*\<rss\>' \
114	-e ':.*\<sctp\>' \
115	-e ':.*\<tso\>' \
116	-e ':.*\<udp\>' \
117	-e ':.*\<[Vv]lan\>' \
118	-e ':.*\<vdpa\>' \
119	-e ':.*\<vsi\>' \
120	| grep \
121	-v ':.*\<OCTEON\ TX\>' \
122	| sed 's,^,\t,')
123[ -z "$bad" ] || printf "Wrong headline lowercase:\n$bad\n"
124
125# special case check for VMDq to give good error message
126bad=$(echo "$headlines" | grep -E --color=always \
127	-e '\<(vmdq|VMDQ)\>' \
128	| sed 's,^,\t,')
129[ -z "$bad" ] || printf "Wrong headline capitalization, use 'VMDq':\n$bad\n"
130
131# check headline length (60 max)
132bad=$(echo "$headlines" |
133	awk 'length>60 {print}' |
134	sed 's,^,\t,')
135[ -z "$bad" ] || printf "Headline too long:\n$bad\n"
136
137# check body lines length (75 max)
138bad=$(echo "$bodylines" | grep -v '^Fixes:' |
139	awk 'length>75 {print}' |
140	sed 's,^,\t,')
141[ -z "$bad" ] || printf "Line too long:\n$bad\n"
142
143# check starting commit message with "It"
144bad=$(for commit in $commits ; do
145	firstbodyline=$(git log --format='%b' -1 $commit | head -n1)
146	echo "$firstbodyline" | grep --color=always -ie '^It '
147done | sed 's,^,\t,')
148[ -z "$bad" ] || printf "Wrong beginning of commit message:\n$bad\n"
149
150# check tags spelling
151bad=$(echo "$tags" |
152	grep -v "^$bytag [^,]* <.*@.*>$" |
153	grep -v '^Fixes: [0-9a-f]\{7\}[0-9a-f]* (".*")$' |
154	sed 's,^.,\t&,')
155[ -z "$bad" ] || printf "Wrong tag:\n$bad\n"
156
157# check missing Fixes: tag
158bad=$(for fix in $fixes ; do
159	git log --format='%b' -1 $fix | grep -q '^Fixes: ' ||
160		git log --format='\t%s' -1 $fix
161done)
162[ -z "$bad" ] || printf "Missing 'Fixes' tag:\n$bad\n"
163
164# check Fixes: reference
165IFS='
166'
167fixtags=$(echo "$tags" | grep '^Fixes: ')
168bad=$(for fixtag in $fixtags ; do
169	hash=$(echo "$fixtag" | sed 's,^Fixes: \([0-9a-f]*\).*,\1,')
170	if git branch --contains $hash 2>&- | grep -q '^\*' ; then
171		good="Fixes: $hash "$(git log --format='("%s")' -1 $hash 2>&-)
172	else
173		good="reference not in current branch"
174	fi
175	printf "$fixtag" | grep -v "^$good$"
176done | sed 's,^,\t,')
177[ -z "$bad" ] || printf "Wrong 'Fixes' reference:\n$bad\n"
178
179# check Cc: stable@dpdk.org for fixes
180bad=$(for fix in $stablefixes ; do
181	git log --format='%b' -1 $fix | grep -qi '^Cc: *stable@dpdk.org' ||
182		git log --format='\t%s' -1 $fix
183done)
184[ -z "$bad" ] || printf "Is it candidate for Cc: stable@dpdk.org backport?\n$bad\n"
185