Skip to content

Commit 5a88f97

Browse files
committed
diff- and log- family: handle "git cmd -h" early
"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>
1 parent f0994fa commit 5a88f97

File tree

4 files changed

+12
-0
lines changed

4 files changed

+12
-0
lines changed

builtin/diff-files.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ int cmd_diff_files(int argc, const char **argv, const char *prefix)
2020
int result;
2121
unsigned options = 0;
2222

23+
if (argc == 2 && !strcmp(argv[1], "-h"))
24+
usage(diff_files_usage);
25+
2326
init_revisions(&rev, prefix);
2427
gitmodules_config();
2528
git_config(git_diff_basic_config, NULL); /* no "diff" UI options */

builtin/diff-index.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ int cmd_diff_index(int argc, const char **argv, const char *prefix)
1717
int i;
1818
int result;
1919

20+
if (argc == 2 && !strcmp(argv[1], "-h"))
21+
usage(diff_cache_usage);
22+
2023
init_revisions(&rev, prefix);
2124
gitmodules_config();
2225
git_config(git_diff_basic_config, NULL); /* no "diff" UI options */

builtin/diff-tree.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix)
105105
struct setup_revision_opt s_r_opt;
106106
int read_stdin = 0;
107107

108+
if (argc == 2 && !strcmp(argv[1], "-h"))
109+
usage(diff_tree_usage);
110+
108111
init_revisions(opt, prefix);
109112
gitmodules_config();
110113
git_config(git_diff_basic_config, NULL); /* no "diff" UI options */

builtin/rev-list.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,9 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
277277
int use_bitmap_index = 0;
278278
const char *show_progress = NULL;
279279

280+
if (argc == 2 && !strcmp(argv[1], "-h"))
281+
usage(rev_list_usage);
282+
280283
git_config(git_default_config, NULL);
281284
init_revisions(&revs, prefix);
282285
revs.abbrev = DEFAULT_ABBREV;

0 commit comments

Comments
 (0)