git@vger.kernel.org mailing list mirror (one of many)
 help / Atom feed
* [PATCH/RFC] sequencer.c: record revert/cherry-pick commit with trailer lines
@ 2018-11-04  7:22 Nguyễn Thái Ngọc Duy
  2018-11-04 16:45 ` Phillip Wood
                   ` (3 more replies)
  0 siblings, 4 replies; 25+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2018-11-04  7:22 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

When a commit is reverted (or cherry-picked with -x) we add an English
sentence recording that commit id in the new commit message. Make
these real trailer lines instead so that they are more friendly to
parsers (especially "git interpret-trailers").

A reverted commit will have a new trailer

    Revert: <commit-id>

Similarly a cherry-picked commit with -x will have

    Cherry-Pick: <commit-id>

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 I think standardizing how we record commit ids in the commit message
 is a good idea. Though to be honest this started because of my irk of
 an English string "cherry picked from..." that cannot be translated.
 It might as well be a computer language that happens to look like
 English.

 Documentation/git-cherry-pick.txt |  5 ++---
 sequencer.c                       | 20 ++++++--------------
 t/t3510-cherry-pick-sequence.sh   | 12 ++++++------
 t/t3511-cherry-pick-x.sh          | 26 +++++++++++++-------------
 4 files changed, 27 insertions(+), 36 deletions(-)

diff --git a/Documentation/git-cherry-pick.txt b/Documentation/git-cherry-pick.txt
index d35d771fc8..8ffbaed1a0 100644
--- a/Documentation/git-cherry-pick.txt
+++ b/Documentation/git-cherry-pick.txt
@@ -58,9 +58,8 @@ OPTIONS
 	message prior to committing.
 
 -x::
-	When recording the commit, append a line that says
-	"(cherry picked from commit ...)" to the original commit
-	message in order to indicate which commit this change was
+	When recording the commit, append "Cherry-Pick:" trailer line
+	recording the commit name which commit this change was
 	cherry-picked from.  This is done only for cherry
 	picks without conflicts.  Do not use this option if
 	you are cherry-picking from your private branch because
diff --git a/sequencer.c b/sequencer.c
index 9e1ab3a2a7..f7318f2862 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -36,7 +36,6 @@
 #define GIT_REFLOG_ACTION "GIT_REFLOG_ACTION"
 
 const char sign_off_header[] = "Signed-off-by: ";
-static const char cherry_picked_prefix[] = "(cherry picked from commit ";
 
 GIT_PATH_FUNC(git_path_commit_editmsg, "COMMIT_EDITMSG")
 
@@ -1758,16 +1757,10 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,
 		base_label = msg.label;
 		next = parent;
 		next_label = msg.parent_label;
-		strbuf_addstr(&msgbuf, "Revert \"");
-		strbuf_addstr(&msgbuf, msg.subject);
-		strbuf_addstr(&msgbuf, "\"\n\nThis reverts commit ");
-		strbuf_addstr(&msgbuf, oid_to_hex(&commit->object.oid));
-
-		if (commit->parents && commit->parents->next) {
-			strbuf_addstr(&msgbuf, ", reversing\nchanges made to ");
-			strbuf_addstr(&msgbuf, oid_to_hex(&parent->object.oid));
-		}
-		strbuf_addstr(&msgbuf, ".\n");
+		strbuf_addf(&msgbuf, "Revert \"%s\"\n\n", msg.subject);
+
+		strbuf_addf(&msgbuf, "Revert: %s\n",
+			    oid_to_hex(&commit->object.oid));
 	} else {
 		const char *p;
 
@@ -1784,9 +1777,8 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,
 			strbuf_complete_line(&msgbuf);
 			if (!has_conforming_footer(&msgbuf, NULL, 0))
 				strbuf_addch(&msgbuf, '\n');
-			strbuf_addstr(&msgbuf, cherry_picked_prefix);
-			strbuf_addstr(&msgbuf, oid_to_hex(&commit->object.oid));
-			strbuf_addstr(&msgbuf, ")\n");
+			strbuf_addf(&msgbuf, "Cherry-Pick: %s\n",
+				    oid_to_hex(&commit->object.oid));
 		}
 		if (!is_fixup(command))
 			author = get_author(msg.message);
diff --git a/t/t3510-cherry-pick-sequence.sh b/t/t3510-cherry-pick-sequence.sh
index c84eeefdc9..89b6e7fc1e 100755
--- a/t/t3510-cherry-pick-sequence.sh
+++ b/t/t3510-cherry-pick-sequence.sh
@@ -390,10 +390,10 @@ test_expect_success '--continue respects opts' '
 	git cat-file commit HEAD~1 >picked_msg &&
 	git cat-file commit HEAD~2 >unrelatedpick_msg &&
 	git cat-file commit HEAD~3 >initial_msg &&
-	! grep "cherry picked from" initial_msg &&
-	grep "cherry picked from" unrelatedpick_msg &&
-	grep "cherry picked from" picked_msg &&
-	grep "cherry picked from" anotherpick_msg
+	! grep "Cherry-Pick:" initial_msg &&
+	grep "Cherry-Pick: " unrelatedpick_msg &&
+	grep "Cherry-Pick: " picked_msg &&
+	grep "Cherry-Pick: " anotherpick_msg
 '
 
 test_expect_success '--continue of single-pick respects -x' '
@@ -404,7 +404,7 @@ test_expect_success '--continue of single-pick respects -x' '
 	git cherry-pick --continue &&
 	test_path_is_missing .git/sequencer &&
 	git cat-file commit HEAD >msg &&
-	grep "cherry picked from" msg
+	grep "Cherry-Pick:" msg
 '
 
 test_expect_success '--continue respects -x in first commit in multi-pick' '
@@ -416,7 +416,7 @@ test_expect_success '--continue respects -x in first commit in multi-pick' '
 	test_path_is_missing .git/sequencer &&
 	git cat-file commit HEAD^ >msg &&
 	picked=$(git rev-parse --verify picked) &&
-	grep "cherry picked from.*$picked" msg
+	grep "Cherry-Pick: $picked" msg
 '
 
 test_expect_failure '--signoff is automatically propagated to resolved conflict' '
diff --git a/t/t3511-cherry-pick-x.sh b/t/t3511-cherry-pick-x.sh
index 9888bf34b9..db11dd2430 100755
--- a/t/t3511-cherry-pick-x.sh
+++ b/t/t3511-cherry-pick-x.sh
@@ -32,7 +32,7 @@ mesg_with_footer_sob="$mesg_with_footer
 Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>"
 
 mesg_with_cherry_footer="$mesg_with_footer_sob
-(cherry picked from commit da39a3ee5e6b4b0d3255bfef95601890afd80709)
+Cherry-Pick: da39a3ee5e6b4b0d3255bfef95601890afd80709
 Tested-by: C.U. Thor <cuthor@example.com>"
 
 mesg_unclean="$mesg_one_line
@@ -81,7 +81,7 @@ test_expect_success 'cherry-pick -x inserts blank line after one line subject' '
 	cat <<-EOF >expect &&
 		$mesg_one_line
 
-		(cherry picked from commit $sha1)
+		Cherry-Pick: $sha1
 	EOF
 	git log -1 --pretty=format:%B >actual &&
 	test_cmp expect actual
@@ -129,7 +129,7 @@ test_expect_success 'cherry-pick -x inserts blank line when conforming footer no
 	cat <<-EOF >expect &&
 		$mesg_no_footer
 
-		(cherry picked from commit $sha1)
+		Cherry-Pick: $sha1
 	EOF
 	git log -1 --pretty=format:%B >actual &&
 	test_cmp expect actual
@@ -154,7 +154,7 @@ test_expect_success 'cherry-pick -x -s inserts blank line when conforming footer
 	cat <<-EOF >expect &&
 		$mesg_no_footer
 
-		(cherry picked from commit $sha1)
+		Cherry-Pick: $sha1
 		Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
 	EOF
 	git log -1 --pretty=format:%B >actual &&
@@ -178,7 +178,7 @@ test_expect_success 'cherry-pick -x -s adds sob when last sob doesnt match commi
 	git cherry-pick -x -s mesg-with-footer &&
 	cat <<-EOF >expect &&
 		$mesg_with_footer
-		(cherry picked from commit $sha1)
+		Cherry-Pick: $sha1
 		Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
 	EOF
 	git log -1 --pretty=format:%B >actual &&
@@ -201,7 +201,7 @@ test_expect_success 'cherry-pick -x -s adds sob even when trailing sob exists fo
 	git cherry-pick -x -s mesg-with-footer-sob &&
 	cat <<-EOF >expect &&
 		$mesg_with_footer_sob
-		(cherry picked from commit $sha1)
+		Cherry-Pick: $sha1
 		Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
 	EOF
 	git log -1 --pretty=format:%B >actual &&
@@ -215,7 +215,7 @@ test_expect_success 'cherry-pick -x handles commits with no NL at end of message
 	git cherry-pick -x $sha1 &&
 	git log -1 --pretty=format:%B >actual &&
 
-	printf "\n(cherry picked from commit %s)\n" $sha1 >>msg &&
+	printf "\nCherry-Pick: %s\n" $sha1 >>msg &&
 	test_cmp msg actual
 '
 
@@ -226,7 +226,7 @@ test_expect_success 'cherry-pick -x handles commits with no footer and no NL at
 	git cherry-pick -x $sha1 &&
 	git log -1 --pretty=format:%B >actual &&
 
-	printf "\n\n(cherry picked from commit %s)\n" $sha1 >>msg &&
+	printf "\n\nCherry-Pick: %s\n" $sha1 >>msg &&
 	test_cmp msg actual
 '
 
@@ -252,19 +252,19 @@ test_expect_success 'cherry-pick -s handles commits with no footer and no NL at
 	test_cmp msg actual
 '
 
-test_expect_success 'cherry-pick -x treats "(cherry picked from..." line as part of footer' '
+test_expect_success 'cherry-pick -x treats "Cherry-Pick:" line as part of footer' '
 	pristine_detach initial &&
 	sha1=$(git rev-parse mesg-with-cherry-footer^0) &&
 	git cherry-pick -x mesg-with-cherry-footer &&
 	cat <<-EOF >expect &&
 		$mesg_with_cherry_footer
-		(cherry picked from commit $sha1)
+		Cherry-Pick: $sha1
 	EOF
 	git log -1 --pretty=format:%B >actual &&
 	test_cmp expect actual
 '
 
-test_expect_success 'cherry-pick -s treats "(cherry picked from..." line as part of footer' '
+test_expect_success 'cherry-pick -s treats "Cherry-Pick:" line as part of footer' '
 	pristine_detach initial &&
 	git cherry-pick -s mesg-with-cherry-footer &&
 	cat <<-EOF >expect &&
@@ -275,13 +275,13 @@ test_expect_success 'cherry-pick -s treats "(cherry picked from..." line as part
 	test_cmp expect actual
 '
 
-test_expect_success 'cherry-pick -x -s treats "(cherry picked from..." line as part of footer' '
+test_expect_success 'cherry-pick -x -s treats "Cherry-Pick:..." line as part of footer' '
 	pristine_detach initial &&
 	sha1=$(git rev-parse mesg-with-cherry-footer^0) &&
 	git cherry-pick -x -s mesg-with-cherry-footer &&
 	cat <<-EOF >expect &&
 		$mesg_with_cherry_footer
-		(cherry picked from commit $sha1)
+		Cherry-Pick: $sha1
 		Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
 	EOF
 	git log -1 --pretty=format:%B >actual &&
-- 
2.19.1.1005.gac84295441


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH/RFC] sequencer.c: record revert/cherry-pick commit with trailer lines
  2018-11-04  7:22 [PATCH/RFC] sequencer.c: record revert/cherry-pick commit with trailer lines Nguyễn Thái Ngọc Duy
