aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLucas Seiki Oshiro <lucasseikioshiro@gmail.com>2025-10-26 19:52:07 -0300
committerJunio C Hamano <gitster@pobox.com>2025-10-26 16:35:12 -0700
commit4a3348aaf7ebadd5abebedbc68f7f627b137b308 (patch)
treeaa7fef2977c14dca6bbe20ece761b993a3c7262c
parentRelNotes: sync with Git 2.51.1 fixups (diff)
downloadgit-4a3348aaf7ebadd5abebedbc68f7f627b137b308.tar.gz
git-4a3348aaf7ebadd5abebedbc68f7f627b137b308.zip
repo: factor out field printing to dedicated function
Move the field printing in git-repo-info to a new function called `print_field`, allowing it to be called by functions other than `print_fields`. Signed-off-by: Lucas Seiki Oshiro <lucasseikioshiro@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--builtin/repo.c33
1 files changed, 19 insertions, 14 deletions
diff --git a/builtin/repo.c b/builtin/repo.c
index bbb0966f2d..3b071e9a50 100644
--- a/builtin/repo.c
+++ b/builtin/repo.c
@@ -77,6 +77,24 @@ static get_value_fn *get_value_fn_for_key(const char *key)
return found ? found->get_value : NULL;
}
+static void print_field(enum output_format format, const char *key,
+ struct strbuf *valbuf, struct strbuf *quotbuf)
+{
+ strbuf_reset(quotbuf);
+
+ switch (format) {
+ case FORMAT_KEYVALUE:
+ quote_c_style(valbuf->buf, quotbuf, NULL, 0);
+ printf("%s=%s\n", key, quotbuf->buf);
+ break;
+ case FORMAT_NUL_TERMINATED:
+ printf("%s\n%s%c", key, valbuf->buf, '\0');
+ break;
+ default:
+ BUG("not a valid output format: %d", format);
+ }
+}
+
static int print_fields(int argc, const char **argv,
struct repository *repo,
enum output_format format)
@@ -97,21 +115,8 @@ static int print_fields(int argc, const char **argv,
}
strbuf_reset(&valbuf);
- strbuf_reset(&quotbuf);
-
get_value(repo, &valbuf);
-
- switch (format) {
- case FORMAT_KEYVALUE:
- quote_c_style(valbuf.buf, &quotbuf, NULL, 0);
- printf("%s=%s\n", key, quotbuf.buf);
- break;
- case FORMAT_NUL_TERMINATED:
- printf("%s\n%s%c", key, valbuf.buf, '\0');
- break;
- default:
- BUG("not a valid output format: %d", format);
- }
+ print_field(format, key, &valbuf, &quotbuf);
}
strbuf_release(&valbuf);