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>

Lucas Seiki Oshiro committed Feb 25, 2026 at 13:32 UTC 7377a6ef6b9cec293a3f65be7499d5e5ee9c3fae
1 file changed +6 -7
builtin/repo.c
+6 -7
@@ -78,14 +78,15 @@ static int repo_info_field_cmp(const void *va, const void *vb)
78 return strcmp(a->key, b->key);
79 }
80
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)
82 {
83 const struct field search_key = { key, NULL };
84 const struct field *found = bsearch(&search_key, repo_info_field,
85 ARRAY_SIZE(repo_info_field),
86 sizeof(*found),
87 repo_info_field_cmp);
88 - return found ? found->get_value : NULL;
88 +
89 + return found;
90 }
91
92 static void print_field(enum output_format format, const char *key,
@@ -113,18 +114,16 @@ static int print_fields(int argc, const char **argv,
114 struct strbuf valbuf = STRBUF_INIT;
115
116 for (int i = 0; i < argc; i++) {
116 - get_value_fn *get_value;
117 const char *key = argv[i];
118 + const struct field *field = get_repo_info_field(key);
119
119 - get_value = get_value_fn_for_key(key);
120 -
121 - if (!get_value) {
120 + if (!field) {
121 ret = error(_("key '%s' not found"), key);
122 continue;
123 }
124
125 strbuf_reset(&valbuf);
127 - get_value(repo, &valbuf);
126 + field->get_value(repo, &valbuf);
127 print_field(format, key, valbuf.buf);
128 }
129