aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2025-11-04 19:49:13 -0800
committerJunio C Hamano <gitster@pobox.com>2025-11-04 19:49:13 -0800
commit1cb757341496cb96b8cb0fbb02e74cf8800c7736 (patch)
tree2ecf1bf1235b4000b867e60a8171a2588adc46a3
parentSync with 'master' (diff)
parentparseopt: remove unreachable code (diff)
downloadgit-1cb757341496cb96b8cb0fbb02e74cf8800c7736.tar.gz
git-1cb757341496cb96b8cb0fbb02e74cf8800c7736.zip
Merge branch 'dk/parseopt-optional-filename-fixes' into next
A recently added configuration variable and command line option syntax ":(optional)" for values that are of filename type inconsistently behaved on an empty file (configuration took it happily, while the command line option pretended as if it did not exist), which has been corrected. * dk/parseopt-optional-filename-fixes: parseopt: remove unreachable code parseopt: restore const qualifier to parsed filename config: use boolean type for a simple flag parseopt: use boolean type for a simple flag doc: clarify command equivalence comment parseopt: fix :(optional) at command line to only ignore missing files
-rw-r--r--Documentation/gitcli.adoc2
-rw-r--r--config.c2
-rw-r--r--parse-options.c8
3 files changed, 5 insertions, 7 deletions
diff --git a/Documentation/gitcli.adoc b/Documentation/gitcli.adoc
index ef2a0a399d..6815d6bfb7 100644
--- a/Documentation/gitcli.adoc
+++ b/Documentation/gitcli.adoc
@@ -223,7 +223,7 @@ Options that take a filename allow a prefix `:(optional)`. For example:
----------------------------
git commit -F :(optional)COMMIT_EDITMSG
-# if COMMIT_EDITMSG does not exist, equivalent to
+# if COMMIT_EDITMSG does not exist, the above is equivalent to
git commit
----------------------------
diff --git a/config.c b/config.c
index 71b136bf7f..f1def0dcfb 100644
--- a/config.c
+++ b/config.c
@@ -1278,7 +1278,7 @@ int git_config_string(char **dest, const char *var, const char *value)
int git_config_pathname(char **dest, const char *var, const char *value)
{
- int is_optional;
+ bool is_optional;
char *path;
if (!value)
diff --git a/parse-options.c b/parse-options.c
index 5933468c19..c9cafc21b9 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -208,12 +208,12 @@ static enum parse_opt_result do_get_value(struct parse_opt_ctx_t *p,
case OPTION_FILENAME:
{
const char *value;
- int is_optional;
+ bool is_optional;
if (unset)
value = NULL;
else if (opt->flags & PARSE_OPT_OPTARG && !p->opt)
- value = (char *)opt->defval;
+ value = (const char *)opt->defval;
else {
int err = get_arg(p, opt, flags, &value);
if (err)
@@ -223,10 +223,8 @@ static enum parse_opt_result do_get_value(struct parse_opt_ctx_t *p,
return 0;
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)) {
+ if (is_optional && is_missing_file(value)) {
free((char *)value);
} else {
FREE_AND_NULL(*(char **)opt->value);