From: Ramkumar Ramachandra <artagnon@gmail.com>
To: Git List <git@vger.kernel.org>
Cc: Junio C Hamano <gitster@pobox.com>,
Jonathan Nieder <jrnieder@gmail.com>,
Christian Couder <chriscool@tuxfamily.org>
Subject: [PATCH 7/7] sequencer: teach parser about CHERRY_PICK_HEAD
Date: Sun, 13 Nov 2011 16:16:21 +0530 [thread overview]
Message-ID: <1321181181-23923-8-git-send-email-artagnon@gmail.com> (raw)
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
next prev parent reply other threads:[~2011-11-13 10:48 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-11-13 10:46 [PATCH 0/7] New sequencer workflow! Ramkumar Ramachandra
2011-11-13 10:46 ` [PATCH 1/7] sequencer: factor code out of revert builtin Ramkumar Ramachandra
2011-11-13 10:46 ` [PATCH 2/7] sequencer: invalidate sequencer state without todo Ramkumar Ramachandra
2011-11-13 10:46 ` [PATCH 3/7] sequencer: handle single-commit pick as special case Ramkumar Ramachandra
2011-11-13 23:23 ` Junio C Hamano
2011-11-15 8:47 ` Ramkumar Ramachandra
2011-11-15 21:58 ` Junio C Hamano
2011-11-16 6:30 ` Ramkumar Ramachandra
2011-11-13 10:46 ` [PATCH 4/7] sequencer: handle cherry-pick conflict in last commit Ramkumar Ramachandra
2011-11-13 10:46 ` [PATCH 5/7] sequencer: introduce git-sequencer builtin Ramkumar Ramachandra
2011-11-13 10:46 ` [PATCH 6/7] sequencer: teach '--continue' how to commit Ramkumar Ramachandra
2011-11-13 10:46 ` Ramkumar Ramachandra [this message]
2011-11-13 20:56 ` [PATCH 0/7] New sequencer workflow! Junio C Hamano
2011-11-14 0:04 ` Junio C Hamano
2011-11-15 8:33 ` Ramkumar Ramachandra
2011-11-15 15:46 ` Phil Hord
2011-11-15 16:12 ` Ramkumar Ramachandra
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1321181181-23923-8-git-send-email-artagnon@gmail.com \
--to=artagnon@gmail.com \
--cc=chriscool@tuxfamily.org \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jrnieder@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).