diff mbox series

[RFC] gcc-git: Add prepare-commit-msg hook.

Message ID 20200523213902.7167-1-jason@redhat.com
State New
Headers show
Series [RFC] gcc-git: Add prepare-commit-msg hook. | expand

Commit Message

Jason Merrill May 23, 2020, 9:39 p.m. UTC
This patch introduces a prepare-commit-msg hook that appends a ChangeLog
skeleton to a commit message that doesn't already have one, and a 'git
amend-mklog' command to amend and append a new ChangeLog skeleton (to be
edited together with existing entries by hand).

Thoughts?

contrib/ChangeLog:

	* prepare-commit-msg: New file.
	* gcc-git-customization.sh: Install it.  Add amend-mklog alias.
---
 contrib/gcc-git-customization.sh |  5 ++++
 contrib/prepare-commit-msg       | 39 ++++++++++++++++++++++++++++++++
 2 files changed, 44 insertions(+)
 create mode 100644 contrib/prepare-commit-msg


base-commit: 584d52b088f9fcf78704b504c3f1f07e17c1cded

Comments

Martin Liška May 25, 2020, 6:14 p.m. UTC | #1
On 5/23/20 11:39 PM, Jason Merrill via Gcc-patches wrote:
> This patch introduces a prepare-commit-msg hook that appends a ChangeLog
> skeleton to a commit message that doesn't already have one, and a 'git
> amend-mklog' command to amend and append a new ChangeLog skeleton (to be
> edited together with existing entries by hand).

As mentioned in the previous email, I prefer to make it opt-in, not opt-out.

So I'm suggesting the 'git commit-mklog' alias that add the skeleton to
a git commit message.

I also changed the hook to use named variables. And I would like to preserve
the ending '# Please enter the commit message for your changes. Lines starting'
section, so I use the mklog.py to put the skeleton to a proper place.

Example:

gcc/ChangeLog:

	* ipa-icf.c (make_pass_ipa_icf):

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# On branch me/add-prepare-commit-msg-hook
# Changes to be committed:
#	modified:   gcc/ipa-icf.c
#

Thoughts?
Martin
Jason Merrill May 25, 2020, 7:50 p.m. UTC | #2
I'll integrate your changes with mine.

On Mon, May 25, 2020 at 2:14 PM Martin Liška <mliska@suse.cz> wrote:
>
> On 5/23/20 11:39 PM, Jason Merrill via Gcc-patches wrote:
> > This patch introduces a prepare-commit-msg hook that appends a ChangeLog
> > skeleton to a commit message that doesn't already have one, and a 'git
> > amend-mklog' command to amend and append a new ChangeLog skeleton (to be
> > edited together with existing entries by hand).
>
> As mentioned in the previous email, I prefer to make it opt-in, not opt-out.
>
> So I'm suggesting the 'git commit-mklog' alias that add the skeleton to
> a git commit message.
>
> I also changed the hook to use named variables. And I would like to preserve
> the ending '# Please enter the commit message for your changes. Lines starting'
> section, so I use the mklog.py to put the skeleton to a proper place.
>
> Example:
>
> gcc/ChangeLog:
>
>         * ipa-icf.c (make_pass_ipa_icf):
>
> # Please enter the commit message for your changes. Lines starting
> # with '#' will be ignored, and an empty message aborts the commit.
> #
> # On branch me/add-prepare-commit-msg-hook
> # Changes to be committed:
> #       modified:   gcc/ipa-icf.c
> #
>
> Thoughts?
> Martin
Jason Merrill May 25, 2020, 8:08 p.m. UTC | #3
On Mon, May 25, 2020 at 3:50 PM Jason Merrill <jason@redhat.com> wrote:
> On Mon, May 25, 2020 at 2:14 PM Martin Liška <mliska@suse.cz> wrote:
> >
> > On 5/23/20 11:39 PM, Jason Merrill via Gcc-patches wrote:
> > > This patch introduces a prepare-commit-msg hook that appends a ChangeLog
> > > skeleton to a commit message that doesn't already have one, and a 'git
> > > amend-mklog' command to amend and append a new ChangeLog skeleton (to be
> > > edited together with existing entries by hand).
> >
> > As mentioned in the previous email, I prefer to make it opt-in, not opt-out.
> >
> > So I'm suggesting the 'git commit-mklog' alias that add the skeleton to
> > a git commit message.
> >
> > I also changed the hook to use named variables. And I would like to preserve
> > the ending '# Please enter the commit message for your changes. Lines starting'
> > section, so I use the mklog.py to put the skeleton to a proper place.
> >
> > Example:
> >
> > gcc/ChangeLog:
> >
> >         * ipa-icf.c (make_pass_ipa_icf):
> >
> > # Please enter the commit message for your changes. Lines starting
> > # with '#' will be ignored, and an empty message aborts the commit.
> > #
> > # On branch me/add-prepare-commit-msg-hook
> > # Changes to be committed:
> > #       modified:   gcc/ipa-icf.c
> > #
> >
> > Thoughts?
>
> I'll integrate your changes with mine.

