Skip to content

Commit 8dcaf24

Browse files
dinatale2behlendorf
authored andcommitted
Add Coverity defect fix commit checker support
Enable commitcheck.sh to test if a commit message is in the expected format for a coverity defect fix. Reviewed-by: George Melikov <mail@gmelikov.ru> Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Signed-off-by: Giuseppe Di Natale <dinatale2@llnl.gov> Closes #6777
1 parent 64b8c58 commit 8dcaf24

File tree

1 file changed

+75
-5
lines changed

1 file changed

+75
-5
lines changed

scripts/commitcheck.sh

Lines changed: 75 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,19 @@ function test_url()
1515
return 0
1616
}
1717

18+
# test commit body for length
19+
function test_commit_bodylength()
20+
{
21+
length="72"
22+
body=$(git log -n 1 --pretty=%b "$REF" | egrep -m 1 ".{$((length + 1))}")
23+
if [ -n "$body" ]; then
24+
echo "error: commit message body contains line over ${length} characters"
25+
return 1
26+
fi
27+
28+
return 0
29+
}
30+
1831
# check for a tagged line
1932
function check_tagged_line()
2033
{
@@ -29,7 +42,7 @@ function check_tagged_line()
2942
}
3043

3144
# check for a tagged line and check that the link is valid
32-
function check_tagged_line_with_url ()
45+
function check_tagged_line_with_url()
3346
{
3447
regex='^\s*'"$1"':\s\K([[:graph:]]+)$'
3548
foundline=$(git log -n 1 "$REF" | grep -Po "$regex")
@@ -63,9 +76,7 @@ function new_change_commit()
6376
fi
6477

6578
# ensure that no lines in the body of the commit are over 72 characters
66-
body=$(git log -n 1 --pretty=%b "$REF" | egrep -m 1 '.{73}')
67-
if [ -n "$body" ]; then
68-
echo "error: commit message body contains line over 72 characters"
79+
if ! test_commit_bodylength ; then
6980
error=1
7081
fi
7182

@@ -85,10 +96,12 @@ function is_openzfs_port()
8596

8697
function openzfs_port_commit()
8798
{
99+
error=0
100+
88101
# subject starts with OpenZFS dddd
89102
subject=$(git log -n 1 --pretty=%s "$REF" | egrep -m 1 '^OpenZFS [[:digit:]]+ - ')
90103
if [ -z "$subject" ]; then
91-
echo "OpenZFS patch ports must have a summary that starts with \"OpenZFS dddd - \""
104+
echo "error: OpenZFS patch ports must have a subject line that starts with \"OpenZFS dddd - \""
92105
error=1
93106
fi
94107

@@ -125,6 +138,54 @@ function openzfs_port_commit()
125138
return $error
126139
}
127140

141+
function is_coverity_fix()
142+
{
143+
# subject starts with Fix coverity defects means it's a coverity fix
144+
subject=$(git log -n 1 --pretty=%s "$REF" | egrep -m 1 '^Fix coverity defects')
145+
if [ -n "$subject" ]; then
146+
return 0
147+
fi
148+
149+
return 1
150+
}
151+
152+
function coverity_fix_commit()
153+
{
154+
error=0
155+
156+
# subject starts with Fix coverity defects: CID dddd, dddd...
157+
subject=$(git log -n 1 --pretty=%s "$REF" |
158+
egrep -m 1 'Fix coverity defects: CID [[:digit:]]+(, [[:digit:]]+)*')
159+
if [ -z "$subject" ]; then
160+
echo "error: Coverity defect fixes must have a subject line that starts with \"Fix coverity defects: CID dddd\""
161+
error=1
162+
fi
163+
164+
# need a signed off by
165+
if ! check_tagged_line "Signed-off-by" ; then
166+
error=1
167+
fi
168+
169+
# test each summary line for the proper format
170+
OLDIFS=$IFS
171+
IFS=$'\n'
172+
for line in $(git log -n 1 --pretty=%b "$REF" | egrep '^CID'); do
173+
echo "$line" | egrep '^CID [[:digit:]]+: ([[:graph:]]+|[[:space:]])+ \(([[:upper:]]|\_)+\)' > /dev/null
174+
if [[ $? -ne 0 ]]; then
175+
echo "error: commit message has an improperly formatted CID defect line"
176+
error=1
177+
fi
178+
done
179+
IFS=$OLDIFS
180+
181+
# ensure that no lines in the body of the commit are over 72 characters
182+
if ! test_commit_bodylength; then
183+
error=1
184+
fi
185+
186+
return $error
187+
}
188+
128189
if [ -n "$1" ]; then
129190
REF="$1"
130191
fi
@@ -138,6 +199,15 @@ if is_openzfs_port; then
138199
fi
139200
fi
140201

202+
# if coverity fix, test against that
203+
if is_coverity_fix; then
204+
if ! coverity_fix_commit; then
205+
exit 1
206+
else
207+
exit 0
208+
fi
209+
fi
210+
141211
# have a normal commit
142212
if ! new_change_commit ; then
143213
exit 1

0 commit comments

Comments
 (0)