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

Re: Some ideas for StGIT

From
Shawn O. Pearce <spearce@spearce.org>
Date
Aug 5, 2007, 02:31 UTC
Message-ID
<20070805023130.GV20052@spearce.org>
In-Reply-To
<f934ve$3oi$1@sea.gmane.org>
Jakub Narebski <jnareb@gmail.com> wrote:
Show 9 quoted lines
> Shawn O. Pearce wrote:
> 
> > (Regarding the performance, cherry-picking 55 patches is
> > slow, especially when many of them would apply trivially with
> > git-diff|git-apply --index.  Be nice to improve that in 1.5.4.)
> 
> Perhaps in the future you would be able to use -i/--interactive mode
> in merge driven git-rebase (git rebase --merge -i <base>), which I think
> should be faster.

Heh. You're talking to someone who actually knows what he is talking about here, and was actually involved in some of these tools... Let me fill the reader in on what's really happening...

`git-rebase` (non -i, non -m) uses `format-patch|am` to apply the changes of each commit it is rebasing. This is insanely fast as builtin diff and apply routines are quite efficient. It sometimes fails due to patches not applying cleanly. In those cases you have to either hand edit the patch, apply and continue the rebase, or abort the rebase and restart with the -m flag so it uses a full three-way file merge.

`git-rebase -m` (aka --merge) uses git-merge-recursive to apply the changes of each commit it is rebasing. (That's the merge part!) However merge-recursive usually takes longer to run then the above `format-patch|am` pipeline, and that is why -m is not the default. But it does handle cases `format-patch|am` cannot do automatically.

For quite a long time now both `git-revert` and `git-cherry-pick` (which are actually the same program!) have also been using git-merge-recursive as their implementation to revert or apply the commit's change. This allows them to perform changes that also involve renames, as well as to apply some changes that might fail as a patch but succeed when done as a three-way file merge.

So really `revert`, `cherry-pick`, `rebase -m` (and also `am -3` as it also uses merge-recursive) are all the same underlying implementation. The major differences between them is what they do *after* the changes have been applied, and which direction the change goes (e.g. revert undoes the change).

Now the new `git-rebase -i` is really just a complicated loop around `cherry-pick`. Really. Go look at the code, it never calls anything except cherry-pick. So `rebase -i` is actually `rebase --merge -i`. That's why its sluggish.

Why is merge-recursive sluggish? It does rename detection. It does full three-way file merges, rather than just applying a patch. It also tries to do a three-way read-tree before doing file level merges. git-apply does none of these things, and is faster because of it.

So that future you speak of above is today. Its also not faster, its slower. Faster would be to do something like `format-patch|am -3` so that merge-recursive is only invoked if git-apply was unable to apply the patch automatically. Except we'd want to save the original tree data so we can do proper rename detection when merge-recursive is fired up.

-- 
Shawn.
Previous: Jakub NarebskiNext: Junio C Hamano
Message 7 of 32 in “Some ideas for StGIT”
  1. Pavel RoskinAug 3, 2007
  2. Andy ParkinsAug 3, 2007
  3. Pavel RoskinAug 4, 2007
  4. Shawn O. PearceAug 4, 2007
  5. Pavel RoskinAug 5, 2007
  6. Jakub NarebskiAug 5, 2007
  7. Shawn O. PearceAug 5, 2007
  8. Junio C HamanoAug 5, 2007
  9. Josef SipekAug 5, 2007
  10. Johannes SchindelinAug 5, 2007
  11. Josef SipekAug 5, 2007
  12. Johannes SchindelinAug 5, 2007
  13. Josef SipekAug 5, 2007
  14. Yann DirsonAug 4, 2007
  15. Catalin MarinasAug 6, 2007
  16. Chris ShoemakerAug 4, 2007
  17. Johannes SchindelinAug 4, 2007
  18. Yann DirsonAug 3, 2007
  19. Catalin MarinasAug 6, 2007
  20. Pavel RoskinAug 6, 2007
  21. Josef SipekAug 6, 2007
  22. Theodore TsoAug 4, 2007
  23. Yann DirsonAug 4, 2007
  24. Josef SipekAug 4, 2007
  25. Pavel RoskinAug 5, 2007
  26. Catalin MarinasAug 6, 2007
  27. Karl HasselströmAug 6, 2007
  28. Pavel RoskinAug 6, 2007
  29. Karl HasselströmAug 6, 2007
  30. Catalin MarinasAug 23, 2007
  31. Karl HasselströmAug 23, 2007
  32. Pavel RoskinAug 6, 2007

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.