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

[PATCH/WIP 0/8] Make git-am a builtin

From
Paul Tan <pyokagan@gmail.com>
Date
May 27, 2015, 13:33 UTC
Message-ID
<1432733618-25629-1-git-send-email-pyokagan@gmail.com>

git-am is a commonly used command for applying a series of patches from a mailbox to the current branch. Currently, it is implemented by the shell script git-am.sh. However, compared to C, shell scripts have certain deficiencies: they need to spawn a lot of processes, introduce a lot of dependencies and cannot take advantage of git's internal caches.

This WIP patch series rewrites git-am.sh into optimized C builtin/am.c. It is based on my finished prototype of the rewrite[1], and over the next 5 weeks I will be cutting out small patches from the prototype to make it easier to review and refine the patch series.

This is part of my GSoC project to rewrite git-pull.sh into git-am.sh into C builtins[2].

A small benchmark that applies 50 patches[3]:
	#!/bin/sh
	git init &&
	echo initial >file &&
	git add file &&
	git commit -m initial &&
	git branch before-am &&
	for x in $(seq 50)
	do
	    echo $x >>file &&
	    git commit -a -m $x
	done &&
	git format-patch --stdout before-am.. >patches &&
	git checkout before-am &&
	time git patches >/dev/null
I ran this benchmark on my *Linux* system.
Timings for git on master:
1.40s, 1.42s, 1.25s, 1.32s, 1.10s. Avg: ~1.30s
Timings for git on master + this patch series applied:
0.24s, 0.22s, 0.22s, 0.19s, 0.25s. Avg: ~0.22s

This is around a 6x speedup. It's not because this patch series does less than git-am.sh -- similar speedups can be observed with the prototype, which passes the test suite[4].

(Sorry for leaving the other reviews hanging. I was too preoccupied with the git-am rewrite, and was afraid of forgetting important details should I context switch. Now that the prototype is finished I can deal with the other patch series'.)

[1] https://github.com/pyokagan/git/compare/master...pyokagan:pt/ref-builtin-am [2] https://gist.github.com/pyokagan/1b7b0d1f4dab6ba3cef1 [3] Since a 56-patch series was posted recently ;-) [4] The subset of the test suite that calls git-rebase and git-am.

Paul Tan (8):
  wrapper: implement xopen()
  wrapper: implement xfopen()
  am: implement patch queue mechanism
  am: split out mbox/maildir patches with git-mailsplit
  am: detect mbox patches
  am: extract patch, message and authorship with git-mailinfo
  am: apply patch with git-apply
  am: commit applied patch
 Makefile          |   2 +-
 builtin.h         |   1 +
 builtin/am.c      | 687 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 git-compat-util.h |   2 +
 git.c             |   1 +
 wrapper.c         |  37 +++
 6 files changed, 729 insertions(+), 1 deletion(-)
 create mode 100644 builtin/am.c
-- 
2.1.4
Next: Paul Tan
Message 1 of 24 in “Make git-am a builtin”
  1. 0/8 Make git-am a builtinPaul Tan, May 27, 2015
  2. 1/8 wrapper: implement xopen()Paul Tan, May 27, 2015
  3. Stefan BellerMay 27, 2015
  4. Torsten BögershausenMay 27, 2015
  5. Jeff KingMay 27, 2015
  6. Paul TanJun 3, 2015
  7. Paul TanJun 4, 2015
  8. 2/8 wrapper: implement xfopen()Paul Tan, May 27, 2015
  9. Jeff KingMay 27, 2015
  10. 3/8 am: implement patch queue mechanismPaul Tan, May 27, 2015
  11. Junio C HamanoMay 27, 2015
  12. 4/8 am: split out mbox/maildir patches with git-mailsplitPaul Tan, May 27, 2015
  13. Eric SunshineMay 28, 2015
  14. Paul TanJun 2, 2015
  15. 5/8 am: detect mbox patchesPaul Tan, May 27, 2015
  16. Eric SunshineMay 31, 2015
  17. 6/8 am: extract patch, message and authorship with git-mailinfoPaul Tan, May 27, 2015
  18. Junio C HamanoMay 27, 2015
  19. Jeff KingMay 27, 2015
  20. Paul TanJun 3, 2015
  21. Junio C HamanoMay 27, 2015
  22. Paul TanJun 3, 2015
  23. 7/8 am: apply patch with git-applyPaul Tan, May 27, 2015
  24. 8/8 am: commit applied patchPaul Tan, May 27, 2015

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.