summaryrefslogtreecommitdiff
path: root/builtin/env--helper.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2020-09-30 12:28:32 (GMT)
committerJunio C Hamano <gitster@pobox.com>2020-09-30 19:53:47 (GMT)
commit424e28fcadfe0a40e444687c10fb4eaff8360f8d (patch)
tree662e00673b62495221049c3bd2dd556bbcd77355 /builtin/env--helper.c
parente885a84f1bc660adfc1dea5f6c25d0a92c7c9dbc (diff)
downloadgit-424e28fcadfe0a40e444687c10fb4eaff8360f8d.zip
git-424e28fcadfe0a40e444687c10fb4eaff8360f8d.tar.gz
git-424e28fcadfe0a40e444687c10fb4eaff8360f8d.tar.bz2
env--helper: write to opt->value in parseopt helper
We use OPT_CALLBACK_F() to call the option_parse_type() callback, passing it the address of "cmdmode" as the value to write to. But the callback doesn't look at opt->value at all, and instead writes to a global variable. This works out because that's the same global variable we happen to pass in, but it's rather confusing. Let's use the passed-in value instead. We'll also make "cmdmode" a local variable of the main function, ensuring we can't make the same mistake again. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/env--helper.c')
-rw-r--r--builtin/env--helper.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/builtin/env--helper.c b/builtin/env--helper.c
index 23c214f..3aa4282 100644
--- a/builtin/env--helper.c
+++ b/builtin/env--helper.c
@@ -7,18 +7,20 @@ static char const * const env__helper_usage[] = {
NULL
};
-static enum {
+enum cmdmode {
ENV_HELPER_TYPE_BOOL = 1,
ENV_HELPER_TYPE_ULONG
-} cmdmode = 0;
+};
static int option_parse_type(const struct option *opt, const char *arg,
int unset)
{
+ enum cmdmode *cmdmode = opt->value;
+
if (!strcmp(arg, "bool"))
- cmdmode = ENV_HELPER_TYPE_BOOL;
+ *cmdmode = ENV_HELPER_TYPE_BOOL;
else if (!strcmp(arg, "ulong"))
- cmdmode = ENV_HELPER_TYPE_ULONG;
+ *cmdmode = ENV_HELPER_TYPE_ULONG;
else
die(_("unrecognized --type argument, %s"), arg);
@@ -33,6 +35,7 @@ int cmd_env__helper(int argc, const char **argv, const char *prefix)
int ret;
int ret_int, default_int;
unsigned long ret_ulong, default_ulong;
+ enum cmdmode cmdmode = 0;
struct option opts[] = {
OPT_CALLBACK_F(0, "type", &cmdmode, N_("type"),
N_("value is given this type"), PARSE_OPT_NONEG,