Re: [PATCH v7 1/5] pretty.c: add %(count) and %(total) placeholders
- From
- Phillip Wood <phillip.wood123@gmail.com>
- Date
- Mar 10, 2026, 14:32 UTC
- Message-ID
- <8855efd5-a53a-47fc-8708-4cd6d416e441@gmail.com>
- In-Reply-To
- <cfed3bddf66ed2fab1f4da896759de1ba086578f.1772839973.git.mroik@delayed.space>
On 06/03/2026 23:34, Mirko Faina wrote:
Show 11 quoted lines
> diff --git a/pretty.c b/pretty.c
> index e0646bbc5d..e29bb8b877 100644
> --- a/pretty.c
> +++ b/pretty.c
> @@ -1549,6 +1549,21 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
> if (!commit->object.parsed)
> parse_object(the_repository, &commit->object.oid);
>
> + if (starts_with(placeholder, "(count)")) {
> + if (!c->pretty_ctx->rev)
> + die(_("this format specifier can't be used with this command"));From the user's point of view it would be more helpful if this message told them which format specifier isn't supported
die(_("%s is not supported by this command"), "%(count)");Normally we do not add code that cannot be exercised so you may want to squash this change into a later patch that adds support and documentation for the new specifiers.
Thanks
Phillip
Show 15 quoted lines
> + strbuf_addf(sb, "%0*d", decimal_width(c->pretty_ctx->rev->total),
> + c->pretty_ctx->rev->nr);
> + return 7;
> + }
> +
> + if (starts_with(placeholder, "(total)")) {
> + if (!c->pretty_ctx->rev)
> + die(_("this format specifier can't be used with this command"));
> + strbuf_addf(sb, "%d", c->pretty_ctx->rev->total);
> + return 7;
> + }
> +
> switch (placeholder[0]) {
> case 'H': /* commit hash */
> strbuf_addstr(sb, diff_get_color(c->auto_color, DIFF_COMMIT));