author | Pierre-Yves David <pierre-yves.david@logilab.fr> |
Wed, 16 Jan 2013 13:18:22 +0100 | |
changeset 18409 | e3f5cef11d6a |
parent 18408 | f332a64fef51 |
child 18425 | 6da1e979340a |
permissions | -rw-r--r-- |
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 |
|
17302
5c64ce6168da
hgweb: fixes traceback for invalid files by removing top-level template
wujek srujek <wujek.srujek@googlemail.com>
parents:
17289
diff
changeset
|
9 |
import os, copy |
14490
1d3e2349304a
web: provide diffstat to the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents:
14055
diff
changeset
|
10 |
from mercurial import match, patch, scmutil, error, ui, util |
14570
9f908ef5a595
web: provide diff summary to the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents:
14562
diff
changeset
|
11 |
from mercurial.i18n import _ |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
12 |
from mercurial.node import hex, nullid |
17289
f2d6b4f8e78c
hgweb: avoid traceback when file or node parameters are missing
Ross Lagerwall <rosslagerwall@gmail.com>
parents:
17202
diff
changeset
|
13 |
from common import ErrorResponse |
f2d6b4f8e78c
hgweb: avoid traceback when file or node parameters are missing
Ross Lagerwall <rosslagerwall@gmail.com>
parents:
17202
diff
changeset
|
14 |
from common import HTTP_NOT_FOUND |
17202
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
15 |
import difflib |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
16 |
|
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
17 |
def up(p): |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
18 |
if p[0] != "/": |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
19 |
p = "/" + p |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
20 |
if p[-1] == "/": |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
21 |
p = p[:-1] |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
22 |
up = os.path.dirname(p) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
23 |
if up == "/": |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
24 |
return "/" |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
25 |
return up + "/" |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
26 |
|
18391
833eb34e90e4
hgweb: better names for _navseq arguments
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18390
diff
changeset
|
27 |
def _navseq(step, firststep=None): |
833eb34e90e4
hgweb: better names for _navseq arguments
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18390
diff
changeset
|
28 |
if firststep: |
833eb34e90e4
hgweb: better names for _navseq arguments
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18390
diff
changeset
|
29 |
yield firststep |
833eb34e90e4
hgweb: better names for _navseq arguments
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18390
diff
changeset
|
30 |
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
|
31 |
firststep = 50 |
88a37b19dc0e
hgweb: ensure _navseq yield strictly increasing numbers
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18391
diff
changeset
|
32 |
yield firststep |
88a37b19dc0e
hgweb: ensure _navseq yield strictly increasing numbers
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18391
diff
changeset
|
33 |
assert step > 0 |
88a37b19dc0e
hgweb: ensure _navseq yield strictly increasing numbers
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18391
diff
changeset
|
34 |
assert firststep > 0 |
88a37b19dc0e
hgweb: ensure _navseq yield strictly increasing numbers
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18391
diff
changeset
|
35 |
while step <= firststep: |
88a37b19dc0e
hgweb: ensure _navseq yield strictly increasing numbers
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18391
diff
changeset
|
36 |
step *= 10 |
18390
28fa9443f751
hgweb: drop recursivity in _navseq
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18389
diff
changeset
|
37 |
while True: |
18391
833eb34e90e4
hgweb: better names for _navseq arguments
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18390
diff
changeset
|
38 |
yield 1 * step |
833eb34e90e4
hgweb: better names for _navseq arguments
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18390
diff
changeset
|
39 |
yield 3 * step |
833eb34e90e4
hgweb: better names for _navseq arguments
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18390
diff
changeset
|
40 |
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
|
41 |
|
18403
bfaee31a83d2
hgweb: move revnavgen into an object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18392
diff
changeset
|
42 |
class revnav(object): |
18320
60680d691a0b
hgweb: document the revnavgen function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17991
diff
changeset
|
43 |
|
18409
e3f5cef11d6a
hgweb: pass repo object to revnav construction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18408
diff
changeset
|
44 |
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
|
45 |
"""Navigation generation object |
1da84a6b136a
hgweb: pass nodefunc to the revnav object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18403
diff
changeset
|
46 |
|
18409
e3f5cef11d6a
hgweb: pass repo object to revnav construction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18408
diff
changeset
|
47 |
: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
|
48 |
""" |
18409
e3f5cef11d6a
hgweb: pass repo object to revnav construction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18408
diff
changeset
|
49 |
# used for hex generation |
e3f5cef11d6a
hgweb: pass repo object to revnav construction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18408
diff
changeset
|
50 |
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
|
51 |
|
18406
20cf53932b6f
hgweb: simplify the handling of empty repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18405
diff
changeset
|
52 |
def __nonzero__(self): |
20cf53932b6f
hgweb: simplify the handling of empty repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18405
diff
changeset
|
53 |
"""return True if any revision to navigate over""" |
20cf53932b6f
hgweb: simplify the handling of empty repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18405
diff
changeset
|
54 |
try: |
18409
e3f5cef11d6a
hgweb: pass repo object to revnav construction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18408
diff
changeset
|
55 |
self._revlog.node(0) |
18406
20cf53932b6f
hgweb: simplify the handling of empty repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18405
diff
changeset
|
56 |
return True |
20cf53932b6f
hgweb: simplify the handling of empty repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18405
diff
changeset
|
57 |
except error.RepoError: |
20cf53932b6f
hgweb: simplify the handling of empty repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18405
diff
changeset
|
58 |
return False |
20cf53932b6f
hgweb: simplify the handling of empty repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18405
diff
changeset
|
59 |
|
18405
1eaf0d017b2c
hgweb: move hex creation into an object method
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18404
diff
changeset
|
60 |
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
|
61 |
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
|
62 |
|
18404
1da84a6b136a
hgweb: pass nodefunc to the revnav object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18403
diff
changeset
|
63 |
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
|
64 |
"""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
|
65 |
|
18403
bfaee31a83d2
hgweb: move revnavgen into an object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18392
diff
changeset
|
66 |
: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
|
67 |
: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
|
68 |
:limit: how far shall we link |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
69 |
|
18403
bfaee31a83d2
hgweb: move revnavgen into an object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18392
diff
changeset
|
70 |
The return is: |
bfaee31a83d2
hgweb: move revnavgen into an object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18392
diff
changeset
|
71 |
- a single element tuple |
bfaee31a83d2
hgweb: move revnavgen into an object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18392
diff
changeset
|
72 |
- containing a dictionary with a `before` and `after` key |
bfaee31a83d2
hgweb: move revnavgen into an object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18392
diff
changeset
|
73 |
- values are generator functions taking arbitrary number of kwargs |
bfaee31a83d2
hgweb: move revnavgen into an object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18392
diff
changeset
|
74 |
- yield items are dictionaries with `label` and `node` keys |
bfaee31a83d2
hgweb: move revnavgen into an object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18392
diff
changeset
|
75 |
""" |
18406
20cf53932b6f
hgweb: simplify the handling of empty repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18405
diff
changeset
|
76 |
if not self: |
20cf53932b6f
hgweb: simplify the handling of empty repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18405
diff
changeset
|
77 |
# empty repo |
20cf53932b6f
hgweb: simplify the handling of empty repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18405
diff
changeset
|
78 |
return ({'before': (), 'after': ()},) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
79 |
|
18407
50dc5b244474
hgweb: simplify addition of "(0) navigation entry"
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18406
diff
changeset
|
80 |
navbefore = [("(0)", self.hex(0))] |
18403
bfaee31a83d2
hgweb: move revnavgen into an object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18392
diff
changeset
|
81 |
navafter = [] |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
82 |
|
18403
bfaee31a83d2
hgweb: move revnavgen into an object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18392
diff
changeset
|
83 |
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
|
84 |
if f > limit: |
bfaee31a83d2
hgweb: move revnavgen into an object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18392
diff
changeset
|
85 |
break |
bfaee31a83d2
hgweb: move revnavgen into an object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18392
diff
changeset
|
86 |
if pos + f < limit: |
18405
1eaf0d017b2c
hgweb: move hex creation into an object method
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18404
diff
changeset
|
87 |
navafter.append(("+%d" % f, self.hex(pos + f))) |
18403
bfaee31a83d2
hgweb: move revnavgen into an object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18392
diff
changeset
|
88 |
if pos - f >= 0: |
18405
1eaf0d017b2c
hgweb: move hex creation into an object method
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18404
diff
changeset
|
89 |
navbefore.insert(0, ("-%d" % f, self.hex(pos - f))) |
10254
8d5de52431f2
hgweb: changenav: separate pages before and after the current position
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9402
diff
changeset
|
90 |
|
18403
bfaee31a83d2
hgweb: move revnavgen into an object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18392
diff
changeset
|
91 |
navafter.append(("tip", "tip")) |
bfaee31a83d2
hgweb: move revnavgen into an object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18392
diff
changeset
|
92 |
|
bfaee31a83d2
hgweb: move revnavgen into an object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18392
diff
changeset
|
93 |
data = lambda i: {"label": i[0], "node": i[1]} |
bfaee31a83d2
hgweb: move revnavgen into an object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18392
diff
changeset
|
94 |
return ({'before': lambda **map: (data(i) for i in navbefore), |
bfaee31a83d2
hgweb: move revnavgen into an object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18392
diff
changeset
|
95 |
'after': lambda **map: (data(i) for i in navafter)},) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
96 |
|
18408
f332a64fef51
hgweb: introduction a filerevnav subclass
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18407
diff
changeset
|
97 |
class filerevnav(revnav): |
18409
e3f5cef11d6a
hgweb: pass repo object to revnav construction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18408
diff
changeset
|
98 |
|
e3f5cef11d6a
hgweb: pass repo object to revnav construction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18408
diff
changeset
|
99 |
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
|
100 |
"""Navigation generation object |
e3f5cef11d6a
hgweb: pass repo object to revnav construction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18408
diff
changeset
|
101 |
|
e3f5cef11d6a
hgweb: pass repo object to revnav construction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18408
diff
changeset
|
102 |
: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
|
103 |
: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
|
104 |
""" |
e3f5cef11d6a
hgweb: pass repo object to revnav construction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18408
diff
changeset
|
105 |
# used for iteration |
e3f5cef11d6a
hgweb: pass repo object to revnav construction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18408
diff
changeset
|
106 |
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
|
107 |
# used for hex generation |
e3f5cef11d6a
hgweb: pass repo object to revnav construction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18408
diff
changeset
|
108 |
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
|
109 |
|
e3f5cef11d6a
hgweb: pass repo object to revnav construction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18408
diff
changeset
|
110 |
def hex(self, rev): |
e3f5cef11d6a
hgweb: pass repo object to revnav construction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18408
diff
changeset
|
111 |
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
|
112 |
|
18408
f332a64fef51
hgweb: introduction a filerevnav subclass
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18407
diff
changeset
|
113 |
|
7671
06cf09c822c4
hgweb: simplify parents/children generation code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7637
diff
changeset
|
114 |
def _siblings(siblings=[], hiderev=None): |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
115 |
siblings = [s for s in siblings if s.node() != nullid] |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
116 |
if len(siblings) == 1 and siblings[0].rev() == hiderev: |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
117 |
return |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
118 |
for s in siblings: |
14055
421d56a055fd
drop {short,hex}(ctx.node()) calls in favor of ctx methods
Alexander Solovyov <alexander@solovyov.net>
parents:
13971
diff
changeset
|
119 |
d = {'node': s.hex(), 'rev': s.rev()} |
7294
f933076a19fc
hgweb: pass more information about parent/child csets to templates
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6750
diff
changeset
|
120 |
d['user'] = s.user() |
f933076a19fc
hgweb: pass more information about parent/child csets to templates
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6750
diff
changeset
|
121 |
d['date'] = s.date() |
f933076a19fc
hgweb: pass more information about parent/child csets to templates
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6750
diff
changeset
|
122 |
d['description'] = s.description() |
7717
f9ba30cb7ee4
hgweb: expose sibling branches to templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7671
diff
changeset
|
123 |
d['branch'] = s.branch() |
14957
16e5271b216f
hgweb: move remaining hasattr calls to safehasattr
Augie Fackler <durin42@gmail.com>
parents:
14570
diff
changeset
|
124 |
if util.safehasattr(s, 'path'): |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
125 |
d['file'] = s.path() |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
126 |
yield d |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
127 |
|
7671
06cf09c822c4
hgweb: simplify parents/children generation code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7637
diff
changeset
|
128 |
def parents(ctx, hide=None): |
06cf09c822c4
hgweb: simplify parents/children generation code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7637
diff
changeset
|
129 |
return _siblings(ctx.parents(), hide) |
06cf09c822c4
hgweb: simplify parents/children generation code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7637
diff
changeset
|
130 |
|
06cf09c822c4
hgweb: simplify parents/children generation code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7637
diff
changeset
|
131 |
def children(ctx, hide=None): |
06cf09c822c4
hgweb: simplify parents/children generation code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7637
diff
changeset
|
132 |
return _siblings(ctx.children(), hide) |
06cf09c822c4
hgweb: simplify parents/children generation code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7637
diff
changeset
|
133 |
|
6434
62e0bb41e682
hgweb: minor improvements for new web style
Matt Mackall <mpm@selenic.com>
parents:
6413
diff
changeset
|
134 |
def renamelink(fctx): |
6437 | 135 |
r = fctx.renamed() |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
136 |
if r: |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
137 |
return [dict(file=r[0], node=hex(r[1]))] |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
138 |
return [] |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
139 |
|
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
140 |
def nodetagsdict(repo, node): |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
141 |
return [{"name": i} for i in repo.nodetags(node)] |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
142 |
|
13596
270f57d35525
hgweb: add display of bookmarks for changelog and changeset
Alexander Solovyov <alexander@solovyov.net>
parents:
12691
diff
changeset
|
143 |
def nodebookmarksdict(repo, node): |
270f57d35525
hgweb: add display of bookmarks for changelog and changeset
Alexander Solovyov <alexander@solovyov.net>
parents:
12691
diff
changeset
|
144 |
return [{"name": i} for i in repo.nodebookmarks(node)] |
270f57d35525
hgweb: add display of bookmarks for changelog and changeset
Alexander Solovyov <alexander@solovyov.net>
parents:
12691
diff
changeset
|
145 |
|
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
146 |
def nodebranchdict(repo, ctx): |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
147 |
branches = [] |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
148 |
branch = ctx.branch() |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
149 |
# 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
|
150 |
# ctx.branch() == 'default'. |
e7bf09acd410
localrepo: add branchtip() method for faster single-branch lookups
Brodie Rao <brodie@sf.io>
parents:
16308
diff
changeset
|
151 |
try: |
e7bf09acd410
localrepo: add branchtip() method for faster single-branch lookups
Brodie Rao <brodie@sf.io>
parents:
16308
diff
changeset
|
152 |
branchnode = repo.branchtip(branch) |
e7bf09acd410
localrepo: add branchtip() method for faster single-branch lookups
Brodie Rao <brodie@sf.io>
parents:
16308
diff
changeset
|
153 |
except error.RepoLookupError: |
e7bf09acd410
localrepo: add branchtip() method for faster single-branch lookups
Brodie Rao <brodie@sf.io>
parents:
16308
diff
changeset
|
154 |
branchnode = None |
e7bf09acd410
localrepo: add branchtip() method for faster single-branch lookups
Brodie Rao <brodie@sf.io>
parents:
16308
diff
changeset
|
155 |
if branchnode == ctx.node(): |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
156 |
branches.append({"name": branch}) |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
157 |
return branches |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
158 |
|
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
159 |
def nodeinbranch(repo, ctx): |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
160 |
branches = [] |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
161 |
branch = ctx.branch() |
16719
e7bf09acd410
localrepo: add branchtip() method for faster single-branch lookups
Brodie Rao <brodie@sf.io>
parents:
16308
diff
changeset
|
162 |
try: |
e7bf09acd410
localrepo: add branchtip() method for faster single-branch lookups
Brodie Rao <brodie@sf.io>
parents:
16308
diff
changeset
|
163 |
branchnode = repo.branchtip(branch) |
e7bf09acd410
localrepo: add branchtip() method for faster single-branch lookups
Brodie Rao <brodie@sf.io>
parents:
16308
diff
changeset
|
164 |
except error.RepoLookupError: |
e7bf09acd410
localrepo: add branchtip() method for faster single-branch lookups
Brodie Rao <brodie@sf.io>
parents:
16308
diff
changeset
|
165 |
branchnode = None |
e7bf09acd410
localrepo: add branchtip() method for faster single-branch lookups
Brodie Rao <brodie@sf.io>
parents:
16308
diff
changeset
|
166 |
if branch != 'default' and branchnode != ctx.node(): |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
167 |
branches.append({"name": branch}) |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
168 |
return branches |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
169 |
|
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
170 |
def nodebranchnodefault(ctx): |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
171 |
branches = [] |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
172 |
branch = ctx.branch() |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
173 |
if branch != 'default': |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
174 |
branches.append({"name": branch}) |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
175 |
return branches |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
176 |
|
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
177 |
def showtag(repo, tmpl, t1, node=nullid, **args): |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
178 |
for t in repo.nodetags(node): |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
179 |
yield tmpl(t1, tag=t, **args) |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
180 |
|
13596
270f57d35525
hgweb: add display of bookmarks for changelog and changeset
Alexander Solovyov <alexander@solovyov.net>
parents:
12691
diff
changeset
|
181 |
def showbookmark(repo, tmpl, t1, node=nullid, **args): |
270f57d35525
hgweb: add display of bookmarks for changelog and changeset
Alexander Solovyov <alexander@solovyov.net>
parents:
12691
diff
changeset
|
182 |
for t in repo.nodebookmarks(node): |
270f57d35525
hgweb: add display of bookmarks for changelog and changeset
Alexander Solovyov <alexander@solovyov.net>
parents:
12691
diff
changeset
|
183 |
yield tmpl(t1, bookmark=t, **args) |
270f57d35525
hgweb: add display of bookmarks for changelog and changeset
Alexander Solovyov <alexander@solovyov.net>
parents:
12691
diff
changeset
|
184 |
|
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
185 |
def cleanpath(repo, path): |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
186 |
path = path.lstrip('/') |
13971
bfeaa88b875d
move canonpath from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13596
diff
changeset
|
187 |
return scmutil.canonpath(repo.root, '', path) |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
188 |
|
17991
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
189 |
def changeidctx (repo, changeid): |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
190 |
try: |
6747
f6c00b17387c
use repo[changeid] to get a changectx
Matt Mackall <mpm@selenic.com>
parents:
6437
diff
changeset
|
191 |
ctx = repo[changeid] |
7637 | 192 |
except error.RepoError: |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
193 |
man = repo.manifest |
7361
9fe97eea5510
linkrev: take a revision number rather than a hash
Matt Mackall <mpm@selenic.com>
parents:
7345
diff
changeset
|
194 |
ctx = repo[man.linkrev(man.rev(man.lookup(changeid)))] |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
195 |
|
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
196 |
return ctx |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
197 |
|
17991
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
198 |
def changectx (repo, req): |
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
199 |
changeid = "tip" |
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
200 |
if 'node' in req.form: |
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
201 |
changeid = req.form['node'][0] |
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
202 |
ipos=changeid.find(':') |
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
203 |
if ipos != -1: |
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
204 |
changeid = changeid[(ipos + 1):] |
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
205 |
elif 'manifest' in req.form: |
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
206 |
changeid = req.form['manifest'][0] |
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
207 |
|
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
208 |
return changeidctx(repo, changeid) |
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
209 |
|
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
210 |
def basechangectx(repo, req): |
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
211 |
if 'node' in req.form: |
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
212 |
changeid = req.form['node'][0] |
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
213 |
ipos=changeid.find(':') |
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
214 |
if ipos != -1: |
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
215 |
changeid = changeid[:ipos] |
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
216 |
return changeidctx(repo, changeid) |
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
217 |
|
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
218 |
return None |
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
219 |
|
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
220 |
def filectx(repo, req): |
17289
f2d6b4f8e78c
hgweb: avoid traceback when file or node parameters are missing
Ross Lagerwall <rosslagerwall@gmail.com>
parents:
17202
diff
changeset
|
221 |
if 'file' not in req.form: |
f2d6b4f8e78c
hgweb: avoid traceback when file or node parameters are missing
Ross Lagerwall <rosslagerwall@gmail.com>
parents:
17202
diff
changeset
|
222 |
raise ErrorResponse(HTTP_NOT_FOUND, 'file not given') |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
223 |
path = cleanpath(repo, req.form['file'][0]) |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
224 |
if 'node' in req.form: |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
225 |
changeid = req.form['node'][0] |
17289
f2d6b4f8e78c
hgweb: avoid traceback when file or node parameters are missing
Ross Lagerwall <rosslagerwall@gmail.com>
parents:
17202
diff
changeset
|
226 |
elif 'filenode' in req.form: |
f2d6b4f8e78c
hgweb: avoid traceback when file or node parameters are missing
Ross Lagerwall <rosslagerwall@gmail.com>
parents:
17202
diff
changeset
|
227 |
changeid = req.form['filenode'][0] |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
228 |
else: |
17289
f2d6b4f8e78c
hgweb: avoid traceback when file or node parameters are missing
Ross Lagerwall <rosslagerwall@gmail.com>
parents:
17202
diff
changeset
|
229 |
raise ErrorResponse(HTTP_NOT_FOUND, 'node or filenode not given') |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
230 |
try: |
6747
f6c00b17387c
use repo[changeid] to get a changectx
Matt Mackall <mpm@selenic.com>
parents:
6437
diff
changeset
|
231 |
fctx = repo[changeid][path] |
7637 | 232 |
except error.RepoError: |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
233 |
fctx = repo.filectx(path, fileid=changeid) |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
234 |
|
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
235 |
return fctx |
7310
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
236 |
|
7311
de9c87fe1620
hgweb: move another utility function into the webutil module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7310
diff
changeset
|
237 |
def listfilediffs(tmpl, files, node, max): |
de9c87fe1620
hgweb: move another utility function into the webutil module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7310
diff
changeset
|
238 |
for f in files[:max]: |
de9c87fe1620
hgweb: move another utility function into the webutil module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7310
diff
changeset
|
239 |
yield tmpl('filedifflink', node=hex(node), file=f) |
de9c87fe1620
hgweb: move another utility function into the webutil module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7310
diff
changeset
|
240 |
if len(files) > max: |
de9c87fe1620
hgweb: move another utility function into the webutil module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7310
diff
changeset
|
241 |
yield tmpl('fileellipses') |
de9c87fe1620
hgweb: move another utility function into the webutil module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7310
diff
changeset
|
242 |
|
17991
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
243 |
def diffs(repo, tmpl, ctx, basectx, files, parity, style): |
7310
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
244 |
|
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
245 |
def countgen(): |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
246 |
start = 1 |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
247 |
while True: |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
248 |
yield start |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
249 |
start += 1 |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
250 |
|
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
251 |
blockcount = countgen() |
16308
2695aaf4eb72
hgweb: add block numbers to diff regions and related links
Paul Boddie <paul@boddie.org.uk>
parents:
14957
diff
changeset
|
252 |
def prettyprintlines(diff, blockno): |
7310
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
253 |
for lineno, l in enumerate(diff.splitlines(True)): |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
254 |
lineno = "%d.%d" % (blockno, lineno + 1) |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
255 |
if l.startswith('+'): |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
256 |
ltype = "difflineplus" |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
257 |
elif l.startswith('-'): |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
258 |
ltype = "difflineminus" |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
259 |
elif l.startswith('@'): |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
260 |
ltype = "difflineat" |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
261 |
else: |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
262 |
ltype = "diffline" |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
263 |
yield tmpl(ltype, |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
264 |
line=l, |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
265 |
lineid="l%s" % lineno, |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
266 |
linenumber="% 8s" % lineno) |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
267 |
|
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
268 |
if files: |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
269 |
m = match.exact(repo.root, repo.getcwd(), files) |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
270 |
else: |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
271 |
m = match.always(repo.root, repo.getcwd()) |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
272 |
|
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
273 |
diffopts = patch.diffopts(repo.ui, untrusted=True) |
17991
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
274 |
if basectx is None: |
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
275 |
parents = ctx.parents() |
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
276 |
node1 = parents and parents[0].node() or nullid |
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
277 |
else: |
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
278 |
node1 = basectx.node() |
7310
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
279 |
node2 = ctx.node() |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
280 |
|
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
281 |
block = [] |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
282 |
for chunk in patch.diff(repo, node1, node2, m, opts=diffopts): |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
283 |
if chunk.startswith('diff') and block: |
16308
2695aaf4eb72
hgweb: add block numbers to diff regions and related links
Paul Boddie <paul@boddie.org.uk>
parents:
14957
diff
changeset
|
284 |
blockno = blockcount.next() |
2695aaf4eb72
hgweb: add block numbers to diff regions and related links
Paul Boddie <paul@boddie.org.uk>
parents:
14957
diff
changeset
|
285 |
yield tmpl('diffblock', parity=parity.next(), blockno=blockno, |
2695aaf4eb72
hgweb: add block numbers to diff regions and related links
Paul Boddie <paul@boddie.org.uk>
parents:
14957
diff
changeset
|
286 |
lines=prettyprintlines(''.join(block), blockno)) |
7310
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
287 |
block = [] |
9402
5d49fdef6fd0
hgweb: show diff header line in raw diffs
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8225
diff
changeset
|
288 |
if chunk.startswith('diff') and style != 'raw': |
7310
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
289 |
chunk = ''.join(chunk.splitlines(True)[1:]) |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
290 |
block.append(chunk) |
16308
2695aaf4eb72
hgweb: add block numbers to diff regions and related links
Paul Boddie <paul@boddie.org.uk>
parents:
14957
diff
changeset
|
291 |
blockno = blockcount.next() |
2695aaf4eb72
hgweb: add block numbers to diff regions and related links
Paul Boddie <paul@boddie.org.uk>
parents:
14957
diff
changeset
|
292 |
yield tmpl('diffblock', parity=parity.next(), blockno=blockno, |
2695aaf4eb72
hgweb: add block numbers to diff regions and related links
Paul Boddie <paul@boddie.org.uk>
parents:
14957
diff
changeset
|
293 |
lines=prettyprintlines(''.join(block), blockno)) |
7345
55651328dfcc
hgweb: fix up the less/more links on the graph page
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7311
diff
changeset
|
294 |
|
17302
5c64ce6168da
hgweb: fixes traceback for invalid files by removing top-level template
wujek srujek <wujek.srujek@googlemail.com>
parents:
17289
diff
changeset
|
295 |
def compare(tmpl, context, leftlines, rightlines): |
17202
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
296 |
'''Generator function that provides side-by-side comparison data.''' |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
297 |
|
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
298 |
def compline(type, leftlineno, leftline, rightlineno, rightline): |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
299 |
lineid = leftlineno and ("l%s" % leftlineno) or '' |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
300 |
lineid += rightlineno and ("r%s" % rightlineno) or '' |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
301 |
return tmpl('comparisonline', |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
302 |
type=type, |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
303 |
lineid=lineid, |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
304 |
leftlinenumber="% 6s" % (leftlineno or ''), |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
305 |
leftline=leftline or '', |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
306 |
rightlinenumber="% 6s" % (rightlineno or ''), |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
307 |
rightline=rightline or '') |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
308 |
|
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
309 |
def getblock(opcodes): |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
310 |
for type, llo, lhi, rlo, rhi in opcodes: |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
311 |
len1 = lhi - llo |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
312 |
len2 = rhi - rlo |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
313 |
count = min(len1, len2) |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
314 |
for i in xrange(count): |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
315 |
yield compline(type=type, |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
316 |
leftlineno=llo + i + 1, |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
317 |
leftline=leftlines[llo + i], |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
318 |
rightlineno=rlo + i + 1, |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
319 |
rightline=rightlines[rlo + i]) |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
320 |
if len1 > len2: |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
321 |
for i in xrange(llo + count, lhi): |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
322 |
yield compline(type=type, |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
323 |
leftlineno=i + 1, |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
324 |
leftline=leftlines[i], |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
325 |
rightlineno=None, |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
326 |
rightline=None) |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
327 |
elif len2 > len1: |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
328 |
for i in xrange(rlo + count, rhi): |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
329 |
yield compline(type=type, |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
330 |
leftlineno=None, |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
331 |
leftline=None, |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
332 |
rightlineno=i + 1, |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
333 |
rightline=rightlines[i]) |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
334 |
|
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
335 |
s = difflib.SequenceMatcher(None, leftlines, rightlines) |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
336 |
if context < 0: |
17302
5c64ce6168da
hgweb: fixes traceback for invalid files by removing top-level template
wujek srujek <wujek.srujek@googlemail.com>
parents:
17289
diff
changeset
|
337 |
yield tmpl('comparisonblock', lines=getblock(s.get_opcodes())) |
17202
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
338 |
else: |
17302
5c64ce6168da
hgweb: fixes traceback for invalid files by removing top-level template
wujek srujek <wujek.srujek@googlemail.com>
parents:
17289
diff
changeset
|
339 |
for oc in s.get_grouped_opcodes(n=context): |
5c64ce6168da
hgweb: fixes traceback for invalid files by removing top-level template
wujek srujek <wujek.srujek@googlemail.com>
parents:
17289
diff
changeset
|
340 |
yield tmpl('comparisonblock', lines=getblock(oc)) |
17202
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
341 |
|
17991
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
342 |
def diffstatgen(ctx, basectx): |
14570
9f908ef5a595
web: provide diff summary to the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents:
14562
diff
changeset
|
343 |
'''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
|
344 |
|
17991
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
345 |
stats = patch.diffstatdata(util.iterlines(ctx.diff(basectx))) |
14490
1d3e2349304a
web: provide diffstat to the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents:
14055
diff
changeset
|
346 |
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
|
347 |
while True: |
9f908ef5a595
web: provide diff summary to the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents:
14562
diff
changeset
|
348 |
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
|
349 |
|
9f908ef5a595
web: provide diff summary to the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents:
14562
diff
changeset
|
350 |
def diffsummary(statgen): |
9f908ef5a595
web: provide diff summary to the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents:
14562
diff
changeset
|
351 |
'''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
|
352 |
|
9f908ef5a595
web: provide diff summary to the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents:
14562
diff
changeset
|
353 |
stats, maxname, maxtotal, addtotal, removetotal, binary = statgen.next() |
9f908ef5a595
web: provide diff summary to the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents:
14562
diff
changeset
|
354 |
return _(' %d files changed, %d insertions(+), %d deletions(-)\n') % ( |
9f908ef5a595
web: provide diff summary to the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents:
14562
diff
changeset
|
355 |
len(stats), addtotal, removetotal) |
9f908ef5a595
web: provide diff summary to the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents:
14562
diff
changeset
|
356 |
|
9f908ef5a595
web: provide diff summary to the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents:
14562
diff
changeset
|
357 |
def diffstat(tmpl, ctx, statgen, parity): |
9f908ef5a595
web: provide diff summary to the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents:
14562
diff
changeset
|
358 |
'''Return a diffstat template for each file in the diff.''' |
9f908ef5a595
web: provide diff summary to the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents:
14562
diff
changeset
|
359 |
|
9f908ef5a595
web: provide diff summary to the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents:
14562
diff
changeset
|
360 |
stats, maxname, maxtotal, addtotal, removetotal, binary = statgen.next() |
14561
925d9f2b188b
web: include all files in the diffstat
Steven Brown <StevenGBrown@gmail.com>
parents:
14490
diff
changeset
|
361 |
files = ctx.files() |
14490
1d3e2349304a
web: provide diffstat to the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents:
14055
diff
changeset
|
362 |
|
14561
925d9f2b188b
web: include all files in the diffstat
Steven Brown <StevenGBrown@gmail.com>
parents:
14490
diff
changeset
|
363 |
def pct(i): |
925d9f2b188b
web: include all files in the diffstat
Steven Brown <StevenGBrown@gmail.com>
parents:
14490
diff
changeset
|
364 |
if maxtotal == 0: |
925d9f2b188b
web: include all files in the diffstat
Steven Brown <StevenGBrown@gmail.com>
parents:
14490
diff
changeset
|
365 |
return 0 |
925d9f2b188b
web: include all files in the diffstat
Steven Brown <StevenGBrown@gmail.com>
parents:
14490
diff
changeset
|
366 |
return (float(i) / maxtotal) * 100 |
14490
1d3e2349304a
web: provide diffstat to the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents:
14055
diff
changeset
|
367 |
|
14562
fccd3b966da7
web: provide the file number to the diffstat templates
Steven Brown <StevenGBrown@gmail.com>
parents:
14561
diff
changeset
|
368 |
fileno = 0 |
14561
925d9f2b188b
web: include all files in the diffstat
Steven Brown <StevenGBrown@gmail.com>
parents:
14490
diff
changeset
|
369 |
for filename, adds, removes, isbinary in stats: |
925d9f2b188b
web: include all files in the diffstat
Steven Brown <StevenGBrown@gmail.com>
parents:
14490
diff
changeset
|
370 |
template = filename in files and 'diffstatlink' or 'diffstatnolink' |
925d9f2b188b
web: include all files in the diffstat
Steven Brown <StevenGBrown@gmail.com>
parents:
14490
diff
changeset
|
371 |
total = adds + removes |
14562
fccd3b966da7
web: provide the file number to the diffstat templates
Steven Brown <StevenGBrown@gmail.com>
parents:
14561
diff
changeset
|
372 |
fileno += 1 |
fccd3b966da7
web: provide the file number to the diffstat templates
Steven Brown <StevenGBrown@gmail.com>
parents:
14561
diff
changeset
|
373 |
yield tmpl(template, node=ctx.hex(), file=filename, fileno=fileno, |
14561
925d9f2b188b
web: include all files in the diffstat
Steven Brown <StevenGBrown@gmail.com>
parents:
14490
diff
changeset
|
374 |
total=total, addpct=pct(adds), removepct=pct(removes), |
925d9f2b188b
web: include all files in the diffstat
Steven Brown <StevenGBrown@gmail.com>
parents:
14490
diff
changeset
|
375 |
parity=parity.next()) |
14490
1d3e2349304a
web: provide diffstat to the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents:
14055
diff
changeset
|
376 |
|
7345
55651328dfcc
hgweb: fix up the less/more links on the graph page
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7311
diff
changeset
|
377 |
class sessionvars(object): |
55651328dfcc
hgweb: fix up the less/more links on the graph page
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7311
diff
changeset
|
378 |
def __init__(self, vars, start='?'): |
55651328dfcc
hgweb: fix up the less/more links on the graph page
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7311
diff
changeset
|
379 |
self.start = start |
55651328dfcc
hgweb: fix up the less/more links on the graph page
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7311
diff
changeset
|
380 |
self.vars = vars |
55651328dfcc
hgweb: fix up the less/more links on the graph page
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7311
diff
changeset
|
381 |
def __getitem__(self, key): |
55651328dfcc
hgweb: fix up the less/more links on the graph page
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7311
diff
changeset
|
382 |
return self.vars[key] |
55651328dfcc
hgweb: fix up the less/more links on the graph page
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7311
diff
changeset
|
383 |
def __setitem__(self, key, value): |
55651328dfcc
hgweb: fix up the less/more links on the graph page
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7311
diff
changeset
|
384 |
self.vars[key] = value |
55651328dfcc
hgweb: fix up the less/more links on the graph page
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7311
diff
changeset
|
385 |
def __copy__(self): |
55651328dfcc
hgweb: fix up the less/more links on the graph page
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7311
diff
changeset
|
386 |
return sessionvars(copy.copy(self.vars), self.start) |
55651328dfcc
hgweb: fix up the less/more links on the graph page
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7311
diff
changeset
|
387 |
def __iter__(self): |
55651328dfcc
hgweb: fix up the less/more links on the graph page
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7311
diff
changeset
|
388 |
separator = self.start |
18367
ae7215f4f7b9
hgweb: generate query strings with parameters sorted by key
Mads Kiilerich <mads@kiilerich.com>
parents:
18320
diff
changeset
|
389 |
for key, value in sorted(self.vars.iteritems()): |
7345
55651328dfcc
hgweb: fix up the less/more links on the graph page
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7311
diff
changeset
|
390 |
yield {'name': key, 'value': str(value), 'separator': separator} |
55651328dfcc
hgweb: fix up the less/more links on the graph page
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7311
diff
changeset
|
391 |
separator = '&' |
12691
1b1a9038a71a
hgweb: fix hgweb_mod as well as hgwebdir_mod
Augie Fackler <durin42@gmail.com>
parents:
10282
diff
changeset
|
392 |
|
1b1a9038a71a
hgweb: fix hgweb_mod as well as hgwebdir_mod
Augie Fackler <durin42@gmail.com>
parents:
10282
diff
changeset
|
393 |
class wsgiui(ui.ui): |
1b1a9038a71a
hgweb: fix hgweb_mod as well as hgwebdir_mod
Augie Fackler <durin42@gmail.com>
parents:
10282
diff
changeset
|
394 |
# 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
|
395 |
def termwidth(self): |
1b1a9038a71a
hgweb: fix hgweb_mod as well as hgwebdir_mod
Augie Fackler <durin42@gmail.com>
parents:
10282
diff
changeset
|
396 |
return 80 |