builtin: consistently pass cmd_* prefix to parse_options

If a builtin uses RUN_SETUP to request that git.c enter the repository directory, we'll get passed in a "prefix" variable with the path to the original directory. It's important to pass this to parse_options(), since we may use it to fix up relative OPT_FILENAME() options. Some builtins don't bother; let's make sure we do so consistently. There may not be any particular bugs fixed here; OPT_FILENAME is actually pretty rare, and none of these commands use it directly. However, this does future-proof us against somebody adding an option that uses it and creating a subtle bug that only shows up when you're in a subdirectory of the repository. In some cases, like hash-object and upload-pack, we don't specify RUN_SETUP, so we know the prefix will always be empty. It's still worth passing the variable along to keep the idiom consistent across all builtins (and of course it protects us if they ever _did_ switch to using RUN_SETUP). Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed May 9, 2019 at 17:28 UTC d64db5b334f8822284bcc7068e093d8fbfb46dd9
5 files changed +5 -5
builtin/column.c
+1 -1
@@ -43,7 +43,7 @@ int cmd_column(int argc, const char **argv, const char *prefix)
43
44 memset(&copts, 0, sizeof(copts));
45 copts.padding = 1;
46 - argc = parse_options(argc, argv, "", options, builtin_column_usage, 0);
46 + argc = parse_options(argc, argv, prefix, options, builtin_column_usage, 0);
47 if (argc)
48 usage_with_options(builtin_column_usage, options);
49 if (real_command || command) {
builtin/hash-object.c
+1 -1
@@ -108,7 +108,7 @@ int cmd_hash_object(int argc, const char **argv, const char *prefix)
108 int i;
109 const char *errstr = NULL;
110
111 - argc = parse_options(argc, argv, NULL, hash_object_options,
111 + argc = parse_options(argc, argv, prefix, hash_object_options,
112 hash_object_usage, 0);
113
114 if (flags & HASH_WRITE_OBJECT)
builtin/range-diff.c
+1 -1
@@ -32,7 +32,7 @@ int cmd_range_diff(int argc, const char **argv, const char *prefix)
32 repo_diff_setup(the_repository, &diffopt);
33
34 options = parse_options_concat(range_diff_options, diffopt.parseopts);
35 - argc = parse_options(argc, argv, NULL, options,
35 + argc = parse_options(argc, argv, prefix, options,
36 builtin_range_diff_usage, 0);
37
38 diff_setup_done(&diffopt);
builtin/rebase--interactive.c
+1 -1
@@ -302,7 +302,7 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix)
302 if (argc == 1)
303 usage_with_options(builtin_rebase_interactive_usage, options);
304
305 - argc = parse_options(argc, argv, NULL, options,
305 + argc = parse_options(argc, argv, prefix, options,
306 builtin_rebase_interactive_usage, PARSE_OPT_KEEP_ARGV0);
307
308 opts.gpg_sign = xstrdup_or_null(opts.gpg_sign);
builtin/upload-pack.c
+1 -1
@@ -33,7 +33,7 @@ int cmd_upload_pack(int argc, const char **argv, const char *prefix)
33 packet_trace_identity("upload-pack");
34 read_replace_refs = 0;
35
36 - argc = parse_options(argc, argv, NULL, options, upload_pack_usage, 0);
36 + argc = parse_options(argc, argv, prefix, options, upload_pack_usage, 0);
37
38 if (argc != 1)
39 usage_with_options(upload_pack_usage, options);