diff options
| -rw-r--r-- | source/ui-diff.c | 38 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| -rwxr-xr-x | tests/t0105-commit.sh | 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2 files changed, 26 insertions, 14 deletions
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("<td class='%s' style='width: %d.%d%%;'></td>", + 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("</td><td class='right'>"); if (info->binary) { - htmlf("bin</td><td class='graph'>%ld -> %ld bytes", + htmlf("bin</td><td class='graph'>%lu -> %lu bytes</td></tr>\n", info->old_size, info->new_size); return; } htmlf("%d", info->added + info->removed); html("</td><td class='graph'>"); - htmlf("<table summary='file diffstat' width='%d%%'><tr>", - max_changes > 100 ? 100 : max_changes); - htmlf("<td class='add' style='width: %.1f%%;'/>", - info->added * 100.0 / scale); - htmlf("<td class='rem' style='width: %.1f%%;'/>", - info->removed * 100.0 / scale); - htmlf("<td class='none' style='width: %.1f%%;'/>", - (max_changes - info->removed - info->added) * 100.0 / scale); + html("<table><tr>"); + 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("</tr></table></td></tr>\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("</table>"); + html("</table>\n"); html("<div class='diffstat-summary'>"); - htmlf("%d files changed, %d insertions, %d deletions", - files, total_adds, total_rems); - html("</div>"); + 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("</div>\n"); } static int over_line_cap(int idx) diff --git a/tests/t0105-commit.sh b/tests/t0105-commit.sh index 47edc5f..b26b4e3 100755 --- a/tests/t0105-commit.sh +++ b/tests/t0105-commit.sh @@ -21,7 +21,7 @@ test_expect_success 'find commit msg' 'grep "<div class=.commit-msg.></div>" tmp test_expect_success 'find diffstat' 'grep "<table summary=.diffstat. class=.diffstat.>" tmp' test_expect_success 'find diff summary' ' - grep "1 files changed, 1 insertions, 0 deletions" tmp + grep "1 file changed, 1 insertion, 0 deletions" tmp ' test_expect_success 'get root commit' ' |
