{"thread":{"id":"61896","subject":"[PATCH] log-tree: use decimal_width()","startedAt":"2024-08-03T12:33:32Z","lastAt":"2024-08-05T16:03:11Z","messageCount":3,"participants":["René Scharfe","Taylor Blau","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"499999","messageId":"06783722-5184-41d5-8edd-94f97b2f2794@web.de","threadId":"61896","inReplyTo":null,"subject":"[PATCH] log-tree: use decimal_width()","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2024-08-03T12:33:24Z","receivedAt":"2024-08-03T12:33:32Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Reduce code duplication by calling decimal_width() to count the digits\nin the number of commits instead of calculating it locally.\n\nIt also has the advantage of returning int, which is the exact type\nexpected by the printf()-like function strbuf_addf() for field width\narguments.\n\nAdditionally, decimal_width() supports numbers bigger than 1410065407,\nwhich is (hopefully) just a theoretical advantage.\n\nSigned-off-by: René Scharfe <l.s.r@web.de>\n---\n log-tree.c | 13 ++-----------\n 1 file changed, 2 insertions(+), 11 deletions(-)\n\ndiff --git a/log-tree.c b/log-tree.c\nindex 576ef30d90..fdb24cbef2 100644\n--- a/log-tree.c\n+++ b/log-tree.c\n@@ -31,6 +31,7 @@\n #include \"tree.h\"\n #include \"wildmatch.h\"\n #include \"write-or-die.h\"\n+#include \"pager.h\"\n\n static struct decoration name_decoration = { \"object names\" };\n static int decoration_loaded;\n@@ -411,16 +412,6 @@ void show_decorations(struct rev_info *opt, struct commit *commit)\n \tstrbuf_release(&sb);\n }\n\n-static unsigned int digits_in_number(unsigned int number)\n-{\n-\tunsigned int i = 10, result = 1;\n-\twhile (i <= number) {\n-\t\ti *= 10;\n-\t\tresult++;\n-\t}\n-\treturn result;\n-}\n-\n void fmt_output_subject(struct strbuf *filename,\n \t\t\tconst char *subject,\n \t\t\tstruct rev_info *info)\n@@ -464,7 +455,7 @@ void fmt_output_email_subject(struct strbuf *sb, struct rev_info *opt)\n \t\tstrbuf_addf(sb, \"Subject: [%s%s%0*d/%d] \",\n \t\t\t    opt->subject_prefix,\n \t\t\t    *opt->subject_prefix ? \" \" : \"\",\n-\t\t\t    digits_in_number(opt->total),\n+\t\t\t    decimal_width(opt->total),\n \t\t\t    opt->nr, opt->total);\n \t} else if (opt->total == 0 && opt->subject_prefix && *opt->subject_prefix) {\n \t\tstrbuf_addf(sb, \"Subject: [%s] \",\n--\n2.46.0\n"},{"id":"500027","messageId":"Zq+oEby6ew3HrWFK@nand.local","threadId":"61896","inReplyTo":"06783722-5184-41d5-8edd-94f97b2f2794@web.de","subject":"Re: [PATCH] log-tree: use decimal_width()","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2024-08-04T16:10:57Z","receivedAt":"2024-08-04T16:11:00Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"On Sat, Aug 03, 2024 at 02:33:24PM +0200, René Scharfe wrote:\n> ---\n>  log-tree.c | 13 ++-----------\n>  1 file changed, 2 insertions(+), 11 deletions(-)\n\nThis looks all very reasonable to me.\n\nSome history (if interesting): lineno_width(), which was the precursor\nto decimal_width() was introduced way back in cee7f245dc (git-pickaxe:\nblame rewritten., 2006-10-19). The piece this patch removes was added in\ne00de24b10 (format-patch -n: make sorting easier by padding number,\n2007-02-09), but lineno_width() did not become part of pager.h until\nec7ff5ba27 (make lineno_width() from blame reusable for others,\n2012-02-12), hence why it wasn't already used here.\n\nThanks,\nTaylor\n"},{"id":"500095","messageId":"xmqqh6bz3qkj.fsf@gitster.g","threadId":"61896","inReplyTo":"Zq+oEby6ew3HrWFK@nand.local","subject":"Re: [PATCH] log-tree: use decimal_width()","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2024-08-05T16:03:08Z","receivedAt":"2024-08-05T16:03:11Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Taylor Blau <me@ttaylorr.com> writes:\n\n> On Sat, Aug 03, 2024 at 02:33:24PM +0200, René Scharfe wrote:\n>> ---\n>>  log-tree.c | 13 ++-----------\n>>  1 file changed, 2 insertions(+), 11 deletions(-)\n>\n> This looks all very reasonable to me.\n>\n> Some history (if interesting): lineno_width(), which was the precursor\n> to decimal_width() was introduced way back in cee7f245dc (git-pickaxe:\n> blame rewritten., 2006-10-19). The piece this patch removes was added in\n> e00de24b10 (format-patch -n: make sorting easier by padding number,\n> 2007-02-09), but lineno_width() did not become part of pager.h until\n> ec7ff5ba27 (make lineno_width() from blame reusable for others,\n> 2012-02-12), hence why it wasn't already used here.\n\nThanks.\n\nI was wondering why the decimal_width() helper is in pager.c in the\nfirst place, as there is no logical reason to tie it to the pager\ninfrastructure.\n"}]}