From: Lucas Seiki Oshiro Date: Mon, 20 Oct 2025 16:19:45 GMT Subject: [PATCH v2 0/2] repo: add --all to repo-info Message-ID: <20251020181943.6314-1-lucasseikioshiro@gmail.com> Hi! The main change introduced in this v2 is that now `git repo info --all ` returns the values for all the available keys plus the value of `` (which will be duplicated). If `` is an invalid key, the command will proceed the same way that it would do without the `--all` flag. PS: Sorry for sending this v2 after a month. I've been really busy last weeks, but I still want to finish this :-) Here's the rangediff against v1: -: ---------- > 1: 5f72f07589 repo: factor out field printing to dedicated function 1: 94c7b835f0 ! 2: b8158bb7b8 repo: add --all to git-repo-info @@ Metadata ## Commit message ## repo: add --all to git-repo-info - Add a new flag `--all` to git-repo-info for requesting all the available - keys. By using this flag, the user can retrieve all the values instead - of searching what are the desired keys for what they wants. + Add a new flag `--all` to git-repo-info for requesting values for all + the available keys. By using this flag, the user can retrieve all the + values instead of searching what are the desired keys for what they + wants. Helped-by: Karthik Nayak Helped-by: Patrick Steinhardt @@ 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 info [--format=(keyvalue|nul)] [-z] [--all | ...] DESCRIPTION ----------- @@ Documentation/git-repo.adoc: THIS COMMAND IS EXPERIMENTAL. THE BEHAVIOR MAY CHAN COMMANDS -------- -`info [--format=(keyvalue|nul)] [-z] [...]`:: -+`info [--format=(keyvalue|nul)] [-z] [--all] [...]`:: ++`info [--format=(keyvalue|nul)] [-z] [--all | ...]`:: Retrieve metadata-related information about the current repository. Only the requested data will be returned based on their keys (see "INFO KEYS" section below). + The values are returned in the same order in which their respective keys were -requested. -+requested. The `--all` flag requests all keys. ++requested. The `--all` flag requests the values for all the available keys. ++Keys requested after `--all` will be duplicated. + The output format can be chosen through the flag `--format`. Two formats are supported: @@ builtin/repo.c static const char *const repo_usage[] = { - "git repo info [--format=(keyvalue|nul)] [-z] [...]", -+ "git repo info [--format=(keyvalue|nul)] [-z] [--all] [...]", ++ "git repo info [--format=(keyvalue|nul)] [-z] [--all | ...]", NULL }; -@@ builtin/repo.c: 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) -@@ builtin/repo.c: static int print_fields(int argc, const char **argv, - } - - strbuf_reset(&valbuf); -- strbuf_reset("buf); -- - get_value(repo, &valbuf); -- -- switch (format) { -- case FORMAT_KEYVALUE: -- quote_c_style(valbuf.buf, "buf, 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, "buf); - } - - strbuf_release(&valbuf); @@ builtin/repo.c: static int print_fields(int argc, const char **argv, return ret; } @@ builtin/repo.c: static int repo_info(int argc, const char **argv, const char *pr argc = parse_options(argc, argv, prefix, options, repo_usage, 0); -+ if (all_keys) { ++ if (all_keys) + print_all_fields(repo, format); -+ return 0; -+ } + return print_fields(argc, argv, repo, format); } ## t/t1900-repo.sh ## +@@ t/t1900-repo.sh: test_description='test git repo-info' + + . ./test-lib.sh + ++# git-repo-info keys. It must contain the same keys listed in the const ++# repo_info_fields, in lexicographical order. ++REPO_INFO_KEYS=' ++ layout.bare ++ layout.shallow ++ object.format ++ references.format ++' ++ + # Test whether a key-value pair is correctly returned + # + # Usage: test_repo_info