move "--follow needs one pathspec" rule to diff_setup_done
authorJeff King <peff@peff.net>
Tue, 20 May 2014 06:49:20 +0000 (02:49 -0400)
committerJunio C Hamano <gitster@pobox.com>
Tue, 20 May 2014 18:09:03 +0000 (11:09 -0700)
Because of the way "--follow" is implemented, we must have
exactly one pathspec. "git log" enforces this restriction,
but other users of the revision traversal code do not. For
example, "git format-patch --follow" will segfault during
try_to_follow_renames, as we have no pathspecs at all.

We can push this check down into diff_setup_done, which is
probably a better place anyway. It is the diff code that
introduces this restriction, so other parts of the code
should not need to care themselves.

Reported-by: "Michael S. Tsirkin" <mst@redhat.com>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/log.c
diff.c
index b708517a3506517a25d4c05f3c9c92a660688f8d..00a4ce602cc3f6784bb51784766c9ef2f655f0e9 100644 (file)
@@ -158,13 +158,9 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix,
        if (rev->show_notes)
                init_display_notes(&rev->notes_opt);
 
-       if (rev->diffopt.pickaxe || rev->diffopt.filter)
+       if (rev->diffopt.pickaxe || rev->diffopt.filter ||
+           DIFF_OPT_TST(&rev->diffopt, FOLLOW_RENAMES))
                rev->always_show_header = 0;
-       if (DIFF_OPT_TST(&rev->diffopt, FOLLOW_RENAMES)) {
-               rev->always_show_header = 0;
-               if (rev->diffopt.pathspec.nr != 1)
-                       usage("git logs can only follow renames on one pathname at a time");
-       }
 
        if (source)
                rev->show_source = 1;
diff --git a/diff.c b/diff.c
index e34bf971207f7737c3b1a10968acd8ffb3ecf93d..a99b925ac74bc4f513bd9d860e757f385cca871b 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -3317,6 +3317,9 @@ void diff_setup_done(struct diff_options *options)
                options->output_format = DIFF_FORMAT_NO_OUTPUT;
                DIFF_OPT_SET(options, EXIT_WITH_STATUS);
        }
+
+       if (DIFF_OPT_TST(options, FOLLOW_RENAMES) && options->pathspec.nr != 1)
+               die(_("--follow requires exactly one pathspec"));
 }
 
 static int opt_arg(const char *arg, int arg_short, const char *arg_long, int *val)