Skip to content

Commit

Permalink
Fix commitcheck on FreeBSD
Browse files Browse the repository at this point in the history
Convert from bash to sh, avoid Perl regexes and \s, prune unused
functions.

Reviewed-by: Mateusz Piotrowski <[email protected]>
Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: Ryan Moeller <[email protected]>
Closes openzfs#11070
  • Loading branch information
Ryan Moeller authored and jsai20 committed Mar 30, 2021
1 parent cceeb00 commit 03726bc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 45 deletions.
2 changes: 1 addition & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ checkbashisms:
-o -name 'make_gitrev.sh' -prune \
-o -type f ! -name 'config*' \
! -name 'libtool' \
-exec bash -c 'awk "NR==1 && /\#\!.*bin\/sh.*/ {print FILENAME;}" "{}"' \;); \
-exec sh -c 'awk "NR==1 && /\#\!.*bin\/sh.*/ {print FILENAME;}" "{}"' \;); \
else \
echo "skipping checkbashisms because checkbashisms is not installed"; \
fi
Expand Down
54 changes: 10 additions & 44 deletions scripts/commitcheck.sh
Original file line number Diff line number Diff line change
@@ -1,23 +1,10 @@
#!/usr/bin/env bash
#!/bin/sh

REF="HEAD"

# test a url
function test_url()
{
url="$1"
if ! curl --output /dev/null --max-time 60 \
--silent --head --fail "$url" ; then
echo "\"$url\" is unreachable"
return 1
fi

return 0
}

# test commit body for length
# lines containing urls are exempt for the length limit.
function test_commit_bodylength()
test_commit_bodylength()
{
length="72"
body=$(git log -n 1 --pretty=%b "$REF" | grep -Ev "http(s)*://" | grep -E -m 1 ".{$((length + 1))}")
Expand All @@ -30,9 +17,9 @@ function test_commit_bodylength()
}

# check for a tagged line
function check_tagged_line()
check_tagged_line()
{
regex='^\s*'"$1"':\s[[:print:]]+\s<[[:graph:]]+>$'
regex='^[[:space:]]*'"$1"':[[:space:]][[:print:]]+[[:space:]]<[[:graph:]]+>$'
foundline=$(git log -n 1 "$REF" | grep -E -m 1 "$regex")
if [ -z "$foundline" ]; then
echo "error: missing \"$1\""
Expand All @@ -42,30 +29,8 @@ function check_tagged_line()
return 0
}

# check for a tagged line and check that the link is valid
function check_tagged_line_with_url()
{
regex='^\s*'"$1"':\s\K([[:graph:]]+)$'
foundline=$(git log -n 1 "$REF" | grep -Po "$regex")
if [ -z "$foundline" ]; then
echo "error: missing \"$1\""
return 1
fi

OLDIFS=$IFS
IFS=$'\n'
for url in $(echo -e "$foundline"); do
if ! test_url "$url"; then
return 1
fi
done
IFS=$OLDIFS

return 0
}

# check commit message for a normal commit
function new_change_commit()
new_change_commit()
{
error=0

Expand All @@ -89,7 +54,7 @@ function new_change_commit()
return $error
}

function is_coverity_fix()
is_coverity_fix()
{
# subject starts with Fix coverity defects means it's a coverity fix
subject=$(git log -n 1 --pretty=%s "$REF" | grep -E -m 1 '^Fix coverity defects')
Expand All @@ -100,7 +65,7 @@ function is_coverity_fix()
return 1
}

function coverity_fix_commit()
coverity_fix_commit()
{
error=0

Expand All @@ -119,11 +84,12 @@ function coverity_fix_commit()

# test each summary line for the proper format
OLDIFS=$IFS
IFS=$'\n'
IFS='
'
for line in $(git log -n 1 --pretty=%b "$REF" | grep -E '^CID'); do
echo "$line" | grep -E '^CID [[:digit:]]+: ([[:graph:]]+|[[:space:]])+ \(([[:upper:]]|\_)+\)' > /dev/null
# shellcheck disable=SC2181
if [[ $? -ne 0 ]]; then
if [ $? -ne 0 ]; then
echo "error: commit message has an improperly formatted CID defect line"
error=1
fi
Expand Down

0 comments on commit 03726bc

Please sign in to comment.