author | Dirkjan Ochtman <dirkjan@ochtman.nl> |
Fri, 07 Nov 2008 23:31:12 +0100 | |
changeset 7345 | 55651328dfcc |
parent 7311 | de9c87fe1620 |
child 7361 | 9fe97eea5510 |
permissions | -rw-r--r-- |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
1 |
# hgweb/webutil.py - utility library for the web interface. |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
2 |
# |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
3 |
# Copyright 21 May 2005 - (c) 2005 Jake Edge <jake@edge2.net> |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
4 |
# Copyright 2005-2007 Matt Mackall <mpm@selenic.com> |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
5 |
# |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
6 |
# This software may be used and distributed according to the terms |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
7 |
# of the GNU General Public License, incorporated herein by reference. |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
8 |
|
7345
55651328dfcc
hgweb: fix up the less/more links on the graph page
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7311
diff
changeset
|
9 |
import os, copy |
7310
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
10 |
from mercurial import match, patch |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
11 |
from mercurial.node import hex, nullid |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
12 |
from mercurial.repo import RepoError |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
13 |
from mercurial import util |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
14 |
|
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
15 |
def up(p): |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
16 |
if p[0] != "/": |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
17 |
p = "/" + p |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
18 |
if p[-1] == "/": |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
19 |
p = p[:-1] |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
20 |
up = os.path.dirname(p) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
21 |
if up == "/": |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
22 |
return "/" |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
23 |
return up + "/" |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
24 |
|
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
25 |
def revnavgen(pos, pagelen, limit, nodefunc): |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
26 |
def seq(factor, limit=None): |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
27 |
if limit: |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
28 |
yield limit |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
29 |
if limit >= 20 and limit <= 40: |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
30 |
yield 50 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
31 |
else: |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
32 |
yield 1 * factor |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
33 |
yield 3 * factor |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
34 |
for f in seq(factor * 10): |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
35 |
yield f |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
36 |
|
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
37 |
def nav(**map): |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
38 |
l = [] |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
39 |
last = 0 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
40 |
for f in seq(1, pagelen): |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
41 |
if f < pagelen or f <= last: |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
42 |
continue |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
43 |
if f > limit: |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
44 |
break |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
45 |
last = f |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
46 |
if pos + f < limit: |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
47 |
l.append(("+%d" % f, hex(nodefunc(pos + f).node()))) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
48 |
if pos - f >= 0: |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
49 |
l.insert(0, ("-%d" % f, hex(nodefunc(pos - f).node()))) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
50 |
|
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
51 |
try: |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
52 |
yield {"label": "(0)", "node": hex(nodefunc('0').node())} |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
53 |
|
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
54 |
for label, node in l: |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
55 |
yield {"label": label, "node": node} |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
56 |
|
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
57 |
yield {"label": "tip", "node": "tip"} |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
58 |
except RepoError: |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
59 |
pass |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
60 |
|
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
61 |
return nav |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
62 |
|
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
63 |
def siblings(siblings=[], hiderev=None, **args): |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
64 |
siblings = [s for s in siblings if s.node() != nullid] |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
65 |
if len(siblings) == 1 and siblings[0].rev() == hiderev: |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
66 |
return |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
67 |
for s in siblings: |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
68 |
d = {'node': hex(s.node()), 'rev': s.rev()} |
7294
f933076a19fc
hgweb: pass more information about parent/child csets to templates
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6750
diff
changeset
|
69 |
d['user'] = s.user() |
f933076a19fc
hgweb: pass more information about parent/child csets to templates
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6750
diff
changeset
|
70 |
d['date'] = s.date() |
f933076a19fc
hgweb: pass more information about parent/child csets to templates
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6750
diff
changeset
|
71 |
d['description'] = s.description() |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
72 |
if hasattr(s, 'path'): |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
73 |
d['file'] = s.path() |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
74 |
d.update(args) |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
75 |
yield d |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
76 |
|
6434
62e0bb41e682
hgweb: minor improvements for new web style
Matt Mackall <mpm@selenic.com>
parents:
6413
diff
changeset
|
77 |
def renamelink(fctx): |
6437 | 78 |
r = fctx.renamed() |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
79 |
if r: |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
80 |
return [dict(file=r[0], node=hex(r[1]))] |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
81 |
return [] |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
82 |
|
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
83 |
def nodetagsdict(repo, node): |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
84 |
return [{"name": i} for i in repo.nodetags(node)] |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
85 |
|
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
86 |
def nodebranchdict(repo, ctx): |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
87 |
branches = [] |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
88 |
branch = ctx.branch() |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
89 |
# If this is an empty repo, ctx.node() == nullid, |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
90 |
# ctx.branch() == 'default', but branchtags() is |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
91 |
# an empty dict. Using dict.get avoids a traceback. |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
92 |
if repo.branchtags().get(branch) == ctx.node(): |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
93 |
branches.append({"name": branch}) |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
94 |
return branches |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
95 |
|
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
96 |
def nodeinbranch(repo, ctx): |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
97 |
branches = [] |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
98 |
branch = ctx.branch() |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
99 |
if branch != 'default' and repo.branchtags().get(branch) != ctx.node(): |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
100 |
branches.append({"name": branch}) |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
101 |
return branches |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
102 |
|
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
103 |
def nodebranchnodefault(ctx): |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
104 |
branches = [] |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
105 |
branch = ctx.branch() |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
106 |
if branch != 'default': |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
107 |
branches.append({"name": branch}) |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
108 |
return branches |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
109 |
|
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
110 |
def showtag(repo, tmpl, t1, node=nullid, **args): |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
111 |
for t in repo.nodetags(node): |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
112 |
yield tmpl(t1, tag=t, **args) |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
113 |
|
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
114 |
def cleanpath(repo, path): |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
115 |
path = path.lstrip('/') |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
116 |
return util.canonpath(repo.root, '', path) |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
117 |
|
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
118 |
def changectx(repo, req): |
6750
fb42030d79d6
add __len__ and __iter__ methods to repo and revlog
Matt Mackall <mpm@selenic.com>
parents:
6747
diff
changeset
|
119 |
changeid = "tip" |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
120 |
if 'node' in req.form: |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
121 |
changeid = req.form['node'][0] |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
122 |
elif 'manifest' in req.form: |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
123 |
changeid = req.form['manifest'][0] |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
124 |
|
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
125 |
try: |
6747
f6c00b17387c
use repo[changeid] to get a changectx
Matt Mackall <mpm@selenic.com>
parents:
6437
diff
changeset
|
126 |
ctx = repo[changeid] |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
127 |
except RepoError: |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
128 |
man = repo.manifest |
6747
f6c00b17387c
use repo[changeid] to get a changectx
Matt Mackall <mpm@selenic.com>
parents:
6437
diff
changeset
|
129 |
ctx = repo[man.linkrev(man.lookup(changeid))] |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
130 |
|
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
131 |
return ctx |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
132 |
|
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
133 |
def filectx(repo, req): |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
134 |
path = cleanpath(repo, req.form['file'][0]) |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
135 |
if 'node' in req.form: |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
136 |
changeid = req.form['node'][0] |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
137 |
else: |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
138 |
changeid = req.form['filenode'][0] |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
139 |
try: |
6747
f6c00b17387c
use repo[changeid] to get a changectx
Matt Mackall <mpm@selenic.com>
parents:
6437
diff
changeset
|
140 |
fctx = repo[changeid][path] |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
141 |
except RepoError: |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
142 |
fctx = repo.filectx(path, fileid=changeid) |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
143 |
|
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
144 |
return fctx |
7310
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
145 |
|
7311
de9c87fe1620
hgweb: move another utility function into the webutil module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7310
diff
changeset
|
146 |
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
|
147 |
for f in files[:max]: |
de9c87fe1620
hgweb: move another utility function into the webutil module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7310
diff
changeset
|
148 |
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
|
149 |
if len(files) > max: |
de9c87fe1620
hgweb: move another utility function into the webutil module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7310
diff
changeset
|
150 |
yield tmpl('fileellipses') |
de9c87fe1620
hgweb: move another utility function into the webutil module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7310
diff
changeset
|
151 |
|
7310
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
152 |
def diffs(repo, tmpl, ctx, files, parity): |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
153 |
|
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
154 |
def countgen(): |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
155 |
start = 1 |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
156 |
while True: |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
157 |
yield start |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
158 |
start += 1 |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
159 |
|
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
160 |
blockcount = countgen() |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
161 |
def prettyprintlines(diff): |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
162 |
blockno = blockcount.next() |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
163 |
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
|
164 |
lineno = "%d.%d" % (blockno, lineno + 1) |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
165 |
if l.startswith('+'): |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
166 |
ltype = "difflineplus" |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
167 |
elif l.startswith('-'): |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
168 |
ltype = "difflineminus" |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
169 |
elif l.startswith('@'): |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
170 |
ltype = "difflineat" |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
171 |
else: |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
172 |
ltype = "diffline" |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
173 |
yield tmpl(ltype, |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
174 |
line=l, |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
175 |
lineid="l%s" % lineno, |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
176 |
linenumber="% 8s" % lineno) |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
177 |
|
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
178 |
if files: |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
179 |
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
|
180 |
else: |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
181 |
m = match.always(repo.root, repo.getcwd()) |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
182 |
|
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
183 |
diffopts = patch.diffopts(repo.ui, untrusted=True) |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
184 |
parents = ctx.parents() |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
185 |
node1 = parents and parents[0].node() or nullid |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
186 |
node2 = ctx.node() |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
187 |
|
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
188 |
block = [] |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
189 |
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
|
190 |
if chunk.startswith('diff') and block: |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
191 |
yield tmpl('diffblock', parity=parity.next(), |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
192 |
lines=prettyprintlines(''.join(block))) |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
193 |
block = [] |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
194 |
if chunk.startswith('diff'): |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
195 |
chunk = ''.join(chunk.splitlines(True)[1:]) |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
196 |
block.append(chunk) |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
197 |
yield tmpl('diffblock', parity=parity.next(), |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7294
diff
changeset
|
198 |
lines=prettyprintlines(''.join(block))) |
7345
55651328dfcc
hgweb: fix up the less/more links on the graph page
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7311
diff
changeset
|
199 |
|
55651328dfcc
hgweb: fix up the less/more links on the graph page
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7311
diff
changeset
|
200 |
class sessionvars(object): |
55651328dfcc
hgweb: fix up the less/more links on the graph page
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7311
diff
changeset
|
201 |
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
|
202 |
self.start = start |
55651328dfcc
hgweb: fix up the less/more links on the graph page
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7311
diff
changeset
|
203 |
self.vars = vars |
55651328dfcc
hgweb: fix up the less/more links on the graph page
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7311
diff
changeset
|
204 |
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
|
205 |
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
|
206 |
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
|
207 |
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
|
208 |
def __copy__(self): |
55651328dfcc
hgweb: fix up the less/more links on the graph page
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7311
diff
changeset
|
209 |
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
|
210 |
def __iter__(self): |
55651328dfcc
hgweb: fix up the less/more links on the graph page
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7311
diff
changeset
|
211 |
separator = self.start |
55651328dfcc
hgweb: fix up the less/more links on the graph page
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7311
diff
changeset
|
212 |
for key, value in self.vars.iteritems(): |
55651328dfcc
hgweb: fix up the less/more links on the graph page
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7311
diff
changeset
|
213 |
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
|
214 |
separator = '&' |