Skip to content

Commit d64db5b

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 76a7bc0 commit d64db5b

File tree

5 files changed

+5
-5
lines changed

5 files changed

+5
-5
lines changed

builtin/column.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ int cmd_column(int argc, const char **argv, const char *prefix)
4343

4444
memset(&copts, 0, sizeof(copts));
4545
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);
4747
if (argc)
4848
usage_with_options(builtin_column_usage, options);
4949
if (real_command || command) {

builtin/hash-object.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ int cmd_hash_object(int argc, const char **argv, const char *prefix)
108108
int i;
109109
const char *errstr = NULL;
110110

111-
argc = parse_options(argc, argv, NULL, hash_object_options,
111+
argc = parse_options(argc, argv, prefix, hash_object_options,
112112
hash_object_usage, 0);
113113

114114
if (flags & HASH_WRITE_OBJECT)

builtin/range-diff.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ int cmd_range_diff(int argc, const char **argv, const char *prefix)
3232
repo_diff_setup(the_repository, &diffopt);
3333

3434
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,
3636
builtin_range_diff_usage, 0);
3737

3838
diff_setup_done(&diffopt);

builtin/rebase--interactive.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix)
302302
if (argc == 1)
303303
usage_with_options(builtin_rebase_interactive_usage, options);
304304

305-
argc = parse_options(argc, argv, NULL, options,
305+
argc = parse_options(argc, argv, prefix, options,
306306
builtin_rebase_interactive_usage, PARSE_OPT_KEEP_ARGV0);
307307

308308
opts.gpg_sign = xstrdup_or_null(opts.gpg_sign);

builtin/upload-pack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ int cmd_upload_pack(int argc, const char **argv, const char *prefix)
3333
packet_trace_identity("upload-pack");
3434
read_replace_refs = 0;
3535

36-
argc = parse_options(argc, argv, NULL, options, upload_pack_usage, 0);
36+
argc = parse_options(argc, argv, prefix, options, upload_pack_usage, 0);
3737

3838
if (argc != 1)
3939
usage_with_options(upload_pack_usage, options);

0 commit comments

Comments
 (0)