Like so:
Martin Liška May 25, 2020, 8:15 p.m. UTC | #4
On 5/25/20 10:08 PM, Jason Merrill wrote:
> Like so:

I like the patch, thanks!

The last question I have: Do we want to make installation of the hook
optional in gcc-git-customization.sh?

Martin
Jason Merrill May 25, 2020, 9:59 p.m. UTC | #5
On 5/25/20 4:15 PM, Martin Liška wrote:
> On 5/25/20 10:08 PM, Jason Merrill wrote:
>> Like so:
> 
> I like the patch, thanks!
> 
> The last question I have: Do we want to make installation of the hook
> optional in gcc-git-customization.sh?

Sure:
Martin Liška May 26, 2020, 6:39 a.m. UTC | #6
On 5/25/20 11:59 PM, Jason Merrill wrote:
> On 5/25/20 4:15 PM, Martin Liška wrote:
>> On 5/25/20 10:08 PM, Jason Merrill wrote:
>>> Like so:
>>
>> I like the patch, thanks!
>>
>> The last question I have: Do we want to make installation of the hook
>> optional in gcc-git-customization.sh?
> 
> Sure:
> 

Thanks, I've just installed your patch and I'm starting testing of it.

Martin
Martin Liška May 26, 2020, 7:12 a.m. UTC | #7
Hi.

There's a small improvement. When filling up the ChangeLog entries,
I see it handy to open a patch in a separate window. I would use
GCC_DIFF_FILE env. variable for saving of the diff file.

Thoughts?
Martin
Jason Merrill May 26, 2020, 6:02 p.m. UTC | #8
On 5/26/20 3:12 AM, Martin Liška wrote:
> Hi.
> 
> There's a small improvement. When filling up the ChangeLog entries,
> I see it handy to open a patch in a separate window. I would use
> GCC_DIFF_FILE env. variable for saving of the diff file.

It seems easy enough to execute the command yourself in another window, 
but I'm not opposed to the change.

Maybe these environment variables should start with GCC_GIT, not just 
GCC, to give more indication what they're for.

Jason
Martin Liška May 27, 2020, 8:15 a.m. UTC | #9
On 5/26/20 8:02 PM, Jason Merrill wrote:
> Maybe these environment variables should start with GCC_GIT, not just GCC, to give more indication what they're for.

All right, I renamed it and pushed to master.

Martin
diff mbox series

Patch

diff --git a/contrib/gcc-git-customization.sh b/contrib/gcc-git-customization.sh
index 7a950ae5f38..a36403f0b2c 100755
--- a/contrib/gcc-git-customization.sh
+++ b/contrib/gcc-git-customization.sh
@@ -30,6 +30,11 @@  git config alias.gcc-backport '!f() { rev=$1; git cherry-pick -x $@; } ; f'
 
 git config alias.gcc-mklog '!f() { "`git rev-parse --show-toplevel`/contrib/mklog.py" $@; } ; f'
 
+hookdir=`git rev-parse --git-path hooks`
+install "`git rev-parse --show-toplevel`/contrib/prepare-commit-msg" "$hookdir"
+
+git config alias.amend-mklog '!f() { GCC_PREPARE_COMMIT_FORCE_APPEND=1 git commit --amend "$@"; }; f'
+
 # Make diff on MD files use "(define" as a function marker.
 # Use this in conjunction with a .gitattributes file containing
 # *.md    diff=md
diff --git a/contrib/prepare-commit-msg b/contrib/prepare-commit-msg
new file mode 100644
index 00000000000..61bc051268f
--- /dev/null
+++ b/contrib/prepare-commit-msg
@@ -0,0 +1,39 @@ 
+#!/bin/sh
+
+#COMMIT_MSG_FILE=$1
+#COMMIT_SOURCE=$2
+#SHA1=$3
+
+#echo "# $*" > $HOME/prepare-commit-msg-args
+
+# Can't do anything if $1 isn't a file.
+if ! [ -f "$1" ]; then exit 0; fi
+
+# Don't mess with existing entries unless requested to.
+if [ -z "$GCC_PREPARE_COMMIT_FORCE_APPEND" ] &&
+       grep -qsF 'ChangeLog:' "$1"
+then exit 0; fi
+
+if [ -z "$2" ] || [ $2 == template ]; then
+    # No source or "template" means new commit.
+    cmd="diff --cached"
+elif [ $2 == message ]; then
+    # "message" means -m, but could be either a new commit or --amend.
+    # Guess which based on whether there are any changes staged.
+    if git diff --cached --quiet; then
+	cmd="show"
+    else
+	cmd="diff --cached"
+    fi
+
+    # Add a blank line before the ChangeLog entries.
+    echo >> "$1"
+elif [ $2 == commit ]; then
+    # The message of an existing commit.
+    cmd="show $3"
+else
+    # Do nothing for merge or squash.
+    exit 0
+fi
+
+git $cmd | git gcc-mklog >> "$1"