Re: [GSoC PATCH v7 5/5] repo: add the --format flag
From: Patrick Steinhardt <hidden>
Date: 2025-08-05 12:50:40
On Fri, Aug 01, 2025 at 10:11:10AM -0300, Lucas Seiki Oshiro wrote:
quoted hunk ↗ jump to hunk
diff --git a/Documentation/git-repo.adoc b/Documentation/git-repo.adoc index 140ee3a0aa..b735cf4737 100644 --- a/Documentation/git-repo.adoc +++ b/Documentation/git-repo.adoc@@ -18,12 +18,23 @@ THIS COMMAND IS EXPERIMENTAL. THE BEHAVIOR MAY CHANGE. COMMANDS -------- -`info [<key>...]`:: +`info [--format=<keyvalue|nul>] [<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 returned data is lexicographically sorted by the keys. ++ +The output format can be chosen through the flag `--format`. Two formats are +supported: ++ +* `keyvalue`: output key-value pairs one per line using the `=` character as +the delimiter between the key and the value. This is the default.
Let's also mention that the value will be C-quoted.
+* `nul`: similar to `keyvalue`, but using a newline character as the delimiter +between the key and the value and using a null character after each value. +This format is better suited for being parsed by another applications than +`keyvalue`.
And here we can then explicitly say that it's not quoted.
quoted hunk ↗ jump to hunk
diff --git a/builtin/repo.c b/builtin/repo.c index 56c3a4027f..4015cf88b7 100644 --- a/builtin/repo.c +++ b/builtin/repo.c@@ -74,18 +79,33 @@ static int qsort_strcmp(const void *va, const void *vb) return strcmp(a, b); } -static int print_fields(int argc, const char **argv, struct repository *repo) +static int print_fields(int argc, const char **argv, + struct repository *repo, + enum output_format format) { int ret = 0; const char *last = ""; struct strbuf sb = STRBUF_INIT; + char kv_sep; + char field_sep;
Nit: we don't usually have newlines between variable declarations. Patrick