annotate mercurial/hgweb/webutil.py @ 24136:46d6cdfce4bf

hgweb: use introrev() for finding parents (issue4506) The issue is titled "filtered revision 'XXX' (not in 'served' subset)" and that is the error message you sometimes get when trying to look at a file (/file or /annotate) in hgweb. For example: http://hg.intevation.org/mercurial/crew/file/90cf454edd70/mercurial/cmdutil.py This happens when a parent revision for a file is hidden, thus it is not 'served' and isn't accessible in hgweb by default. When hgweb tries to access such changeset, it produces the error and HTTP status code 404. Another detail is that the parents() function, that is used in multiple places in hgweb, sometimes returned changesets that were obsoleted by the current changeset for the file. For example, when using rebase with evolve and rebasing a divergent changeset that introduces a file on top of current branch. Or grafting a change and making the new grafted changeset obsolete the source (shown in the test case). The result is the same - the obsoleted changeset was mistakingly returned from parents(), even though it's not a parent and the only link to the new changeset is an obsoletion marker (and rebase/graft metadata? not sure it matters). The problem is fixed by using introrev() instead of linkrev() for finding parents. This prevents parents() function from returning unrelated obsolete changesets. The test case prepares a separate repo because (afaict) all other test cases never reuse file names, so there are no files that were changed in multiple changesets. So no previously available files have obsolete changesets in their history.
author Anton Shestakov <engored@ya.ru>
date Thu, 19 Feb 2015 19:32:06 +0800
parents 513d47905114
children f53b7174facf
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
25e572394f5c Update license to GPLv2+
Matt Mackall <mpm@selenic.com>
parents: 9402
diff changeset
7 # GNU General Public License version 2 or any later version.
6392
2540521dc7c1 hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
8
17302
5c64ce6168da hgweb: fixes traceback for invalid files by removing top-level template
wujek srujek <wujek.srujek@googlemail.com>
parents: 17289
diff changeset
9 import os, copy
21122
50981ce36236 hgweb: show as same parents as "hg parents -r REV FILE" in pages for file
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20681
diff changeset
10 from mercurial import match, patch, error, ui, util, pathutil, context
14570
9f908ef5a595 web: provide diff summary to the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents: 14562
diff changeset
11 from mercurial.i18n import _
6392
2540521dc7c1 hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
12 from mercurial.node import hex, nullid
17289
f2d6b4f8e78c hgweb: avoid traceback when file or node parameters are missing
Ross Lagerwall <rosslagerwall@gmail.com>
parents: 17202
diff changeset
13 from common import ErrorResponse
f2d6b4f8e78c hgweb: avoid traceback when file or node parameters are missing
Ross Lagerwall <rosslagerwall@gmail.com>
parents: 17202
diff changeset
14 from common import HTTP_NOT_FOUND
17202
1ae119269ddc hgweb: side-by-side comparison functionality
wujek srujek
parents: 16719
diff changeset
15 import difflib
6392
2540521dc7c1 hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
16
6393
894875eae49b hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6392
diff changeset
17 def up(p):
894875eae49b hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6392
diff changeset
18 if p[0] != "/":
894875eae49b hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6392
diff changeset
19 p = "/" + p
894875eae49b hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6392
diff changeset
20 if p[-1] == "/":
894875eae49b hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6392
diff changeset
21 p = p[:-1]
894875eae49b hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6392
diff changeset
22 up = os.path.dirname(p)
894875eae49b hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6392
diff changeset
23 if up == "/":
894875eae49b hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6392
diff changeset
24 return "/"
894875eae49b hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6392
diff changeset
25 return up + "/"
894875eae49b hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6392
diff changeset
26
18391
833eb34e90e4 hgweb: better names for _navseq arguments
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18390
diff changeset
27 def _navseq(step, firststep=None):
833eb34e90e4 hgweb: better names for _navseq arguments
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18390
diff changeset
28 if firststep:
833eb34e90e4 hgweb: better names for _navseq arguments
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18390
diff changeset
29 yield firststep
833eb34e90e4 hgweb: better names for _navseq arguments
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18390
diff changeset
30 if firststep >= 20 and firststep <= 40:
18392
88a37b19dc0e hgweb: ensure _navseq yield strictly increasing numbers
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18391
diff changeset
31 firststep = 50
88a37b19dc0e hgweb: ensure _navseq yield strictly increasing numbers
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18391
diff changeset
32 yield firststep
88a37b19dc0e hgweb: ensure _navseq yield strictly increasing numbers
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18391
diff changeset
33 assert step > 0
88a37b19dc0e hgweb: ensure _navseq yield strictly increasing numbers
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18391
diff changeset
34 assert firststep > 0
88a37b19dc0e hgweb: ensure _navseq yield strictly increasing numbers
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18391
diff changeset
35 while step <= firststep:
88a37b19dc0e hgweb: ensure _navseq yield strictly increasing numbers
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18391
diff changeset
36 step *= 10
18390
28fa9443f751 hgweb: drop recursivity in _navseq
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18389
diff changeset
37 while True:
18391
833eb34e90e4 hgweb: better names for _navseq arguments
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18390
diff changeset
38 yield 1 * step
833eb34e90e4 hgweb: better names for _navseq arguments
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18390
diff changeset
39 yield 3 * step
833eb34e90e4 hgweb: better names for _navseq arguments
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18390
diff changeset
40 step *= 10
18389
82572533bc00 hgweb: move the `seq` function out of the revnavgen scope
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18388
diff changeset
41
18403
bfaee31a83d2 hgweb: move revnavgen into an object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18392
diff changeset
42 class revnav(object):
18320
60680d691a0b hgweb: document the revnavgen function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17991
diff changeset
43
18409
e3f5cef11d6a hgweb: pass repo object to revnav construction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18408
diff changeset
44 def __init__(self, repo):
18404
1da84a6b136a hgweb: pass nodefunc to the revnav object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18403
diff changeset
45 """Navigation generation object
1da84a6b136a hgweb: pass nodefunc to the revnav object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18403
diff changeset
46
18409
e3f5cef11d6a hgweb: pass repo object to revnav construction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18408
diff changeset
47 :repo: repo object we generate nav for
18404
1da84a6b136a hgweb: pass nodefunc to the revnav object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18403
diff changeset
48 """
18409
e3f5cef11d6a hgweb: pass repo object to revnav construction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18408
diff changeset
49 # used for hex generation
e3f5cef11d6a hgweb: pass repo object to revnav construction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18408
diff changeset
50 self._revlog = repo.changelog
18404
1da84a6b136a hgweb: pass nodefunc to the revnav object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18403
diff changeset
51
18406
20cf53932b6f hgweb: simplify the handling of empty repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18405
diff changeset
52 def __nonzero__(self):
20cf53932b6f hgweb: simplify the handling of empty repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18405
diff changeset
53 """return True if any revision to navigate over"""
19094
fc1b77db123f hgweb: handle filtered "0" rev in navigation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 19093
diff changeset
54 return self._first() is not None
fc1b77db123f hgweb: handle filtered "0" rev in navigation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 19093
diff changeset
55
fc1b77db123f hgweb: handle filtered "0" rev in navigation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 19093
diff changeset
56 def _first(self):
fc1b77db123f hgweb: handle filtered "0" rev in navigation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 19093
diff changeset
57 """return the minimum non-filtered changeset or None"""
fc1b77db123f hgweb: handle filtered "0" rev in navigation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 19093
diff changeset
58 try:
fc1b77db123f hgweb: handle filtered "0" rev in navigation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 19093
diff changeset
59 return iter(self._revlog).next()
fc1b77db123f hgweb: handle filtered "0" rev in navigation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 19093
diff changeset
60 except StopIteration:
fc1b77db123f hgweb: handle filtered "0" rev in navigation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 19093
diff changeset
61 return None
18406
20cf53932b6f hgweb: simplify the handling of empty repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18405
diff changeset
62
18405
1eaf0d017b2c hgweb: move hex creation into an object method
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18404
diff changeset
63 def hex(self, rev):
18409
e3f5cef11d6a hgweb: pass repo object to revnav construction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18408
diff changeset
64 return hex(self._revlog.node(rev))
18405
1eaf0d017b2c hgweb: move hex creation into an object method
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18404
diff changeset
65
18404
1da84a6b136a hgweb: pass nodefunc to the revnav object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18403
diff changeset
66 def gen(self, pos, pagelen, limit):
18403
bfaee31a83d2 hgweb: move revnavgen into an object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18392
diff changeset
67 """computes label and revision id for navigation link
18320
60680d691a0b hgweb: document the revnavgen function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17991
diff changeset
68
18403
bfaee31a83d2 hgweb: move revnavgen into an object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18392
diff changeset
69 :pos: is the revision relative to which we generate navigation.
bfaee31a83d2 hgweb: move revnavgen into an object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18392
diff changeset
70 :pagelen: the size of each navigation page
bfaee31a83d2 hgweb: move revnavgen into an object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18392
diff changeset
71 :limit: how far shall we link
6393
894875eae49b hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6392
diff changeset
72
18403
bfaee31a83d2 hgweb: move revnavgen into an object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18392
diff changeset
73 The return is:
bfaee31a83d2 hgweb: move revnavgen into an object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18392
diff changeset
74 - a single element tuple
bfaee31a83d2 hgweb: move revnavgen into an object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18392
diff changeset
75 - containing a dictionary with a `before` and `after` key
bfaee31a83d2 hgweb: move revnavgen into an object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18392
diff changeset
76 - values are generator functions taking arbitrary number of kwargs
bfaee31a83d2 hgweb: move revnavgen into an object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18392
diff changeset
77 - yield items are dictionaries with `label` and `node` keys
bfaee31a83d2 hgweb: move revnavgen into an object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18392
diff changeset
78 """
18406
20cf53932b6f hgweb: simplify the handling of empty repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18405
diff changeset
79 if not self:
20cf53932b6f hgweb: simplify the handling of empty repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18405
diff changeset
80 # empty repo
20cf53932b6f hgweb: simplify the handling of empty repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18405
diff changeset
81 return ({'before': (), 'after': ()},)
6393
894875eae49b hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6392
diff changeset
82
18425
6da1e979340a hgweb: generate revnav in two phase
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18409
diff changeset
83 targets = []
18403
bfaee31a83d2 hgweb: move revnavgen into an object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18392
diff changeset
84 for f in _navseq(1, pagelen):
bfaee31a83d2 hgweb: move revnavgen into an object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18392
diff changeset
85 if f > limit:
bfaee31a83d2 hgweb: move revnavgen into an object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18392
diff changeset
86 break
18425
6da1e979340a hgweb: generate revnav in two phase
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18409
diff changeset
87 targets.append(pos + f)
6da1e979340a hgweb: generate revnav in two phase
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18409
diff changeset
88 targets.append(pos - f)
6da1e979340a hgweb: generate revnav in two phase
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18409
diff changeset
89 targets.sort()
6da1e979340a hgweb: generate revnav in two phase
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18409
diff changeset
90
19094
fc1b77db123f hgweb: handle filtered "0" rev in navigation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 19093
diff changeset
91 first = self._first()
fc1b77db123f hgweb: handle filtered "0" rev in navigation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 19093
diff changeset
92 navbefore = [("(%i)" % first, self.hex(first))]
18425
6da1e979340a hgweb: generate revnav in two phase
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18409
diff changeset
93 navafter = []
6da1e979340a hgweb: generate revnav in two phase
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18409
diff changeset
94 for rev in targets:
18426
01638b51df44 hgweb: ignore filtered revision in revnav
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18425
diff changeset
95 if rev not in self._revlog:
01638b51df44 hgweb: ignore filtered revision in revnav
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18425
diff changeset
96 continue
18425
6da1e979340a hgweb: generate revnav in two phase
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18409
diff changeset
97 if pos < rev < limit:
18503
7f769d3a8ad2 hgweb: fix navigation label (issue3792)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18426
diff changeset
98 navafter.append(("+%d" % abs(rev - pos), self.hex(rev)))
18425
6da1e979340a hgweb: generate revnav in two phase
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18409
diff changeset
99 if 0 < rev < pos:
18503
7f769d3a8ad2 hgweb: fix navigation label (issue3792)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18426
diff changeset
100 navbefore.append(("-%d" % abs(rev - pos), self.hex(rev)))
18425
6da1e979340a hgweb: generate revnav in two phase
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18409
diff changeset
101
10254
8d5de52431f2 hgweb: changenav: separate pages before and after the current position
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 9402
diff changeset
102
18403
bfaee31a83d2 hgweb: move revnavgen into an object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18392
diff changeset
103 navafter.append(("tip", "tip"))
bfaee31a83d2 hgweb: move revnavgen into an object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18392
diff changeset
104
bfaee31a83d2 hgweb: move revnavgen into an object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18392
diff changeset
105 data = lambda i: {"label": i[0], "node": i[1]}
bfaee31a83d2 hgweb: move revnavgen into an object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18392
diff changeset
106 return ({'before': lambda **map: (data(i) for i in navbefore),
bfaee31a83d2 hgweb: move revnavgen into an object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18392
diff changeset
107 'after': lambda **map: (data(i) for i in navafter)},)
6393
894875eae49b hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6392
diff changeset
108
18408
f332a64fef51 hgweb: introduction a filerevnav subclass
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18407
diff changeset
109 class filerevnav(revnav):
18409
e3f5cef11d6a hgweb: pass repo object to revnav construction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18408
diff changeset
110
e3f5cef11d6a hgweb: pass repo object to revnav construction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18408
diff changeset
111 def __init__(self, repo, path):
e3f5cef11d6a hgweb: pass repo object to revnav construction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18408
diff changeset
112 """Navigation generation object
e3f5cef11d6a hgweb: pass repo object to revnav construction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18408
diff changeset
113
e3f5cef11d6a hgweb: pass repo object to revnav construction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18408
diff changeset
114 :repo: repo object we generate nav for
e3f5cef11d6a hgweb: pass repo object to revnav construction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18408
diff changeset
115 :path: path of the file we generate nav for
e3f5cef11d6a hgweb: pass repo object to revnav construction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18408
diff changeset
116 """
e3f5cef11d6a hgweb: pass repo object to revnav construction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18408
diff changeset
117 # used for iteration
e3f5cef11d6a hgweb: pass repo object to revnav construction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18408
diff changeset
118 self._changelog = repo.unfiltered().changelog
e3f5cef11d6a hgweb: pass repo object to revnav construction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18408
diff changeset
119 # used for hex generation
e3f5cef11d6a hgweb: pass repo object to revnav construction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18408
diff changeset
120 self._revlog = repo.file(path)
e3f5cef11d6a hgweb: pass repo object to revnav construction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18408
diff changeset
121
e3f5cef11d6a hgweb: pass repo object to revnav construction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18408
diff changeset
122 def hex(self, rev):
e3f5cef11d6a hgweb: pass repo object to revnav construction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18408
diff changeset
123 return hex(self._changelog.node(self._revlog.linkrev(rev)))
e3f5cef11d6a hgweb: pass repo object to revnav construction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18408
diff changeset
124
18408
f332a64fef51 hgweb: introduction a filerevnav subclass
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18407
diff changeset
125
7671
06cf09c822c4 hgweb: simplify parents/children generation code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7637
diff changeset
126 def _siblings(siblings=[], hiderev=None):
6392
2540521dc7c1 hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
127 siblings = [s for s in siblings if s.node() != nullid]
2540521dc7c1 hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
128 if len(siblings) == 1 and siblings[0].rev() == hiderev:
2540521dc7c1 hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
129 return
2540521dc7c1 hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
130 for s in siblings:
14055
421d56a055fd drop {short,hex}(ctx.node()) calls in favor of ctx methods
Alexander Solovyov <alexander@solovyov.net>
parents: 13971
diff changeset
131 d = {'node': s.hex(), 'rev': s.rev()}
7294
f933076a19fc hgweb: pass more information about parent/child csets to templates
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6750
diff changeset
132 d['user'] = s.user()
f933076a19fc hgweb: pass more information about parent/child csets to templates
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6750
diff changeset
133 d['date'] = s.date()
f933076a19fc hgweb: pass more information about parent/child csets to templates
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6750
diff changeset
134 d['description'] = s.description()
7717
f9ba30cb7ee4 hgweb: expose sibling branches to templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7671
diff changeset
135 d['branch'] = s.branch()
14957
16e5271b216f hgweb: move remaining hasattr calls to safehasattr
Augie Fackler <durin42@gmail.com>
parents: 14570
diff changeset
136 if util.safehasattr(s, 'path'):
6392
2540521dc7c1 hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
137 d['file'] = s.path()
2540521dc7c1 hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
138 yield d
2540521dc7c1 hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
139
7671
06cf09c822c4 hgweb: simplify parents/children generation code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7637
diff changeset
140 def parents(ctx, hide=None):
24136
46d6cdfce4bf hgweb: use introrev() for finding parents (issue4506)
Anton Shestakov <engored@ya.ru>
parents: 23745
diff changeset
141 if isinstance(ctx, context.basefilectx):
46d6cdfce4bf hgweb: use introrev() for finding parents (issue4506)
Anton Shestakov <engored@ya.ru>
parents: 23745
diff changeset
142 introrev = ctx.introrev()
46d6cdfce4bf hgweb: use introrev() for finding parents (issue4506)
Anton Shestakov <engored@ya.ru>
parents: 23745
diff changeset
143 if ctx.changectx().rev() != introrev:
46d6cdfce4bf hgweb: use introrev() for finding parents (issue4506)
Anton Shestakov <engored@ya.ru>
parents: 23745
diff changeset
144 return _siblings([ctx._repo[introrev]], hide)
7671
06cf09c822c4 hgweb: simplify parents/children generation code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7637
diff changeset
145 return _siblings(ctx.parents(), hide)
06cf09c822c4 hgweb: simplify parents/children generation code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7637
diff changeset
146
06cf09c822c4 hgweb: simplify parents/children generation code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7637
diff changeset
147 def children(ctx, hide=None):
06cf09c822c4 hgweb: simplify parents/children generation code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7637
diff changeset
148 return _siblings(ctx.children(), hide)
06cf09c822c4 hgweb: simplify parents/children generation code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7637
diff changeset
149
6434
62e0bb41e682 hgweb: minor improvements for new web style
Matt Mackall <mpm@selenic.com>
parents: 6413
diff changeset
150 def renamelink(fctx):
6437
101526031d06 hgweb: fix merge breakage
Matt Mackall <mpm@selenic.com>
parents: 6434
diff changeset
151 r = fctx.renamed()
6392
2540521dc7c1 hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
152 if r:
20681
52e5aca15f0c webutil: move from dict() construction to {} literals
Augie Fackler <raf@durin42.com>
parents: 20033
diff changeset
153 return [{'file': r[0], 'node': hex(r[1])}]
6392
2540521dc7c1 hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
154 return []
2540521dc7c1 hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
155
2540521dc7c1 hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
156 def nodetagsdict(repo, node):
2540521dc7c1 hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
157 return [{"name": i} for i in repo.nodetags(node)]
2540521dc7c1 hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
158
13596
270f57d35525 hgweb: add display of bookmarks for changelog and changeset
Alexander Solovyov <alexander@solovyov.net>
parents: 12691
diff changeset
159 def nodebookmarksdict(repo, node):
270f57d35525 hgweb: add display of bookmarks for changelog and changeset
Alexander Solovyov <alexander@solovyov.net>
parents: 12691
diff changeset
160 return [{"name": i} for i in repo.nodebookmarks(node)]
270f57d35525 hgweb: add display of bookmarks for changelog and changeset
Alexander Solovyov <alexander@solovyov.net>
parents: 12691
diff changeset
161
6392
2540521dc7c1 hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
162 def nodebranchdict(repo, ctx):
2540521dc7c1 hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
163 branches = []
2540521dc7c1 hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
164 branch = ctx.branch()
2540521dc7c1 hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
165 # If this is an empty repo, ctx.node() == nullid,
16719
e7bf09acd410 localrepo: add branchtip() method for faster single-branch lookups
Brodie Rao <brodie@sf.io>
parents: 16308
diff changeset
166 # ctx.branch() == 'default'.
e7bf09acd410 localrepo: add branchtip() method for faster single-branch lookups
Brodie Rao <brodie@sf.io>
parents: 16308
diff changeset
167 try:
e7bf09acd410 localrepo: add branchtip() method for faster single-branch lookups
Brodie Rao <brodie@sf.io>
parents: 16308
diff changeset
168 branchnode = repo.branchtip(branch)
e7bf09acd410 localrepo: add branchtip() method for faster single-branch lookups
Brodie Rao <brodie@sf.io>
parents: 16308
diff changeset
169 except error.RepoLookupError:
e7bf09acd410 localrepo: add branchtip() method for faster single-branch lookups
Brodie Rao <brodie@sf.io>
parents: 16308
diff changeset
170 branchnode = None
e7bf09acd410 localrepo: add branchtip() method for faster single-branch lookups
Brodie Rao <brodie@sf.io>
parents: 16308
diff changeset
171 if branchnode == ctx.node():
6392
2540521dc7c1 hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
172 branches.append({"name": branch})
2540521dc7c1 hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
173 return branches
2540521dc7c1 hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
174
2540521dc7c1 hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
175 def nodeinbranch(repo, ctx):
2540521dc7c1 hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
176 branches = []
2540521dc7c1 hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
177 branch = ctx.branch()
16719
e7bf09acd410 localrepo: add branchtip() method for faster single-branch lookups
Brodie Rao <brodie@sf.io>
parents: 16308
diff changeset
178 try:
e7bf09acd410 localrepo: add branchtip() method for faster single-branch lookups
Brodie Rao <brodie@sf.io>
parents: 16308
diff changeset
179 branchnode = repo.branchtip(branch)
e7bf09acd410 localrepo: add branchtip() method for faster single-branch lookups
Brodie Rao <brodie@sf.io>
parents: 16308
diff changeset
180 except error.RepoLookupError:
e7bf09acd410 localrepo: add branchtip() method for faster single-branch lookups
Brodie Rao <brodie@sf.io>
parents: 16308
diff changeset
181 branchnode = None
e7bf09acd410 localrepo: add branchtip() method for faster single-branch lookups
Brodie Rao <brodie@sf.io>
parents: 16308
diff changeset
182 if branch != 'default' and branchnode != ctx.node():
6392
2540521dc7c1 hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
183 branches.append({"name": branch})
2540521dc7c1 hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
184 return branches
2540521dc7c1 hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
185
2540521dc7c1 hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
186 def nodebranchnodefault(ctx):
2540521dc7c1 hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
187 branches = []
2540521dc7c1 hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
188 branch = ctx.branch()
2540521dc7c1 hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
189 if branch != 'default':
2540521dc7c1 hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
190 branches.append({"name": branch})
2540521dc7c1 hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
191 return branches
2540521dc7c1 hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
192
2540521dc7c1 hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
193 def showtag(repo, tmpl, t1, node=nullid, **args):
2540521dc7c1 hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
194 for t in repo.nodetags(node):
2540521dc7c1 hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
195 yield tmpl(t1, tag=t, **args)
2540521dc7c1 hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
196
13596
270f57d35525 hgweb: add display of bookmarks for changelog and changeset
Alexander Solovyov <alexander@solovyov.net>
parents: 12691
diff changeset
197 def showbookmark(repo, tmpl, t1, node=nullid, **args):
270f57d35525 hgweb: add display of bookmarks for changelog and changeset
Alexander Solovyov <alexander@solovyov.net>
parents: 12691
diff changeset
198 for t in repo.nodebookmarks(node):
270f57d35525 hgweb: add display of bookmarks for changelog and changeset
Alexander Solovyov <alexander@solovyov.net>
parents: 12691
diff changeset
199 yield tmpl(t1, bookmark=t, **args)
270f57d35525 hgweb: add display of bookmarks for changelog and changeset
Alexander Solovyov <alexander@solovyov.net>
parents: 12691
diff changeset
200
6392
2540521dc7c1 hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
201 def cleanpath(repo, path):
2540521dc7c1 hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
202 path = path.lstrip('/')
20033
f962870712da pathutil: tease out a new library to break an import cycle from canonpath use
Augie Fackler <raf@durin42.com>
parents: 19094
diff changeset
203 return pathutil.canonpath(repo.root, '', path)
6392
2540521dc7c1 hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
204
17991
d605a82cf189 hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents: 17302
diff changeset
205 def changeidctx (repo, changeid):
6392
2540521dc7c1 hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
206 try:
6747
f6c00b17387c use repo[changeid] to get a changectx
Matt Mackall <mpm@selenic.com>
parents: 6437
diff changeset
207 ctx = repo[changeid]
7637
1d54e2f6c0b7 error: move repo errors
Matt Mackall <mpm@selenic.com>
parents: 7361
diff changeset
208 except error.RepoError:
6392
2540521dc7c1 hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
209 man = repo.manifest
7361
9fe97eea5510 linkrev: take a revision number rather than a hash
Matt Mackall <mpm@selenic.com>
parents: 7345
diff changeset
210 ctx = repo[man.linkrev(man.rev(man.lookup(changeid)))]
6392
2540521dc7c1 hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
211
2540521dc7c1 hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
212 return ctx
2540521dc7c1 hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
213
17991
d605a82cf189 hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents: 17302
diff changeset
214 def changectx (repo, req):
d605a82cf189 hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents: 17302
diff changeset
215 changeid = "tip"
d605a82cf189 hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents: 17302
diff changeset
216 if 'node' in req.form:
d605a82cf189 hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents: 17302
diff changeset
217 changeid = req.form['node'][0]
d605a82cf189 hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents: 17302
diff changeset
218 ipos=changeid.find(':')
d605a82cf189 hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents: 17302
diff changeset
219 if ipos != -1:
d605a82cf189 hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents: 17302
diff changeset
220 changeid = changeid[(ipos + 1):]
d605a82cf189 hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents: 17302
diff changeset
221 elif 'manifest' in req.form:
d605a82cf189 hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents: 17302
diff changeset
222 changeid = req.form['manifest'][0]
d605a82cf189 hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents: 17302
diff changeset
223
d605a82cf189 hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents: 17302
diff changeset
224 return changeidctx(repo, changeid)
d605a82cf189 hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents: 17302
diff changeset
225
d605a82cf189 hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents: 17302
diff changeset
226 def basechangectx(repo, req):
d605a82cf189 hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents: 17302
diff changeset
227 if 'node' in req.form:
d605a82cf189 hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents: 17302
diff changeset
228 changeid = req.form['node'][0]
d605a82cf189 hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents: 17302
diff changeset
229 ipos=changeid.find(':')
d605a82cf189 hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents: 17302
diff changeset
230 if ipos != -1:
d605a82cf189 hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents: 17302
diff changeset
231 changeid = changeid[:ipos]
d605a82cf189 hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents: 17302
diff changeset
232 return changeidctx(repo, changeid)
d605a82cf189 hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents: 17302
diff changeset
233
d605a82cf189 hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents: 17302
diff changeset
234 return None
d605a82cf189 hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents: 17302
diff changeset
235
6392
2540521dc7c1 hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
236 def filectx(repo, req):
17289
f2d6b4f8e78c hgweb: avoid traceback when file or node parameters are missing
Ross Lagerwall <rosslagerwall@gmail.com>
parents: 17202
diff changeset
237 if 'file' not in req.form:
f2d6b4f8e78c hgweb: avoid traceback when file or node parameters are missing
Ross Lagerwall <rosslagerwall@gmail.com>
parents: 17202
diff changeset
238 raise ErrorResponse(HTTP_NOT_FOUND, 'file not given')
6392
2540521dc7c1 hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
239 path = cleanpath(repo, req.form['file'][0])
2540521dc7c1 hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
240 if 'node' in req.form:
2540521dc7c1 hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
241 changeid = req.form['node'][0]
17289
f2d6b4f8e78c hgweb: avoid traceback when file or node parameters are missing
Ross Lagerwall <rosslagerwall@gmail.com>
parents: 17202
diff changeset
242 elif 'filenode' in req.form:
f2d6b4f8e78c hgweb: avoid traceback when file or node parameters are missing
Ross Lagerwall <rosslagerwall@gmail.com>
parents: 17202
diff changeset
243 changeid = req.form['filenode'][0]
6392
2540521dc7c1 hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
244 else:
17289
f2d6b4f8e78c hgweb: avoid traceback when file or node parameters are missing
Ross Lagerwall <rosslagerwall@gmail.com>
parents: 17202
diff changeset
245 raise ErrorResponse(HTTP_NOT_FOUND, 'node or filenode not given')
6392
2540521dc7c1 hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
246 try:
6747
f6c00b17387c use repo[changeid] to get a changectx
Matt Mackall <mpm@selenic.com>
parents: 6437
diff changeset
247 fctx = repo[changeid][path]
7637
1d54e2f6c0b7 error: move repo errors
Matt Mackall <mpm@selenic.com>
parents: 7361
diff changeset
248 except error.RepoError:
6392
2540521dc7c1 hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
249 fctx = repo.filectx(path, fileid=changeid)
2540521dc7c1 hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
250
2540521dc7c1 hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
251 return fctx
7310
bd522d09d5e3 hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7294
diff changeset
252
23745
513d47905114 hgweb: extract changelist entry generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21122
diff changeset
253 def changelistentry(web, ctx, tmpl):
513d47905114 hgweb: extract changelist entry generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21122
diff changeset
254 '''Obtain a dictionary to be used for entries in a changelist.
513d47905114 hgweb: extract changelist entry generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21122
diff changeset
255
513d47905114 hgweb: extract changelist entry generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21122
diff changeset
256 This function is called when producing items for the "entries" list passed
513d47905114 hgweb: extract changelist entry generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21122
diff changeset
257 to the "shortlog" and "changelog" templates.
513d47905114 hgweb: extract changelist entry generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21122
diff changeset
258 '''
513d47905114 hgweb: extract changelist entry generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21122
diff changeset
259 repo = web.repo
513d47905114 hgweb: extract changelist entry generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21122
diff changeset
260 rev = ctx.rev()
513d47905114 hgweb: extract changelist entry generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21122
diff changeset
261 n = ctx.node()
513d47905114 hgweb: extract changelist entry generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21122
diff changeset
262 showtags = showtag(repo, tmpl, 'changelogtag', n)
513d47905114 hgweb: extract changelist entry generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21122
diff changeset
263 files = listfilediffs(tmpl, ctx.files(), n, web.maxfiles)
513d47905114 hgweb: extract changelist entry generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21122
diff changeset
264
513d47905114 hgweb: extract changelist entry generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21122
diff changeset
265 return {
513d47905114 hgweb: extract changelist entry generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21122
diff changeset
266 "author": ctx.user(),
513d47905114 hgweb: extract changelist entry generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21122
diff changeset
267 "parent": parents(ctx, rev - 1),
513d47905114 hgweb: extract changelist entry generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21122
diff changeset
268 "child": children(ctx, rev + 1),
513d47905114 hgweb: extract changelist entry generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21122
diff changeset
269 "changelogtag": showtags,
513d47905114 hgweb: extract changelist entry generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21122
diff changeset
270 "desc": ctx.description(),
513d47905114 hgweb: extract changelist entry generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21122
diff changeset
271 "extra": ctx.extra(),
513d47905114 hgweb: extract changelist entry generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21122
diff changeset
272 "date": ctx.date(),
513d47905114 hgweb: extract changelist entry generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21122
diff changeset
273 "files": files,
513d47905114 hgweb: extract changelist entry generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21122
diff changeset
274 "rev": rev,
513d47905114 hgweb: extract changelist entry generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21122
diff changeset
275 "node": hex(n),
513d47905114 hgweb: extract changelist entry generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21122
diff changeset
276 "tags": nodetagsdict(repo, n),
513d47905114 hgweb: extract changelist entry generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21122
diff changeset
277 "bookmarks": nodebookmarksdict(repo, n),
513d47905114 hgweb: extract changelist entry generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21122
diff changeset
278 "inbranch": nodeinbranch(repo, ctx),
513d47905114 hgweb: extract changelist entry generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21122
diff changeset
279 "branches": nodebranchdict(repo, ctx)
513d47905114 hgweb: extract changelist entry generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21122
diff changeset
280 }
513d47905114 hgweb: extract changelist entry generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21122
diff changeset
281
7311
de9c87fe1620 hgweb: move another utility function into the webutil module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7310
diff changeset
282 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
283 for f in files[:max]:
de9c87fe1620 hgweb: move another utility function into the webutil module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7310
diff changeset
284 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
285 if len(files) > max:
de9c87fe1620 hgweb: move another utility function into the webutil module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7310
diff changeset
286 yield tmpl('fileellipses')
de9c87fe1620 hgweb: move another utility function into the webutil module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7310
diff changeset
287
17991
d605a82cf189 hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents: 17302
diff changeset
288 def diffs(repo, tmpl, ctx, basectx, files, parity, style):
7310
bd522d09d5e3 hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7294
diff changeset
289
bd522d09d5e3 hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7294
diff changeset
290 def countgen():
bd522d09d5e3 hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7294
diff changeset
291 start = 1
bd522d09d5e3 hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7294
diff changeset
292 while True:
bd522d09d5e3 hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7294
diff changeset
293 yield start
bd522d09d5e3 hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7294
diff changeset
294 start += 1
bd522d09d5e3 hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7294
diff changeset
295
bd522d09d5e3 hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7294
diff changeset
296 blockcount = countgen()
16308
2695aaf4eb72 hgweb: add block numbers to diff regions and related links
Paul Boddie <paul@boddie.org.uk>
parents: 14957
diff changeset
297 def prettyprintlines(diff, blockno):
7310
bd522d09d5e3 hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7294
diff changeset
298 for lineno, l in enumerate(diff.splitlines(True)):
bd522d09d5e3 hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7294
diff changeset
299 lineno = "%d.%d" % (blockno, lineno + 1)
bd522d09d5e3 hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7294
diff changeset
300 if l.startswith('+'):
bd522d09d5e3 hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7294
diff changeset
301 ltype = "difflineplus"
bd522d09d5e3 hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7294
diff changeset
302 elif l.startswith('-'):
bd522d09d5e3 hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7294
diff changeset
303 ltype = "difflineminus"
bd522d09d5e3 hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7294
diff changeset
304 elif l.startswith('@'):
bd522d09d5e3 hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7294
diff changeset
305 ltype = "difflineat"
bd522d09d5e3 hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7294
diff changeset
306 else:
bd522d09d5e3 hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7294
diff changeset
307 ltype = "diffline"
bd522d09d5e3 hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7294
diff changeset
308 yield tmpl(ltype,
bd522d09d5e3 hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7294
diff changeset
309 line=l,
bd522d09d5e3 hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7294
diff changeset
310 lineid="l%s" % lineno,
bd522d09d5e3 hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7294
diff changeset
311 linenumber="% 8s" % lineno)
bd522d09d5e3 hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7294
diff changeset
312
bd522d09d5e3 hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7294
diff changeset
313 if files:
bd522d09d5e3 hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7294
diff changeset
314 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
315 else:
bd522d09d5e3 hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7294
diff changeset
316 m = match.always(repo.root, repo.getcwd())
bd522d09d5e3 hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7294
diff changeset
317
bd522d09d5e3 hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7294
diff changeset
318 diffopts = patch.diffopts(repo.ui, untrusted=True)
17991
d605a82cf189 hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents: 17302
diff changeset
319 if basectx is None:
d605a82cf189 hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents: 17302
diff changeset
320 parents = ctx.parents()
d605a82cf189 hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents: 17302
diff changeset
321 node1 = parents and parents[0].node() or nullid
d605a82cf189 hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents: 17302
diff changeset
322 else:
d605a82cf189 hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents: 17302
diff changeset
323 node1 = basectx.node()
7310
bd522d09d5e3 hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7294
diff changeset
324 node2 = ctx.node()
bd522d09d5e3 hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7294
diff changeset
325
bd522d09d5e3 hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7294
diff changeset
326 block = []
bd522d09d5e3 hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7294
diff changeset
327 for chunk in patch.diff(repo, node1, node2, m, opts=diffopts):
bd522d09d5e3 hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7294
diff changeset
328 if chunk.startswith('diff') and block:
16308
2695aaf4eb72 hgweb: add block numbers to diff regions and related links
Paul Boddie <paul@boddie.org.uk>
parents: 14957
diff changeset
329 blockno = blockcount.next()
2695aaf4eb72 hgweb: add block numbers to diff regions and related links
Paul Boddie <paul@boddie.org.uk>
parents: 14957
diff changeset
330 yield tmpl('diffblock', parity=parity.next(), blockno=blockno,
2695aaf4eb72 hgweb: add block numbers to diff regions and related links
Paul Boddie <paul@boddie.org.uk>
parents: 14957
diff changeset
331 lines=prettyprintlines(''.join(block), blockno))
7310
bd522d09d5e3 hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7294
diff changeset
332 block = []
9402
5d49fdef6fd0 hgweb: show diff header line in raw diffs
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 8225
diff changeset
333 if chunk.startswith('diff') and style != 'raw':
7310
bd522d09d5e3 hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7294
diff changeset
334 chunk = ''.join(chunk.splitlines(True)[1:])
bd522d09d5e3 hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7294
diff changeset
335 block.append(chunk)
16308
2695aaf4eb72 hgweb: add block numbers to diff regions and related links
Paul Boddie <paul@boddie.org.uk>
parents: 14957
diff changeset
336 blockno = blockcount.next()
2695aaf4eb72 hgweb: add block numbers to diff regions and related links
Paul Boddie <paul@boddie.org.uk>
parents: 14957
diff changeset
337 yield tmpl('diffblock', parity=parity.next(), blockno=blockno,
2695aaf4eb72 hgweb: add block numbers to diff regions and related links
Paul Boddie <paul@boddie.org.uk>
parents: 14957
diff changeset
338 lines=prettyprintlines(''.join(block), blockno))
7345
55651328dfcc hgweb: fix up the less/more links on the graph page
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7311
diff changeset
339
17302
5c64ce6168da hgweb: fixes traceback for invalid files by removing top-level template
wujek srujek <wujek.srujek@googlemail.com>
parents: 17289
diff changeset
340 def compare(tmpl, context, leftlines, rightlines):
17202
1ae119269ddc hgweb: side-by-side comparison functionality
wujek srujek
parents: 16719
diff changeset
341 '''Generator function that provides side-by-side comparison data.'''
1ae119269ddc hgweb: side-by-side comparison functionality
wujek srujek
parents: 16719
diff changeset
342
1ae119269ddc hgweb: side-by-side comparison functionality
wujek srujek
parents: 16719
diff changeset
343 def compline(type, leftlineno, leftline, rightlineno, rightline):
1ae119269ddc hgweb: side-by-side comparison functionality
wujek srujek
parents: 16719
diff changeset
344 lineid = leftlineno and ("l%s" % leftlineno) or ''
1ae119269ddc hgweb: side-by-side comparison functionality
wujek srujek
parents: 16719
diff changeset
345 lineid += rightlineno and ("r%s" % rightlineno) or ''
1ae119269ddc hgweb: side-by-side comparison functionality
wujek srujek
parents: 16719
diff changeset
346 return tmpl('comparisonline',
1ae119269ddc hgweb: side-by-side comparison functionality
wujek srujek
parents: 16719
diff changeset
347 type=type,
1ae119269ddc hgweb: side-by-side comparison functionality
wujek srujek
parents: 16719
diff changeset
348 lineid=lineid,
1ae119269ddc hgweb: side-by-side comparison functionality
wujek srujek
parents: 16719
diff changeset
349 leftlinenumber="% 6s" % (leftlineno or ''),
1ae119269ddc hgweb: side-by-side comparison functionality
wujek srujek
parents: 16719
diff changeset
350 leftline=leftline or '',
1ae119269ddc hgweb: side-by-side comparison functionality
wujek srujek
parents: 16719
diff changeset
351 rightlinenumber="% 6s" % (rightlineno or ''),
1ae119269ddc hgweb: side-by-side comparison functionality
wujek srujek
parents: 16719
diff changeset
352 rightline=rightline or '')
1ae119269ddc hgweb: side-by-side comparison functionality
wujek srujek
parents: 16719
diff changeset
353
1ae119269ddc hgweb: side-by-side comparison functionality
wujek srujek
parents: 16719
diff changeset
354 def getblock(opcodes):
1ae119269ddc hgweb: side-by-side comparison functionality
wujek srujek
parents: 16719
diff changeset
355 for type, llo, lhi, rlo, rhi in opcodes:
1ae119269ddc hgweb: side-by-side comparison functionality
wujek srujek
parents: 16719
diff changeset
356 len1 = lhi - llo
1ae119269ddc hgweb: side-by-side comparison functionality
wujek srujek
parents: 16719
diff changeset
357 len2 = rhi - rlo
1ae119269ddc hgweb: side-by-side comparison functionality
wujek srujek
parents: 16719
diff changeset
358 count = min(len1, len2)
1ae119269ddc hgweb: side-by-side comparison functionality
wujek srujek
parents: 16719
diff changeset
359 for i in xrange(count):
1ae119269ddc hgweb: side-by-side comparison functionality
wujek srujek
parents: 16719
diff changeset
360 yield compline(type=type,
1ae119269ddc hgweb: side-by-side comparison functionality
wujek srujek
parents: 16719
diff changeset
361 leftlineno=llo + i + 1,
1ae119269ddc hgweb: side-by-side comparison functionality
wujek srujek
parents: 16719
diff changeset
362 leftline=leftlines[llo + i],
1ae119269ddc hgweb: side-by-side comparison functionality
wujek srujek
parents: 16719
diff changeset
363 rightlineno=rlo + i + 1,
1ae119269ddc hgweb: side-by-side comparison functionality
wujek srujek
parents: 16719
diff changeset
364 rightline=rightlines[rlo + i])
1ae119269ddc hgweb: side-by-side comparison functionality
wujek srujek
parents: 16719
diff changeset
365 if len1 > len2:
1ae119269ddc hgweb: side-by-side comparison functionality
wujek srujek
parents: 16719
diff changeset
366 for i in xrange(llo + count, lhi):
1ae119269ddc hgweb: side-by-side comparison functionality
wujek srujek
parents: 16719
diff changeset
367 yield compline(type=type,
1ae119269ddc hgweb: side-by-side comparison functionality
wujek srujek
parents: 16719
diff changeset
368 leftlineno=i + 1,
1ae119269ddc hgweb: side-by-side comparison functionality
wujek srujek
parents: 16719
diff changeset
369 leftline=leftlines[i],
1ae119269ddc hgweb: side-by-side comparison functionality
wujek srujek
parents: 16719
diff changeset
370 rightlineno=None,
1ae119269ddc hgweb: side-by-side comparison functionality
wujek srujek
parents: 16719
diff changeset
371 rightline=None)
1ae119269ddc hgweb: side-by-side comparison functionality
wujek srujek
parents: 16719
diff changeset
372 elif len2 > len1:
1ae119269ddc hgweb: side-by-side comparison functionality
wujek srujek
parents: 16719
diff changeset
373 for i in xrange(rlo + count, rhi):
1ae119269ddc hgweb: side-by-side comparison functionality
wujek srujek
parents: 16719
diff changeset
374 yield compline(type=type,
1ae119269ddc hgweb: side-by-side comparison functionality
wujek srujek
parents: 16719
diff changeset
375 leftlineno=None,
1ae119269ddc hgweb: side-by-side comparison functionality
wujek srujek
parents: 16719
diff changeset
376 leftline=None,
1ae119269ddc hgweb: side-by-side comparison functionality
wujek srujek
parents: 16719
diff changeset
377 rightlineno=i + 1,
1ae119269ddc hgweb: side-by-side comparison functionality
wujek srujek
parents: 16719
diff changeset
378 rightline=rightlines[i])
1ae119269ddc hgweb: side-by-side comparison functionality
wujek srujek
parents: 16719
diff changeset
379
1ae119269ddc hgweb: side-by-side comparison functionality
wujek srujek
parents: 16719
diff changeset
380 s = difflib.SequenceMatcher(None, leftlines, rightlines)
1ae119269ddc hgweb: side-by-side comparison functionality
wujek srujek
parents: 16719
diff changeset
381 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
382 yield tmpl('comparisonblock', lines=getblock(s.get_opcodes()))
17202
1ae119269ddc hgweb: side-by-side comparison functionality
wujek srujek
parents: 16719
diff changeset
383 else:
17302
5c64ce6168da hgweb: fixes traceback for invalid files by removing top-level template
wujek srujek <wujek.srujek@googlemail.com>
parents: 17289
diff changeset
384 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
385 yield tmpl('comparisonblock', lines=getblock(oc))
17202
1ae119269ddc hgweb: side-by-side comparison functionality
wujek srujek
parents: 16719
diff changeset
386
17991
d605a82cf189 hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents: 17302
diff changeset
387 def diffstatgen(ctx, basectx):
14570
9f908ef5a595 web: provide diff summary to the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents: 14562
diff changeset
388 '''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
389
17991
d605a82cf189 hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents: 17302
diff changeset
390 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
391 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
392 while True:
9f908ef5a595 web: provide diff summary to the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents: 14562
diff changeset
393 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
394
9f908ef5a595 web: provide diff summary to the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents: 14562
diff changeset
395 def diffsummary(statgen):
9f908ef5a595 web: provide diff summary to the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents: 14562
diff changeset
396 '''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
397
9f908ef5a595 web: provide diff summary to the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents: 14562
diff changeset
398 stats, maxname, maxtotal, addtotal, removetotal, binary = statgen.next()
9f908ef5a595 web: provide diff summary to the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents: 14562
diff changeset
399 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
400 len(stats), addtotal, removetotal)
9f908ef5a595 web: provide diff summary to the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents: 14562
diff changeset
401
9f908ef5a595 web: provide diff summary to the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents: 14562
diff changeset
402 def diffstat(tmpl, ctx, statgen, parity):
9f908ef5a595 web: provide diff summary to the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents: 14562
diff changeset
403 '''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
404
9f908ef5a595 web: provide diff summary to the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents: 14562
diff changeset
405 stats, maxname, maxtotal, addtotal, removetotal, binary = statgen.next()
14561
925d9f2b188b web: include all files in the diffstat
Steven Brown <StevenGBrown@gmail.com>
parents: 14490
diff changeset
406 files = ctx.files()
14490
1d3e2349304a web: provide diffstat to the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents: 14055
diff changeset
407
14561
925d9f2b188b web: include all files in the diffstat
Steven Brown <StevenGBrown@gmail.com>
parents: 14490
diff changeset
408 def pct(i):
925d9f2b188b web: include all files in the diffstat
Steven Brown <StevenGBrown@gmail.com>
parents: 14490
diff changeset
409 if maxtotal == 0:
925d9f2b188b web: include all files in the diffstat
Steven Brown <StevenGBrown@gmail.com>
parents: 14490
diff changeset
410 return 0
925d9f2b188b web: include all files in the diffstat
Steven Brown <StevenGBrown@gmail.com>
parents: 14490
diff changeset
411 return (float(i) / maxtotal) * 100
14490
1d3e2349304a web: provide diffstat to the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents: 14055
diff changeset
412
14562
fccd3b966da7 web: provide the file number to the diffstat templates
Steven Brown <StevenGBrown@gmail.com>
parents: 14561
diff changeset
413 fileno = 0
14561
925d9f2b188b web: include all files in the diffstat
Steven Brown <StevenGBrown@gmail.com>
parents: 14490
diff changeset
414 for filename, adds, removes, isbinary in stats:
925d9f2b188b web: include all files in the diffstat
Steven Brown <StevenGBrown@gmail.com>
parents: 14490
diff changeset
415 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
416 total = adds + removes
14562
fccd3b966da7 web: provide the file number to the diffstat templates
Steven Brown <StevenGBrown@gmail.com>
parents: 14561
diff changeset
417 fileno += 1
fccd3b966da7 web: provide the file number to the diffstat templates
Steven Brown <StevenGBrown@gmail.com>
parents: 14561
diff changeset
418 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
419 total=total, addpct=pct(adds), removepct=pct(removes),
925d9f2b188b web: include all files in the diffstat
Steven Brown <StevenGBrown@gmail.com>
parents: 14490
diff changeset
420 parity=parity.next())
14490
1d3e2349304a web: provide diffstat to the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents: 14055
diff changeset
421
7345
55651328dfcc hgweb: fix up the less/more links on the graph page
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7311
diff changeset
422 class sessionvars(object):
55651328dfcc hgweb: fix up the less/more links on the graph page
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7311
diff changeset
423 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
424 self.start = start
55651328dfcc hgweb: fix up the less/more links on the graph page
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7311
diff changeset
425 self.vars = vars
55651328dfcc hgweb: fix up the less/more links on the graph page
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7311
diff changeset
426 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
427 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
428 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
429 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
430 def __copy__(self):
55651328dfcc hgweb: fix up the less/more links on the graph page
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7311
diff changeset
431 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
432 def __iter__(self):
55651328dfcc hgweb: fix up the less/more links on the graph page
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7311
diff changeset
433 separator = self.start
18367
ae7215f4f7b9 hgweb: generate query strings with parameters sorted by key
Mads Kiilerich <mads@kiilerich.com>
parents: 18320
diff changeset
434 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
435 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
436 separator = '&'
12691
1b1a9038a71a hgweb: fix hgweb_mod as well as hgwebdir_mod
Augie Fackler <durin42@gmail.com>
parents: 10282
diff changeset
437
1b1a9038a71a hgweb: fix hgweb_mod as well as hgwebdir_mod
Augie Fackler <durin42@gmail.com>
parents: 10282
diff changeset
438 class wsgiui(ui.ui):
1b1a9038a71a hgweb: fix hgweb_mod as well as hgwebdir_mod
Augie Fackler <durin42@gmail.com>
parents: 10282
diff changeset
439 # 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
440 def termwidth(self):
1b1a9038a71a hgweb: fix hgweb_mod as well as hgwebdir_mod
Augie Fackler <durin42@gmail.com>
parents: 10282
diff changeset
441 return 80