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

[PATCH 7/7] sequencer: teach parser about CHERRY_PICK_HEAD

From
Ramkumar Ramachandra <artagnon@gmail.com>
Date
Nov 13, 2011, 10:46 UTC
Message-ID
<1321181181-23923-8-git-send-email-artagnon@gmail.com>
In-Reply-To
<1321181181-23923-1-git-send-email-artagnon@gmail.com>

The final step in unifying the sequencer interface involves making sure that a single-commit pick can be concluded with a '--continue'.

  $ git cherry-pick foo
  ... conflict ...
  $ echo "resolved" >problematicfile
  $ git add problematicfile
  $ git sequencer --continue

To do this, we have to update our parser that normally reads '.git/sequencer/todo' to read '.git/CHERRY_PICK_HEAD' as a special case before proceeding as usual. Add a new test in 't3510-sequencer.sh' to make sure that this works. Although we have added a similar test for revert in the same patch for symmetry, the test doesn't depend on this patch to work. A single-commit revert operation does not create a '.git/CHERRY_PICK_HEAD' at all: it uses the information in '.git/sequencer' as usual.

Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
---
 sequencer.c          |   32 ++++++++++++++++++++++++++++----
 t/t3510-sequencer.sh |   44 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 72 insertions(+), 4 deletions(-)
diff --git a/sequencer.c b/sequencer.c
index 7b10b7b..84df926 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -569,12 +569,32 @@ static int parse_insn_buffer(char *buf, struct replay_insn_list **todo_list)
 	return 0;
 }
 
-static void read_populate_todo(struct replay_insn_list **todo_list)
+static void read_populate_todo(struct replay_insn_list **todo_list, int cph_flag)
 {
 	const char *todo_file = git_path(SEQ_TODO_FILE);
 	struct strbuf buf = STRBUF_INIT;
 	int fd, res;
 
+	if (cph_flag) {
+		struct replay_insn_list item = {0, NULL, NULL};
+		const char *name = "CHERRY_PICK_HEAD";
+		const char *CHERRY_PICK_HEAD = git_path(name);
+
+		fd = open(CHERRY_PICK_HEAD, O_RDONLY);
+		if (fd < 0)
+			die_errno(_("Could not open %s."), CHERRY_PICK_HEAD);
+
+		item.action = REPLAY_PICK;
+		item.operand = lookup_commit_reference_by_name(name);
+
+		if (!item.operand)
+			die(_("could not lookup commit %s"), name);
+		replay_insn_list_append(item.action, item.operand, todo_list);
+		close(fd);
+		strbuf_release(&buf);
+		return;
+	}
+
 	fd = open(todo_file, O_RDONLY);
 	if (fd < 0)
 		die_errno(_("Could not open %s."), todo_file);
@@ -792,10 +812,14 @@ int sequencer_pick_revisions(struct replay_opts *opts)
 		remove_sequencer_state(1);
 		return 0;
 	} else if (opts->subcommand == REPLAY_CONTINUE) {
-		if (!file_exists(git_path(SEQ_TODO_FILE)))
-			goto error;
+		if (!file_exists(git_path(SEQ_TODO_FILE))) {
+			if (!file_exists(git_path("CHERRY_PICK_HEAD")))
+				goto error;
+			read_populate_todo(&todo_list, 1);
+		}
+		else
+			read_populate_todo(&todo_list, 0);
 		read_populate_opts(&opts);
-		read_populate_todo(&todo_list);
 
 		if (!index_differs_from("HEAD", 0))
 			todo_list = todo_list->next;
diff --git a/t/t3510-sequencer.sh b/t/t3510-sequencer.sh
index 65f2724..f7c3a37 100755
--- a/t/t3510-sequencer.sh
+++ b/t/t3510-sequencer.sh
@@ -45,6 +45,50 @@ test_expect_success '--continue complains when there are unresolved conflicts' '
 	test_must_fail git sequencer --continue
 '
 
+test_expect_success '--continue continues single-commit cherry-pick' '
+	pristine_detach initial &&
+	test_must_fail git cherry-pick anotherpick &&
+	echo "c" >foo &&
+	git add foo &&
+	git sequencer --continue &&
+	test_path_is_missing .git/sequencer &&
+	{
+		git rev-list HEAD |
+		git diff-tree --root --stdin |
+		sed "s/$_x40/OBJID/g"
+	} >actual &&
+	cat >expect <<-\EOF &&
+	OBJID
+	:100644 100644 OBJID OBJID M	foo
+	OBJID
+	:000000 100644 OBJID OBJID A	foo
+	:000000 100644 OBJID OBJID A	unrelated
+	EOF
+	test_cmp expect actual
+'
+
+test_expect_success '--continue continues single-commit revert' '
+	pristine_detach initial &&
+	test_must_fail git revert anotherpick &&
+	echo "c" >foo &&
+	git add foo &&
+	git sequencer --continue &&
+	test_path_is_missing .git/sequencer &&
+	{
+		git rev-list HEAD |
+		git diff-tree --root --stdin |
+		sed "s/$_x40/OBJID/g"
+	} >actual &&
+	cat >expect <<-\EOF &&
+	OBJID
+	:100644 100644 OBJID OBJID M	foo
+	OBJID
+	:000000 100644 OBJID OBJID A	foo
+	:000000 100644 OBJID OBJID A	unrelated
+	EOF
+	test_cmp expect actual
+'
+
 test_expect_success '--continue continues after conflicts are resolved' '
 	pristine_detach initial &&
 	test_must_fail git cherry-pick base..anotherpick &&
-- 
1.7.6.351.gb35ac.dirty
Previous: Ramkumar RamachandraNext: Junio C Hamano
Message 12 of 17 in “New sequencer workflow!”
  1. 0/7 New sequencer workflow!Ramkumar Ramachandra, Nov 13, 2011
  2. 1/7 sequencer: factor code out of revert builtinRamkumar Ramachandra, Nov 13, 2011
  3. 2/7 sequencer: invalidate sequencer state without todoRamkumar Ramachandra, Nov 13, 2011
  4. 3/7 sequencer: handle single-commit pick as special caseRamkumar Ramachandra, Nov 13, 2011
  5. Junio C HamanoNov 13, 2011
  6. Ramkumar RamachandraNov 15, 2011
  7. Junio C HamanoNov 15, 2011
  8. Ramkumar RamachandraNov 16, 2011
  9. 4/7 sequencer: handle cherry-pick conflict in last commitRamkumar Ramachandra, Nov 13, 2011
  10. 5/7 sequencer: introduce git-sequencer builtinRamkumar Ramachandra, Nov 13, 2011
  11. 6/7 sequencer: teach '--continue' how to commitRamkumar Ramachandra, Nov 13, 2011
  12. 7/7 sequencer: teach parser about CHERRY_PICK_HEADRamkumar Ramachandra, Nov 13, 2011
  13. Junio C HamanoNov 13, 2011
  14. Junio C HamanoNov 14, 2011
  15. Ramkumar RamachandraNov 15, 2011
  16. Phil HordNov 15, 2011
  17. Ramkumar RamachandraNov 15, 2011

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.