@ 2018-11-04 16:45 ` Phillip Wood
  2018-11-04 17:41   ` Duy Nguyen
  2018-11-04 18:10 ` [PATCH/RFC v2] " Nguyễn Thái Ngọc Duy
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 25+ messages in thread
From: Phillip Wood @ 2018-11-04 16:45 UTC (permalink / raw)
  To: Nguyễn Thái Ngọc Duy, git

On 04/11/2018 07:22, Nguyễn Thái Ngọc Duy wrote:
> When a commit is reverted (or cherry-picked with -x) we add an English
> sentence recording that commit id in the new commit message. Make
> these real trailer lines instead so that they are more friendly to
> parsers (especially "git interpret-trailers").
> 
> A reverted commit will have a new trailer
> 
>      Revert: <commit-id>
> 
> Similarly a cherry-picked commit with -x will have
> 
>      Cherry-Pick: <commit-id>

I think this is a good idea though I wonder if it will break someones 
script that is looking for the messages generated by -x at the moment. 
I've got a couple of comments below.

> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> ---
>   I think standardizing how we record commit ids in the commit message
>   is a good idea. Though to be honest this started because of my irk of
>   an English string "cherry picked from..." that cannot be translated.
>   It might as well be a computer language that happens to look like
>   English.
> 
>   Documentation/git-cherry-pick.txt |  5 ++---
>   sequencer.c                       | 20 ++++++--------------
>   t/t3510-cherry-pick-sequence.sh   | 12 ++++++------
>   t/t3511-cherry-pick-x.sh          | 26 +++++++++++++-------------
>   4 files changed, 27 insertions(+), 36 deletions(-)
> 
> diff --git a/Documentation/git-cherry-pick.txt b/Documentation/git-cherry-pick.txt
> index d35d771fc8..8ffbaed1a0 100644
> --- a/Documentation/git-cherry-pick.txt
> +++ b/Documentation/git-cherry-pick.txt
> @@ -58,9 +58,8 @@ OPTIONS
>   	message prior to committing.
>   
>   -x::
> -	When recording the commit, append a line that says
> -	"(cherry picked from commit ...)" to the original commit
> -	message in order to indicate which commit this change was
> +	When recording the commit, append "Cherry-Pick:" trailer line
> +	recording the commit name which commit this change was
>   	cherry-picked from.  This is done only for cherry
>   	picks without conflicts.  Do not use this option if
>   	you are cherry-picking from your private branch because
> diff --git a/sequencer.c b/sequencer.c
> index 9e1ab3a2a7..f7318f2862 100644
> --- a/sequencer.c
> +++ b/sequencer.c
> @@ -36,7 +36,6 @@
>   #define GIT_REFLOG_ACTION "GIT_REFLOG_ACTION"
>   
>   const char sign_off_header[] = "Signed-off-by: ";
> -static const char cherry_picked_prefix[] = "(cherry picked from commit ";
>   
>   GIT_PATH_FUNC(git_path_commit_editmsg, "COMMIT_EDITMSG")
>   
> @@ -1758,16 +1757,10 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,
>   		base_label = msg.label;
>   		next = parent;
>   		next_label = msg.parent_label;
> -		strbuf_addstr(&msgbuf, "Revert \"");
> -		strbuf_addstr(&msgbuf, msg.subject);
> -		strbuf_addstr(&msgbuf, "\"\n\nThis reverts commit ");
> -		strbuf_addstr(&msgbuf, oid_to_hex(&commit->object.oid));
> -
> -		if (commit->parents && commit->parents->next) {
> -			strbuf_addstr(&msgbuf, ", reversing\nchanges made to ");
> -			strbuf_addstr(&msgbuf, oid_to_hex(&parent->object.oid));
> -		}

As revert currently records the parent given on the command line when 
reverting a merge commit it would probably be a good idea to add that 
either as a separate trailer or to the Revert: trailer and possibly also 
generate it for cherry picks.

> -		strbuf_addstr(&msgbuf, ".\n");
> +		strbuf_addf(&msgbuf, "Revert \"%s\"\n\n", msg.subject);

If the message already contains trailers then should we just append the 
Revert trailer those rather than inserting "\n\n"?

Best Wishes

Phillip

> +
> +		strbuf_addf(&msgbuf, "Revert: %s\n",
> +			    oid_to_hex(&commit->object.oid));

>   	} else {
>   		const char *p;
>   
> @@ -1784,9 +1777,8 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,
>   			strbuf_complete_line(&msgbuf);
>   			if (!has_conforming_footer(&msgbuf, NULL, 0))
>   				strbuf_addch(&msgbuf, '\n');
> -			strbuf_addstr(&msgbuf, cherry_picked_prefix);
> -			strbuf_addstr(&msgbuf, oid_to_hex(&commit->object.oid));
> -			strbuf_addstr(&msgbuf, ")\n");
> +			strbuf_addf(&msgbuf, "Cherry-Pick: %s\n",
> +				    oid_to_hex(&commit->object.oid));
>   		}
>   		if (!is_fixup(command))
>   			author = get_author(msg.message);
> diff --git a/t/t3510-cherry-pick-sequence.sh b/t/t3510-cherry-pick-sequence.sh
> index c84eeefdc9..89b6e7fc1e 100755
> --- a/t/t3510-cherry-pick-sequence.sh
> +++ b/t/t3510-cherry-pick-sequence.sh
> @@ -390,10 +390,10 @@ test_expect_success '--continue respects opts' '
>   	git cat-file commit HEAD~1 >picked_msg &&
>   	git cat-file commit HEAD~2 >unrelatedpick_msg &&
>   	git cat-file commit HEAD~3 >initial_msg &&
> -	! grep "cherry picked from" initial_msg &&
> -	grep "cherry picked from" unrelatedpick_msg &&
> -	grep "cherry picked from" picked_msg &&
> -	grep "cherry picked from" anotherpick_msg
> +	! grep "Cherry-Pick:" initial_msg &&
> +	grep "Cherry-Pick: " unrelatedpick_msg &&
> +	grep "Cherry-Pick: " picked_msg &&
> +	grep "Cherry-Pick: " anotherpick_msg
>   '
>   
>   test_expect_success '--continue of single-pick respects -x' '
> @@ -404,7 +404,7 @@ test_expect_success '--continue of single-pick respects -x' '
>   	git cherry-pick --continue &&
>   	test_path_is_missing .git/sequencer &&
>   	git cat-file commit HEAD >msg &&
> -	grep "cherry picked from" msg
> +	grep "Cherry-Pick:" msg
>   '
>   
>   test_expect_success '--continue respects -x in first commit in multi-pick' '
> @@ -416,7 +416,7 @@ test_expect_success '--continue respects -x in first commit in multi-pick' '
>   	test_path_is_missing .git/sequencer &&
>   	git cat-file commit HEAD^ >msg &&
>   	picked=$(git rev-parse --verify picked) &&
> -	grep "cherry picked from.*$picked" msg
> +	grep "Cherry-Pick: $picked" msg
>   '
>   
>   test_expect_failure '--signoff is automatically propagated to resolved conflict' '
> diff --git a/t/t3511-cherry-pick-x.sh b/t/t3511-cherry-pick-x.sh
> index 9888bf34b9..db11dd2430 100755
> --- a/t/t3511-cherry-pick-x.sh
> +++ b/t/t3511-cherry-pick-x.sh
> @@ -32,7 +32,7 @@ mesg_with_footer_sob="$mesg_with_footer
>   Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>"
>   
>   mesg_with_cherry_footer="$mesg_with_footer_sob
> -(cherry picked from commit da39a3ee5e6b4b0d3255bfef95601890afd80709)
> +Cherry-Pick: da39a3ee5e6b4b0d3255bfef95601890afd80709
>   Tested-by: C.U. Thor <cuthor@example.com>"
>   
>   mesg_unclean="$mesg_one_line
> @@ -81,7 +81,7 @@ test_expect_success 'cherry-pick -x inserts blank line after one line subject' '
>   	cat <<-EOF >expect &&
>   		$mesg_one_line
>   
> -		(cherry picked from commit $sha1)
> +		Cherry-Pick: $sha1
>   	EOF
>   	git log -1 --pretty=format:%B >actual &&
>   	test_cmp expect actual
> @@ -129,7 +129,7 @@ test_expect_success 'cherry-pick -x inserts blank line when conforming footer no
>   	cat <<-EOF >expect &&
>   		$mesg_no_footer
>   
> -		(cherry picked from commit $sha1)
> +		Cherry-Pick: $sha1
>   	EOF
>   	git log -1 --pretty=format:%B >actual &&
>   	test_cmp expect actual
> @@ -154,7 +154,7 @@ test_expect_success 'cherry-pick -x -s inserts blank line when conforming footer
>   	cat <<-EOF >expect &&
>   		$mesg_no_footer
>   
> -		(cherry picked from commit $sha1)
> +		Cherry-Pick: $sha1
>   		Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
>   	EOF
>   	git log -1 --pretty=format:%B >actual &&
> @@ -178,7 +178,7 @@ test_expect_success 'cherry-pick -x -s adds sob when last sob doesnt match commi
>   	git cherry-pick -x -s mesg-with-footer &&
>   	cat <<-EOF >expect &&
>   		$mesg_with_footer
> -		(cherry picked from commit $sha1)
> +		Cherry-Pick: $sha1
>   		Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
>   	EOF
>   	git log -1 --pretty=format:%B >actual &&
> @@ -201,7 +201,7 @@ test_expect_success 'cherry-pick -x -s adds sob even when trailing sob exists fo
>   	git cherry-pick -x -s mesg-with-footer-sob &&
>   	cat <<-EOF >expect &&
>   		$mesg_with_footer_sob
> -		(cherry picked from commit $sha1)
> +		Cherry-Pick: $sha1
>   		Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
>   	EOF
>   	git log -1 --pretty=format:%B >actual &&
> @@ -215,7 +215,7 @@ test_expect_success 'cherry-pick -x handles commits with no NL at end of message
>   	git cherry-pick -x $sha1 &&
>   	git log -1 --pretty=format:%B >actual &&
>   
> -	printf "\n(cherry picked from commit %s)\n" $sha1 >>msg &&
> +	printf "\nCherry-Pick: %s\n" $sha1 >>msg &&
>   	test_cmp msg actual
>   '
>   
> @@ -226,7 +226,7 @@ test_expect_success 'cherry-pick -x handles commits with no footer and no NL at
>   	git cherry-pick -x $sha1 &&
>   	git log -1 --pretty=format:%B >actual &&
>   
> -	printf "\n\n(cherry picked from commit %s)\n" $sha1 >>msg &&
> +	printf "\n\nCherry-Pick: %s\n" $sha1 >>msg &&
>   	test_cmp msg actual
>   '
>   
> @@ -252,19 +252,19 @@ test_expect_success 'cherry-pick -s handles commits with no footer and no NL at
>   	test_cmp msg actual
>   '
>   
> -test_expect_success 'cherry-pick -x treats "(cherry picked from..." line as part of footer' '
> +test_expect_success 'cherry-pick -x treats "Cherry-Pick:" line as part of footer' '
>   	pristine_detach initial &&
>   	sha1=$(git rev-parse mesg-with-cherry-footer^0) &&
>   	git cherry-pick -x mesg-with-cherry-footer &&
>   	cat <<-EOF >expect &&
>   		$mesg_with_cherry_footer
> -		(cherry picked from commit $sha1)
> +		Cherry-Pick: $sha1
>   	EOF
>   	git log -1 --pretty=format:%B >actual &&
>   	test_cmp expect actual
>   '
>   
> -test_expect_success 'cherry-pick -s treats "(cherry picked from..." line as part of footer' '
> +test_expect_success 'cherry-pick -s treats "Cherry-Pick:" line as part of footer' '
>   	pristine_detach initial &&
>   	git cherry-pick -s mesg-with-cherry-footer &&
>   	cat <<-EOF >expect &&
> @@ -275,13 +275,13 @@ test_expect_success 'cherry-pick -s treats "(cherry picked from..." line as part
>   	test_cmp expect actual
>   '
>   
> -test_expect_success 'cherry-pick -x -s treats "(cherry picked from..." line as part of footer' '
> +test_expect_success 'cherry-pick -x -s treats "Cherry-Pick:..." line as part of footer' '
>   	pristine_detach initial &&
>   	sha1=$(git rev-parse mesg-with-cherry-footer^0) &&
>   	git cherry-pick -x -s mesg-with-cherry-footer &&
>   	cat <<-EOF >expect &&
>   		$mesg_with_cherry_footer
> -		(cherry picked from commit $sha1)
> +		Cherry-Pick: $sha1
>   		Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
>   	EOF
>   	git log -1 --pretty=format:%B >actual &&
> 


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH/RFC] sequencer.c: record revert/cherry-pick commit with trailer lines
  2018-11-04 16:45 ` Phillip Wood
@ 2018-11-04 17:41   ` Duy Nguyen
  2018-11-04 21:12     ` Phillip Wood
  2018-11-05 21:57     ` Johannes Schindelin
  0 siblings, 2 replies; 25+ messages in thread
From: Duy Nguyen @ 2018-11-04 17:41 UTC (permalink / raw)
  To: Phillip Wood; +Cc: Git Mailing List

On Sun, Nov 4, 2018 at 5:45 PM Phillip Wood <phillip.wood@talktalk.net> wrote:
>
> On 04/11/2018 07:22, Nguyễn Thái Ngọc Duy wrote:
> > When a commit is reverted (or cherry-picked with -x) we add an English
> > sentence recording that commit id in the new commit message. Make
> > these real trailer lines instead so that they are more friendly to
> > parsers (especially "git interpret-trailers").
> >
> > A reverted commit will have a new trailer
> >
> >      Revert: <commit-id>
> >
> > Similarly a cherry-picked commit with -x will have
> >
> >      Cherry-Pick: <commit-id>
>
> I think this is a good idea though I wonder if it will break someones
> script that is looking for the messages generated by -x at the moment.

It will [1] but I still think it's worth the trouble. The script will
be less likely to break after, and you can use git-interpret-trailers
instead of plain grep.

[1] https://public-inbox.org/git/20181017143921.GR270328@devbig004.ftw2.facebook.com/

> > @@ -1758,16 +1757,10 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,
> >               base_label = msg.label;
> >               next = parent;
> >               next_label = msg.parent_label;
> > -             strbuf_addstr(&msgbuf, "Revert \"");
> > -             strbuf_addstr(&msgbuf, msg.subject);
> > -             strbuf_addstr(&msgbuf, "\"\n\nThis reverts commit ");
> > -             strbuf_addstr(&msgbuf, oid_to_hex(&commit->object.oid));
> > -
> > -             if (commit->parents && commit->parents->next) {
> > -                     strbuf_addstr(&msgbuf, ", reversing\nchanges made to ");
> > -                     strbuf_addstr(&msgbuf, oid_to_hex(&parent->object.oid));
> > -             }
>
> As revert currently records the parent given on the command line when
> reverting a merge commit it would probably be a good idea to add that
> either as a separate trailer or to the Revert: trailer and possibly also
> generate it for cherry picks.

My mistake. I didn't read carefully and thought it was logging
commit->parents, which is pointless.

So what should be the trailer for this (I don't think putting it in
Revert: is a good idea, too much to parse)? Revert-parent: ?
Revert-merge: ?

> > -             strbuf_addstr(&msgbuf, ".\n");
> > +             strbuf_addf(&msgbuf, "Revert \"%s\"\n\n", msg.subject);
>
> If the message already contains trailers then should we just append the
> Revert trailer those rather than inserting "\n\n"?

Umm.. but this \n\n is for separating the subject and the body. I
think we need it anyway, trailer or not.

> > @@ -1784,9 +1777,8 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,
> >                       strbuf_complete_line(&msgbuf);
> >                       if (!has_conforming_footer(&msgbuf, NULL, 0))
> >                               strbuf_addch(&msgbuf, '\n');
> > -                     strbuf_addstr(&msgbuf, cherry_picked_prefix);
> > -                     strbuf_addstr(&msgbuf, oid_to_hex(&commit->object.oid));
> > -                     strbuf_addstr(&msgbuf, ")\n");
> > +                     strbuf_addf(&msgbuf, "Cherry-Pick: %s\n",
> > +                                 oid_to_hex(&commit->object.oid));

I will probably make this "Cherry-picked-from:" to match our S-o-b style.
-- 
Duy

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH/RFC v2] sequencer.c: record revert/cherry-pick commit with trailer lines
  2018-11-04  7:22 [PATCH/RFC] sequencer.c: record revert/cherry-pick commit with trailer lines Nguyễn Thái Ngọc Duy
  2018-11-04 16:45 ` Phillip Wood
