From 12a93f67983889f47b62121502fbc173b7c1c95e Mon Sep 17 00:00:00 2001 From: Stephen Rothwell Date: Thu, 8 Oct 2020 11:52:31 +1100 Subject: [PATCH] check_fixes: use extglob to avoind some regexp work also simplify some message creation --- check_fixes | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/check_fixes b/check_fixes index d75e1ef..84d7215 100755 --- a/check_fixes +++ b/check_fixes @@ -1,5 +1,7 @@ #!/bin/bash +shopt -s extglob + if [ "$#" -lt 1 ]; then printf 'Usage: %s \n', "$0" 1>&2 exit 1 @@ -20,32 +22,24 @@ tab=$'\t' # Strip the leading and training spaces from a string strip_spaces() { - [[ "$1" =~ ^[[:space:]]*(.*[^[:space:]])[[:space:]]*$ ]] - echo "${BASH_REMATCH[1]}" + local str="${1##*([[:space:]])}" + str="${str%%*([[:space:]])}" + echo "$str" } for c in $commits; do - commit_log=$(git log -1 --format='%h ("%s")' "$c") - commit_msg="In commit - - $commit_log - -" - - fixes_lines=$(git log -1 --format='%B' "$c" | - grep -i '^[[:space:]]*Fixes:') - - while read -r fline; do - [[ "$fline" =~ ^[[:space:]]*[Ff][Ii][Xx][Ee][Ss]:[[:space:]]*(.*)$ ]] - f="${BASH_REMATCH[1]}" - fixes_msg="Fixes tag - - $fline + printf -v commit_msg 'In commit\n\n %s\n\n' \ + "$(git log -1 --format='%h ("%s")' "$c")" -has these problem(s): + readarray -t fixes_lines < <(git log -1 --format='%B' "$c" | + grep -i '^[[:space:]]*Fixes:') + fixes_lines=( "${fixes_lines[@]##*([[:space:]])}" ) + fixes_lines=( "${fixes_lines[@]%%*([[:space:]])}" ) -" + for fline in "${fixes_lines[@]}"; do + f="${fline##[Ff][Ii][Xx][Ee][Ss]:*([[:space:]])}" + printf -v fixes_msg 'Fixes tag\n\n %s\n\nhas these problem(s):\n\n' "$fline" sha= subject= msg= @@ -141,7 +135,7 @@ has these problem(s): printf '%s%s%s\n' "$commit_msg" "$fixes_msg" "$msg" commit_msg='' fi - done <<< "$fixes_lines" + done done exit 0 -- 2.39.2