summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin von Zweigbergk <martinvonz@gmail.com>2012-08-29 06:15:56 (GMT)
committerJunio C Hamano <gitster@pobox.com>2012-08-30 21:00:23 (GMT)
commita73e22e96350c9bcb5c0e31e0298ce67bec0a527 (patch)
tree667b12cc32e64fe6a6b3beac6a713267837c50b9
parentd023c248a39a7ac3ee226e34eadcee6913913f2f (diff)
downloadgit-a73e22e96350c9bcb5c0e31e0298ce67bec0a527.zip
git-a73e22e96350c9bcb5c0e31e0298ce67bec0a527.tar.gz
git-a73e22e96350c9bcb5c0e31e0298ce67bec0a527.tar.bz2
cherry-pick/revert: respect order of revisions to pick
When giving multiple individual revisions to cherry-pick or revert, as in 'git cherry-pick A B' or 'git revert B A', one would expect them to be picked/reverted in the order given on the command line. They are instead ordered by their commit timestamp -- in chronological order for "cherry-pick" and in reverse chronological order for "revert". This matches the order in which one would usually give them on the command line, making this bug somewhat hard to notice. Still, it has been reported at least once before [1]. It seems like the chronological sorting happened by accident because the revision walker has traditionally always sorted commits in reverse chronological order when rev_info.no_walk was enabled. In the case of 'git revert B A' where B is newer than A, this sorting is a no-op. For 'git cherry-pick A B', the sorting would reverse the arguments, but because the sequencer also flips the rev_info.reverse flag when picking (as opposed to reverting), the end result is a chronological order. The rev_info.reverse flag was probably flipped so that the revision walker emits B before C in 'git cherry-pick A..C'; that it happened to effectively undo the unexpected sorting done when not walking, was probably a coincidence that allowed this bug to happen at all. Fix the bug by telling the revision walker not to sort the commits when not walking. The only case we want to reverse the order is now when cherry-picking and walking revisions (rev_info.no_walk = 0). [1] http://thread.gmane.org/gmane.comp.version-control.git/164794 Signed-off-by: Martin von Zweigbergk <martinvonz@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--builtin/revert.c2
-rw-r--r--sequencer.c6
-rwxr-xr-xt/t3508-cherry-pick-many-commits.sh2
3 files changed, 7 insertions, 3 deletions
diff --git a/builtin/revert.c b/builtin/revert.c
index 42ce399..98ad641 100644
--- a/builtin/revert.c
+++ b/builtin/revert.c
@@ -193,7 +193,7 @@ static void parse_args(int argc, const char **argv, struct replay_opts *opts)
struct setup_revision_opt s_r_opt;
opts->revs = xmalloc(sizeof(*opts->revs));
init_revisions(opts->revs, NULL);
- opts->revs->no_walk = REVISION_WALK_NO_WALK_SORTED;
+ opts->revs->no_walk = REVISION_WALK_NO_WALK_UNSORTED;
if (argc < 2)
usage_with_options(usage_str, options);
memset(&s_r_opt, 0, sizeof(s_r_opt));
diff --git a/sequencer.c b/sequencer.c
index bf078f2..bd62680 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -543,7 +543,11 @@ static int do_pick_commit(struct commit *commit, struct replay_opts *opts)
static void prepare_revs(struct replay_opts *opts)
{
- if (opts->action != REPLAY_REVERT)
+ /*
+ * picking (but not reverting) ranges (but not individual revisions)
+ * should be done in reverse
+ */
+ if (opts->action == REPLAY_PICK && !opts->revs->no_walk)
opts->revs->reverse ^= 1;
if (prepare_revision_walk(opts->revs))
diff --git a/t/t3508-cherry-pick-many-commits.sh b/t/t3508-cherry-pick-many-commits.sh
index afda2d5..340afc7 100755
--- a/t/t3508-cherry-pick-many-commits.sh
+++ b/t/t3508-cherry-pick-many-commits.sh
@@ -44,7 +44,7 @@ test_expect_success 'cherry-pick first..fourth works' '
check_head_differs_from fourth
'
-test_expect_failure 'cherry-pick three one two works' '
+test_expect_success 'cherry-pick three one two works' '
git checkout -f first &&
test_commit one &&
test_commit two &&