ce6c15eac459c7ba646c45a5f99884b7dbba7c02
[deb_dpdk.git] / scripts / check-git-log.sh
1 #! /bin/sh
2
3 # BSD LICENSE
4 #
5 # Copyright 2016 6WIND S.A.
6 #
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
9 # are met:
10 #
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
16 #     distribution.
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.
20 #
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.
32
33 # Check commit logs (headlines and references)
34 #
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>
37
38 if [ "$1" = '-h' -o "$1" = '--help' ] ; then
39         cat <<- END_OF_HELP
40         usage: $(basename $0) [-h] [range]
41
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.
46         END_OF_HELP
47         exit
48 fi
49
50 range=${1:-origin/master..}
51
52 headlines=$(git log --format='%s' $range)
53 bodylines=$(git log --format='%b' $range)
54 tags=$(git log --format='%b' $range | grep -i -e 'by *:' -e 'fix.*:')
55 fixes=$(git log --format='%h %s' $range | grep -i ': *fix' | cut -d' ' -f1)
56
57 # check headline format (spacing, no punctuation, no code)
58 bad=$(echo "$headlines" | grep \
59         -e '    ' \
60         -e '^ ' \
61         -e ' $' \
62         -e '\.$' \
63         -e '[,;!?&|]' \
64         -e ':.*_' \
65         -e '^[^:]*$' \
66         -e ':[^ ]' \
67         -e ' :' \
68         | sed 's,^,\t,')
69 [ -z "$bad" ] || printf "Wrong headline format:\n$bad\n"
70
71 # check headline label for common typos
72 bad=$(echo "$headlines" | grep \
73         -e '^example[:/]' \
74         -e '^apps/' \
75         -e '^testpmd' \
76         -e 'test-pmd' \
77         -e '^bond:' \
78         | sed 's,^,\t,')
79 [ -z "$bad" ] || printf "Wrong headline label:\n$bad\n"
80
81 # check headline lowercase for first words
82 bad=$(echo "$headlines" | grep \
83         -e '^.*[A-Z].*:' \
84         -e ': *[A-Z]' \
85         | sed 's,^,\t,')
86 [ -z "$bad" ] || printf "Wrong headline uppercase:\n$bad\n"
87
88 # check headline uppercase (Rx/Tx, VF, L2, MAC, Linux, ARM...)
89 bad=$(echo "$headlines" | grep \
90         -e 'rx\|tx\|RX\|TX' \
91         -e '\<[pv]f\>' \
92         -e '\<l[234]\>' \
93         -e ':.*\<dma\>' \
94         -e ':.*\<pci\>' \
95         -e ':.*\<mtu\>' \
96         -e ':.*\<mac\>' \
97         -e ':.*\<vlan\>' \
98         -e ':.*\<rss\>' \
99         -e ':.*\<freebsd\>' \
100         -e ':.*\<linux\>' \
101         -e ':.*\<tilegx\>' \
102         -e ':.*\<tile-gx\>' \
103         -e ':.*\<arm\>' \
104         -e ':.*\<armv7\>' \
105         -e ':.*\<armv8\>' \
106         | sed 's,^,\t,')
107 [ -z "$bad" ] || printf "Wrong headline lowercase:\n$bad\n"
108
109 # check headline length (60 max)
110 bad=$(echo "$headlines" | awk 'length>60 {print}' | sed 's,^,\t,')
111 [ -z "$bad" ] || printf "Headline too long:\n$bad\n"
112
113 # check body lines length (75 max)
114 bad=$(echo "$bodylines" | awk 'length>75 {print}' | sed 's,^,\t,')
115 [ -z "$bad" ] || printf "Line too long:\n$bad\n"
116
117 # check tags spelling
118 bad=$(echo "$tags" |
119         grep -v '^\(Reported\|Suggested\|Signed-off\|Acked\|Reviewed\|Tested\)-by: [^,]* <.*@.*>$' |
120         grep -v '^Fixes: [0-9a-f]\{7\}[0-9a-f]* (".*")$' |
121         sed 's,^.,\t&,')
122 [ -z "$bad" ] || printf "Wrong tag:\n$bad\n"
123
124 # check missing Fixes: tag
125 bad=$(for fix in $fixes ; do
126         git log --format='%b' -1 $fix | grep -q '^Fixes: ' ||
127                 git log --format='\t%s' -1 $fix
128 done)
129 [ -z "$bad" ] || printf "Missing 'Fixes' tag:\n$bad\n"
130
131 # check Fixes: reference
132 IFS='
133 '
134 fixtags=$(echo "$tags" | grep '^Fixes: ')
135 bad=$(for fixtag in $fixtags ; do
136         hash=$(echo "$fixtag" | sed 's,^Fixes: \([0-9a-f]*\).*,\1,')
137         good="Fixes: $hash "$(git log --format='("%s")' -1 $hash 2>&-)
138         printf "$fixtag" | grep -v "^$good$"
139 done | sed 's,^,\t,')
140 [ -z "$bad" ] || printf "Wrong 'Fixes' reference:\n$bad\n"