git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] log-tree: use decimal_width()
@ 2024-08-03 12:33 René Scharfe
  2024-08-04 16:10 ` Taylor Blau
  0 siblings, 1 reply; 3+ messages in thread
From: René Scharfe @ 2024-08-03 12:33 UTC (permalink / raw)
  To: Git List

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>
---
 log-tree.c | 13 ++-----------
 1 file changed, 2 insertions(+), 11 deletions(-)

diff --git a/log-tree.c b/log-tree.c
index 576ef30d90..fdb24cbef2 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -31,6 +31,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;
@@ -411,16 +412,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)
@@ -464,7 +455,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] ",
--
2.46.0

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-08-05 16:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-03 12:33 [PATCH] log-tree: use decimal_width() René Scharfe
2024-08-04 16:10 ` Taylor Blau
2024-08-05 16:03   ` Junio C Hamano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).