@ 2018-11-04 18:10 ` " Nguyễn Thái Ngọc Duy
  2018-11-04 21:30   ` brian m. carlson
  2018-11-06 17:16   ` [PATCH/RFC] Support --append-trailer in cherry-pick and revert Nguyễn Thái Ngọc Duy
  2018-11-05  0:56 ` [PATCH/RFC] sequencer.c: record revert/cherry-pick commit with trailer lines Junio C Hamano
  2018-11-06  8:57 ` Ævar Arnfjörð Bjarmason
  3 siblings, 2 replies; 25+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2018-11-04 18:10 UTC (permalink / raw)
  To: pclouds; +Cc: git, phillip.wood

When a commit is reverted (or cherry-picked with -x) we add an English
sentence recording that commit id in the new commit message. Make
these real trailer lines instead so that they are more friendly to
parsers (especially "git interpret-trailers").

A reverted commit will have a new trailer

    Revert: <commit-id>

Similarly a cherry-picked commit with -x will have

    Cherry-picked-from: <commit-id>

When reverting or cherry picking a merge, the reverted/cherry-picked
branch will be shown using extended SHA-1 syntax, e.g.

    Revert: <commit-id>~2

Since we're not producing the old lines "This reverts commit ..." and
"(cherry picked from commit .." anymore, scripts that look for these
lines will need to be updated to handle both. Fresh new history could
just rely on git-interpret-trailers instead.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 v2 adds the third syntax "~2" and renames Cherry-Pick: to
 Cherry-picked-from: and acknowledge the problem with breaking
 scripts. I don't have a pretty solution for that though.

 Documentation/git-cherry-pick.txt |  5 ++---
 sequencer.c                       | 33 +++++++++++++++++--------------
 t/t3510-cherry-pick-sequence.sh   | 12 +++++------
 t/t3511-cherry-pick-x.sh          | 26 ++++++++++++------------
 4 files changed, 39 insertions(+), 37 deletions(-)

diff --git a/Documentation/git-cherry-pick.txt b/Documentation/git-cherry-pick.txt
index d35d771fc8..54e73e74c0 100644
--- a/Documentation/git-cherry-pick.txt
+++ b/Documentation/git-cherry-pick.txt
@@ -58,9 +58,8 @@ OPTIONS
 	message prior to committing.
 
 -x::
-	When recording the commit, append a line that says
-	"(cherry picked from commit ...)" to the original commit
-	message in order to indicate which commit this change was
+	When recording the commit, append "Cherry-picked-from:" trailer line
+	recording the commit name which commit this change was
 	cherry-picked from.  This is done only for cherry
 	picks without conflicts.  Do not use this option if
 	you are cherry-picking from your private branch because
diff --git a/sequencer.c b/sequencer.c
index 9e1ab3a2a7..f804406b68 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -36,7 +36,6 @@
 #define GIT_REFLOG_ACTION "GIT_REFLOG_ACTION"
 
 const char sign_off_header[] = "Signed-off-by: ";
-static const char cherry_picked_prefix[] = "(cherry picked from commit ";
 
 GIT_PATH_FUNC(git_path_commit_editmsg, "COMMIT_EDITMSG")
 
@@ -1669,7 +1668,7 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,
 	char *author = NULL;
 	struct commit_message msg = { NULL, NULL, NULL, NULL };
 	struct strbuf msgbuf = STRBUF_INIT;
-	int res, unborn = 0, allow;
+	int res, unborn = 0, allow, parent_id = -1;
 
 	if (opts->no_commit) {
 		/*
@@ -1716,6 +1715,7 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,
 			return error(_("commit %s does not have parent %d"),
 				oid_to_hex(&commit->object.oid), opts->mainline);
 		parent = p->item;
+		parent_id = cnt;
 	} else if (0 < opts->mainline)
 		return error(_("mainline was specified but commit %s is not a merge."),
 			oid_to_hex(&commit->object.oid));
@@ -1758,16 +1758,15 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,
 		base_label = msg.label;
 		next = parent;
 		next_label = msg.parent_label;
-		strbuf_addstr(&msgbuf, "Revert \"");
-		strbuf_addstr(&msgbuf, msg.subject);
-		strbuf_addstr(&msgbuf, "\"\n\nThis reverts commit ");
-		strbuf_addstr(&msgbuf, oid_to_hex(&commit->object.oid));
-
-		if (commit->parents && commit->parents->next) {
-			strbuf_addstr(&msgbuf, ", reversing\nchanges made to ");
-			strbuf_addstr(&msgbuf, oid_to_hex(&parent->object.oid));
-		}
-		strbuf_addstr(&msgbuf, ".\n");
+		strbuf_addf(&msgbuf, "Revert \"%s\"\n\n", msg.subject);
+
+		if (parent_id != -1)
+			strbuf_addf(&msgbuf, "Revert: %s~%d\n",
+				    oid_to_hex(&commit->object.oid),
+				    parent_id);
+		else
+			strbuf_addf(&msgbuf, "Revert: %s\n",
+				    oid_to_hex(&commit->object.oid));
 	} else {
 		const char *p;
 
@@ -1784,9 +1783,13 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,
 			strbuf_complete_line(&msgbuf);
 			if (!has_conforming_footer(&msgbuf, NULL, 0))
 				strbuf_addch(&msgbuf, '\n');
-			strbuf_addstr(&msgbuf, cherry_picked_prefix);
-			strbuf_addstr(&msgbuf, oid_to_hex(&commit->object.oid));
-			strbuf_addstr(&msgbuf, ")\n");
+			if (parent_id != -1)
+				strbuf_addf(&msgbuf, "Cherry-picked-from: %s~%d\n",
+					    oid_to_hex(&commit->object.oid),
+					    parent_id);
+			else
+				strbuf_addf(&msgbuf, "Cherry-picked-from: %s\n",
+					    oid_to_hex(&commit->object.oid));
 		}
 		if (!is_fixup(command))
 			author = get_author(msg.message);
diff --git a/t/t3510-cherry-pick-sequence.sh b/t/t3510-cherry-pick-sequence.sh
index c84eeefdc9..504423ec20 100755
--- a/t/t3510-cherry-pick-sequence.sh
+++ b/t/t3510-cherry-pick-sequence.sh
@@ -390,10 +390,10 @@ test_expect_success '--continue respects opts' '
 	git cat-file commit HEAD~1 >picked_msg &&
 	git cat-file commit HEAD~2 >unrelatedpick_msg &&
 	git cat-file commit HEAD~3 >initial_msg &&
-	! grep "cherry picked from" initial_msg &&
-	grep "cherry picked from" unrelatedpick_msg &&
-	grep "cherry picked from" picked_msg &&
-	grep "cherry picked from" anotherpick_msg
+	! grep "Cherry-picked-from:" initial_msg &&
+	grep "Cherry-picked-from: " unrelatedpick_msg &&
+	grep "Cherry-picked-from: " picked_msg &&
+	grep "Cherry-picked-from: " anotherpick_msg
 '
 
 test_expect_success '--continue of single-pick respects -x' '
@@ -404,7 +404,7 @@ test_expect_success '--continue of single-pick respects -x' '
 	git cherry-pick --continue &&
 	test_path_is_missing .git/sequencer &&
 	git cat-file commit HEAD >msg &&
-	grep "cherry picked from" msg
+	grep "Cherry-picked-from:" msg
 '
 
 test_expect_success '--continue respects -x in first commit in multi-pick' '
@@ -416,7 +416,7 @@ test_expect_success '--continue respects -x in first commit in multi-pick' '
 	test_path_is_missing .git/sequencer &&
 	git cat-file commit HEAD^ >msg &&
 	picked=$(git rev-parse --verify picked) &&
-	grep "cherry picked from.*$picked" msg
+	grep "Cherry-picked-from: $picked" msg
 '
 
 test_expect_failure '--signoff is automatically propagated to resolved conflict' '
diff --git a/t/t3511-cherry-pick-x.sh b/t/t3511-cherry-pick-x.sh
index 9888bf34b9..798fdaf8da 100755
--- a/t/t3511-cherry-pick-x.sh
+++ b/t/t3511-cherry-pick-x.sh
@@ -32,7 +32,7 @@ mesg_with_footer_sob="$mesg_with_footer
 Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>"
 
 mesg_with_cherry_footer="$mesg_with_footer_sob
-(cherry picked from commit da39a3ee5e6b4b0d3255bfef95601890afd80709)
+Cherry-picked-from: da39a3ee5e6b4b0d3255bfef95601890afd80709
 Tested-by: C.U. Thor <cuthor@example.com>"
 
 mesg_unclean="$mesg_one_line
@@ -81,7 +81,7 @@ test_expect_success 'cherry-pick -x inserts blank line after one line subject' '
 	cat <<-EOF >expect &&
 		$mesg_one_line
 
-		(cherry picked from commit $sha1)
+		Cherry-picked-from: $sha1
 	EOF
 	git log -1 --pretty=format:%B >actual &&
 	test_cmp expect actual
@@ -129,7 +129,7 @@ test_expect_success 'cherry-pick -x inserts blank line when conforming footer no
 	cat <<-EOF >expect &&
 		$mesg_no_footer
 
-		(cherry picked from commit $sha1)
+		Cherry-picked-from: $sha1
 	EOF
 	git log -1 --pretty=format:%B >actual &&
 	test_cmp expect actual
@@ -154,7 +154,7 @@ test_expect_success 'cherry-pick -x -s inserts blank line when conforming footer
 	cat <<-EOF >expect &&
 		$mesg_no_footer
 
-		(cherry picked from commit $sha1)
+		Cherry-picked-from: $sha1
 		Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
 	EOF
 	git log -1 --pretty=format:%B >actual &&
@@ -178,7 +178,7 @@ test_expect_success 'cherry-pick -x -s adds sob when last sob doesnt match commi
 	git cherry-pick -x -s mesg-with-footer &&
 	cat <<-EOF >expect &&
 		$mesg_with_footer
-		(cherry picked from commit $sha1)
+		Cherry-picked-from: $sha1
 		Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
 	EOF
 	git log -1 --pretty=format:%B >actual &&
@@ -201,7 +201,7 @@ test_expect_success 'cherry-pick -x -s adds sob even when trailing sob exists fo
 	git cherry-pick -x -s mesg-with-footer-sob &&
 	cat <<-EOF >expect &&
 		$mesg_with_footer_sob
-		(cherry picked from commit $sha1)
+		Cherry-picked-from: $sha1
 		Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
 	EOF
 	git log -1 --pretty=format:%B >actual &&
@@ -215,7 +215,7 @@ test_expect_success 'cherry-pick -x handles commits with no NL at end of message
 	git cherry-pick -x $sha1 &&
 	git log -1 --pretty=format:%B >actual &&
 
-	printf "\n(cherry picked from commit %s)\n" $sha1 >>msg &&
+	printf "\nCherry-picked-from: %s\n" $sha1 >>msg &&
 	test_cmp msg actual
 '
 
@@ -226,7 +226,7 @@ test_expect_success 'cherry-pick -x handles commits with no footer and no NL at
 	git cherry-pick -x $sha1 &&
 	git log -1 --pretty=format:%B >actual &&
 
-	printf "\n\n(cherry picked from commit %s)\n" $sha1 >>msg &&
+	printf "\n\nCherry-picked-from: %s\n" $sha1 >>msg &&
 	test_cmp msg actual
 '
 
@@ -252,19 +252,19 @@ test_expect_success 'cherry-pick -s handles commits with no footer and no NL at
 	test_cmp msg actual
 '
 
-test_expect_success 'cherry-pick -x treats "(cherry picked from..." line as part of footer' '
+test_expect_success 'cherry-pick -x treats "Cherry-picked-from:" line as part of footer' '
 	pristine_detach initial &&
 	sha1=$(git rev-parse mesg-with-cherry-footer^0) &&
 	git cherry-pick -x mesg-with-cherry-footer &&
 	cat <<-EOF >expect &&
 		$mesg_with_cherry_footer
-		(cherry picked from commit $sha1)
+		Cherry-picked-from: $sha1
 	EOF
 	git log -1 --pretty=format:%B >actual &&
 	test_cmp expect actual
 '
 
-test_expect_success 'cherry-pick -s treats "(cherry picked from..." line as part of footer' '
+test_expect_success 'cherry-pick -s treats "Cherry-picked-from:" line as part of footer' '
 	pristine_detach initial &&
 	git cherry-pick -s mesg-with-cherry-footer &&
 	cat <<-EOF >expect &&
@@ -275,13 +275,13 @@ test_expect_success 'cherry-pick -s treats "(cherry picked from..." line as part
 	test_cmp expect actual
 '
 
-test_expect_success 'cherry-pick -x -s treats "(cherry picked from..." line as part of footer' '
+test_expect_success 'cherry-pick -x -s treats "Cherry-picked-from:..." line as part of footer' '
 	pristine_detach initial &&
 	sha1=$(git rev-parse mesg-with-cherry-footer^0) &&
 	git cherry-pick -x -s mesg-with-cherry-footer &&
 	cat <<-EOF >expect &&
 		$mesg_with_cherry_footer
-		(cherry picked from commit $sha1)
+		Cherry-picked-from: $sha1
 		Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
 	EOF
 	git log -1 --pretty=format:%B >actual &&
-- 
2.19.1.1005.gac84295441


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH/RFC] sequencer.c: record revert/cherry-pick commit with trailer lines
  2018-11-04 17:41   ` Duy Nguyen
@ 2018-11-04 21:12     ` Phillip Wood
  2018-11-05 21:57     ` Johannes Schindelin
  1 sibling, 0 replies; 25+ messages in thread
From: Phillip Wood @ 2018-11-04 21:12 UTC (permalink / raw)
  To: Duy Nguyen, Phillip Wood; +Cc: Git Mailing List

Hi Duy

