home » zplus/clif.git
Author zPlus <zplus@peers.community> 2022-08-08 06:00:16
Committer zPlus <zplus@peers.community> 2022-08-08 06:00:16
Commit 1c93532 (patch)
Tree 044a6c6
Parent(s)

Allow expandable diffs in commit page. Allow expansion and shrinkage of diffed files in the commit page.


commits diff: 120ac72..1c93532
3 files changed, 103 insertions, 71 deletionsdownload


Diffstat
-rw-r--r-- static/css/clif.css 56
-rw-r--r-- templates/repository/commit.html 108
-rw-r--r-- web.py 10

Diff options
View
Side
Whitespace
Context lines
Inter-hunk lines
+38/-18 M   static/css/clif.css
index 5c82909..a8afbad
old size: 9K - new size: 10K
@@ -393,67 +393,87 @@ div.commit {
393 393 margin-top: .5rem;
394 394 }
395 395
396 - div.commit .diff {
396 + div.commit details.diff_view {
397 + border: 1px solid black;
397 398 border: 1px solid #d4d4d4;
399 + box-shadow: 0 .5rem 1rem -.5rem #ccc;
400 + margin-top: 1rem;
401 + position: relative;
402 + }
403 +
404 + div.commit details.diff_view summary {
405 + background-color: #f7f7f7;
406 + border-bottom: 1px solid #d4d4d4;
407 + list-style: none;
408 + padding: .2rem;
409 + }
410 +
411 + div.commit details.diff_view summary:after {
412 + content: "➕";
413 + position: absolute;
414 + right: .5rem;
415 + top: .5rem;
416 + transition: 100ms linear;
417 + }
418 +
419 + div.commit details.diff_view[open] summary:after {
420 + transform: rotate(45deg);
421 + }
422 +
423 + div.commit details.diff_view .diff {
398 424 border-collapse: collapse;
399 425 border-spacing: 0;
400 426 font-family: monospace;
401 427 font-size: 1rem;
402 - margin-top: 2rem;
403 428 width: 100%;
404 429 }
405 430
406 - div.commit .diff thead {
407 - background-color: #f7f7f7;
408 - border: 1px solid #d4d4d4;
409 - }
410 -
411 - div.commit .diff td {
431 + div.commit details.diff_view .diff td {
412 432 padding: .1rem .5rem;
413 433 }
414 434
415 - div.commit .diff .histogram {
435 + div.commit details.diff_view .diff .histogram {
416 436 border-bottom: .3rem solid;
417 437 display: inline-block;
418 438 vertical-align: middle;
419 439 }
420 440
421 - div.commit .diff .header {
441 + div.commit details.diff_view .diff .header {
422 442 background-color: #f0f9ff;
423 443 color: darkblue;
424 444 }
425 445
426 - div.commit .diff .header td {
446 + div.commit details.diff_view .diff .header td {
427 447 padding: .5rem .5rem;
428 448 }
429 449
430 - div.commit .diff .lineno {
450 + div.commit details.diff_view .diff .lineno {
431 451 color: gray;
432 452 text-align: center;
433 453 width: 0;
434 454 }
435 455
436 - div.commit .diff .origin {
456 + div.commit details.diff_view .diff .origin {
437 457 width: 0;
438 458 }
439 459
440 - div.commit .diff .deletion {
460 + div.commit details.diff_view .diff .deletion {
441 461 background-color: #ffeef0;
442 462 }
443 463
444 - div.commit .diff .insertion {
464 + div.commit details.diff_view .diff .insertion {
445 465 background-color: #e6ffed;
446 466 }
447 467
448 - div.commit .diff .change {
468 + div.commit details.diff_view .diff .change {
449 469 background-color: #feffbe;
450 470 }
451 471
452 - div.commit .diff .content {
472 + div.commit details.diff_view .diff .content {
453 473 white-space: pre-wrap;
454 474 }
455 475
456 - div.commit .diff .ssdiff .content {
476 + div.commit details.diff_view .diff .ssdiff .content {
457 477 width: 50%;
458 478 }
459 479

+58/-50 M   templates/repository/commit.html
index 7973425..f89aea7
old size: 16K - new size: 17K
@@ -60,7 +60,7 @@
60 60
61 61 <br /><br /><br /><br />
62 62
63 - <details class="diffstat" {{ 'open' if defaults.DIFF_SHOW_DIFFSTAT }}>
63 + <details class="diffstat" {{ 'open' if defaults.DIFF_EXPAND_DIFFSTAT }}>
64 64 {# pygit2 appears to recompute all the stats every time we use diff.stats,
65 65 # therefore we set this variable in order to compute it only once.
66 66 #}
@@ -91,7 +91,7 @@
91 91
92 92 <br />
93 93
94 - <details class="diff_options">
94 + <details class="diff_options" {{ 'open' if defaults.DIFF_EXPAND_DIFFOPTIONS }}>
95 95 <summary>Diff options</summary>
96 96 <form action="" method="get">
97 97 <table>
@@ -147,8 +147,8 @@
147 147
148 148 {% for patch in diff %}
149 149
150 - <table class="diff">
151 -
150 + <details class="diff_view" {{ 'open' if defaults.DIFF_EXPAND }}>
151 +
152 152 {# The following status values are defined in the git_delta_t enum
153 153 # in libgit2. See https://github.com/libgit2/libgit2/blob/main/include/git2/diff.h
154 154 # 0 = UNCHANGED
@@ -159,40 +159,38 @@
159 159 # 5 = COPIED
160 160 # ... (there are other codes that we don't use)
161 161 #}
162 - <thead>
163 - <tr>
164 - <td colspan="4">
165 - {% if patch.line_stats[1] + patch.line_stats[2] > 0 %}
166 - {% set color_border = patch.line_stats[1] / ( patch.line_stats[1] + patch.line_stats[2] ) * 100 %}
167 - {% else %}
168 - {% set color_border = 0 %}
169 - {% endif %}
170 -
171 - <span class="histogram" style="border-image: linear-gradient(to right, lightgreen {{ color_border }}%, red {{ color_border }}%) 1;">
172 - +{{ patch.line_stats[1] }}/-{{ patch.line_stats[2] }}
173 - </span>
174 -
175 - {% if patch.delta.status == 1 %}
176 - <b title="Added">A</b> {{ patch.delta.new_file.path }}
177 - {% endif %}
178 -
179 - {% if patch.delta.status == 2 %}
180 - <b title="Deleted">D</b> {{ patch.delta.old_file.path }}
181 - {% endif %}
182 -
183 - {% if patch.delta.status == 3 %}
184 - <b title="Modified">M</b> {{ patch.delta.new_file.path }}
185 - {% endif %}
186 -
187 - {% if patch.delta.status == 4 %}
188 - <b title="Renamed">R</b> {{ patch.delta.old_file.path }} -> {{ patch.delta.new_file.path }}
189 - {% endif %}
190 -
191 - {% if patch.delta.status == 5 %}
192 - <b title="Copied">C</b> {{ patch.delta.old_file.path }} {{ patch.delta.new_file.path }}
193 - {% endif %}
194 - </td>
195 - </tr>
162 + <summary>
163 + {% if patch.line_stats[1] + patch.line_stats[2] > 0 %}
164 + {% set color_border = patch.line_stats[1] / ( patch.line_stats[1] + patch.line_stats[2] ) * 100 %}
165 + {% else %}
166 + {% set color_border = 0 %}
167 + {% endif %}
168 +
169 + <span class="histogram" style="border-image: linear-gradient(to right, lightgreen {{ color_border }}%, red {{ color_border }}%) 1;">
170 + +{{ patch.line_stats[1] }}/-{{ patch.line_stats[2] }}
171 + </span>
172 +
173 + {% if patch.delta.status == 1 %}
174 + <b title="Added">A</b> {{ patch.delta.new_file.path }}
175 + {% endif %}
176 +
177 + {% if patch.delta.status == 2 %}
178 + <b title="Deleted">D</b> {{ patch.delta.old_file.path }}
179 + {% endif %}
180 +
181 + {% if patch.delta.status == 3 %}
182 + <b title="Modified">M</b> {{ patch.delta.new_file.path }}
183 + {% endif %}
184 +
185 + {% if patch.delta.status == 4 %}
186 + <b title="Renamed">R</b> {{ patch.delta.old_file.path }} -> {{ patch.delta.new_file.path }}
187 + {% endif %}
188 +
189 + {% if patch.delta.status == 5 %}
190 + <b title="Copied">C</b> {{ patch.delta.old_file.path }} {{ patch.delta.new_file.path }}
191 + {% endif %}
192 +
193 + <table>
196 194 <tr>
197 195 <td colspan="4">
198 196 old size: {{ patch.delta.old_file.size|human_size(B=true) }}
@@ -213,8 +211,10 @@
213 211 {% endif %}
214 212 </td>
215 213 </tr>
216 - </thead>
217 - <tbody>
214 + </table>
215 + </summary>
216 +
217 + <table class="diff">
218 218 {% if patch.delta.is_binary %}
219 219 <tr>
220 220 <td colspan="4">
@@ -226,6 +226,7 @@
226 226 {% for hunk in patch.hunks if not patch.delta.is_binary %}
227 227
228 228 {#### UDIFF mode ####}
229 + {# In this mode the lines are printed one after the other. #}
229 230
230 231 {% if mode == 'udiff' %}
231 232 <tr class="header">
@@ -254,8 +255,15 @@
254 255 {% endif %}
255 256
256 257 {#### SSDIFF mode ####}
258 + {# In this mode, changed lines are buffered until we find an
259 + # unchanged line. When an unchanged line has been found, the
260 + # buffer is emptied.
261 + #}
257 262
258 263 {% if mode == 'ssdiff' %}
264 + {% set buffer_deletions = [] %}
265 + {% set buffer_insertions = [] %}
266 +
259 267 {% macro print_buffer(buffer_deletions, buffer_insertions) %}
260 268 {% for buffer_del, buffer_ins in zip_longest(buffer_deletions, buffer_insertions) %}
261 269 <tr class="ssdiff">
@@ -283,9 +291,9 @@
283 291 </tr>
284 292 {% endfor %}
285 293
286 - {# .clear() empties the buffer. However since it requires
287 - # {{}} brackets instead of {%%}, this line will print the
288 - # value of "buffer_deletions" which is "None".
294 + {# .clear() empties the buffer. Since this requires {{}}
295 + # brackets instead of {%%}, this line will print the value
296 + # of "buffer_deletions" which is "None".
289 297 # "or ''" is a hack for printing an empty line instead of "None".
290 298 #}
291 299 {{ buffer_deletions.clear() or '' }}
@@ -296,9 +304,6 @@
296 304 <td colspan=4>{{ hunk.header }}</td>
297 305 </tr>
298 306
299 - {% set buffer_deletions = [] %}
300 - {% set buffer_insertions = [] %}
301 -
302 307 {% for line in hunk.lines %}
303 308 {% if line.old_lineno < 0 %}
304 309 {{ buffer_insertions.append(line) or '' }}
@@ -313,6 +318,7 @@
313 318 {# Unload buffer #}
314 319 {{ print_buffer(buffer_deletions, buffer_insertions) }}
315 320
321 + {# Insert the unchanged line. #}
316 322 <tr class="ssdiff">
317 323 <td class="lineno">
318 324 {{ line.old_lineno }}
@@ -327,14 +333,16 @@
327 333 {% endif %}
328 334 {% endfor %}
329 335
330 - {# Empty remaining buffer #}
336 + {# Empty remaining buffer. There is a non-empty buffer if we did
337 + # not find an unchanged line, for example when context_lines=0.
338 + #}
331 339 {{ print_buffer(buffer_deletions, buffer_insertions) }}
332 340 {% endif %}
333 341
334 342 {% endfor %}
335 - </tbody>
336 -
337 - </table>
343 +
344 + </table>
345 + </details>
338 346
339 347 {% endfor %}
340 348 </div>

+7/-3 M   web.py
index 62a2060..1e36c61
old size: 28K - new size: 28K
@@ -44,13 +44,15 @@ INSTANCE_DOMAIN = 'domain.local'
44 44 # How many commits to show in the log page
45 45 LOG_PAGINATION = 100
46 46
47 - # Default options when showing diffs in "commit" page
47 + # Default options for showing diffs in "commit" page
48 48 DIFF_VIEW = 'udiff' # "udiff", "ssdiff"
49 49 DIFF_CONTEXT_LINES = 3
50 50 DIFF_INTERHUNK_LINES = 0
51 - DIFF_SHOW_DIFFSTAT = False
52 51 DIFF_SIDE = 'normal' # "normal", "reverse"
53 52 DIFF_WHITESPACE = 'include' # "include", "ignore_all", "ignore_change", "ignore_eol"
53 + DIFF_EXPAND = True # Show expanded diff files by default
54 + DIFF_EXPAND_DIFFSTAT = False
55 + DIFF_EXPAND_DIFFOPTIONS = False
54 56
55 57
56 58
@@ -177,7 +179,9 @@ template = functools.partial(template, template_settings = {
177 179 'url': application.get_url,
178 180 'zip_longest': itertools.zip_longest,
179 181 'defaults': {
180 - 'DIFF_SHOW_DIFFSTAT': DIFF_SHOW_DIFFSTAT
182 + 'DIFF_EXPAND': DIFF_EXPAND,
183 + 'DIFF_EXPAND_DIFFSTAT': DIFF_EXPAND_DIFFSTAT,
184 + 'DIFF_EXPAND_DIFFOPTIONS': DIFF_EXPAND_DIFFOPTIONS
181 185 }
182 186 },
183 187 'autoescape': True