From: Stephen Rothwell Date: Mon, 22 Apr 2019 02:27:15 +0000 (+1000) Subject: check_commits: some tidying and reformatting X-Git-Url: https://git.ozlabs.org/?a=commitdiff_plain;h=7813058cfb00be63352f7fedd479404c073705bc;p=next-scripts check_commits: some tidying and reformatting --- diff --git a/check_commits b/check_commits index 5d7d060..d383d77 100755 --- a/check_commits +++ b/check_commits @@ -1,21 +1,24 @@ #!/bin/bash if [ "$#" -lt 1 ]; then - printf "Usage: %s \n", "$0" 1>&2 + printf 'Usage: %s \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 "$@"