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

Re: Use a *real* built-in diff generator

From
Linus Torvalds <torvalds@osdl.org>
Date
Mar 25, 2006, 15:56 UTC
Message-ID
<Pine.LNX.4.64.0603250742340.15714@g5.osdl.org>
In-Reply-To
<Pine.LNX.4.64.0603250734130.15714@g5.osdl.org>
On Sat, 25 Mar 2006, Linus Torvalds wrote:
> 
> I'll be taking a look at trying to fix it. 
Actually, it ended up being easier than I expected it to be.
This (on top of the previous patch) should fix it.
And yes, with this, I can pass the output of
	git diff v2.6.16..

to "git-apply" and it not only passes the "--stat" thing (which verifies that git-apply is happy with the diff) but it also results in exactly the same tree when applied on top of v2.6.16 (and the patch has two cases where the "no newline" test triggers).

The speed-up is quite noticeable, especially when doing things like
	git diff v2.6.16.. | git-apply --stat

which just _used_ to be painfully slow (25 seconds for me) and is now under five seconds. That's the difference between "twiddling your thumbs" and "ok, that wasn't too bad".

Now, to be honest, the real reason I wanted a built-in diff wasn't the speed advantage, but the fact that it's so much more flexible. The lack of fork/exec just allows us to do things that weren't practical before.

		Linus
----
diff --git a/xdiff/xutils.c b/xdiff/xutils.c
index 01e6765..b68afa2 100644
--- a/xdiff/xutils.c
+++ b/xdiff/xutils.c
@@ -31,14 +31,22 @@
 
 int xdl_emit_diffrec(char const *rec, long size, char const *pre, long psize,
 		     xdemitcb_t *ecb) {
-	mmbuffer_t mb[2];
+	mmbuffer_t mb[3];
+	int i;
 
 	mb[0].ptr = (char *) pre;
 	mb[0].size = psize;
 	mb[1].ptr = (char *) rec;
 	mb[1].size = size;
+	i = 2;
 
-	if (ecb->outf(ecb->priv, mb, 2) < 0) {
+	if (!size || rec[size-1] != '\n') {
+		mb[2].ptr = "\n\\ No newline at end of file\n";
+		mb[2].size = strlen(mb[2].ptr);
+		i = 3;
+	}
+
+	if (ecb->outf(ecb->priv, mb, i) < 0) {
 
 		return -1;
 	}
Previous: Linus TorvaldsNext: Davide Libenzi
Message 11 of 22 in “Use a *real* built-in diff generator”
  1. Linus TorvaldsMar 25, 2006
  2. Junio C HamanoMar 25, 2006
  3. Junio C HamanoMar 25, 2006
  4. Linus TorvaldsMar 25, 2006
  5. Davide LibenziMar 25, 2006
  6. Marco CostalbaMar 25, 2006
  7. Alex RiesenMar 25, 2006
  8. Linus TorvaldsMar 25, 2006
  9. Morten WelinderMar 25, 2006
  10. Linus TorvaldsMar 25, 2006
  11. Linus TorvaldsMar 25, 2006
  12. Davide LibenziMar 25, 2006
  13. Linus TorvaldsMar 25, 2006
  14. Davide LibenziMar 26, 2006
  15. Ralf BaechleMar 26, 2006
  16. Petr BaudisMar 26, 2006
  17. Linus TorvaldsMar 25, 2006
  18. Davide LibenziMar 26, 2006
  19. Junio C HamanoMar 25, 2006
  20. Junio C HamanoMar 25, 2006
  21. Linus TorvaldsMar 25, 2006
  22. Linus TorvaldsMar 25, 2006

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.