diff options
| author | Junio C Hamano <gitster@pobox.com> | 2025-10-14 12:56:09 -0700 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2025-10-14 12:56:09 -0700 |
| commit | 44dee53a303ad91305158bb1e2d9a8704b300c15 (patch) | |
| tree | de50ca1587e3919b39a676dea702c88ac89608a9 /parse-options.c | |
| parent | 1003719fb700df37557d6d161e757fabb952e78a (diff) | |
| parent | ccfcaf399ffcc91553395a8de8e833e7685e7cc2 (diff) | |
Merge branch 'jc/optional-path'
Configuration variables that take a pathname as a value
(e.g. blame.ignorerevsfile) can be marked as optional by prefixing
":(optoinal)" before its value.
* jc/optional-path:
parseopt: values of pathname type can be prefixed with :(optional)
config: values of pathname type can be prefixed with :(optional)
t7500: fix GIT_EDITOR shell snippet
t7500: make each piece more independent
Diffstat (limited to 'parse-options.c')
| -rw-r--r-- | parse-options.c | 31 |
1 files changed, 20 insertions, 11 deletions
diff --git a/parse-options.c b/parse-options.c index 992ec9631f..5933468c19 100644 --- a/parse-options.c +++ b/parse-options.c @@ -133,7 +133,6 @@ static enum parse_opt_result do_get_value(struct parse_opt_ctx_t *p, { const char *arg; const int unset = flags & OPT_UNSET; - int err; if (unset && p->opt) return error(_("%s takes no value"), optname(opt, flags)); @@ -209,21 +208,31 @@ static enum parse_opt_result do_get_value(struct parse_opt_ctx_t *p, case OPTION_FILENAME: { const char *value; - - FREE_AND_NULL(*(char **)opt->value); - - err = 0; + int is_optional; if (unset) value = NULL; else if (opt->flags & PARSE_OPT_OPTARG && !p->opt) - value = (const char *) opt->defval; - else - err = get_arg(p, opt, flags, &value); + value = (char *)opt->defval; + else { + int err = get_arg(p, opt, flags, &value); + if (err) + return err; + } + if (!value) + return 0; - if (!err) - *(char **)opt->value = fix_filename(p->prefix, value); - return err; + is_optional = skip_prefix(value, ":(optional)", &value); + if (!value) + is_optional = 0; + value = fix_filename(p->prefix, value); + if (is_optional && is_empty_or_missing_file(value)) { + free((char *)value); + } else { + FREE_AND_NULL(*(char **)opt->value); + *(const char **)opt->value = value; + } + return 0; } case OPTION_CALLBACK: { |
