Skip to content

Commit d1cfa0c

Browse files
committed
config: format paths gently
Move the logic for formatting path config values into a helper method and use gentle parsing when needed. Signed-off-by: Derrick Stolee <stolee@gmail.com>
1 parent fafafc5 commit d1cfa0c

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

builtin/config.c

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,28 @@ static int format_config_bool_or_str(struct strbuf *buf,
314314
return 0;
315315
}
316316

317+
static int format_config_path(struct strbuf *buf,
318+
const char *key_,
319+
const char *value_,
320+
int gently)
321+
{
322+
char *v;
323+
if (gently) {
324+
if (git_parse_maybe_pathname(value_, &v) < 0)
325+
return -1;
326+
} else if (git_config_pathname(&v, key_, value_) < 0) {
327+
return -1;
328+
}
329+
330+
if (v)
331+
strbuf_addstr(buf, v);
332+
else
333+
return 1; /* :(optional)no-such-file */
334+
335+
free(v);
336+
return 0;
337+
}
338+
317339
/*
318340
* Format the configuration key-value pair (`key_`, `value_`) and
319341
* append it into strbuf `buf`. Returns a negative value on failure,
@@ -347,16 +369,9 @@ static int format_config(const struct config_display_options *opts,
347369
res = format_config_bool_or_int(buf, key_, value_, kvi, gently);
348370
else if (opts->type == TYPE_BOOL_OR_STR)
349371
res = format_config_bool_or_str(buf, value_);
350-
else if (opts->type == TYPE_PATH) {
351-
char *v;
352-
if (git_config_pathname(&v, key_, value_) < 0)
353-
return -1;
354-
if (v)
355-
strbuf_addstr(buf, v);
356-
else
357-
return 1; /* :(optional)no-such-file */
358-
free((char *)v);
359-
} else if (opts->type == TYPE_EXPIRY_DATE) {
372+
else if (opts->type == TYPE_PATH)
373+
res = format_config_path(buf, key_, value_, gently);
374+
else if (opts->type == TYPE_EXPIRY_DATE) {
360375
timestamp_t t;
361376
if (git_config_expiry_date(&t, key_, value_) < 0)
362377
return -1;

0 commit comments

Comments
 (0)