Skip to contentSkip to conversation

sequencer: remove use of comment character

PATCH Superseded Tony Tung via GitGitGadget 5 participants 18 messages Oct 30, 2023 – Nov 1, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sequencer: remove use of comment character

From: Tony Tung <[email protected]>

Instead of using the hardcoded # , use the
user-defined comment_line_char. Adds a test
to prevent regressions.

---
sequencer: remove use of hardcoded comment char

Instead of using the hardcoded # , use the user-defined comment_line_char. Adds a test to prevent regressions.

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1603%2Fttung%2Fttung%2Fcommentchar-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1603/ttung/ttung/commentchar-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/1603

 sequencer.c                   |  5 +++--
 t/t3404-rebase-interactive.sh | 39 +++++++++++++++++++++++++++++++++++
 2 files changed, 42 insertions(+), 2 deletions(-)
sequencer.c +3 -2
index d584cac8ed9..8c6666d5e43 100644
@@ -6082,8 +6082,9 @@ static int add_decorations_to_list(const struct commit *commit,
 		/* If the branch is checked out, then leave a comment instead. */
 		if ((path = branch_checked_out(decoration->name))) {
 			item->command = TODO_COMMENT;
-			strbuf_addf(ctx->buf, "# Ref %s checked out at '%s'\n",
-				    decoration->name, path);
+			strbuf_commented_addf(ctx->buf, comment_line_char,
+					      "Ref %s checked out at '%s'\n",
+					      decoration->name, path);
 		} else {
 			struct string_list_item *sti;
 			item->command = TODO_UPDATE_REF;
t/t3404-rebase-interactive.sh +39 -0
index 8ea2bf13026..076dca87871 100755
@@ -1839,6 +1839,45 @@ test_expect_success '--update-refs adds label and update-ref commands' '
 	)
 '
 
+test_expect_success '--update-refs works with core.commentChar' '
+	git checkout -b update-refs-with-commentchar no-conflict-branch &&
+	test_config core.commentChar : &&
+	git branch -f base HEAD~4 &&
+	git branch -f first HEAD~3 &&
+	git branch -f second HEAD~3 &&
+	git branch -f third HEAD~1 &&
+	git commit --allow-empty --fixup=third &&
+	git branch -f is-not-reordered &&
+	git commit --allow-empty --fixup=HEAD~4 &&
+	git branch -f shared-tip &&
+	git checkout update-refs &&
+	(
+		write_script fake-editor.sh <<-\EOF &&
+		grep "^[^:]" "$1"
+		exit 1
+		EOF
+		test_set_editor "$(pwd)/fake-editor.sh" &&
+
+		cat >expect <<-EOF &&
+		pick $(git log -1 --format=%h J) J
+		fixup $(git log -1 --format=%h update-refs) fixup! J : empty
+		update-ref refs/heads/second
+		update-ref refs/heads/first
+		pick $(git log -1 --format=%h K) K
+		pick $(git log -1 --format=%h L) L
+		fixup $(git log -1 --format=%h is-not-reordered) fixup! L : empty
+		update-ref refs/heads/third
+		pick $(git log -1 --format=%h M) M
+		update-ref refs/heads/no-conflict-branch
+		update-ref refs/heads/is-not-reordered
+		update-ref refs/heads/update-refs-with-commentchar
+		EOF
+
+		test_must_fail git rebase -i --autosquash --update-refs primary shared-tip >todo &&
+		test_cmp expect todo
+	)
+'
+
 test_expect_success '--update-refs adds commands with --rebase-merges' '
 	git checkout -b update-refs-with-merge no-conflict-branch &&
 	git branch -f base HEAD~4 &&

base-commit: 2e8e77cbac8ac17f94eee2087187fa1718e38b14

Signature · 1 line
gitgitgadget
#1 lore raw
Quoted 5 lines · Tony Tung via GitGitGadget

From: Tony Tung <[email protected]>

Instead of using the hardcoded # , use the
user-defined comment_line_char. Adds a test
to prevent regressions.

Good spotting.

Two observations.

(1) There are a few more places that need similar treatment in the same file; you may want to fix them all while at it.

(2) The second argument to strbuf_commented_addf() is always the comment_line_char global variable, not just inside this file but all callers across the codebase. We probably should drop it and have the strbuf_commented_addf() helper itself refer to the global. That way, if we ever want to change the global variable reference to something else (e.g. function call), we only have to touch a single place.

The latter is meant as #leftoverbits and will be a lot wider clean-up that we may want to do long after this patch hits out codebase. The "other places" I spotted for the former are the following, but needs to be taken with a huge grain of salt, as it has not even been compile tested.

Thanks.

 sequencer.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
sequencer.c +4 -4
index d584cac8ed..33208b1660 100644
@@ -1893,8 +1893,8 @@ static void update_squash_message_for_fixup(struct strbuf *msg)
 	size_t orig_msg_len;
 	int i = 1;
 
-	strbuf_addf(&buf1, "# %s\n", _(first_commit_msg_str));
-	strbuf_addf(&buf2, "# %s\n", _(skip_first_commit_msg_str));
+	strbuf_addf(&buf1, comment_line_char, "%s\n", _(first_commit_msg_str));
+	strbuf_addf(&buf2, comment_line_char, "%s\n", _(skip_first_commit_msg_str));
 	s = start = orig_msg = strbuf_detach(msg, &orig_msg_len);
 	while (s) {
 		const char *next;
@@ -2269,8 +2269,8 @@ static int do_pick_commit(struct repository *r,
 		next = parent;
 		next_label = msg.parent_label;
 		if (opts->commit_use_reference) {
-			strbuf_addstr(&msgbuf,
-				"# *** SAY WHY WE ARE REVERTING ON THE TITLE LINE ***");
+			strbuf_commented_addf(&msgbuf, comment_line_char, "%s",
+				"*** SAY WHY WE ARE REVERTING ON THE TITLE LINE ***");
 		} else if (skip_prefix(msg.subject, "Revert \"", &orig_subject) &&
 			   /*
 			    * We don't touch pre-existing repeated reverts, because
#2 lore raw
Quoted 52 lines · Junio C Hamano
Quoted 5 lines · Tony Tung via GitGitGadget

From: Tony Tung <[email protected]>

Instead of using the hardcoded # , use the
user-defined comment_line_char. Adds a test
to prevent regressions.

Good spotting.

Two observations.

(1) There are a few more places that need similar treatment in the same file; you may want to fix them all while at it.

(2) The second argument to strbuf_commented_addf() is always the comment_line_char global variable, not just inside this file but all callers across the codebase. We probably should drop it and have the strbuf_commented_addf() helper itself refer to the global. That way, if we ever want to change the global variable reference to something else (e.g. function call), we only have to touch a single place.

The latter is meant as #leftoverbits and will be a lot wider clean-up that we may want to do long after this patch hits out codebase. The "other places" I spotted for the former are the following, but needs to be taken with a huge grain of salt, as it has not even been compile tested.

Thanks.

 sequencer.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
sequencer.c +2 -2
index d584cac8ed..33208b1660 100644
@@ -1893,8 +1893,8 @@ static void update_squash_message_for_fixup(struct strbuf *msg)
        size_t orig_msg_len;
        int i = 1;
 
-       strbuf_addf(&buf1, "# %s\n", _(first_commit_msg_str));
-       strbuf_addf(&buf2, "# %s\n", _(skip_first_commit_msg_str));
+       strbuf_addf(&buf1, comment_line_char, "%s\n", _(first_commit_msg_str));
+       strbuf_addf(&buf2, comment_line_char, "%s\n", _(skip_first_commit_msg_str));
        s = start = orig_msg = strbuf_detach(msg, &orig_msg_len);
        while (s) {
                const char *next;

sequencer.c static int do_pick_commit(struct repository *r, · line 2276

Quoted 10 lines
sequencer.c +2 -2
@@ -2269,8 +2269,8 @@ static int do_pick_commit(struct repository *r,
                next = parent;
                next_label = msg.parent_label;
                if (opts->commit_use_reference) {
-                       strbuf_addstr(&msgbuf,
-                               "# *** SAY WHY WE ARE REVERTING ON THE TITLE LINE ***");
+                       strbuf_commented_addf(&msgbuf, comment_line_char, "%s",
+                               "*** SAY WHY WE ARE REVERTING ON THE TITLE LINE ***");
                } else if (skip_prefix(msg.subject, "Revert \"", &orig_subject) &&
                           /*
                            * We don't touch pre-existing repeated reverts, because

I thought the point of the comment_line_char was so that commit messages could have lines starting with '#'. That rationale doesn't apply to the TODO list generation or parsing, and I'm not sure if we want to add the same complexity there. If we do want to add the same complexity there, I'm worried that making these changes are insufficent; there are some other hardcoded '#' references in the code (as a quick greps for '".*#' and "'#'" will turn up). Since those other references include parsing as well as generation, I think we might actually be introducing bugs in the TODO list handling if we only partially convert it, but someone would need to double check.

#3 lore raw
Quoted 4 lines · Elijah Newren

I thought the point of the comment_line_char was so that commit messages could have lines starting with '#'. That rationale doesn't apply to the TODO list generation or parsing, and I'm not sure if we want to add the same complexity there.

Thanks for a healthy dose of sanity. I noticed existing use of comment_line_char everywhere in sequencer.c and assumed we would want to be consistent, but you are right to point out that they are all about the COMMIT_EDITMSG kind of thing, and not about what appears in "sequencer/todo".

#4 lore raw
Quoted 10 lines · Junio C Hamano
Quoted 4 lines · Elijah Newren

I thought the point of the comment_line_char was so that commit messages could have lines starting with '#'. That rationale doesn't apply to the TODO list generation or parsing, and I'm not sure if we want to add the same complexity there.

Quoted 5 lines

Thanks for a healthy dose of sanity. I noticed existing use of comment_line_char everywhere in sequencer.c and assumed we would want to be consistent, but you are right to point out that they are all about the COMMIT_EDITMSG kind of thing, and not about what appears in "sequencer/todo”.

I believe comment_line_char is being applied when the sequencer reads back the instructions, which is why I ran into this problem to begin with.

If the intent is not to apply it to the sequencer, then the bugfix is in the wrong place.

Thanks

#5 lore raw
In reply to Junio C Hamano
Quoted 10 lines · Junio C Hamano
Quoted 4 lines · Elijah Newren

I thought the point of the comment_line_char was so that commit messages could have lines starting with '#'. That rationale doesn't apply to the TODO list generation or parsing, and I'm not sure if we want to add the same complexity there.

Quoted 5 lines

Thanks for a healthy dose of sanity. I noticed existing use of comment_line_char everywhere in sequencer.c and assumed we would want to be consistent, but you are right to point out that they are all about the COMMIT_EDITMSG kind of thing, and not about what appears in "sequencer/todo”.

Actually, I withdraw my previous comment. comment_line_char is all over sequencer.c, and there are tests that say, "rebase -i respects core.commentchar”, which strongly implies that the *intent* is that rebase -i respects comment_line_char.

I would propose that we move forward with this, except perhaps removing more instances of comment_line_char.

Thanks.

#8 lore raw

v2 cover sequencer: remove use of hardcoded comment char

In reply to Tony Tung via GitGitGadget

Instead of using the hardcoded # , use the user-defined comment_line_char. Adds a test to prevent regressions.

Tony Tung (2):
sequencer: remove use of comment character
sequencer: fix remaining hardcoded comment char

 sequencer.c                   | 21 +++++++++++++------
 t/t3404-rebase-interactive.sh | 39 +++++++++++++++++++++++++++++++++++
 2 files changed, 54 insertions(+), 6 deletions(-)

base-commit: 2e8e77cbac8ac17f94eee2087187fa1718e38b14
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1603%2Fttung%2Fttung%2Fcommentchar-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1603/ttung/ttung/commentchar-v2
Pull-Request: https://github.com/gitgitgadget/git/pull/1603

Range-diff vs v1:

 1:  10598a56d64 = 1:  10598a56d64 sequencer: remove use of comment character
 -:  ----------- > 2:  c9f4ff34dbd sequencer: fix remaining hardcoded comment char
Signature · 1 line
gitgitgadget
#9 lore raw

PATCH v2 1/2 sequencer: remove use of comment character

From: Tony Tung <[email protected]>

Instead of using the hardcoded # , use the
user-defined comment_line_char. Adds a test
to prevent regressions.

---
 sequencer.c                   |  5 +++--
 t/t3404-rebase-interactive.sh | 39 +++++++++++++++++++++++++++++++++++
 2 files changed, 42 insertions(+), 2 deletions(-)
sequencer.c +3 -2
index d584cac8ed9..8c6666d5e43 100644
@@ -6082,8 +6082,9 @@ static int add_decorations_to_list(const struct commit *commit,
 		/* If the branch is checked out, then leave a comment instead. */
 		if ((path = branch_checked_out(decoration->name))) {
 			item->command = TODO_COMMENT;
-			strbuf_addf(ctx->buf, "# Ref %s checked out at '%s'\n",
-				    decoration->name, path);
+			strbuf_commented_addf(ctx->buf, comment_line_char,
+					      "Ref %s checked out at '%s'\n",
+					      decoration->name, path);
 		} else {
 			struct string_list_item *sti;
 			item->command = TODO_UPDATE_REF;
t/t3404-rebase-interactive.sh +39 -0
index 8ea2bf13026..076dca87871 100755
@@ -1839,6 +1839,45 @@ test_expect_success '--update-refs adds label and update-ref commands' '
 	)
 '
 
+test_expect_success '--update-refs works with core.commentChar' '
+	git checkout -b update-refs-with-commentchar no-conflict-branch &&
+	test_config core.commentChar : &&
+	git branch -f base HEAD~4 &&
+	git branch -f first HEAD~3 &&
+	git branch -f second HEAD~3 &&
+	git branch -f third HEAD~1 &&
+	git commit --allow-empty --fixup=third &&
+	git branch -f is-not-reordered &&
+	git commit --allow-empty --fixup=HEAD~4 &&
+	git branch -f shared-tip &&
+	git checkout update-refs &&
+	(
+		write_script fake-editor.sh <<-\EOF &&
+		grep "^[^:]" "$1"
+		exit 1
+		EOF
+		test_set_editor "$(pwd)/fake-editor.sh" &&
+
+		cat >expect <<-EOF &&
+		pick $(git log -1 --format=%h J) J
+		fixup $(git log -1 --format=%h update-refs) fixup! J : empty
+		update-ref refs/heads/second
+		update-ref refs/heads/first
+		pick $(git log -1 --format=%h K) K
+		pick $(git log -1 --format=%h L) L
+		fixup $(git log -1 --format=%h is-not-reordered) fixup! L : empty
+		update-ref refs/heads/third
+		pick $(git log -1 --format=%h M) M
+		update-ref refs/heads/no-conflict-branch
+		update-ref refs/heads/is-not-reordered
+		update-ref refs/heads/update-refs-with-commentchar
+		EOF
+
+		test_must_fail git rebase -i --autosquash --update-refs primary shared-tip >todo &&
+		test_cmp expect todo
+	)
+'
+
 test_expect_success '--update-refs adds commands with --rebase-merges' '
 	git checkout -b update-refs-with-merge no-conflict-branch &&
 	git branch -f base HEAD~4 &&
Signature · 1 line
gitgitgadget
#12 lore raw

PATCH v2 2/2 sequencer: fix remaining hardcoded comment char

In reply to Tony Tung via GitGitGadget

From: Tony Tung <[email protected]>

---
 sequencer.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)
sequencer.c +13 -5
index 8c6666d5e43..bbadc3fb710 100644
@@ -1893,8 +1893,14 @@ static void update_squash_message_for_fixup(struct strbuf *msg)
 	size_t orig_msg_len;
 	int i = 1;
 
-	strbuf_addf(&buf1, "# %s\n", _(first_commit_msg_str));
-	strbuf_addf(&buf2, "# %s\n", _(skip_first_commit_msg_str));
+	strbuf_commented_addf(&buf1,
+			      comment_line_char,
+			      "%s\n",
+			      _(first_commit_msg_str));
+	strbuf_commented_addf(&buf2,
+			      comment_line_char,
+			      "%s\n",
+			      _(skip_first_commit_msg_str));
 	s = start = orig_msg = strbuf_detach(msg, &orig_msg_len);
 	while (s) {
 		const char *next;
@@ -2269,8 +2275,9 @@ static int do_pick_commit(struct repository *r,
 		next = parent;
 		next_label = msg.parent_label;
 		if (opts->commit_use_reference) {
-			strbuf_addstr(&msgbuf,
-				"# *** SAY WHY WE ARE REVERTING ON THE TITLE LINE ***");
+			strbuf_commented_addf(&msgbuf,
+					      "%s",
+					      "*** SAY WHY WE ARE REVERTING ON THE TITLE LINE ***");
 		} else if (skip_prefix(msg.subject, "Revert \"", &orig_subject) &&
 			   /*
 			    * We don't touch pre-existing repeated reverts, because
@@ -6082,7 +6089,8 @@ static int add_decorations_to_list(const struct commit *commit,
 		/* If the branch is checked out, then leave a comment instead. */
 		if ((path = branch_checked_out(decoration->name))) {
 			item->command = TODO_COMMENT;
-			strbuf_commented_addf(ctx->buf, comment_line_char,
+			strbuf_commented_addf(ctx->buf,
+					      comment_line_char,
 					      "Ref %s checked out at '%s'\n",
 					      decoration->name, path);
 		} else {
Signature · 1 line
gitgitgadget
#6 lore raw
In reply to Junio C Hamano
Quoted 6 lines · Junio C Hamano
Quoted 4 lines · Elijah Newren

I thought the point of the comment_line_char was so that commit messages could have lines starting with '#'. That rationale doesn't apply to the TODO list generation or parsing, and I'm not sure if we want to add the same complexity there.

Earlier I said

Quoted 5 lines

Thanks for a healthy dose of sanity. I noticed existing use of comment_line_char everywhere in sequencer.c and assumed we would want to be consistent, but you are right to point out that they are all about the COMMIT_EDITMSG kind of thing, and not about what appears in "sequencer/todo".

but with something as simple as

    $ git -c core.commentchar='@' rebase -i master seen^2

I can see that the references to comment_line_char in sequencer.c are about the commented lines after the list of insn in the generated sequencer/todo file, so even though the rationale does not apply, isn't this already "broken" in the current code anyway?

Thanks.

#7 lore raw
Quoted 18 lines · Junio C Hamano
Quoted 6 lines · Junio C Hamano
Quoted 4 lines · Elijah Newren

I thought the point of the comment_line_char was so that commit messages could have lines starting with '#'. That rationale doesn't apply to the TODO list generation or parsing, and I'm not sure if we want to add the same complexity there.

Earlier I said

Quoted 5 lines

Thanks for a healthy dose of sanity. I noticed existing use of comment_line_char everywhere in sequencer.c and assumed we would want to be consistent, but you are right to point out that they are all about the COMMIT_EDITMSG kind of thing, and not about what appears in "sequencer/todo".

Quoted 8 lines

but with something as simple as

    $ git -c core.commentchar='@' rebase -i master seen^2

I can see that the references to comment_line_char in sequencer.c are about the commented lines after the list of insn in the generated sequencer/todo file, so even though the rationale does not apply, isn't this already "broken" in the current code anyway?

Yes, I believe it is. However, I remember specifically looking at cases with --rebase-merges about a year and a half ago, and noted that there was a mixture of hardcoded '#' references along with comment_line_char. I noted at the time that changing comment_line_char looked like it had a bug, and that the parsing in particular would be fooled and do wrong things if it changed. Unfortunately, I can't find any notes from the time with the details, so I don't remember exactly what or how it was triggered.

However, I do suspect that the references to comment_line_char in the rebase -i codepaths was not for any actual intended purpose, but just noting that they were used elsewhere in the file (for COMMIT_EDITMSG, where it made sense) and just mimicking that code without realizing the lack of rationale. That would have been mere wasted effort had the comment_line_char been consistently supported in the TODO file editing and parsing, but it wasn't, which left TODO editing & parsing somewhat broken.

I think supporting comment_line_char for the TODO file provides no value, and I think the easier fix would be undoing the uses of comment_line_char relative to the TODO file (perhaps also leaving in-code comments to the effect that comment_line_char just doesn't apply to the TODO file).

However, if someone prefers to make the TODO file also respect comment_line_char, despite its dubious value, then I expect any patch should
1) audit *every* reference found via git grep -e '".*#' -e "'#'" sequencer.c
2) add a test case (or cases) involving --rebase-merges -i that
trigger the relevant code paths
If they don't do that, then I fear we might make the bug more likely to be triggered rather than less.

#14 lore raw

Re: [PATCH v2 0/2] sequencer: remove use of hardcoded comment char

In reply to Tony Tung via GitGitGadget

Hi,

Quoted 7 lines · Tony Tung via GitGitGadget

Instead of using the hardcoded # , use the user-defined comment_line_char. Adds a test to prevent regressions.

Tony Tung (2):
sequencer: remove use of comment character
sequencer: fix remaining hardcoded comment char

The second commit message seems to suggest that the two commits should just be squashed; there's no explicit or even implicit reason provided for why the two small patches are logically independent. After reading them carefully, and digging through the particular changes being made and what part of the code they touch, I think I can guess at a potential reason, but I feel like I'm crossing into the territory of mind reading trying to articulate that reason. (Besides, my rationale would argue that the two patches should be split differently.) Perhaps a comment could be added, to either the second commit message or the cover letter, to explain that better?

More importantly, though, I think the second commit message is actually wrong. Before and after applying this series:

$ git grep -c -e '".*#' -e "'#'" -- sequencer.c
sequencer.c:16
$ b4 am c9f4ff34dbdb7ba221e4203bb6551b80948dc71d.1698728953.git.gitgitgadget@gmail.com
$ git am ./v2_20231031_gitgitgadget_sequencer_remove_use_of_hardcoded_comment_char.mbx
$ git grep -c -e '".*#' -e "'#'" -- sequencer.c
sequencer.c:12

Granted, four of those lines are code comments, but that still leaves 8 hard coded references to '#' in the code at the end (i.e. the majority are still left), meaning your second patch doesn't do what its subject line claims.

And, most important of all is still the first patch. As I stated elsewhere in this thread (at CABPp-BFY7m_g+sT131_Ubxqo5FsHGKOPMng7=90_0-+xCS9NEQ@mail.gmail.com):

"""
I think supporting comment_line_char for the TODO file provides no value, and I think the easier fix would be undoing the uses of comment_line_char relative to the TODO file (perhaps also leaving in-code comments to the effect that comment_line_char just doesn't apply to the TODO file).

However, if someone prefers to make the TODO file also respect comment_line_char, despite its dubious value, then I expect any patch should
1) audit *every* reference found via git grep -e '".*#' -e "'#'" sequencer.c
2) add a test case (or cases) involving --rebase-merges -i that
trigger the relevant code paths
If they don't do that, then I fear we might make the bug more likely to be triggered rather than less.
"""

Personally, I would rather not accept patches changing the handling of the TODO script relative to comment_line_char until the above is done, and I worry that half measures _might_ end up being more hurtful than helpful.

I feel quite differently about patches that make COMMIT_EDITMSG handling use comment_line_char more consistently since that code simply writes the file without re-parsing it; although fixing everything would be best, even fixing some of them to use comment_line_char would be welcome. I think the first two hunks of your second patch happen to fall into this category, so if those were split out, then I'd say those are good partial solutions.

#15 lore raw

Re: [PATCH v2 0/2] sequencer: remove use of hardcoded comment char

Hi Elijah

Quoted 26 lines · Elijah Newren

Hi,

Quoted 7 lines · Tony Tung via GitGitGadget

Instead of using the hardcoded # , use the user-defined comment_line_char. Adds a test to prevent regressions.

Tony Tung (2):
sequencer: remove use of comment character
sequencer: fix remaining hardcoded comment char

The second commit message seems to suggest that the two commits should just be squashed; there's no explicit or even implicit reason provided for why the two small patches are logically independent. After reading them carefully, and digging through the particular changes being made and what part of the code they touch, I think I can guess at a potential reason, but I feel like I'm crossing into the territory of mind reading trying to articulate that reason. (Besides, my rationale would argue that the two patches should be split differently.) Perhaps a comment could be added, to either the second commit message or the cover letter, to explain that better?

More importantly, though, I think the second commit message is actually wrong. Before and after applying this series:

Quoted 8 lines
$ git grep -c -e '".*#' -e "'#'" -- sequencer.c
sequencer.c:16
$ b4 am c9f4ff34dbdb7ba221e4203bb6551b80948dc71d.1698728953.git.gitgitgadget@gmail.com
$ git am ./v2_20231031_gitgitgadget_sequencer_remove_use_of_hardcoded_comment_char.mbx
$ git grep -c -e '".*#' -e "'#'" -- sequencer.c
sequencer.c:12

As far as I can see those remaining instances are all to do with the '#' that separates a merge subject line from its parents. I don't think we need to complicate things anymore by respecting core.commentchar there as the '#' is not denoting a commented line, it is being used as an intra-line separator instead.

Quoted 9 lines

Granted, four of those lines are code comments, but that still leaves 8 hard coded references to '#' in the code at the end (i.e. the majority are still left), meaning your second patch doesn't do what its subject line claims.

And, most important of all is still the first patch. As I stated elsewhere in this thread (at CABPp-BFY7m_g+sT131_Ubxqo5FsHGKOPMng7=90_0-+xCS9NEQ@mail.gmail.com):

Quoted 6 lines

"""
I think supporting comment_line_char for the TODO file provides no value, and I think the easier fix would be undoing the uses of comment_line_char relative to the TODO file (perhaps also leaving in-code comments to the effect that comment_line_char just doesn't apply to the TODO file).

I agree that I don't see much point in respecting core.commentchar in the TODO file as unlike a commit message a legitimate non-commented line will never begin with '#'. Unfortunately I think we're committed to respecting it - see 180bad3d10f (rebase -i: respect core.commentchar, 2013-02-11)

Quoted 7 lines

[...] I feel quite differently about patches that make COMMIT_EDITMSG handling use comment_line_char more consistently since that code simply writes the file without re-parsing it; although fixing everything would be best, even fixing some of them to use comment_line_char would be welcome. I think the first two hunks of your second patch happen to fall into this category, so if those were split out, then I'd say those are good partial solutions.

I think splitting the changes so that we have one patch that fixes the TODO file generation and another that fixes the commit message generation for fixup commands would be best.

Best Wishes

Phillip

#13 lore raw

Re: [PATCH v2 2/2] sequencer: fix remaining hardcoded comment char

In reply to Tony Tung via GitGitGadget

Hi Tony

Thanks for working on this. When you're submitting patches please try testing them locally and check the CI before doing '/submit'. In this case all the jobs that try to compile git are failing - see https://github.com/gitgitgadget/git/actions/runs/6702301267/job/18211090139?pr=1603#step:4:260 for example.

Quoted 12 lines · Tony Tung via GitGitGadget

From: Tony Tung <[email protected]>

---
  sequencer.c | 18 +++++++++++++-----
  1 file changed, 13 insertions(+), 5 deletions(-)
sequencer.c +0 -0
index 8c6666d5e43..bbadc3fb710 100644

sequencer.c static void update_squash_message_for_fixup(struct strbuf *msg) · line 1899

Quoted 9 lines
sequencer.c +4 -2
@@ -1893,8 +1893,14 @@ static void update_squash_message_for_fixup(struct strbuf *msg)
  	size_t orig_msg_len;
  	int i = 1;
 
-	strbuf_addf(&buf1, "# %s\n", _(first_commit_msg_str));
-	strbuf_addf(&buf2, "# %s\n", _(skip_first_commit_msg_str));
+	strbuf_commented_addf(&buf1,
+			      comment_line_char,
+			      "%s\n",
+			      _(first_commit_msg_str));

This is what is causing the compilation the fail. It should be

	strbuf_commented_addf(&buf1, "%c $s\n", comment_char_line,
			      _(first_commit_msg_str));

sequencer.c static void update_squash_message_for_fixup(struct strbuf *msg) · line 1903

Quoted 4 lines
sequencer.c +4 -0
+	strbuf_commented_addf(&buf2,
+			      comment_line_char,
+			      "%s\n",
+			      _(skip_first_commit_msg_str));

This needs changing in the same way.

It would be nice to add a test for this. I think we can do that by adding

test_config core.commentchar :

To the beginning of the test '--skip after failed fixup cleans commit message' in t3418-rebase-continue.sh and changing the expected message so that it uses ':' instead of '#' for the comments.

Quoted 16 lines
sequencer.c +3 -2
  	s = start = orig_msg = strbuf_detach(msg, &orig_msg_len);
  	while (s) {
  		const char *next;
@@ -2269,8 +2275,9 @@ static int do_pick_commit(struct repository *r,
  		next = parent;
  		next_label = msg.parent_label;
  		if (opts->commit_use_reference) {
-			strbuf_addstr(&msgbuf,
-				"# *** SAY WHY WE ARE REVERTING ON THE TITLE LINE ***");
+			strbuf_commented_addf(&msgbuf,
+					      "%s",
+					      "*** SAY WHY WE ARE REVERTING ON THE TITLE LINE ***");
  		} else if (skip_prefix(msg.subject, "Revert \"", &orig_subject) &&
  			   /*
  			    * We don't touch pre-existing repeated reverts, because

sequencer.c static int add_decorations_to_list(const struct commit *commit, · line 6095

Quoted 8 lines
sequencer.c +2 -1
@@ -6082,7 +6089,8 @@ static int add_decorations_to_list(const struct commit *commit,
  		/* If the branch is checked out, then leave a comment instead. */
  		if ((path = branch_checked_out(decoration->name))) {
  			item->command = TODO_COMMENT;
-			strbuf_commented_addf(ctx->buf, comment_line_char,
+			strbuf_commented_addf(ctx->buf,
+					      comment_line_char,
  					      "Ref %s checked out at '%s'\n",
  					      decoration->name, path);

This hunk is unnecessary - it is just changing the code you added in the first patch.

Best Wishes

Phillip

#10 lore raw
In reply to Tony Tung via GitGitGadget

Hi Tony

Quoted 5 lines · Tony Tung via GitGitGadget

From: Tony Tung <[email protected]>

Instead of using the hardcoded # , use the
user-defined comment_line_char. Adds a test
to prevent regressions.

Well spotted and thanks for fixing this. Normally we wrap the commit message at ~72 chars.

Quoted 27 lines
---
  sequencer.c                   |  5 +++--
  t/t3404-rebase-interactive.sh | 39 +++++++++++++++++++++++++++++++++++
  2 files changed, 42 insertions(+), 2 deletions(-)
sequencer.c +3 -2
index d584cac8ed9..8c6666d5e43 100644
@@ -6082,8 +6082,9 @@ static int add_decorations_to_list(const struct commit *commit,
  		/* If the branch is checked out, then leave a comment instead. */
  		if ((path = branch_checked_out(decoration->name))) {
  			item->command = TODO_COMMENT;
-			strbuf_addf(ctx->buf, "# Ref %s checked out at '%s'\n",
-				    decoration->name, path);
+			strbuf_commented_addf(ctx->buf, comment_line_char,
+					      "Ref %s checked out at '%s'\n",
+					      decoration->name, path);
  		} else {
  			struct string_list_item *sti;
  			item->command = TODO_UPDATE_REF;
t/t3404-rebase-interactive.sh +0 -0
index 8ea2bf13026..076dca87871 100755

t/t3404-rebase-interactive.sh test_expect_success '--update-refs adds label and update-ref commands' ' · line 1840

Quoted 2 lines
t/t3404-rebase-interactive.sh +0 -0
@@ -1839,6 +1839,45 @@ test_expect_success '--update-refs adds label and update-ref commands' '
  	)
  '

Thank you for taking the time to add a test. I think it could be simplified though as all we really need to do is check that the expected comment is present in the todo list. Something like (untested)

test_expect_success '--update-refs works with core.commentChar' '

	git worktree add new-branch &&
	test_when_finished "git worktree remove new-branch" &&
	test_config core.commentchar : &&
	write_script fake-editor.sh <<-\EOF &&
	grep "^: Ref refs/heads/new-branch checked out at .*new-branch" "$1" &&
	# no need to rebase
	>"$1"
	EOF
	(
		test_set_editor "$(pwd)/fake-editor.sh" &&
		git rebase -i --update-refs HEAD^
	)

'

Best Wishes

Phillip

Quoted 42 lines
t/t3404-rebase-interactive.sh +39 -0
+test_expect_success '--update-refs works with core.commentChar' '
+	git checkout -b update-refs-with-commentchar no-conflict-branch &&
+	test_config core.commentChar : &&
+	git branch -f base HEAD~4 &&
+	git branch -f first HEAD~3 &&
+	git branch -f second HEAD~3 &&
+	git branch -f third HEAD~1 &&
+	git commit --allow-empty --fixup=third &&
+	git branch -f is-not-reordered &&
+	git commit --allow-empty --fixup=HEAD~4 &&
+	git branch -f shared-tip &&
+	git checkout update-refs &&
+	(
+		write_script fake-editor.sh <<-\EOF &&
+		grep "^[^:]" "$1"
+		exit 1
+		EOF
+		test_set_editor "$(pwd)/fake-editor.sh" &&
+
+		cat >expect <<-EOF &&
+		pick $(git log -1 --format=%h J) J
+		fixup $(git log -1 --format=%h update-refs) fixup! J : empty
+		update-ref refs/heads/second
+		update-ref refs/heads/first
+		pick $(git log -1 --format=%h K) K
+		pick $(git log -1 --format=%h L) L
+		fixup $(git log -1 --format=%h is-not-reordered) fixup! L : empty
+		update-ref refs/heads/third
+		pick $(git log -1 --format=%h M) M
+		update-ref refs/heads/no-conflict-branch
+		update-ref refs/heads/is-not-reordered
+		update-ref refs/heads/update-refs-with-commentchar
+		EOF
+
+		test_must_fail git rebase -i --autosquash --update-refs primary shared-tip >todo &&
+		test_cmp expect todo
+	)
+'
+
  test_expect_success '--update-refs adds commands with --rebase-merges' '
  	git checkout -b update-refs-with-merge no-conflict-branch &&
  	git branch -f base HEAD~4 &&
#16 lore raw

Re: [PATCH v2 0/2] sequencer: remove use of hardcoded comment char

In reply to Phillip Wood
Quoted 5 lines · Phillip Wood

As far as I can see those remaining instances are all to do with the '#' that separates a merge subject line from its parents. I don't think we need to complicate things anymore by respecting core.commentchar there as the '#' is not denoting a commented line, it is being used as an intra-line separator instead.

It is unfortunate that the format of the file needs an intra-line separator in the first place, but I tend to agree with you that the comment-line-char would be a terrible fit there. '#' or any replacement character at the beginning of a line is easy to spot as a signal that the line in its entirety is commented out, but it is much harder to eyeball-spot a single punctuation character in the middle of a line. If we do not have to look for a different character depending on the comment-line-char setting, it would make the system (slightly) easier to use.

Quoted 5 lines

I agree that I don't see much point in respecting core.commentchar in the TODO file as unlike a commit message a legitimate non-commented line will never begin with '#'. Unfortunately I think we're committed to respecting it - see 180bad3d10f (rebase -i: respect core.commentchar, 2013-02-11)

Yeah, the ship has long sailed.

Quoted 3 lines

I think splitting the changes so that we have one patch that fixes the TODO file generation and another that fixes the commit message generation for fixup commands would be best.

Yes, it would be great.

Thanks.

#17 lore raw

Re: [PATCH v2 0/2] sequencer: remove use of hardcoded comment char

In reply to Phillip Wood
Quoted 36 lines · Phillip Wood

Hi Elijah

Quoted 32 lines · Elijah Newren

Hi,

Quoted 7 lines · Tony Tung via GitGitGadget

Instead of using the hardcoded # , use the user-defined comment_line_char. Adds a test to prevent regressions.

Tony Tung (2):
sequencer: remove use of comment character
sequencer: fix remaining hardcoded comment char

The second commit message seems to suggest that the two commits should just be squashed; there's no explicit or even implicit reason provided for why the two small patches are logically independent. After reading them carefully, and digging through the particular changes being made and what part of the code they touch, I think I can guess at a potential reason, but I feel like I'm crossing into the territory of mind reading trying to articulate that reason. (Besides, my rationale would argue that the two patches should be split differently.) Perhaps a comment could be added, to either the second commit message or the cover letter, to explain that better?

More importantly, though, I think the second commit message is actually wrong. Before and after applying this series:

$ git grep -c -e '".*#' -e "'#'" -- sequencer.c
sequencer.c:16
$ b4 am c9f4ff34dbdb7ba221e4203bb6551b80948dc71d.1698728953.git.gitgitgadget@gmail.com
$ git am ./v2_20231031_gitgitgadget_sequencer_remove_use_of_hardcoded_comment_char.mbx
Quoted 8 lines
Quoted 2 lines
$ git grep -c -e '".*#' -e "'#'" -- sequencer.c
sequencer.c:12

As far as I can see those remaining instances are all to do with the '#' that separates a merge subject line from its parents. I don't think we need to complicate things anymore by respecting core.commentchar there as the '#' is not denoting a commented line, it is being used as an intra-line separator instead.

Ah, that might be jogging my memory slightly. I had a patch to put a comment before the one-line commit summaries in the TODO list
(https://github.com/git/git/commit/f1ae608477e010b96557d6fc87eed9f3f39b905e).
I think I at some point noticed comment_line_char, and went to switch to it, probably also switching the mid-line comment char for merges, and then noticed the potential for breakage due to the manual parsing of those.

Anyway, I trust your analysis, but I believe some of that analysis belongs in the relevant commit messages if we push forward with these changes.

Quoted 16 lines
Quoted 9 lines

Granted, four of those lines are code comments, but that still leaves 8 hard coded references to '#' in the code at the end (i.e. the majority are still left), meaning your second patch doesn't do what its subject line claims.

And, most important of all is still the first patch. As I stated elsewhere in this thread (at CABPp-BFY7m_g+sT131_Ubxqo5FsHGKOPMng7=90_0-+xCS9NEQ@mail.gmail.com):

Quoted 6 lines

"""
I think supporting comment_line_char for the TODO file provides no value, and I think the easier fix would be undoing the uses of comment_line_char relative to the TODO file (perhaps also leaving in-code comments to the effect that comment_line_char just doesn't apply to the TODO file).

Quoted 5 lines

I agree that I don't see much point in respecting core.commentchar in the TODO file as unlike a commit message a legitimate non-commented line will never begin with '#'. Unfortunately I think we're committed to respecting it - see 180bad3d10f (rebase -i: respect core.commentchar, 2013-02-11)

Thanks for digging up the old commit and the explicit mention of the TODO file. Kind of disappointing. While I can't imagine anything that would actually break by reverting this, it's not worth it at this point.

Quoted 9 lines
Quoted 8 lines

[...]
I feel quite differently about patches that make COMMIT_EDITMSG handling use comment_line_char more consistently since that code simply writes the file without re-parsing it; although fixing everything would be best, even fixing some of them to use comment_line_char would be welcome. I think the first two hunks of your second patch happen to fall into this category, so if those were split out, then I'd say those are good partial solutions.

Quoted 3 lines

I think splitting the changes so that we have one patch that fixes the TODO file generation and another that fixes the commit message generation for fixup commands would be best.

That would seem more logical to me.

#11 lore raw
In reply to Tony Tung via GitGitGadget
Quoted 1 line · Tony Tung via GitGitGadget

Subject: Re: [PATCH v2 1/2] sequencer: remove use of comment character

The patch does not seem to be doing that, though. It may have removed '#' in "# Ref", but still uses comment_line_char, so it does not remove use at all (and we do not want to, of course).

"use the core.commentchar consistently"

Quoted 5 lines

From: Tony Tung <[email protected]>

Instead of using the hardcoded # , use the
user-defined comment_line_char. Adds a test
to prevent regressions.

Overly short lines.

The readers cannot tell where in the output the hardcoded # appears with the above description. I am guessing that it is in comments in the sequencer/todo file that mark commits that are at the tip of branches that are checked out, but there may be more specific circumstances in which the comment is used, like "when rebase -i is used with the --update-refs option", if so that also need to be told to the readers.

Describe the condition well enough so that readers can easily see the defect the patch attempts to fix.

sequencer.c static int add_decorations_to_list(const struct commit *commit, · line 6087

Quoted 5 lines
sequencer.c +3 -2
-			strbuf_addf(ctx->buf, "# Ref %s checked out at '%s'\n",
-				    decoration->name, path);
+			strbuf_commented_addf(ctx->buf, comment_line_char,
+					      "Ref %s checked out at '%s'\n",
+					      decoration->name, path);

OK.