On 04/11/2018 17:41, Duy Nguyen wrote:
> On Sun, Nov 4, 2018 at 5:45 PM Phillip Wood <phillip.wood@talktalk.net> wrote:
>>
>> On 04/11/2018 07:22, Nguyễn Thái Ngọc Duy wrote:
>>> When a commit is reverted (or cherry-picked with -x) we add an English
>>> sentence recording that commit id in the new commit message. Make
>>> these real trailer lines instead so that they are more friendly to
>>> parsers (especially "git interpret-trailers").
>>>
>>> A reverted commit will have a new trailer
>>>
>>>       Revert: <commit-id>
>>>
>>> Similarly a cherry-picked commit with -x will have
>>>
>>>       Cherry-Pick: <commit-id>
>>
>> I think this is a good idea though I wonder if it will break someones
>> script that is looking for the messages generated by -x at the moment.
> 
> It will [1] but I still think it's worth the trouble. The script will
> be less likely to break after, and you can use git-interpret-trailers
> instead of plain grep.
> 
> [1] https://public-inbox.org/git/20181017143921.GR270328@devbig004.ftw2.facebook.com/
> 
>>> @@ -1758,16 +1757,10 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,
>>>                base_label = msg.label;
>>>                next = parent;
>>>                next_label = msg.parent_label;
>>> -             strbuf_addstr(&msgbuf, "Revert \"");
>>> -             strbuf_addstr(&msgbuf, msg.subject);
>>> -             strbuf_addstr(&msgbuf, "\"\n\nThis reverts commit ");
>>> -             strbuf_addstr(&msgbuf, oid_to_hex(&commit->object.oid));
>>> -
>>> -             if (commit->parents && commit->parents->next) {
>>> -                     strbuf_addstr(&msgbuf, ", reversing\nchanges made to ");
>>> -                     strbuf_addstr(&msgbuf, oid_to_hex(&parent->object.oid));
>>> -             }
>>
>> As revert currently records the parent given on the command line when
>> reverting a merge commit it would probably be a good idea to add that
>> either as a separate trailer or to the Revert: trailer and possibly also
>> generate it for cherry picks.
> 
> My mistake. I didn't read carefully and thought it was logging
> commit->parents, which is pointless.
> 
> So what should be the trailer for this (I don't think putting it in
> Revert: is a good idea, too much to parse)? Revert-parent: ?
> Revert-merge: ?

I think Revert-parent: is good, though you seem to have gone for 
including it the Revert: trailer in v2.
>>> -             strbuf_addstr(&msgbuf, ".\n");
>>> +             strbuf_addf(&msgbuf, "Revert \"%s\"\n\n", msg.subject);
>>
>> If the message already contains trailers then should we just append the
>> Revert trailer those rather than inserting "\n\n"?
> 
> Umm.. but this \n\n is for separating the subject and the body. I
> think we need it anyway, trailer or not.

Ah you're right, I had forgotten that the revert message body is empty, 
unlike cherry-pick where the message is copied (and that does the right 
thing already when there are existing trailers).

Best wishes

Phillip


>>> @@ -1784,9 +1777,8 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,
>>>                        strbuf_complete_line(&msgbuf);
>>>                        if (!has_conforming_footer(&msgbuf, NULL, 0))
>>>                                strbuf_addch(&msgbuf, '\n');
>>> -                     strbuf_addstr(&msgbuf, cherry_picked_prefix);
>>> -                     strbuf_addstr(&msgbuf, oid_to_hex(&commit->object.oid));
>>> -                     strbuf_addstr(&msgbuf, ")\n");
>>> +                     strbuf_addf(&msgbuf, "Cherry-Pick: %s\n",
>>> +                                 oid_to_hex(&commit->object.oid));
> 
> I will probably make this "Cherry-picked-from:" to match our S-o-b style.
> 


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH/RFC v2] sequencer.c: record revert/cherry-pick commit with trailer lines
  2018-11-04 18:10 ` [PATCH/RFC v2] " Nguyễn Thái Ngọc Duy
@ 2018-11-04 21:30   ` brian m. carlson
  2018-11-05 16:08     ` Duy Nguyen
  2018-11-06 17:16   ` [PATCH/RFC] Support --append-trailer in cherry-pick and revert Nguyễn Thái Ngọc Duy
  1 sibling, 1 reply; 25+ messages in thread
From: brian m. carlson @ 2018-11-04 21:30 UTC (permalink / raw)
  To: Nguyễn Thái Ngọc Duy; +Cc: git, phillip.wood

[-- Attachment #1: Type: text/plain, Size: 1784 bytes --]

On Sun, Nov 04, 2018 at 07:10:26PM +0100, Nguyễn Thái Ngọc Duy wrote:
> When a commit is reverted (or cherry-picked with -x) we add an English
> sentence recording that commit id in the new commit message. Make
> these real trailer lines instead so that they are more friendly to
> parsers (especially "git interpret-trailers").
> 
> A reverted commit will have a new trailer
> 
>     Revert: <commit-id>
> 
> Similarly a cherry-picked commit with -x will have
> 
>     Cherry-picked-from: <commit-id>
> 
> When reverting or cherry picking a merge, the reverted/cherry-picked
> branch will be shown using extended SHA-1 syntax, e.g.
> 
>     Revert: <commit-id>~2
> 
> Since we're not producing the old lines "This reverts commit ..." and
> "(cherry picked from commit .." anymore, scripts that look for these
> lines will need to be updated to handle both. Fresh new history could
> just rely on git-interpret-trailers instead.

Overall, I like the idea of this series.  This is a much cleaner way to
handle things and much better for machine-readability.  I foresee git
cherry potentially learning how to parse this, for example, for cases
where the patch-id doesn't match due to context changes.

However, I do have concerns about breaking compatibility with existing
scripts.  I wonder if we could add a long alias for git cherry-pick -x,
say "--notate" and have "--notate=text" mean "-x" and "--notate=trailer"
mean this new format.  Similarly, git revert could learn such an option
as well.

One final thought: since our trailers seem to act as if we wrote "this
commit" (has been), I wonder if we should say "Reverts" instead of
"Revert" for consistency.
-- 
brian m. carlson: Houston, Texas, US
OpenPGP: https://keybase.io/bk2204

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 868 bytes --]

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH/RFC] sequencer.c: record revert/cherry-pick commit with trailer lines
  2018-11-04  7:22 [PATCH/RFC] sequencer.c: record revert/cherry-pick commit with trailer lines Nguyễn Thái Ngọc Duy
  2018-11-04 16:45 ` Phillip Wood
  2018-11-04 18:10 ` [PATCH/RFC v2] " Nguyễn Thái Ngọc Duy
@ 2018-11-05  0:56 ` Junio C Hamano
  2018-11-05 16:17   ` Duy Nguyen
  2018-11-06  8:57 ` Ævar Arnfjörð Bjarmason
  3 siblings, 1 reply; 25+ messages in thread
From: Junio C Hamano @ 2018-11-05  0:56 UTC (permalink / raw)
  To: Nguyễn Thái Ngọc Duy; +Cc: git

Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:

> A reverted commit will have a new trailer
>
>     Revert: <commit-id>

Please don't, unless you are keeping the current "the effect of
commit X relative to its parent Y was reverted" writtein in prose,
which is meant to be followed up with a manually written "because
..." and adding this as an extra footer that is meant solely for
machine consumption.  Of course reversion of a merge needs to say
relative to which parent of the merge it is undoing.

> Similarly a cherry-picked commit with -x will have
>
>     Cherry-Pick: <commit-id>

Unlike the "revert" change above, this probably is a good change, as
a"(cherry-pickt-from: X)" does not try to convey anything more or
anything less than such a standard looking trailer and it is in
different shape only by historical accident.  But people's scripts
may need to have a long transition period for this change to happen.


>
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> ---
>  I think standardizing how we record commit ids in the commit message
>  is a good idea. Though to be honest this started because of my irk of
>  an English string "cherry picked from..." that cannot be translated.
>  It might as well be a computer language that happens to look like
>  English.
>
>  Documentation/git-cherry-pick.txt |  5 ++---
>  sequencer.c                       | 20 ++++++--------------
>  t/t3510-cherry-pick-sequence.sh   | 12 ++++++------
>  t/t3511-cherry-pick-x.sh          | 26 +++++++++++++-------------
>  4 files changed, 27 insertions(+), 36 deletions(-)
>
> diff --git a/Documentation/git-cherry-pick.txt b/Documentation/git-cherry-pick.txt
> index d35d771fc8..8ffbaed1a0 100644
> --- a/Documentation/git-cherry-pick.txt
> +++ b/Documentation/git-cherry-pick.txt
> @@ -58,9 +58,8 @@ OPTIONS
>  	message prior to committing.
>  
>  -x::
> -	When recording the commit, append a line that says
> -	"(cherry picked from commit ...)" to the original commit
> -	message in order to indicate which commit this change was
> +	When recording the commit, append "Cherry-Pick:" trailer line
> +	recording the commit name which commit this change was
>  	cherry-picked from.  This is done only for cherry
>  	picks without conflicts.  Do not use this option if
>  	you are cherry-picking from your private branch because
> diff --git a/sequencer.c b/sequencer.c
> index 9e1ab3a2a7..f7318f2862 100644
> --- a/sequencer.c
> +++ b/sequencer.c
> @@ -36,7 +36,6 @@
>  #define GIT_REFLOG_ACTION "GIT_REFLOG_ACTION"
>  
>  const char sign_off_header[] = "Signed-off-by: ";
> -static const char cherry_picked_prefix[] = "(cherry picked from commit ";
>  
>  GIT_PATH_FUNC(git_path_commit_editmsg, "COMMIT_EDITMSG")
>  
> @@ -1758,16 +1757,10 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,
>  		base_label = msg.label;
>  		next = parent;
>  		next_label = msg.parent_label;
> -		strbuf_addstr(&msgbuf, "Revert \"");
> -		strbuf_addstr(&msgbuf, msg.subject);
> -		strbuf_addstr(&msgbuf, "\"\n\nThis reverts commit ");
> -		strbuf_addstr(&msgbuf, oid_to_hex(&commit->object.oid));
> -
> -		if (commit->parents && commit->parents->next) {
> -			strbuf_addstr(&msgbuf, ", reversing\nchanges made to ");
> -			strbuf_addstr(&msgbuf, oid_to_hex(&parent->object.oid));
> -		}
> -		strbuf_addstr(&msgbuf, ".\n");
> +		strbuf_addf(&msgbuf, "Revert \"%s\"\n\n", msg.subject);
> +
> +		strbuf_addf(&msgbuf, "Revert: %s\n",
> +			    oid_to_hex(&commit->object.oid));
>  	} else {
>  		const char *p;
>  
> @@ -1784,9 +1777,8 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,
>  			strbuf_complete_line(&msgbuf);
>  			if (!has_conforming_footer(&msgbuf, NULL, 0))
>  				strbuf_addch(&msgbuf, '\n');
> -			strbuf_addstr(&msgbuf, cherry_picked_prefix);
> -			strbuf_addstr(&msgbuf, oid_to_hex(&commit->object.oid));
> -			strbuf_addstr(&msgbuf, ")\n");
> +			strbuf_addf(&msgbuf, "Cherry-Pick: %s\n",
> +				    oid_to_hex(&commit->object.oid));
>  		}
>  		if (!is_fixup(command))
>  			author = get_author(msg.message);
> diff --git a/t/t3510-cherry-pick-sequence.sh b/t/t3510-cherry-pick-sequence.sh
> index c84eeefdc9..89b6e7fc1e 100755
> --- a/t/t3510-cherry-pick-sequence.sh
> +++ b/t/t3510-cherry-pick-sequence.sh
> @@ -390,10 +390,10 @@ test_expect_success '--continue respects opts' '
>  	git cat-file commit HEAD~1 >picked_msg &&
>  	git cat-file commit HEAD~2 >unrelatedpick_msg &&
>  	git cat-file commit HEAD~3 >initial_msg &&
> -	! grep "cherry picked from" initial_msg &&
> -	grep "cherry picked from" unrelatedpick_msg &&
> -	grep "cherry picked from" picked_msg &&
> -	grep "cherry picked from" anotherpick_msg
> +	! grep "Cherry-Pick:" initial_msg &&
> +	grep "Cherry-Pick: " unrelatedpick_msg &&
> +	grep "Cherry-Pick: " picked_msg &&
> +	grep "Cherry-Pick: " anotherpick_msg
>  '
>  
>  test_expect_success '--continue of single-pick respects -x' '
> @@ -404,7 +404,7 @@ test_expect_success '--continue of single-pick respects -x' '
>  	git cherry-pick --continue &&
>  	test_path_is_missing .git/sequencer &&
>  	git cat-file commit HEAD >msg &&
> -	grep "cherry picked from" msg
> +	grep "Cherry-Pick:" msg
>  '
>  
>  test_expect_success '--continue respects -x in first commit in multi-pick' '
> @@ -416,7 +416,7 @@ test_expect_success '--continue respects -x in first commit in multi-pick' '
>  	test_path_is_missing .git/sequencer &&
>  	git cat-file commit HEAD^ >msg &&
>  	picked=$(git rev-parse --verify picked) &&
> -	grep "cherry picked from.*$picked" msg
> +	grep "Cherry-Pick: $picked" msg
>  '
>  
>  test_expect_failure '--signoff is automatically propagated to resolved conflict' '
> diff --git a/t/t3511-cherry-pick-x.sh b/t/t3511-cherry-pick-x.sh
> index 9888bf34b9..db11dd2430 100755
> --- a/t/t3511-cherry-pick-x.sh
> +++ b/t/t3511-cherry-pick-x.sh
> @@ -32,7 +32,7 @@ mesg_with_footer_sob="$mesg_with_footer
>  Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>"
>  
>  mesg_with_cherry_footer="$mesg_with_footer_sob
> -(cherry picked from commit da39a3ee5e6b4b0d3255bfef95601890afd80709)
> +Cherry-Pick: da39a3ee5e6b4b0d3255bfef95601890afd80709
>  Tested-by: C.U. Thor <cuthor@example.com>"
>  
>  mesg_unclean="$mesg_one_line
> @@ -81,7 +81,7 @@ test_expect_success 'cherry-pick -x inserts blank line after one line subject' '
>  	cat <<-EOF >expect &&
>  		$mesg_one_line
>  
> -		(cherry picked from commit $sha1)
> +		Cherry-Pick: $sha1
>  	EOF
>  	git log -1 --pretty=format:%B >actual &&
>  	test_cmp expect actual
> @@ -129,7 +129,7 @@ test_expect_success 'cherry-pick -x inserts blank line when conforming footer no
>  	cat <<-EOF >expect &&
>  		$mesg_no_footer
>  
> -		(cherry picked from commit $sha1)
> +		Cherry-Pick: $sha1
>  	EOF
>  	git log -1 --pretty=format:%B >actual &&
>  	test_cmp expect actual
> @@ -154,7 +154,7 @@ test_expect_success 'cherry-pick -x -s inserts blank line when conforming footer
>  	cat <<-EOF >expect &&
>  		$mesg_no_footer
>  
> -		(cherry picked from commit $sha1)
> +		Cherry-Pick: $sha1
>  		Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
>  	EOF
>  	git log -1 --pretty=format:%B >actual &&
> @@ -178,7 +178,7 @@ test_expect_success 'cherry-pick -x -s adds sob when last sob doesnt match commi
>  	git cherry-pick -x -s mesg-with-footer &&
>  	cat <<-EOF >expect &&
>  		$mesg_with_footer
> -		(cherry picked from commit $sha1)
> +		Cherry-Pick: $sha1
>  		Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
>  	EOF
>  	git log -1 --pretty=format:%B >actual &&
> @@ -201,7 +201,7 @@ test_expect_success 'cherry-pick -x -s adds sob even when trailing sob exists fo
>  	git cherry-pick -x -s mesg-with-footer-sob &&
>  	cat <<-EOF >expect &&
>  		$mesg_with_footer_sob
> -		(cherry picked from commit $sha1)
> +		Cherry-Pick: $sha1
>  		Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
>  	EOF
>  	git log -1 --pretty=format:%B >actual &&
> @@ -215,7 +215,7 @@ test_expect_success 'cherry-pick -x handles commits with no NL at end of message
>  	git cherry-pick -x $sha1 &&
>  	git log -1 --pretty=format:%B >actual &&
>  
> -	printf "\n(cherry picked from commit %s)\n" $sha1 >>msg &&
> +	printf "\nCherry-Pick: %s\n" $sha1 >>msg &&
>  	test_cmp msg actual
>  '
>  
> @@ -226,7 +226,7 @@ test_expect_success 'cherry-pick -x handles commits with no footer and no NL at
>  	git cherry-pick -x $sha1 &&
>  	git log -1 --pretty=format:%B >actual &&
>  
> -	printf "\n\n(cherry picked from commit %s)\n" $sha1 >>msg &&
> +	printf "\n\nCherry-Pick: %s\n" $sha1 >>msg &&
>  	test_cmp msg actual
>  '
>  
> @@ -252,19 +252,19 @@ test_expect_success 'cherry-pick -s handles commits with no footer and no NL at
>  	test_cmp msg actual
>  '
>  
> -test_expect_success 'cherry-pick -x treats "(cherry picked from..." line as part of footer' '
> +test_expect_success 'cherry-pick -x treats "Cherry-Pick:" line as part of footer' '
>  	pristine_detach initial &&
>  	sha1=$(git rev-parse mesg-with-cherry-footer^0) &&
>  	git cherry-pick -x mesg-with-cherry-footer &&
>  	cat <<-EOF >expect &&
>  		$mesg_with_cherry_footer
> -		(cherry picked from commit $sha1)
> +		Cherry-Pick: $sha1
>  	EOF
>  	git log -1 --pretty=format:%B >actual &&
>  	test_cmp expect actual
>  '
>  
> -test_expect_success 'cherry-pick -s treats "(cherry picked from..." line as part of footer' '
> +test_expect_success 'cherry-pick -s treats "Cherry-Pick:" line as part of footer' '
>  	pristine_detach initial &&
>  	git cherry-pick -s mesg-with-cherry-footer &&
>  	cat <<-EOF >expect &&
> @@ -275,13 +275,13 @@ test_expect_success 'cherry-pick -s treats "(cherry picked from..." line as part
>  	test_cmp expect actual
>  '
>  
> -test_expect_success 'cherry-pick -x -s treats "(cherry picked from..." line as part of footer' '
> +test_expect_success 'cherry-pick -x -s treats "Cherry-Pick:..." line as part of footer' '
>  	pristine_detach initial &&
>  	sha1=$(git rev-parse mesg-with-cherry-footer^0) &&
>  	git cherry-pick -x -s mesg-with-cherry-footer &&
>  	cat <<-EOF >expect &&
>  		$mesg_with_cherry_footer
> -		(cherry picked from commit $sha1)
> +		Cherry-Pick: $sha1
>  		Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
>  	EOF
>  	git log -1 --pretty=format:%B >actual &&

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH/RFC v2] sequencer.c: record revert/cherry-pick commit with trailer lines
  2018-11-04 21:30   ` brian m. carlson
