config: restructure format_config() for better control flow
Commit 578625fa91
(config: add '--name-only' option to list only
variable names, 2015-08-10) modified format_config() such that it
returned from the middle of the function when showing only keys,
resulting in ugly code structure.
Reorganize the if statements and dealing with the key-value delimiter to
make the function easier to read.
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
905f2036d0
commit
ebca2d4957
@ -108,21 +108,16 @@ struct strbuf_list {
|
|||||||
|
|
||||||
static int format_config(struct strbuf *buf, const char *key_, const char *value_)
|
static int format_config(struct strbuf *buf, const char *key_, const char *value_)
|
||||||
{
|
{
|
||||||
|
strbuf_init(buf, 0);
|
||||||
|
|
||||||
|
if (show_keys)
|
||||||
|
strbuf_addstr(buf, key_);
|
||||||
|
if (!omit_values) {
|
||||||
int must_free_vptr = 0;
|
int must_free_vptr = 0;
|
||||||
int must_print_delim = 0;
|
int must_add_delim = show_keys;
|
||||||
char value[256];
|
char value[256];
|
||||||
const char *vptr = value;
|
const char *vptr = value;
|
||||||
|
|
||||||
strbuf_init(buf, 0);
|
|
||||||
|
|
||||||
if (show_keys) {
|
|
||||||
strbuf_addstr(buf, key_);
|
|
||||||
must_print_delim = 1;
|
|
||||||
}
|
|
||||||
if (omit_values) {
|
|
||||||
strbuf_addch(buf, term);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
if (types == TYPE_INT)
|
if (types == TYPE_INT)
|
||||||
sprintf(value, "%"PRId64,
|
sprintf(value, "%"PRId64,
|
||||||
git_config_int64(key_, value_ ? value_ : ""));
|
git_config_int64(key_, value_ ? value_ : ""));
|
||||||
@ -144,16 +139,17 @@ static int format_config(struct strbuf *buf, const char *key_, const char *value
|
|||||||
} else {
|
} else {
|
||||||
/* Just show the key name */
|
/* Just show the key name */
|
||||||
vptr = "";
|
vptr = "";
|
||||||
must_print_delim = 0;
|
must_add_delim = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (must_print_delim)
|
if (must_add_delim)
|
||||||
strbuf_addch(buf, key_delim);
|
strbuf_addch(buf, key_delim);
|
||||||
strbuf_addstr(buf, vptr);
|
strbuf_addstr(buf, vptr);
|
||||||
strbuf_addch(buf, term);
|
|
||||||
|
|
||||||
if (must_free_vptr)
|
if (must_free_vptr)
|
||||||
free((char *)vptr);
|
free((char *)vptr);
|
||||||
|
}
|
||||||
|
strbuf_addch(buf, term);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user