aboutsummaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
authorLucas Seiki Oshiro <lucasseikioshiro@gmail.com>2026-02-25 13:32:12 -0300
committerJunio C Hamano <gitster@pobox.com>2026-02-25 11:47:42 -0800
commit7377a6ef6b9cec293a3f65be7499d5e5ee9c3fae (patch)
tree151ffbdd0a9fc319312c3d5cd618f7e4dd71f491 /builtin
parent3d4e6d319383d31b319227ed099a7dbd0706e165 (diff)
downloadgit-7377a6ef6b9cec293a3f65be7499d5e5ee9c3fae.tar.xz
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>
Diffstat (limited to 'builtin')
-rw-r--r--builtin/repo.c13
1 files changed, 6 insertions, 7 deletions
diff --git a/builtin/repo.c b/builtin/repo.c
index aa9a154cd2..c60a41ba7b 100644
--- a/builtin/repo.c
+++ b/builtin/repo.c
@@ -78,14 +78,15 @@ static int repo_info_field_cmp(const void *va, const void *vb)
return strcmp(a->key, b->key);
}
-static get_value_fn *get_value_fn_for_key(const char *key)
+static const struct field *get_repo_info_field(const char *key)
{
const struct field search_key = { key, NULL };
const struct field *found = bsearch(&search_key, repo_info_field,
ARRAY_SIZE(repo_info_field),
sizeof(*found),
repo_info_field_cmp);
- return found ? found->get_value : NULL;
+
+ return found;
}
static void print_field(enum output_format format, const char *key,
@@ -113,18 +114,16 @@ static int print_fields(int argc, const char **argv,
struct strbuf valbuf = STRBUF_INIT;
for (int i = 0; i < argc; i++) {
- get_value_fn *get_value;
const char *key = argv[i];
+ const struct field *field = get_repo_info_field(key);
- get_value = get_value_fn_for_key(key);
-
- if (!get_value) {
+ if (!field) {
ret = error(_("key '%s' not found"), key);
continue;
}
strbuf_reset(&valbuf);
- get_value(repo, &valbuf);
+ field->get_value(repo, &valbuf);
print_field(format, key, valbuf.buf);
}