]> git.ipfire.org Git - thirdparty/git.git/commitdiff
log-tree: use decimal_width()
authorRené Scharfe <l.s.r@web.de>
Sat, 3 Aug 2024 12:33:24 +0000 (14:33 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 5 Aug 2024 15:59:40 +0000 (08:59 -0700)
Reduce code duplication by calling decimal_width() to count the digits
in the number of commits instead of calculating it locally.

It also has the advantage of returning int, which is the exact type
expected by the printf()-like function strbuf_addf() for field width
arguments.

Additionally, decimal_width() supports numbers bigger than 1410065407,
which is (hopefully) just a theoretical advantage.

Signed-off-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
log-tree.c

index 337b9334cdbafe0d3ffd2bf2fd36898f6d112410..0b0c63d5c2a90d21b175497623bac777a7ac17a1 100644 (file)
@@ -29,6 +29,7 @@
 #include "tree.h"
 #include "wildmatch.h"
 #include "write-or-die.h"
+#include "pager.h"
 
 static struct decoration name_decoration = { "object names" };
 static int decoration_loaded;
@@ -406,16 +407,6 @@ void show_decorations(struct rev_info *opt, struct commit *commit)
        strbuf_release(&sb);
 }
 
-static unsigned int digits_in_number(unsigned int number)
-{
-       unsigned int i = 10, result = 1;
-       while (i <= number) {
-               i *= 10;
-               result++;
-       }
-       return result;
-}
-
 void fmt_output_subject(struct strbuf *filename,
                        const char *subject,
                        struct rev_info *info)
@@ -459,7 +450,7 @@ void fmt_output_email_subject(struct strbuf *sb, struct rev_info *opt)
                strbuf_addf(sb, "Subject: [%s%s%0*d/%d] ",
                            opt->subject_prefix,
                            *opt->subject_prefix ? " " : "",
-                           digits_in_number(opt->total),
+                           decimal_width(opt->total),
                            opt->nr, opt->total);
        } else if (opt->total == 0 && opt->subject_prefix && *opt->subject_prefix) {
                strbuf_addf(sb, "Subject: [%s] ",