@ 2018-11-05 16:08     ` Duy Nguyen
  0 siblings, 0 replies; 25+ messages in thread
From: Duy Nguyen @ 2018-11-05 16:08 UTC (permalink / raw)
  To: brian m. carlson, Git Mailing List, Phillip Wood

On Sun, Nov 4, 2018 at 10:30 PM brian m. carlson
<sandals@crustytoothpaste.net> wrote:
> However, I do have concerns about breaking compatibility with existing
> scripts.  I wonder if we could add a long alias for git cherry-pick -x,
> say "--notate" and have "--notate=text" mean "-x" and "--notate=trailer"
> mean this new format.  Similarly, git revert could learn such an option
> as well.

I don't think it will help unless you are the only developer on some
repo. If you have some scripts parsing the old format, people could
choose to commit using the new format anyway and your scripts will
have to adapt (it's too late to revert because it's already part of
git history).

The transition plan could be outputing both old and new formats at the
same time (optionally allowing to disable the old one) and leave it
like that for a couple releases. Then we could stop producing the old
output and hope that all the scripts in the world have caught up. Not
a great plan.

> One final thought: since our trailers seem to act as if we wrote "this
> commit" (has been), I wonder if we should say "Reverts" instead of
> "Revert" for consistency.

Yeah that or Reverting:, both are better than Revert:. I guess I'll
just go with Reverts: if this patch moves forward.
-- 
Duy

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH/RFC] sequencer.c: record revert/cherry-pick commit with trailer lines
  2018-11-05  0:56 ` [PATCH/RFC] sequencer.c: record revert/cherry-pick commit with trailer lines Junio C Hamano
@ 2018-11-05 16:17   ` Duy Nguyen
  2018-11-06  1:44     ` Junio C Hamano
  0 siblings, 1 reply; 25+ messages in thread
From: Duy Nguyen @ 2018-11-05 16:17 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Git Mailing List

On Mon, Nov 5, 2018 at 1:56 AM Junio C Hamano <gitster@pobox.com> wrote:
>
> Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:
>
> > A reverted commit will have a new trailer
> >
> >     Revert: <commit-id>
>
> Please don't, unless you are keeping the current "the effect of
> commit X relative to its parent Y was reverted" writtein in prose,
> which is meant to be followed up with a manually written "because
> ..." and adding this as an extra footer that is meant solely for
> machine consumption.  Of course reversion of a merge needs to say
> relative to which parent of the merge it is undoing.

I think the intent of writing "This reverts .... " to encourage
writing "because ..." is good, but in practice many people just simply
not do it. And by not describing anything at all (footers don't count)
some commit hook can force people to actually write something.

But for the transition period I think we need to keep both anyway,
whether this "This reverts ..." should stay could be revisited another
day (or not, even).

> > Similarly a cherry-picked commit with -x will have
> >
> >     Cherry-Pick: <commit-id>
>
> Unlike the "revert" change above, this probably is a good change, as
> a"(cherry-pickt-from: X)" does not try to convey anything more or
> anything less than such a standard looking trailer and it is in
> different shape only by historical accident.  But people's scripts
> may need to have a long transition period for this change to happen.

Yep. I'll code something up to print both by default with config knobs
to disable either. Unless you have some better plan of course.
-- 
Duy

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH/RFC] sequencer.c: record revert/cherry-pick commit with trailer lines
  2018-11-04 17:41   ` Duy Nguyen
  2018-11-04 21:12     ` Phillip Wood
@ 2018-11-05 21:57     ` Johannes Schindelin
  1 sibling, 0 replies; 25+ messages in thread
From: Johannes Schindelin @ 2018-11-05 21:57 UTC (permalink / raw)
  To: Duy Nguyen; +Cc: Phillip Wood, Git Mailing List

[-- Attachment #1: Type: text/plain, Size: 3923 bytes --]

Hi,

On Sun, 4 Nov 2018, Duy Nguyen wrote:

> On Sun, Nov 4, 2018 at 5:45 PM Phillip Wood <phillip.wood@talktalk.net> wrote:
> >
> > On 04/11/2018 07:22, Nguyễn Thái Ngọc Duy wrote:
> > > When a commit is reverted (or cherry-picked with -x) we add an English
> > > sentence recording that commit id in the new commit message. Make
> > > these real trailer lines instead so that they are more friendly to
> > > parsers (especially "git interpret-trailers").
> > >
> > > A reverted commit will have a new trailer
> > >
> > >      Revert: <commit-id>
> > >
> > > Similarly a cherry-picked commit with -x will have
> > >
> > >      Cherry-Pick: <commit-id>
> >
> > I think this is a good idea though I wonder if it will break someones
> > script that is looking for the messages generated by -x at the moment.
> 
> It will [1] but I still think it's worth the trouble. The script will
> be less likely to break after, and you can use git-interpret-trailers
> instead of plain grep.

Since this is a wilfull backwards-incompatible patch, it needs to be done
carefully.

I am not enthused by the idea of breaking power users' setups, and I could
imagine that a much better way to do it would be to introduce a config
setting that guards the new behavior, then add a deprecation notice when
-x is used without that config setting, and then let that simmer for a
couple of versions.

Ciao,
Johannes

> 
> [1] https://public-inbox.org/git/20181017143921.GR270328@devbig004.ftw2.facebook.com/
> 
> > > @@ -1758,16 +1757,10 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,
> > >               base_label = msg.label;
> > >               next = parent;
> > >               next_label = msg.parent_label;
> > > -             strbuf_addstr(&msgbuf, "Revert \"");
> > > -             strbuf_addstr(&msgbuf, msg.subject);
> > > -             strbuf_addstr(&msgbuf, "\"\n\nThis reverts commit ");
> > > -             strbuf_addstr(&msgbuf, oid_to_hex(&commit->object.oid));
> > > -
> > > -             if (commit->parents && commit->parents->next) {
> > > -                     strbuf_addstr(&msgbuf, ", reversing\nchanges made to ");
> > > -                     strbuf_addstr(&msgbuf, oid_to_hex(&parent->object.oid));
> > > -             }
> >
> > As revert currently records the parent given on the command line when
> > reverting a merge commit it would probably be a good idea to add that
> > either as a separate trailer or to the Revert: trailer and possibly also
> > generate it for cherry picks.
> 
> My mistake. I didn't read carefully and thought it was logging
> commit->parents, which is pointless.
> 
> So what should be the trailer for this (I don't think putting it in
> Revert: is a good idea, too much to parse)? Revert-parent: ?
> Revert-merge: ?
> 
> > > -             strbuf_addstr(&msgbuf, ".\n");
> > > +             strbuf_addf(&msgbuf, "Revert \"%s\"\n\n", msg.subject);
> >
> > If the message already contains trailers then should we just append the
> > Revert trailer those rather than inserting "\n\n"?
> 
> Umm.. but this \n\n is for separating the subject and the body. I
> think we need it anyway, trailer or not.
> 
> > > @@ -1784,9 +1777,8 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,
> > >                       strbuf_complete_line(&msgbuf);
> > >                       if (!has_conforming_footer(&msgbuf, NULL, 0))
> > >                               strbuf_addch(&msgbuf, '\n');
> > > -                     strbuf_addstr(&msgbuf, cherry_picked_prefix);
> > > -                     strbuf_addstr(&msgbuf, oid_to_hex(&commit->object.oid));
> > > -                     strbuf_addstr(&msgbuf, ")\n");
> > > +                     strbuf_addf(&msgbuf, "Cherry-Pick: %s\n",
> > > +                                 oid_to_hex(&commit->object.oid));
> 
> I will probably make this "Cherry-picked-from:" to match our S-o-b style.
> -- 
> Duy
> 
^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH/RFC] sequencer.c: record revert/cherry-pick commit with trailer lines
  2018-11-05 16:17   ` Duy Nguyen
