]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Fix revision log diff setup, avoid unnecessary diff generation
authorLinus Torvalds <torvalds@linux-foundation.org>
Sat, 29 Sep 2007 16:50:39 +0000 (09:50 -0700)
committerJunio C Hamano <gitster@pobox.com>
Sat, 29 Sep 2007 22:42:32 +0000 (15:42 -0700)
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>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
revision.c

index 33d092c3c4b4c08fb6f39228e464219df4cb4f1c..658471385cfaa2480ee78b19fe38fc51d9b51ab2 100644 (file)
@@ -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;