From d78ce6f9df7416730f4592e9863cd94ed7c275d8 Mon Sep 17 00:00:00 2001 From: Stephen Rothwell Date: Mon, 28 Jan 2019 11:25:45 +1100 Subject: [PATCH] check_fixes: consolidate matching --- check_fixes | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/check_fixes b/check_fixes index 593b735..34576ce 100755 --- a/check_fixes +++ b/check_fixes @@ -12,9 +12,8 @@ fi # This should be a git tree that contains *only* Linus' tree Linus_tree="${HOME}/kernels/linus.git" -split_re1='^([[:xdigit:]]{5,})[[:space:]]+(.*)$' -split_re2='^([[:xdigit:]]{5,})[[:space:]]*(.*)$' -split_re3='^([Cc][Oo][Mm][Mm][Ii][Tt])[[:space:]]*([[:xdigit:]]{5,})[[:space:]]*(.*)$' + +split_re='^([Cc][Oo][Mm][Mm][Ii][Tt])?[[:space:]]*([[:xdigit:]]{5,})([[:space:]]*)(.*)$' nl=$'\n' # Strip the leading and training spaces from a string @@ -49,24 +48,20 @@ has these problem(s): sha= subject= msg= - if [[ "$f" =~ $split_re1 ]]; then - sha="${BASH_REMATCH[1]}" - subject="${BASH_REMATCH[2]}" - elif [[ "$f" =~ $split_re2 ]]; then - sha="${BASH_REMATCH[1]}" - subject="${BASH_REMATCH[2]}" - msg="${msg:+${msg}${nl}} - " + if [[ "$f" =~ $split_re ]]; then + first="${BASH_REMATCH[1]}" + sha="${BASH_REMATCH[2]}" + spaces="${BASH_REMATCH[3]}" + subject="${BASH_REMATCH[4]}" + if [ "$first" ]; then + msg="${msg:+${msg}${nl}} - leading word '$first' unexpected" + fi if [ -z "$subject" ]; then - msg+="missing subject" - else - msg+="missing space between the SHA1 and the subject" + msg="${msg:+${msg}${nl}} - missing subject" + elif [ -z "$spaces" ]; then + msg="${msg:+${msg}${nl}} - missing space between the SHA1 and the subject" fi - elif [[ "$f" =~ $split_re3 ]]; then - sha="${BASH_REMATCH[2]}" - subject="${BASH_REMATCH[3]}" - msg="${msg:+${msg}${nl}} - leading word '${BASH_REMATCH[1]}' unexpected" - fi - if [ -z "$sha" ]; then + else printf '%s%s - %s\n' "$commit_msg" "$fixes_msg" 'No SHA1 recognised' commit_msg='' continue -- 2.39.5