Mercurial > hg
annotate mercurial/hgweb/webutil.py @ 43812:bf0453866c80
fuzz: use a variable to allow specifying python-config to use
Eventually we should probably default this to just `python-config` and have
the oss-fuzz build.sh script specify the sanpy python-config, but for now this
lets us make progress.
Differential Revision: https://phab.mercurial-scm.org/D7563
author | Augie Fackler <augie@google.com> |
---|---|
date | Fri, 06 Dec 2019 15:15:05 -0500 |
parents | 29adf0a087a1 |
children | 14d0e89520a2 |
rev | line source |
---|---|
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
1 # hgweb/webutil.py - utility library for the web interface. |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
2 # |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
3 # Copyright 21 May 2005 - (c) 2005 Jake Edge <jake@edge2.net> |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
4 # Copyright 2005-2007 Matt Mackall <mpm@selenic.com> |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
5 # |
8225
46293a0c7e9f
updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents:
7717
diff
changeset
|
6 # This software may be used and distributed according to the terms of the |
10263 | 7 # GNU General Public License version 2 or any later version. |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
8 |
27046
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27023
diff
changeset
|
9 from __future__ import absolute_import |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27023
diff
changeset
|
10 |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27023
diff
changeset
|
11 import copy |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27023
diff
changeset
|
12 import difflib |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27023
diff
changeset
|
13 import os |
26162
268b39770c28
hgweb: extract web substitutions table generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26129
diff
changeset
|
14 import re |
27046
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27023
diff
changeset
|
15 |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27023
diff
changeset
|
16 from ..i18n import _ |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27023
diff
changeset
|
17 from ..node import hex, nullid, short |
43087
66f2cc210a29
py3: manually import pycompat.setattr where it is needed
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43077
diff
changeset
|
18 from ..pycompat import setattr |
27046
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27023
diff
changeset
|
19 |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27023
diff
changeset
|
20 from .common import ( |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27023
diff
changeset
|
21 ErrorResponse, |
31665
5e6d44511317
hgweb: handle a "linerange" request parameter in filelog command
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31660
diff
changeset
|
22 HTTP_BAD_REQUEST, |
27046
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27023
diff
changeset
|
23 HTTP_NOT_FOUND, |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27023
diff
changeset
|
24 paritygen, |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27023
diff
changeset
|
25 ) |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27023
diff
changeset
|
26 |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27023
diff
changeset
|
27 from .. import ( |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27023
diff
changeset
|
28 context, |
38588
1c93e0237a24
diffutil: move the module out of utils package
Yuya Nishihara <yuya@tcha.org>
parents:
38585
diff
changeset
|
29 diffutil, |
27046
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27023
diff
changeset
|
30 error, |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27023
diff
changeset
|
31 match, |
31808
ca3b4a2b7e54
mdiff: add a hunkinrange helper function
Denis Laxalde <denis@laxalde.org>
parents:
31727
diff
changeset
|
32 mdiff, |
36955
f21798a6bc20
hgweb: explain instabilities of unstable changesets
Anton Shestakov <av6@dwimlabs.net>
parents:
36886
diff
changeset
|
33 obsutil, |
27046
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27023
diff
changeset
|
34 patch, |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27023
diff
changeset
|
35 pathutil, |
34807
3caec3c032c8
webutil: use pycompat.bytestr() instead of str()
Augie Fackler <augie@google.com>
parents:
34403
diff
changeset
|
36 pycompat, |
37335
956260cbc564
hgweb: use revsymbol() for creating context from changeid
Martin von Zweigbergk <martinvonz@google.com>
parents:
37334
diff
changeset
|
37 scmutil, |
27046
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27023
diff
changeset
|
38 templatefilters, |
35485
1721ce06100a
hgweb: display fate of obsolete changesets
Anton Shestakov <av6@dwimlabs.net>
parents:
35454
diff
changeset
|
39 templatekw, |
37515
8a5ee6aa8870
hgweb: wrap {archives} with mappinglist
Yuya Nishihara <yuya@tcha.org>
parents:
37514
diff
changeset
|
40 templateutil, |
27046
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27023
diff
changeset
|
41 ui as uimod, |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27023
diff
changeset
|
42 util, |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27023
diff
changeset
|
43 ) |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
44 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
45 from ..utils import stringutil |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
46 |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
47 archivespecs = util.sortdict( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
48 ( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
49 (b'zip', (b'application/zip', b'zip', b'.zip', None)), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
50 (b'gz', (b'application/x-gzip', b'tgz', b'.tar.gz', None)), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
51 (b'bz2', (b'application/x-bzip2', b'tbz2', b'.tar.bz2', None)), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
52 ) |
37084
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
37069
diff
changeset
|
53 ) |
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
37069
diff
changeset
|
54 |
37511
356e61e82c2a
hgweb: move archivespecs to webutil
Yuya Nishihara <yuya@tcha.org>
parents:
37503
diff
changeset
|
55 |
37514
034a422aeaff
hgweb: forward archivelist() of hgweb to webutil
Yuya Nishihara <yuya@tcha.org>
parents:
37513
diff
changeset
|
56 def archivelist(ui, nodeid, url=None): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
57 allowed = ui.configlist(b'web', b'allow-archive', untrusted=True) |
37513
40a7c1dd2df9
hgweb: move archivelist() of hgwebdir to webutil
Yuya Nishihara <yuya@tcha.org>
parents:
37511
diff
changeset
|
58 archives = [] |
40a7c1dd2df9
hgweb: move archivelist() of hgwebdir to webutil
Yuya Nishihara <yuya@tcha.org>
parents:
37511
diff
changeset
|
59 |
43106
d783f945a701
py3: finish porting iteritems() to pycompat and remove source transformer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43087
diff
changeset
|
60 for typ, spec in pycompat.iteritems(archivespecs): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
61 if typ in allowed or ui.configbool( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
62 b'web', b'allow' + typ, untrusted=True |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
63 ): |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
64 archives.append( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
65 { |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
66 b'type': typ, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
67 b'extension': spec[2], |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
68 b'node': nodeid, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
69 b'url': url, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
70 } |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
71 ) |
37513
40a7c1dd2df9
hgweb: move archivelist() of hgwebdir to webutil
Yuya Nishihara <yuya@tcha.org>
parents:
37511
diff
changeset
|
72 |
37515
8a5ee6aa8870
hgweb: wrap {archives} with mappinglist
Yuya Nishihara <yuya@tcha.org>
parents:
37514
diff
changeset
|
73 return templateutil.mappinglist(archives) |
37513
40a7c1dd2df9
hgweb: move archivelist() of hgwebdir to webutil
Yuya Nishihara <yuya@tcha.org>
parents:
37511
diff
changeset
|
74 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
75 |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
76 def up(p): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
77 if p[0:1] != b"/": |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
78 p = b"/" + p |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
79 if p[-1:] == b"/": |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
80 p = p[:-1] |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
81 up = os.path.dirname(p) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
82 if up == b"/": |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
83 return b"/" |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
84 return up + b"/" |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
85 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
86 |
18391
833eb34e90e4
hgweb: better names for _navseq arguments
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18390
diff
changeset
|
87 def _navseq(step, firststep=None): |
833eb34e90e4
hgweb: better names for _navseq arguments
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18390
diff
changeset
|
88 if firststep: |
833eb34e90e4
hgweb: better names for _navseq arguments
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18390
diff
changeset
|
89 yield firststep |
833eb34e90e4
hgweb: better names for _navseq arguments
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18390
diff
changeset
|
90 if firststep >= 20 and firststep <= 40: |
18392
88a37b19dc0e
hgweb: ensure _navseq yield strictly increasing numbers
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18391
diff
changeset
|
91 firststep = 50 |
88a37b19dc0e
hgweb: ensure _navseq yield strictly increasing numbers
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18391
diff
changeset
|
92 yield firststep |
88a37b19dc0e
hgweb: ensure _navseq yield strictly increasing numbers
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18391
diff
changeset
|
93 assert step > 0 |
88a37b19dc0e
hgweb: ensure _navseq yield strictly increasing numbers
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18391
diff
changeset
|
94 assert firststep > 0 |
88a37b19dc0e
hgweb: ensure _navseq yield strictly increasing numbers
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18391
diff
changeset
|
95 while step <= firststep: |
88a37b19dc0e
hgweb: ensure _navseq yield strictly increasing numbers
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18391
diff
changeset
|
96 step *= 10 |
18390
28fa9443f751
hgweb: drop recursivity in _navseq
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18389
diff
changeset
|
97 while True: |
18391
833eb34e90e4
hgweb: better names for _navseq arguments
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18390
diff
changeset
|
98 yield 1 * step |
833eb34e90e4
hgweb: better names for _navseq arguments
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18390
diff
changeset
|
99 yield 3 * step |
833eb34e90e4
hgweb: better names for _navseq arguments
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18390
diff
changeset
|
100 step *= 10 |
18389
82572533bc00
hgweb: move the `seq` function out of the revnavgen scope
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18388
diff
changeset
|
101 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
102 |
18403
bfaee31a83d2
hgweb: move revnavgen into an object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18392
diff
changeset
|
103 class revnav(object): |
18409
e3f5cef11d6a
hgweb: pass repo object to revnav construction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18408
diff
changeset
|
104 def __init__(self, repo): |
18404
1da84a6b136a
hgweb: pass nodefunc to the revnav object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18403
diff
changeset
|
105 """Navigation generation object |
1da84a6b136a
hgweb: pass nodefunc to the revnav object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18403
diff
changeset
|
106 |
18409
e3f5cef11d6a
hgweb: pass repo object to revnav construction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18408
diff
changeset
|
107 :repo: repo object we generate nav for |
18404
1da84a6b136a
hgweb: pass nodefunc to the revnav object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18403
diff
changeset
|
108 """ |
18409
e3f5cef11d6a
hgweb: pass repo object to revnav construction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18408
diff
changeset
|
109 # used for hex generation |
e3f5cef11d6a
hgweb: pass repo object to revnav construction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18408
diff
changeset
|
110 self._revlog = repo.changelog |
18404
1da84a6b136a
hgweb: pass nodefunc to the revnav object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18403
diff
changeset
|
111 |
18406
20cf53932b6f
hgweb: simplify the handling of empty repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18405
diff
changeset
|
112 def __nonzero__(self): |
20cf53932b6f
hgweb: simplify the handling of empty repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18405
diff
changeset
|
113 """return True if any revision to navigate over""" |
19094
fc1b77db123f
hgweb: handle filtered "0" rev in navigation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
19093
diff
changeset
|
114 return self._first() is not None |
fc1b77db123f
hgweb: handle filtered "0" rev in navigation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
19093
diff
changeset
|
115 |
31476
413b44003462
py3: add __bool__ to every class defining __nonzero__
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31434
diff
changeset
|
116 __bool__ = __nonzero__ |
413b44003462
py3: add __bool__ to every class defining __nonzero__
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31434
diff
changeset
|
117 |
19094
fc1b77db123f
hgweb: handle filtered "0" rev in navigation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
19093
diff
changeset
|
118 def _first(self): |
fc1b77db123f
hgweb: handle filtered "0" rev in navigation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
19093
diff
changeset
|
119 """return the minimum non-filtered changeset or None""" |
fc1b77db123f
hgweb: handle filtered "0" rev in navigation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
19093
diff
changeset
|
120 try: |
29216
ead25aa27a43
py3: convert to next() function
timeless <timeless@mozdev.org>
parents:
28709
diff
changeset
|
121 return next(iter(self._revlog)) |
19094
fc1b77db123f
hgweb: handle filtered "0" rev in navigation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
19093
diff
changeset
|
122 except StopIteration: |
fc1b77db123f
hgweb: handle filtered "0" rev in navigation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
19093
diff
changeset
|
123 return None |
18406
20cf53932b6f
hgweb: simplify the handling of empty repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18405
diff
changeset
|
124 |
18405
1eaf0d017b2c
hgweb: move hex creation into an object method
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18404
diff
changeset
|
125 def hex(self, rev): |
18409
e3f5cef11d6a
hgweb: pass repo object to revnav construction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18408
diff
changeset
|
126 return hex(self._revlog.node(rev)) |
18405
1eaf0d017b2c
hgweb: move hex creation into an object method
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18404
diff
changeset
|
127 |
18404
1da84a6b136a
hgweb: pass nodefunc to the revnav object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18403
diff
changeset
|
128 def gen(self, pos, pagelen, limit): |
18403
bfaee31a83d2
hgweb: move revnavgen into an object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18392
diff
changeset
|
129 """computes label and revision id for navigation link |
18320
60680d691a0b
hgweb: document the revnavgen function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17991
diff
changeset
|
130 |
18403
bfaee31a83d2
hgweb: move revnavgen into an object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18392
diff
changeset
|
131 :pos: is the revision relative to which we generate navigation. |
bfaee31a83d2
hgweb: move revnavgen into an object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18392
diff
changeset
|
132 :pagelen: the size of each navigation page |
bfaee31a83d2
hgweb: move revnavgen into an object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18392
diff
changeset
|
133 :limit: how far shall we link |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
134 |
18403
bfaee31a83d2
hgweb: move revnavgen into an object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18392
diff
changeset
|
135 The return is: |
37698
7738ae638b62
hgweb: wrap {changenav} and {nav} with mappinglist
Yuya Nishihara <yuya@tcha.org>
parents:
37697
diff
changeset
|
136 - a single element mappinglist |
18403
bfaee31a83d2
hgweb: move revnavgen into an object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18392
diff
changeset
|
137 - containing a dictionary with a `before` and `after` key |
37697
6fb50e912aa8
hgweb: make revnav.gen() simply build a list of mappings by one pass
Yuya Nishihara <yuya@tcha.org>
parents:
37696
diff
changeset
|
138 - values are dictionaries with `label` and `node` keys |
18403
bfaee31a83d2
hgweb: move revnavgen into an object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18392
diff
changeset
|
139 """ |
18406
20cf53932b6f
hgweb: simplify the handling of empty repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18405
diff
changeset
|
140 if not self: |
20cf53932b6f
hgweb: simplify the handling of empty repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18405
diff
changeset
|
141 # empty repo |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
142 return templateutil.mappinglist( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
143 [ |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
144 { |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
145 b'before': templateutil.mappinglist([]), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
146 b'after': templateutil.mappinglist([]), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
147 }, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
148 ] |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
149 ) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
150 |
18425
6da1e979340a
hgweb: generate revnav in two phase
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18409
diff
changeset
|
151 targets = [] |
18403
bfaee31a83d2
hgweb: move revnavgen into an object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18392
diff
changeset
|
152 for f in _navseq(1, pagelen): |
bfaee31a83d2
hgweb: move revnavgen into an object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18392
diff
changeset
|
153 if f > limit: |
bfaee31a83d2
hgweb: move revnavgen into an object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18392
diff
changeset
|
154 break |
18425
6da1e979340a
hgweb: generate revnav in two phase
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18409
diff
changeset
|
155 targets.append(pos + f) |
6da1e979340a
hgweb: generate revnav in two phase
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18409
diff
changeset
|
156 targets.append(pos - f) |
6da1e979340a
hgweb: generate revnav in two phase
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18409
diff
changeset
|
157 targets.sort() |
6da1e979340a
hgweb: generate revnav in two phase
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18409
diff
changeset
|
158 |
19094
fc1b77db123f
hgweb: handle filtered "0" rev in navigation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
19093
diff
changeset
|
159 first = self._first() |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
160 navbefore = [{b'label': b'(%i)' % first, b'node': self.hex(first)}] |
18425
6da1e979340a
hgweb: generate revnav in two phase
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18409
diff
changeset
|
161 navafter = [] |
6da1e979340a
hgweb: generate revnav in two phase
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18409
diff
changeset
|
162 for rev in targets: |
18426
01638b51df44
hgweb: ignore filtered revision in revnav
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18425
diff
changeset
|
163 if rev not in self._revlog: |
01638b51df44
hgweb: ignore filtered revision in revnav
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18425
diff
changeset
|
164 continue |
18425
6da1e979340a
hgweb: generate revnav in two phase
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18409
diff
changeset
|
165 if pos < rev < limit: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
166 navafter.append( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
167 {b'label': b'+%d' % abs(rev - pos), b'node': self.hex(rev)} |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
168 ) |
18425
6da1e979340a
hgweb: generate revnav in two phase
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18409
diff
changeset
|
169 if 0 < rev < pos: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
170 navbefore.append( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
171 {b'label': b'-%d' % abs(rev - pos), b'node': self.hex(rev)} |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
172 ) |
10254
8d5de52431f2
hgweb: changenav: separate pages before and after the current position
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9402
diff
changeset
|
173 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
174 navafter.append({b'label': b'tip', b'node': b'tip'}) |
18403
bfaee31a83d2
hgweb: move revnavgen into an object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18392
diff
changeset
|
175 |
37698
7738ae638b62
hgweb: wrap {changenav} and {nav} with mappinglist
Yuya Nishihara <yuya@tcha.org>
parents:
37697
diff
changeset
|
176 # TODO: maybe this can be a scalar object supporting tomap() |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
177 return templateutil.mappinglist( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
178 [ |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
179 { |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
180 b'before': templateutil.mappinglist(navbefore), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
181 b'after': templateutil.mappinglist(navafter), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
182 }, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
183 ] |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
184 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
185 |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
186 |
18408
f332a64fef51
hgweb: introduction a filerevnav subclass
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18407
diff
changeset
|
187 class filerevnav(revnav): |
18409
e3f5cef11d6a
hgweb: pass repo object to revnav construction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18408
diff
changeset
|
188 def __init__(self, repo, path): |
e3f5cef11d6a
hgweb: pass repo object to revnav construction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18408
diff
changeset
|
189 """Navigation generation object |
e3f5cef11d6a
hgweb: pass repo object to revnav construction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18408
diff
changeset
|
190 |
e3f5cef11d6a
hgweb: pass repo object to revnav construction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18408
diff
changeset
|
191 :repo: repo object we generate nav for |
e3f5cef11d6a
hgweb: pass repo object to revnav construction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18408
diff
changeset
|
192 :path: path of the file we generate nav for |
e3f5cef11d6a
hgweb: pass repo object to revnav construction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18408
diff
changeset
|
193 """ |
e3f5cef11d6a
hgweb: pass repo object to revnav construction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18408
diff
changeset
|
194 # used for iteration |
e3f5cef11d6a
hgweb: pass repo object to revnav construction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18408
diff
changeset
|
195 self._changelog = repo.unfiltered().changelog |
e3f5cef11d6a
hgweb: pass repo object to revnav construction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18408
diff
changeset
|
196 # used for hex generation |
e3f5cef11d6a
hgweb: pass repo object to revnav construction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18408
diff
changeset
|
197 self._revlog = repo.file(path) |
e3f5cef11d6a
hgweb: pass repo object to revnav construction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18408
diff
changeset
|
198 |
e3f5cef11d6a
hgweb: pass repo object to revnav construction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18408
diff
changeset
|
199 def hex(self, rev): |
e3f5cef11d6a
hgweb: pass repo object to revnav construction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18408
diff
changeset
|
200 return hex(self._changelog.node(self._revlog.linkrev(rev))) |
e3f5cef11d6a
hgweb: pass repo object to revnav construction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18408
diff
changeset
|
201 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
202 |
37699
0e02eb838b96
hgweb: extract a generator function of _siblings class
Yuya Nishihara <yuya@tcha.org>
parents:
37698
diff
changeset
|
203 # TODO: maybe this can be a wrapper class for changectx/filectx list, which |
0e02eb838b96
hgweb: extract a generator function of _siblings class
Yuya Nishihara <yuya@tcha.org>
parents:
37698
diff
changeset
|
204 # yields {'ctx': ctx} |
37700
495fbeae63cc
hgweb: convert _siblings to a factory function of mappinggenerator
Yuya Nishihara <yuya@tcha.org>
parents:
37699
diff
changeset
|
205 def _ctxsgen(context, ctxs): |
37699
0e02eb838b96
hgweb: extract a generator function of _siblings class
Yuya Nishihara <yuya@tcha.org>
parents:
37698
diff
changeset
|
206 for s in ctxs: |
0e02eb838b96
hgweb: extract a generator function of _siblings class
Yuya Nishihara <yuya@tcha.org>
parents:
37698
diff
changeset
|
207 d = { |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
208 b'node': s.hex(), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
209 b'rev': s.rev(), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
210 b'user': s.user(), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
211 b'date': s.date(), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
212 b'description': s.description(), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
213 b'branch': s.branch(), |
37699
0e02eb838b96
hgweb: extract a generator function of _siblings class
Yuya Nishihara <yuya@tcha.org>
parents:
37698
diff
changeset
|
214 } |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
215 if util.safehasattr(s, b'path'): |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
216 d[b'file'] = s.path() |
37699
0e02eb838b96
hgweb: extract a generator function of _siblings class
Yuya Nishihara <yuya@tcha.org>
parents:
37698
diff
changeset
|
217 yield d |
0e02eb838b96
hgweb: extract a generator function of _siblings class
Yuya Nishihara <yuya@tcha.org>
parents:
37698
diff
changeset
|
218 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
219 |
37700
495fbeae63cc
hgweb: convert _siblings to a factory function of mappinggenerator
Yuya Nishihara <yuya@tcha.org>
parents:
37699
diff
changeset
|
220 def _siblings(siblings=None, hiderev=None): |
495fbeae63cc
hgweb: convert _siblings to a factory function of mappinggenerator
Yuya Nishihara <yuya@tcha.org>
parents:
37699
diff
changeset
|
221 if siblings is None: |
495fbeae63cc
hgweb: convert _siblings to a factory function of mappinggenerator
Yuya Nishihara <yuya@tcha.org>
parents:
37699
diff
changeset
|
222 siblings = [] |
495fbeae63cc
hgweb: convert _siblings to a factory function of mappinggenerator
Yuya Nishihara <yuya@tcha.org>
parents:
37699
diff
changeset
|
223 siblings = [s for s in siblings if s.node() != nullid] |
495fbeae63cc
hgweb: convert _siblings to a factory function of mappinggenerator
Yuya Nishihara <yuya@tcha.org>
parents:
37699
diff
changeset
|
224 if len(siblings) == 1 and siblings[0].rev() == hiderev: |
495fbeae63cc
hgweb: convert _siblings to a factory function of mappinggenerator
Yuya Nishihara <yuya@tcha.org>
parents:
37699
diff
changeset
|
225 siblings = [] |
495fbeae63cc
hgweb: convert _siblings to a factory function of mappinggenerator
Yuya Nishihara <yuya@tcha.org>
parents:
37699
diff
changeset
|
226 return templateutil.mappinggenerator(_ctxsgen, args=(siblings,)) |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
227 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
228 |
34390
f6492f482c60
hgweb: query string arguments to control whitespace for annotate
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34246
diff
changeset
|
229 def difffeatureopts(req, ui, section): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
230 diffopts = diffutil.difffeatureopts( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
231 ui, untrusted=True, section=section, whitespace=True |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
232 ) |
34390
f6492f482c60
hgweb: query string arguments to control whitespace for annotate
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34246
diff
changeset
|
233 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
234 for k in ( |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
235 b'ignorews', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
236 b'ignorewsamount', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
237 b'ignorewseol', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
238 b'ignoreblanklines', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
239 ): |
36886
563fd95a6efb
hgweb: pass modern request type into various webutil functions (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36885
diff
changeset
|
240 v = req.qsparams.get(k) |
34390
f6492f482c60
hgweb: query string arguments to control whitespace for annotate
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34246
diff
changeset
|
241 if v is not None: |
37084
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
37069
diff
changeset
|
242 v = stringutil.parsebool(v) |
34403
407ebe7a9b93
hgweb: use parsebool for parsing diff query string options
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34390
diff
changeset
|
243 setattr(diffopts, k, v if v is not None else True) |
34390
f6492f482c60
hgweb: query string arguments to control whitespace for annotate
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34246
diff
changeset
|
244 |
f6492f482c60
hgweb: query string arguments to control whitespace for annotate
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34246
diff
changeset
|
245 return diffopts |
f6492f482c60
hgweb: query string arguments to control whitespace for annotate
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34246
diff
changeset
|
246 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
247 |
34390
f6492f482c60
hgweb: query string arguments to control whitespace for annotate
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34246
diff
changeset
|
248 def annotate(req, fctx, ui): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
249 diffopts = difffeatureopts(req, ui, b'annotate') |
37065
b235bde38a83
annotate: drop linenumber flag from fctx.annotate() (API)
Yuya Nishihara <yuya@tcha.org>
parents:
37019
diff
changeset
|
250 return fctx.annotate(follow=True, diffopts=diffopts) |
30081
dd0ff715a82c
hgweb: make fctx.annotate a separated function so it could be wrapped
Jun Wu <quark@fb.com>
parents:
29216
diff
changeset
|
251 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
252 |
7671
06cf09c822c4
hgweb: simplify parents/children generation code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7637
diff
changeset
|
253 def parents(ctx, hide=None): |
24136
46d6cdfce4bf
hgweb: use introrev() for finding parents (issue4506)
Anton Shestakov <engored@ya.ru>
parents:
23745
diff
changeset
|
254 if isinstance(ctx, context.basefilectx): |
46d6cdfce4bf
hgweb: use introrev() for finding parents (issue4506)
Anton Shestakov <engored@ya.ru>
parents:
23745
diff
changeset
|
255 introrev = ctx.introrev() |
46d6cdfce4bf
hgweb: use introrev() for finding parents (issue4506)
Anton Shestakov <engored@ya.ru>
parents:
23745
diff
changeset
|
256 if ctx.changectx().rev() != introrev: |
24340
567ae5365754
hgweb: replace 'ctx._repo' with 'ctx.repo()'
Matt Harbison <matt_harbison@yahoo.com>
parents:
24306
diff
changeset
|
257 return _siblings([ctx.repo()[introrev]], hide) |
7671
06cf09c822c4
hgweb: simplify parents/children generation code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7637
diff
changeset
|
258 return _siblings(ctx.parents(), hide) |
06cf09c822c4
hgweb: simplify parents/children generation code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7637
diff
changeset
|
259 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
260 |
7671
06cf09c822c4
hgweb: simplify parents/children generation code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7637
diff
changeset
|
261 def children(ctx, hide=None): |
06cf09c822c4
hgweb: simplify parents/children generation code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7637
diff
changeset
|
262 return _siblings(ctx.children(), hide) |
06cf09c822c4
hgweb: simplify parents/children generation code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7637
diff
changeset
|
263 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
264 |
6434
62e0bb41e682
hgweb: minor improvements for new web style
Matt Mackall <mpm@selenic.com>
parents:
6413
diff
changeset
|
265 def renamelink(fctx): |
6437 | 266 r = fctx.renamed() |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
267 if r: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
268 return templateutil.mappinglist([{b'file': r[0], b'node': hex(r[1])}]) |
37902
2095331ff926
hgweb: wrap {rename} with mappinglist
Yuya Nishihara <yuya@tcha.org>
parents:
37700
diff
changeset
|
269 return templateutil.mappinglist([]) |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
270 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
271 |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
272 def nodetagsdict(repo, node): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
273 return templateutil.hybridlist(repo.nodetags(node), name=b'name') |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
274 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
275 |
13596
270f57d35525
hgweb: add display of bookmarks for changelog and changeset
Alexander Solovyov <alexander@solovyov.net>
parents:
12691
diff
changeset
|
276 def nodebookmarksdict(repo, node): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
277 return templateutil.hybridlist(repo.nodebookmarks(node), name=b'name') |
13596
270f57d35525
hgweb: add display of bookmarks for changelog and changeset
Alexander Solovyov <alexander@solovyov.net>
parents:
12691
diff
changeset
|
278 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
279 |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
280 def nodebranchdict(repo, ctx): |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
281 branches = [] |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
282 branch = ctx.branch() |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
283 # If this is an empty repo, ctx.node() == nullid, |
16719
e7bf09acd410
localrepo: add branchtip() method for faster single-branch lookups
Brodie Rao <brodie@sf.io>
parents:
16308
diff
changeset
|
284 # ctx.branch() == 'default'. |
e7bf09acd410
localrepo: add branchtip() method for faster single-branch lookups
Brodie Rao <brodie@sf.io>
parents:
16308
diff
changeset
|
285 try: |
e7bf09acd410
localrepo: add branchtip() method for faster single-branch lookups
Brodie Rao <brodie@sf.io>
parents:
16308
diff
changeset
|
286 branchnode = repo.branchtip(branch) |
e7bf09acd410
localrepo: add branchtip() method for faster single-branch lookups
Brodie Rao <brodie@sf.io>
parents:
16308
diff
changeset
|
287 except error.RepoLookupError: |
e7bf09acd410
localrepo: add branchtip() method for faster single-branch lookups
Brodie Rao <brodie@sf.io>
parents:
16308
diff
changeset
|
288 branchnode = None |
e7bf09acd410
localrepo: add branchtip() method for faster single-branch lookups
Brodie Rao <brodie@sf.io>
parents:
16308
diff
changeset
|
289 if branchnode == ctx.node(): |
37905
f5155bca5023
hgweb: wrap {branches} by hybridlist()
Yuya Nishihara <yuya@tcha.org>
parents:
37904
diff
changeset
|
290 branches.append(branch) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
291 return templateutil.hybridlist(branches, name=b'name') |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
292 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
293 |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
294 def nodeinbranch(repo, ctx): |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
295 branches = [] |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
296 branch = ctx.branch() |
16719
e7bf09acd410
localrepo: add branchtip() method for faster single-branch lookups
Brodie Rao <brodie@sf.io>
parents:
16308
diff
changeset
|
297 try: |
e7bf09acd410
localrepo: add branchtip() method for faster single-branch lookups
Brodie Rao <brodie@sf.io>
parents:
16308
diff
changeset
|
298 branchnode = repo.branchtip(branch) |
e7bf09acd410
localrepo: add branchtip() method for faster single-branch lookups
Brodie Rao <brodie@sf.io>
parents:
16308
diff
changeset
|
299 except error.RepoLookupError: |
e7bf09acd410
localrepo: add branchtip() method for faster single-branch lookups
Brodie Rao <brodie@sf.io>
parents:
16308
diff
changeset
|
300 branchnode = None |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
301 if branch != b'default' and branchnode != ctx.node(): |
37906
a5d16f23a2c9
hgweb: wrap {inbranch} by hybridlist()
Yuya Nishihara <yuya@tcha.org>
parents:
37905
diff
changeset
|
302 branches.append(branch) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
303 return templateutil.hybridlist(branches, name=b'name') |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
304 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
305 |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
306 def nodebranchnodefault(ctx): |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
307 branches = [] |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
308 branch = ctx.branch() |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
309 if branch != b'default': |
37907
3b3d818bde8b
hgweb: wrap {branch} and {changesetbranch} by hybridlist()
Yuya Nishihara <yuya@tcha.org>
parents:
37906
diff
changeset
|
310 branches.append(branch) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
311 return templateutil.hybridlist(branches, name=b'name') |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
312 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
313 |
37911
26aed0d561e8
hgweb: wrap {changelogtag}, {changesettag}, and {changesetbookmark}
Yuya Nishihara <yuya@tcha.org>
parents:
37910
diff
changeset
|
314 def _nodenamesgen(context, f, node, name): |
26aed0d561e8
hgweb: wrap {changelogtag}, {changesettag}, and {changesetbookmark}
Yuya Nishihara <yuya@tcha.org>
parents:
37910
diff
changeset
|
315 for t in f(node): |
26aed0d561e8
hgweb: wrap {changelogtag}, {changesettag}, and {changesetbookmark}
Yuya Nishihara <yuya@tcha.org>
parents:
37910
diff
changeset
|
316 yield {name: t} |
26aed0d561e8
hgweb: wrap {changelogtag}, {changesettag}, and {changesetbookmark}
Yuya Nishihara <yuya@tcha.org>
parents:
37910
diff
changeset
|
317 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
318 |
37912
16c7a6ac8f94
hgweb: drop tmpl argument from webutil.showtag() and showbookmark()
Yuya Nishihara <yuya@tcha.org>
parents:
37911
diff
changeset
|
319 def showtag(repo, t1, node=nullid): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
320 args = (repo.nodetags, node, b'tag') |
37911
26aed0d561e8
hgweb: wrap {changelogtag}, {changesettag}, and {changesetbookmark}
Yuya Nishihara <yuya@tcha.org>
parents:
37910
diff
changeset
|
321 return templateutil.mappinggenerator(_nodenamesgen, args=args, name=t1) |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
322 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
323 |
37912
16c7a6ac8f94
hgweb: drop tmpl argument from webutil.showtag() and showbookmark()
Yuya Nishihara <yuya@tcha.org>
parents:
37911
diff
changeset
|
324 def showbookmark(repo, t1, node=nullid): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
325 args = (repo.nodebookmarks, node, b'bookmark') |
37911
26aed0d561e8
hgweb: wrap {changelogtag}, {changesettag}, and {changesetbookmark}
Yuya Nishihara <yuya@tcha.org>
parents:
37910
diff
changeset
|
326 return templateutil.mappinggenerator(_nodenamesgen, args=args, name=t1) |
13596
270f57d35525
hgweb: add display of bookmarks for changelog and changeset
Alexander Solovyov <alexander@solovyov.net>
parents:
12691
diff
changeset
|
327 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
328 |
26129
a103ecb8a04a
hgweb: move branchentries code from webcommands to webutil
Anton Shestakov <av6@dwimlabs.net>
parents:
25999
diff
changeset
|
329 def branchentries(repo, stripecount, limit=0): |
a103ecb8a04a
hgweb: move branchentries code from webcommands to webutil
Anton Shestakov <av6@dwimlabs.net>
parents:
25999
diff
changeset
|
330 tips = [] |
a103ecb8a04a
hgweb: move branchentries code from webcommands to webutil
Anton Shestakov <av6@dwimlabs.net>
parents:
25999
diff
changeset
|
331 heads = repo.heads() |
a103ecb8a04a
hgweb: move branchentries code from webcommands to webutil
Anton Shestakov <av6@dwimlabs.net>
parents:
25999
diff
changeset
|
332 parity = paritygen(stripecount) |
a103ecb8a04a
hgweb: move branchentries code from webcommands to webutil
Anton Shestakov <av6@dwimlabs.net>
parents:
25999
diff
changeset
|
333 sortkey = lambda item: (not item[1], item[0].rev()) |
a103ecb8a04a
hgweb: move branchentries code from webcommands to webutil
Anton Shestakov <av6@dwimlabs.net>
parents:
25999
diff
changeset
|
334 |
37913
89db78126f7f
hgweb: wrap {branches} and {entries} of branches with mappinggenerator
Yuya Nishihara <yuya@tcha.org>
parents:
37912
diff
changeset
|
335 def entries(context): |
26129
a103ecb8a04a
hgweb: move branchentries code from webcommands to webutil
Anton Shestakov <av6@dwimlabs.net>
parents:
25999
diff
changeset
|
336 count = 0 |
a103ecb8a04a
hgweb: move branchentries code from webcommands to webutil
Anton Shestakov <av6@dwimlabs.net>
parents:
25999
diff
changeset
|
337 if not tips: |
a103ecb8a04a
hgweb: move branchentries code from webcommands to webutil
Anton Shestakov <av6@dwimlabs.net>
parents:
25999
diff
changeset
|
338 for tag, hs, tip, closed in repo.branchmap().iterbranches(): |
a103ecb8a04a
hgweb: move branchentries code from webcommands to webutil
Anton Shestakov <av6@dwimlabs.net>
parents:
25999
diff
changeset
|
339 tips.append((repo[tip], closed)) |
a103ecb8a04a
hgweb: move branchentries code from webcommands to webutil
Anton Shestakov <av6@dwimlabs.net>
parents:
25999
diff
changeset
|
340 for ctx, closed in sorted(tips, key=sortkey, reverse=True): |
a103ecb8a04a
hgweb: move branchentries code from webcommands to webutil
Anton Shestakov <av6@dwimlabs.net>
parents:
25999
diff
changeset
|
341 if limit > 0 and count >= limit: |
a103ecb8a04a
hgweb: move branchentries code from webcommands to webutil
Anton Shestakov <av6@dwimlabs.net>
parents:
25999
diff
changeset
|
342 return |
a103ecb8a04a
hgweb: move branchentries code from webcommands to webutil
Anton Shestakov <av6@dwimlabs.net>
parents:
25999
diff
changeset
|
343 count += 1 |
a103ecb8a04a
hgweb: move branchentries code from webcommands to webutil
Anton Shestakov <av6@dwimlabs.net>
parents:
25999
diff
changeset
|
344 if closed: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
345 status = b'closed' |
26129
a103ecb8a04a
hgweb: move branchentries code from webcommands to webutil
Anton Shestakov <av6@dwimlabs.net>
parents:
25999
diff
changeset
|
346 elif ctx.node() not in heads: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
347 status = b'inactive' |
26129
a103ecb8a04a
hgweb: move branchentries code from webcommands to webutil
Anton Shestakov <av6@dwimlabs.net>
parents:
25999
diff
changeset
|
348 else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
349 status = b'open' |
26129
a103ecb8a04a
hgweb: move branchentries code from webcommands to webutil
Anton Shestakov <av6@dwimlabs.net>
parents:
25999
diff
changeset
|
350 yield { |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
351 b'parity': next(parity), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
352 b'branch': ctx.branch(), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
353 b'status': status, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
354 b'node': ctx.hex(), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
355 b'date': ctx.date(), |
26129
a103ecb8a04a
hgweb: move branchentries code from webcommands to webutil
Anton Shestakov <av6@dwimlabs.net>
parents:
25999
diff
changeset
|
356 } |
a103ecb8a04a
hgweb: move branchentries code from webcommands to webutil
Anton Shestakov <av6@dwimlabs.net>
parents:
25999
diff
changeset
|
357 |
37913
89db78126f7f
hgweb: wrap {branches} and {entries} of branches with mappinggenerator
Yuya Nishihara <yuya@tcha.org>
parents:
37912
diff
changeset
|
358 return templateutil.mappinggenerator(entries) |
26129
a103ecb8a04a
hgweb: move branchentries code from webcommands to webutil
Anton Shestakov <av6@dwimlabs.net>
parents:
25999
diff
changeset
|
359 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
360 |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
361 def cleanpath(repo, path): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
362 path = path.lstrip(b'/') |
39471
15e8250a82da
hgweb: do not audit URL path as working-directory path
Yuya Nishihara <yuya@tcha.org>
parents:
38929
diff
changeset
|
363 auditor = pathutil.pathauditor(repo.root, realfs=False) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
364 return pathutil.canonpath(repo.root, b'', path, auditor=auditor) |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
365 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
366 |
25999
1c75249e159b
style: adjust whitespaces in webutil.py
Anton Shestakov <av6@dwimlabs.net>
parents:
25778
diff
changeset
|
367 def changectx(repo, req): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
368 changeid = b"tip" |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
369 if b'node' in req.qsparams: |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
370 changeid = req.qsparams[b'node'] |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
371 ipos = changeid.find(b':') |
17991
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
372 if ipos != -1: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
373 changeid = changeid[(ipos + 1) :] |
17991
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
374 |
37335
956260cbc564
hgweb: use revsymbol() for creating context from changeid
Martin von Zweigbergk <martinvonz@google.com>
parents:
37334
diff
changeset
|
375 return scmutil.revsymbol(repo, changeid) |
17991
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
376 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
377 |
17991
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
378 def basechangectx(repo, req): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
379 if b'node' in req.qsparams: |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
380 changeid = req.qsparams[b'node'] |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
381 ipos = changeid.find(b':') |
17991
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
382 if ipos != -1: |
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
383 changeid = changeid[:ipos] |
37335
956260cbc564
hgweb: use revsymbol() for creating context from changeid
Martin von Zweigbergk <martinvonz@google.com>
parents:
37334
diff
changeset
|
384 return scmutil.revsymbol(repo, changeid) |
17991
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
385 |
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
386 return None |
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
387 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
388 |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
389 def filectx(repo, req): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
390 if b'file' not in req.qsparams: |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
391 raise ErrorResponse(HTTP_NOT_FOUND, b'file not given') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
392 path = cleanpath(repo, req.qsparams[b'file']) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
393 if b'node' in req.qsparams: |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
394 changeid = req.qsparams[b'node'] |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
395 elif b'filenode' in req.qsparams: |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
396 changeid = req.qsparams[b'filenode'] |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
397 else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
398 raise ErrorResponse(HTTP_NOT_FOUND, b'node or filenode not given') |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
399 try: |
37335
956260cbc564
hgweb: use revsymbol() for creating context from changeid
Martin von Zweigbergk <martinvonz@google.com>
parents:
37334
diff
changeset
|
400 fctx = scmutil.revsymbol(repo, changeid)[path] |
7637 | 401 except error.RepoError: |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
402 fctx = repo.filectx(path, fileid=changeid) |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
403 |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
404 return fctx |
7310
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
405 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
406 |
31665
5e6d44511317
hgweb: handle a "linerange" request parameter in filelog command
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31660
diff
changeset
|
407 def linerange(req): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
408 linerange = req.qsparams.getall(b'linerange') |
36865
3d60a22e27f5
hgweb: perform all parameter lookup via qsparams
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36863
diff
changeset
|
409 if not linerange: |
31665
5e6d44511317
hgweb: handle a "linerange" request parameter in filelog command
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31660
diff
changeset
|
410 return None |
5e6d44511317
hgweb: handle a "linerange" request parameter in filelog command
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31660
diff
changeset
|
411 if len(linerange) > 1: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
412 raise ErrorResponse(HTTP_BAD_REQUEST, b'redundant linerange parameter') |
31665
5e6d44511317
hgweb: handle a "linerange" request parameter in filelog command
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31660
diff
changeset
|
413 try: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
414 fromline, toline = map(int, linerange[0].split(b':', 1)) |
31665
5e6d44511317
hgweb: handle a "linerange" request parameter in filelog command
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31660
diff
changeset
|
415 except ValueError: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
416 raise ErrorResponse(HTTP_BAD_REQUEST, b'invalid linerange parameter') |
31665
5e6d44511317
hgweb: handle a "linerange" request parameter in filelog command
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31660
diff
changeset
|
417 try: |
5e6d44511317
hgweb: handle a "linerange" request parameter in filelog command
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31660
diff
changeset
|
418 return util.processlinerange(fromline, toline) |
5e6d44511317
hgweb: handle a "linerange" request parameter in filelog command
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31660
diff
changeset
|
419 except error.ParseError as exc: |
36258
af0a19d8812b
py3: get bytes-repr of network errors portably
Augie Fackler <augie@google.com>
parents:
36183
diff
changeset
|
420 raise ErrorResponse(HTTP_BAD_REQUEST, pycompat.bytestr(exc)) |
31665
5e6d44511317
hgweb: handle a "linerange" request parameter in filelog command
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31660
diff
changeset
|
421 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
422 |
31665
5e6d44511317
hgweb: handle a "linerange" request parameter in filelog command
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31660
diff
changeset
|
423 def formatlinerange(fromline, toline): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
424 return b'%d:%d' % (fromline + 1, toline) |
31665
5e6d44511317
hgweb: handle a "linerange" request parameter in filelog command
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31660
diff
changeset
|
425 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
426 |
37914
10d3dc8123c5
hgweb: wrap {succsandmarkers} with mappinggenerator
Yuya Nishihara <yuya@tcha.org>
parents:
37913
diff
changeset
|
427 def _succsandmarkersgen(context, mapping): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
428 repo = context.resource(mapping, b'repo') |
37503
49a8c2cc7978
templatekw: fix return type of {succsandmarkers} (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
37335
diff
changeset
|
429 itemmappings = templatekw.showsuccsandmarkers(context, mapping) |
49a8c2cc7978
templatekw: fix return type of {succsandmarkers} (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
37335
diff
changeset
|
430 for item in itemmappings.tovalue(context, mapping): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
431 item[b'successors'] = _siblings( |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
432 repo[successor] for successor in item[b'successors'] |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
433 ) |
35486
4c7ae95e1c71
hgweb: link to successors of obsoleted changesets
Anton Shestakov <av6@dwimlabs.net>
parents:
35485
diff
changeset
|
434 yield item |
35485
1721ce06100a
hgweb: display fate of obsolete changesets
Anton Shestakov <av6@dwimlabs.net>
parents:
35454
diff
changeset
|
435 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
436 |
37914
10d3dc8123c5
hgweb: wrap {succsandmarkers} with mappinggenerator
Yuya Nishihara <yuya@tcha.org>
parents:
37913
diff
changeset
|
437 def succsandmarkers(context, mapping): |
10d3dc8123c5
hgweb: wrap {succsandmarkers} with mappinggenerator
Yuya Nishihara <yuya@tcha.org>
parents:
37913
diff
changeset
|
438 return templateutil.mappinggenerator(_succsandmarkersgen, args=(mapping,)) |
10d3dc8123c5
hgweb: wrap {succsandmarkers} with mappinggenerator
Yuya Nishihara <yuya@tcha.org>
parents:
37913
diff
changeset
|
439 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
440 |
36594
59ee648870a7
templatekw: switch obsfate-related template keywords to new API
Yuya Nishihara <yuya@tcha.org>
parents:
36518
diff
changeset
|
441 # teach templater succsandmarkers is switched to (context, mapping) API |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
442 succsandmarkers._requires = {b'repo', b'ctx'} |
36594
59ee648870a7
templatekw: switch obsfate-related template keywords to new API
Yuya Nishihara <yuya@tcha.org>
parents:
36518
diff
changeset
|
443 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
444 |
37915
3dc4045db164
hgweb: wrap {whyunstable} with mappinggenerator
Yuya Nishihara <yuya@tcha.org>
parents:
37914
diff
changeset
|
445 def _whyunstablegen(context, mapping): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
446 repo = context.resource(mapping, b'repo') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
447 ctx = context.resource(mapping, b'ctx') |
36955
f21798a6bc20
hgweb: explain instabilities of unstable changesets
Anton Shestakov <av6@dwimlabs.net>
parents:
36886
diff
changeset
|
448 |
f21798a6bc20
hgweb: explain instabilities of unstable changesets
Anton Shestakov <av6@dwimlabs.net>
parents:
36886
diff
changeset
|
449 entries = obsutil.whyunstable(repo, ctx) |
f21798a6bc20
hgweb: explain instabilities of unstable changesets
Anton Shestakov <av6@dwimlabs.net>
parents:
36886
diff
changeset
|
450 for entry in entries: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
451 if entry.get(b'divergentnodes'): |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
452 entry[b'divergentnodes'] = _siblings(entry[b'divergentnodes']) |
36955
f21798a6bc20
hgweb: explain instabilities of unstable changesets
Anton Shestakov <av6@dwimlabs.net>
parents:
36886
diff
changeset
|
453 yield entry |
f21798a6bc20
hgweb: explain instabilities of unstable changesets
Anton Shestakov <av6@dwimlabs.net>
parents:
36886
diff
changeset
|
454 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
455 |
37915
3dc4045db164
hgweb: wrap {whyunstable} with mappinggenerator
Yuya Nishihara <yuya@tcha.org>
parents:
37914
diff
changeset
|
456 def whyunstable(context, mapping): |
3dc4045db164
hgweb: wrap {whyunstable} with mappinggenerator
Yuya Nishihara <yuya@tcha.org>
parents:
37914
diff
changeset
|
457 return templateutil.mappinggenerator(_whyunstablegen, args=(mapping,)) |
3dc4045db164
hgweb: wrap {whyunstable} with mappinggenerator
Yuya Nishihara <yuya@tcha.org>
parents:
37914
diff
changeset
|
458 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
459 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
460 whyunstable._requires = {b'repo', b'ctx'} |
36955
f21798a6bc20
hgweb: explain instabilities of unstable changesets
Anton Shestakov <av6@dwimlabs.net>
parents:
36886
diff
changeset
|
461 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
462 |
27294
5aa2afb4f81a
hgweb: move entry-preparing code from webcommands to webutils.commonentry()
Anton Shestakov <av6@dwimlabs.net>
parents:
27046
diff
changeset
|
463 def commonentry(repo, ctx): |
39794
4f44f747f094
hgweb: use scmutil.binnode() to translate None to wdir hash (issue5988)
Yuya Nishihara <yuya@tcha.org>
parents:
39471
diff
changeset
|
464 node = scmutil.binnode(ctx) |
27294
5aa2afb4f81a
hgweb: move entry-preparing code from webcommands to webutils.commonentry()
Anton Shestakov <av6@dwimlabs.net>
parents:
27046
diff
changeset
|
465 return { |
36518
7937850a523d
hgweb: make templater mostly compatible with log templates
Yuya Nishihara <yuya@tcha.org>
parents:
36434
diff
changeset
|
466 # TODO: perhaps ctx.changectx() should be assigned if ctx is a |
7937850a523d
hgweb: make templater mostly compatible with log templates
Yuya Nishihara <yuya@tcha.org>
parents:
36434
diff
changeset
|
467 # filectx, but I'm not pretty sure if that would always work because |
7937850a523d
hgweb: make templater mostly compatible with log templates
Yuya Nishihara <yuya@tcha.org>
parents:
36434
diff
changeset
|
468 # fctx.parents() != fctx.changectx.parents() for example. |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
469 b'ctx': ctx, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
470 b'rev': ctx.rev(), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
471 b'node': hex(node), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
472 b'author': ctx.user(), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
473 b'desc': ctx.description(), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
474 b'date': ctx.date(), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
475 b'extra': ctx.extra(), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
476 b'phase': ctx.phasestr(), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
477 b'obsolete': ctx.obsolete(), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
478 b'succsandmarkers': succsandmarkers, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
479 b'instabilities': templateutil.hybridlist( |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
480 ctx.instabilities(), name=b'instability' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
481 ), |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
482 b'whyunstable': whyunstable, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
483 b'branch': nodebranchnodefault(ctx), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
484 b'inbranch': nodeinbranch(repo, ctx), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
485 b'branches': nodebranchdict(repo, ctx), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
486 b'tags': nodetagsdict(repo, node), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
487 b'bookmarks': nodebookmarksdict(repo, node), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
488 b'parent': lambda context, mapping: parents(ctx), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
489 b'child': lambda context, mapping: children(ctx), |
27294
5aa2afb4f81a
hgweb: move entry-preparing code from webcommands to webutils.commonentry()
Anton Shestakov <av6@dwimlabs.net>
parents:
27046
diff
changeset
|
490 } |
5aa2afb4f81a
hgweb: move entry-preparing code from webcommands to webutils.commonentry()
Anton Shestakov <av6@dwimlabs.net>
parents:
27046
diff
changeset
|
491 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
492 |
36885
c68e79dcf21c
hgweb: don't redundantly pass templater with requestcontext (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36865
diff
changeset
|
493 def changelistentry(web, ctx): |
23745
513d47905114
hgweb: extract changelist entry generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21122
diff
changeset
|
494 '''Obtain a dictionary to be used for entries in a changelist. |
513d47905114
hgweb: extract changelist entry generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21122
diff
changeset
|
495 |
513d47905114
hgweb: extract changelist entry generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21122
diff
changeset
|
496 This function is called when producing items for the "entries" list passed |
513d47905114
hgweb: extract changelist entry generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21122
diff
changeset
|
497 to the "shortlog" and "changelog" templates. |
513d47905114
hgweb: extract changelist entry generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21122
diff
changeset
|
498 ''' |
513d47905114
hgweb: extract changelist entry generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21122
diff
changeset
|
499 repo = web.repo |
513d47905114
hgweb: extract changelist entry generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21122
diff
changeset
|
500 rev = ctx.rev() |
39794
4f44f747f094
hgweb: use scmutil.binnode() to translate None to wdir hash (issue5988)
Yuya Nishihara <yuya@tcha.org>
parents:
39471
diff
changeset
|
501 n = scmutil.binnode(ctx) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
502 showtags = showtag(repo, b'changelogtag', n) |
37954
9482498b96b0
hgweb: remove unused argument 'tmpl' from listfilediffs()
Yuya Nishihara <yuya@tcha.org>
parents:
37953
diff
changeset
|
503 files = listfilediffs(ctx.files(), n, web.maxfiles) |
23745
513d47905114
hgweb: extract changelist entry generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21122
diff
changeset
|
504 |
27294
5aa2afb4f81a
hgweb: move entry-preparing code from webcommands to webutils.commonentry()
Anton Shestakov <av6@dwimlabs.net>
parents:
27046
diff
changeset
|
505 entry = commonentry(repo, ctx) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
506 entry.update( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
507 { |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
508 b'allparents': lambda context, mapping: parents(ctx), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
509 b'parent': lambda context, mapping: parents(ctx, rev - 1), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
510 b'child': lambda context, mapping: children(ctx, rev + 1), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
511 b'changelogtag': showtags, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
512 b'files': files, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
513 } |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
514 ) |
27294
5aa2afb4f81a
hgweb: move entry-preparing code from webcommands to webutils.commonentry()
Anton Shestakov <av6@dwimlabs.net>
parents:
27046
diff
changeset
|
515 return entry |
23745
513d47905114
hgweb: extract changelist entry generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21122
diff
changeset
|
516 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
517 |
38043
5989261a8356
hgweb: extract code for emitting multiple changelist records
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37993
diff
changeset
|
518 def changelistentries(web, revs, maxcount, parityfn): |
5989261a8356
hgweb: extract code for emitting multiple changelist records
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37993
diff
changeset
|
519 """Emit up to N records for an iterable of revisions.""" |
5989261a8356
hgweb: extract code for emitting multiple changelist records
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37993
diff
changeset
|
520 repo = web.repo |
5989261a8356
hgweb: extract code for emitting multiple changelist records
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37993
diff
changeset
|
521 |
5989261a8356
hgweb: extract code for emitting multiple changelist records
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37993
diff
changeset
|
522 count = 0 |
5989261a8356
hgweb: extract code for emitting multiple changelist records
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37993
diff
changeset
|
523 for rev in revs: |
5989261a8356
hgweb: extract code for emitting multiple changelist records
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37993
diff
changeset
|
524 if count >= maxcount: |
5989261a8356
hgweb: extract code for emitting multiple changelist records
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37993
diff
changeset
|
525 break |
5989261a8356
hgweb: extract code for emitting multiple changelist records
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37993
diff
changeset
|
526 |
5989261a8356
hgweb: extract code for emitting multiple changelist records
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37993
diff
changeset
|
527 count += 1 |
5989261a8356
hgweb: extract code for emitting multiple changelist records
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37993
diff
changeset
|
528 |
5989261a8356
hgweb: extract code for emitting multiple changelist records
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37993
diff
changeset
|
529 entry = changelistentry(web, repo[rev]) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
530 entry[b'parity'] = next(parityfn) |
38043
5989261a8356
hgweb: extract code for emitting multiple changelist records
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37993
diff
changeset
|
531 |
5989261a8356
hgweb: extract code for emitting multiple changelist records
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37993
diff
changeset
|
532 yield entry |
5989261a8356
hgweb: extract code for emitting multiple changelist records
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37993
diff
changeset
|
533 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
534 |
25602
85fb416f2fa7
hgweb: provide symrev (symbolic revision) property to the templates
Anton Shestakov <av6@dwimlabs.net>
parents:
25278
diff
changeset
|
535 def symrevorshortnode(req, ctx): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
536 if b'node' in req.qsparams: |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
537 return templatefilters.revescape(req.qsparams[b'node']) |
25602
85fb416f2fa7
hgweb: provide symrev (symbolic revision) property to the templates
Anton Shestakov <av6@dwimlabs.net>
parents:
25278
diff
changeset
|
538 else: |
39794
4f44f747f094
hgweb: use scmutil.binnode() to translate None to wdir hash (issue5988)
Yuya Nishihara <yuya@tcha.org>
parents:
39471
diff
changeset
|
539 return short(scmutil.binnode(ctx)) |
25602
85fb416f2fa7
hgweb: provide symrev (symbolic revision) property to the templates
Anton Shestakov <av6@dwimlabs.net>
parents:
25278
diff
changeset
|
540 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
541 |
37951
c4313a9fde7b
hgweb: use template context to render {files} of changesetentry()
Yuya Nishihara <yuya@tcha.org>
parents:
37950
diff
changeset
|
542 def _listfilesgen(context, ctx, stripecount): |
37949
1129e444fd6c
hgweb: extract generator of {files} from changesetentry()
Yuya Nishihara <yuya@tcha.org>
parents:
37916
diff
changeset
|
543 parity = paritygen(stripecount) |
43716
33cff871d3b9
hgweb: add a status property to file list context
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
43106
diff
changeset
|
544 filesadded = ctx.filesadded() |
37949
1129e444fd6c
hgweb: extract generator of {files} from changesetentry()
Yuya Nishihara <yuya@tcha.org>
parents:
37916
diff
changeset
|
545 for blockno, f in enumerate(ctx.files()): |
43716
33cff871d3b9
hgweb: add a status property to file list context
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
43106
diff
changeset
|
546 if f not in ctx: |
33cff871d3b9
hgweb: add a status property to file list context
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
43106
diff
changeset
|
547 status = b'removed' |
33cff871d3b9
hgweb: add a status property to file list context
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
43106
diff
changeset
|
548 elif f in filesadded: |
33cff871d3b9
hgweb: add a status property to file list context
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
43106
diff
changeset
|
549 status = b'added' |
33cff871d3b9
hgweb: add a status property to file list context
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
43106
diff
changeset
|
550 else: |
33cff871d3b9
hgweb: add a status property to file list context
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
43106
diff
changeset
|
551 status = b'modified' |
33cff871d3b9
hgweb: add a status property to file list context
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
43106
diff
changeset
|
552 template = b'filenolink' if status == b'removed' else b'filenodelink' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
553 yield context.process( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
554 template, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
555 { |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
556 b'node': ctx.hex(), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
557 b'file': f, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
558 b'blockno': blockno + 1, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
559 b'parity': next(parity), |
43716
33cff871d3b9
hgweb: add a status property to file list context
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
43106
diff
changeset
|
560 b'status': status, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
561 }, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
562 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
563 |
37949
1129e444fd6c
hgweb: extract generator of {files} from changesetentry()
Yuya Nishihara <yuya@tcha.org>
parents:
37916
diff
changeset
|
564 |
36886
563fd95a6efb
hgweb: pass modern request type into various webutil functions (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36885
diff
changeset
|
565 def changesetentry(web, ctx): |
24177
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
566 '''Obtain a dictionary to be used to render the "changeset" template.''' |
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
567 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
568 showtags = showtag(web.repo, b'changesettag', scmutil.binnode(ctx)) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
569 showbookmarks = showbookmark( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
570 web.repo, b'changesetbookmark', scmutil.binnode(ctx) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
571 ) |
24177
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
572 showbranch = nodebranchnodefault(ctx) |
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
573 |
36886
563fd95a6efb
hgweb: pass modern request type into various webutil functions (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36885
diff
changeset
|
574 basectx = basechangectx(web.repo, web.req) |
24177
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
575 if basectx is None: |
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
576 basectx = ctx.p1() |
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
577 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
578 style = web.config(b'web', b'style') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
579 if b'style' in web.req.qsparams: |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
580 style = web.req.qsparams[b'style'] |
24177
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
581 |
36885
c68e79dcf21c
hgweb: don't redundantly pass templater with requestcontext (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36865
diff
changeset
|
582 diff = diffs(web, ctx, basectx, None, style) |
24177
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
583 |
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
584 parity = paritygen(web.stripecount) |
38585
66eb74f9d87d
hgweb: pass ui to diffstatgen() explicitly
Yuya Nishihara <yuya@tcha.org>
parents:
38566
diff
changeset
|
585 diffstatsgen = diffstatgen(web.repo.ui, ctx, basectx) |
38059
4c3ab15f3532
hgweb: drop unused argument 'tmpl' from webutil.diffstat()
Yuya Nishihara <yuya@tcha.org>
parents:
38058
diff
changeset
|
586 diffstats = diffstat(ctx, diffstatsgen, parity) |
24177
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
587 |
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
588 return dict( |
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
589 diff=diff, |
36886
563fd95a6efb
hgweb: pass modern request type into various webutil functions (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36885
diff
changeset
|
590 symrev=symrevorshortnode(web.req, ctx), |
24177
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
591 basenode=basectx.hex(), |
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
592 changesettag=showtags, |
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
593 changesetbookmark=showbookmarks, |
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
594 changesetbranch=showbranch, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
595 files=templateutil.mappedgenerator( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
596 _listfilesgen, args=(ctx, web.stripecount) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
597 ), |
42337
832c59d1196e
templater: drop support for old style keywords (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
41676
diff
changeset
|
598 diffsummary=lambda context, mapping: diffsummary(diffstatsgen), |
24177
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
599 diffstat=diffstats, |
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
600 archives=web.archivelist(ctx.hex()), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
601 **pycompat.strkwargs(commonentry(web.repo, ctx)) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
602 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
603 |
24177
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
604 |
37953
4237d07fad2c
hgweb: use template context to render {files} of changelist entries
Yuya Nishihara <yuya@tcha.org>
parents:
37952
diff
changeset
|
605 def _listfilediffsgen(context, files, node, max): |
7311
de9c87fe1620
hgweb: move another utility function into the webutil module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7310
diff
changeset
|
606 for f in files[:max]: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
607 yield context.process(b'filedifflink', {b'node': hex(node), b'file': f}) |
7311
de9c87fe1620
hgweb: move another utility function into the webutil module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7310
diff
changeset
|
608 if len(files) > max: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
609 yield context.process(b'fileellipses', {}) |
7311
de9c87fe1620
hgweb: move another utility function into the webutil module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7310
diff
changeset
|
610 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
611 |
37954
9482498b96b0
hgweb: remove unused argument 'tmpl' from listfilediffs()
Yuya Nishihara <yuya@tcha.org>
parents:
37953
diff
changeset
|
612 def listfilediffs(files, node, max): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
613 return templateutil.mappedgenerator( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
614 _listfilediffsgen, args=(files, node, max) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
615 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
616 |
37952
028d7c24f2e5
hgweb: wrap {files} of changelist entries with mappedgenerator
Yuya Nishihara <yuya@tcha.org>
parents:
37951
diff
changeset
|
617 |
37986
7a9e9fbaa559
hgweb: use template context to render {lines} of {diff}
Yuya Nishihara <yuya@tcha.org>
parents:
37985
diff
changeset
|
618 def _prettyprintdifflines(context, lines, blockno, lineidprefix): |
37984
3f70466ec7aa
hgweb: move prettyprintlines() closure out of diffs()
Yuya Nishihara <yuya@tcha.org>
parents:
37954
diff
changeset
|
619 for lineno, l in enumerate(lines, 1): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
620 difflineno = b"%d.%d" % (blockno, lineno) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
621 if l.startswith(b'+'): |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
622 ltype = b"difflineplus" |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
623 elif l.startswith(b'-'): |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
624 ltype = b"difflineminus" |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
625 elif l.startswith(b'@'): |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
626 ltype = b"difflineat" |
37984
3f70466ec7aa
hgweb: move prettyprintlines() closure out of diffs()
Yuya Nishihara <yuya@tcha.org>
parents:
37954
diff
changeset
|
627 else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
628 ltype = b"diffline" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
629 yield context.process( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
630 ltype, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
631 { |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
632 b'line': l, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
633 b'lineno': lineno, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
634 b'lineid': lineidprefix + b"l%s" % difflineno, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
635 b'linenumber': b"% 8s" % difflineno, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
636 }, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
637 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
638 |
37984
3f70466ec7aa
hgweb: move prettyprintlines() closure out of diffs()
Yuya Nishihara <yuya@tcha.org>
parents:
37954
diff
changeset
|
639 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
640 def _diffsgen( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
641 context, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
642 repo, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
643 ctx, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
644 basectx, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
645 files, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
646 style, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
647 stripecount, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
648 linerange, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
649 lineidprefix, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
650 ): |
7310
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
651 if files: |
41676
0531dff73d0b
match: delete unused root and cwd arguments from {always,never,exact}() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
41618
diff
changeset
|
652 m = match.exact(files) |
7310
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
653 else: |
41676
0531dff73d0b
match: delete unused root and cwd arguments from {always,never,exact}() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
41618
diff
changeset
|
654 m = match.always() |
7310
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
655 |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
656 diffopts = patch.diffopts(repo.ui, untrusted=True) |
37987
8cc23a46df37
hgweb: convert {diff} to a mappinggenerator with named template
Yuya Nishihara <yuya@tcha.org>
parents:
37986
diff
changeset
|
657 parity = paritygen(stripecount) |
7310
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
658 |
41618
e834f6f6f221
patch: pass in context objects into diffhunks() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
41325
diff
changeset
|
659 diffhunks = patch.diffhunks(repo, basectx, ctx, m, opts=diffopts) |
34855
35c6a54ec1ff
diff: also yield file context objects in patch.trydiff() (API)
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34807
diff
changeset
|
660 for blockno, (fctx1, fctx2, header, hunks) in enumerate(diffhunks, 1): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
661 if style != b'raw': |
31276
cd29673cebdb
hgweb: use patch.diffhunks in webutil.diffs to simplify the algorithm
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31275
diff
changeset
|
662 header = header[1:] |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
663 lines = [h + b'\n' for h in header] |
31276
cd29673cebdb
hgweb: use patch.diffhunks in webutil.diffs to simplify the algorithm
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31275
diff
changeset
|
664 for hunkrange, hunklines in hunks: |
31666
aaebc80c9f1d
hgweb: add a 'linerange' parameter to webutil.diffs()
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31665
diff
changeset
|
665 if linerange is not None and hunkrange is not None: |
aaebc80c9f1d
hgweb: add a 'linerange' parameter to webutil.diffs()
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31665
diff
changeset
|
666 s1, l1, s2, l2 = hunkrange |
31808
ca3b4a2b7e54
mdiff: add a hunkinrange helper function
Denis Laxalde <denis@laxalde.org>
parents:
31727
diff
changeset
|
667 if not mdiff.hunkinrange((s2, l2), linerange): |
31666
aaebc80c9f1d
hgweb: add a 'linerange' parameter to webutil.diffs()
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31665
diff
changeset
|
668 continue |
31276
cd29673cebdb
hgweb: use patch.diffhunks in webutil.diffs to simplify the algorithm
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31275
diff
changeset
|
669 lines.extend(hunklines) |
cd29673cebdb
hgweb: use patch.diffhunks in webutil.diffs to simplify the algorithm
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31275
diff
changeset
|
670 if lines: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
671 l = templateutil.mappedgenerator( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
672 _prettyprintdifflines, args=(lines, blockno, lineidprefix) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
673 ) |
37987
8cc23a46df37
hgweb: convert {diff} to a mappinggenerator with named template
Yuya Nishihara <yuya@tcha.org>
parents:
37986
diff
changeset
|
674 yield { |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
675 b'parity': next(parity), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
676 b'blockno': blockno, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
677 b'lines': l, |
37987
8cc23a46df37
hgweb: convert {diff} to a mappinggenerator with named template
Yuya Nishihara <yuya@tcha.org>
parents:
37986
diff
changeset
|
678 } |
8cc23a46df37
hgweb: convert {diff} to a mappinggenerator with named template
Yuya Nishihara <yuya@tcha.org>
parents:
37986
diff
changeset
|
679 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
680 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
681 def diffs(web, ctx, basectx, files, style, linerange=None, lineidprefix=b''): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
682 args = ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
683 web.repo, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
684 ctx, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
685 basectx, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
686 files, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
687 style, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
688 web.stripecount, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
689 linerange, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
690 lineidprefix, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
691 ) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
692 return templateutil.mappinggenerator( |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
693 _diffsgen, args=args, name=b'diffblock' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
694 ) |
7345
55651328dfcc
hgweb: fix up the less/more links on the graph page
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7311
diff
changeset
|
695 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
696 |
37990
c0ccbf4fbe47
hgweb: convert comparison {lines} to a mappinggenerator with named template
Yuya Nishihara <yuya@tcha.org>
parents:
37989
diff
changeset
|
697 def _compline(type, leftlineno, leftline, rightlineno, rightline): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
698 lineid = leftlineno and (b"l%d" % leftlineno) or b'' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
699 lineid += rightlineno and (b"r%d" % rightlineno) or b'' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
700 llno = b'%d' % leftlineno if leftlineno else b'' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
701 rlno = b'%d' % rightlineno if rightlineno else b'' |
37990
c0ccbf4fbe47
hgweb: convert comparison {lines} to a mappinggenerator with named template
Yuya Nishihara <yuya@tcha.org>
parents:
37989
diff
changeset
|
702 return { |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
703 b'type': type, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
704 b'lineid': lineid, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
705 b'leftlineno': leftlineno, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
706 b'leftlinenumber': b"% 6s" % llno, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
707 b'leftline': leftline or b'', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
708 b'rightlineno': rightlineno, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
709 b'rightlinenumber': b"% 6s" % rlno, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
710 b'rightline': rightline or b'', |
37990
c0ccbf4fbe47
hgweb: convert comparison {lines} to a mappinggenerator with named template
Yuya Nishihara <yuya@tcha.org>
parents:
37989
diff
changeset
|
711 } |
37988
406f945c5814
hgweb: move compline() closure out of compare()
Yuya Nishihara <yuya@tcha.org>
parents:
37987
diff
changeset
|
712 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
713 |
37990
c0ccbf4fbe47
hgweb: convert comparison {lines} to a mappinggenerator with named template
Yuya Nishihara <yuya@tcha.org>
parents:
37989
diff
changeset
|
714 def _getcompblockgen(context, leftlines, rightlines, opcodes): |
37989
53b0a51aed72
hgweb: move getblock() closure out of compare()
Yuya Nishihara <yuya@tcha.org>
parents:
37988
diff
changeset
|
715 for type, llo, lhi, rlo, rhi in opcodes: |
40156
5716d48b2a5b
py3: convert diff opcode name to bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39794
diff
changeset
|
716 type = pycompat.sysbytes(type) |
37989
53b0a51aed72
hgweb: move getblock() closure out of compare()
Yuya Nishihara <yuya@tcha.org>
parents:
37988
diff
changeset
|
717 len1 = lhi - llo |
53b0a51aed72
hgweb: move getblock() closure out of compare()
Yuya Nishihara <yuya@tcha.org>
parents:
37988
diff
changeset
|
718 len2 = rhi - rlo |
53b0a51aed72
hgweb: move getblock() closure out of compare()
Yuya Nishihara <yuya@tcha.org>
parents:
37988
diff
changeset
|
719 count = min(len1, len2) |
38783
e7aa113b14f7
global: use pycompat.xrange()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
38588
diff
changeset
|
720 for i in pycompat.xrange(count): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
721 yield _compline( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
722 type=type, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
723 leftlineno=llo + i + 1, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
724 leftline=leftlines[llo + i], |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
725 rightlineno=rlo + i + 1, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
726 rightline=rightlines[rlo + i], |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
727 ) |
37989
53b0a51aed72
hgweb: move getblock() closure out of compare()
Yuya Nishihara <yuya@tcha.org>
parents:
37988
diff
changeset
|
728 if len1 > len2: |
38783
e7aa113b14f7
global: use pycompat.xrange()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
38588
diff
changeset
|
729 for i in pycompat.xrange(llo + count, lhi): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
730 yield _compline( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
731 type=type, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
732 leftlineno=i + 1, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
733 leftline=leftlines[i], |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
734 rightlineno=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
735 rightline=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
736 ) |
37989
53b0a51aed72
hgweb: move getblock() closure out of compare()
Yuya Nishihara <yuya@tcha.org>
parents:
37988
diff
changeset
|
737 elif len2 > len1: |
38783
e7aa113b14f7
global: use pycompat.xrange()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
38588
diff
changeset
|
738 for i in pycompat.xrange(rlo + count, rhi): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
739 yield _compline( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
740 type=type, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
741 leftlineno=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
742 leftline=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
743 rightlineno=i + 1, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
744 rightline=rightlines[i], |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
745 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
746 |
17202
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
747 |
37990
c0ccbf4fbe47
hgweb: convert comparison {lines} to a mappinggenerator with named template
Yuya Nishihara <yuya@tcha.org>
parents:
37989
diff
changeset
|
748 def _getcompblock(leftlines, rightlines, opcodes): |
c0ccbf4fbe47
hgweb: convert comparison {lines} to a mappinggenerator with named template
Yuya Nishihara <yuya@tcha.org>
parents:
37989
diff
changeset
|
749 args = (leftlines, rightlines, opcodes) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
750 return templateutil.mappinggenerator( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
751 _getcompblockgen, args=args, name=b'comparisonline' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
752 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
753 |
37990
c0ccbf4fbe47
hgweb: convert comparison {lines} to a mappinggenerator with named template
Yuya Nishihara <yuya@tcha.org>
parents:
37989
diff
changeset
|
754 |
37992
b3992c21b7f3
hgweb: convert {comparison} to a mappinggenerator with named template
Yuya Nishihara <yuya@tcha.org>
parents:
37991
diff
changeset
|
755 def _comparegen(context, contextnum, leftlines, rightlines): |
37989
53b0a51aed72
hgweb: move getblock() closure out of compare()
Yuya Nishihara <yuya@tcha.org>
parents:
37988
diff
changeset
|
756 '''Generator function that provides side-by-side comparison data.''' |
17202
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
757 s = difflib.SequenceMatcher(None, leftlines, rightlines) |
37991
4e407c7b1fbd
hgweb: rename 'context' argument of webutil.compare() to avoid name conflicts
Yuya Nishihara <yuya@tcha.org>
parents:
37990
diff
changeset
|
758 if contextnum < 0: |
37990
c0ccbf4fbe47
hgweb: convert comparison {lines} to a mappinggenerator with named template
Yuya Nishihara <yuya@tcha.org>
parents:
37989
diff
changeset
|
759 l = _getcompblock(leftlines, rightlines, s.get_opcodes()) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
760 yield {b'lines': l} |
17202
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
761 else: |
37991
4e407c7b1fbd
hgweb: rename 'context' argument of webutil.compare() to avoid name conflicts
Yuya Nishihara <yuya@tcha.org>
parents:
37990
diff
changeset
|
762 for oc in s.get_grouped_opcodes(n=contextnum): |
37990
c0ccbf4fbe47
hgweb: convert comparison {lines} to a mappinggenerator with named template
Yuya Nishihara <yuya@tcha.org>
parents:
37989
diff
changeset
|
763 l = _getcompblock(leftlines, rightlines, oc) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
764 yield {b'lines': l} |
37992
b3992c21b7f3
hgweb: convert {comparison} to a mappinggenerator with named template
Yuya Nishihara <yuya@tcha.org>
parents:
37991
diff
changeset
|
765 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
766 |
37993
623dc2651d26
hgweb: drop unused argument 'tmpl' from webutil.compare()
Yuya Nishihara <yuya@tcha.org>
parents:
37992
diff
changeset
|
767 def compare(contextnum, leftlines, rightlines): |
37992
b3992c21b7f3
hgweb: convert {comparison} to a mappinggenerator with named template
Yuya Nishihara <yuya@tcha.org>
parents:
37991
diff
changeset
|
768 args = (contextnum, leftlines, rightlines) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
769 return templateutil.mappinggenerator( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
770 _comparegen, args=args, name=b'comparisonblock' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
771 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
772 |
17202
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
773 |
38585
66eb74f9d87d
hgweb: pass ui to diffstatgen() explicitly
Yuya Nishihara <yuya@tcha.org>
parents:
38566
diff
changeset
|
774 def diffstatgen(ui, ctx, basectx): |
14570
9f908ef5a595
web: provide diff summary to the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents:
14562
diff
changeset
|
775 '''Generator function that provides the diffstat data.''' |
14490
1d3e2349304a
web: provide diffstat to the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents:
14055
diff
changeset
|
776 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
777 diffopts = patch.diffopts(ui, {b'noprefix': False}) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
778 stats = patch.diffstatdata(util.iterlines(ctx.diff(basectx, opts=diffopts))) |
14490
1d3e2349304a
web: provide diffstat to the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents:
14055
diff
changeset
|
779 maxname, maxtotal, addtotal, removetotal, binary = patch.diffstatsum(stats) |
14570
9f908ef5a595
web: provide diff summary to the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents:
14562
diff
changeset
|
780 while True: |
9f908ef5a595
web: provide diff summary to the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents:
14562
diff
changeset
|
781 yield stats, maxname, maxtotal, addtotal, removetotal, binary |
9f908ef5a595
web: provide diff summary to the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents:
14562
diff
changeset
|
782 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
783 |
14570
9f908ef5a595
web: provide diff summary to the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents:
14562
diff
changeset
|
784 def diffsummary(statgen): |
9f908ef5a595
web: provide diff summary to the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents:
14562
diff
changeset
|
785 '''Return a short summary of the diff.''' |
9f908ef5a595
web: provide diff summary to the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents:
14562
diff
changeset
|
786 |
29216
ead25aa27a43
py3: convert to next() function
timeless <timeless@mozdev.org>
parents:
28709
diff
changeset
|
787 stats, maxname, maxtotal, addtotal, removetotal, binary = next(statgen) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
788 return _(b' %d files changed, %d insertions(+), %d deletions(-)\n') % ( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
789 len(stats), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
790 addtotal, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
791 removetotal, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
792 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
793 |
14570
9f908ef5a595
web: provide diff summary to the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents:
14562
diff
changeset
|
794 |
38058
6369e21e97ac
hgweb: use template context to render {diffstat}
Yuya Nishihara <yuya@tcha.org>
parents:
38057
diff
changeset
|
795 def _diffstattmplgen(context, ctx, statgen, parity): |
29216
ead25aa27a43
py3: convert to next() function
timeless <timeless@mozdev.org>
parents:
28709
diff
changeset
|
796 stats, maxname, maxtotal, addtotal, removetotal, binary = next(statgen) |
14561
925d9f2b188b
web: include all files in the diffstat
Steven Brown <StevenGBrown@gmail.com>
parents:
14490
diff
changeset
|
797 files = ctx.files() |
14490
1d3e2349304a
web: provide diffstat to the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents:
14055
diff
changeset
|
798 |
14561
925d9f2b188b
web: include all files in the diffstat
Steven Brown <StevenGBrown@gmail.com>
parents:
14490
diff
changeset
|
799 def pct(i): |
925d9f2b188b
web: include all files in the diffstat
Steven Brown <StevenGBrown@gmail.com>
parents:
14490
diff
changeset
|
800 if maxtotal == 0: |
925d9f2b188b
web: include all files in the diffstat
Steven Brown <StevenGBrown@gmail.com>
parents:
14490
diff
changeset
|
801 return 0 |
925d9f2b188b
web: include all files in the diffstat
Steven Brown <StevenGBrown@gmail.com>
parents:
14490
diff
changeset
|
802 return (float(i) / maxtotal) * 100 |
14490
1d3e2349304a
web: provide diffstat to the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents:
14055
diff
changeset
|
803 |
14562
fccd3b966da7
web: provide the file number to the diffstat templates
Steven Brown <StevenGBrown@gmail.com>
parents:
14561
diff
changeset
|
804 fileno = 0 |
14561
925d9f2b188b
web: include all files in the diffstat
Steven Brown <StevenGBrown@gmail.com>
parents:
14490
diff
changeset
|
805 for filename, adds, removes, isbinary in stats: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
806 template = b'diffstatlink' if filename in files else b'diffstatnolink' |
14561
925d9f2b188b
web: include all files in the diffstat
Steven Brown <StevenGBrown@gmail.com>
parents:
14490
diff
changeset
|
807 total = adds + removes |
14562
fccd3b966da7
web: provide the file number to the diffstat templates
Steven Brown <StevenGBrown@gmail.com>
parents:
14561
diff
changeset
|
808 fileno += 1 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
809 yield context.process( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
810 template, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
811 { |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
812 b'node': ctx.hex(), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
813 b'file': filename, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
814 b'fileno': fileno, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
815 b'total': total, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
816 b'addpct': pct(adds), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
817 b'removepct': pct(removes), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
818 b'parity': next(parity), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
819 }, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
820 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
821 |
14490
1d3e2349304a
web: provide diffstat to the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents:
14055
diff
changeset
|
822 |
38059
4c3ab15f3532
hgweb: drop unused argument 'tmpl' from webutil.diffstat()
Yuya Nishihara <yuya@tcha.org>
parents:
38058
diff
changeset
|
823 def diffstat(ctx, statgen, parity): |
38057
f0ee627162f4
hgweb: wrap {diffstat} with mappedgenerator
Yuya Nishihara <yuya@tcha.org>
parents:
38043
diff
changeset
|
824 '''Return a diffstat template for each file in the diff.''' |
38058
6369e21e97ac
hgweb: use template context to render {diffstat}
Yuya Nishihara <yuya@tcha.org>
parents:
38057
diff
changeset
|
825 args = (ctx, statgen, parity) |
38057
f0ee627162f4
hgweb: wrap {diffstat} with mappedgenerator
Yuya Nishihara <yuya@tcha.org>
parents:
38043
diff
changeset
|
826 return templateutil.mappedgenerator(_diffstattmplgen, args=args) |
f0ee627162f4
hgweb: wrap {diffstat} with mappedgenerator
Yuya Nishihara <yuya@tcha.org>
parents:
38043
diff
changeset
|
827 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
828 |
37696
9ac3e97b299b
hgweb: lift {sessionvars} to a wrapped type
Yuya Nishihara <yuya@tcha.org>
parents:
37695
diff
changeset
|
829 class sessionvars(templateutil.wrapped): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
830 def __init__(self, vars, start=b'?'): |
37694
d14dbf46e5c7
hgweb: prefix private variables of sessionvars with '_'
Yuya Nishihara <yuya@tcha.org>
parents:
37515
diff
changeset
|
831 self._start = start |
d14dbf46e5c7
hgweb: prefix private variables of sessionvars with '_'
Yuya Nishihara <yuya@tcha.org>
parents:
37515
diff
changeset
|
832 self._vars = vars |
37695
570a4426c5b8
hgweb: make sessionvars class less dense
Yuya Nishihara <yuya@tcha.org>
parents:
37694
diff
changeset
|
833 |
7345
55651328dfcc
hgweb: fix up the less/more links on the graph page
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7311
diff
changeset
|
834 def __getitem__(self, key): |
37694
d14dbf46e5c7
hgweb: prefix private variables of sessionvars with '_'
Yuya Nishihara <yuya@tcha.org>
parents:
37515
diff
changeset
|
835 return self._vars[key] |
37695
570a4426c5b8
hgweb: make sessionvars class less dense
Yuya Nishihara <yuya@tcha.org>
parents:
37694
diff
changeset
|
836 |
7345
55651328dfcc
hgweb: fix up the less/more links on the graph page
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7311
diff
changeset
|
837 def __setitem__(self, key, value): |
37694
d14dbf46e5c7
hgweb: prefix private variables of sessionvars with '_'
Yuya Nishihara <yuya@tcha.org>
parents:
37515
diff
changeset
|
838 self._vars[key] = value |
37695
570a4426c5b8
hgweb: make sessionvars class less dense
Yuya Nishihara <yuya@tcha.org>
parents:
37694
diff
changeset
|
839 |
7345
55651328dfcc
hgweb: fix up the less/more links on the graph page
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7311
diff
changeset
|
840 def __copy__(self): |
37694
d14dbf46e5c7
hgweb: prefix private variables of sessionvars with '_'
Yuya Nishihara <yuya@tcha.org>
parents:
37515
diff
changeset
|
841 return sessionvars(copy.copy(self._vars), self._start) |
37695
570a4426c5b8
hgweb: make sessionvars class less dense
Yuya Nishihara <yuya@tcha.org>
parents:
37694
diff
changeset
|
842 |
38267
fb874fc1d9b4
templater: abstract ifcontains() over wrapped types
Yuya Nishihara <yuya@tcha.org>
parents:
38265
diff
changeset
|
843 def contains(self, context, mapping, item): |
fb874fc1d9b4
templater: abstract ifcontains() over wrapped types
Yuya Nishihara <yuya@tcha.org>
parents:
38265
diff
changeset
|
844 item = templateutil.unwrapvalue(context, mapping, item) |
fb874fc1d9b4
templater: abstract ifcontains() over wrapped types
Yuya Nishihara <yuya@tcha.org>
parents:
38265
diff
changeset
|
845 return item in self._vars |
fb874fc1d9b4
templater: abstract ifcontains() over wrapped types
Yuya Nishihara <yuya@tcha.org>
parents:
38265
diff
changeset
|
846 |
38243
06d11cd90516
templater: promote getmember() to an interface of wrapped types
Yuya Nishihara <yuya@tcha.org>
parents:
38215
diff
changeset
|
847 def getmember(self, context, mapping, key): |
38244
688fbb758ba9
templater: resolve type of dict key in getmember()
Yuya Nishihara <yuya@tcha.org>
parents:
38243
diff
changeset
|
848 key = templateutil.unwrapvalue(context, mapping, key) |
38243
06d11cd90516
templater: promote getmember() to an interface of wrapped types
Yuya Nishihara <yuya@tcha.org>
parents:
38215
diff
changeset
|
849 return self._vars.get(key) |
06d11cd90516
templater: promote getmember() to an interface of wrapped types
Yuya Nishihara <yuya@tcha.org>
parents:
38215
diff
changeset
|
850 |
38265
41ae9b3cbfb9
templater: abstract min/max away
Yuya Nishihara <yuya@tcha.org>
parents:
38244
diff
changeset
|
851 def getmin(self, context, mapping): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
852 raise error.ParseError(_(b'not comparable')) |
38265
41ae9b3cbfb9
templater: abstract min/max away
Yuya Nishihara <yuya@tcha.org>
parents:
38244
diff
changeset
|
853 |
41ae9b3cbfb9
templater: abstract min/max away
Yuya Nishihara <yuya@tcha.org>
parents:
38244
diff
changeset
|
854 def getmax(self, context, mapping): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
855 raise error.ParseError(_(b'not comparable')) |
38265
41ae9b3cbfb9
templater: abstract min/max away
Yuya Nishihara <yuya@tcha.org>
parents:
38244
diff
changeset
|
856 |
38448
dae829b4de78
templater: introduce filter() function to remove empty items from list
Yuya Nishihara <yuya@tcha.org>
parents:
38289
diff
changeset
|
857 def filter(self, context, mapping, select): |
dae829b4de78
templater: introduce filter() function to remove empty items from list
Yuya Nishihara <yuya@tcha.org>
parents:
38289
diff
changeset
|
858 # implement if necessary |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
859 raise error.ParseError(_(b'not filterable')) |
38448
dae829b4de78
templater: introduce filter() function to remove empty items from list
Yuya Nishihara <yuya@tcha.org>
parents:
38289
diff
changeset
|
860 |
37696
9ac3e97b299b
hgweb: lift {sessionvars} to a wrapped type
Yuya Nishihara <yuya@tcha.org>
parents:
37695
diff
changeset
|
861 def itermaps(self, context): |
37694
d14dbf46e5c7
hgweb: prefix private variables of sessionvars with '_'
Yuya Nishihara <yuya@tcha.org>
parents:
37515
diff
changeset
|
862 separator = self._start |
43106
d783f945a701
py3: finish porting iteritems() to pycompat and remove source transformer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43087
diff
changeset
|
863 for key, value in sorted(pycompat.iteritems(self._vars)): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
864 yield { |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
865 b'name': key, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
866 b'value': pycompat.bytestr(value), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
867 b'separator': separator, |
34807
3caec3c032c8
webutil: use pycompat.bytestr() instead of str()
Augie Fackler <augie@google.com>
parents:
34403
diff
changeset
|
868 } |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
869 separator = b'&' |
12691
1b1a9038a71a
hgweb: fix hgweb_mod as well as hgwebdir_mod
Augie Fackler <durin42@gmail.com>
parents:
10282
diff
changeset
|
870 |
37696
9ac3e97b299b
hgweb: lift {sessionvars} to a wrapped type
Yuya Nishihara <yuya@tcha.org>
parents:
37695
diff
changeset
|
871 def join(self, context, mapping, sep): |
9ac3e97b299b
hgweb: lift {sessionvars} to a wrapped type
Yuya Nishihara <yuya@tcha.org>
parents:
37695
diff
changeset
|
872 # could be '{separator}{name}={value|urlescape}' |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
873 raise error.ParseError(_(b'not displayable without template')) |
37696
9ac3e97b299b
hgweb: lift {sessionvars} to a wrapped type
Yuya Nishihara <yuya@tcha.org>
parents:
37695
diff
changeset
|
874 |
9ac3e97b299b
hgweb: lift {sessionvars} to a wrapped type
Yuya Nishihara <yuya@tcha.org>
parents:
37695
diff
changeset
|
875 def show(self, context, mapping): |
43737
371765e775a2
webutil: add missing argument to join()
Matt Harbison <matt_harbison@yahoo.com>
parents:
43106
diff
changeset
|
876 return self.join(context, mapping, b'') |
37696
9ac3e97b299b
hgweb: lift {sessionvars} to a wrapped type
Yuya Nishihara <yuya@tcha.org>
parents:
37695
diff
changeset
|
877 |
38289
f9c426385853
templater: abstract truth testing to fix {if(list_of_empty_strings)}
Yuya Nishihara <yuya@tcha.org>
parents:
38267
diff
changeset
|
878 def tobool(self, context, mapping): |
f9c426385853
templater: abstract truth testing to fix {if(list_of_empty_strings)}
Yuya Nishihara <yuya@tcha.org>
parents:
38267
diff
changeset
|
879 return bool(self._vars) |
f9c426385853
templater: abstract truth testing to fix {if(list_of_empty_strings)}
Yuya Nishihara <yuya@tcha.org>
parents:
38267
diff
changeset
|
880 |
37696
9ac3e97b299b
hgweb: lift {sessionvars} to a wrapped type
Yuya Nishihara <yuya@tcha.org>
parents:
37695
diff
changeset
|
881 def tovalue(self, context, mapping): |
9ac3e97b299b
hgweb: lift {sessionvars} to a wrapped type
Yuya Nishihara <yuya@tcha.org>
parents:
37695
diff
changeset
|
882 return self._vars |
9ac3e97b299b
hgweb: lift {sessionvars} to a wrapped type
Yuya Nishihara <yuya@tcha.org>
parents:
37695
diff
changeset
|
883 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
884 |
27007
c8cbef073645
hgweb: alias ui module as uimod
Yuya Nishihara <yuya@tcha.org>
parents:
26894
diff
changeset
|
885 class wsgiui(uimod.ui): |
12691
1b1a9038a71a
hgweb: fix hgweb_mod as well as hgwebdir_mod
Augie Fackler <durin42@gmail.com>
parents:
10282
diff
changeset
|
886 # default termwidth breaks under mod_wsgi |
1b1a9038a71a
hgweb: fix hgweb_mod as well as hgwebdir_mod
Augie Fackler <durin42@gmail.com>
parents:
10282
diff
changeset
|
887 def termwidth(self): |
1b1a9038a71a
hgweb: fix hgweb_mod as well as hgwebdir_mod
Augie Fackler <durin42@gmail.com>
parents:
10282
diff
changeset
|
888 return 80 |
26162
268b39770c28
hgweb: extract web substitutions table generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26129
diff
changeset
|
889 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
890 |
26162
268b39770c28
hgweb: extract web substitutions table generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26129
diff
changeset
|
891 def getwebsubs(repo): |
268b39770c28
hgweb: extract web substitutions table generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26129
diff
changeset
|
892 websubtable = [] |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
893 websubdefs = repo.ui.configitems(b'websub') |
26162
268b39770c28
hgweb: extract web substitutions table generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26129
diff
changeset
|
894 # we must maintain interhg backwards compatibility |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
895 websubdefs += repo.ui.configitems(b'interhg') |
26162
268b39770c28
hgweb: extract web substitutions table generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26129
diff
changeset
|
896 for key, pattern in websubdefs: |
268b39770c28
hgweb: extract web substitutions table generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26129
diff
changeset
|
897 # grab the delimiter from the character after the "s" |
36180
34e850440271
py3: slice over bytes to prevent getting ascii values
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35486
diff
changeset
|
898 unesc = pattern[1:2] |
38475
67dc32d4e790
cleanup: migrate from re.escape to stringutil.reescape
Augie Fackler <augie@google.com>
parents:
38448
diff
changeset
|
899 delim = stringutil.reescape(unesc) |
26162
268b39770c28
hgweb: extract web substitutions table generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26129
diff
changeset
|
900 |
268b39770c28
hgweb: extract web substitutions table generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26129
diff
changeset
|
901 # identify portions of the pattern, taking care to avoid escaped |
268b39770c28
hgweb: extract web substitutions table generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26129
diff
changeset
|
902 # delimiters. the replace format and flags are optional, but |
268b39770c28
hgweb: extract web substitutions table generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26129
diff
changeset
|
903 # delimiters are required. |
268b39770c28
hgweb: extract web substitutions table generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26129
diff
changeset
|
904 match = re.match( |
36183
44a519ec5077
py3: add b'' to make sure regex pattern are bytes in hgweb/webutil.py
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36180
diff
changeset
|
905 br'^s%s(.+)(?:(?<=\\\\)|(?<!\\))%s(.*)%s([ilmsux])*$' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
906 % (delim, delim, delim), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
907 pattern, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
908 ) |
26162
268b39770c28
hgweb: extract web substitutions table generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26129
diff
changeset
|
909 if not match: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
910 repo.ui.warn( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
911 _(b"websub: invalid pattern for %s: %s\n") % (key, pattern) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
912 ) |
26162
268b39770c28
hgweb: extract web substitutions table generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26129
diff
changeset
|
913 continue |
268b39770c28
hgweb: extract web substitutions table generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26129
diff
changeset
|
914 |
268b39770c28
hgweb: extract web substitutions table generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26129
diff
changeset
|
915 # we need to unescape the delimiter for regexp and format |
36183
44a519ec5077
py3: add b'' to make sure regex pattern are bytes in hgweb/webutil.py
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36180
diff
changeset
|
916 delim_re = re.compile(br'(?<!\\)\\%s' % delim) |
26162
268b39770c28
hgweb: extract web substitutions table generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26129
diff
changeset
|
917 regexp = delim_re.sub(unesc, match.group(1)) |
268b39770c28
hgweb: extract web substitutions table generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26129
diff
changeset
|
918 format = delim_re.sub(unesc, match.group(2)) |
268b39770c28
hgweb: extract web substitutions table generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26129
diff
changeset
|
919 |
268b39770c28
hgweb: extract web substitutions table generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26129
diff
changeset
|
920 # the pattern allows for 6 regexp flags, so set them if necessary |
268b39770c28
hgweb: extract web substitutions table generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26129
diff
changeset
|
921 flagin = match.group(3) |
268b39770c28
hgweb: extract web substitutions table generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26129
diff
changeset
|
922 flags = 0 |
268b39770c28
hgweb: extract web substitutions table generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26129
diff
changeset
|
923 if flagin: |
42919
6ccf539aec71
hgweb: fix websub regex flag syntax on Python 3
Connor Sheehan <sheehan@mozilla.com>
parents:
42337
diff
changeset
|
924 for flag in pycompat.sysstr(flagin.upper()): |
26162
268b39770c28
hgweb: extract web substitutions table generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26129
diff
changeset
|
925 flags |= re.__dict__[flag] |
268b39770c28
hgweb: extract web substitutions table generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26129
diff
changeset
|
926 |
268b39770c28
hgweb: extract web substitutions table generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26129
diff
changeset
|
927 try: |
268b39770c28
hgweb: extract web substitutions table generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26129
diff
changeset
|
928 regexp = re.compile(regexp, flags) |
268b39770c28
hgweb: extract web substitutions table generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26129
diff
changeset
|
929 websubtable.append((regexp, format)) |
268b39770c28
hgweb: extract web substitutions table generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26129
diff
changeset
|
930 except re.error: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
931 repo.ui.warn( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
932 _(b"websub: invalid regexp for %s: %s\n") % (key, regexp) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
933 ) |
26162
268b39770c28
hgweb: extract web substitutions table generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26129
diff
changeset
|
934 return websubtable |
37909
7fae76c2c564
hgweb: reuse graph node-related functions from templates
Anton Shestakov <av6@dwimlabs.net>
parents:
37907
diff
changeset
|
935 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
936 |
37909
7fae76c2c564
hgweb: reuse graph node-related functions from templates
Anton Shestakov <av6@dwimlabs.net>
parents:
37907
diff
changeset
|
937 def getgraphnode(repo, ctx): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
938 return templatekw.getgraphnodecurrent( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
939 repo, ctx |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42919
diff
changeset
|
940 ) + templatekw.getgraphnodesymbol(ctx) |