Mercurial > hg
annotate mercurial/hgweb/webutil.py @ 34679:143337bcec9b
merge: add tests to show current behavior on failed filemerges
Currently, failed file merges will nevertheless force the user to continue
attempting to merge all additional unresolved files. Future patches will allow
the user to halt the merge process instead. This patch first introduces a test
demonstrating the current bejhavior so the upcoming changes are more obvious.
Differential Revision: https://phab.mercurial-scm.org/D930
author | Ryan McElroy <rmcelroy@fb.com> |
---|---|
date | Fri, 06 Oct 2017 06:48:43 -0700 |
parents | 407ebe7a9b93 |
children | 3caec3c032c8 |
rev | line source |
---|---|
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
1 # hgweb/webutil.py - utility library for the web interface. |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
2 # |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
3 # Copyright 21 May 2005 - (c) 2005 Jake Edge <jake@edge2.net> |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
4 # Copyright 2005-2007 Matt Mackall <mpm@selenic.com> |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
5 # |
8225
46293a0c7e9f
updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents:
7717
diff
changeset
|
6 # This software may be used and distributed according to the terms of the |
10263 | 7 # GNU General Public License version 2 or any later version. |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
8 |
27046
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27023
diff
changeset
|
9 from __future__ import absolute_import |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27023
diff
changeset
|
10 |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27023
diff
changeset
|
11 import copy |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27023
diff
changeset
|
12 import difflib |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27023
diff
changeset
|
13 import os |
26162
268b39770c28
hgweb: extract web substitutions table generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26129
diff
changeset
|
14 import re |
27046
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27023
diff
changeset
|
15 |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27023
diff
changeset
|
16 from ..i18n import _ |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27023
diff
changeset
|
17 from ..node import hex, nullid, short |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27023
diff
changeset
|
18 |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27023
diff
changeset
|
19 from .common import ( |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27023
diff
changeset
|
20 ErrorResponse, |
31665
5e6d44511317
hgweb: handle a "linerange" request parameter in filelog command
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31660
diff
changeset
|
21 HTTP_BAD_REQUEST, |
27046
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27023
diff
changeset
|
22 HTTP_NOT_FOUND, |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27023
diff
changeset
|
23 paritygen, |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27023
diff
changeset
|
24 ) |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27023
diff
changeset
|
25 |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27023
diff
changeset
|
26 from .. import ( |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27023
diff
changeset
|
27 context, |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27023
diff
changeset
|
28 error, |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27023
diff
changeset
|
29 match, |
31808
ca3b4a2b7e54
mdiff: add a hunkinrange helper function
Denis Laxalde <denis@laxalde.org>
parents:
31727
diff
changeset
|
30 mdiff, |
27046
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27023
diff
changeset
|
31 patch, |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27023
diff
changeset
|
32 pathutil, |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27023
diff
changeset
|
33 templatefilters, |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27023
diff
changeset
|
34 ui as uimod, |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27023
diff
changeset
|
35 util, |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27023
diff
changeset
|
36 ) |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
37 |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
38 def up(p): |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
39 if p[0] != "/": |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
40 p = "/" + p |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
41 if p[-1] == "/": |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
42 p = p[:-1] |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
43 up = os.path.dirname(p) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
44 if up == "/": |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
45 return "/" |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
46 return up + "/" |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
47 |
18391
833eb34e90e4
hgweb: better names for _navseq arguments
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18390
diff
changeset
|
48 def _navseq(step, firststep=None): |
833eb34e90e4
hgweb: better names for _navseq arguments
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18390
diff
changeset
|
49 if firststep: |
833eb34e90e4
hgweb: better names for _navseq arguments
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18390
diff
changeset
|
50 yield firststep |
833eb34e90e4
hgweb: better names for _navseq arguments
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18390
diff
changeset
|
51 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
|
52 firststep = 50 |
88a37b19dc0e
hgweb: ensure _navseq yield strictly increasing numbers
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18391
diff
changeset
|
53 yield firststep |
88a37b19dc0e
hgweb: ensure _navseq yield strictly increasing numbers
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18391
diff
changeset
|
54 assert step > 0 |
88a37b19dc0e
hgweb: ensure _navseq yield strictly increasing numbers
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18391
diff
changeset
|
55 assert firststep > 0 |
88a37b19dc0e
hgweb: ensure _navseq yield strictly increasing numbers
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18391
diff
changeset
|
56 while step <= firststep: |
88a37b19dc0e
hgweb: ensure _navseq yield strictly increasing numbers
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18391
diff
changeset
|
57 step *= 10 |
18390
28fa9443f751
hgweb: drop recursivity in _navseq
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18389
diff
changeset
|
58 while True: |
18391
833eb34e90e4
hgweb: better names for _navseq arguments
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18390
diff
changeset
|
59 yield 1 * step |
833eb34e90e4
hgweb: better names for _navseq arguments
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18390
diff
changeset
|
60 yield 3 * step |
833eb34e90e4
hgweb: better names for _navseq arguments
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18390
diff
changeset
|
61 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
|
62 |
18403
bfaee31a83d2
hgweb: move revnavgen into an object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18392
diff
changeset
|
63 class revnav(object): |
18320
60680d691a0b
hgweb: document the revnavgen function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17991
diff
changeset
|
64 |
18409
e3f5cef11d6a
hgweb: pass repo object to revnav construction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18408
diff
changeset
|
65 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
|
66 """Navigation generation object |
1da84a6b136a
hgweb: pass nodefunc to the revnav object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18403
diff
changeset
|
67 |
18409
e3f5cef11d6a
hgweb: pass repo object to revnav construction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18408
diff
changeset
|
68 :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
|
69 """ |
18409
e3f5cef11d6a
hgweb: pass repo object to revnav construction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18408
diff
changeset
|
70 # used for hex generation |
e3f5cef11d6a
hgweb: pass repo object to revnav construction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18408
diff
changeset
|
71 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
|
72 |
18406
20cf53932b6f
hgweb: simplify the handling of empty repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18405
diff
changeset
|
73 def __nonzero__(self): |
20cf53932b6f
hgweb: simplify the handling of empty repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18405
diff
changeset
|
74 """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
|
75 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
|
76 |
31476
413b44003462
py3: add __bool__ to every class defining __nonzero__
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31434
diff
changeset
|
77 __bool__ = __nonzero__ |
413b44003462
py3: add __bool__ to every class defining __nonzero__
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31434
diff
changeset
|
78 |
19094
fc1b77db123f
hgweb: handle filtered "0" rev in navigation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
19093
diff
changeset
|
79 def _first(self): |
fc1b77db123f
hgweb: handle filtered "0" rev in navigation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
19093
diff
changeset
|
80 """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
|
81 try: |
29216
ead25aa27a43
py3: convert to next() function
timeless <timeless@mozdev.org>
parents:
28709
diff
changeset
|
82 return next(iter(self._revlog)) |
19094
fc1b77db123f
hgweb: handle filtered "0" rev in navigation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
19093
diff
changeset
|
83 except StopIteration: |
fc1b77db123f
hgweb: handle filtered "0" rev in navigation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
19093
diff
changeset
|
84 return None |
18406
20cf53932b6f
hgweb: simplify the handling of empty repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18405
diff
changeset
|
85 |
18405
1eaf0d017b2c
hgweb: move hex creation into an object method
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18404
diff
changeset
|
86 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
|
87 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
|
88 |
18404
1da84a6b136a
hgweb: pass nodefunc to the revnav object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18403
diff
changeset
|
89 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
|
90 """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
|
91 |
18403
bfaee31a83d2
hgweb: move revnavgen into an object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18392
diff
changeset
|
92 :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
|
93 :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
|
94 :limit: how far shall we link |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
95 |
18403
bfaee31a83d2
hgweb: move revnavgen into an object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18392
diff
changeset
|
96 The return is: |
bfaee31a83d2
hgweb: move revnavgen into an object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18392
diff
changeset
|
97 - a single element tuple |
bfaee31a83d2
hgweb: move revnavgen into an object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18392
diff
changeset
|
98 - 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
|
99 - 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
|
100 - 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
|
101 """ |
18406
20cf53932b6f
hgweb: simplify the handling of empty repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18405
diff
changeset
|
102 if not self: |
20cf53932b6f
hgweb: simplify the handling of empty repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18405
diff
changeset
|
103 # empty repo |
20cf53932b6f
hgweb: simplify the handling of empty repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18405
diff
changeset
|
104 return ({'before': (), 'after': ()},) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
105 |
18425
6da1e979340a
hgweb: generate revnav in two phase
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18409
diff
changeset
|
106 targets = [] |
18403
bfaee31a83d2
hgweb: move revnavgen into an object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18392
diff
changeset
|
107 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
|
108 if f > limit: |
bfaee31a83d2
hgweb: move revnavgen into an object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18392
diff
changeset
|
109 break |
18425
6da1e979340a
hgweb: generate revnav in two phase
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18409
diff
changeset
|
110 targets.append(pos + f) |
6da1e979340a
hgweb: generate revnav in two phase
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18409
diff
changeset
|
111 targets.append(pos - f) |
6da1e979340a
hgweb: generate revnav in two phase
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18409
diff
changeset
|
112 targets.sort() |
6da1e979340a
hgweb: generate revnav in two phase
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18409
diff
changeset
|
113 |
19094
fc1b77db123f
hgweb: handle filtered "0" rev in navigation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
19093
diff
changeset
|
114 first = self._first() |
fc1b77db123f
hgweb: handle filtered "0" rev in navigation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
19093
diff
changeset
|
115 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
|
116 navafter = [] |
6da1e979340a
hgweb: generate revnav in two phase
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18409
diff
changeset
|
117 for rev in targets: |
18426
01638b51df44
hgweb: ignore filtered revision in revnav
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18425
diff
changeset
|
118 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
|
119 continue |
18425
6da1e979340a
hgweb: generate revnav in two phase
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18409
diff
changeset
|
120 if pos < rev < limit: |
18503
7f769d3a8ad2
hgweb: fix navigation label (issue3792)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18426
diff
changeset
|
121 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
|
122 if 0 < rev < pos: |
18503
7f769d3a8ad2
hgweb: fix navigation label (issue3792)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18426
diff
changeset
|
123 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
|
124 |
10254
8d5de52431f2
hgweb: changenav: separate pages before and after the current position
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9402
diff
changeset
|
125 |
18403
bfaee31a83d2
hgweb: move revnavgen into an object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18392
diff
changeset
|
126 navafter.append(("tip", "tip")) |
bfaee31a83d2
hgweb: move revnavgen into an object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18392
diff
changeset
|
127 |
bfaee31a83d2
hgweb: move revnavgen into an object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18392
diff
changeset
|
128 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
|
129 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
|
130 'after': lambda **map: (data(i) for i in navafter)},) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
131 |
18408
f332a64fef51
hgweb: introduction a filerevnav subclass
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18407
diff
changeset
|
132 class filerevnav(revnav): |
18409
e3f5cef11d6a
hgweb: pass repo object to revnav construction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18408
diff
changeset
|
133 |
e3f5cef11d6a
hgweb: pass repo object to revnav construction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18408
diff
changeset
|
134 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
|
135 """Navigation generation object |
e3f5cef11d6a
hgweb: pass repo object to revnav construction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18408
diff
changeset
|
136 |
e3f5cef11d6a
hgweb: pass repo object to revnav construction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18408
diff
changeset
|
137 :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
|
138 :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
|
139 """ |
e3f5cef11d6a
hgweb: pass repo object to revnav construction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18408
diff
changeset
|
140 # used for iteration |
e3f5cef11d6a
hgweb: pass repo object to revnav construction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18408
diff
changeset
|
141 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
|
142 # used for hex generation |
e3f5cef11d6a
hgweb: pass repo object to revnav construction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18408
diff
changeset
|
143 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
|
144 |
e3f5cef11d6a
hgweb: pass repo object to revnav construction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18408
diff
changeset
|
145 def hex(self, rev): |
e3f5cef11d6a
hgweb: pass repo object to revnav construction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18408
diff
changeset
|
146 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
|
147 |
27023
0c8ef79b9fd7
webutil: make _siblings into an object with __iter__ and __len__
Anton Shestakov <av6@dwimlabs.net>
parents:
27008
diff
changeset
|
148 class _siblings(object): |
31391
d2878bec55bd
hgweb: don't use mutable default argument value
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31276
diff
changeset
|
149 def __init__(self, siblings=None, hiderev=None): |
31434
d4645ae6ba15
hgweb: explicitly tests for None in webutil
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31391
diff
changeset
|
150 if siblings is None: |
d4645ae6ba15
hgweb: explicitly tests for None in webutil
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31391
diff
changeset
|
151 siblings = [] |
d4645ae6ba15
hgweb: explicitly tests for None in webutil
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31391
diff
changeset
|
152 self.siblings = [s for s in siblings if s.node() != nullid] |
27023
0c8ef79b9fd7
webutil: make _siblings into an object with __iter__ and __len__
Anton Shestakov <av6@dwimlabs.net>
parents:
27008
diff
changeset
|
153 if len(self.siblings) == 1 and self.siblings[0].rev() == hiderev: |
0c8ef79b9fd7
webutil: make _siblings into an object with __iter__ and __len__
Anton Shestakov <av6@dwimlabs.net>
parents:
27008
diff
changeset
|
154 self.siblings = [] |
18408
f332a64fef51
hgweb: introduction a filerevnav subclass
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18407
diff
changeset
|
155 |
27023
0c8ef79b9fd7
webutil: make _siblings into an object with __iter__ and __len__
Anton Shestakov <av6@dwimlabs.net>
parents:
27008
diff
changeset
|
156 def __iter__(self): |
0c8ef79b9fd7
webutil: make _siblings into an object with __iter__ and __len__
Anton Shestakov <av6@dwimlabs.net>
parents:
27008
diff
changeset
|
157 for s in self.siblings: |
0c8ef79b9fd7
webutil: make _siblings into an object with __iter__ and __len__
Anton Shestakov <av6@dwimlabs.net>
parents:
27008
diff
changeset
|
158 d = { |
0c8ef79b9fd7
webutil: make _siblings into an object with __iter__ and __len__
Anton Shestakov <av6@dwimlabs.net>
parents:
27008
diff
changeset
|
159 'node': s.hex(), |
0c8ef79b9fd7
webutil: make _siblings into an object with __iter__ and __len__
Anton Shestakov <av6@dwimlabs.net>
parents:
27008
diff
changeset
|
160 'rev': s.rev(), |
0c8ef79b9fd7
webutil: make _siblings into an object with __iter__ and __len__
Anton Shestakov <av6@dwimlabs.net>
parents:
27008
diff
changeset
|
161 'user': s.user(), |
0c8ef79b9fd7
webutil: make _siblings into an object with __iter__ and __len__
Anton Shestakov <av6@dwimlabs.net>
parents:
27008
diff
changeset
|
162 'date': s.date(), |
0c8ef79b9fd7
webutil: make _siblings into an object with __iter__ and __len__
Anton Shestakov <av6@dwimlabs.net>
parents:
27008
diff
changeset
|
163 'description': s.description(), |
0c8ef79b9fd7
webutil: make _siblings into an object with __iter__ and __len__
Anton Shestakov <av6@dwimlabs.net>
parents:
27008
diff
changeset
|
164 'branch': s.branch(), |
0c8ef79b9fd7
webutil: make _siblings into an object with __iter__ and __len__
Anton Shestakov <av6@dwimlabs.net>
parents:
27008
diff
changeset
|
165 } |
0c8ef79b9fd7
webutil: make _siblings into an object with __iter__ and __len__
Anton Shestakov <av6@dwimlabs.net>
parents:
27008
diff
changeset
|
166 if util.safehasattr(s, 'path'): |
0c8ef79b9fd7
webutil: make _siblings into an object with __iter__ and __len__
Anton Shestakov <av6@dwimlabs.net>
parents:
27008
diff
changeset
|
167 d['file'] = s.path() |
0c8ef79b9fd7
webutil: make _siblings into an object with __iter__ and __len__
Anton Shestakov <av6@dwimlabs.net>
parents:
27008
diff
changeset
|
168 yield d |
0c8ef79b9fd7
webutil: make _siblings into an object with __iter__ and __len__
Anton Shestakov <av6@dwimlabs.net>
parents:
27008
diff
changeset
|
169 |
0c8ef79b9fd7
webutil: make _siblings into an object with __iter__ and __len__
Anton Shestakov <av6@dwimlabs.net>
parents:
27008
diff
changeset
|
170 def __len__(self): |
0c8ef79b9fd7
webutil: make _siblings into an object with __iter__ and __len__
Anton Shestakov <av6@dwimlabs.net>
parents:
27008
diff
changeset
|
171 return len(self.siblings) |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
172 |
34390
f6492f482c60
hgweb: query string arguments to control whitespace for annotate
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34246
diff
changeset
|
173 def difffeatureopts(req, ui, section): |
30081
dd0ff715a82c
hgweb: make fctx.annotate a separated function so it could be wrapped
Jun Wu <quark@fb.com>
parents:
29216
diff
changeset
|
174 diffopts = patch.difffeatureopts(ui, untrusted=True, |
34390
f6492f482c60
hgweb: query string arguments to control whitespace for annotate
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34246
diff
changeset
|
175 section=section, whitespace=True) |
f6492f482c60
hgweb: query string arguments to control whitespace for annotate
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34246
diff
changeset
|
176 |
f6492f482c60
hgweb: query string arguments to control whitespace for annotate
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34246
diff
changeset
|
177 for k in ('ignorews', 'ignorewsamount', 'ignorewseol', 'ignoreblanklines'): |
f6492f482c60
hgweb: query string arguments to control whitespace for annotate
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34246
diff
changeset
|
178 v = req.form.get(k, [None])[0] |
f6492f482c60
hgweb: query string arguments to control whitespace for annotate
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34246
diff
changeset
|
179 if v is not None: |
34403
407ebe7a9b93
hgweb: use parsebool for parsing diff query string options
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34390
diff
changeset
|
180 v = util.parsebool(v) |
407ebe7a9b93
hgweb: use parsebool for parsing diff query string options
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34390
diff
changeset
|
181 setattr(diffopts, k, v if v is not None else True) |
34390
f6492f482c60
hgweb: query string arguments to control whitespace for annotate
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34246
diff
changeset
|
182 |
f6492f482c60
hgweb: query string arguments to control whitespace for annotate
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34246
diff
changeset
|
183 return diffopts |
f6492f482c60
hgweb: query string arguments to control whitespace for annotate
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34246
diff
changeset
|
184 |
f6492f482c60
hgweb: query string arguments to control whitespace for annotate
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34246
diff
changeset
|
185 def annotate(req, fctx, ui): |
f6492f482c60
hgweb: query string arguments to control whitespace for annotate
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34246
diff
changeset
|
186 diffopts = difffeatureopts(req, ui, 'annotate') |
30081
dd0ff715a82c
hgweb: make fctx.annotate a separated function so it could be wrapped
Jun Wu <quark@fb.com>
parents:
29216
diff
changeset
|
187 return fctx.annotate(follow=True, linenumber=True, diffopts=diffopts) |
dd0ff715a82c
hgweb: make fctx.annotate a separated function so it could be wrapped
Jun Wu <quark@fb.com>
parents:
29216
diff
changeset
|
188 |
7671
06cf09c822c4
hgweb: simplify parents/children generation code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7637
diff
changeset
|
189 def parents(ctx, hide=None): |
24136
46d6cdfce4bf
hgweb: use introrev() for finding parents (issue4506)
Anton Shestakov <engored@ya.ru>
parents:
23745
diff
changeset
|
190 if isinstance(ctx, context.basefilectx): |
46d6cdfce4bf
hgweb: use introrev() for finding parents (issue4506)
Anton Shestakov <engored@ya.ru>
parents:
23745
diff
changeset
|
191 introrev = ctx.introrev() |
46d6cdfce4bf
hgweb: use introrev() for finding parents (issue4506)
Anton Shestakov <engored@ya.ru>
parents:
23745
diff
changeset
|
192 if ctx.changectx().rev() != introrev: |
24340
567ae5365754
hgweb: replace 'ctx._repo' with 'ctx.repo()'
Matt Harbison <matt_harbison@yahoo.com>
parents:
24306
diff
changeset
|
193 return _siblings([ctx.repo()[introrev]], hide) |
7671
06cf09c822c4
hgweb: simplify parents/children generation code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7637
diff
changeset
|
194 return _siblings(ctx.parents(), hide) |
06cf09c822c4
hgweb: simplify parents/children generation code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7637
diff
changeset
|
195 |
06cf09c822c4
hgweb: simplify parents/children generation code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7637
diff
changeset
|
196 def children(ctx, hide=None): |
06cf09c822c4
hgweb: simplify parents/children generation code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7637
diff
changeset
|
197 return _siblings(ctx.children(), hide) |
06cf09c822c4
hgweb: simplify parents/children generation code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7637
diff
changeset
|
198 |
6434
62e0bb41e682
hgweb: minor improvements for new web style
Matt Mackall <mpm@selenic.com>
parents:
6413
diff
changeset
|
199 def renamelink(fctx): |
6437 | 200 r = fctx.renamed() |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
201 if r: |
20681
52e5aca15f0c
webutil: move from dict() construction to {} literals
Augie Fackler <raf@durin42.com>
parents:
20033
diff
changeset
|
202 return [{'file': r[0], 'node': hex(r[1])}] |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
203 return [] |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
204 |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
205 def nodetagsdict(repo, node): |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
206 return [{"name": i} for i in repo.nodetags(node)] |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
207 |
13596
270f57d35525
hgweb: add display of bookmarks for changelog and changeset
Alexander Solovyov <alexander@solovyov.net>
parents:
12691
diff
changeset
|
208 def nodebookmarksdict(repo, node): |
270f57d35525
hgweb: add display of bookmarks for changelog and changeset
Alexander Solovyov <alexander@solovyov.net>
parents:
12691
diff
changeset
|
209 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
|
210 |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
211 def nodebranchdict(repo, ctx): |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
212 branches = [] |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
213 branch = ctx.branch() |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
214 # 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
|
215 # ctx.branch() == 'default'. |
e7bf09acd410
localrepo: add branchtip() method for faster single-branch lookups
Brodie Rao <brodie@sf.io>
parents:
16308
diff
changeset
|
216 try: |
e7bf09acd410
localrepo: add branchtip() method for faster single-branch lookups
Brodie Rao <brodie@sf.io>
parents:
16308
diff
changeset
|
217 branchnode = repo.branchtip(branch) |
e7bf09acd410
localrepo: add branchtip() method for faster single-branch lookups
Brodie Rao <brodie@sf.io>
parents:
16308
diff
changeset
|
218 except error.RepoLookupError: |
e7bf09acd410
localrepo: add branchtip() method for faster single-branch lookups
Brodie Rao <brodie@sf.io>
parents:
16308
diff
changeset
|
219 branchnode = None |
e7bf09acd410
localrepo: add branchtip() method for faster single-branch lookups
Brodie Rao <brodie@sf.io>
parents:
16308
diff
changeset
|
220 if branchnode == ctx.node(): |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
221 branches.append({"name": branch}) |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
222 return branches |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
223 |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
224 def nodeinbranch(repo, ctx): |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
225 branches = [] |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
226 branch = ctx.branch() |
16719
e7bf09acd410
localrepo: add branchtip() method for faster single-branch lookups
Brodie Rao <brodie@sf.io>
parents:
16308
diff
changeset
|
227 try: |
e7bf09acd410
localrepo: add branchtip() method for faster single-branch lookups
Brodie Rao <brodie@sf.io>
parents:
16308
diff
changeset
|
228 branchnode = repo.branchtip(branch) |
e7bf09acd410
localrepo: add branchtip() method for faster single-branch lookups
Brodie Rao <brodie@sf.io>
parents:
16308
diff
changeset
|
229 except error.RepoLookupError: |
e7bf09acd410
localrepo: add branchtip() method for faster single-branch lookups
Brodie Rao <brodie@sf.io>
parents:
16308
diff
changeset
|
230 branchnode = None |
e7bf09acd410
localrepo: add branchtip() method for faster single-branch lookups
Brodie Rao <brodie@sf.io>
parents:
16308
diff
changeset
|
231 if branch != 'default' and branchnode != ctx.node(): |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
232 branches.append({"name": branch}) |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
233 return branches |
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 def nodebranchnodefault(ctx): |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
236 branches = [] |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
237 branch = ctx.branch() |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
238 if branch != 'default': |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
239 branches.append({"name": branch}) |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
240 return branches |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
241 |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
242 def showtag(repo, tmpl, t1, node=nullid, **args): |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
243 for t in repo.nodetags(node): |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
244 yield tmpl(t1, tag=t, **args) |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
245 |
13596
270f57d35525
hgweb: add display of bookmarks for changelog and changeset
Alexander Solovyov <alexander@solovyov.net>
parents:
12691
diff
changeset
|
246 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
|
247 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
|
248 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
|
249 |
26129
a103ecb8a04a
hgweb: move branchentries code from webcommands to webutil
Anton Shestakov <av6@dwimlabs.net>
parents:
25999
diff
changeset
|
250 def branchentries(repo, stripecount, limit=0): |
a103ecb8a04a
hgweb: move branchentries code from webcommands to webutil
Anton Shestakov <av6@dwimlabs.net>
parents:
25999
diff
changeset
|
251 tips = [] |
a103ecb8a04a
hgweb: move branchentries code from webcommands to webutil
Anton Shestakov <av6@dwimlabs.net>
parents:
25999
diff
changeset
|
252 heads = repo.heads() |
a103ecb8a04a
hgweb: move branchentries code from webcommands to webutil
Anton Shestakov <av6@dwimlabs.net>
parents:
25999
diff
changeset
|
253 parity = paritygen(stripecount) |
a103ecb8a04a
hgweb: move branchentries code from webcommands to webutil
Anton Shestakov <av6@dwimlabs.net>
parents:
25999
diff
changeset
|
254 sortkey = lambda item: (not item[1], item[0].rev()) |
a103ecb8a04a
hgweb: move branchentries code from webcommands to webutil
Anton Shestakov <av6@dwimlabs.net>
parents:
25999
diff
changeset
|
255 |
a103ecb8a04a
hgweb: move branchentries code from webcommands to webutil
Anton Shestakov <av6@dwimlabs.net>
parents:
25999
diff
changeset
|
256 def entries(**map): |
a103ecb8a04a
hgweb: move branchentries code from webcommands to webutil
Anton Shestakov <av6@dwimlabs.net>
parents:
25999
diff
changeset
|
257 count = 0 |
a103ecb8a04a
hgweb: move branchentries code from webcommands to webutil
Anton Shestakov <av6@dwimlabs.net>
parents:
25999
diff
changeset
|
258 if not tips: |
a103ecb8a04a
hgweb: move branchentries code from webcommands to webutil
Anton Shestakov <av6@dwimlabs.net>
parents:
25999
diff
changeset
|
259 for tag, hs, tip, closed in repo.branchmap().iterbranches(): |
a103ecb8a04a
hgweb: move branchentries code from webcommands to webutil
Anton Shestakov <av6@dwimlabs.net>
parents:
25999
diff
changeset
|
260 tips.append((repo[tip], closed)) |
a103ecb8a04a
hgweb: move branchentries code from webcommands to webutil
Anton Shestakov <av6@dwimlabs.net>
parents:
25999
diff
changeset
|
261 for ctx, closed in sorted(tips, key=sortkey, reverse=True): |
a103ecb8a04a
hgweb: move branchentries code from webcommands to webutil
Anton Shestakov <av6@dwimlabs.net>
parents:
25999
diff
changeset
|
262 if limit > 0 and count >= limit: |
a103ecb8a04a
hgweb: move branchentries code from webcommands to webutil
Anton Shestakov <av6@dwimlabs.net>
parents:
25999
diff
changeset
|
263 return |
a103ecb8a04a
hgweb: move branchentries code from webcommands to webutil
Anton Shestakov <av6@dwimlabs.net>
parents:
25999
diff
changeset
|
264 count += 1 |
a103ecb8a04a
hgweb: move branchentries code from webcommands to webutil
Anton Shestakov <av6@dwimlabs.net>
parents:
25999
diff
changeset
|
265 if closed: |
a103ecb8a04a
hgweb: move branchentries code from webcommands to webutil
Anton Shestakov <av6@dwimlabs.net>
parents:
25999
diff
changeset
|
266 status = 'closed' |
a103ecb8a04a
hgweb: move branchentries code from webcommands to webutil
Anton Shestakov <av6@dwimlabs.net>
parents:
25999
diff
changeset
|
267 elif ctx.node() not in heads: |
a103ecb8a04a
hgweb: move branchentries code from webcommands to webutil
Anton Shestakov <av6@dwimlabs.net>
parents:
25999
diff
changeset
|
268 status = 'inactive' |
a103ecb8a04a
hgweb: move branchentries code from webcommands to webutil
Anton Shestakov <av6@dwimlabs.net>
parents:
25999
diff
changeset
|
269 else: |
a103ecb8a04a
hgweb: move branchentries code from webcommands to webutil
Anton Shestakov <av6@dwimlabs.net>
parents:
25999
diff
changeset
|
270 status = 'open' |
a103ecb8a04a
hgweb: move branchentries code from webcommands to webutil
Anton Shestakov <av6@dwimlabs.net>
parents:
25999
diff
changeset
|
271 yield { |
29216
ead25aa27a43
py3: convert to next() function
timeless <timeless@mozdev.org>
parents:
28709
diff
changeset
|
272 'parity': next(parity), |
26129
a103ecb8a04a
hgweb: move branchentries code from webcommands to webutil
Anton Shestakov <av6@dwimlabs.net>
parents:
25999
diff
changeset
|
273 'branch': ctx.branch(), |
a103ecb8a04a
hgweb: move branchentries code from webcommands to webutil
Anton Shestakov <av6@dwimlabs.net>
parents:
25999
diff
changeset
|
274 'status': status, |
a103ecb8a04a
hgweb: move branchentries code from webcommands to webutil
Anton Shestakov <av6@dwimlabs.net>
parents:
25999
diff
changeset
|
275 'node': ctx.hex(), |
a103ecb8a04a
hgweb: move branchentries code from webcommands to webutil
Anton Shestakov <av6@dwimlabs.net>
parents:
25999
diff
changeset
|
276 'date': ctx.date() |
a103ecb8a04a
hgweb: move branchentries code from webcommands to webutil
Anton Shestakov <av6@dwimlabs.net>
parents:
25999
diff
changeset
|
277 } |
a103ecb8a04a
hgweb: move branchentries code from webcommands to webutil
Anton Shestakov <av6@dwimlabs.net>
parents:
25999
diff
changeset
|
278 |
a103ecb8a04a
hgweb: move branchentries code from webcommands to webutil
Anton Shestakov <av6@dwimlabs.net>
parents:
25999
diff
changeset
|
279 return entries |
a103ecb8a04a
hgweb: move branchentries code from webcommands to webutil
Anton Shestakov <av6@dwimlabs.net>
parents:
25999
diff
changeset
|
280 |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
281 def cleanpath(repo, path): |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
282 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
|
283 return pathutil.canonpath(repo.root, '', path) |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
284 |
25999
1c75249e159b
style: adjust whitespaces in webutil.py
Anton Shestakov <av6@dwimlabs.net>
parents:
25778
diff
changeset
|
285 def changeidctx(repo, changeid): |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
286 try: |
6747
f6c00b17387c
use repo[changeid] to get a changectx
Matt Mackall <mpm@selenic.com>
parents:
6437
diff
changeset
|
287 ctx = repo[changeid] |
7637 | 288 except error.RepoError: |
30375
11b8b740d54a
manifest: remove last uses of repo.manifest
Durham Goode <durham@fb.com>
parents:
30081
diff
changeset
|
289 man = repo.manifestlog._revlog |
7361
9fe97eea5510
linkrev: take a revision number rather than a hash
Matt Mackall <mpm@selenic.com>
parents:
7345
diff
changeset
|
290 ctx = repo[man.linkrev(man.rev(man.lookup(changeid)))] |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
291 |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
292 return ctx |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
293 |
25999
1c75249e159b
style: adjust whitespaces in webutil.py
Anton Shestakov <av6@dwimlabs.net>
parents:
25778
diff
changeset
|
294 def changectx(repo, req): |
17991
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
295 changeid = "tip" |
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
296 if 'node' in req.form: |
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
297 changeid = req.form['node'][0] |
25999
1c75249e159b
style: adjust whitespaces in webutil.py
Anton Shestakov <av6@dwimlabs.net>
parents:
25778
diff
changeset
|
298 ipos = changeid.find(':') |
17991
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
299 if ipos != -1: |
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
300 changeid = changeid[(ipos + 1):] |
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
301 elif 'manifest' in req.form: |
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
302 changeid = req.form['manifest'][0] |
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
303 |
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
304 return changeidctx(repo, changeid) |
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
305 |
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
306 def basechangectx(repo, req): |
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
307 if 'node' in req.form: |
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
308 changeid = req.form['node'][0] |
25999
1c75249e159b
style: adjust whitespaces in webutil.py
Anton Shestakov <av6@dwimlabs.net>
parents:
25778
diff
changeset
|
309 ipos = changeid.find(':') |
17991
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
310 if ipos != -1: |
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
311 changeid = changeid[:ipos] |
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
312 return changeidctx(repo, changeid) |
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
313 |
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
314 return None |
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
315 |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
316 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
|
317 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
|
318 raise ErrorResponse(HTTP_NOT_FOUND, 'file not given') |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
319 path = cleanpath(repo, req.form['file'][0]) |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
320 if 'node' in req.form: |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
321 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
|
322 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
|
323 changeid = req.form['filenode'][0] |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
324 else: |
17289
f2d6b4f8e78c
hgweb: avoid traceback when file or node parameters are missing
Ross Lagerwall <rosslagerwall@gmail.com>
parents:
17202
diff
changeset
|
325 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
|
326 try: |
6747
f6c00b17387c
use repo[changeid] to get a changectx
Matt Mackall <mpm@selenic.com>
parents:
6437
diff
changeset
|
327 fctx = repo[changeid][path] |
7637 | 328 except error.RepoError: |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
329 fctx = repo.filectx(path, fileid=changeid) |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
330 |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
331 return fctx |
7310
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
332 |
31665
5e6d44511317
hgweb: handle a "linerange" request parameter in filelog command
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31660
diff
changeset
|
333 def linerange(req): |
5e6d44511317
hgweb: handle a "linerange" request parameter in filelog command
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31660
diff
changeset
|
334 linerange = req.form.get('linerange') |
5e6d44511317
hgweb: handle a "linerange" request parameter in filelog command
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31660
diff
changeset
|
335 if linerange is None: |
5e6d44511317
hgweb: handle a "linerange" request parameter in filelog command
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31660
diff
changeset
|
336 return None |
5e6d44511317
hgweb: handle a "linerange" request parameter in filelog command
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31660
diff
changeset
|
337 if len(linerange) > 1: |
5e6d44511317
hgweb: handle a "linerange" request parameter in filelog command
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31660
diff
changeset
|
338 raise ErrorResponse(HTTP_BAD_REQUEST, |
5e6d44511317
hgweb: handle a "linerange" request parameter in filelog command
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31660
diff
changeset
|
339 'redundant linerange parameter') |
5e6d44511317
hgweb: handle a "linerange" request parameter in filelog command
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31660
diff
changeset
|
340 try: |
5e6d44511317
hgweb: handle a "linerange" request parameter in filelog command
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31660
diff
changeset
|
341 fromline, toline = map(int, linerange[0].split(':', 1)) |
5e6d44511317
hgweb: handle a "linerange" request parameter in filelog command
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31660
diff
changeset
|
342 except ValueError: |
5e6d44511317
hgweb: handle a "linerange" request parameter in filelog command
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31660
diff
changeset
|
343 raise ErrorResponse(HTTP_BAD_REQUEST, |
5e6d44511317
hgweb: handle a "linerange" request parameter in filelog command
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31660
diff
changeset
|
344 'invalid linerange parameter') |
5e6d44511317
hgweb: handle a "linerange" request parameter in filelog command
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31660
diff
changeset
|
345 try: |
5e6d44511317
hgweb: handle a "linerange" request parameter in filelog command
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31660
diff
changeset
|
346 return util.processlinerange(fromline, toline) |
5e6d44511317
hgweb: handle a "linerange" request parameter in filelog command
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31660
diff
changeset
|
347 except error.ParseError as exc: |
5e6d44511317
hgweb: handle a "linerange" request parameter in filelog command
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31660
diff
changeset
|
348 raise ErrorResponse(HTTP_BAD_REQUEST, str(exc)) |
5e6d44511317
hgweb: handle a "linerange" request parameter in filelog command
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31660
diff
changeset
|
349 |
5e6d44511317
hgweb: handle a "linerange" request parameter in filelog command
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31660
diff
changeset
|
350 def formatlinerange(fromline, toline): |
5e6d44511317
hgweb: handle a "linerange" request parameter in filelog command
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31660
diff
changeset
|
351 return '%d:%d' % (fromline + 1, toline) |
5e6d44511317
hgweb: handle a "linerange" request parameter in filelog command
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31660
diff
changeset
|
352 |
27294
5aa2afb4f81a
hgweb: move entry-preparing code from webcommands to webutils.commonentry()
Anton Shestakov <av6@dwimlabs.net>
parents:
27046
diff
changeset
|
353 def commonentry(repo, ctx): |
5aa2afb4f81a
hgweb: move entry-preparing code from webcommands to webutils.commonentry()
Anton Shestakov <av6@dwimlabs.net>
parents:
27046
diff
changeset
|
354 node = ctx.node() |
5aa2afb4f81a
hgweb: move entry-preparing code from webcommands to webutils.commonentry()
Anton Shestakov <av6@dwimlabs.net>
parents:
27046
diff
changeset
|
355 return { |
5aa2afb4f81a
hgweb: move entry-preparing code from webcommands to webutils.commonentry()
Anton Shestakov <av6@dwimlabs.net>
parents:
27046
diff
changeset
|
356 'rev': ctx.rev(), |
5aa2afb4f81a
hgweb: move entry-preparing code from webcommands to webutils.commonentry()
Anton Shestakov <av6@dwimlabs.net>
parents:
27046
diff
changeset
|
357 'node': hex(node), |
5aa2afb4f81a
hgweb: move entry-preparing code from webcommands to webutils.commonentry()
Anton Shestakov <av6@dwimlabs.net>
parents:
27046
diff
changeset
|
358 'author': ctx.user(), |
5aa2afb4f81a
hgweb: move entry-preparing code from webcommands to webutils.commonentry()
Anton Shestakov <av6@dwimlabs.net>
parents:
27046
diff
changeset
|
359 'desc': ctx.description(), |
5aa2afb4f81a
hgweb: move entry-preparing code from webcommands to webutils.commonentry()
Anton Shestakov <av6@dwimlabs.net>
parents:
27046
diff
changeset
|
360 'date': ctx.date(), |
5aa2afb4f81a
hgweb: move entry-preparing code from webcommands to webutils.commonentry()
Anton Shestakov <av6@dwimlabs.net>
parents:
27046
diff
changeset
|
361 'extra': ctx.extra(), |
5aa2afb4f81a
hgweb: move entry-preparing code from webcommands to webutils.commonentry()
Anton Shestakov <av6@dwimlabs.net>
parents:
27046
diff
changeset
|
362 'phase': ctx.phasestr(), |
5aa2afb4f81a
hgweb: move entry-preparing code from webcommands to webutils.commonentry()
Anton Shestakov <av6@dwimlabs.net>
parents:
27046
diff
changeset
|
363 'branch': nodebranchnodefault(ctx), |
5aa2afb4f81a
hgweb: move entry-preparing code from webcommands to webutils.commonentry()
Anton Shestakov <av6@dwimlabs.net>
parents:
27046
diff
changeset
|
364 'inbranch': nodeinbranch(repo, ctx), |
5aa2afb4f81a
hgweb: move entry-preparing code from webcommands to webutils.commonentry()
Anton Shestakov <av6@dwimlabs.net>
parents:
27046
diff
changeset
|
365 'branches': nodebranchdict(repo, ctx), |
5aa2afb4f81a
hgweb: move entry-preparing code from webcommands to webutils.commonentry()
Anton Shestakov <av6@dwimlabs.net>
parents:
27046
diff
changeset
|
366 'tags': nodetagsdict(repo, node), |
5aa2afb4f81a
hgweb: move entry-preparing code from webcommands to webutils.commonentry()
Anton Shestakov <av6@dwimlabs.net>
parents:
27046
diff
changeset
|
367 'bookmarks': nodebookmarksdict(repo, node), |
5aa2afb4f81a
hgweb: move entry-preparing code from webcommands to webutils.commonentry()
Anton Shestakov <av6@dwimlabs.net>
parents:
27046
diff
changeset
|
368 'parent': lambda **x: parents(ctx), |
5aa2afb4f81a
hgweb: move entry-preparing code from webcommands to webutils.commonentry()
Anton Shestakov <av6@dwimlabs.net>
parents:
27046
diff
changeset
|
369 'child': lambda **x: children(ctx), |
5aa2afb4f81a
hgweb: move entry-preparing code from webcommands to webutils.commonentry()
Anton Shestakov <av6@dwimlabs.net>
parents:
27046
diff
changeset
|
370 } |
5aa2afb4f81a
hgweb: move entry-preparing code from webcommands to webutils.commonentry()
Anton Shestakov <av6@dwimlabs.net>
parents:
27046
diff
changeset
|
371 |
23745
513d47905114
hgweb: extract changelist entry generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21122
diff
changeset
|
372 def changelistentry(web, ctx, tmpl): |
513d47905114
hgweb: extract changelist entry generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21122
diff
changeset
|
373 '''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
|
374 |
513d47905114
hgweb: extract changelist entry generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21122
diff
changeset
|
375 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
|
376 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
|
377 ''' |
513d47905114
hgweb: extract changelist entry generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21122
diff
changeset
|
378 repo = web.repo |
513d47905114
hgweb: extract changelist entry generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21122
diff
changeset
|
379 rev = ctx.rev() |
513d47905114
hgweb: extract changelist entry generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21122
diff
changeset
|
380 n = ctx.node() |
513d47905114
hgweb: extract changelist entry generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21122
diff
changeset
|
381 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
|
382 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
|
383 |
27294
5aa2afb4f81a
hgweb: move entry-preparing code from webcommands to webutils.commonentry()
Anton Shestakov <av6@dwimlabs.net>
parents:
27046
diff
changeset
|
384 entry = commonentry(repo, ctx) |
5aa2afb4f81a
hgweb: move entry-preparing code from webcommands to webutils.commonentry()
Anton Shestakov <av6@dwimlabs.net>
parents:
27046
diff
changeset
|
385 entry.update( |
28709
94494031f659
hgweb: add parents to json-log (issue5074)
Anton Shestakov <av6@dwimlabs.net>
parents:
27294
diff
changeset
|
386 allparents=lambda **x: parents(ctx), |
27294
5aa2afb4f81a
hgweb: move entry-preparing code from webcommands to webutils.commonentry()
Anton Shestakov <av6@dwimlabs.net>
parents:
27046
diff
changeset
|
387 parent=lambda **x: parents(ctx, rev - 1), |
5aa2afb4f81a
hgweb: move entry-preparing code from webcommands to webutils.commonentry()
Anton Shestakov <av6@dwimlabs.net>
parents:
27046
diff
changeset
|
388 child=lambda **x: children(ctx, rev + 1), |
5aa2afb4f81a
hgweb: move entry-preparing code from webcommands to webutils.commonentry()
Anton Shestakov <av6@dwimlabs.net>
parents:
27046
diff
changeset
|
389 changelogtag=showtags, |
5aa2afb4f81a
hgweb: move entry-preparing code from webcommands to webutils.commonentry()
Anton Shestakov <av6@dwimlabs.net>
parents:
27046
diff
changeset
|
390 files=files, |
5aa2afb4f81a
hgweb: move entry-preparing code from webcommands to webutils.commonentry()
Anton Shestakov <av6@dwimlabs.net>
parents:
27046
diff
changeset
|
391 ) |
5aa2afb4f81a
hgweb: move entry-preparing code from webcommands to webutils.commonentry()
Anton Shestakov <av6@dwimlabs.net>
parents:
27046
diff
changeset
|
392 return entry |
23745
513d47905114
hgweb: extract changelist entry generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21122
diff
changeset
|
393 |
25602
85fb416f2fa7
hgweb: provide symrev (symbolic revision) property to the templates
Anton Shestakov <av6@dwimlabs.net>
parents:
25278
diff
changeset
|
394 def symrevorshortnode(req, ctx): |
85fb416f2fa7
hgweb: provide symrev (symbolic revision) property to the templates
Anton Shestakov <av6@dwimlabs.net>
parents:
25278
diff
changeset
|
395 if 'node' in req.form: |
27008
7f19f331ef59
hgweb: do not import templatefilters.revescape and websub as symbol
Yuya Nishihara <yuya@tcha.org>
parents:
27007
diff
changeset
|
396 return templatefilters.revescape(req.form['node'][0]) |
25602
85fb416f2fa7
hgweb: provide symrev (symbolic revision) property to the templates
Anton Shestakov <av6@dwimlabs.net>
parents:
25278
diff
changeset
|
397 else: |
85fb416f2fa7
hgweb: provide symrev (symbolic revision) property to the templates
Anton Shestakov <av6@dwimlabs.net>
parents:
25278
diff
changeset
|
398 return short(ctx.node()) |
85fb416f2fa7
hgweb: provide symrev (symbolic revision) property to the templates
Anton Shestakov <av6@dwimlabs.net>
parents:
25278
diff
changeset
|
399 |
24177
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
400 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
|
401 '''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
|
402 |
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
403 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
|
404 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
|
405 ctx.node()) |
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
406 showbranch = nodebranchnodefault(ctx) |
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
407 |
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
408 files = [] |
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
409 parity = paritygen(web.stripecount) |
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
410 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
|
411 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
|
412 files.append(tmpl(template, |
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
413 node=ctx.hex(), file=f, blockno=blockno + 1, |
29216
ead25aa27a43
py3: convert to next() function
timeless <timeless@mozdev.org>
parents:
28709
diff
changeset
|
414 parity=next(parity))) |
24177
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
415 |
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
416 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
|
417 if basectx is None: |
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
418 basectx = ctx.p1() |
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
419 |
34246
db63872e10cc
configitems: register the 'web.style' config
Boris Feld <boris.feld@octobus.net>
parents:
31808
diff
changeset
|
420 style = web.config('web', 'style') |
24177
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
421 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
|
422 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
|
423 |
31660
c2dbd818e884
hgweb: handle "parity" internally in webutil.diffs()
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31476
diff
changeset
|
424 diff = diffs(web, tmpl, ctx, basectx, None, style) |
24177
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
425 |
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
426 parity = paritygen(web.stripecount) |
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
427 diffstatsgen = diffstatgen(ctx, basectx) |
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
428 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
|
429 |
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
430 return dict( |
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
431 diff=diff, |
25602
85fb416f2fa7
hgweb: provide symrev (symbolic revision) property to the templates
Anton Shestakov <av6@dwimlabs.net>
parents:
25278
diff
changeset
|
432 symrev=symrevorshortnode(req, ctx), |
24177
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
433 basenode=basectx.hex(), |
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
434 changesettag=showtags, |
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
435 changesetbookmark=showbookmarks, |
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
436 changesetbranch=showbranch, |
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
437 files=files, |
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
438 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
|
439 diffstat=diffstats, |
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
440 archives=web.archivelist(ctx.hex()), |
27294
5aa2afb4f81a
hgweb: move entry-preparing code from webcommands to webutils.commonentry()
Anton Shestakov <av6@dwimlabs.net>
parents:
27046
diff
changeset
|
441 **commonentry(web.repo, ctx)) |
24177
f53b7174facf
hgweb: extract changeset template mapping generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24136
diff
changeset
|
442 |
7311
de9c87fe1620
hgweb: move another utility function into the webutil module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7310
diff
changeset
|
443 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
|
444 for f in files[:max]: |
de9c87fe1620
hgweb: move another utility function into the webutil module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7310
diff
changeset
|
445 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
|
446 if len(files) > max: |
de9c87fe1620
hgweb: move another utility function into the webutil module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7310
diff
changeset
|
447 yield tmpl('fileellipses') |
de9c87fe1620
hgweb: move another utility function into the webutil module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7310
diff
changeset
|
448 |
31727
6be6e4becaaf
hgweb: prefix line id by ctx shortnode in filelog when patches are shown
Denis Laxalde <denis@laxalde.org>
parents:
31704
diff
changeset
|
449 def diffs(web, tmpl, ctx, basectx, files, style, linerange=None, |
6be6e4becaaf
hgweb: prefix line id by ctx shortnode in filelog when patches are shown
Denis Laxalde <denis@laxalde.org>
parents:
31704
diff
changeset
|
450 lineidprefix=''): |
7310
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
451 |
31276
cd29673cebdb
hgweb: use patch.diffhunks in webutil.diffs to simplify the algorithm
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31275
diff
changeset
|
452 def prettyprintlines(lines, blockno): |
cd29673cebdb
hgweb: use patch.diffhunks in webutil.diffs to simplify the algorithm
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31275
diff
changeset
|
453 for lineno, l in enumerate(lines, 1): |
31275
e2f141045634
hgweb: start enumerate at 1 in webutil.diffs's inner function prettyprintlines
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31082
diff
changeset
|
454 difflineno = "%d.%d" % (blockno, lineno) |
7310
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
455 if l.startswith('+'): |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
456 ltype = "difflineplus" |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
457 elif l.startswith('-'): |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
458 ltype = "difflineminus" |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
459 elif l.startswith('@'): |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
460 ltype = "difflineat" |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
461 else: |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
462 ltype = "diffline" |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
463 yield tmpl(ltype, |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
464 line=l, |
31275
e2f141045634
hgweb: start enumerate at 1 in webutil.diffs's inner function prettyprintlines
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31082
diff
changeset
|
465 lineno=lineno, |
31727
6be6e4becaaf
hgweb: prefix line id by ctx shortnode in filelog when patches are shown
Denis Laxalde <denis@laxalde.org>
parents:
31704
diff
changeset
|
466 lineid=lineidprefix + "l%s" % difflineno, |
24712
bbf1ae6b6a44
hgweb: expose raw line numbers to templates
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24564
diff
changeset
|
467 linenumber="% 8s" % difflineno) |
7310
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
468 |
31660
c2dbd818e884
hgweb: handle "parity" internally in webutil.diffs()
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31476
diff
changeset
|
469 repo = web.repo |
7310
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
470 if files: |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
471 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
|
472 else: |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
473 m = match.always(repo.root, repo.getcwd()) |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
474 |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
475 diffopts = patch.diffopts(repo.ui, untrusted=True) |
31082
abb92b3d370e
hgweb: explictly pass basectx in webutil.diffs
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
30375
diff
changeset
|
476 node1 = basectx.node() |
7310
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
477 node2 = ctx.node() |
31660
c2dbd818e884
hgweb: handle "parity" internally in webutil.diffs()
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31476
diff
changeset
|
478 parity = paritygen(web.stripecount) |
7310
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
479 |
31276
cd29673cebdb
hgweb: use patch.diffhunks in webutil.diffs to simplify the algorithm
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31275
diff
changeset
|
480 diffhunks = patch.diffhunks(repo, node1, node2, m, opts=diffopts) |
cd29673cebdb
hgweb: use patch.diffhunks in webutil.diffs to simplify the algorithm
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31275
diff
changeset
|
481 for blockno, (header, hunks) in enumerate(diffhunks, 1): |
cd29673cebdb
hgweb: use patch.diffhunks in webutil.diffs to simplify the algorithm
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31275
diff
changeset
|
482 if style != 'raw': |
cd29673cebdb
hgweb: use patch.diffhunks in webutil.diffs to simplify the algorithm
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31275
diff
changeset
|
483 header = header[1:] |
cd29673cebdb
hgweb: use patch.diffhunks in webutil.diffs to simplify the algorithm
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31275
diff
changeset
|
484 lines = [h + '\n' for h in header] |
cd29673cebdb
hgweb: use patch.diffhunks in webutil.diffs to simplify the algorithm
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31275
diff
changeset
|
485 for hunkrange, hunklines in hunks: |
31666
aaebc80c9f1d
hgweb: add a 'linerange' parameter to webutil.diffs()
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31665
diff
changeset
|
486 if linerange is not None and hunkrange is not None: |
aaebc80c9f1d
hgweb: add a 'linerange' parameter to webutil.diffs()
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31665
diff
changeset
|
487 s1, l1, s2, l2 = hunkrange |
31808
ca3b4a2b7e54
mdiff: add a hunkinrange helper function
Denis Laxalde <denis@laxalde.org>
parents:
31727
diff
changeset
|
488 if not mdiff.hunkinrange((s2, l2), linerange): |
31666
aaebc80c9f1d
hgweb: add a 'linerange' parameter to webutil.diffs()
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31665
diff
changeset
|
489 continue |
31276
cd29673cebdb
hgweb: use patch.diffhunks in webutil.diffs to simplify the algorithm
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31275
diff
changeset
|
490 lines.extend(hunklines) |
cd29673cebdb
hgweb: use patch.diffhunks in webutil.diffs to simplify the algorithm
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31275
diff
changeset
|
491 if lines: |
29216
ead25aa27a43
py3: convert to next() function
timeless <timeless@mozdev.org>
parents:
28709
diff
changeset
|
492 yield tmpl('diffblock', parity=next(parity), blockno=blockno, |
31276
cd29673cebdb
hgweb: use patch.diffhunks in webutil.diffs to simplify the algorithm
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31275
diff
changeset
|
493 lines=prettyprintlines(lines, blockno)) |
7345
55651328dfcc
hgweb: fix up the less/more links on the graph page
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7311
diff
changeset
|
494 |
17302
5c64ce6168da
hgweb: fixes traceback for invalid files by removing top-level template
wujek srujek <wujek.srujek@googlemail.com>
parents:
17289
diff
changeset
|
495 def compare(tmpl, context, leftlines, rightlines): |
17202
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
496 '''Generator function that provides side-by-side comparison data.''' |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
497 |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
498 def compline(type, leftlineno, leftline, rightlineno, rightline): |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
499 lineid = leftlineno and ("l%s" % leftlineno) or '' |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
500 lineid += rightlineno and ("r%s" % rightlineno) or '' |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
501 return tmpl('comparisonline', |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
502 type=type, |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
503 lineid=lineid, |
24712
bbf1ae6b6a44
hgweb: expose raw line numbers to templates
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24564
diff
changeset
|
504 leftlineno=leftlineno, |
17202
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
505 leftlinenumber="% 6s" % (leftlineno or ''), |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
506 leftline=leftline or '', |
24712
bbf1ae6b6a44
hgweb: expose raw line numbers to templates
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24564
diff
changeset
|
507 rightlineno=rightlineno, |
17202
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
508 rightlinenumber="% 6s" % (rightlineno or ''), |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
509 rightline=rightline or '') |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
510 |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
511 def getblock(opcodes): |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
512 for type, llo, lhi, rlo, rhi in opcodes: |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
513 len1 = lhi - llo |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
514 len2 = rhi - rlo |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
515 count = min(len1, len2) |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
516 for i in xrange(count): |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
517 yield compline(type=type, |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
518 leftlineno=llo + i + 1, |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
519 leftline=leftlines[llo + i], |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
520 rightlineno=rlo + i + 1, |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
521 rightline=rightlines[rlo + i]) |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
522 if len1 > len2: |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
523 for i in xrange(llo + count, lhi): |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
524 yield compline(type=type, |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
525 leftlineno=i + 1, |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
526 leftline=leftlines[i], |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
527 rightlineno=None, |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
528 rightline=None) |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
529 elif len2 > len1: |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
530 for i in xrange(rlo + count, rhi): |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
531 yield compline(type=type, |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
532 leftlineno=None, |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
533 leftline=None, |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
534 rightlineno=i + 1, |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
535 rightline=rightlines[i]) |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
536 |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
537 s = difflib.SequenceMatcher(None, leftlines, rightlines) |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
538 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
|
539 yield tmpl('comparisonblock', lines=getblock(s.get_opcodes())) |
17202
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
540 else: |
17302
5c64ce6168da
hgweb: fixes traceback for invalid files by removing top-level template
wujek srujek <wujek.srujek@googlemail.com>
parents:
17289
diff
changeset
|
541 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
|
542 yield tmpl('comparisonblock', lines=getblock(oc)) |
17202
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
16719
diff
changeset
|
543 |
17991
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
544 def diffstatgen(ctx, basectx): |
14570
9f908ef5a595
web: provide diff summary to the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents:
14562
diff
changeset
|
545 '''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
|
546 |
17991
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17302
diff
changeset
|
547 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
|
548 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
|
549 while True: |
9f908ef5a595
web: provide diff summary to the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents:
14562
diff
changeset
|
550 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
|
551 |
9f908ef5a595
web: provide diff summary to the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents:
14562
diff
changeset
|
552 def diffsummary(statgen): |
9f908ef5a595
web: provide diff summary to the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents:
14562
diff
changeset
|
553 '''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
|
554 |
29216
ead25aa27a43
py3: convert to next() function
timeless <timeless@mozdev.org>
parents:
28709
diff
changeset
|
555 stats, maxname, maxtotal, addtotal, removetotal, binary = next(statgen) |
14570
9f908ef5a595
web: provide diff summary to the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents:
14562
diff
changeset
|
556 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
|
557 len(stats), addtotal, removetotal) |
9f908ef5a595
web: provide diff summary to the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents:
14562
diff
changeset
|
558 |
9f908ef5a595
web: provide diff summary to the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents:
14562
diff
changeset
|
559 def diffstat(tmpl, ctx, statgen, parity): |
9f908ef5a595
web: provide diff summary to the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents:
14562
diff
changeset
|
560 '''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
|
561 |
29216
ead25aa27a43
py3: convert to next() function
timeless <timeless@mozdev.org>
parents:
28709
diff
changeset
|
562 stats, maxname, maxtotal, addtotal, removetotal, binary = next(statgen) |
14561
925d9f2b188b
web: include all files in the diffstat
Steven Brown <StevenGBrown@gmail.com>
parents:
14490
diff
changeset
|
563 files = ctx.files() |
14490
1d3e2349304a
web: provide diffstat to the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents:
14055
diff
changeset
|
564 |
14561
925d9f2b188b
web: include all files in the diffstat
Steven Brown <StevenGBrown@gmail.com>
parents:
14490
diff
changeset
|
565 def pct(i): |
925d9f2b188b
web: include all files in the diffstat
Steven Brown <StevenGBrown@gmail.com>
parents:
14490
diff
changeset
|
566 if maxtotal == 0: |
925d9f2b188b
web: include all files in the diffstat
Steven Brown <StevenGBrown@gmail.com>
parents:
14490
diff
changeset
|
567 return 0 |
925d9f2b188b
web: include all files in the diffstat
Steven Brown <StevenGBrown@gmail.com>
parents:
14490
diff
changeset
|
568 return (float(i) / maxtotal) * 100 |
14490
1d3e2349304a
web: provide diffstat to the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents:
14055
diff
changeset
|
569 |
14562
fccd3b966da7
web: provide the file number to the diffstat templates
Steven Brown <StevenGBrown@gmail.com>
parents:
14561
diff
changeset
|
570 fileno = 0 |
14561
925d9f2b188b
web: include all files in the diffstat
Steven Brown <StevenGBrown@gmail.com>
parents:
14490
diff
changeset
|
571 for filename, adds, removes, isbinary in stats: |
925d9f2b188b
web: include all files in the diffstat
Steven Brown <StevenGBrown@gmail.com>
parents:
14490
diff
changeset
|
572 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
|
573 total = adds + removes |
14562
fccd3b966da7
web: provide the file number to the diffstat templates
Steven Brown <StevenGBrown@gmail.com>
parents:
14561
diff
changeset
|
574 fileno += 1 |
fccd3b966da7
web: provide the file number to the diffstat templates
Steven Brown <StevenGBrown@gmail.com>
parents:
14561
diff
changeset
|
575 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
|
576 total=total, addpct=pct(adds), removepct=pct(removes), |
29216
ead25aa27a43
py3: convert to next() function
timeless <timeless@mozdev.org>
parents:
28709
diff
changeset
|
577 parity=next(parity)) |
14490
1d3e2349304a
web: provide diffstat to the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents:
14055
diff
changeset
|
578 |
7345
55651328dfcc
hgweb: fix up the less/more links on the graph page
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7311
diff
changeset
|
579 class sessionvars(object): |
55651328dfcc
hgweb: fix up the less/more links on the graph page
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7311
diff
changeset
|
580 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
|
581 self.start = start |
55651328dfcc
hgweb: fix up the less/more links on the graph page
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7311
diff
changeset
|
582 self.vars = vars |
55651328dfcc
hgweb: fix up the less/more links on the graph page
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7311
diff
changeset
|
583 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
|
584 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
|
585 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
|
586 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
|
587 def __copy__(self): |
55651328dfcc
hgweb: fix up the less/more links on the graph page
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7311
diff
changeset
|
588 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
|
589 def __iter__(self): |
55651328dfcc
hgweb: fix up the less/more links on the graph page
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7311
diff
changeset
|
590 separator = self.start |
18367
ae7215f4f7b9
hgweb: generate query strings with parameters sorted by key
Mads Kiilerich <mads@kiilerich.com>
parents:
18320
diff
changeset
|
591 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
|
592 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
|
593 separator = '&' |
12691
1b1a9038a71a
hgweb: fix hgweb_mod as well as hgwebdir_mod
Augie Fackler <durin42@gmail.com>
parents:
10282
diff
changeset
|
594 |
27007
c8cbef073645
hgweb: alias ui module as uimod
Yuya Nishihara <yuya@tcha.org>
parents:
26894
diff
changeset
|
595 class wsgiui(uimod.ui): |
12691
1b1a9038a71a
hgweb: fix hgweb_mod as well as hgwebdir_mod
Augie Fackler <durin42@gmail.com>
parents:
10282
diff
changeset
|
596 # 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
|
597 def termwidth(self): |
1b1a9038a71a
hgweb: fix hgweb_mod as well as hgwebdir_mod
Augie Fackler <durin42@gmail.com>
parents:
10282
diff
changeset
|
598 return 80 |
26162
268b39770c28
hgweb: extract web substitutions table generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26129
diff
changeset
|
599 |
268b39770c28
hgweb: extract web substitutions table generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26129
diff
changeset
|
600 def getwebsubs(repo): |
268b39770c28
hgweb: extract web substitutions table generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26129
diff
changeset
|
601 websubtable = [] |
268b39770c28
hgweb: extract web substitutions table generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26129
diff
changeset
|
602 websubdefs = repo.ui.configitems('websub') |
268b39770c28
hgweb: extract web substitutions table generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26129
diff
changeset
|
603 # we must maintain interhg backwards compatibility |
268b39770c28
hgweb: extract web substitutions table generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26129
diff
changeset
|
604 websubdefs += repo.ui.configitems('interhg') |
268b39770c28
hgweb: extract web substitutions table generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26129
diff
changeset
|
605 for key, pattern in websubdefs: |
268b39770c28
hgweb: extract web substitutions table generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26129
diff
changeset
|
606 # grab the delimiter from the character after the "s" |
268b39770c28
hgweb: extract web substitutions table generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26129
diff
changeset
|
607 unesc = pattern[1] |
268b39770c28
hgweb: extract web substitutions table generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26129
diff
changeset
|
608 delim = re.escape(unesc) |
268b39770c28
hgweb: extract web substitutions table generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26129
diff
changeset
|
609 |
268b39770c28
hgweb: extract web substitutions table generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26129
diff
changeset
|
610 # identify portions of the pattern, taking care to avoid escaped |
268b39770c28
hgweb: extract web substitutions table generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26129
diff
changeset
|
611 # delimiters. the replace format and flags are optional, but |
268b39770c28
hgweb: extract web substitutions table generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26129
diff
changeset
|
612 # delimiters are required. |
268b39770c28
hgweb: extract web substitutions table generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26129
diff
changeset
|
613 match = re.match( |
268b39770c28
hgweb: extract web substitutions table generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26129
diff
changeset
|
614 r'^s%s(.+)(?:(?<=\\\\)|(?<!\\))%s(.*)%s([ilmsux])*$' |
268b39770c28
hgweb: extract web substitutions table generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26129
diff
changeset
|
615 % (delim, delim, delim), pattern) |
268b39770c28
hgweb: extract web substitutions table generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26129
diff
changeset
|
616 if not match: |
268b39770c28
hgweb: extract web substitutions table generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26129
diff
changeset
|
617 repo.ui.warn(_("websub: invalid pattern for %s: %s\n") |
268b39770c28
hgweb: extract web substitutions table generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26129
diff
changeset
|
618 % (key, pattern)) |
268b39770c28
hgweb: extract web substitutions table generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26129
diff
changeset
|
619 continue |
268b39770c28
hgweb: extract web substitutions table generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26129
diff
changeset
|
620 |
268b39770c28
hgweb: extract web substitutions table generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26129
diff
changeset
|
621 # we need to unescape the delimiter for regexp and format |
268b39770c28
hgweb: extract web substitutions table generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26129
diff
changeset
|
622 delim_re = re.compile(r'(?<!\\)\\%s' % delim) |
268b39770c28
hgweb: extract web substitutions table generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26129
diff
changeset
|
623 regexp = delim_re.sub(unesc, match.group(1)) |
268b39770c28
hgweb: extract web substitutions table generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26129
diff
changeset
|
624 format = delim_re.sub(unesc, match.group(2)) |
268b39770c28
hgweb: extract web substitutions table generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26129
diff
changeset
|
625 |
268b39770c28
hgweb: extract web substitutions table generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26129
diff
changeset
|
626 # the pattern allows for 6 regexp flags, so set them if necessary |
268b39770c28
hgweb: extract web substitutions table generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26129
diff
changeset
|
627 flagin = match.group(3) |
268b39770c28
hgweb: extract web substitutions table generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26129
diff
changeset
|
628 flags = 0 |
268b39770c28
hgweb: extract web substitutions table generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26129
diff
changeset
|
629 if flagin: |
268b39770c28
hgweb: extract web substitutions table generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26129
diff
changeset
|
630 for flag in flagin.upper(): |
268b39770c28
hgweb: extract web substitutions table generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26129
diff
changeset
|
631 flags |= re.__dict__[flag] |
268b39770c28
hgweb: extract web substitutions table generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26129
diff
changeset
|
632 |
268b39770c28
hgweb: extract web substitutions table generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26129
diff
changeset
|
633 try: |
268b39770c28
hgweb: extract web substitutions table generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26129
diff
changeset
|
634 regexp = re.compile(regexp, flags) |
268b39770c28
hgweb: extract web substitutions table generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26129
diff
changeset
|
635 websubtable.append((regexp, format)) |
268b39770c28
hgweb: extract web substitutions table generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26129
diff
changeset
|
636 except re.error: |
268b39770c28
hgweb: extract web substitutions table generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26129
diff
changeset
|
637 repo.ui.warn(_("websub: invalid regexp for %s: %s\n") |
268b39770c28
hgweb: extract web substitutions table generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26129
diff
changeset
|
638 % (key, regexp)) |
268b39770c28
hgweb: extract web substitutions table generation to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26129
diff
changeset
|
639 return websubtable |