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

[PATCH 2/3] rebase -i --keep-empty: don't prune empty commits

From
PWPhillip Wood <phillip.wood@talktalk.net>
Date
Mar 20, 2018, 10:03 UTC
Message-ID
<20180320100315.15261-3-phillip.wood@talktalk.net>
In-Reply-To
<20180320100315.15261-1-phillip.wood@talktalk.net>
From: Phillip Wood <phillip.wood@dunelm.org.uk>

If there are empty commits on the left hand side of $upstream...HEAD then the empty commits on the right hand side that we want to keep are pruned by --cherry-pick. Fix this by using --cherry-mark instead of --cherry-pick and keeping the commits that are empty or are not marked as cherry-picks.

Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
---
 sequencer.c                       | 18 +++++++++++-------
 t/t3421-rebase-topology-linear.sh |  2 +-
 2 files changed, 12 insertions(+), 8 deletions(-)
diff --git a/sequencer.c b/sequencer.c
index 4d3f60594c..96ff812c8d 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -2470,7 +2470,7 @@ int sequencer_make_script(FILE *out, int argc, const char **argv,
 	init_revisions(&revs, NULL);
 	revs.verbose_header = 1;
 	revs.max_parents = 1;
-	revs.cherry_pick = 1;
+	revs.cherry_mark = 1;
 	revs.limited = 1;
 	revs.reverse = 1;
 	revs.right_only = 1;
@@ -2495,14 +2495,18 @@ int sequencer_make_script(FILE *out, int argc, const char **argv,
 		return error(_("make_script: error preparing revisions"));
 
 	while ((commit = get_revision(&revs))) {
+		int is_empty  = is_original_commit_empty(commit);
+
 		strbuf_reset(&buf);
-		if (!keep_empty && is_original_commit_empty(commit))
+		if (!keep_empty && is_empty)
 			strbuf_addf(&buf, "%c ", comment_line_char);
-		strbuf_addf(&buf, "%s %s ", insn,
-			    oid_to_hex(&commit->object.oid));
-		pretty_print_commit(&pp, commit, &buf);
-		strbuf_addch(&buf, '\n');
-		fputs(buf.buf, out);
+		if (is_empty || !(commit->object.flags & PATCHSAME)) {
+			strbuf_addf(&buf, "%s %s ", insn,
+				    oid_to_hex(&commit->object.oid));
+			pretty_print_commit(&pp, commit, &buf);
+			strbuf_addch(&buf, '\n');
+			fputs(buf.buf, out);
+		}
 	}
 	strbuf_release(&buf);
 	return 0;
diff --git a/t/t3421-rebase-topology-linear.sh b/t/t3421-rebase-topology-linear.sh
index 68fe2003ef..52fc6885e5 100755
--- a/t/t3421-rebase-topology-linear.sh
+++ b/t/t3421-rebase-topology-linear.sh
@@ -215,7 +215,7 @@ test_run_rebase () {
 }
 test_run_rebase success ''
 test_run_rebase failure -m
-test_run_rebase failure -i
+test_run_rebase success -i
 test_run_rebase failure -p
 
 #       m
-- 
2.16.2
Previous: Phillip WoodNext: Johannes Schindelin
Message 3 of 10 in “rebase --keep-empty/--root fixes”
  1. 0/3 rebase --keep-empty/--root fixesPhillip Wood, Mar 20, 2018
  2. 3/3 rebase: respect --no-keep-emptyPhillip Wood, Mar 20, 2018
  3. 2/3 rebase -i --keep-empty: don't prune empty commitsPhillip Wood, Mar 20, 2018
  4. Johannes SchindelinMar 20, 2018
  5. Junio C HamanoMar 20, 2018
  6. Phillip WoodMar 20, 2018
  7. Johannes SchindelinMar 21, 2018
  8. Junio C HamanoMar 29, 2018
  9. 1/3 rebase --root: stop assuming squash_onto is unsetPhillip Wood, Mar 20, 2018
  10. Johannes SchindelinMar 20, 2018

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.