Skip to content

Commit 0c4d5aa

Browse files
rscharfegitster
authored andcommitted
log-tree: use decimal_width()
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 337b4d4 commit 0c4d5aa

File tree

1 file changed

+2
-11
lines changed

1 file changed

+2
-11
lines changed

log-tree.c

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "tree.h"
3030
#include "wildmatch.h"
3131
#include "write-or-die.h"
32+
#include "pager.h"
3233

3334
static struct decoration name_decoration = { "object names" };
3435
static int decoration_loaded;
@@ -406,16 +407,6 @@ void show_decorations(struct rev_info *opt, struct commit *commit)
406407
strbuf_release(&sb);
407408
}
408409

409-
static unsigned int digits_in_number(unsigned int number)
410-
{
411-
unsigned int i = 10, result = 1;
412-
while (i <= number) {
413-
i *= 10;
414-
result++;
415-
}
416-
return result;
417-
}
418-
419410
void fmt_output_subject(struct strbuf *filename,
420411
const char *subject,
421412
struct rev_info *info)
@@ -459,7 +450,7 @@ void fmt_output_email_subject(struct strbuf *sb, struct rev_info *opt)
459450
strbuf_addf(sb, "Subject: [%s%s%0*d/%d] ",
460451
opt->subject_prefix,
461452
*opt->subject_prefix ? " " : "",
462-
digits_in_number(opt->total),
453+
decimal_width(opt->total),
463454
opt->nr, opt->total);
464455
} else if (opt->total == 0 && opt->subject_prefix && *opt->subject_prefix) {
465456
strbuf_addf(sb, "Subject: [%s] ",

0 commit comments

Comments
 (0)