Skip to content

Commit ddb3231

Browse files
lucasoshirogitster
authored andcommitted
repo: replace get_value_fn_for_key by get_repo_info_field
Remove the function `get_value_fn_for_key`, which returns a function that retrieves a value for a certain repo info key. Introduce `get_repo_info_field` instead, which returns a struct field. This refactor makes the structure of the function print_fields more consistent to the function print_all_fields, improving its readability. Signed-off-by: Lucas Seiki Oshiro <lucasseikioshiro@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent f453ac3 commit ddb3231

1 file changed

Lines changed: 6 additions & 7 deletions

File tree

builtin/repo.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,15 @@ static int repo_info_field_cmp(const void *va, const void *vb)
7878
return strcmp(a->key, b->key);
7979
}
8080

81-
static get_value_fn *get_value_fn_for_key(const char *key)
81+
static const struct field *get_repo_info_field(const char *key)
8282
{
8383
const struct field search_key = { key, NULL };
8484
const struct field *found = bsearch(&search_key, repo_info_field,
8585
ARRAY_SIZE(repo_info_field),
8686
sizeof(*found),
8787
repo_info_field_cmp);
88-
return found ? found->get_value : NULL;
88+
89+
return found;
8990
}
9091

9192
static void print_field(enum output_format format, const char *key,
@@ -113,18 +114,16 @@ static int print_fields(int argc, const char **argv,
113114
struct strbuf valbuf = STRBUF_INIT;
114115

115116
for (int i = 0; i < argc; i++) {
116-
get_value_fn *get_value;
117117
const char *key = argv[i];
118+
const struct field *field = get_repo_info_field(key);
118119

119-
get_value = get_value_fn_for_key(key);
120-
121-
if (!get_value) {
120+
if (!field) {
122121
ret = error(_("key '%s' not found"), key);
123122
continue;
124123
}
125124

126125
strbuf_reset(&valbuf);
127-
get_value(repo, &valbuf);
126+
field->get_value(repo, &valbuf);
128127
print_field(format, key, valbuf.buf);
129128
}
130129

0 commit comments

Comments
 (0)