From: Lucas Seiki Oshiro Date: Mon, 17 Nov 2025 15:02:50 GMT Subject: [PATCH v4 0/2] repo: add --all to git-repo-info Message-ID: <20251117151844.14802-1-lucasseikioshiro@gmail.com> In-Reply-To: <20250915223618.13093-1-lucasseikioshiro@gmail.com> Hi! Sorry for only sending this after some weeks. I've been busy finishing my master's and I didn't have enough time to send another version. But here it is. This fourth version of this patch addresses the issues pointed by Eric in the v3: - I dropped the `strbuf quotebuf`, since it can be replaced by outputting `quote_c_style` directly to `stdout`; - `print_field` now uses the string `value` instead of the `strbuf valbuf`; - The variable `field` in `print_fields` was replaced by a pointer, since it didn't require to be copied; - replace the help string by the suggested. Lucas Seiki Oshiro (2): repo: factor out field printing to dedicated function repo: add --all to git-repo-info Documentation/git-repo.adoc | 6 ++-- builtin/repo.c | 62 +++++++++++++++++++++++++++---------- t/t1900-repo.sh | 21 +++++++++++++ 3 files changed, 69 insertions(+), 20 deletions(-) Range-diff against v3: 1: 0db9aad2bc ! 1: fce09770b8 repo: factor out field printing to dedicated function @@ builtin/repo.c: static get_value_fn *get_value_fn_for_key(const char *key) } +static void print_field(enum output_format format, const char *key, -+ struct strbuf *valbuf, struct strbuf *quotbuf) ++ const char *value) +{ -+ strbuf_reset(quotbuf); -+ + switch (format) { + case FORMAT_KEYVALUE: -+ quote_c_style(valbuf->buf, quotbuf, NULL, 0); -+ printf("%s=%s\n", key, quotbuf->buf); ++ printf("%s=", key); ++ quote_c_style(value, NULL, stdout, 0); ++ putchar('\n'); + break; + case FORMAT_NUL_TERMINATED: -+ printf("%s\n%s%c", key, valbuf->buf, '\0'); ++ printf("%s\n%s%c", key, value, '\0'); + break; + default: + BUG("not a valid output format: %d", format); @@ builtin/repo.c: static get_value_fn *get_value_fn_for_key(const char *key) static int print_fields(int argc, const char **argv, struct repository *repo, enum output_format format) + { + int ret = 0; + struct strbuf valbuf = STRBUF_INIT; +- struct strbuf quotbuf = STRBUF_INIT; + + for (int i = 0; i < argc; i++) { + get_value_fn *get_value; @@ builtin/repo.c: static int print_fields(int argc, const char **argv, } @@ builtin/repo.c: static int print_fields(int argc, const char **argv, - default: - BUG("not a valid output format: %d", format); - } -+ print_field(format, key, &valbuf, "buf); ++ print_field(format, key, valbuf.buf); } strbuf_release(&valbuf); +- strbuf_release("buf); + return ret; + } + 2: b6ecdc2c2f ! 2: ccdad86123 repo: add --all to git-repo-info @@ Documentation/git-repo.adoc: git-repo - Retrieve information about the repositor [synopsis] -git repo info [--format=(keyvalue|nul)] [-z] [...] +git repo info [--format=(keyvalue|nul)] [-z] [--all | ...] + git repo structure [--format=(table|keyvalue|nul)] DESCRIPTION - ----------- @@ Documentation/git-repo.adoc: THIS COMMAND IS EXPERIMENTAL. THE BEHAVIOR MAY CHANGE. COMMANDS @@ Documentation/git-repo.adoc: THIS COMMAND IS EXPERIMENTAL. THE BEHAVIOR MAY CHAN ## builtin/repo.c ## @@ - #include "shallow.h" + #include "utf8.h" static const char *const repo_usage[] = { - "git repo info [--format=(keyvalue|nul)] [-z] [...]", + "git repo info [--format=(keyvalue|nul)] [-z] [--all | ...]", + "git repo structure [--format=(table|keyvalue|nul)]", NULL }; - @@ builtin/repo.c: static int print_fields(int argc, const char **argv, return ret; } @@ builtin/repo.c: static int print_fields(int argc, const char **argv, + enum output_format format) +{ + struct strbuf valbuf = STRBUF_INIT; -+ struct strbuf quotbuf = STRBUF_INIT; + + for (unsigned long i = 0; i < ARRAY_SIZE(repo_info_fields); i++) { -+ struct field field = repo_info_fields[i]; ++ const struct field *field = &repo_info_fields[i]; + + strbuf_reset(&valbuf); -+ field.get_value(repo, &valbuf); -+ print_field(format, field.key, &valbuf, "buf); ++ field->get_value(repo, &valbuf); ++ print_field(format, field->key, valbuf.buf); + } + + strbuf_release(&valbuf); -+ strbuf_release("buf); +} + static int parse_format_cb(const struct option *opt, const char *arg, int unset UNUSED) { -@@ builtin/repo.c: static int repo_info(int argc, const char **argv, const char *prefix, - struct repository *repo) +@@ builtin/repo.c: static int cmd_repo_info(int argc, const char **argv, const char *prefix, + struct repository *repo) { enum output_format format = FORMAT_KEYVALUE; + int all_keys = 0; struct option options[] = { OPT_CALLBACK_F(0, "format", &format, N_("format"), N_("output format"), -@@ builtin/repo.c: static int repo_info(int argc, const char **argv, const char *prefix, +@@ builtin/repo.c: static int cmd_repo_info(int argc, const char **argv, const char *prefix, N_("synonym for --format=nul"), PARSE_OPT_NONEG | PARSE_OPT_NOARG, parse_format_cb), -+ OPT_BOOL(0, "all", &all_keys, N_("return all keys")), ++ OPT_BOOL(0, "all", &all_keys, N_("print all keys/values")), OPT_END() }; - argc = parse_options(argc, argv, prefix, options, repo_usage, 0); +@@ builtin/repo.c: static int cmd_repo_info(int argc, const char **argv, const char *prefix, + if (format != FORMAT_KEYVALUE && format != FORMAT_NUL_TERMINATED) + die(_("unsupported output format")); + if (all_keys) { + if (argc) -- 2.50.1 (Apple Git-155)