On 10/06/20 13:13 +0100, Jonathan Wakely wrote:
On 10/06/20 09:43 +0200, Martin Liška wrote:
On 6/9/20 9:46 PM, Jonathan Wakely wrote:
Is this worth adding to contrib/prepare-commit-msg?

I like the idea and I would make it conditional based on
an environment variable? Similarly to GCC_GIT_DIFF_FILE?

With this patch you can use the gcc-config.use-mklog-hook config key
instead of defining GCC_FORCE_MKLOG in the environment.

My new behaviour is enabled when that variable is set to
'smart-amend' (either in the environment, or in your git config).

And this is another little patch that just avoids running 'git diff'
twice, by using tee(1) to write to $GCC_GIT_DIFF_FILE as a side effect
of generating the diff to pipe to mklog.py.


commit e147d6164775d004d608501963befeb551732529
Author: Jonathan Wakely <jwak...@redhat.com>
Date:   Wed Jun 10 13:05:39 2020 +0100

    contrib: Avoid redundant 'git diff' in prepare-commit-msg hook
    
    contrib/ChangeLog:
    
            * prepare-commit-msg: Use 'tee' to save the diff to a file
            instead of running 'git diff' twice.

diff --git a/contrib/prepare-commit-msg b/contrib/prepare-commit-msg
index cfcf0e7afe5..d27861f4cd6 100755
--- a/contrib/prepare-commit-msg
+++ b/contrib/prepare-commit-msg
@@ -76,7 +76,9 @@ fi
 
 # Save diff to a file if requested.
 if ! [ -z "$GCC_GIT_DIFF_FILE" ]; then
-  git $cmd > "$GCC_GIT_DIFF_FILE";
+    tee="tee $GCC_GIT_DIFF_FILE"
+else
+    tee="cat"
 fi
 
-git $cmd | git gcc-mklog -c "$COMMIT_MSG_FILE"
+git $cmd | $tee | git gcc-mklog -c "$COMMIT_MSG_FILE"

Reply via email to