]> git.ipfire.org Git - thirdparty/git.git/commitdiff
diff- and log- family: handle "git cmd -h" early
authorJunio C Hamano <gitster@pobox.com>
Thu, 1 Jun 2017 04:38:16 +0000 (13:38 +0900)
committerJunio C Hamano <gitster@pobox.com>
Mon, 5 Jun 2017 02:39:59 +0000 (11:39 +0900)
"git $builtin -h" bypasses the usual repository setup and calls the
cmd_$builtin() function, expecting it to show the help text.

Unfortunately the commands in the log- and the diff- family want to
call into the revisions machinery, which by definition needs to have
a repository already discovered.  Strictly speaking, they may not
need a repository only for parsing "-h", but it is a good discipline
to future-proof codepath to ensure that setup_revisions() is called
after we know that a repository is there.

Handle the "git $builtin -h" special case very early in these
commands to work around potential issues.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/diff-files.c
builtin/diff-index.c
builtin/diff-tree.c
builtin/rev-list.c

index 15c61fd8d1ef891b013404ea5e7cbe42befac7bd..6be1df684a8459d7d2226faf9b28fbc55ea443b5 100644 (file)
@@ -20,6 +20,9 @@ int cmd_diff_files(int argc, const char **argv, const char *prefix)
        int result;
        unsigned options = 0;
 
+       if (argc == 2 && !strcmp(argv[1], "-h"))
+               usage(diff_files_usage);
+
        init_revisions(&rev, prefix);
        gitmodules_config();
        git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
index 1af373d0021f56f539a1d261e908a60d92ff5b4f..02dd35ba456ed4e0d12d4a1fe8fd58f0c4d406a1 100644 (file)
@@ -17,6 +17,9 @@ int cmd_diff_index(int argc, const char **argv, const char *prefix)
        int i;
        int result;
 
+       if (argc == 2 && !strcmp(argv[1], "-h"))
+               usage(diff_cache_usage);
+
        init_revisions(&rev, prefix);
        gitmodules_config();
        git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
index 326f88b6576d6c02e9a0bcecb5a0b402bb257372..773cc254b5909713b2838db4ba52e7b6f9e88e60 100644 (file)
@@ -105,6 +105,9 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix)
        struct setup_revision_opt s_r_opt;
        int read_stdin = 0;
 
+       if (argc == 2 && !strcmp(argv[1], "-h"))
+               usage(diff_tree_usage);
+
        init_revisions(opt, prefix);
        gitmodules_config();
        git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
index bcf77f0b8a201278f0887933e568937473eb7251..2951e0efd7e315dd7ec93f37142a730e2c27fb6a 100644 (file)
@@ -277,6 +277,9 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
        int use_bitmap_index = 0;
        const char *show_progress = NULL;
 
+       if (argc == 2 && !strcmp(argv[1], "-h"))
+               usage(rev_list_usage);
+
        git_config(git_default_config, NULL);
        init_revisions(&revs, prefix);
        revs.abbrev = DEFAULT_ABBREV;