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

Re: [BUG] multi-commit cherry-pick messes up the order of commits

From
Jeff King <peff@peff.net>
Date
Jan 12, 2012, 19:47 UTC
Message-ID
<20120112194710.GA28148@sigill.intra.peff.net>
In-Reply-To
<CALkWK0kk0mVNaetr=triuVYva7inyx2aZvam81qTVA9=Q=UzGw@mail.gmail.com>
On Fri, Jan 13, 2012 at 12:55:58AM +0530, Ramkumar Ramachandra wrote:
Show 7 quoted lines
> Junio C Hamano wrote:
> > You should be able to look at revs->cmdline and tell if you need to let
> > cherry-pick walk (i.e. "cherry-pick master..next"), or if the user wants
> > individual commits (i.e. "cherry-pick A B C").
> >
> > And you do prepare_revision_walk() only when you need to walk; otherwise
> > you use the contents of revs->pending in order.

I am tempted to suggest that cherry-pick should not feed its arguments to the revision machinery in the first place, but instead accept a set of arguments, each argument of which is either a single commit (interpreted by get_sha1) or a range specifier (which can be fed to setup-revisions). And then get a linearized set of commits for _each_ argument independently and concatenate them (possibly eliminating duplicates). That would make all of these work as most people would expect:

  git cherry-pick A B C
  git cherry-pick A..B
  git cherry-pick A..B B..C
but would be a regression for:
  git cherry-pick B ^A

versus the current code. I suspect that the latter form is not all that commonly used, though, and certainly I would accept it as a casualty of making the "A B C" form work. My only hesitation is that it is in fact a regression.

Show 8 quoted lines
> Okay, just to make sure I understand this correctly: if more than one
> argument is literally specified, I should not set up the revision
> walker and pick the commits listed in revs->pending, correct?  Then,
> when I encounter the following command,
> 
>   $ git cherry-pick maint ^master
> 
> I should just pick two commits: maint, and ^master.

But ^master is not a commit, it is a negation. So it is nonsensical if the arguments are considered independent of each other (you _could_ use a heuristic to guess that they are not independent, but I'd rather not go there). So you'd probably end up just rejecting the arguments.

-Peff
Previous: Ramkumar RamachandraNext: Jonathan Nieder
Message 16 of 24 in “[BUG] multi-commit cherry-pick messes up the order of commits”
  1. SZEDER GáborJan 11, 2012
  2. Christian CouderJan 12, 2012
  3. SZEDER GáborJan 12, 2012
  4. Ramkumar RamachandraJan 12, 2012
  5. Jeff KingJan 12, 2012
  6. Ramkumar RamachandraJan 12, 2012
  7. Ramkumar RamachandraJan 12, 2012
  8. Jeff KingJan 12, 2012
  9. Ramkumar RamachandraJan 12, 2012
  10. cherry-pick: add failing test for out-of-order pickRamkumar Ramachandra, Jan 12, 2012
  11. Jonathan NiederJan 12, 2012
  12. cherry-pick: add failing test for out-of-order pickRamkumar Ramachandra, Jan 12, 2012
  13. Jonathan NiederJan 12, 2012
  14. Junio C HamanoJan 12, 2012
  15. Ramkumar RamachandraJan 12, 2012
  16. Jeff KingJan 12, 2012
  17. Jonathan NiederJan 12, 2012
  18. Jeff KingJan 12, 2012
  19. Junio C HamanoJan 12, 2012
  20. Johannes SixtJan 12, 2012
  21. Ramkumar RamachandraJan 12, 2012
  22. Jonathan NiederJan 12, 2012
  23. Jonathan NiederJan 12, 2012
  24. Junio C HamanoJan 12, 2012

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.