public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/users/guojiufu/heads/personal-branch)] contrib: Make prepare-commit-msg hook smarter for amends
@ 2020-06-13  2:58 Jiu Fu Guo
  0 siblings, 0 replies; only message in thread
From: Jiu Fu Guo @ 2020-06-13  2:58 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:df665e568dcba2fe0b14a6cf0888cc78b4ebbf44

commit df665e568dcba2fe0b14a6cf0888cc78b4ebbf44
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Thu Jun 11 20:22:17 2020 +0100

    contrib: Make prepare-commit-msg hook smarter for amends
    
    With this change the prepare-commit-msg hook can compare the log of a
    commit being amended with the staged changes, and not run mklog.py
    unnecessarily. This is controlled by a git config option,
    gcc-config.mklog-hook-type.
    
    contrib/ChangeLog:
    
            * prepare-commit-msg: Use the gcc-config.mklog-hook-type Git
            config key instead of the GCC_FORCE_MKLOG environment variable.
            Optionally disable generating a new ChangeLog template for
            amended commits when the existing log is still OK.

Diff:
---
 contrib/prepare-commit-msg | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/contrib/prepare-commit-msg b/contrib/prepare-commit-msg
index cc9ba2e6ba1..969847df6f4 100755
--- a/contrib/prepare-commit-msg
+++ b/contrib/prepare-commit-msg
@@ -49,6 +49,19 @@ elif [ $COMMIT_SOURCE = commit ]; then
     # otherwise, assume a new commit with -C.
     if [ $SHA1 = HEAD ]; then
 	cmd="diff --cached HEAD^"
+	if [ "$(git config gcc-config.mklog-hook-type)" = "smart-amend" ]; then
+	    # Check if the existing message still describes the staged changes.
+	    f=$(mktemp /tmp/git-commit.XXXXXX) || exit 1
+	    git log -1 --pretty=email HEAD > $f
+	    printf '\n---\n\n' >> $f
+	    git $cmd >> $f
+	    if contrib/gcc-changelog/git_email.py "$f" >/dev/null 2>&1; then
+		# Existing commit message is still OK for amended commit.
+		rm $f
+		exit 0
+	    fi
+	    rm $f
+	fi
     else
 	cmd="diff --cached"
     fi


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-06-13  2:58 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-13  2:58 [gcc(refs/users/guojiufu/heads/personal-branch)] contrib: Make prepare-commit-msg hook smarter for amends Jiu Fu Guo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).