Hi!
The main change introduced in this v2 is that now `git repo info --all <some.key>` returns the values for all the available keys plus the value of `<some.key>` (which will be duplicated). If `<some.key>` 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 <karthik.188@gmail.com>
Helped-by: Patrick Steinhardt <ps@pks.im>
@@ Documentation/git-repo.adoc: git-repo - Retrieve information about the repositor
--------
[synopsis]
-git repo info [--format=(keyvalue|nul)] [-z] [<key>...]
-+git repo info [--format=(keyvalue|nul)] [-z] [--all] [<key>...]
++git repo info [--format=(keyvalue|nul)] [-z] [--all | <key>...]
DESCRIPTION
-----------
@@ Documentation/git-repo.adoc: THIS COMMAND IS EXPERIMENTAL. THE BEHAVIOR MAY CHAN
COMMANDS
--------
-`info [--format=(keyvalue|nul)] [-z] [<key>...]`::
-+`info [--format=(keyvalue|nul)] [-z] [--all] [<key>...]`::
++`info [--format=(keyvalue|nul)] [-z] [--all | <key>...]`::
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] [<key>...]",
-+ "git repo info [--format=(keyvalue|nul)] [-z] [--all] [<key>...]",
++ "git repo info [--format=(keyvalue|nul)] [-z] [--all | <key>...]",
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 <label> <init command> <repo_name> <key> <expected value>
@@ t/t1900-repo.sh: test_expect_success 'git repo info uses the last requested format' '
test_cmp expected actual
'
-+test_expect_success 'git repo info --all returns all fields' '
-+ git repo info layout.bare layout.shallow object.format references.format >expect &&
++test_expect_success 'git repo info --all returns all key-value pairs' '
++ git repo info $REPO_INFO_KEYS >expect &&
+ git repo info --all >actual &&
+ test_cmp expect actual
+'
++
++test_expect_success 'git repo info --all <key> duplicates <key>' '
++ git repo info $REPO_INFO_KEYS object.format >expect &&
++ git repo info --all object.format >actual &&
++ test_cmp expect actual
++'
++
++test_expect_success 'git repo info --all <invalid key> warns about invalid key' '
++ git repo info $REPO_INFO_KEYS >expect &&
++ echo "error: key ${SQ}no.key${SQ} not found" >expect_err &&
++ test_must_fail git repo info --all no.key >actual 2>actual_err &&
++ test_cmp expect actual &&
++ test_cmp expect_err actual_err
++'
+
test_doneLucas Seiki Oshiro (2): repo: factor out field printing to dedicated function repo: add --all to git-repo-info
Documentation/git-repo.adoc | 7 +++-- builtin/repo.c | 60 +++++++++++++++++++++++++++---------- t/t1900-repo.sh | 29 ++++++++++++++++++ 3 files changed, 78 insertions(+), 18 deletions(-)
-- 2.50.1 (Apple Git-155)