Re: [PATCH 3/4] builtin/repo: add keyvalue format for stats
- From
Karthik Nayak <karthik.188@gmail.com>
- Date
- Sep 23, 2025, 15:39 UTC
- Message-ID
- <CAOLa=ZT0y-WOOFz8FdLm40AqwEATzNsg2fzvnJKPzx2mkPiz-g@mail.gmail.com>
- In-Reply-To
- <20250923025700.3046260-4-jltobler@gmail.com>
Justin Tobler <jltobler@gmail.com> writes:
[snip]
Show 34 quoted lines
> diff --git a/Documentation/git-repo.adoc b/Documentation/git-repo.adoc > index 2a67abfca8..7d0341e4f1 100644 > --- a/Documentation/git-repo.adoc > +++ b/Documentation/git-repo.adoc > @@ -9,7 +9,7 @@ SYNOPSIS > -------- > [synopsis] > git repo info [--format=(keyvalue|nul)] [-z] [<key>...] > -git repo stats > +git repo stats [--format=(table|keyvalue)] > > DESCRIPTION > ----------- > @@ -44,12 +44,22 @@ supported: > + > `-z` is an alias for `--format=nul`. > > -stats:: > +`stats [--format=(table|keyvalue)]`:: > Retrieve stats about the current repository. All references and > reachable objects in the repository are categorized and counted > accordingly. > + > -The table output format may change and is not intended for machine parsing. > +The output format can be chosen through the flag `--format`. Two formats are > +supported: > ++ > +`table`::: > + Outputs repository stats in a human-friendly table and is used by > + default. This format may change and is not intended for machine > + parsing. > + > +`keyvalue`::: > + Each line of output contains a key-value pair of a repostiory stat. The
s/repostiory/repository
> + '=' character is used to delimit between the key and the value. >
Does each value end with a newline or with a NUL? We should mention that here.
[snip]
Show 26 quoted lines
> +static void stats_print(struct stats *stats)
> +{
> + struct strbuf buf = STRBUF_INIT;
> +
> + strbuf_addf(&buf, "references.branches.count=%" PRIuMAX "\n",
> + (uintmax_t)stats->refs.branches);
> + strbuf_addf(&buf, "references.tags.count=%" PRIuMAX "\n",
> + (uintmax_t)stats->refs.tags);
> + strbuf_addf(&buf, "references.remotes.count=%" PRIuMAX "\n",
> + (uintmax_t)stats->refs.remotes);
> + strbuf_addf(&buf, "references.others.count=%" PRIuMAX "\n",
> + (uintmax_t)stats->refs.others);
> +
> + strbuf_addf(&buf, "objects.commits.count=%" PRIuMAX "\n",
> + (uintmax_t)stats->objects.commits);
> + strbuf_addf(&buf, "objects.trees.count=%" PRIuMAX "\n",
> + (uintmax_t)stats->objects.trees);
> + strbuf_addf(&buf, "objects.blobs.count=%" PRIuMAX "\n",
> + (uintmax_t)stats->objects.blobs);
> + strbuf_addf(&buf, "objects.tags.count=%" PRIuMAX "\n",
> + (uintmax_t)stats->objects.tags);
> +
> + fwrite(buf.buf, sizeof(char), buf.len, stdout);
> + strbuf_release(&buf);
> +}
> +Okay so newline delimeted, similar to 'git repo info'.
Show 30 quoted lines
> static void stats_count_references(struct ref_stats *stats, struct ref_array *refs)
> {
> for (int i = 0; i < refs->nr; i++) {
> @@ -359,9 +390,16 @@ static void stats_count_objects(struct object_stats *stats,
> path_walk_info_clear(&info);
> }
>
> -static int repo_stats(int argc UNUSED, const char **argv UNUSED,
> - const char *prefix, struct repository *repo)
> +static int repo_stats(int argc, const char **argv, const char *prefix,
> + struct repository *repo)
> {
> + enum output_format format = FORMAT_TABLE;
> + struct option options[] = {
> + OPT_CALLBACK_F(0, "format", &format, N_("format"),
> + N_("output format"),
> + PARSE_OPT_NONEG, parse_format_cb),
> + OPT_END()
> + };
> struct ref_filter filter = REF_FILTER_INIT;
> struct strvec ref_patterns = STRVEC_INIT;
> struct stats_table table = { 0 };
> @@ -369,6 +407,10 @@ static int repo_stats(int argc UNUSED, const char **argv UNUSED,
> struct stats stats = { 0 };
> struct rev_info revs;
>
> + parse_options(argc, argv, prefix, options, repo_usage, 0);
> + if (format == FORMAT_NUL_TERMINATED)
> + die(_("nul format not yet supported"));
> +Okay I forsee the next patch adding this support.
The patch looks good!
[snip]