Debian Codegraph @

contrib/check-patches

raw
1 #!/bin/sh
2
3 set -e
4
5 revision_range="${1?revision range}"
6
7 valid=0
8 revisions=$(git rev-list --reverse "$revision_range")
9 total=$(echo $revisions | wc -w)
10 if [ "$total" -eq 0 ]; then
11 exit 0
12 fi
13
14 allowed_trailers="
15 Fixes
16 Implements
17 References
18 Link
19 Changelog-added
20 Changelog-fixed
21 Changelog-changed
22 Changelog-deprecated
23 Cc
24 Suggested-by
25 Requested-by
26 Reported-by
27 Co-authored-by
28 Signed-off-by
29 Tested-by
30 Reviewed-by
31 Acked-by
32 "
33
34
35 n=0
36 title=
37 fail=false
38
39 err() {
40 echo "error [PATCH $n/$total] '$title' $*" >&2
41 fail=true
42 }
43
44 for rev in $revisions; do
45 n=$((n + 1))
46 title=$(git log --format='%s' -1 "$rev")
47 fail=false
48
49 if [ "$(echo "$title" | wc -m)" -gt 72 ]; then
50 err "title is longer than 72 characters, please make it shorter"
51 fi
52
53 if ! echo "$title" | grep -qE '^[a-z0-9,{}/_-]+: '; then
54 err "title lacks a topic prefix (e.g. 'imap:')"
55 fi
56
57 author=$(git log --format='%an <%ae>' -1 "$rev")
58 if ! git log --format="%(trailers:key=Signed-off-by,only,valueonly,unfold)" -1 "$rev" |
59 grep -qFx "$author"; then
60 err "'Signed-off-by: $author' trailer is missing"
61 fi
62
63 for trailer in $(git log --format="%(trailers:only,keyonly)" -1 "$rev"); do
64 if ! echo "$allowed_trailers" | grep -qFx "$trailer"; then
65 err "trailer '$trailer' is misspelled or not in the sanctioned list"
66 fi
67 done
68
69 if git log --format="%(trailers:only,unfold)" -1 "$rev" | \
70 grep -vE '^Changelog-[a-z]+: [A-Z`\*_].+\.$' | \
71 grep -qE '^Changelog-[a-z]+: '; then
72 err "Changelog-* trailers should start with a capital letter and end with a period"
73 fi
74
75 body=$(git log --format='%b' -1 "$rev")
76 body=${body%$(git log --format='%(trailers)' -1 "$rev")}
77 if [ "$(echo "$body" | wc -w)" -lt 3 ]; then
78 err "body has less than three words, please describe your changes"
79 fi
80
81 if ! git log --format='%s%n%b' -1 "$rev" | codespell -; then
82 err "typos in title and/or body"
83 fi
84
85 if [ "$fail" = true ]; then
86 continue
87 fi
88 echo "ok [PATCH $n/$total] '$title'"
89 valid=$((valid + 1))
90 done
91
92 echo "$valid/$total valid patches"
93 if [ "$valid" -ne "$total" ]; then
94 exit 1
95 fi