]> git.ipfire.org Git - thirdparty/git.git/commitdiff
pretty.c: add %(count) and %(total) placeholders
authorMirko Faina <mroik@delayed.space>
Fri, 6 Mar 2026 23:34:40 +0000 (00:34 +0100)
committerJunio C Hamano <gitster@pobox.com>
Sat, 7 Mar 2026 01:16:44 +0000 (17:16 -0800)
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>
pretty.c

index e0646bbc5d49cc6b792c4e826b4022282ac7179b..e29bb8b877411d074eacf693dfd07185b106f46d 100644 (file)
--- 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"));
+               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));