pretty.c: add %(count) and %(total) placeholders

In many commands we can customize the output through the "--format" or the "--pretty" options. This patch adds two new placeholders used mainly when there's a range of commits that we want to show. Currently these two placeholders are not usable as they're coupled with the rev_info->nr and rev_info->total fields, fields that are used only by the format-patch numbered email subjects. Teach repo_format_commit_message() the %(count) and %(total) placeholders. Signed-off-by: Mirko Faina <mroik@delayed.space> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Mirko Faina committed Mar 7, 2026 at 00:34 UTC 9ccd9e6fcab2573a04b24f81d96cfdc355a7d51f
1 file changed +15
pretty.c
+15
@@ -1549,6 +1549,21 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
1549 if (!commit->object.parsed)
1550 parse_object(the_repository, &commit->object.oid);
1551
1552 + if (starts_with(placeholder, "(count)")) {
1553 + if (!c->pretty_ctx->rev)
1554 + die(_("this format specifier can't be used with this command"));
1555 + strbuf_addf(sb, "%0*d", decimal_width(c->pretty_ctx->rev->total),
1556 + c->pretty_ctx->rev->nr);
1557 + return 7;
1558 + }
1559 +
1560 + if (starts_with(placeholder, "(total)")) {
1561 + if (!c->pretty_ctx->rev)
1562 + die(_("this format specifier can't be used with this command"));
1563 + strbuf_addf(sb, "%d", c->pretty_ctx->rev->total);
1564 + return 7;
1565 + }
1566 +
1567 switch (placeholder[0]) {
1568 case 'H': /* commit hash */
1569 strbuf_addstr(sb, diff_get_color(c->auto_color, DIFF_COMMIT));