@ 2018-11-06  1:44     ` Junio C Hamano
  0 siblings, 0 replies; 25+ messages in thread
From: Junio C Hamano @ 2018-11-06  1:44 UTC (permalink / raw)
  To: Duy Nguyen; +Cc: Git Mailing List

Duy Nguyen <pclouds@gmail.com> writes:

> I think the intent of writing "This reverts .... " to encourage
> writing "because ..." is good, but in practice many people just simply
> not do it. And by not describing anything at all (footers don't count)
> some commit hook can force people to actually write something.
>
> But for the transition period I think we need to keep both anyway,

I do not see any need to qualify the statement with "for the
transition period".  You showed *no* need to transition, but
I do agree that adding a fixed-spelled footer in addition to
what we produce in the body is a good idea.

When we know a feature with good intent is not used properly by many
people, the first thing to do is not talk about removing it, but to
think how we can educate people to make good use of it.

And if we know a feature with good intent is not used by many people
but we know that "many" is not "100%", why are we talking about
removing it at all?

> Yep. I'll code something up to print both by default with config knobs
> to disable either. Unless you have some better plan of course.

Does it make sense to put both, with exactly the same piece of
information?  I am not sure whom it would help.

The tools need to be updated to deal with both old and new format if
the pick-origin information is used, instead of getting updated to
learn new and forget old format, as existing commits in their
history do not know about the new format and their tools need to
understand them.

I'd say it would be sufficient to have a per-repository knob that
says which one to use, and between the release we add that knob and
the release we make the new format the default, when we do not see
the knob is set to either way, keep warning that in the future the
default will change and give advice that the knob can be used to
either keep the old format or update to the new format before or
after the default switch (in addition to squelch the warning and the
advice).

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH/RFC] sequencer.c: record revert/cherry-pick commit with trailer lines
  2018-11-04  7:22 [PATCH/RFC] sequencer.c: record revert/cherry-pick commit with trailer lines Nguyễn Thái Ngọc Duy
                   ` (2 preceding siblings ...)
  2018-11-05  0:56 ` [PATCH/RFC] sequencer.c: record revert/cherry-pick commit with trailer lines Junio C Hamano
@ 2018-11-06  8:57 ` Ævar Arnfjörð Bjarmason
  2018-11-06 16:13   ` Duy Nguyen
  3 siblings, 1 reply; 25+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2018-11-06  8:57 UTC (permalink / raw)
  To: Nguyễn Thái Ngọc Duy; +Cc: git


On Sun, Nov 04 2018, Nguyễn Thái Ngọc Duy wrote:

> When a commit is reverted (or cherry-picked with -x) we add an English
> sentence recording that commit id in the new commit message. Make
> these real trailer lines instead so that they are more friendly to
> parsers (especially "git interpret-trailers").
>
> A reverted commit will have a new trailer
>
>     Revert: <commit-id>
>
> Similarly a cherry-picked commit with -x will have
>
>     Cherry-Pick: <commit-id>
> [...]
>  I think standardizing how we record commit ids in the commit message
>  is a good idea. Though to be honest this started because of my irk of
>  an English string "cherry picked from..." that cannot be translated.
>  It might as well be a computer language that happens to look like
>  English.
> [...]
> @@ -1758,16 +1757,10 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,
>  		base_label = msg.label;
>  		next = parent;
>  		next_label = msg.parent_label;
> -		strbuf_addstr(&msgbuf, "Revert \"");
> -		strbuf_addstr(&msgbuf, msg.subject);
> -		strbuf_addstr(&msgbuf, "\"\n\nThis reverts commit ");
> -		strbuf_addstr(&msgbuf, oid_to_hex(&commit->object.oid));
> -
> -		if (commit->parents && commit->parents->next) {
> -			strbuf_addstr(&msgbuf, ", reversing\nchanges made to ");
> -			strbuf_addstr(&msgbuf, oid_to_hex(&parent->object.oid));
> -		}
> -		strbuf_addstr(&msgbuf, ".\n");
> +		strbuf_addf(&msgbuf, "Revert \"%s\"\n\n", msg.subject);
> +
> +		strbuf_addf(&msgbuf, "Revert: %s\n",
> +			    oid_to_hex(&commit->object.oid));
>  	} else {
>  		const char *p;

Others have already commented on the backwards-compatibility /
switchover concerns, so I won't spend much time on that. Except to say
that I don't think changing this would be a big deal.

Anyone trying to parse out /This reverts commit/ or other pre-set
English texts we put into the commit object is already needing to deal
with users changing the message. E.g. I have a habit of doing partial
reverts and changing it to "This partially reverts..." etc.

Leaving aside the question of whether the pain of switching is worth it,
I think it's a worthwihle to consider if we could stop hardcoding one
specific human language in commit messages, and instead leave something
machine-readable behind.

We do that with reverts, and also with merge commits, which could be
given a similar treatment where we change e.g. "Merge branches
'jc/convert', 'jc/bigfile' and 'jc/replacing' into jc/streaming" (to use
git.git's 02071b27f1 as an example) to:

    Merge-branch-1: jc/convert
    Merge-branch-2: jc/bigfile
    Merge-branch-3: jc/replacing
    Merge-branch-into: jc/streaming

Then, when rendering the commit in the UI we could parse that out, and
put a "Merge branches[...]" message at the top, except this time in the
user's own language.

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH/RFC] sequencer.c: record revert/cherry-pick commit with trailer lines
  2018-11-06  8:57 ` Ævar Arnfjörð Bjarmason
@ 2018-11-06 16:13   ` Duy Nguyen
  2018-11-06 17:44     ` Ævar Arnfjörð Bjarmason
  0 siblings, 1 reply; 25+ messages in thread
From: Duy Nguyen @ 2018-11-06 16:13 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason; +Cc: Git Mailing List

On Tue, Nov 6, 2018 at 9:57 AM Ævar Arnfjörð Bjarmason <avarab@gmail.com> wrote:
> Leaving aside the question of whether the pain of switching is worth it,
> I think it's a worthwihle to consider if we could stop hardcoding one
> specific human language in commit messages, and instead leave something
> machine-readable behind.
>
> We do that with reverts, and also with merge commits, which could be
> given a similar treatment where we change e.g. "Merge branches
> 'jc/convert', 'jc/bigfile' and 'jc/replacing' into jc/streaming" (to use
> git.git's 02071b27f1 as an example) to:
>
>     Merge-branch-1: jc/convert
>     Merge-branch-2: jc/bigfile
>     Merge-branch-3: jc/replacing
>     Merge-branch-into: jc/streaming
>
> Then, when rendering the commit in the UI we could parse that out, and
> put a "Merge branches[...]" message at the top, except this time in the
> user's own language.

My first reaction of this was "but branch name is a local thing and
not significant anyway!". But then if people use one branch as a
bundle of other branches like 'pu', then the ability to recreate
branches (with the right name of course) from those merges may be
useful. So... yeah, maybe.
-- 
Duy

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH/RFC] Support --append-trailer in cherry-pick and revert
  2018-11-04 18:10 ` [PATCH/RFC v2] " Nguyễn Thái Ngọc Duy
  2018-11-04 21:30   ` brian m. carlson
@ 2018-11-06 17:16   ` Nguyễn Thái Ngọc Duy
  2018-11-06 17:48     ` Ævar Arnfjörð Bjarmason
  2018-11-07  0:31     ` Junio C Hamano
  1 sibling, 2 replies; 25+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2018-11-06 17:16 UTC (permalink / raw)
  To: pclouds
  Cc: git, phillip.wood, andals, Ævar Arnfjörð,
	Junio C Hamano, Johannes.Schindelin

OK here is a less constroversal attempt to add new trailers. Instead
of changing the default behavior (which could be done incrementally
later), this patch simply adds a new option --append-trailer to revert
and cherry-pick.

Both will show either

    Reverts: <commit>[~<num>]

or

    Cherry-picked-from: <commit>[~<num>]

--append-trailer could be added to more commands (e.g. merge) that
generate commit messages if they have something for machine
consumption.

After this, perhaps we could have a config key to turn this on by
default (for revert; for cherry-pick it will turn off "-x" too). Then
after a couple releases, the we got good reception, we'll make it
default?

No tests, no proper commit message since I think we're still going to
discuss a bit more before settling down.

PS. maybe --append-trailer is too generic? We have --signoff which is
also a trailer. But that one carries more weights than just "machine
generated tags".

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 Documentation/git-cherry-pick.txt |  6 +++++
 Documentation/git-revert.txt      |  6 +++++
 builtin/revert.c                  |  7 ++++++
 sequencer.c                       | 39 +++++++++++++++++++++++++++----
 sequencer.h                       |  1 +
 5 files changed, 55 insertions(+), 4 deletions(-)

diff --git a/Documentation/git-cherry-pick.txt b/Documentation/git-cherry-pick.txt
index d35d771fc8..b5dff29ead 100644
--- a/Documentation/git-cherry-pick.txt
+++ b/Documentation/git-cherry-pick.txt
@@ -102,6 +102,12 @@ effect to your index in a row.
 	Add Signed-off-by line at the end of the commit message.
 	See the signoff option in linkgit:git-commit[1] for more information.
 
+--append-trailer::
+	When recording a commit, append a "Cherry-picked-from:" line
+	with object name of the cherry-picked commit. If a merge is
+	cherry-picked with `-m`, the extended SHA-1 syntax is used
+	to indicate the side of the merge to be cherry-picked.
+
 -S[<keyid>]::
 --gpg-sign[=<keyid>]::
 	GPG-sign commits. The `keyid` argument is optional and
diff --git a/Documentation/git-revert.txt b/Documentation/git-revert.txt
index 837707a8fd..e08010b200 100644
--- a/Documentation/git-revert.txt
+++ b/Documentation/git-revert.txt
@@ -91,6 +91,12 @@ effect to your index in a row.
 	Add Signed-off-by line at the end of the commit message.
 	See the signoff option in linkgit:git-commit[1] for more information.
 
+--append-trailer::
+	When recording a commit, append a "Cherry-picked-from:" line
+	with object name of the cherry-picked commit. If a merge is
+	cherry-picked with `-m`, the extended SHA-1 syntax is used
+	to indicate the side of the merge to be cherry-picked.
+
 --strategy=<strategy>::
 	Use the given merge strategy.  Should only be used once.
 	See the MERGE STRATEGIES section in linkgit:git-merge[1]
diff --git a/builtin/revert.c b/builtin/revert.c
index c93393c89b..3bd8f57b90 100644
--- a/builtin/revert.c
+++ b/builtin/revert.c
@@ -119,6 +119,7 @@ static int run_sequencer(int argc, const char **argv, struct replay_opts *opts)
 	if (opts->action == REPLAY_PICK) {
 		struct option cp_extra[] = {
 			OPT_BOOL('x', NULL, &opts->record_origin, N_("append commit name")),
+			OPT_BOOL(0, "append-trailer", &opts->append_trailer, N_("record cherry picked commit as trailer")),
 			OPT_BOOL(0, "ff", &opts->allow_ff, N_("allow fast-forward")),
 			OPT_BOOL(0, "allow-empty", &opts->allow_empty, N_("preserve initially empty commits")),
 			OPT_BOOL(0, "allow-empty-message", &opts->allow_empty_message, N_("allow commits with empty messages")),
@@ -126,6 +127,12 @@ static int run_sequencer(int argc, const char **argv, struct replay_opts *opts)
 			OPT_END(),
 		};
 		options = parse_options_concat(options, cp_extra);
+	} else if (opts->action == REPLAY_REVERT) {
+		struct option cp_extra[] = {
+			OPT_BOOL(0, "append-trailer", &opts->append_trailer, N_("record reverted commit as trailer")),
+			OPT_END(),
+		};
+		options = parse_options_concat(options, cp_extra);
 	}
 
 	argc = parse_options(argc, argv, NULL, options, usage_str,
diff --git a/sequencer.c b/sequencer.c
index 9e1ab3a2a7..e8fa307109 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -911,7 +911,7 @@ static int run_git_commit(const char *defmsg, struct replay_opts *opts,
 	if ((flags & EDIT_MSG))
 		argv_array_push(&cmd.args, "-e");
 	else if (!(flags & CLEANUP_MSG) &&
-		 !opts->signoff && !opts->record_origin &&
+		 !opts->signoff && !opts->record_origin && !opts->append_trailer &&
 		 git_config_get_value("commit.cleanup", &value))
 		argv_array_push(&cmd.args, "--cleanup=verbatim");
 
@@ -1669,7 +1669,7 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,
 	char *author = NULL;
 	struct commit_message msg = { NULL, NULL, NULL, NULL };
 	struct strbuf msgbuf = STRBUF_INIT;
-	int res, unborn = 0, allow;
+	int res, unborn = 0, allow, parent_id = -1;
 
 	if (opts->no_commit) {
 		/*
@@ -1716,6 +1716,7 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,
 			return error(_("commit %s does not have parent %d"),
 				oid_to_hex(&commit->object.oid), opts->mainline);
 		parent = p->item;
+		parent_id = cnt;
 	} else if (0 < opts->mainline)
 		return error(_("mainline was specified but commit %s is not a merge."),
 			oid_to_hex(&commit->object.oid));
@@ -1768,6 +1769,17 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,
 			strbuf_addstr(&msgbuf, oid_to_hex(&parent->object.oid));
 		}
 		strbuf_addstr(&msgbuf, ".\n");
+
+		if (opts->append_trailer) {
+			strbuf_addstr(&msgbuf, "\n");
+			if (parent_id != -1)
+				strbuf_addf(&msgbuf, "Reverts: %s~%d\n",
+					    oid_to_hex(&commit->object.oid),
+					    parent_id);
+			else
+				strbuf_addf(&msgbuf, "Reverts: %s\n",
+					    oid_to_hex(&commit->object.oid));
+		}
 	} else {
 		const char *p;
 
@@ -1780,14 +1792,28 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,
 		if (find_commit_subject(msg.message, &p))
 			strbuf_addstr(&msgbuf, p);
 
-		if (opts->record_origin) {
+		if (opts->record_origin || opts->append_trailer) {
 			strbuf_complete_line(&msgbuf);
 			if (!has_conforming_footer(&msgbuf, NULL, 0))
 				strbuf_addch(&msgbuf, '\n');
+		}
+
+		if (opts->record_origin) {
 			strbuf_addstr(&msgbuf, cherry_picked_prefix);
 			strbuf_addstr(&msgbuf, oid_to_hex(&commit->object.oid));
 			strbuf_addstr(&msgbuf, ")\n");
 		}
+		if (opts->append_trailer) {
+			if (opts->record_origin)
+				strbuf_addstr(&msgbuf, "\n");
+			if (parent_id != -1)
+				strbuf_addf(&msgbuf, "Cherry-picked-from: %s~%d\n",
+					    oid_to_hex(&commit->object.oid),
+					    parent_id);
+			else
+				strbuf_addf(&msgbuf, "Cherry-picked-from: %s\n",
+					    oid_to_hex(&commit->object.oid));
+		}
 		if (!is_fixup(command))
 			author = get_author(msg.message);
 	}
@@ -2227,6 +2253,8 @@ static int populate_opts_cb(const char *key, const char *value, void *data)
 		opts->signoff = git_config_bool_or_int(key, value, &error_flag);
 	else if (!strcmp(key, "options.record-origin"))
 		opts->record_origin = git_config_bool_or_int(key, value, &error_flag);
+	else if (!strcmp(key, "options.append-trailer"))
+		opts->append_trailer = git_config_bool_or_int(key, value, &error_flag);
 	else if (!strcmp(key, "options.allow-ff"))
 		opts->allow_ff = git_config_bool_or_int(key, value, &error_flag);
 	else if (!strcmp(key, "options.mainline"))
@@ -2618,6 +2646,8 @@ static int save_opts(struct replay_opts *opts)
 		res |= git_config_set_in_file_gently(opts_file, "options.signoff", "true");
 	if (opts->record_origin)
 		res |= git_config_set_in_file_gently(opts_file, "options.record-origin", "true");
+	if (opts->append_trailer)
+		res |= git_config_set_in_file_gently(opts_file, "options.append-trailer", "true");
 	if (opts->allow_ff)
 		res |= git_config_set_in_file_gently(opts_file, "options.allow-ff", "true");
 	if (opts->mainline) {
@@ -3432,7 +3462,8 @@ static int pick_commits(struct todo_list *todo_list, struct replay_opts *opts)
 	setenv(GIT_REFLOG_ACTION, action_name(opts), 0);
 	if (opts->allow_ff)
 		assert(!(opts->signoff || opts->no_commit ||
-				opts->record_origin || opts->edit));
+			 opts->record_origin || opts->append_trailer ||
+			 opts->edit));
 	if (read_and_refresh_cache(opts))
 		return -1;
 
diff --git a/sequencer.h b/sequencer.h
index 660cff5050..7d7c1fe6b4 100644
--- a/sequencer.h
+++ b/sequencer.h
@@ -31,6 +31,7 @@ struct replay_opts {
 	/* Boolean options */
 	int edit;
 	int record_origin;
+	int append_trailer;
 	int no_commit;
 	int signoff;
 	int allow_ff;
-- 
2.19.1.1005.gac84295441


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH/RFC] sequencer.c: record revert/cherry-pick commit with trailer lines
  2018-11-06 16:13   ` Duy Nguyen
