Skip to content

Commit 7faba18

Browse files
peffgitster
authored andcommitted
multi-pack-index: avoid writing to global in option callback
We declare the --object-dir option like: OPT_CALLBACK(0, "object-dir", &opts.object_dir, ...); but the pointer to opts.object_dir is completely unused. Instead, the callback writes directly to a global. Which fortunately happens to be opts.object_dir. So everything works as expected, but it's unnecessarily confusing. Instead, let's have the callback write to the option value pointer that has been passed in. This also quiets a -Wunused-parameter warning (since we don't otherwise look at "opt"). Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6823c19 commit 7faba18

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

builtin/multi-pack-index.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,12 @@ static struct opts_multi_pack_index {
5656
static int parse_object_dir(const struct option *opt, const char *arg,
5757
int unset)
5858
{
59-
free(opts.object_dir);
59+
char **value = opt->value;
60+
free(*value);
6061
if (unset)
61-
opts.object_dir = xstrdup(get_object_directory());
62+
*value = xstrdup(get_object_directory());
6263
else
63-
opts.object_dir = real_pathdup(arg, 1);
64+
*value = real_pathdup(arg, 1);
6465
return 0;
6566
}
6667

0 commit comments

Comments
 (0)