From b50f97b6010a6dae50afbddbe3bc179d31f449f2 Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Wed, 21 Feb 2018 20:39:43 -0800 Subject: [PATCH] mail.sh: include copy/rename detection warnings When performing diffs via diff-tree, mail.sh attempts to show renames and copies if there are any. For non-exact copies and renames, this detection can be expensive. Git limits its efforts in this regard when there are many possibilities to test (see the `diff.renameLimit` config item). If the number of items to check exceeds the limit, Git spouts warnings to STDERR about it including, if appropriate, a possible new setting for the `diff.renameLimit` config. Previously these warnings would just clutter up taskd.pl's STDERR output. Instead, include the warnings in the diffs that get sent out as they are relevant to readers of the diffs as to whether or not there might be undetected non-exact copies and/or renames present. But the value to increase `diff.renameLimit` to is not relevant to the diffs included in mail.sh's notifications, therefore suppress any of those that show up while including the relevant warnings. Signed-off-by: Kyle J. McKay --- taskd/mail.sh | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/taskd/mail.sh b/taskd/mail.sh index ac7def6..1bbdf5c 100755 --- a/taskd/mail.sh +++ b/taskd/mail.sh @@ -94,6 +94,23 @@ echol() } # +# Function to run git diff-tree with select warnings redirected to stdout +# +git_diff_tree() +{ + [ -n "$differrtmp" ] || + differrtmp="$(mktemp -u "${TMPDIR:-/tmp}/difftree-$$-XXXXXX")" + _gdtec=0 + >"$differrtmp" + git diff-tree "$@" 2>"$differrtmp" || _gdtec=$? + ! [ -s "$differrtmp" ] || + # omit anything that mentions a ".renameLimit" config item + <"$differrtmp" LC_ALL=C grep -v -i -F '.renameLimit' || : + rm -f "$differrtmp" + return ${_gdtec:-0} +} + +# # Function to read a tag's (the single argument) header fields into # tagobject the "object" value # tagtype the "type" value @@ -416,7 +433,7 @@ generate_create_branch_email() fi echol "" echol "Summary of changes:" - git diff-tree --no-color --stat=72 --summary -B --find-copies-harder "$oldrev" "$newrev" -- + git_diff_tree --no-color --stat=72 --summary -B --find-copies-harder "$oldrev" "$newrev" -- fi } @@ -596,7 +613,7 @@ generate_update_branch_email() # non-fast-forward updates. echol "" echol "Summary of changes:" - git diff-tree --no-color --stat=72 --summary -B --find-copies-harder "$oldrev..$newrev" -- + git_diff_tree --no-color --stat=72 --summary -B --find-copies-harder "$oldrev..$newrev" -- } # @@ -607,7 +624,7 @@ generate_delete_branch_email() echol " was $oldrev" echol "" echol "$LOGBEGIN" - git diff-tree --no-color --date="$datefmt" -s --abbrev-commit --abbrev=$habbr --always --encoding=UTF-8 --pretty=oneline "$oldrev" -- + git_diff_tree --no-color --date="$datefmt" -s --abbrev-commit --abbrev=$habbr --always --encoding=UTF-8 --pretty=oneline "$oldrev" -- echol "$LOGEND" } @@ -744,7 +761,7 @@ generate_delete_atag_email() echol " was $oldrev" echol "" echol "$LOGBEGIN" - git diff-tree --no-color --date="$datefmt" -s --abbrev-commit --abbrev=$habbr --always --encoding=UTF-8 --pretty=oneline "$oldrev" -- + git_diff_tree --no-color --date="$datefmt" -s --abbrev-commit --abbrev=$habbr --always --encoding=UTF-8 --pretty=oneline "$oldrev" -- echol "$LOGEND" } @@ -795,7 +812,7 @@ generate_general_email() pfmt12="$pfmt1$pfmt2" fi echol "$LOGBEGIN" - git diff-tree --no-color --date="$datefmt" --root -s --always --encoding=UTF-8 --format="$pfmt12$projurlesc/$newrev16$pfmt3" --abbrev=$habbr "$newrev" -- + git_diff_tree --no-color --date="$datefmt" --root -s --always --encoding=UTF-8 --format="$pfmt12$projurlesc/$newrev16$pfmt3" --abbrev=$habbr "$newrev" -- echol "$LOGEND" else # What can we do here? The tag marks an object that is not @@ -814,7 +831,7 @@ generate_delete_general_email() echol " was $oldrev" echol "" echol "$LOGBEGIN" - git diff-tree --no-color --date="$datefmt" -s --abbrev-commit --abbrev=$habbr --always --encoding=UTF-8 --pretty=oneline "$oldrev" -- + git_diff_tree --no-color --date="$datefmt" -s --abbrev-commit --abbrev=$habbr --always --encoding=UTF-8 --pretty=oneline "$oldrev" -- echol "$LOGEND" } @@ -908,7 +925,7 @@ show_new_revisions() fi scratch="${onerev#????????????????}" onerev16="${onerev%$scratch}" - git diff-tree --no-color --date="$datefmt" $opts --always --encoding=UTF-8 --format="$pfmt12$projurlesc/$onerev16$pfmt3" --abbrev=$habbr -B -C --root "$onerev" -- + git_diff_tree --no-color --date="$datefmt" $opts --always --encoding=UTF-8 --format="$pfmt12$projurlesc/$onerev16$pfmt3" --abbrev=$habbr -B -C --root "$onerev" -- echo fi done <