From 51a5cf049e3d21065f9da5cfdcb977ce8eef6fc7 Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Thu, 16 Jul 2026 11:35:38 -1000 Subject: Fix diffstat and submodule diff output The diffstat divided by zero when a commit changed no lines, and a submodule change was printed with a hardcoded length that dropped a digit of a sha-1 and most of a sha-256. --- source/ui-diff.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'source') diff --git a/source/ui-diff.c b/source/ui-diff.c index 6cfa697..04bbecc 100644 --- a/source/ui-diff.c +++ b/source/ui-diff.c @@ -117,11 +117,11 @@ static void print_fileinfo(struct fileinfo *info) html(""); htmlf("", (max_changes > 100 ? 100 : max_changes)); htmlf("
", - info->added * 100.0 / max_changes); + info->added * 100.0 / (max_changes ? max_changes : 1)); htmlf("", - info->removed * 100.0 / max_changes); + info->removed * 100.0 / (max_changes ? max_changes : 1)); htmlf("", - (max_changes - info->removed - info->added) * 100.0 / max_changes); + (max_changes - info->removed - info->added) * 100.0 / (max_changes ? max_changes : 1)); html("
\n"); } @@ -314,10 +314,14 @@ static void filepair_cb(struct diff_filepair *pair) if (use_ssdiff) cgit_ssdiff_header_end(); if (S_ISGITLINK(pair->one->mode) || S_ISGITLINK(pair->two->mode)) { - if (S_ISGITLINK(pair->one->mode)) - print_line_fn(fmt("-Subproject %s", oid_to_hex(&pair->one->oid)), 52); - if (S_ISGITLINK(pair->two->mode)) - print_line_fn(fmt("+Subproject %s", oid_to_hex(&pair->two->oid)), 52); + if (S_ISGITLINK(pair->one->mode)) { + char *l = fmt("-Subproject %s", oid_to_hex(&pair->one->oid)); + print_line_fn(l, strlen(l) + 1); + } + if (S_ISGITLINK(pair->two->mode)) { + char *l = fmt("+Subproject %s", oid_to_hex(&pair->two->oid)); + print_line_fn(l, strlen(l) + 1); + } if (use_ssdiff) cgit_ssdiff_footer(); return; -- cgit v2.8.0