@ 2018-11-06 17:44     ` Ævar Arnfjörð Bjarmason
  0 siblings, 0 replies; 25+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2018-11-06 17:44 UTC (permalink / raw)
  To: Duy Nguyen; +Cc: Git Mailing List


On Tue, Nov 06 2018, Duy Nguyen wrote:

> On Tue, Nov 6, 2018 at 9:57 AM Ævar Arnfjörð Bjarmason <avarab@gmail.com> wrote:
>> Leaving aside the question of whether the pain of switching is worth it,
>> I think it's a worthwihle to consider if we could stop hardcoding one
>> specific human language in commit messages, and instead leave something
>> machine-readable behind.
>>
>> We do that with reverts, and also with merge commits, which could be
>> given a similar treatment where we change e.g. "Merge branches
>> 'jc/convert', 'jc/bigfile' and 'jc/replacing' into jc/streaming" (to use
>> git.git's 02071b27f1 as an example) to:
>>
>>     Merge-branch-1: jc/convert
>>     Merge-branch-2: jc/bigfile
>>     Merge-branch-3: jc/replacing
>>     Merge-branch-into: jc/streaming
>>
>> Then, when rendering the commit in the UI we could parse that out, and
>> put a "Merge branches[...]" message at the top, except this time in the
>> user's own language.
>
> My first reaction of this was "but branch name is a local thing and
> not significant anyway!". But then if people use one branch as a
> bundle of other branches like 'pu', then the ability to recreate
> branches (with the right name of course) from those merges may be
> useful. So... yeah, maybe.

Yeah, in theory, in practice no. But all I'm observing is that we're
*already* encoding this information, so to me at least the logical end
game to changes like what you're proposing is something like the above,
otherwise why bother?

But having thought about it a bit more I wonder if
git-interpret-trailers (or some command like it) shouldn't just as a
special-case learn to do more parsing of commit messages we've
historically generated.

E.g. know how to parse out a merge message we've produced and spew out
something like the above Merge-* output. Same for existing "Revert"
output, if anyone cares about parsing this they'll need to do that
anyway.

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH/RFC] Support --append-trailer in cherry-pick and revert
  2018-11-06 17:16   ` [PATCH/RFC] Support --append-trailer in cherry-pick and revert Nguyễn Thái Ngọc Duy
@ 2018-11-06 17:48     ` Ævar Arnfjörð Bjarmason
  2018-11-06 22:11       ` Jeff King
  2018-11-07  0:31     ` Junio C Hamano
  1 sibling, 1 reply; 25+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2018-11-06 17:48 UTC (permalink / raw)
  To: Nguyễn Thái Ngọc Duy
  Cc: git, phillip.wood, andals, Junio C Hamano, Johannes.Schindelin


On Tue, Nov 06 2018, Nguyễn Thái Ngọc Duy wrote:

> OK here is a less constroversal attempt to add new trailers. Instead
> of changing the default behavior (which could be done incrementally
> later), this patch simply adds a new option --append-trailer to revert
> and cherry-pick.
>
> Both will show either
>
>     Reverts: <commit>[~<num>]
>
> or
>
>     Cherry-picked-from: <commit>[~<num>]
>
> --append-trailer could be added to more commands (e.g. merge) that
> generate commit messages if they have something for machine
> consumption.
>
> After this, perhaps we could have a config key to turn this on by
> default (for revert; for cherry-pick it will turn off "-x" too). Then
> after a couple releases, the we got good reception, we'll make it
> default?
>
> No tests, no proper commit message since I think we're still going to
> discuss a bit more before settling down.
>
> PS. maybe --append-trailer is too generic? We have --signoff which is
> also a trailer. But that one carries more weights than just "machine
> generated tags".
>
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>

The implementation looks fine to me, but as noted in
https://public-inbox.org/git/8736se6qyc.fsf@evledraar.gmail.com/ I
wonder what the plausible end-game is. That we'll turn this on by
default in a few years, and then you can only worry about
git-interpret-trailers for repos created as of 2020 or something?

Otherwise it seems we'll need to *also* parse out the existing messages
we've added.

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH/RFC] Support --append-trailer in cherry-pick and revert
  2018-11-06 17:48     ` Ævar Arnfjörð Bjarmason
@ 2018-11-06 22:11       ` Jeff King
  2018-11-06 22:29         ` Jeff King
                           ` (2 more replies)
  0 siblings, 3 replies; 25+ messages in thread
From: Jeff King @ 2018-11-06 22:11 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason
  Cc: Nguyễn Thái Ngọc Duy, git, phillip.wood, andals,
	Junio C Hamano, Johannes.Schindelin

On Tue, Nov 06, 2018 at 06:48:22PM +0100, Ævar Arnfjörð Bjarmason wrote:

> The implementation looks fine to me, but as noted in
> https://public-inbox.org/git/8736se6qyc.fsf@evledraar.gmail.com/ I
> wonder what the plausible end-game is. That we'll turn this on by
> default in a few years, and then you can only worry about
> git-interpret-trailers for repos created as of 2020 or something?
> 
> Otherwise it seems we'll need to *also* parse out the existing messages
> we've added.

Could we help the reading scripts by normalizing old and new output via
interpret-trailers, %(trailers), etc?

I think "(cherry picked from ...)" is already considered a trailer by
the trailer code. If the caller instructs us to, we could probably
rewrite it to:

  Cherry-picked-from: ...

in the output. Then the end-game is that scripts should just use
interpret-trailers, etc, and old and new commits will Just Work.

-Peff

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH/RFC] Support --append-trailer in cherry-pick and revert
  2018-11-06 22:11       ` Jeff King
@ 2018-11-06 22:29         ` Jeff King
  2018-11-07  0:42         ` Junio C Hamano
  2018-11-07 15:30         ` Duy Nguyen
  2 siblings, 0 replies; 25+ messages in thread
From: Jeff King @ 2018-11-06 22:29 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason
  Cc: Nguyễn Thái Ngọc Duy, git, phillip.wood, andals,
	Junio C Hamano, Johannes.Schindelin

On Tue, Nov 06, 2018 at 05:11:18PM -0500, Jeff King wrote:

> On Tue, Nov 06, 2018 at 06:48:22PM +0100, Ævar Arnfjörð Bjarmason wrote:
> 
> > The implementation looks fine to me, but as noted in
> > https://public-inbox.org/git/8736se6qyc.fsf@evledraar.gmail.com/ I
> > wonder what the plausible end-game is. That we'll turn this on by
> > default in a few years, and then you can only worry about
> > git-interpret-trailers for repos created as of 2020 or something?
> > 
> > Otherwise it seems we'll need to *also* parse out the existing messages
> > we've added.
> 
> Could we help the reading scripts by normalizing old and new output via
> interpret-trailers, %(trailers), etc?
> 
> I think "(cherry picked from ...)" is already considered a trailer by
> the trailer code. If the caller instructs us to, we could probably
> rewrite it to:
> 
>   Cherry-picked-from: ...
> 
> in the output. Then the end-game is that scripts should just use
> interpret-trailers, etc, and old and new commits will Just Work.

I.e., something like this:

diff --git a/trailer.c b/trailer.c
index 0796f326b3..491c7c240e 100644
--- a/trailer.c
+++ b/trailer.c
@@ -46,9 +46,11 @@ static int configured;
 
 #define TRAILER_ARG_STRING "$ARG"
 
+#define CHERRY_PICK_PREFIX "(cherry picked from commit "
+
 static const char *git_generated_prefixes[] = {
 	"Signed-off-by: ",
-	"(cherry picked from commit ",
+	CHERRY_PICK_PREFIX,
 	NULL
 };
 
@@ -1141,6 +1143,8 @@ static void format_trailer_info(struct strbuf *out,
 	for (i = 0; i < info->trailer_nr; i++) {
 		char *trailer = info->trailers[i];
 		ssize_t separator_pos = find_separator(trailer, separators);
+		const char *hex;
+		struct object_id oid;
 
 		if (separator_pos >= 1) {
 			struct strbuf tok = STRBUF_INIT;
@@ -1154,6 +1158,12 @@ static void format_trailer_info(struct strbuf *out,
 			strbuf_release(&tok);
 			strbuf_release(&val);
 
+		} else if (/* should check opts->normalize_cherry_pick */1 &&
+			   skip_prefix(trailer, CHERRY_PICK_PREFIX, &hex) &&
+			   !get_oid_hex(hex, &oid)) {
+			strbuf_addf(out, "Cherry-picked-from: %s\n",
+				    oid_to_hex(&oid));
+
 		} else if (!opts->only_trailers) {
 			strbuf_addstr(out, trailer);
 		}

That would need to add the normalize_cherry_pick flag to the options
struct, and then plumb it through. But it's enough to play around with,
and:

  git log --format='%h%n%(trailers:only)'

works.

-Peff

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH/RFC] Support --append-trailer in cherry-pick and revert
  2018-11-06 17:16   ` [PATCH/RFC] Support --append-trailer in cherry-pick and revert Nguyễn Thái Ngọc Duy
  2018-11-06 17:48     ` Ævar Arnfjörð Bjarmason
@ 2018-11-07  0:31     ` Junio C Hamano
  1 sibling, 0 replies; 25+ messages in thread
From: Junio C Hamano @ 2018-11-07  0:31 UTC (permalink / raw)
  To: Nguyễn Thái Ngọc Duy
  Cc: git, phillip.wood, andals, Ævar Arnfjörð,
	Johannes.Schindelin

Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:

> OK here is a less constroversal attempt to add new trailers. Instead
> of changing the default behavior (which could be done incrementally
> later), this patch simply adds a new option --append-trailer to revert
> and cherry-pick.

I almost agree, except that the the textual description in a revert
and the funny-looking trailer-wannabe in a cherry-pick are two
fundamentally different things, and adding duplicate to the latter
does not make much sense, while keeping both does make sense for the
former.

> PS. maybe --append-trailer is too generic? We have --signoff which is
> also a trailer. But that one carries more weights than just "machine
> generated tags".

> +		if (opts->append_trailer) {
> +			strbuf_addstr(&msgbuf, "\n");
> +			if (parent_id != -1)
> +				strbuf_addf(&msgbuf, "Reverts: %s~%d\n",
> +					    oid_to_hex(&commit->object.oid),
> +					    parent_id);
> +			else
> +				strbuf_addf(&msgbuf, "Reverts: %s\n",
> +					    oid_to_hex(&commit->object.oid));
> +		}

Makes sense, I guess.

> @@ -1780,14 +1792,28 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,
>  		if (find_commit_subject(msg.message, &p))
>  			strbuf_addstr(&msgbuf, p);
>  
> -		if (opts->record_origin) {
> +		if (opts->record_origin || opts->append_trailer) {
>  			strbuf_complete_line(&msgbuf);
>  			if (!has_conforming_footer(&msgbuf, NULL, 0))
>  				strbuf_addch(&msgbuf, '\n');
> +		}
> +
> +		if (opts->record_origin) {
>  			strbuf_addstr(&msgbuf, cherry_picked_prefix);
>  			strbuf_addstr(&msgbuf, oid_to_hex(&commit->object.oid));
>  			strbuf_addstr(&msgbuf, ")\n");
>  		}
> +		if (opts->append_trailer) {

These should be either-or, I would think, as adding exactly the same
piece of information in two different machine-readable form does not
make much sense.  The command line parser may even want to make sure
that both are not given at the same time.

Alternatively, we can keep using -x as "we are going to record where
the change was cherry-picked from" and use .record_origin to store
that bit, and use the new .append_trailer bit as "if we are recording
the origin, in which format between the old and the new do we do
so?" bit.

I think the latter makes more sense, at least to me.


> +			if (opts->record_origin)
> +				strbuf_addstr(&msgbuf, "\n");
> +			if (parent_id != -1)
> +				strbuf_addf(&msgbuf, "Cherry-picked-from: %s~%d\n",
> +					    oid_to_hex(&commit->object.oid),
> +					    parent_id);
> +			else
> +				strbuf_addf(&msgbuf, "Cherry-picked-from: %s\n",
> +					    oid_to_hex(&commit->object.oid));
> +		}

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH/RFC] Support --append-trailer in cherry-pick and revert
  2018-11-06 22:11       ` Jeff King
  2018-11-06 22:29         ` Jeff King
@ 2018-11-07  0:42         ` Junio C Hamano
  2018-11-07 15:30         ` Duy Nguyen
  2 siblings, 0 replies; 25+ messages in thread
