Mercurial > hg
annotate mercurial/hgweb/webutil.py @ 24793:2ec894582ea2
bundle2: add a 'copy' method on parts
This is the first step in our quest for preserving the server output on error
(issue4594). We want to be able to copy the output parts from the aborted reply
into the exception bundle.
The function will be used in a later patch.
author | Pierre-Yves David <pierre-yves.david@fb.com> |
---|---|
date | Thu, 16 Apr 2015 03:15:28 -0400 |
parents | bbf1ae6b6a44 |
children | 858618d43524 |
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 |
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 |
21122
50981ce36236
hgweb: show as same parents as "hg parents -r REV FILE" in pages for file
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20681
diff
changeset
|
10 from mercurial import match, patch, error, ui, util, pathutil, context |
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 |
24177
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
13 from common import ErrorResponse, paritygen |
17289
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""" |
19094
fc1b77db123f
hgweb: handle filtered "0" rev in navigation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
19093
diff
changeset
|
54 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
|
55 |
fc1b77db123f
hgweb: handle filtered "0" rev in navigation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
19093
diff
changeset
|
56 def _first(self): |
fc1b77db123f
hgweb: handle filtered "0" rev in navigation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
19093
diff
changeset
|
57 """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
|
58 try: |
fc1b77db123f
hgweb: handle filtered "0" rev in navigation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
19093
diff
changeset
|
59 return iter(self._revlog).next() |
fc1b77db123f
hgweb: handle filtered "0" rev in navigation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
19093
diff
changeset
|
60 except StopIteration: |
fc1b77db123f
hgweb: handle filtered "0" rev in navigation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
19093
diff
changeset
|
61 return None |
18406
20cf53932b6f
hgweb: simplify the handling of empty repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18405
diff
changeset
|
62 |
18405
1eaf0d017b2c
hgweb: move hex creation into an object method
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18404
diff
changeset
|
63 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
|
64 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
|
65 |
18404
1da84a6b136a
hgweb: pass nodefunc to the revnav object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18403
diff
changeset
|
66 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
|
67 """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
|
68 |
18403
bfaee31a83d2
hgweb: move revnavgen into an object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18392
diff
changeset
|
69 :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
|
70 :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
|
71 :limit: how far shall we link |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
72 |
18403
bfaee31a83d2
hgweb: move revnavgen into an object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18392
diff
changeset
|
73 The return is: |
bfaee31a83d2
hgweb: move revnavgen into an object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18392
diff
changeset
|
74 - a single element tuple |
bfaee31a83d2
hgweb: move revnavgen into an object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18392
diff
changeset
|
75 - 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
|
76 - 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
|
77 - 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
|
78 """ |
18406
20cf53932b6f
hgweb: simplify the handling of empty repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18405
diff
changeset
|
79 if not self: |
20cf53932b6f
hgweb: simplify the handling of empty repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18405
diff
changeset
|
80 # empty repo |
20cf53932b6f
hgweb: simplify the handling of empty repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18405
diff
changeset
|
81 return ({'before': (), 'after': ()},) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
82 |
18425
6da1e979340a
hgweb: generate revnav in two phase
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18409
diff
changeset
|
83 targets = [] |
18403
bfaee31a83d2
hgweb: move revnavgen into an object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18392
diff
changeset
|
84 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
|
85 if f > limit: |
bfaee31a83d2
hgweb: move revnavgen into an object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18392
diff
changeset
|
86 break |
18425
6da1e979340a
hgweb: generate revnav in two phase
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18409
diff
changeset
|
87 targets.append(pos + f) |
6da1e979340a
hgweb: generate revnav in two phase
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18409
diff
changeset
|
88 targets.append(pos - f) |
6da1e979340a
hgweb: generate revnav in two phase
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18409
diff
changeset
|
89 targets.sort() |
6da1e979340a
hgweb: generate revnav in two phase
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18409
diff
changeset
|
90 |
19094
fc1b77db123f
hgweb: handle filtered "0" rev in navigation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
19093
diff
changeset
|
91 first = self._first() |
fc1b77db123f
hgweb: handle filtered "0" rev in navigation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
19093
diff
changeset
|
92 navbefore = [("(%i)" % first, self.hex(first))] |
18425
6da1e979340a
hgweb: generate revnav in two phase
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18409
diff
changeset
|
93 navafter = [] |
6da1e979340a
hgweb: generate revnav in two phase
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18409
diff
changeset
|
94 for rev in targets: |
18426
01638b51df44
hgweb: ignore filtered revision in revnav
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18425
diff
changeset
|
95 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
|
96 continue |
18425
6da1e979340a
hgweb: generate revnav in two phase
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18409
diff
changeset
|
97 if pos < rev < limit: |
18503
7f769d3a8ad2
hgweb: fix navigation label (issue3792)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18426
diff
changeset
|
98 navafter.append(("+%d" % abs(rev - pos), self.hex(rev))) |
18425
6da1e979340a
hgweb: generate revnav in two phase
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18409
diff
changeset
|
99 if 0 < rev < pos: |
18503
7f769d3a8ad2
hgweb: fix navigation label (issue3792)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18426
diff
changeset
|
100 navbefore.append(("-%d" % abs(rev - pos), self.hex(rev))) |
18425
6da1e979340a
hgweb: generate revnav in two phase
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18409
diff
changeset
|
101 |
10254
8d5de52431f2
hgweb: changenav: separate pages before and after the current position
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9402
diff
changeset
|
102 |
18403
bfaee31a83d2
hgweb: move revnavgen into an object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18392
diff
changeset
|
103 navafter.append(("tip", "tip")) |
bfaee31a83d2
hgweb: move revnavgen into an object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18392
diff
changeset
|
104 |
bfaee31a83d2
hgweb: move revnavgen into an object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18392
diff
changeset
|
105 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
|
106 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
|
107 'after': lambda **map: (data(i) for i in navafter)},) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
108 |
18408
f332a64fef51
hgweb: introduction a filerevnav subclass
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18407
diff
changeset
|
109 class filerevnav(revnav): |
18409
e3f5cef11d6a
hgweb: pass repo object to revnav construction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18408
diff
changeset
|
110 |
e3f5cef11d6a
hgweb: pass repo object to revnav construction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18408
diff
changeset
|
111 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
|
112 """Navigation generation object |
e3f5cef11d6a
hgweb: pass repo object to revnav construction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18408
diff
changeset
|
113 |
e3f5cef11d6a
hgweb: pass repo object to revnav construction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18408
diff
changeset
|
114 :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
|
115 :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
|
116 """ |
e3f5cef11d6a
hgweb: pass repo object to revnav construction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18408
diff
changeset
|
117 # used for iteration |
e3f5cef11d6a
hgweb: pass repo object to revnav construction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18408
diff
changeset
|
118 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
|
119 # used for hex generation |
e3f5cef11d6a
hgweb: pass repo object to revnav construction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18408
diff
changeset
|
120 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
|
121 |
e3f5cef11d6a
hgweb: pass repo object to revnav construction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18408
diff
changeset
|
122 def hex(self, rev): |
e3f5cef11d6a
hgweb: pass repo object to revnav construction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18408
diff
changeset
|
123 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
|
124 |
18408
f332a64fef51
hgweb: introduction a filerevnav subclass
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18407
diff
changeset
|
125 |
7671
06cf09c822c4
hgweb: simplify parents/children generation code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7637
diff
changeset
|
126 def _siblings(siblings=[], hiderev=None): |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
127 siblings = [s for s in siblings if s.node() != nullid] |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
128 if len(siblings) == 1 and siblings[0].rev() == hiderev: |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
129 return |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
130 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
|
131 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
|
132 d['user'] = s.user() |
f933076a19fc
hgweb: pass more information about parent/child csets to templates
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6750
diff
changeset
|
133 d['date'] = s.date() |
f933076a19fc
hgweb: pass more information about parent/child csets to templates
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6750
diff
changeset
|
134 d['description'] = s.description() |
7717
f9ba30cb7ee4
hgweb: expose sibling branches to templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7671
diff
changeset
|
135 d['branch'] = s.branch() |
14957
16e5271b216f
hgweb: move remaining hasattr calls to safehasattr
Augie Fackler <durin42@gmail.com>
parents:
14570
diff
changeset
|
136 if util.safehasattr(s, 'path'): |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
137 d['file'] = s.path() |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
138 yield d |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
139 |
7671
06cf09c822c4
hgweb: simplify parents/children generation code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7637
diff
changeset
|
140 def parents(ctx, hide=None): |
24136
46d6cdfce4bf
hgweb: use introrev() for finding parents (issue4506)
Anton Shestakov <engored@ya.ru>
parents:
23745
diff
changeset
|
141 if isinstance(ctx, context.basefilectx): |
46d6cdfce4bf
hgweb: use introrev() for finding parents (issue4506)
Anton Shestakov <engored@ya.ru>
parents:
23745
diff
changeset
|
142 introrev = ctx.introrev() |
46d6cdfce4bf
hgweb: use introrev() for finding parents (issue4506)
Anton Shestakov <engored@ya.ru>
parents:
23745
diff
changeset
|
143 if ctx.changectx().rev() != introrev: |
24340
567ae5365754
hgweb: replace 'ctx._repo' with 'ctx.repo()'
Matt Harbison <matt_harbison@yahoo.com>
parents:
24306
diff
changeset
|
144 return _siblings([ctx.repo()[introrev]], hide) |
7671
06cf09c822c4
hgweb: simplify parents/children generation code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7637
diff
changeset
|
145 return _siblings(ctx.parents(), hide) |
06cf09c822c4
hgweb: simplify parents/children generation code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7637
diff
changeset
|
146 |
06cf09c822c4
hgweb: simplify parents/children generation code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7637
diff
changeset
|
147 def children(ctx, hide=None): |
06cf09c822c4
hgweb: simplify parents/children generation code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7637
diff
changeset
|
148 return _siblings(ctx.children(), hide) |
06cf09c822c4
hgweb: simplify parents/children generation code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7637
diff
changeset
|
149 |
6434
62e0bb41e682
hgweb: minor improvements for new web style
Matt Mackall <mpm@selenic.com>
parents:
6413
diff
changeset
|
150 def renamelink(fctx): |
6437 | 151 r = fctx.renamed() |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
152 if r: |
20681
52e5aca15f0c
webutil: move from dict() construction to {} literals
Augie Fackler <raf@durin42.com>
parents:
20033
diff
changeset
|
153 return [{'file': r[0], 'node': hex(r[1])}] |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
154 return [] |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
155 |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
156 def nodetagsdict(repo, node): |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
157 return [{"name": i} for i in repo.nodetags(node)] |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
158 |
13596
270f57d35525
hgweb: add display of bookmarks for changelog and changeset
Alexander Solovyov <alexander@solovyov.net>
parents:
12691
diff
changeset
|
159 def nodebookmarksdict(repo, node): |
270f57d35525
hgweb: add display of bookmarks for changelog and changeset
Alexander Solovyov <alexander@solovyov.net>
parents:
12691
diff
changeset
|
160 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
|
161 |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
162 def nodebranchdict(repo, ctx): |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
163 branches = [] |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
164 branch = ctx.branch() |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
165 # 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
|
166 # ctx.branch() == 'default'. |
e7bf09acd410
localrepo: add branchtip() method for faster single-branch lookups
Brodie Rao <brodie@sf.io>
parents:
16308
diff
changeset
|
167 try: |
e7bf09acd410
localrepo: add branchtip() method for faster single-branch lookups
Brodie Rao <brodie@sf.io>
parents:
16308
diff
changeset
|
168 branchnode = repo.branchtip(branch) |
e7bf09acd410
localrepo: add branchtip() method for faster single-branch lookups
Brodie Rao <brodie@sf.io>
parents:
16308
diff
changeset
|
169 except error.RepoLookupError: |
e7bf09acd410
localrepo: add branchtip() method for faster single-branch lookups
Brodie Rao <brodie@sf.io>
parents:
16308
diff
changeset
|
170 branchnode = None |
e7bf09acd410
localrepo: add branchtip() method for faster single-branch lookups
Brodie Rao <brodie@sf.io>
parents:
16308
diff
changeset
|
171 if branchnode == ctx.node(): |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
172 branches.append({"name": branch}) |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
173 return branches |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
174 |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
175 def nodeinbranch(repo, ctx): |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
176 branches = [] |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
177 branch = ctx.branch() |
16719
e7bf09acd410
localrepo: add branchtip() method for faster single-branch lookups
Brodie Rao <brodie@sf.io>
parents:
16308
diff
changeset
|
178 try: |
e7bf09acd410
localrepo: add branchtip() method for faster single-branch lookups
Brodie Rao <brodie@sf.io>
parents:
16308
diff
changeset
|
179 branchnode = repo.branchtip(branch) |
e7bf09acd410
localrepo: add branchtip() method for faster single-branch lookups
Brodie Rao <brodie@sf.io>
parents:
16308
diff
changeset
|
180 except error.RepoLookupError: |
e7bf09acd410
localrepo: add branchtip() method for faster single-branch lookups
Brodie Rao <brodie@sf.io>
parents:
16308
diff
changeset
|
181 branchnode = None |
e7bf09acd410
localrepo: add branchtip() method for faster single-branch lookups
Brodie Rao <brodie@sf.io>
parents:
16308
diff
changeset
|
182 if branch != 'default' and branchnode != ctx.node(): |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
183 branches.append({"name": branch}) |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
184 return branches |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
185 |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
186 def nodebranchnodefault(ctx): |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
187 branches = [] |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
188 branch = ctx.branch() |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
189 if branch != 'default': |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
190 branches.append({"name": branch}) |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
191 return branches |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
192 |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
193 def showtag(repo, tmpl, t1, node=nullid, **args): |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
194 for t in repo.nodetags(node): |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
195 yield tmpl(t1, tag=t, **args) |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
196 |
13596
270f57d35525
hgweb: add display of bookmarks for changelog and changeset
Alexander Solovyov <alexander@solovyov.net>
parents:
12691
diff
changeset
|
197 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
|
198 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
|
199 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
|
200 |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
201 def cleanpath(repo, path): |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
202 path = path.lstrip('/') |
20033
f962870712da
pathutil: tease out a new library to break an import cycle from canonpath use
Augie Fackler <raf@durin42.com>
parents:
19094
diff
changeset
|
203 return pathutil.canonpath(repo.root, '', path) |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
204 |
17991
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
205 def changeidctx (repo, changeid): |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
206 try: |
6747
f6c00b17387c
use repo[changeid] to get a changectx
Matt Mackall <mpm@selenic.com>
parents:
6437
diff
changeset
|
207 ctx = repo[changeid] |
7637 | 208 except error.RepoError: |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
209 man = repo.manifest |
7361
9fe97eea5510
linkrev: take a revision number rather than a hash
Matt Mackall <mpm@selenic.com>
parents:
7345
diff
changeset
|
210 ctx = repo[man.linkrev(man.rev(man.lookup(changeid)))] |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
211 |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
212 return ctx |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
213 |
17991
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
214 def changectx (repo, req): |
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
215 changeid = "tip" |
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
216 if 'node' in req.form: |
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
217 changeid = req.form['node'][0] |
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
218 ipos=changeid.find(':') |
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
219 if ipos != -1: |
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
220 changeid = changeid[(ipos + 1):] |
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
221 elif 'manifest' in req.form: |
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
222 changeid = req.form['manifest'][0] |
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
223 |
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
224 return changeidctx(repo, changeid) |
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
225 |
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
226 def basechangectx(repo, req): |
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
227 if 'node' in req.form: |
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
228 changeid = req.form['node'][0] |
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
229 ipos=changeid.find(':') |
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
230 if ipos != -1: |
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
231 changeid = changeid[:ipos] |
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
232 return changeidctx(repo, changeid) |
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
233 |
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
234 return None |
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
235 |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
236 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
|
237 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
|
238 raise ErrorResponse(HTTP_NOT_FOUND, 'file not given') |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
239 path = cleanpath(repo, req.form['file'][0]) |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
240 if 'node' in req.form: |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
241 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
|
242 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
|
243 changeid = req.form['filenode'][0] |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
244 else: |
17289
f2d6b4f8e78c
hgweb: avoid traceback when file or node parameters are missing
Ross Lagerwall <rosslagerwall@gmail.com>
parents:
17202
diff
changeset
|
245 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
|
246 try: |
6747
f6c00b17387c
use repo[changeid] to get a changectx
Matt Mackall <mpm@selenic.com>
parents:
6437
diff
changeset
|
247 fctx = repo[changeid][path] |
7637 | 248 except error.RepoError: |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
249 fctx = repo.filectx(path, fileid=changeid) |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
250 |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
251 return fctx |
7310
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
252 |
23745
513d47905114
hgweb: extract changelist entry generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21122
diff
changeset
|
253 def changelistentry(web, ctx, tmpl): |
513d47905114
hgweb: extract changelist entry generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21122
diff
changeset
|
254 '''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
|
255 |
513d47905114
hgweb: extract changelist entry generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21122
diff
changeset
|
256 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
|
257 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
|
258 ''' |
513d47905114
hgweb: extract changelist entry generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21122
diff
changeset
|
259 repo = web.repo |
513d47905114
hgweb: extract changelist entry generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21122
diff
changeset
|
260 rev = ctx.rev() |
513d47905114
hgweb: extract changelist entry generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21122
diff
changeset
|
261 n = ctx.node() |
513d47905114
hgweb: extract changelist entry generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21122
diff
changeset
|
262 showtags = showtag(repo, tmpl, 'changelogtag', n) |
513d47905114
hgweb: extract changelist entry generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21122
diff
changeset
|
263 files = listfilediffs(tmpl, ctx.files(), n, web.maxfiles) |
513d47905114
hgweb: extract changelist entry generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21122
diff
changeset
|
264 |
513d47905114
hgweb: extract changelist entry generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21122
diff
changeset
|
265 return { |
513d47905114
hgweb: extract changelist entry generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21122
diff
changeset
|
266 "author": ctx.user(), |
513d47905114
hgweb: extract changelist entry generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21122
diff
changeset
|
267 "parent": parents(ctx, rev - 1), |
513d47905114
hgweb: extract changelist entry generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21122
diff
changeset
|
268 "child": children(ctx, rev + 1), |
513d47905114
hgweb: extract changelist entry generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21122
diff
changeset
|
269 "changelogtag": showtags, |
513d47905114
hgweb: extract changelist entry generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21122
diff
changeset
|
270 "desc": ctx.description(), |
513d47905114
hgweb: extract changelist entry generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21122
diff
changeset
|
271 "extra": ctx.extra(), |
513d47905114
hgweb: extract changelist entry generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21122
diff
changeset
|
272 "date": ctx.date(), |
513d47905114
hgweb: extract changelist entry generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21122
diff
changeset
|
273 "files": files, |
513d47905114
hgweb: extract changelist entry generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21122
diff
changeset
|
274 "rev": rev, |
513d47905114
hgweb: extract changelist entry generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21122
diff
changeset
|
275 "node": hex(n), |
513d47905114
hgweb: extract changelist entry generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21122
diff
changeset
|
276 "tags": nodetagsdict(repo, n), |
513d47905114
hgweb: extract changelist entry generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21122
diff
changeset
|
277 "bookmarks": nodebookmarksdict(repo, n), |
513d47905114
hgweb: extract changelist entry generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21122
diff
changeset
|
278 "inbranch": nodeinbranch(repo, ctx), |
513d47905114
hgweb: extract changelist entry generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21122
diff
changeset
|
279 "branches": nodebranchdict(repo, ctx) |
513d47905114
hgweb: extract changelist entry generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21122
diff
changeset
|
280 } |
513d47905114
hgweb: extract changelist entry generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21122
diff
changeset
|
281 |
24177
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
282 def changesetentry(web, req, tmpl, ctx): |
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
283 '''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
|
284 |
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
285 showtags = showtag(web.repo, tmpl, 'changesettag', ctx.node()) |
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
286 showbookmarks = showbookmark(web.repo, tmpl, 'changesetbookmark', |
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
287 ctx.node()) |
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
288 showbranch = nodebranchnodefault(ctx) |
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
289 |
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
290 files = [] |
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
291 parity = paritygen(web.stripecount) |
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
292 for blockno, f in enumerate(ctx.files()): |
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
293 template = f in ctx and 'filenodelink' or 'filenolink' |
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
294 files.append(tmpl(template, |
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
295 node=ctx.hex(), file=f, blockno=blockno + 1, |
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
296 parity=parity.next())) |
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
297 |
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
298 basectx = basechangectx(web.repo, req) |
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
299 if basectx is None: |
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
300 basectx = ctx.p1() |
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
301 |
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
302 style = web.config('web', 'style', 'paper') |
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
303 if 'style' in req.form: |
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
304 style = req.form['style'][0] |
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
305 |
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
306 parity = paritygen(web.stripecount) |
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
307 diff = diffs(web.repo, tmpl, ctx, basectx, None, parity, style) |
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
308 |
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
309 parity = paritygen(web.stripecount) |
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
310 diffstatsgen = diffstatgen(ctx, basectx) |
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
311 diffstats = diffstat(tmpl, ctx, diffstatsgen, parity) |
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
312 |
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
313 return dict( |
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
314 diff=diff, |
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
315 rev=ctx.rev(), |
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
316 node=ctx.hex(), |
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
317 parent=tuple(parents(ctx)), |
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
318 child=children(ctx), |
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
319 basenode=basectx.hex(), |
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
320 changesettag=showtags, |
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
321 changesetbookmark=showbookmarks, |
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
322 changesetbranch=showbranch, |
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
323 author=ctx.user(), |
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
324 desc=ctx.description(), |
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
325 extra=ctx.extra(), |
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
326 date=ctx.date(), |
24564
5ec4bda3097a
hgweb: add phase to {changeset} template
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24340
diff
changeset
|
327 phase=ctx.phasestr(), |
24177
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
328 files=files, |
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
329 diffsummary=lambda **x: diffsummary(diffstatsgen), |
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
330 diffstat=diffstats, |
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
331 archives=web.archivelist(ctx.hex()), |
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
332 tags=nodetagsdict(web.repo, ctx.node()), |
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
333 bookmarks=nodebookmarksdict(web.repo, ctx.node()), |
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
334 branch=nodebranchnodefault(ctx), |
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
335 inbranch=nodeinbranch(web.repo, ctx), |
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
336 branches=nodebranchdict(web.repo, ctx)) |
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
337 |
7311
de9c87fe1620
hgweb: move another utility function into the webutil module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7310
diff
changeset
|
338 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
|
339 for f in files[:max]: |
de9c87fe1620
hgweb: move another utility function into the webutil module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7310
diff
changeset
|
340 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
|
341 if len(files) > max: |
de9c87fe1620
hgweb: move another utility function into the webutil module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7310
diff
changeset
|
342 yield tmpl('fileellipses') |
de9c87fe1620
hgweb: move another utility function into the webutil module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7310
diff
changeset
|
343 |
17991
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
344 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
|
345 |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
346 def countgen(): |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
347 start = 1 |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
348 while True: |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
349 yield start |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
350 start += 1 |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
351 |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
352 blockcount = countgen() |
16308
2695aaf4eb72
hgweb: add block numbers to diff regions and related links
Paul Boddie <paul@boddie.org.uk>
parents:
14957
diff
changeset
|
353 def prettyprintlines(diff, blockno): |
7310
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
354 for lineno, l in enumerate(diff.splitlines(True)): |
24712
bbf1ae6b6a44
hgweb: expose raw line numbers to templates
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24564
diff
changeset
|
355 difflineno = "%d.%d" % (blockno, lineno + 1) |
7310
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
356 if l.startswith('+'): |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
357 ltype = "difflineplus" |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
358 elif l.startswith('-'): |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
359 ltype = "difflineminus" |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
360 elif l.startswith('@'): |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
361 ltype = "difflineat" |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
362 else: |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
363 ltype = "diffline" |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
364 yield tmpl(ltype, |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
365 line=l, |
24712
bbf1ae6b6a44
hgweb: expose raw line numbers to templates
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24564
diff
changeset
|
366 lineno=lineno + 1, |
bbf1ae6b6a44
hgweb: expose raw line numbers to templates
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24564
diff
changeset
|
367 lineid="l%s" % difflineno, |
bbf1ae6b6a44
hgweb: expose raw line numbers to templates
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24564
diff
changeset
|
368 linenumber="% 8s" % difflineno) |
7310
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
369 |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
370 if files: |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
371 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
|
372 else: |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
373 m = match.always(repo.root, repo.getcwd()) |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
374 |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
375 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
|
376 if basectx is None: |
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
377 parents = ctx.parents() |
24306
6ddc86eedc3b
style: kill ersatz if-else ternary operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
24177
diff
changeset
|
378 if parents: |
6ddc86eedc3b
style: kill ersatz if-else ternary operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
24177
diff
changeset
|
379 node1 = parents[0].node() |
6ddc86eedc3b
style: kill ersatz if-else ternary operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
24177
diff
changeset
|
380 else: |
6ddc86eedc3b
style: kill ersatz if-else ternary operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
24177
diff
changeset
|
381 node1 = nullid |
17991
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
382 else: |
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
383 node1 = basectx.node() |
7310
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
384 node2 = ctx.node() |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
385 |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
386 block = [] |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
387 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
|
388 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
|
389 blockno = blockcount.next() |
2695aaf4eb72
hgweb: add block numbers to diff regions and related links
Paul Boddie <paul@boddie.org.uk>
parents:
14957
diff
changeset
|
390 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
|
391 lines=prettyprintlines(''.join(block), blockno)) |
7310
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
392 block = [] |
9402
5d49fdef6fd0
hgweb: show diff header line in raw diffs
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8225
diff
changeset
|
393 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
|
394 chunk = ''.join(chunk.splitlines(True)[1:]) |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
395 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
|
396 blockno = blockcount.next() |
2695aaf4eb72
hgweb: add block numbers to diff regions and related links
Paul Boddie <paul@boddie.org.uk>
parents:
14957
diff
changeset
|
397 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
|
398 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
|
399 |
17302
5c64ce6168da
hgweb: fixes traceback for invalid files by removing top-level template
wujek srujek <wujek.srujek@googlemail.com>
parents:
17289
diff
changeset
|
400 def compare(tmpl, context, leftlines, rightlines): |
17202
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
401 '''Generator function that provides side-by-side comparison data.''' |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
402 |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
403 def compline(type, leftlineno, leftline, rightlineno, rightline): |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
404 lineid = leftlineno and ("l%s" % leftlineno) or '' |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
405 lineid += rightlineno and ("r%s" % rightlineno) or '' |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
406 return tmpl('comparisonline', |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
407 type=type, |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
408 lineid=lineid, |
24712
bbf1ae6b6a44
hgweb: expose raw line numbers to templates
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24564
diff
changeset
|
409 leftlineno=leftlineno, |
17202
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
410 leftlinenumber="% 6s" % (leftlineno or ''), |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
411 leftline=leftline or '', |
24712
bbf1ae6b6a44
hgweb: expose raw line numbers to templates
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24564
diff
changeset
|
412 rightlineno=rightlineno, |
17202
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
413 rightlinenumber="% 6s" % (rightlineno or ''), |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
414 rightline=rightline or '') |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
415 |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
416 def getblock(opcodes): |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
417 for type, llo, lhi, rlo, rhi in opcodes: |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
418 len1 = lhi - llo |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
419 len2 = rhi - rlo |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
420 count = min(len1, len2) |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
421 for i in xrange(count): |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
422 yield compline(type=type, |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
423 leftlineno=llo + i + 1, |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
424 leftline=leftlines[llo + i], |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
425 rightlineno=rlo + i + 1, |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
426 rightline=rightlines[rlo + i]) |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
427 if len1 > len2: |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
428 for i in xrange(llo + count, lhi): |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
429 yield compline(type=type, |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
430 leftlineno=i + 1, |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
431 leftline=leftlines[i], |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
432 rightlineno=None, |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
433 rightline=None) |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
434 elif len2 > len1: |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
435 for i in xrange(rlo + count, rhi): |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
436 yield compline(type=type, |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
437 leftlineno=None, |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
438 leftline=None, |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
439 rightlineno=i + 1, |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
440 rightline=rightlines[i]) |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
441 |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
442 s = difflib.SequenceMatcher(None, leftlines, rightlines) |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
443 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
|
444 yield tmpl('comparisonblock', lines=getblock(s.get_opcodes())) |
17202
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
445 else: |
17302
5c64ce6168da
hgweb: fixes traceback for invalid files by removing top-level template
wujek srujek <wujek.srujek@googlemail.com>
parents:
17289
diff
changeset
|
446 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
|
447 yield tmpl('comparisonblock', lines=getblock(oc)) |
17202
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
448 |
17991
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
449 def diffstatgen(ctx, basectx): |
14570
9f908ef5a595
web: provide diff summary to the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents:
14562
diff
changeset
|
450 '''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
|
451 |
17991
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
452 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
|
453 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
|
454 while True: |
9f908ef5a595
web: provide diff summary to the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents:
14562
diff
changeset
|
455 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
|
456 |
9f908ef5a595
web: provide diff summary to the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents:
14562
diff
changeset
|
457 def diffsummary(statgen): |
9f908ef5a595
web: provide diff summary to the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents:
14562
diff
changeset
|
458 '''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
|
459 |
9f908ef5a595
web: provide diff summary to the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents:
14562
diff
changeset
|
460 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
|
461 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
|
462 len(stats), addtotal, removetotal) |
9f908ef5a595
web: provide diff summary to the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents:
14562
diff
changeset
|
463 |
9f908ef5a595
web: provide diff summary to the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents:
14562
diff
changeset
|
464 def diffstat(tmpl, ctx, statgen, parity): |
9f908ef5a595
web: provide diff summary to the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents:
14562
diff
changeset
|
465 '''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
|
466 |
9f908ef5a595
web: provide diff summary to the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents:
14562
diff
changeset
|
467 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
|
468 files = ctx.files() |
14490
1d3e2349304a
web: provide diffstat to the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents:
14055
diff
changeset
|
469 |
14561
925d9f2b188b
web: include all files in the diffstat
Steven Brown <StevenGBrown@gmail.com>
parents:
14490
diff
changeset
|
470 def pct(i): |
925d9f2b188b
web: include all files in the diffstat
Steven Brown <StevenGBrown@gmail.com>
parents:
14490
diff
changeset
|
471 if maxtotal == 0: |
925d9f2b188b
web: include all files in the diffstat
Steven Brown <StevenGBrown@gmail.com>
parents:
14490
diff
changeset
|
472 return 0 |
925d9f2b188b
web: include all files in the diffstat
Steven Brown <StevenGBrown@gmail.com>
parents:
14490
diff
changeset
|
473 return (float(i) / maxtotal) * 100 |
14490
1d3e2349304a
web: provide diffstat to the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents:
14055
diff
changeset
|
474 |
14562
fccd3b966da7
web: provide the file number to the diffstat templates
Steven Brown <StevenGBrown@gmail.com>
parents:
14561
diff
changeset
|
475 fileno = 0 |
14561
925d9f2b188b
web: include all files in the diffstat
Steven Brown <StevenGBrown@gmail.com>
parents:
14490
diff
changeset
|
476 for filename, adds, removes, isbinary in stats: |
925d9f2b188b
web: include all files in the diffstat
Steven Brown <StevenGBrown@gmail.com>
parents:
14490
diff
changeset
|
477 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
|
478 total = adds + removes |
14562
fccd3b966da7
web: provide the file number to the diffstat templates
Steven Brown <StevenGBrown@gmail.com>
parents:
14561
diff
changeset
|
479 fileno += 1 |
fccd3b966da7
web: provide the file number to the diffstat templates
Steven Brown <StevenGBrown@gmail.com>
parents:
14561
diff
changeset
|
480 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
|
481 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
|
482 parity=parity.next()) |
14490
1d3e2349304a
web: provide diffstat to the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents:
14055
diff
changeset
|
483 |
7345
55651328dfcc
hgweb: fix up the less/more links on the graph page
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7311
diff
changeset
|
484 class sessionvars(object): |
55651328dfcc
hgweb: fix up the less/more links on the graph page
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7311
diff
changeset
|
485 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
|
486 self.start = start |
55651328dfcc
hgweb: fix up the less/more links on the graph page
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7311
diff
changeset
|
487 self.vars = vars |
55651328dfcc
hgweb: fix up the less/more links on the graph page
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7311
diff
changeset
|
488 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
|
489 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
|
490 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
|
491 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
|
492 def __copy__(self): |
55651328dfcc
hgweb: fix up the less/more links on the graph page
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7311
diff
changeset
|
493 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
|
494 def __iter__(self): |
55651328dfcc
hgweb: fix up the less/more links on the graph page
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7311
diff
changeset
|
495 separator = self.start |
18367
ae7215f4f7b9
hgweb: generate query strings with parameters sorted by key
Mads Kiilerich <mads@kiilerich.com>
parents:
18320
diff
changeset
|
496 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
|
497 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
|
498 separator = '&' |
12691
1b1a9038a71a
hgweb: fix hgweb_mod as well as hgwebdir_mod
Augie Fackler <durin42@gmail.com>
parents:
10282
diff
changeset
|
499 |
1b1a9038a71a
hgweb: fix hgweb_mod as well as hgwebdir_mod
Augie Fackler <durin42@gmail.com>
parents:
10282
diff
changeset
|
500 class wsgiui(ui.ui): |
1b1a9038a71a
hgweb: fix hgweb_mod as well as hgwebdir_mod
Augie Fackler <durin42@gmail.com>
parents:
10282
diff
changeset
|
501 # 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
|
502 def termwidth(self): |
1b1a9038a71a
hgweb: fix hgweb_mod as well as hgwebdir_mod
Augie Fackler <durin42@gmail.com>
parents:
10282
diff
changeset
|
503 return 80 |