home » zplus/clif.git
Author zPlus <zplus@peers.community> 2022-08-07 21:14:31
Committer zPlus <zplus@peers.community> 2022-08-07 21:14:31
Commit 120ac72 (patch)
Tree 27b05ed
Parent(s)

Add user settings for committs diffs. Allow admins to set the default options for showing commits diffs, for example DIFF_MODE (udiff, ssdiff) or DIFF_CONTEXT_LINES.


commits diff: 108bbbe..120ac72
2 files changed, 18 insertions, 7 deletionsdownload


Diffstat
-rw-r--r-- templates/repository/commit.html 2
-rw-r--r-- web.py 23

Diff options
View
Side
Whitespace
Context lines
Inter-hunk lines
+1/-1 M   templates/repository/commit.html
index e3de9bf..7973425
old size: 16K - new size: 16K
@@ -60,7 +60,7 @@
60 60
61 61 <br /><br /><br /><br />
62 62
63 - <details class="diffstat" open>
63 + <details class="diffstat" {{ 'open' if defaults.DIFF_SHOW_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 #}

+17/-6 M   web.py
index 26ac0c5..62a2060
old size: 28K - new size: 28K
@@ -44,6 +44,14 @@ 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
48 + DIFF_VIEW = 'udiff' # "udiff", "ssdiff"
49 + DIFF_CONTEXT_LINES = 3
50 + DIFF_INTERHUNK_LINES = 0
51 + DIFF_SHOW_DIFFSTAT = False
52 + DIFF_SIDE = 'normal' # "normal", "reverse"
53 + DIFF_WHITESPACE = 'include' # "include", "ignore_all", "ignore_change", "ignore_eol"
54 +
47 55
48 56
49 57
@@ -167,7 +175,10 @@ template = functools.partial(template, template_settings = {
167 175 'now': lambda: datetime.datetime.now(datetime.timezone.utc),
168 176 'request': request,
169 177 'url': application.get_url,
170 - 'zip_longest': itertools.zip_longest
178 + 'zip_longest': itertools.zip_longest,
179 + 'defaults': {
180 + 'DIFF_SHOW_DIFFSTAT': DIFF_SHOW_DIFFSTAT
181 + }
171 182 },
172 183 'autoescape': True
173 184 })
@@ -545,21 +556,21 @@ def commit(repository, commit_id):
545 556
546 557 # Diff options
547 558
548 - diff_mode = 'udiff'
559 + diff_mode = DIFF_VIEW
549 560 if 'mode' in request.query:
550 561 if request.query.get('mode') in [ 'udiff', 'ssdiff' ]:
551 562 diff_mode = request.query.get('mode')
552 563 else:
553 564 bottle.abort(400, 'Bad request: mode')
554 565
555 - try: diff_context_lines = int(request.query.get('context_lines', 3))
566 + try: diff_context_lines = int(request.query.get('context_lines', DIFF_CONTEXT_LINES))
556 567 except: bottle.abort(400, 'Bad request: context_lines')
557 568
558 - try: diff_inter_hunk_lines = int(request.query.get('inter_hunk_lines', 0))
569 + try: diff_inter_hunk_lines = int(request.query.get('inter_hunk_lines', DIFF_INTERHUNK_LINES))
559 570 except: bottle.abort(400, 'Bad request: inter_hunk_lines')
560 571
561 572 diff_flags = pygit2.GIT_DIFF_NORMAL
562 - diff_side = 'normal'
573 + diff_side = DIFF_SIDE
563 574 if 'side' in request.query:
564 575 if request.query.get('side') == 'normal':
565 576 diff_side = 'normal'
@@ -569,7 +580,7 @@ def commit(repository, commit_id):
569 580 else:
570 581 bottle.abort(400, 'Bad request: side')
571 582
572 - diff_whitespace = 'include'
583 + diff_whitespace = DIFF_WHITESPACE
573 584 if 'whitespace' in request.query:
574 585 if request.query.get('whitespace') == 'include':
575 586 diff_whitespace = 'include'