From: Junio C Hamano @ 2018-11-07  0:42 UTC (permalink / raw)
  To: Jeff King
  Cc: Ævar Arnfjörð Bjarmason,
	Nguyễn Thái Ngọc Duy, git, phillip.wood, andals,
	Johannes.Schindelin

Jeff King <peff@peff.net> writes:

> Could we help the reading scripts by normalizing old and new output via
> interpret-trailers, %(trailers), etc?
>
> I think "(cherry picked from ...)" is already considered a trailer by
> the trailer code.

;-)  

Great minds think alike, I guess.  I think it is a great idea
to ask interpret-trailers to help us here.

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH/RFC] Support --append-trailer in cherry-pick and revert
  2018-11-06 22:11       ` Jeff King
  2018-11-06 22:29         ` Jeff King
  2018-11-07  0:42         ` Junio C Hamano
@ 2018-11-07 15:30         ` Duy Nguyen
  2018-11-07 21:02           ` Jeff King
  2018-11-08  0:36           ` Junio C Hamano
  2 siblings, 2 replies; 25+ messages in thread
From: Duy Nguyen @ 2018-11-07 15:30 UTC (permalink / raw)
  To: Jeff King
  Cc: Ævar Arnfjörð Bjarmason, Git Mailing List,
	Phillip Wood, andals, Junio C Hamano, Johannes Schindelin

On Tue, Nov 6, 2018 at 11:11 PM Jeff King <peff@peff.net> wrote:
>
> On Tue, Nov 06, 2018 at 06:48:22PM +0100, Ævar Arnfjörð Bjarmason wrote:
>
> > The implementation looks fine to me, but as noted in
> > https://public-inbox.org/git/8736se6qyc.fsf@evledraar.gmail.com/ I
> > wonder what the plausible end-game is. That we'll turn this on by
> > default in a few years, and then you can only worry about
> > git-interpret-trailers for repos created as of 2020 or something?
> >
> > Otherwise it seems we'll need to *also* parse out the existing messages
> > we've added.
>
> Could we help the reading scripts by normalizing old and new output via
> interpret-trailers, %(trailers), etc?
>
> I think "(cherry picked from ...)" is already considered a trailer by
> the trailer code. If the caller instructs us to, we could probably
> rewrite it to:
>
>   Cherry-picked-from: ...
>
> in the output. Then the end-game is that scripts should just use
> interpret-trailers, etc, and old and new commits will Just Work.

There is still one thing to settle. "revert -m1" could produce
something like this

    This reverts commit <SHA1>, reversing
    changes made to <SHA2>.

My proposal produces this

    Reverts: <SHA1>^2

And I can't really convert the former to latter without accessing
object database (probably not a good idea?) to check if SHA2 is the
second parent of SHA1. So either

 - I access object database anyway
 - Generate just "Reverts: <SHA1>" (i.e. losing info) with interpret-trailers
 - Change Reverts: tag to a different output format, or maybe use two
tags instead.
-- 
Duy

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH/RFC] Support --append-trailer in cherry-pick and revert
  2018-11-07 15:30         ` Duy Nguyen
@ 2018-11-07 21:02           ` Jeff King
  2018-11-08  0:36           ` Junio C Hamano
  1 sibling, 0 replies; 25+ messages in thread
From: Jeff King @ 2018-11-07 21:02 UTC (permalink / raw)
  To: Duy Nguyen
  Cc: Ævar Arnfjörð Bjarmason, Git Mailing List,
	Phillip Wood, andals, Junio C Hamano, Johannes Schindelin

On Wed, Nov 07, 2018 at 04:30:38PM +0100, Duy Nguyen wrote:

> > Could we help the reading scripts by normalizing old and new output via
> > interpret-trailers, %(trailers), etc?
> >
> > I think "(cherry picked from ...)" is already considered a trailer by
> > the trailer code. If the caller instructs us to, we could probably
> > rewrite it to:
> >
> >   Cherry-picked-from: ...
> >
> > in the output. Then the end-game is that scripts should just use
> > interpret-trailers, etc, and old and new commits will Just Work.
> 
> There is still one thing to settle. "revert -m1" could produce
> something like this
> 
>     This reverts commit <SHA1>, reversing
>     changes made to <SHA2>.
> 
> My proposal produces this
> 
>     Reverts: <SHA1>^2
> 
> And I can't really convert the former to latter without accessing
> object database (probably not a good idea?) to check if SHA2 is the
> second parent of SHA1. So either
> 
>  - I access object database anyway
>  - Generate just "Reverts: <SHA1>" (i.e. losing info) with interpret-trailers
>  - Change Reverts: tag to a different output format, or maybe use two
> tags instead.

IMHO the revert case is way less interesting for automated parsing. In a
workflow like Git's, cherry-picks aren't very common, but there _are_
workflows where there's a lot of cherry-picking between dev/release
branches, and automated analysis is useful there. Whereas for revert,
it's almost always a human-scale thing. A commit was bad, so you revert
it. The annotation is useful if you're digging, but it's not generally
going to be a fundamental part of a workflow. And it's not really any
different than fixing a bug later.

And I think that's reflected in the way we just casually stick the
reverted oid in the human-readable part of the commit message (and the
lack of any tools to parse it).

So IMHO it would be OK to treat this less carefully than the cherry-pick
case.

-Peff

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH/RFC] Support --append-trailer in cherry-pick and revert
  2018-11-07 15:30         ` Duy Nguyen
  2018-11-07 21:02           ` Jeff King
@ 2018-11-08  0:36           ` Junio C Hamano
  2018-11-08  1:29             ` Jeff King
  1 sibling, 1 reply; 25+ messages in thread
From: Junio C Hamano @ 2018-11-08  0:36 UTC (permalink / raw)
  To: Duy Nguyen
  Cc: Jeff King, Ævar Arnfjörð Bjarmason,
	Git Mailing List, Phillip Wood, andals, Johannes Schindelin

Duy Nguyen <pclouds@gmail.com> writes:

> There is still one thing to settle. "revert -m1" could produce
> something like this
>
>     This reverts commit <SHA1>, reversing
>     changes made to <SHA2>.

I do not think it is relevant, with or without multiple parents, to
even attempt to read this message.

The description is not meant to be machine readable/parseable, but
is meant to be updated to describe the reason why the reversion was
made for human readers.  Spending any cycle to attempt interpreting
it by machines will give a wrong signal to encourage people not to
touch it.  Instead we should actively encourage people to take that
as the beginning of their description.

I even suspect that an update to that message to read something like
these

	"This reverts commit <SHA-1> because FILL IN THE REASONS HERE"

	"This reverts commit <SHA-1>, reversing changes made to
	 <SHA-1>, because FILL IN THE REASONS HERE"

would be a good idea.  It of course is orthogonal to the topic of
introducing a new footer to record the "what happened" (without the
"why") in a machine-readable way.


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH/RFC] Support --append-trailer in cherry-pick and revert
  2018-11-08  0:36           ` Junio C Hamano
@ 2018-11-08  1:29             ` Jeff King
  2018-11-08  3:34               ` Junio C Hamano
  0 siblings, 1 reply; 25+ messages in thread
From: Jeff King @ 2018-11-08  1:29 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: Duy Nguyen, Ævar Arnfjörð Bjarmason,
	Git Mailing List, Phillip Wood, andals, Johannes Schindelin

On Thu, Nov 08, 2018 at 09:36:56AM +0900, Junio C Hamano wrote:

> Duy Nguyen <pclouds@gmail.com> writes:
> 
> > There is still one thing to settle. "revert -m1" could produce
> > something like this
> >
> >     This reverts commit <SHA1>, reversing
> >     changes made to <SHA2>.
> 
> I do not think it is relevant, with or without multiple parents, to
> even attempt to read this message.
> 
> The description is not meant to be machine readable/parseable, but
> is meant to be updated to describe the reason why the reversion was
> made for human readers.  Spending any cycle to attempt interpreting
> it by machines will give a wrong signal to encourage people not to
> touch it.  Instead we should actively encourage people to take that
> as the beginning of their description.
> 
> I even suspect that an update to that message to read something like
> these
> 
> 	"This reverts commit <SHA-1> because FILL IN THE REASONS HERE"
> 
> 	"This reverts commit <SHA-1>, reversing changes made to
> 	 <SHA-1>, because FILL IN THE REASONS HERE"

Yeah, that was the point I was trying to make earlier today in this
thread. I really think of this as a human-readable message.

But as far as how this impacts the addition of a trailer: once we have a
machine-readable "Reverts:", people naturally may want to know about
"Reverts" for older commits. Our options are:

  1. say "sorry, there was no machine-readable version back then"

  2. try to parse our "This reverts" message and normalize it into
     "Reverts" for their benefit.

Before introducing the new footer, it's worth thinking about the
end-game here. If we do (1), then people may want to parse themselves.
They are stuck parsing both the old and new (to handle old and new
commits). We could make life a little easier on them if we included
_both_ the English text and the machine-readable version. And then if
they just chose to parse the English, it would work for old and new.

But I guess that is really just a losing battle, if we consider the
English to be changeable. And doing it ourselves in (2) is really just
pushing that losing battle onto ourselves.

So if we are comfortable with saying that this is a new feature to have
the machine-readable trailer version, and there isn't a robust way to
get historical revert information (because there really isn't[1]), then
I think we can just punt on any kind of trailer-normalization magic.

-Peff

[1] Thinking back on reverts I have done, they are often _not_
    straight-up reverts. For example, I may end up dropping half of a
    commit, but leaving some traces of it in place in order to build up
    the correct solution on top (i.e., fixing whatever problem caused me
    to revert in the first place). I list those as "this is morally a
    revert of 1234abcd...", which is definitely not machine readable. ;)

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH/RFC] Support --append-trailer in cherry-pick and revert
  2018-11-08  1:29             ` Jeff King
@ 2018-11-08  3:34               ` Junio C Hamano
  0 siblings, 0 replies; 25+ messages in thread
From: Junio C Hamano @ 2018-11-08  3:34 UTC (permalink / raw)
  To: Jeff King
  Cc: Duy Nguyen, Ævar Arnfjörð Bjarmason,
	Git Mailing List, Phillip Wood, andals, Johannes Schindelin

Jeff King <peff@peff.net> writes:

> So if we are comfortable with saying that this is a new feature to have
> the machine-readable trailer version, and there isn't a robust way to
> get historical revert information (because there really isn't[1]), then
> I think we can just punt on any kind of trailer-normalization magic.

Yes, I do consider that the original suggestion was two-part

 - cherry-pick did have machine readable info, but by historical
   accident, it is shaped differently from "trailers", so we'd
   transition into the new format.

 - revert did not have machine readble info at all, so we are adding
   one, even though it is not that interesting as cherry-pick (for
   the reasons you stated in an earlier message in this thread).

So my "honest answer" is your #1, "sorry, there was no
machine-readable version back then", for reverts.  We do not have
such a problem with cherry-pick luckily ;-)

> [1] Thinking back on reverts I have done, they are often _not_
>     straight-up reverts. For example, I may end up dropping half of a
>     commit, but leaving some traces of it in place in order to build up
>     the correct solution on top (i.e., fixing whatever problem caused me
>     to revert in the first place). I list those as "this is morally a
>     revert of 1234abcd...", which is definitely not machine readable. ;)

Yup, and it is debatable if it even makes sense to add the machine
readable trailer for such a commit.  A human-made claim that it is a
"moral equivalent of reverting X" may not look any different from a
"textual revert of X" to a machine, but the actual patch text would
be quite different---unless the machine reading it understands
"moral equivalence", letting it blindly take on faith whatever
humans say may not be a good idea.

^ permalink raw reply	[flat|nested] 25+ messages in thread

end of thread, back to index

Thread overview: 25+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-04  7:22 [PATCH/RFC] sequencer.c: record revert/cherry-pick commit with trailer lines Nguyễn Thái Ngọc Duy
2018-11-04 16:45 ` Phillip Wood
2018-11-04 17:41   ` Duy Nguyen
2018-11-04 21:12     ` Phillip Wood
2018-11-05 21:57     ` Johannes Schindelin
2018-11-04 18:10 ` [PATCH/RFC v2] " Nguyễn Thái Ngọc Duy
2018-11-04 21:30   ` brian m. carlson
2018-11-05 16:08     ` Duy Nguyen
2018-11-06 17:16   ` [PATCH/RFC] Support --append-trailer in cherry-pick and revert Nguyễn Thái Ngọc Duy
2018-11-06 17:48     ` Ævar Arnfjörð Bjarmason
2018-11-06 22:11       ` Jeff King
2018-11-06 22:29         ` Jeff King
2018-11-07  0:42         ` Junio C Hamano
2018-11-07 15:30         ` Duy Nguyen
2018-11-07 21:02           ` Jeff King
2018-11-08  0:36           ` Junio C Hamano
2018-11-08  1:29             ` Jeff King
2018-11-08  3:34               ` Junio C Hamano
2018-11-07  0:31     ` Junio C Hamano
2018-11-05  0:56 ` [PATCH/RFC] sequencer.c: record revert/cherry-pick commit with trailer lines Junio C Hamano
2018-11-05 16:17   ` Duy Nguyen
2018-11-06  1:44     ` Junio C Hamano
2018-11-06  8:57 ` Ævar Arnfjörð Bjarmason
2018-11-06 16:13   ` Duy Nguyen
2018-11-06 17:44     ` Ævar Arnfjörð Bjarmason

git@vger.kernel.org mailing list mirror (one of many)

Archives are clonable:
	git clone --mirror https://public-inbox.org/git
	git clone --mirror http://ou63pmih66umazou.onion/git
	git clone --mirror http://czquwvybam4bgbro.onion/git
	git clone --mirror http://hjrcffqmbrq6wope.onion/git

Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.version-control.git
	nntp://ou63pmih66umazou.onion/inbox.comp.version-control.git
	nntp://czquwvybam4bgbro.onion/inbox.comp.version-control.git
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.version-control.git
	nntp://news.gmane.org/gmane.comp.version-control.git

 note: .onion URLs require Tor: https://www.torproject.org/
       or Tor2web: https://www.tor2web.org/

AGPL code for this site: git clone https://public-inbox.org/ public-inbox