Subject: Re: [PATCH v7 1/5] pretty.c: add %(count) and %(total) placeholders

From: Phillip Wood <[email-masked]>
Date: Tue, 10 Mar 2026 14:32:54 +0000

On 06/03/2026 23:34, Mirko Faina wrote:
> 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

> +		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));