From b40080b847db4caa2c5a84931046a416fccbe7f4 Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Fri, 14 Aug 2026 09:31:39 -1000 Subject: Rework the diffstat rows and their summary --- source/ui-diff.c | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) (limited to 'source') diff --git a/source/ui-diff.c b/source/ui-diff.c index f0ad58a..6b6b30f 100644 --- a/source/ui-diff.c +++ b/source/ui-diff.c @@ -79,6 +79,19 @@ static void release_bodies(void) strbuf_release(&items[i].body); } +/* + * One bar segment of the per-file diffstat graph. The width is printed from + * integers so that a locale with a comma decimal separator, which a Lua + * filter can install mid-process, cannot render the declaration invalid. + */ +static void print_graph_cell(const char *class, int count, int scale) +{ + int tenths = (int)(count * 1000.0 / scale + 0.5); + + htmlf("", + class, tenths / 10, tenths % 10); +} + static void print_fileinfo(struct fileinfo *info) { int scale = max_changes ? max_changes : 1; @@ -139,20 +152,17 @@ static void print_fileinfo(struct fileinfo *info) } html(""); if (info->binary) { - htmlf("bin%ld -> %ld bytes", + htmlf("bin%lu -> %lu bytes\n", info->old_size, info->new_size); return; } htmlf("%d", info->added + info->removed); html(""); - htmlf("", - max_changes > 100 ? 100 : max_changes); - htmlf("\n"); } @@ -465,11 +475,13 @@ static void print_diffstat(const struct object_id *old_oid, ctx.qry.ignorews); for (i = 0; i < files; i++) print_fileinfo(&items[i]); - html("
", - info->added * 100.0 / scale); - htmlf("", - info->removed * 100.0 / scale); - htmlf("", - (max_changes - info->removed - info->added) * 100.0 / scale); + html(""); + print_graph_cell("add", info->added, scale); + print_graph_cell("rem", info->removed, scale); + print_graph_cell("none", max_changes - info->removed - info->added, + scale); html("
"); + html("\n"); html("
"); - htmlf("%d files changed, %d insertions, %d deletions", - files, total_adds, total_rems); - html("
"); + htmlf("%d file%s changed, %d insertion%s, %d deletion%s", + files, files == 1 ? "" : "s", + total_adds, total_adds == 1 ? "" : "s", + total_rems, total_rems == 1 ? "" : "s"); + html("\n"); } static int over_line_cap(int idx) -- cgit v2.8.0