From 108bbbea3c60b1062552d97875412cacaece24e2 Mon Sep 17 00:00:00 2001 From: zPlus Date: Sun, 7 Aug 2022 22:52:55 +0200 Subject: [PATCH] Add diffstat histogram in commit page. --- static/css/clif.css | 71 +++++++++++++- templates/repository/commit.html | 163 ++++++++++++++++++------------- templates/repository/log.html | 2 +- 3 files changed, 168 insertions(+), 68 deletions(-) diff --git a/static/css/clif.css b/static/css/clif.css index f104018..5c82909 100644 --- a/static/css/clif.css +++ b/static/css/clif.css @@ -326,10 +326,73 @@ div.commit { } div.commit .message { - margin: 2rem 0; white-space: pre-wrap; } + div.commit details.diffstat { + } + + div.commit details.diffstat table { + width: 100%; + } + + div.commit details.diffstat table .filemode { + font-family: monospace; + font-size: 1rem; + white-space: nowrap; + width: 0; + } + + div.commit details.diffstat table .path { + font-family: monospace; + font-size: 1rem; + padding: 0 1rem; + white-space: nowrap; + width: 0; + } + + div.commit details.diffstat table .lines { + font-family: monospace; + font-size: 1rem; + text-align: right; + white-space: nowrap; + width:0; + } + + div.commit details.diffstat table .histogram { + max-width: 20%; + } + + div.commit details.diffstat table .histogram span { + display: inline-block; + height:1rem; + vertical-align: middle; + } + + div.commit details.diffstat table .histogram .insertions { + background: lightgreen; + } + + div.commit details.diffstat table .histogram .deletions { + background: red; + } + + div.commit details.diffstat .accumulated { + margin-top: .5rem; + } + + div.commit details.diffstat .accumulated .insertions { + color: darkgreen; + } + + div.commit details.diffstat .accumulated .deletions { + color: darkred; + } + + div.commit details.diff_options input[type=submit] { + margin-top: .5rem; + } + div.commit .diff { border: 1px solid #d4d4d4; border-collapse: collapse; @@ -349,6 +412,12 @@ div.commit { padding: .1rem .5rem; } + div.commit .diff .histogram { + border-bottom: .3rem solid; + display: inline-block; + vertical-align: middle; + } + div.commit .diff .header { background-color: #f0f9ff; color: darkblue; diff --git a/templates/repository/commit.html b/templates/repository/commit.html index f814f2d..e3de9bf 100644 --- a/templates/repository/commit.html +++ b/templates/repository/commit.html @@ -51,76 +51,99 @@ {% endfor %} - - - ± - - - {{ diff.stats.files_changed }} files changed, - {{ diff.stats.insertions }} insertions, - {{ diff.stats.deletions }} deletions - - +
+
{{ commit.message }}
-
-
- Diff options -
- - - - - - - - - - - - - - - - - - - - - -
- View - - - -
- Context lines - - -
- Inter-hunk lines - - -
- Side - - - -
- Whitespace - - - - - -
- -
-
-
+



+ +
+ {# pygit2 appears to recompute all the stats every time we use diff.stats, + # therefore we set this variable in order to compute it only once. + #} + {% set diff_stats = diff.stats %} + + Diffstat + + {% for patch in diff %} + + + + + + + + {% endfor %} +
{{ patch.delta.new_file.mode|filemode }}{{ patch.delta.new_file.path }}{{ patch.line_stats[1] + patch.line_stats[2] }} + +
+ +
+ {{ diff_stats.files_changed }} file{{ 's' if diff_stats.files_changed != 1 }} changed, + {{ diff_stats.insertions }} insertion{{ 's' if diff_stats.insertions != 1 }}, + {{ diff_stats.deletions }} deletion{{ 's' if diff_stats.deletions != 1 }} +
+
+ +
+ +
+ Diff options +
+ + + + + + + + + + + + + + + + + + + + + +
+ View + + + +
+ Context lines + + +
+ Inter-hunk lines + + +
+ Side + + + +
+ Whitespace + + + + + +
+ +
+
{% for patch in diff %} @@ -139,7 +162,15 @@ - -{{ patch.line_stats[2] }}/+{{ patch.line_stats[1] }} + {% if patch.line_stats[1] + patch.line_stats[2] > 0 %} + {% set color_border = patch.line_stats[1] / ( patch.line_stats[1] + patch.line_stats[2] ) * 100 %} + {% else %} + {% set color_border = 0 %} + {% endif %} + + + +{{ patch.line_stats[1] }}/-{{ patch.line_stats[2] }} + {% if patch.delta.status == 1 %} A {{ patch.delta.new_file.path }} diff --git a/templates/repository/log.html b/templates/repository/log.html index 2ec71a7..c2da4bc 100644 --- a/templates/repository/log.html +++ b/templates/repository/log.html @@ -78,7 +78,7 @@ {% if commit.short_id in diff %} - -{{ diff[commit.short_id].stats.deletions }}/+{{ diff[commit.short_id].stats.insertions }} + +{{ diff[commit.short_id].stats.insertions }}/-{{ diff[commit.short_id].stats.deletions }} {% endif %}