git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] merge & sequencer: turn "Conflicts:" hint into a comment

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 24, 2014, 21:24 UTC
Message-ID
<xmqqr3xxf9ey.fsf_-_@gitster.dls.corp.google.com>
In-Reply-To
<xmqqvbn9f9ig.fsf@gitster.dls.corp.google.com>

Just like other hints such as "Change to be committed" we show in the editor to remind the committer what paths were involved in the resulting commit to improve their log message, this section is merely a reminder. Traditionally, it was not made into comments primarily because it has to be generated outside wt-status infrastructure, and secondary it was meant as a bit stronger reminder than the rest (i.e. explaining how you resolved conflicts is much more important than mentioning what you did to every paths involved in the commit), but that still does not make this hint a hint, which should be commented out by default.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 builtin/commit.c                | 42 ++++++++++++++++++++---------------------
 sequencer.c                     |  7 +++----
 t/t3507-cherry-pick-conflict.sh | 22 +++++++++++++--------
 3 files changed, 38 insertions(+), 33 deletions(-)
diff --git a/builtin/commit.c b/builtin/commit.c
index fedb45a..3a1d1a8 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -719,30 +719,30 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
 		stripspace(&sb, 0);
 
 	if (signoff) {
-		/*
-		 * See if we have a Conflicts: block at the end. If yes, count
-		 * its size, so we can ignore it.
-		 */
-		int ignore_footer = 0;
-		int i, eol, previous = 0;
-		const char *nl;
-
-		for (i = 0; i < sb.len; i++) {
-			nl = memchr(sb.buf + i, '\n', sb.len - i);
-			if (nl)
-				eol = nl - sb.buf;
+		/* Ignore comments and blanks after the trailer */
+		int boc = 0;
+		int bol = 0;
+
+		while (bol < sb.len) {
+			char *next_line;
+
+			if (!(next_line = memchr(sb.buf + bol, '\n', sb.len - bol)))
+				next_line = sb.buf + sb.len;
 			else
-				eol = sb.len;
-			if (!prefixcmp(sb.buf + previous, "\nConflicts:\n")) {
-				ignore_footer = sb.len - previous;
-				break;
+				next_line++;
+
+			if (sb.buf[bol] == comment_line_char || sb.buf[bol] == '\n') {
+				/* is this the first of the run of comments? */
+				if (!boc)
+					boc = bol;
+				/* otherwise, it is just continuing */
+			} else if (boc) {
+				/* the previous was not trailing comment */
+				boc = 0;
 			}
-			while (i < eol)
-				i++;
-			previous = eol;
+			bol = next_line - sb.buf;
 		}
-
-		append_signoff(&sb, ignore_footer, 0);
+		append_signoff(&sb, boc ? sb.len - boc : 0, 0);
 	}
 
 	if (fwrite(sb.buf, 1, sb.len, s->fp) < sb.len)
diff --git a/sequencer.c b/sequencer.c
index 0f84bbe..1d97da3 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -291,13 +291,12 @@ void append_conflicts_hint(struct strbuf *msgbuf)
 {
 	int i;
 
-	strbuf_addstr(msgbuf, "\nConflicts:\n");
+	strbuf_addch(msgbuf, '\n');
+	strbuf_commented_addf(msgbuf, "Conflicts:\n");
 	for (i = 0; i < active_nr;) {
 		const struct cache_entry *ce = active_cache[i++];
 		if (ce_stage(ce)) {
-			strbuf_addch(msgbuf, '\t');
-			strbuf_addstr(msgbuf, ce->name);
-			strbuf_addch(msgbuf, '\n');
+			strbuf_commented_addf(msgbuf, "\t%s\n", ce->name);
 			while (i < active_nr && !strcmp(ce->name,
 							active_cache[i]->name))
 				i++;
diff --git a/t/t3507-cherry-pick-conflict.sh b/t/t3507-cherry-pick-conflict.sh
index 223b984..fa04226 100755
--- a/t/t3507-cherry-pick-conflict.sh
+++ b/t/t3507-cherry-pick-conflict.sh
@@ -351,18 +351,24 @@ test_expect_success 'commit after failed cherry-pick does not add duplicated -s'
 test_expect_success 'commit after failed cherry-pick adds -s at the right place' '
 	pristine_detach initial &&
 	test_must_fail git cherry-pick picked &&
+
 	git commit -a -s &&
-	pwd &&
-	cat <<EOF > expected &&
-picked
 
-Signed-off-by: C O Mitter <committer@example.com>
+	# Do S-o-b and Conflicts appear in the right order?
+	cat <<-\EOF >expect &&
+	Signed-off-by: C O Mitter <committer@example.com>
+	# Conflicts:
+	EOF
+	grep -e "^# Conflicts:" -e '^Signed-off-by' <.git/COMMIT_EDITMSG >actual &&
+	test_cmp expect actual &&
+
+	cat <<-\EOF >expected &&
+	picked
 
-Conflicts:
-	foo
-EOF
+	Signed-off-by: C O Mitter <committer@example.com>
+	EOF
 
-	git show -s --pretty=format:%B > actual &&
+	git show -s --pretty=format:%B >actual &&
 	test_cmp expected actual
 '
 
-- 
2.1.2-595-g1568c45
Previous: Junio C HamanoNext: Jeff King
Message 4 of 11 in “builtin/merge.c: drop a parameter that is never used”
  1. builtin/merge.c: drop a parameter that is never usedJunio C Hamano, Oct 24, 2014
  2. Jonathan NiederOct 24, 2014
  3. merge & sequencer: unify codepaths that write "Conflicts:" hintJunio C Hamano, Oct 24, 2014
  4. merge & sequencer: turn "Conflicts:" hint into a commentJunio C Hamano, Oct 24, 2014
  5. Jeff KingOct 26, 2014
  6. Junio C HamanoOct 27, 2014
  7. Junio C HamanoOct 27, 2014
  8. Jeff KingOct 28, 2014
  9. Christian CouderOct 28, 2014
  10. Jonathan NiederOct 27, 2014
  11. Jeff KingOct 28, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.