]> git.ozlabs.org Git - next-scripts/commitdiff
check_commits: some tidying and reformatting
authorStephen Rothwell <sfr@canb.auug.org.au>
Mon, 22 Apr 2019 02:27:15 +0000 (12:27 +1000)
committerStephen Rothwell <sfr@canb.auug.org.au>
Mon, 22 Apr 2019 02:27:15 +0000 (12:27 +1000)
check_commits

index 5d7d0602ed57d1a74f6dfcfca1d7ed23f039eb6d..d383d7759e2c632f485f3a351f2efd837d3a852f 100755 (executable)
@@ -1,21 +1,24 @@
 #!/bin/bash
 
 if [ "$#" -lt 1 ]; then
-       printf "Usage: %s <commit range>\n", "$0" 1>&2
+       printf 'Usage: %s <commit range>\n' "$0" 1>&2
        exit 1
 fi
 
 commits=$(git rev-list --no-merges "$@")
 if [ -z "$commits" ]; then
-       printf "No commits\n"
+       printf 'No commits\n'
        exit 0
 fi
 
-author_missing=
-committer_missing=
+declare -a author_missing committer_missing
 
 print_commits()
 {
+       if [ "$#" -eq 1 ]; then
+               return
+       fi
+
        local t="$1"
 
        shift
@@ -23,38 +26,32 @@ print_commits()
        s=
        is='is'
        its='its'
-       [ "$#" -gt 1 ] && {
+       if [ "$#" -gt 1 ]; then
                s='s'
                is='are'
                its='their'
-       }
-       printf "Commit%s\n\n" "$s"
+       fi
+       printf 'Commit%s\n\n' "$s"
        git log --no-walk --pretty='format:  %h ("%s")' "$@"
-       printf "\n%s missing a Signed-off-by from %s %s%s.\n" "$is" "$its" "$t" "$s"
-       printf "\n"
+       printf '\n%s missing a Signed-off-by from %s %s%s.\n\n' \
+               "$is" "$its" "$t" "$s"
 }
 
 for c in $commits; do
        ae=$(git log -1 --format='<%ae>%n<%aE>%n %an %n %aN ' "$c" | sort -u)
        ce=$(git log -1 --format='<%ce>%n<%cE>%n %cn %n %cN ' "$c" | sort -u)
-       msg=$(git log -1 --format='%b' "$c")
-       sob=$(echo "$msg" | sed -En 's/^\s*Signed-off-by:?\s*/ /ip')
-
-       am=false
-       cm=false
-       grep -i -F -q "$ae" <<<"$sob" ||
-               am=true
-       grep -i -F -q "$ce" <<<"$sob" ||
-               cm=true
-       "$am" && author_missing+=" $c"
-       "$cm" && committer_missing+=" $c"
+       sob=$(git log -1 --format='%b' "$c" |
+               sed -En 's/^\s*Signed-off-by:?\s*/ /ip')
+
+       if ! grep -i -F -q "$ae" <<<"$sob"; then
+               author_missing+=("$c")
+       fi
+       if ! grep -i -F -q "$ce" <<<"$sob"; then
+               committer_missing+=("$c")
+       fi
 done
 
-if [ "$author_missing" ]; then
-       print_commits "author" $author_missing
-fi
-if [ "$committer_missing" ]; then
-       print_commits "committer" $committer_missing
-fi
+print_commits 'author' "${author_missing[@]}"
+print_commits 'committer' "${committer_missing[@]}"
 
 exec gitk "$@"