Skip to content

Commit 4badef0

Browse files
committed
Merge branch 'dk/parseopt-optional-filename-fixes'
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
2 parents e569dce + a2584d0 commit 4badef0

File tree

3 files changed

+5
-7
lines changed

3 files changed

+5
-7
lines changed

Documentation/gitcli.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ Options that take a filename allow a prefix `:(optional)`. For example:
223223
224224
----------------------------
225225
git commit -F :(optional)COMMIT_EDITMSG
226-
# if COMMIT_EDITMSG does not exist, equivalent to
226+
# if COMMIT_EDITMSG does not exist, the above is equivalent to
227227
git commit
228228
----------------------------
229229

config.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1278,7 +1278,7 @@ int git_config_string(char **dest, const char *var, const char *value)
12781278

12791279
int git_config_pathname(char **dest, const char *var, const char *value)
12801280
{
1281-
int is_optional;
1281+
bool is_optional;
12821282
char *path;
12831283

12841284
if (!value)

parse-options.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -208,12 +208,12 @@ static enum parse_opt_result do_get_value(struct parse_opt_ctx_t *p,
208208
case OPTION_FILENAME:
209209
{
210210
const char *value;
211-
int is_optional;
211+
bool is_optional;
212212

213213
if (unset)
214214
value = NULL;
215215
else if (opt->flags & PARSE_OPT_OPTARG && !p->opt)
216-
value = (char *)opt->defval;
216+
value = (const char *)opt->defval;
217217
else {
218218
int err = get_arg(p, opt, flags, &value);
219219
if (err)
@@ -223,10 +223,8 @@ static enum parse_opt_result do_get_value(struct parse_opt_ctx_t *p,
223223
return 0;
224224

225225
is_optional = skip_prefix(value, ":(optional)", &value);
226-
if (!value)
227-
is_optional = 0;
228226
value = fix_filename(p->prefix, value);
229-
if (is_optional && is_empty_or_missing_file(value)) {
227+
if (is_optional && is_missing_file(value)) {
230228
free((char *)value);
231229
} else {
232230
FREE_AND_NULL(*(char **)opt->value);

0 commit comments

Comments
 (0)