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

Fix revision log diff setup, avoid unnecessary diff generation

From
Linus Torvalds <torvalds@linux-foundation.org>
Date
Sep 29, 2007, 16:50 UTC
Message-ID
<alpine.LFD.0.999.0709290932040.3579@woody.linux-foundation.org>
In-Reply-To
<20070929123724.01BB045EC@madism.org>

We used to incorrectly start calculating diffs whenever any argument but '-z' was recognized by the diff options parsing. That was bogus, since not all arguments result in diffs being needed, so we just waste a lot of time and effort on calculating diffs that don't matter.

This actually also fixes another bug in "git log". Try this:
	git log -C

and notice how it prints an extra empty line in between log entries, even though it never prints the actual diff (because we didn't ask for any diff format, so the diff machinery never prints anything).

With this patch, that bogus empty line is gone, because "revs->diff" is never set. So this isn't just a "wasted time and effort" issue, it's also a slight semantic fix.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
---
On Sat, 29 Sep 2007, Pierre Habouzit wrote:
Show 6 quoted lines
>
> -				if (strcmp(argv[i], "-z"))
> -					revs->diff = 1;
> +				revs->diff = strcmp(argv[i], "-z")
> +					&& strcmp(argv[i], "--color")
> +					&& strcmp(argv[i], "--no-color");

The old code was already pretty damn ugly, the new code is worse (never mind the bug).

I don't think we should care *at*all* about the actual argument string, we should just look at what the diffopts end up being at the end.

So I would suggest a patch like the appended instead!

(Maybe there are other cases where we'd want to run the diff, but I can't think of any)

		Linus
---
 revision.c |   10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/revision.c b/revision.c
index 33d092c..6584713 100644
--- a/revision.c
+++ b/revision.c
@@ -1209,8 +1209,6 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
 
 			opts = diff_opt_parse(&revs->diffopt, argv+i, argc-i);
 			if (opts > 0) {
-				if (strcmp(argv[i], "-z"))
-					revs->diff = 1;
 				i += opts - 1;
 				continue;
 			}
@@ -1254,6 +1252,14 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
 		add_pending_object_with_mode(revs, object, def, mode);
 	}
 
+	/* Did the user ask for any diff output? Run the diff! */
+	if (revs->diffopt.output_format & ~DIFF_FORMAT_NO_OUTPUT)
+		revs->diff = 1;
+
+	/* Pickaxe needs diffs */
+	if (revs->diffopt.pickaxe)
+		revs->diff = 1;
+
 	if (revs->topo_order)
 		revs->limited = 1;
 
Previous: Marco CostalbaNext: Junio C Hamano
Message 10 of 12 in “Big performance regression with --no-color option in git-log”
  1. Marco CostalbaSep 29, 2007
  2. Pierre HabouzitSep 29, 2007
  3. Pierre HabouzitSep 29, 2007
  4. Marco CostalbaSep 29, 2007
  5. 1/1 --color and --no-color git-log options don't need diffs to be computed.Pierre Habouzit, Sep 29, 2007
  6. David KastrupSep 29, 2007
  7. Pierre HabouzitSep 29, 2007
  8. Marco CostalbaSep 29, 2007
  9. Marco CostalbaSep 29, 2007
  10. Fix revision log diff setup, avoid unnecessary diff generationLinus Torvalds, Sep 29, 2007
  11. Junio C HamanoSep 29, 2007
  12. Junio C HamanoSep 29, 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.