author | Gregory Szorc <gregory.szorc@gmail.com> |
Fri, 06 Feb 2015 20:43:54 -0800 | |
changeset 24083 | 5fbb5217a6c8 |
parent 24082 | 32dabf811b39 |
child 24084 | ef06e2b1a3d1 |
permissions | -rw-r--r-- |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
1 |
# |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
2 |
# Copyright 21 May 2005 - (c) 2005 Jake Edge <jake@edge2.net> |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
3 |
# Copyright 2005-2007 Matt Mackall <mpm@selenic.com> |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
4 |
# |
8225
46293a0c7e9f
updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents:
8209
diff
changeset
|
5 |
# This software may be used and distributed according to the terms of the |
10263 | 6 |
# GNU General Public License version 2 or any later version. |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
7 |
|
7345
55651328dfcc
hgweb: fix up the less/more links on the graph page
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7332
diff
changeset
|
8 |
import os, mimetypes, re, cgi, copy |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6368
diff
changeset
|
9 |
import webutil |
11332
716e176a4e01
hgweb: specify a charset when sending raw text files
Julian Cowley <julian@lava.net>
parents:
10394
diff
changeset
|
10 |
from mercurial import error, encoding, archival, templater, templatefilters |
21123
92fab48dfec1
hgweb: show revisions and hashes gotten from changelog in "comparison" page
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21121
diff
changeset
|
11 |
from mercurial.node import short, hex |
19657
145636d31bb4
hgweb: import the whole util module in webcommands instead of just one function
Alexander Plavin <alexander@plav.in>
parents:
19656
diff
changeset
|
12 |
from mercurial import util |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
13 |
from common import paritygen, staticfile, get_contact, ErrorResponse |
7029
b84d27386285
hgweb: Respond with HTTP 403 for disabled archive types instead of 404
Rocco Rutte <pdmef@gmx.net>
parents:
6981
diff
changeset
|
14 |
from common import HTTP_OK, HTTP_FORBIDDEN, HTTP_NOT_FOUND |
15528
a84698badf0b
annotate: support diff whitespace filtering flags (issue3030)
Patrick Mezard <pmezard@gmail.com>
parents:
15004
diff
changeset
|
15 |
from mercurial import graphmod, patch |
17933
8243dd66e0e3
webcommands: allow hgweb's archive to recurse into subrepos
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17322
diff
changeset
|
16 |
from mercurial import scmutil |
12666
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
17 |
from mercurial.i18n import _ |
19722
bf15935b68a3
hgweb: add revset syntax support to search
Alexander Plavin <alexander@plav.in>
parents:
19657
diff
changeset
|
18 |
from mercurial.error import ParseError, RepoLookupError, Abort |
bf15935b68a3
hgweb: add revset syntax support to search
Alexander Plavin <alexander@plav.in>
parents:
19657
diff
changeset
|
19 |
from mercurial import revset |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
20 |
|
24076
b53d2afd11fb
webcommands: define web commands using a decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23992
diff
changeset
|
21 |
__all__ = [] |
24077
e8046ca0405d
webcommands: define a dict of available commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24076
diff
changeset
|
22 |
commands = {} |
24076
b53d2afd11fb
webcommands: define web commands using a decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23992
diff
changeset
|
23 |
|
b53d2afd11fb
webcommands: define web commands using a decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23992
diff
changeset
|
24 |
class webcommand(object): |
b53d2afd11fb
webcommands: define web commands using a decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23992
diff
changeset
|
25 |
"""Decorator used to register a web command handler. |
b53d2afd11fb
webcommands: define web commands using a decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23992
diff
changeset
|
26 |
|
b53d2afd11fb
webcommands: define web commands using a decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23992
diff
changeset
|
27 |
The decorator takes as its positional arguments the name/path the |
b53d2afd11fb
webcommands: define web commands using a decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23992
diff
changeset
|
28 |
command should be accessible under. |
b53d2afd11fb
webcommands: define web commands using a decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23992
diff
changeset
|
29 |
|
b53d2afd11fb
webcommands: define web commands using a decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23992
diff
changeset
|
30 |
Usage: |
5963
5be210afe1b8
hgweb: explicitly check if requested command exists
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5960
diff
changeset
|
31 |
|
24076
b53d2afd11fb
webcommands: define web commands using a decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23992
diff
changeset
|
32 |
@webcommand('mycommand') |
b53d2afd11fb
webcommands: define web commands using a decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23992
diff
changeset
|
33 |
def mycommand(web, req, tmpl): |
b53d2afd11fb
webcommands: define web commands using a decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23992
diff
changeset
|
34 |
pass |
b53d2afd11fb
webcommands: define web commands using a decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23992
diff
changeset
|
35 |
""" |
5963
5be210afe1b8
hgweb: explicitly check if requested command exists
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5960
diff
changeset
|
36 |
|
24076
b53d2afd11fb
webcommands: define web commands using a decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23992
diff
changeset
|
37 |
def __init__(self, name): |
b53d2afd11fb
webcommands: define web commands using a decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23992
diff
changeset
|
38 |
self.name = name |
b53d2afd11fb
webcommands: define web commands using a decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23992
diff
changeset
|
39 |
|
b53d2afd11fb
webcommands: define web commands using a decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23992
diff
changeset
|
40 |
def __call__(self, func): |
b53d2afd11fb
webcommands: define web commands using a decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23992
diff
changeset
|
41 |
__all__.append(self.name) |
24077
e8046ca0405d
webcommands: define a dict of available commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24076
diff
changeset
|
42 |
commands[self.name] = func |
24076
b53d2afd11fb
webcommands: define web commands using a decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23992
diff
changeset
|
43 |
return func |
b53d2afd11fb
webcommands: define web commands using a decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23992
diff
changeset
|
44 |
|
b53d2afd11fb
webcommands: define web commands using a decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23992
diff
changeset
|
45 |
@webcommand('log') |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5598
diff
changeset
|
46 |
def log(web, req, tmpl): |
5915
d0576d065993
Prefer i in d over d.has_key(i)
Christian Ebert <blacktrash@gmx.net>
parents:
5890
diff
changeset
|
47 |
if 'file' in req.form and req.form['file'][0]: |
5964
1cd1582ef25f
hgweb: centralize req.write() calls
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5963
diff
changeset
|
48 |
return filelog(web, req, tmpl) |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
49 |
else: |
5964
1cd1582ef25f
hgweb: centralize req.write() calls
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5963
diff
changeset
|
50 |
return changelog(web, req, tmpl) |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
51 |
|
24076
b53d2afd11fb
webcommands: define web commands using a decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23992
diff
changeset
|
52 |
@webcommand('rawfile') |
5890
a0e20a5eba3c
hgweb: fast path for sending raw files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5600
diff
changeset
|
53 |
def rawfile(web, req, tmpl): |
15004
d06b9c55ddab
hgweb: raw file mimetype guessing configurable, off by default (BC) (issue2923)
Matt Mackall <mpm@selenic.com>
parents:
14771
diff
changeset
|
54 |
guessmime = web.configbool('web', 'guessmime', False) |
d06b9c55ddab
hgweb: raw file mimetype guessing configurable, off by default (BC) (issue2923)
Matt Mackall <mpm@selenic.com>
parents:
14771
diff
changeset
|
55 |
|
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6368
diff
changeset
|
56 |
path = webutil.cleanpath(web.repo, req.form.get('file', [''])[0]) |
5890
a0e20a5eba3c
hgweb: fast path for sending raw files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5600
diff
changeset
|
57 |
if not path: |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
58 |
content = manifest(web, req, tmpl) |
5993
948a41e77902
hgweb: explicit response status
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5964
diff
changeset
|
59 |
req.respond(HTTP_OK, web.ctype) |
948a41e77902
hgweb: explicit response status
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5964
diff
changeset
|
60 |
return content |
5890
a0e20a5eba3c
hgweb: fast path for sending raw files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5600
diff
changeset
|
61 |
|
a0e20a5eba3c
hgweb: fast path for sending raw files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5600
diff
changeset
|
62 |
try: |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6368
diff
changeset
|
63 |
fctx = webutil.filectx(web.repo, req) |
7633 | 64 |
except error.LookupError, inst: |
6368
2c370f08c486
hgweb: better error messages
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6217
diff
changeset
|
65 |
try: |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
66 |
content = manifest(web, req, tmpl) |
6368
2c370f08c486
hgweb: better error messages
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6217
diff
changeset
|
67 |
req.respond(HTTP_OK, web.ctype) |
2c370f08c486
hgweb: better error messages
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6217
diff
changeset
|
68 |
return content |
2c370f08c486
hgweb: better error messages
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6217
diff
changeset
|
69 |
except ErrorResponse: |
2c370f08c486
hgweb: better error messages
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6217
diff
changeset
|
70 |
raise inst |
5890
a0e20a5eba3c
hgweb: fast path for sending raw files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5600
diff
changeset
|
71 |
|
a0e20a5eba3c
hgweb: fast path for sending raw files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5600
diff
changeset
|
72 |
path = fctx.path() |
a0e20a5eba3c
hgweb: fast path for sending raw files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5600
diff
changeset
|
73 |
text = fctx.data() |
15004
d06b9c55ddab
hgweb: raw file mimetype guessing configurable, off by default (BC) (issue2923)
Matt Mackall <mpm@selenic.com>
parents:
14771
diff
changeset
|
74 |
mt = 'application/binary' |
d06b9c55ddab
hgweb: raw file mimetype guessing configurable, off by default (BC) (issue2923)
Matt Mackall <mpm@selenic.com>
parents:
14771
diff
changeset
|
75 |
if guessmime: |
d06b9c55ddab
hgweb: raw file mimetype guessing configurable, off by default (BC) (issue2923)
Matt Mackall <mpm@selenic.com>
parents:
14771
diff
changeset
|
76 |
mt = mimetypes.guess_type(path)[0] |
d06b9c55ddab
hgweb: raw file mimetype guessing configurable, off by default (BC) (issue2923)
Matt Mackall <mpm@selenic.com>
parents:
14771
diff
changeset
|
77 |
if mt is None: |
19657
145636d31bb4
hgweb: import the whole util module in webcommands instead of just one function
Alexander Plavin <alexander@plav.in>
parents:
19656
diff
changeset
|
78 |
mt = util.binary(text) and 'application/binary' or 'text/plain' |
11332
716e176a4e01
hgweb: specify a charset when sending raw text files
Julian Cowley <julian@lava.net>
parents:
10394
diff
changeset
|
79 |
if mt.startswith('text/'): |
716e176a4e01
hgweb: specify a charset when sending raw text files
Julian Cowley <julian@lava.net>
parents:
10394
diff
changeset
|
80 |
mt += '; charset="%s"' % encoding.encoding |
5890
a0e20a5eba3c
hgweb: fast path for sending raw files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5600
diff
changeset
|
81 |
|
18352
e33b9b92a200
hgweb: pass the actual response body to request.response, not just the length
Mads Kiilerich <mads@kiilerich.com>
parents:
18348
diff
changeset
|
82 |
req.respond(HTTP_OK, mt, path, body=text) |
e33b9b92a200
hgweb: pass the actual response body to request.response, not just the length
Mads Kiilerich <mads@kiilerich.com>
parents:
18348
diff
changeset
|
83 |
return [] |
5890
a0e20a5eba3c
hgweb: fast path for sending raw files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5600
diff
changeset
|
84 |
|
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
85 |
def _filerevision(web, tmpl, fctx): |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
86 |
f = fctx.path() |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
87 |
text = fctx.data() |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
88 |
parity = paritygen(web.stripecount) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
89 |
|
19657
145636d31bb4
hgweb: import the whole util module in webcommands instead of just one function
Alexander Plavin <alexander@plav.in>
parents:
19656
diff
changeset
|
90 |
if util.binary(text): |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
91 |
mt = mimetypes.guess_type(f)[0] or 'application/octet-stream' |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
92 |
text = '(binary:%s)' % mt |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
93 |
|
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
94 |
def lines(): |
9136
31177742f54a
for calls expecting bool args, pass bool instead of int
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8842
diff
changeset
|
95 |
for lineno, t in enumerate(text.splitlines(True)): |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
96 |
yield {"line": t, |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
97 |
"lineid": "l%d" % (lineno + 1), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
98 |
"linenumber": "% 6d" % (lineno + 1), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
99 |
"parity": parity.next()} |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
100 |
|
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
101 |
return tmpl("filerevision", |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
102 |
file=f, |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
103 |
path=webutil.up(f), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
104 |
text=lines(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
105 |
rev=fctx.rev(), |
14055
421d56a055fd
drop {short,hex}(ctx.node()) calls in favor of ctx methods
Alexander Solovyov <alexander@solovyov.net>
parents:
14043
diff
changeset
|
106 |
node=fctx.hex(), |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
107 |
author=fctx.user(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
108 |
date=fctx.date(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
109 |
desc=fctx.description(), |
18581
3490c91a1fcb
templates: export extra as a dict to templates
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
18563
diff
changeset
|
110 |
extra=fctx.extra(), |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
111 |
branch=webutil.nodebranchnodefault(fctx), |
7671
06cf09c822c4
hgweb: simplify parents/children generation code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7637
diff
changeset
|
112 |
parent=webutil.parents(fctx), |
06cf09c822c4
hgweb: simplify parents/children generation code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7637
diff
changeset
|
113 |
child=webutil.children(fctx), |
6434
62e0bb41e682
hgweb: minor improvements for new web style
Matt Mackall <mpm@selenic.com>
parents:
6410
diff
changeset
|
114 |
rename=webutil.renamelink(fctx), |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
115 |
permissions=fctx.manifest().flags(f)) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
116 |
|
24076
b53d2afd11fb
webcommands: define web commands using a decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23992
diff
changeset
|
117 |
@webcommand('file') |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5598
diff
changeset
|
118 |
def file(web, req, tmpl): |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6368
diff
changeset
|
119 |
path = webutil.cleanpath(web.repo, req.form.get('file', [''])[0]) |
6853
2ff0829bdae5
hgweb: do not use unassigned variables in exception handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6669
diff
changeset
|
120 |
if not path: |
6857 | 121 |
return manifest(web, req, tmpl) |
6853
2ff0829bdae5
hgweb: do not use unassigned variables in exception handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6669
diff
changeset
|
122 |
try: |
6857 | 123 |
return _filerevision(web, tmpl, webutil.filectx(web.repo, req)) |
7633 | 124 |
except error.LookupError, inst: |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
125 |
try: |
6857 | 126 |
return manifest(web, req, tmpl) |
6853
2ff0829bdae5
hgweb: do not use unassigned variables in exception handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6669
diff
changeset
|
127 |
except ErrorResponse: |
2ff0829bdae5
hgweb: do not use unassigned variables in exception handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6669
diff
changeset
|
128 |
raise inst |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
129 |
|
10247
e8c7410371e0
hgweb: add less/more links for search logs (issue1972)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10246
diff
changeset
|
130 |
def _search(web, req, tmpl): |
19656
60ce14e41faf
hgweb: add string constants for search mode names
Alexander Plavin <alexander@plav.in>
parents:
19634
diff
changeset
|
131 |
MODE_REVISION = 'rev' |
60ce14e41faf
hgweb: add string constants for search mode names
Alexander Plavin <alexander@plav.in>
parents:
19634
diff
changeset
|
132 |
MODE_KEYWORD = 'keyword' |
19722
bf15935b68a3
hgweb: add revset syntax support to search
Alexander Plavin <alexander@plav.in>
parents:
19657
diff
changeset
|
133 |
MODE_REVSET = 'revset' |
10247
e8c7410371e0
hgweb: add less/more links for search logs (issue1972)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10246
diff
changeset
|
134 |
|
19633
217f2b9acee0
hgweb: search() function supports direct pointing to revision
Alexander Plavin <alexander@plav.in>
parents:
19632
diff
changeset
|
135 |
def revsearch(ctx): |
217f2b9acee0
hgweb: search() function supports direct pointing to revision
Alexander Plavin <alexander@plav.in>
parents:
19632
diff
changeset
|
136 |
yield ctx |
217f2b9acee0
hgweb: search() function supports direct pointing to revision
Alexander Plavin <alexander@plav.in>
parents:
19632
diff
changeset
|
137 |
|
19632
299511aabf85
hgweb: pass arguments which a function depends on explicitly in search
Alexander Plavin <alexander@plav.in>
parents:
19631
diff
changeset
|
138 |
def keywordsearch(query): |
15727
917f263eeb26
i18n: use "encoding.lower()" to normalize string in hgweb search query
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15528
diff
changeset
|
139 |
lower = encoding.lower |
917f263eeb26
i18n: use "encoding.lower()" to normalize string in hgweb search query
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15528
diff
changeset
|
140 |
qw = lower(query).split() |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
141 |
|
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
142 |
def revgen(): |
18497
a58d8936647a
hgweb: prevent traceback during search when filtered (issue3783)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18478
diff
changeset
|
143 |
cl = web.repo.changelog |
12059
0de6cfdcaad8
webcommands: remove unncessary access to repo.changelog
Patrick Mezard <pmezard@gmail.com>
parents:
11332
diff
changeset
|
144 |
for i in xrange(len(web.repo) - 1, 0, -100): |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
145 |
l = [] |
19491
e111d5e6bbbd
hgweb: fix duplication for some search queries
Alexander Plavin <me@aplavin.ru>
parents:
19487
diff
changeset
|
146 |
for j in cl.revs(max(0, i - 99), i): |
6747
f6c00b17387c
use repo[changeid] to get a changectx
Matt Mackall <mpm@selenic.com>
parents:
6720
diff
changeset
|
147 |
ctx = web.repo[j] |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
148 |
l.append(ctx) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
149 |
l.reverse() |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
150 |
for e in l: |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
151 |
yield e |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
152 |
|
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
153 |
for ctx in revgen(): |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
154 |
miss = 0 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
155 |
for q in qw: |
15727
917f263eeb26
i18n: use "encoding.lower()" to normalize string in hgweb search query
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15528
diff
changeset
|
156 |
if not (q in lower(ctx.user()) or |
917f263eeb26
i18n: use "encoding.lower()" to normalize string in hgweb search query
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15528
diff
changeset
|
157 |
q in lower(ctx.description()) or |
917f263eeb26
i18n: use "encoding.lower()" to normalize string in hgweb search query
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15528
diff
changeset
|
158 |
q in lower(" ".join(ctx.files()))): |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
159 |
miss = 1 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
160 |
break |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
161 |
if miss: |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
162 |
continue |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
163 |
|
19533
9a020b354d93
hgweb: separate search itself and template generation
Alexander Plavin <alexander@plav.in>
parents:
19499
diff
changeset
|
164 |
yield ctx |
9a020b354d93
hgweb: separate search itself and template generation
Alexander Plavin <alexander@plav.in>
parents:
19499
diff
changeset
|
165 |
|
19722
bf15935b68a3
hgweb: add revset syntax support to search
Alexander Plavin <alexander@plav.in>
parents:
19657
diff
changeset
|
166 |
def revsetsearch(revs): |
bf15935b68a3
hgweb: add revset syntax support to search
Alexander Plavin <alexander@plav.in>
parents:
19657
diff
changeset
|
167 |
for r in revs: |
bf15935b68a3
hgweb: add revset syntax support to search
Alexander Plavin <alexander@plav.in>
parents:
19657
diff
changeset
|
168 |
yield web.repo[r] |
bf15935b68a3
hgweb: add revset syntax support to search
Alexander Plavin <alexander@plav.in>
parents:
19657
diff
changeset
|
169 |
|
19631
cf9e5e45c1d3
hgweb: add dynamic search function selection, depending on the query
Alexander Plavin <alexander@plav.in>
parents:
19534
diff
changeset
|
170 |
searchfuncs = { |
20004
06e118c097ff
hgweb, i18n: do not translate search mode description
Wagner Bruna <wbruna@softwareexpress.com.br>
parents:
19951
diff
changeset
|
171 |
MODE_REVISION: (revsearch, 'exact revision search'), |
06e118c097ff
hgweb, i18n: do not translate search mode description
Wagner Bruna <wbruna@softwareexpress.com.br>
parents:
19951
diff
changeset
|
172 |
MODE_KEYWORD: (keywordsearch, 'literal keyword search'), |
06e118c097ff
hgweb, i18n: do not translate search mode description
Wagner Bruna <wbruna@softwareexpress.com.br>
parents:
19951
diff
changeset
|
173 |
MODE_REVSET: (revsetsearch, 'revset expression search'), |
19631
cf9e5e45c1d3
hgweb: add dynamic search function selection, depending on the query
Alexander Plavin <alexander@plav.in>
parents:
19534
diff
changeset
|
174 |
} |
cf9e5e45c1d3
hgweb: add dynamic search function selection, depending on the query
Alexander Plavin <alexander@plav.in>
parents:
19534
diff
changeset
|
175 |
|
19632
299511aabf85
hgweb: pass arguments which a function depends on explicitly in search
Alexander Plavin <alexander@plav.in>
parents:
19631
diff
changeset
|
176 |
def getsearchmode(query): |
19633
217f2b9acee0
hgweb: search() function supports direct pointing to revision
Alexander Plavin <alexander@plav.in>
parents:
19632
diff
changeset
|
177 |
try: |
217f2b9acee0
hgweb: search() function supports direct pointing to revision
Alexander Plavin <alexander@plav.in>
parents:
19632
diff
changeset
|
178 |
ctx = web.repo[query] |
217f2b9acee0
hgweb: search() function supports direct pointing to revision
Alexander Plavin <alexander@plav.in>
parents:
19632
diff
changeset
|
179 |
except (error.RepoError, error.LookupError): |
19722
bf15935b68a3
hgweb: add revset syntax support to search
Alexander Plavin <alexander@plav.in>
parents:
19657
diff
changeset
|
180 |
# query is not an exact revision pointer, need to |
19951
d51c4d85ec23
spelling: random spell checker fixes
Mads Kiilerich <madski@unity3d.com>
parents:
19886
diff
changeset
|
181 |
# decide if it's a revset expression or keywords |
19722
bf15935b68a3
hgweb: add revset syntax support to search
Alexander Plavin <alexander@plav.in>
parents:
19657
diff
changeset
|
182 |
pass |
19633
217f2b9acee0
hgweb: search() function supports direct pointing to revision
Alexander Plavin <alexander@plav.in>
parents:
19632
diff
changeset
|
183 |
else: |
19656
60ce14e41faf
hgweb: add string constants for search mode names
Alexander Plavin <alexander@plav.in>
parents:
19634
diff
changeset
|
184 |
return MODE_REVISION, ctx |
19631
cf9e5e45c1d3
hgweb: add dynamic search function selection, depending on the query
Alexander Plavin <alexander@plav.in>
parents:
19534
diff
changeset
|
185 |
|
19722
bf15935b68a3
hgweb: add revset syntax support to search
Alexander Plavin <alexander@plav.in>
parents:
19657
diff
changeset
|
186 |
revdef = 'reverse(%s)' % query |
bf15935b68a3
hgweb: add revset syntax support to search
Alexander Plavin <alexander@plav.in>
parents:
19657
diff
changeset
|
187 |
try: |
bf15935b68a3
hgweb: add revset syntax support to search
Alexander Plavin <alexander@plav.in>
parents:
19657
diff
changeset
|
188 |
tree, pos = revset.parse(revdef) |
bf15935b68a3
hgweb: add revset syntax support to search
Alexander Plavin <alexander@plav.in>
parents:
19657
diff
changeset
|
189 |
except ParseError: |
bf15935b68a3
hgweb: add revset syntax support to search
Alexander Plavin <alexander@plav.in>
parents:
19657
diff
changeset
|
190 |
# can't parse to a revset tree |
bf15935b68a3
hgweb: add revset syntax support to search
Alexander Plavin <alexander@plav.in>
parents:
19657
diff
changeset
|
191 |
return MODE_KEYWORD, query |
bf15935b68a3
hgweb: add revset syntax support to search
Alexander Plavin <alexander@plav.in>
parents:
19657
diff
changeset
|
192 |
|
bf15935b68a3
hgweb: add revset syntax support to search
Alexander Plavin <alexander@plav.in>
parents:
19657
diff
changeset
|
193 |
if revset.depth(tree) <= 2: |
bf15935b68a3
hgweb: add revset syntax support to search
Alexander Plavin <alexander@plav.in>
parents:
19657
diff
changeset
|
194 |
# no revset syntax used |
bf15935b68a3
hgweb: add revset syntax support to search
Alexander Plavin <alexander@plav.in>
parents:
19657
diff
changeset
|
195 |
return MODE_KEYWORD, query |
bf15935b68a3
hgweb: add revset syntax support to search
Alexander Plavin <alexander@plav.in>
parents:
19657
diff
changeset
|
196 |
|
bf15935b68a3
hgweb: add revset syntax support to search
Alexander Plavin <alexander@plav.in>
parents:
19657
diff
changeset
|
197 |
if util.any((token, (value or '')[:3]) == ('string', 're:') |
bf15935b68a3
hgweb: add revset syntax support to search
Alexander Plavin <alexander@plav.in>
parents:
19657
diff
changeset
|
198 |
for token, value, pos in revset.tokenize(revdef)): |
bf15935b68a3
hgweb: add revset syntax support to search
Alexander Plavin <alexander@plav.in>
parents:
19657
diff
changeset
|
199 |
return MODE_KEYWORD, query |
bf15935b68a3
hgweb: add revset syntax support to search
Alexander Plavin <alexander@plav.in>
parents:
19657
diff
changeset
|
200 |
|
bf15935b68a3
hgweb: add revset syntax support to search
Alexander Plavin <alexander@plav.in>
parents:
19657
diff
changeset
|
201 |
funcsused = revset.funcsused(tree) |
bf15935b68a3
hgweb: add revset syntax support to search
Alexander Plavin <alexander@plav.in>
parents:
19657
diff
changeset
|
202 |
if not funcsused.issubset(revset.safesymbols): |
bf15935b68a3
hgweb: add revset syntax support to search
Alexander Plavin <alexander@plav.in>
parents:
19657
diff
changeset
|
203 |
return MODE_KEYWORD, query |
bf15935b68a3
hgweb: add revset syntax support to search
Alexander Plavin <alexander@plav.in>
parents:
19657
diff
changeset
|
204 |
|
bf15935b68a3
hgweb: add revset syntax support to search
Alexander Plavin <alexander@plav.in>
parents:
19657
diff
changeset
|
205 |
mfunc = revset.match(web.repo.ui, revdef) |
bf15935b68a3
hgweb: add revset syntax support to search
Alexander Plavin <alexander@plav.in>
parents:
19657
diff
changeset
|
206 |
try: |
23992
db85e454fccc
hgweb: use revset.spanset where appropriate
Yuya Nishihara <yuya@tcha.org>
parents:
23745
diff
changeset
|
207 |
revs = mfunc(web.repo, revset.spanset(web.repo)) |
19722
bf15935b68a3
hgweb: add revset syntax support to search
Alexander Plavin <alexander@plav.in>
parents:
19657
diff
changeset
|
208 |
return MODE_REVSET, revs |
bf15935b68a3
hgweb: add revset syntax support to search
Alexander Plavin <alexander@plav.in>
parents:
19657
diff
changeset
|
209 |
# ParseError: wrongly placed tokens, wrongs arguments, etc |
bf15935b68a3
hgweb: add revset syntax support to search
Alexander Plavin <alexander@plav.in>
parents:
19657
diff
changeset
|
210 |
# RepoLookupError: no such revision, e.g. in 'revision:' |
bf15935b68a3
hgweb: add revset syntax support to search
Alexander Plavin <alexander@plav.in>
parents:
19657
diff
changeset
|
211 |
# Abort: bookmark/tag not exists |
bf15935b68a3
hgweb: add revset syntax support to search
Alexander Plavin <alexander@plav.in>
parents:
19657
diff
changeset
|
212 |
# LookupError: ambiguous identifier, e.g. in '(bc)' on a large repo |
bf15935b68a3
hgweb: add revset syntax support to search
Alexander Plavin <alexander@plav.in>
parents:
19657
diff
changeset
|
213 |
except (ParseError, RepoLookupError, Abort, LookupError): |
bf15935b68a3
hgweb: add revset syntax support to search
Alexander Plavin <alexander@plav.in>
parents:
19657
diff
changeset
|
214 |
return MODE_KEYWORD, query |
bf15935b68a3
hgweb: add revset syntax support to search
Alexander Plavin <alexander@plav.in>
parents:
19657
diff
changeset
|
215 |
|
19533
9a020b354d93
hgweb: separate search itself and template generation
Alexander Plavin <alexander@plav.in>
parents:
19499
diff
changeset
|
216 |
def changelist(**map): |
9a020b354d93
hgweb: separate search itself and template generation
Alexander Plavin <alexander@plav.in>
parents:
19499
diff
changeset
|
217 |
count = 0 |
9a020b354d93
hgweb: separate search itself and template generation
Alexander Plavin <alexander@plav.in>
parents:
19499
diff
changeset
|
218 |
|
19765
521c373ff134
hgweb: pass variable with current search mode name to the search template
Alexander Plavin <alexander@plav.in>
parents:
19738
diff
changeset
|
219 |
for ctx in searchfunc[0](funcarg): |
6659
bc553c6d1ef9
webcommands: fix increments lost by 894875eae49b
Andrew Beekhof <beekhof@gmail.com>
parents:
6657
diff
changeset
|
220 |
count += 1 |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
221 |
n = ctx.node() |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
222 |
showtags = webutil.showtag(web.repo, tmpl, 'changelogtag', n) |
7311
de9c87fe1620
hgweb: move another utility function into the webutil module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7310
diff
changeset
|
223 |
files = webutil.listfilediffs(tmpl, ctx.files(), n, web.maxfiles) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
224 |
|
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
225 |
yield tmpl('searchentry', |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
226 |
parity=parity.next(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
227 |
author=ctx.user(), |
7671
06cf09c822c4
hgweb: simplify parents/children generation code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7637
diff
changeset
|
228 |
parent=webutil.parents(ctx), |
06cf09c822c4
hgweb: simplify parents/children generation code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7637
diff
changeset
|
229 |
child=webutil.children(ctx), |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
230 |
changelogtag=showtags, |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
231 |
desc=ctx.description(), |
18581
3490c91a1fcb
templates: export extra as a dict to templates
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
18563
diff
changeset
|
232 |
extra=ctx.extra(), |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
233 |
date=ctx.date(), |
7311
de9c87fe1620
hgweb: move another utility function into the webutil module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7310
diff
changeset
|
234 |
files=files, |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
235 |
rev=ctx.rev(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
236 |
node=hex(n), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
237 |
tags=webutil.nodetagsdict(web.repo, n), |
13794
5c18a0bca26f
hgweb: add bookmark labels to monoblue theme (based on 270f57d35525)
Yuya Nishihara <yuya@tcha.org>
parents:
13597
diff
changeset
|
238 |
bookmarks=webutil.nodebookmarksdict(web.repo, n), |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
239 |
inbranch=webutil.nodeinbranch(web.repo, ctx), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
240 |
branches=webutil.nodebranchdict(web.repo, ctx)) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
241 |
|
10247
e8c7410371e0
hgweb: add less/more links for search logs (issue1972)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10246
diff
changeset
|
242 |
if count >= revcount: |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
243 |
break |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
244 |
|
19418
55b9d98a1ef4
hgweb: move local changelist function to the beginning of the parent one
Alexander Plavin <me@aplavin.ru>
parents:
19396
diff
changeset
|
245 |
query = req.form['rev'][0] |
55b9d98a1ef4
hgweb: move local changelist function to the beginning of the parent one
Alexander Plavin <me@aplavin.ru>
parents:
19396
diff
changeset
|
246 |
revcount = web.maxchanges |
55b9d98a1ef4
hgweb: move local changelist function to the beginning of the parent one
Alexander Plavin <me@aplavin.ru>
parents:
19396
diff
changeset
|
247 |
if 'revcount' in req.form: |
20092
77acd8ce01ce
hgweb: ignore non numeric "revcount" parameter values (issue4091)
Isaac Jurado <diptongo@gmail.com>
parents:
20004
diff
changeset
|
248 |
try: |
77acd8ce01ce
hgweb: ignore non numeric "revcount" parameter values (issue4091)
Isaac Jurado <diptongo@gmail.com>
parents:
20004
diff
changeset
|
249 |
revcount = int(req.form.get('revcount', [revcount])[0]) |
77acd8ce01ce
hgweb: ignore non numeric "revcount" parameter values (issue4091)
Isaac Jurado <diptongo@gmail.com>
parents:
20004
diff
changeset
|
250 |
revcount = max(revcount, 1) |
77acd8ce01ce
hgweb: ignore non numeric "revcount" parameter values (issue4091)
Isaac Jurado <diptongo@gmail.com>
parents:
20004
diff
changeset
|
251 |
tmpl.defaults['sessionvars']['revcount'] = revcount |
77acd8ce01ce
hgweb: ignore non numeric "revcount" parameter values (issue4091)
Isaac Jurado <diptongo@gmail.com>
parents:
20004
diff
changeset
|
252 |
except ValueError: |
77acd8ce01ce
hgweb: ignore non numeric "revcount" parameter values (issue4091)
Isaac Jurado <diptongo@gmail.com>
parents:
20004
diff
changeset
|
253 |
pass |
19418
55b9d98a1ef4
hgweb: move local changelist function to the beginning of the parent one
Alexander Plavin <me@aplavin.ru>
parents:
19396
diff
changeset
|
254 |
|
55b9d98a1ef4
hgweb: move local changelist function to the beginning of the parent one
Alexander Plavin <me@aplavin.ru>
parents:
19396
diff
changeset
|
255 |
lessvars = copy.copy(tmpl.defaults['sessionvars']) |
55b9d98a1ef4
hgweb: move local changelist function to the beginning of the parent one
Alexander Plavin <me@aplavin.ru>
parents:
19396
diff
changeset
|
256 |
lessvars['revcount'] = max(revcount / 2, 1) |
55b9d98a1ef4
hgweb: move local changelist function to the beginning of the parent one
Alexander Plavin <me@aplavin.ru>
parents:
19396
diff
changeset
|
257 |
lessvars['rev'] = query |
55b9d98a1ef4
hgweb: move local changelist function to the beginning of the parent one
Alexander Plavin <me@aplavin.ru>
parents:
19396
diff
changeset
|
258 |
morevars = copy.copy(tmpl.defaults['sessionvars']) |
55b9d98a1ef4
hgweb: move local changelist function to the beginning of the parent one
Alexander Plavin <me@aplavin.ru>
parents:
19396
diff
changeset
|
259 |
morevars['revcount'] = revcount * 2 |
55b9d98a1ef4
hgweb: move local changelist function to the beginning of the parent one
Alexander Plavin <me@aplavin.ru>
parents:
19396
diff
changeset
|
260 |
morevars['rev'] = query |
55b9d98a1ef4
hgweb: move local changelist function to the beginning of the parent one
Alexander Plavin <me@aplavin.ru>
parents:
19396
diff
changeset
|
261 |
|
19632
299511aabf85
hgweb: pass arguments which a function depends on explicitly in search
Alexander Plavin <alexander@plav.in>
parents:
19631
diff
changeset
|
262 |
mode, funcarg = getsearchmode(query) |
19768
186f54d40fdd
hgweb: add link to force literal keyword search
Alexander Plavin <alexander@plav.in>
parents:
19765
diff
changeset
|
263 |
|
186f54d40fdd
hgweb: add link to force literal keyword search
Alexander Plavin <alexander@plav.in>
parents:
19765
diff
changeset
|
264 |
if 'forcekw' in req.form: |
186f54d40fdd
hgweb: add link to force literal keyword search
Alexander Plavin <alexander@plav.in>
parents:
19765
diff
changeset
|
265 |
showforcekw = '' |
186f54d40fdd
hgweb: add link to force literal keyword search
Alexander Plavin <alexander@plav.in>
parents:
19765
diff
changeset
|
266 |
showunforcekw = searchfuncs[mode][1] |
186f54d40fdd
hgweb: add link to force literal keyword search
Alexander Plavin <alexander@plav.in>
parents:
19765
diff
changeset
|
267 |
mode = MODE_KEYWORD |
186f54d40fdd
hgweb: add link to force literal keyword search
Alexander Plavin <alexander@plav.in>
parents:
19765
diff
changeset
|
268 |
funcarg = query |
186f54d40fdd
hgweb: add link to force literal keyword search
Alexander Plavin <alexander@plav.in>
parents:
19765
diff
changeset
|
269 |
else: |
186f54d40fdd
hgweb: add link to force literal keyword search
Alexander Plavin <alexander@plav.in>
parents:
19765
diff
changeset
|
270 |
if mode != MODE_KEYWORD: |
186f54d40fdd
hgweb: add link to force literal keyword search
Alexander Plavin <alexander@plav.in>
parents:
19765
diff
changeset
|
271 |
showforcekw = searchfuncs[MODE_KEYWORD][1] |
186f54d40fdd
hgweb: add link to force literal keyword search
Alexander Plavin <alexander@plav.in>
parents:
19765
diff
changeset
|
272 |
else: |
186f54d40fdd
hgweb: add link to force literal keyword search
Alexander Plavin <alexander@plav.in>
parents:
19765
diff
changeset
|
273 |
showforcekw = '' |
186f54d40fdd
hgweb: add link to force literal keyword search
Alexander Plavin <alexander@plav.in>
parents:
19765
diff
changeset
|
274 |
showunforcekw = '' |
186f54d40fdd
hgweb: add link to force literal keyword search
Alexander Plavin <alexander@plav.in>
parents:
19765
diff
changeset
|
275 |
|
19631
cf9e5e45c1d3
hgweb: add dynamic search function selection, depending on the query
Alexander Plavin <alexander@plav.in>
parents:
19534
diff
changeset
|
276 |
searchfunc = searchfuncs[mode] |
cf9e5e45c1d3
hgweb: add dynamic search function selection, depending on the query
Alexander Plavin <alexander@plav.in>
parents:
19534
diff
changeset
|
277 |
|
12059
0de6cfdcaad8
webcommands: remove unncessary access to repo.changelog
Patrick Mezard <pmezard@gmail.com>
parents:
11332
diff
changeset
|
278 |
tip = web.repo['tip'] |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
279 |
parity = paritygen(web.stripecount) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
280 |
|
12059
0de6cfdcaad8
webcommands: remove unncessary access to repo.changelog
Patrick Mezard <pmezard@gmail.com>
parents:
11332
diff
changeset
|
281 |
return tmpl('search', query=query, node=tip.hex(), |
10247
e8c7410371e0
hgweb: add less/more links for search logs (issue1972)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10246
diff
changeset
|
282 |
entries=changelist, archives=web.archivelist("tip"), |
19765
521c373ff134
hgweb: pass variable with current search mode name to the search template
Alexander Plavin <alexander@plav.in>
parents:
19738
diff
changeset
|
283 |
morevars=morevars, lessvars=lessvars, |
19768
186f54d40fdd
hgweb: add link to force literal keyword search
Alexander Plavin <alexander@plav.in>
parents:
19765
diff
changeset
|
284 |
modedesc=searchfunc[1], |
186f54d40fdd
hgweb: add link to force literal keyword search
Alexander Plavin <alexander@plav.in>
parents:
19765
diff
changeset
|
285 |
showforcekw=showforcekw, showunforcekw=showunforcekw) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
286 |
|
24076
b53d2afd11fb
webcommands: define web commands using a decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23992
diff
changeset
|
287 |
@webcommand('changelog') |
10247
e8c7410371e0
hgweb: add less/more links for search logs (issue1972)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10246
diff
changeset
|
288 |
def changelog(web, req, tmpl, shortlog=False): |
e8c7410371e0
hgweb: add less/more links for search logs (issue1972)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10246
diff
changeset
|
289 |
|
19396
afc23eddc324
hgweb: show current search query in the input field
Alexander Plavin <me@aplavin.ru>
parents:
18968
diff
changeset
|
290 |
query = '' |
5915
d0576d065993
Prefer i in d over d.has_key(i)
Christian Ebert <blacktrash@gmx.net>
parents:
5890
diff
changeset
|
291 |
if 'node' in req.form: |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6368
diff
changeset
|
292 |
ctx = webutil.changectx(web.repo, req) |
19534
983bb4069004
hgweb: cleaner if conditions in changelog() function
Alexander Plavin <alexander@plav.in>
parents:
19533
diff
changeset
|
293 |
elif 'rev' in req.form: |
19634
49a068b8fb0c
hgweb: always run search when a query is entered (bc)
Alexander Plavin <alexander@plav.in>
parents:
19633
diff
changeset
|
294 |
return _search(web, req, tmpl) |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
295 |
else: |
19534
983bb4069004
hgweb: cleaner if conditions in changelog() function
Alexander Plavin <alexander@plav.in>
parents:
19533
diff
changeset
|
296 |
ctx = web.repo['tip'] |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
297 |
|
19737
ab5442f45441
hgweb: always compute all entries and latestentry in changelog
Alexander Plavin <alexander@plav.in>
parents:
19735
diff
changeset
|
298 |
def changelist(): |
18427
56ca4443a343
hgweb: use changelog for iteration
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18409
diff
changeset
|
299 |
revs = [] |
19486
002b711a3e8a
hgweb: fix incorrect way to count revisions in log (issue3977)
Alexander Plavin <me@aplavin.ru>
parents:
19485
diff
changeset
|
300 |
if pos != -1: |
002b711a3e8a
hgweb: fix incorrect way to count revisions in log (issue3977)
Alexander Plavin <me@aplavin.ru>
parents:
19485
diff
changeset
|
301 |
revs = web.repo.changelog.revs(pos, 0) |
002b711a3e8a
hgweb: fix incorrect way to count revisions in log (issue3977)
Alexander Plavin <me@aplavin.ru>
parents:
19485
diff
changeset
|
302 |
curcount = 0 |
23745
513d47905114
hgweb: extract changelist entry generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23740
diff
changeset
|
303 |
for rev in revs: |
19486
002b711a3e8a
hgweb: fix incorrect way to count revisions in log (issue3977)
Alexander Plavin <me@aplavin.ru>
parents:
19485
diff
changeset
|
304 |
curcount += 1 |
19738
93b8544c4482
hgweb: add nextentry variable for easy pagination in changelog
Alexander Plavin <alexander@plav.in>
parents:
19737
diff
changeset
|
305 |
if curcount > revcount + 1: |
19486
002b711a3e8a
hgweb: fix incorrect way to count revisions in log (issue3977)
Alexander Plavin <me@aplavin.ru>
parents:
19485
diff
changeset
|
306 |
break |
23745
513d47905114
hgweb: extract changelist entry generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23740
diff
changeset
|
307 |
|
513d47905114
hgweb: extract changelist entry generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23740
diff
changeset
|
308 |
entry = webutil.changelistentry(web, web.repo[rev], tmpl) |
513d47905114
hgweb: extract changelist entry generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23740
diff
changeset
|
309 |
entry['parity'] = parity.next() |
513d47905114
hgweb: extract changelist entry generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23740
diff
changeset
|
310 |
yield entry |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
311 |
|
10246
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
312 |
revcount = shortlog and web.maxshortchanges or web.maxchanges |
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
313 |
if 'revcount' in req.form: |
20092
77acd8ce01ce
hgweb: ignore non numeric "revcount" parameter values (issue4091)
Isaac Jurado <diptongo@gmail.com>
parents:
20004
diff
changeset
|
314 |
try: |
77acd8ce01ce
hgweb: ignore non numeric "revcount" parameter values (issue4091)
Isaac Jurado <diptongo@gmail.com>
parents:
20004
diff
changeset
|
315 |
revcount = int(req.form.get('revcount', [revcount])[0]) |
77acd8ce01ce
hgweb: ignore non numeric "revcount" parameter values (issue4091)
Isaac Jurado <diptongo@gmail.com>
parents:
20004
diff
changeset
|
316 |
revcount = max(revcount, 1) |
77acd8ce01ce
hgweb: ignore non numeric "revcount" parameter values (issue4091)
Isaac Jurado <diptongo@gmail.com>
parents:
20004
diff
changeset
|
317 |
tmpl.defaults['sessionvars']['revcount'] = revcount |
77acd8ce01ce
hgweb: ignore non numeric "revcount" parameter values (issue4091)
Isaac Jurado <diptongo@gmail.com>
parents:
20004
diff
changeset
|
318 |
except ValueError: |
77acd8ce01ce
hgweb: ignore non numeric "revcount" parameter values (issue4091)
Isaac Jurado <diptongo@gmail.com>
parents:
20004
diff
changeset
|
319 |
pass |
10246
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
320 |
|
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
321 |
lessvars = copy.copy(tmpl.defaults['sessionvars']) |
13931
c3372529247f
hgweb: set minimum number of revision to display to 1 when revcount is 0
Md. O. Shayan <mdoshayan@gmail.com>
parents:
13924
diff
changeset
|
322 |
lessvars['revcount'] = max(revcount / 2, 1) |
10246
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
323 |
morevars = copy.copy(tmpl.defaults['sessionvars']) |
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
324 |
morevars['revcount'] = revcount * 2 |
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
325 |
|
12059
0de6cfdcaad8
webcommands: remove unncessary access to repo.changelog
Patrick Mezard <pmezard@gmail.com>
parents:
11332
diff
changeset
|
326 |
count = len(web.repo) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
327 |
pos = ctx.rev() |
19486
002b711a3e8a
hgweb: fix incorrect way to count revisions in log (issue3977)
Alexander Plavin <me@aplavin.ru>
parents:
19485
diff
changeset
|
328 |
parity = paritygen(web.stripecount) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
329 |
|
18409
e3f5cef11d6a
hgweb: pass repo object to revnav construction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18408
diff
changeset
|
330 |
changenav = webutil.revnav(web.repo).gen(pos, revcount, count) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
331 |
|
19737
ab5442f45441
hgweb: always compute all entries and latestentry in changelog
Alexander Plavin <alexander@plav.in>
parents:
19735
diff
changeset
|
332 |
entries = list(changelist()) |
ab5442f45441
hgweb: always compute all entries and latestentry in changelog
Alexander Plavin <alexander@plav.in>
parents:
19735
diff
changeset
|
333 |
latestentry = entries[:1] |
19738
93b8544c4482
hgweb: add nextentry variable for easy pagination in changelog
Alexander Plavin <alexander@plav.in>
parents:
19737
diff
changeset
|
334 |
if len(entries) > revcount: |
93b8544c4482
hgweb: add nextentry variable for easy pagination in changelog
Alexander Plavin <alexander@plav.in>
parents:
19737
diff
changeset
|
335 |
nextentry = entries[-1:] |
93b8544c4482
hgweb: add nextentry variable for easy pagination in changelog
Alexander Plavin <alexander@plav.in>
parents:
19737
diff
changeset
|
336 |
entries = entries[:-1] |
93b8544c4482
hgweb: add nextentry variable for easy pagination in changelog
Alexander Plavin <alexander@plav.in>
parents:
19737
diff
changeset
|
337 |
else: |
93b8544c4482
hgweb: add nextentry variable for easy pagination in changelog
Alexander Plavin <alexander@plav.in>
parents:
19737
diff
changeset
|
338 |
nextentry = [] |
19737
ab5442f45441
hgweb: always compute all entries and latestentry in changelog
Alexander Plavin <alexander@plav.in>
parents:
19735
diff
changeset
|
339 |
|
10246
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
340 |
return tmpl(shortlog and 'shortlog' or 'changelog', changenav=changenav, |
14055
421d56a055fd
drop {short,hex}(ctx.node()) calls in favor of ctx methods
Alexander Solovyov <alexander@solovyov.net>
parents:
14043
diff
changeset
|
341 |
node=ctx.hex(), rev=pos, changesets=count, |
19737
ab5442f45441
hgweb: always compute all entries and latestentry in changelog
Alexander Plavin <alexander@plav.in>
parents:
19735
diff
changeset
|
342 |
entries=entries, |
19738
93b8544c4482
hgweb: add nextentry variable for easy pagination in changelog
Alexander Plavin <alexander@plav.in>
parents:
19737
diff
changeset
|
343 |
latestentry=latestentry, nextentry=nextentry, |
10246
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
344 |
archives=web.archivelist("tip"), revcount=revcount, |
19396
afc23eddc324
hgweb: show current search query in the input field
Alexander Plavin <me@aplavin.ru>
parents:
18968
diff
changeset
|
345 |
morevars=morevars, lessvars=lessvars, query=query) |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
346 |
|
24076
b53d2afd11fb
webcommands: define web commands using a decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23992
diff
changeset
|
347 |
@webcommand('shortlog') |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5598
diff
changeset
|
348 |
def shortlog(web, req, tmpl): |
19872
681f7b9213a4
check-code: check for spaces around = for named parameters
Mads Kiilerich <madski@unity3d.com>
parents:
19768
diff
changeset
|
349 |
return changelog(web, req, tmpl, shortlog=True) |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
350 |
|
24076
b53d2afd11fb
webcommands: define web commands using a decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23992
diff
changeset
|
351 |
@webcommand('changeset') |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5598
diff
changeset
|
352 |
def changeset(web, req, tmpl): |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
353 |
ctx = webutil.changectx(web.repo, req) |
17991
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17933
diff
changeset
|
354 |
basectx = webutil.basechangectx(web.repo, req) |
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17933
diff
changeset
|
355 |
if basectx is None: |
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17933
diff
changeset
|
356 |
basectx = ctx.p1() |
7310
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7305
diff
changeset
|
357 |
showtags = webutil.showtag(web.repo, tmpl, 'changesettag', ctx.node()) |
13596
270f57d35525
hgweb: add display of bookmarks for changelog and changeset
Alexander Solovyov <alexander@solovyov.net>
parents:
13199
diff
changeset
|
358 |
showbookmarks = webutil.showbookmark(web.repo, tmpl, 'changesetbookmark', |
270f57d35525
hgweb: add display of bookmarks for changelog and changeset
Alexander Solovyov <alexander@solovyov.net>
parents:
13199
diff
changeset
|
359 |
ctx.node()) |
7410
f1111704061e
coal/paper: show branch name in changeset view
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7409
diff
changeset
|
360 |
showbranch = webutil.nodebranchnodefault(ctx) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
361 |
|
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
362 |
files = [] |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
363 |
parity = paritygen(web.stripecount) |
16308
2695aaf4eb72
hgweb: add block numbers to diff regions and related links
Paul Boddie <paul@boddie.org.uk>
parents:
16129
diff
changeset
|
364 |
for blockno, f in enumerate(ctx.files()): |
7182
295af5bc1bcc
hgweb: remove links to non-existent file versions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7107
diff
changeset
|
365 |
template = f in ctx and 'filenodelink' or 'filenolink' |
295af5bc1bcc
hgweb: remove links to non-existent file versions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7107
diff
changeset
|
366 |
files.append(tmpl(template, |
16308
2695aaf4eb72
hgweb: add block numbers to diff regions and related links
Paul Boddie <paul@boddie.org.uk>
parents:
16129
diff
changeset
|
367 |
node=ctx.hex(), file=f, blockno=blockno + 1, |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
368 |
parity=parity.next())) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
369 |
|
9402
5d49fdef6fd0
hgweb: show diff header line in raw diffs
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8842
diff
changeset
|
370 |
style = web.config('web', 'style', 'paper') |
5d49fdef6fd0
hgweb: show diff header line in raw diffs
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8842
diff
changeset
|
371 |
if 'style' in req.form: |
5d49fdef6fd0
hgweb: show diff header line in raw diffs
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8842
diff
changeset
|
372 |
style = req.form['style'][0] |
5d49fdef6fd0
hgweb: show diff header line in raw diffs
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8842
diff
changeset
|
373 |
|
14490
1d3e2349304a
web: provide diffstat to the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents:
14055
diff
changeset
|
374 |
parity = paritygen(web.stripecount) |
17991
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17933
diff
changeset
|
375 |
diffs = webutil.diffs(web.repo, tmpl, ctx, basectx, None, parity, style) |
14490
1d3e2349304a
web: provide diffstat to the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents:
14055
diff
changeset
|
376 |
|
1d3e2349304a
web: provide diffstat to the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents:
14055
diff
changeset
|
377 |
parity = paritygen(web.stripecount) |
17991
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17933
diff
changeset
|
378 |
diffstatgen = webutil.diffstatgen(ctx, basectx) |
14570
9f908ef5a595
web: provide diff summary to the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents:
14514
diff
changeset
|
379 |
diffstat = webutil.diffstat(tmpl, ctx, diffstatgen, parity) |
14490
1d3e2349304a
web: provide diffstat to the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents:
14055
diff
changeset
|
380 |
|
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
381 |
return tmpl('changeset', |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
382 |
diff=diffs, |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
383 |
rev=ctx.rev(), |
7310
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7305
diff
changeset
|
384 |
node=ctx.hex(), |
23740
9e1f4c65f5f5
hgweb: allow viewing diffs against p1 or p2 for merge commits (issue3904)
Anton Shestakov <engored@ya.ru>
parents:
23689
diff
changeset
|
385 |
parent=tuple(webutil.parents(ctx)), |
7671
06cf09c822c4
hgweb: simplify parents/children generation code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7637
diff
changeset
|
386 |
child=webutil.children(ctx), |
18524
66ae2ded0968
hgweb: rename 'currentbaseline' template keyword to 'basenode'
Kevin Bullock <kbullock@ringworld.org>
parents:
18497
diff
changeset
|
387 |
basenode=basectx.hex(), |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
388 |
changesettag=showtags, |
13596
270f57d35525
hgweb: add display of bookmarks for changelog and changeset
Alexander Solovyov <alexander@solovyov.net>
parents:
13199
diff
changeset
|
389 |
changesetbookmark=showbookmarks, |
7410
f1111704061e
coal/paper: show branch name in changeset view
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7409
diff
changeset
|
390 |
changesetbranch=showbranch, |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
391 |
author=ctx.user(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
392 |
desc=ctx.description(), |
18581
3490c91a1fcb
templates: export extra as a dict to templates
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
18563
diff
changeset
|
393 |
extra=ctx.extra(), |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
394 |
date=ctx.date(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
395 |
files=files, |
14570
9f908ef5a595
web: provide diff summary to the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents:
14514
diff
changeset
|
396 |
diffsummary=lambda **x: webutil.diffsummary(diffstatgen), |
14490
1d3e2349304a
web: provide diffstat to the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents:
14055
diff
changeset
|
397 |
diffstat=diffstat, |
7310
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7305
diff
changeset
|
398 |
archives=web.archivelist(ctx.hex()), |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7305
diff
changeset
|
399 |
tags=webutil.nodetagsdict(web.repo, ctx.node()), |
13596
270f57d35525
hgweb: add display of bookmarks for changelog and changeset
Alexander Solovyov <alexander@solovyov.net>
parents:
13199
diff
changeset
|
400 |
bookmarks=webutil.nodebookmarksdict(web.repo, ctx.node()), |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
401 |
branch=webutil.nodebranchnodefault(ctx), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
402 |
inbranch=webutil.nodeinbranch(web.repo, ctx), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
403 |
branches=webutil.nodebranchdict(web.repo, ctx)) |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
404 |
|
24076
b53d2afd11fb
webcommands: define web commands using a decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23992
diff
changeset
|
405 |
rev = webcommand('rev')(changeset) |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
406 |
|
16448
e6b45e9a75dc
hgweb: add hook for remapping repository path into virtual paths
Martin Geisler <mg@lazybytes.net>
parents:
16308
diff
changeset
|
407 |
def decodepath(path): |
e6b45e9a75dc
hgweb: add hook for remapping repository path into virtual paths
Martin Geisler <mg@lazybytes.net>
parents:
16308
diff
changeset
|
408 |
"""Hook for mapping a path in the repository to a path in the |
e6b45e9a75dc
hgweb: add hook for remapping repository path into virtual paths
Martin Geisler <mg@lazybytes.net>
parents:
16308
diff
changeset
|
409 |
working copy. |
e6b45e9a75dc
hgweb: add hook for remapping repository path into virtual paths
Martin Geisler <mg@lazybytes.net>
parents:
16308
diff
changeset
|
410 |
|
e6b45e9a75dc
hgweb: add hook for remapping repository path into virtual paths
Martin Geisler <mg@lazybytes.net>
parents:
16308
diff
changeset
|
411 |
Extensions (e.g., largefiles) can override this to remap files in |
e6b45e9a75dc
hgweb: add hook for remapping repository path into virtual paths
Martin Geisler <mg@lazybytes.net>
parents:
16308
diff
changeset
|
412 |
the virtual file system presented by the manifest command below.""" |
e6b45e9a75dc
hgweb: add hook for remapping repository path into virtual paths
Martin Geisler <mg@lazybytes.net>
parents:
16308
diff
changeset
|
413 |
return path |
e6b45e9a75dc
hgweb: add hook for remapping repository path into virtual paths
Martin Geisler <mg@lazybytes.net>
parents:
16308
diff
changeset
|
414 |
|
24076
b53d2afd11fb
webcommands: define web commands using a decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23992
diff
changeset
|
415 |
@webcommand('manifest') |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5598
diff
changeset
|
416 |
def manifest(web, req, tmpl): |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
417 |
ctx = webutil.changectx(web.repo, req) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
418 |
path = webutil.cleanpath(web.repo, req.form.get('file', [''])[0]) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
419 |
mf = ctx.manifest() |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
420 |
node = ctx.node() |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
421 |
|
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
422 |
files = {} |
7305
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
423 |
dirs = {} |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
424 |
parity = paritygen(web.stripecount) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
425 |
|
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
426 |
if path and path[-1] != "/": |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
427 |
path += "/" |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
428 |
l = len(path) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
429 |
abspath = "/" + path |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
430 |
|
16448
e6b45e9a75dc
hgweb: add hook for remapping repository path into virtual paths
Martin Geisler <mg@lazybytes.net>
parents:
16308
diff
changeset
|
431 |
for full, n in mf.iteritems(): |
e6b45e9a75dc
hgweb: add hook for remapping repository path into virtual paths
Martin Geisler <mg@lazybytes.net>
parents:
16308
diff
changeset
|
432 |
# the virtual path (working copy path) used for the full |
e6b45e9a75dc
hgweb: add hook for remapping repository path into virtual paths
Martin Geisler <mg@lazybytes.net>
parents:
16308
diff
changeset
|
433 |
# (repository) path |
e6b45e9a75dc
hgweb: add hook for remapping repository path into virtual paths
Martin Geisler <mg@lazybytes.net>
parents:
16308
diff
changeset
|
434 |
f = decodepath(full) |
e6b45e9a75dc
hgweb: add hook for remapping repository path into virtual paths
Martin Geisler <mg@lazybytes.net>
parents:
16308
diff
changeset
|
435 |
|
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
436 |
if f[:l] != path: |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
437 |
continue |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
438 |
remain = f[l:] |
7305
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
439 |
elements = remain.split('/') |
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
440 |
if len(elements) == 1: |
16448
e6b45e9a75dc
hgweb: add hook for remapping repository path into virtual paths
Martin Geisler <mg@lazybytes.net>
parents:
16308
diff
changeset
|
441 |
files[remain] = full |
7305
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
442 |
else: |
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
443 |
h = dirs # need to retain ref to dirs (root) |
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
444 |
for elem in elements[0:-1]: |
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
445 |
if elem not in h: |
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
446 |
h[elem] = {} |
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
447 |
h = h[elem] |
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
448 |
if len(h) > 1: |
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
449 |
break |
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
450 |
h[None] = None # denotes files present |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
451 |
|
7565
5f162f61e479
hgweb: fix problems with empty repositories
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7434
diff
changeset
|
452 |
if mf and not files and not dirs: |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
453 |
raise ErrorResponse(HTTP_NOT_FOUND, 'path not found: ' + path) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
454 |
|
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
455 |
def filelist(**map): |
8209
a1a5a57efe90
replace util.sort with sorted built-in
Matt Mackall <mpm@selenic.com>
parents:
7966
diff
changeset
|
456 |
for f in sorted(files): |
7305
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
457 |
full = files[f] |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
458 |
|
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
459 |
fctx = ctx.filectx(full) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
460 |
yield {"file": full, |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
461 |
"parity": parity.next(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
462 |
"basename": f, |
6747
f6c00b17387c
use repo[changeid] to get a changectx
Matt Mackall <mpm@selenic.com>
parents:
6720
diff
changeset
|
463 |
"date": fctx.date(), |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
464 |
"size": fctx.size(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
465 |
"permissions": mf.flags(full)} |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
466 |
|
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
467 |
def dirlist(**map): |
8209
a1a5a57efe90
replace util.sort with sorted built-in
Matt Mackall <mpm@selenic.com>
parents:
7966
diff
changeset
|
468 |
for d in sorted(dirs): |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
469 |
|
7305
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
470 |
emptydirs = [] |
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
471 |
h = dirs[d] |
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
472 |
while isinstance(h, dict) and len(h) == 1: |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
473 |
k, v = h.items()[0] |
7305
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
474 |
if v: |
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
475 |
emptydirs.append(k) |
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
476 |
h = v |
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
477 |
|
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
478 |
path = "%s%s" % (abspath, d) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
479 |
yield {"parity": parity.next(), |
7305
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
480 |
"path": path, |
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
481 |
"emptydirs": "/".join(emptydirs), |
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
482 |
"basename": d} |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
483 |
|
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
484 |
return tmpl("manifest", |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
485 |
rev=ctx.rev(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
486 |
node=hex(node), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
487 |
path=abspath, |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
488 |
up=webutil.up(abspath), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
489 |
upparity=parity.next(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
490 |
fentries=filelist, |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
491 |
dentries=dirlist, |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
492 |
archives=web.archivelist(hex(node)), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
493 |
tags=webutil.nodetagsdict(web.repo, node), |
13794
5c18a0bca26f
hgweb: add bookmark labels to monoblue theme (based on 270f57d35525)
Yuya Nishihara <yuya@tcha.org>
parents:
13597
diff
changeset
|
494 |
bookmarks=webutil.nodebookmarksdict(web.repo, node), |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
495 |
inbranch=webutil.nodeinbranch(web.repo, ctx), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
496 |
branches=webutil.nodebranchdict(web.repo, ctx)) |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
497 |
|
24076
b53d2afd11fb
webcommands: define web commands using a decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23992
diff
changeset
|
498 |
@webcommand('tags') |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5598
diff
changeset
|
499 |
def tags(web, req, tmpl): |
18029
109a6a9dcca8
hgweb: fix iterator reuse in atom feed generation
Matt Mackall <mpm@selenic.com>
parents:
17322
diff
changeset
|
500 |
i = list(reversed(web.repo.tagslist())) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
501 |
parity = paritygen(web.stripecount) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
502 |
|
18402
bfba6d954108
hgweb: `limit` argument is actually `latestonly` renames and enforce
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18352
diff
changeset
|
503 |
def entries(notip, latestonly, **map): |
bfba6d954108
hgweb: `limit` argument is actually `latestonly` renames and enforce
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18352
diff
changeset
|
504 |
t = i |
bfba6d954108
hgweb: `limit` argument is actually `latestonly` renames and enforce
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18352
diff
changeset
|
505 |
if notip: |
bfba6d954108
hgweb: `limit` argument is actually `latestonly` renames and enforce
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18352
diff
changeset
|
506 |
t = [(k, n) for k, n in i if k != "tip"] |
bfba6d954108
hgweb: `limit` argument is actually `latestonly` renames and enforce
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18352
diff
changeset
|
507 |
if latestonly: |
bfba6d954108
hgweb: `limit` argument is actually `latestonly` renames and enforce
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18352
diff
changeset
|
508 |
t = t[:1] |
bfba6d954108
hgweb: `limit` argument is actually `latestonly` renames and enforce
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18352
diff
changeset
|
509 |
for k, n in t: |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
510 |
yield {"parity": parity.next(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
511 |
"tag": k, |
6747
f6c00b17387c
use repo[changeid] to get a changectx
Matt Mackall <mpm@selenic.com>
parents:
6720
diff
changeset
|
512 |
"date": web.repo[n].date(), |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
513 |
"node": hex(n)} |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
514 |
|
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
515 |
return tmpl("tags", |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
516 |
node=hex(web.repo.changelog.tip()), |
18402
bfba6d954108
hgweb: `limit` argument is actually `latestonly` renames and enforce
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18352
diff
changeset
|
517 |
entries=lambda **x: entries(False, False, **x), |
bfba6d954108
hgweb: `limit` argument is actually `latestonly` renames and enforce
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18352
diff
changeset
|
518 |
entriesnotip=lambda **x: entries(True, False, **x), |
bfba6d954108
hgweb: `limit` argument is actually `latestonly` renames and enforce
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18352
diff
changeset
|
519 |
latestentry=lambda **x: entries(True, True, **x)) |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
520 |
|
24076
b53d2afd11fb
webcommands: define web commands using a decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23992
diff
changeset
|
521 |
@webcommand('bookmarks') |
13597
38c9837b1f75
hgweb: add separate page with bookmarks listing
Alexander Solovyov <alexander@solovyov.net>
parents:
13596
diff
changeset
|
522 |
def bookmarks(web, req, tmpl): |
24083
5fbb5217a6c8
webcommands: document "bookmarks" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24082
diff
changeset
|
523 |
""" |
5fbb5217a6c8
webcommands: document "bookmarks" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24082
diff
changeset
|
524 |
/bookmarks |
5fbb5217a6c8
webcommands: document "bookmarks" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24082
diff
changeset
|
525 |
---------- |
5fbb5217a6c8
webcommands: document "bookmarks" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24082
diff
changeset
|
526 |
|
5fbb5217a6c8
webcommands: document "bookmarks" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24082
diff
changeset
|
527 |
Show information about bookmarks. |
5fbb5217a6c8
webcommands: document "bookmarks" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24082
diff
changeset
|
528 |
|
5fbb5217a6c8
webcommands: document "bookmarks" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24082
diff
changeset
|
529 |
No arguments are accepted. |
5fbb5217a6c8
webcommands: document "bookmarks" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24082
diff
changeset
|
530 |
|
5fbb5217a6c8
webcommands: document "bookmarks" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24082
diff
changeset
|
531 |
The ``bookmarks`` template is rendered. |
5fbb5217a6c8
webcommands: document "bookmarks" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24082
diff
changeset
|
532 |
""" |
18478
886936ecc21b
hgweb: don't attempt to show hidden bookmarks (issue3774)
Kevin Bullock <kbullock@ringworld.org>
parents:
18477
diff
changeset
|
533 |
i = [b for b in web.repo._bookmarks.items() if b[1] in web.repo] |
13597
38c9837b1f75
hgweb: add separate page with bookmarks listing
Alexander Solovyov <alexander@solovyov.net>
parents:
13596
diff
changeset
|
534 |
parity = paritygen(web.stripecount) |
38c9837b1f75
hgweb: add separate page with bookmarks listing
Alexander Solovyov <alexander@solovyov.net>
parents:
13596
diff
changeset
|
535 |
|
18402
bfba6d954108
hgweb: `limit` argument is actually `latestonly` renames and enforce
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18352
diff
changeset
|
536 |
def entries(latestonly, **map): |
bfba6d954108
hgweb: `limit` argument is actually `latestonly` renames and enforce
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18352
diff
changeset
|
537 |
if latestonly: |
bfba6d954108
hgweb: `limit` argument is actually `latestonly` renames and enforce
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18352
diff
changeset
|
538 |
t = [min(i)] |
bfba6d954108
hgweb: `limit` argument is actually `latestonly` renames and enforce
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18352
diff
changeset
|
539 |
else: |
bfba6d954108
hgweb: `limit` argument is actually `latestonly` renames and enforce
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18352
diff
changeset
|
540 |
t = sorted(i) |
bfba6d954108
hgweb: `limit` argument is actually `latestonly` renames and enforce
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18352
diff
changeset
|
541 |
for k, n in t: |
13597
38c9837b1f75
hgweb: add separate page with bookmarks listing
Alexander Solovyov <alexander@solovyov.net>
parents:
13596
diff
changeset
|
542 |
yield {"parity": parity.next(), |
38c9837b1f75
hgweb: add separate page with bookmarks listing
Alexander Solovyov <alexander@solovyov.net>
parents:
13596
diff
changeset
|
543 |
"bookmark": k, |
38c9837b1f75
hgweb: add separate page with bookmarks listing
Alexander Solovyov <alexander@solovyov.net>
parents:
13596
diff
changeset
|
544 |
"date": web.repo[n].date(), |
38c9837b1f75
hgweb: add separate page with bookmarks listing
Alexander Solovyov <alexander@solovyov.net>
parents:
13596
diff
changeset
|
545 |
"node": hex(n)} |
38c9837b1f75
hgweb: add separate page with bookmarks listing
Alexander Solovyov <alexander@solovyov.net>
parents:
13596
diff
changeset
|
546 |
|
38c9837b1f75
hgweb: add separate page with bookmarks listing
Alexander Solovyov <alexander@solovyov.net>
parents:
13596
diff
changeset
|
547 |
return tmpl("bookmarks", |
38c9837b1f75
hgweb: add separate page with bookmarks listing
Alexander Solovyov <alexander@solovyov.net>
parents:
13596
diff
changeset
|
548 |
node=hex(web.repo.changelog.tip()), |
18402
bfba6d954108
hgweb: `limit` argument is actually `latestonly` renames and enforce
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18352
diff
changeset
|
549 |
entries=lambda **x: entries(latestonly=False, **x), |
bfba6d954108
hgweb: `limit` argument is actually `latestonly` renames and enforce
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18352
diff
changeset
|
550 |
latestentry=lambda **x: entries(latestonly=True, **x)) |
13597
38c9837b1f75
hgweb: add separate page with bookmarks listing
Alexander Solovyov <alexander@solovyov.net>
parents:
13596
diff
changeset
|
551 |
|
24076
b53d2afd11fb
webcommands: define web commands using a decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23992
diff
changeset
|
552 |
@webcommand('branches') |
8352
eefcb59d44d6
webcommands: add 'branches' command, similar to 'tags'
Sune Foldager <cryo@cyanite.org>
parents:
8236
diff
changeset
|
553 |
def branches(web, req, tmpl): |
24082
32dabf811b39
webcommands: document "branches" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24081
diff
changeset
|
554 |
""" |
32dabf811b39
webcommands: document "branches" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24081
diff
changeset
|
555 |
/branches |
32dabf811b39
webcommands: document "branches" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24081
diff
changeset
|
556 |
--------- |
32dabf811b39
webcommands: document "branches" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24081
diff
changeset
|
557 |
|
32dabf811b39
webcommands: document "branches" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24081
diff
changeset
|
558 |
Show information about branches. |
32dabf811b39
webcommands: document "branches" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24081
diff
changeset
|
559 |
|
32dabf811b39
webcommands: document "branches" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24081
diff
changeset
|
560 |
All known branches are contained in the output, even closed branches. |
32dabf811b39
webcommands: document "branches" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24081
diff
changeset
|
561 |
|
32dabf811b39
webcommands: document "branches" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24081
diff
changeset
|
562 |
No arguments are accepted. |
32dabf811b39
webcommands: document "branches" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24081
diff
changeset
|
563 |
|
32dabf811b39
webcommands: document "branches" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24081
diff
changeset
|
564 |
The ``branches`` template is rendered. |
32dabf811b39
webcommands: document "branches" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24081
diff
changeset
|
565 |
""" |
18030
ebc0fa067c07
hgweb: avoid generator exhaustion with branches
Matt Mackall <mpm@selenic.com>
parents:
18029
diff
changeset
|
566 |
tips = [] |
8796
2bcef677a6c3
localrepo: remove 'closed' argument to heads(...) function
John Mulligan <phlogistonjohn@asynchrono.us>
parents:
8713
diff
changeset
|
567 |
heads = web.repo.heads() |
8352
eefcb59d44d6
webcommands: add 'branches' command, similar to 'tags'
Sune Foldager <cryo@cyanite.org>
parents:
8236
diff
changeset
|
568 |
parity = paritygen(web.stripecount) |
20194
9985e188d940
hgweb: simplify branches with repo.branchmap().iterbranches()
Brodie Rao <brodie@sf.io>
parents:
20193
diff
changeset
|
569 |
sortkey = lambda item: (not item[1], item[0].rev()) |
8352
eefcb59d44d6
webcommands: add 'branches' command, similar to 'tags'
Sune Foldager <cryo@cyanite.org>
parents:
8236
diff
changeset
|
570 |
|
eefcb59d44d6
webcommands: add 'branches' command, similar to 'tags'
Sune Foldager <cryo@cyanite.org>
parents:
8236
diff
changeset
|
571 |
def entries(limit, **map): |
eefcb59d44d6
webcommands: add 'branches' command, similar to 'tags'
Sune Foldager <cryo@cyanite.org>
parents:
8236
diff
changeset
|
572 |
count = 0 |
18030
ebc0fa067c07
hgweb: avoid generator exhaustion with branches
Matt Mackall <mpm@selenic.com>
parents:
18029
diff
changeset
|
573 |
if not tips: |
20194
9985e188d940
hgweb: simplify branches with repo.branchmap().iterbranches()
Brodie Rao <brodie@sf.io>
parents:
20193
diff
changeset
|
574 |
for tag, hs, tip, closed in web.repo.branchmap().iterbranches(): |
9985e188d940
hgweb: simplify branches with repo.branchmap().iterbranches()
Brodie Rao <brodie@sf.io>
parents:
20193
diff
changeset
|
575 |
tips.append((web.repo[tip], closed)) |
9985e188d940
hgweb: simplify branches with repo.branchmap().iterbranches()
Brodie Rao <brodie@sf.io>
parents:
20193
diff
changeset
|
576 |
for ctx, closed in sorted(tips, key=sortkey, reverse=True): |
8352
eefcb59d44d6
webcommands: add 'branches' command, similar to 'tags'
Sune Foldager <cryo@cyanite.org>
parents:
8236
diff
changeset
|
577 |
if limit > 0 and count >= limit: |
eefcb59d44d6
webcommands: add 'branches' command, similar to 'tags'
Sune Foldager <cryo@cyanite.org>
parents:
8236
diff
changeset
|
578 |
return |
eefcb59d44d6
webcommands: add 'branches' command, similar to 'tags'
Sune Foldager <cryo@cyanite.org>
parents:
8236
diff
changeset
|
579 |
count += 1 |
20194
9985e188d940
hgweb: simplify branches with repo.branchmap().iterbranches()
Brodie Rao <brodie@sf.io>
parents:
20193
diff
changeset
|
580 |
if closed: |
14771
0cc66f13bea0
hgweb: treat branch attribute `closed' as more important than `inactive'
Jesse Long <jpl@unknown.za.net>
parents:
14570
diff
changeset
|
581 |
status = 'closed' |
0cc66f13bea0
hgweb: treat branch attribute `closed' as more important than `inactive'
Jesse Long <jpl@unknown.za.net>
parents:
14570
diff
changeset
|
582 |
elif ctx.node() not in heads: |
8796
2bcef677a6c3
localrepo: remove 'closed' argument to heads(...) function
John Mulligan <phlogistonjohn@asynchrono.us>
parents:
8713
diff
changeset
|
583 |
status = 'inactive' |
2bcef677a6c3
localrepo: remove 'closed' argument to heads(...) function
John Mulligan <phlogistonjohn@asynchrono.us>
parents:
8713
diff
changeset
|
584 |
else: |
2bcef677a6c3
localrepo: remove 'closed' argument to heads(...) function
John Mulligan <phlogistonjohn@asynchrono.us>
parents:
8713
diff
changeset
|
585 |
status = 'open' |
8352
eefcb59d44d6
webcommands: add 'branches' command, similar to 'tags'
Sune Foldager <cryo@cyanite.org>
parents:
8236
diff
changeset
|
586 |
yield {'parity': parity.next(), |
8354
418ea63f00fb
hgweb: use context api in branches webcommand
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8352
diff
changeset
|
587 |
'branch': ctx.branch(), |
8713
de6bb29e208a
hgweb: allow distinction between open/closed branches on branches page
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8390
diff
changeset
|
588 |
'status': status, |
8354
418ea63f00fb
hgweb: use context api in branches webcommand
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8352
diff
changeset
|
589 |
'node': ctx.hex(), |
418ea63f00fb
hgweb: use context api in branches webcommand
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8352
diff
changeset
|
590 |
'date': ctx.date()} |
8352
eefcb59d44d6
webcommands: add 'branches' command, similar to 'tags'
Sune Foldager <cryo@cyanite.org>
parents:
8236
diff
changeset
|
591 |
|
eefcb59d44d6
webcommands: add 'branches' command, similar to 'tags'
Sune Foldager <cryo@cyanite.org>
parents:
8236
diff
changeset
|
592 |
return tmpl('branches', node=hex(web.repo.changelog.tip()), |
eefcb59d44d6
webcommands: add 'branches' command, similar to 'tags'
Sune Foldager <cryo@cyanite.org>
parents:
8236
diff
changeset
|
593 |
entries=lambda **x: entries(0, **x), |
eefcb59d44d6
webcommands: add 'branches' command, similar to 'tags'
Sune Foldager <cryo@cyanite.org>
parents:
8236
diff
changeset
|
594 |
latestentry=lambda **x: entries(1, **x)) |
eefcb59d44d6
webcommands: add 'branches' command, similar to 'tags'
Sune Foldager <cryo@cyanite.org>
parents:
8236
diff
changeset
|
595 |
|
24076
b53d2afd11fb
webcommands: define web commands using a decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23992
diff
changeset
|
596 |
@webcommand('summary') |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5598
diff
changeset
|
597 |
def summary(web, req, tmpl): |
17261
c0068b058fcd
webcommands: do not modify repo.tagslist()
Patrick Mezard <patrick@mezard.eu>
parents:
17202
diff
changeset
|
598 |
i = reversed(web.repo.tagslist()) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
599 |
|
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
600 |
def tagentries(**map): |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
601 |
parity = paritygen(web.stripecount) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
602 |
count = 0 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
603 |
for k, n in i: |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
604 |
if k == "tip": # skip tip |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
605 |
continue |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
606 |
|
6659
bc553c6d1ef9
webcommands: fix increments lost by 894875eae49b
Andrew Beekhof <beekhof@gmail.com>
parents:
6657
diff
changeset
|
607 |
count += 1 |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
608 |
if count > 10: # limit to 10 tags |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
609 |
break |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
610 |
|
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
611 |
yield tmpl("tagentry", |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
612 |
parity=parity.next(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
613 |
tag=k, |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
614 |
node=hex(n), |
6747
f6c00b17387c
use repo[changeid] to get a changectx
Matt Mackall <mpm@selenic.com>
parents:
6720
diff
changeset
|
615 |
date=web.repo[n].date()) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
616 |
|
13924
ea726c97c1b6
hgweb: add bookmarks listing to summary page of gitweb/monoblue styles
Yuya Nishihara <yuya@tcha.org>
parents:
13923
diff
changeset
|
617 |
def bookmarks(**map): |
ea726c97c1b6
hgweb: add bookmarks listing to summary page of gitweb/monoblue styles
Yuya Nishihara <yuya@tcha.org>
parents:
13923
diff
changeset
|
618 |
parity = paritygen(web.stripecount) |
18563
6d098adc5a46
hgweb: make 'summary' work with hidden changesets (issue3810)
Kevin Bullock <kbullock@ringworld.org>
parents:
18524
diff
changeset
|
619 |
marks = [b for b in web.repo._bookmarks.items() if b[1] in web.repo] |
6d098adc5a46
hgweb: make 'summary' work with hidden changesets (issue3810)
Kevin Bullock <kbullock@ringworld.org>
parents:
18524
diff
changeset
|
620 |
for k, n in sorted(marks)[:10]: # limit to 10 bookmarks |
13924
ea726c97c1b6
hgweb: add bookmarks listing to summary page of gitweb/monoblue styles
Yuya Nishihara <yuya@tcha.org>
parents:
13923
diff
changeset
|
621 |
yield {'parity': parity.next(), |
ea726c97c1b6
hgweb: add bookmarks listing to summary page of gitweb/monoblue styles
Yuya Nishihara <yuya@tcha.org>
parents:
13923
diff
changeset
|
622 |
'bookmark': k, |
ea726c97c1b6
hgweb: add bookmarks listing to summary page of gitweb/monoblue styles
Yuya Nishihara <yuya@tcha.org>
parents:
13923
diff
changeset
|
623 |
'date': web.repo[n].date(), |
ea726c97c1b6
hgweb: add bookmarks listing to summary page of gitweb/monoblue styles
Yuya Nishihara <yuya@tcha.org>
parents:
13923
diff
changeset
|
624 |
'node': hex(n)} |
ea726c97c1b6
hgweb: add bookmarks listing to summary page of gitweb/monoblue styles
Yuya Nishihara <yuya@tcha.org>
parents:
13923
diff
changeset
|
625 |
|
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
626 |
def branches(**map): |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
627 |
parity = paritygen(web.stripecount) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
628 |
|
20193
7d40e706412c
hgweb: simplify summary with repo.branchmap().iterbranches()
Brodie Rao <brodie@sf.io>
parents:
20095
diff
changeset
|
629 |
b = web.repo.branchmap() |
7d40e706412c
hgweb: simplify summary with repo.branchmap().iterbranches()
Brodie Rao <brodie@sf.io>
parents:
20095
diff
changeset
|
630 |
l = [(-web.repo.changelog.rev(tip), tip, tag) |
7d40e706412c
hgweb: simplify summary with repo.branchmap().iterbranches()
Brodie Rao <brodie@sf.io>
parents:
20095
diff
changeset
|
631 |
for tag, heads, tip, closed in b.iterbranches()] |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
632 |
for r, n, t in sorted(l): |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
633 |
yield {'parity': parity.next(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
634 |
'branch': t, |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
635 |
'node': hex(n), |
6747
f6c00b17387c
use repo[changeid] to get a changectx
Matt Mackall <mpm@selenic.com>
parents:
6720
diff
changeset
|
636 |
'date': web.repo[n].date()} |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
637 |
|
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
638 |
def changelist(**map): |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
639 |
parity = paritygen(web.stripecount, offset=start - end) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
640 |
l = [] # build a list in forward order for efficiency |
18563
6d098adc5a46
hgweb: make 'summary' work with hidden changesets (issue3810)
Kevin Bullock <kbullock@ringworld.org>
parents:
18524
diff
changeset
|
641 |
revs = [] |
6d098adc5a46
hgweb: make 'summary' work with hidden changesets (issue3810)
Kevin Bullock <kbullock@ringworld.org>
parents:
18524
diff
changeset
|
642 |
if start < end: |
6d098adc5a46
hgweb: make 'summary' work with hidden changesets (issue3810)
Kevin Bullock <kbullock@ringworld.org>
parents:
18524
diff
changeset
|
643 |
revs = web.repo.changelog.revs(start, end - 1) |
6d098adc5a46
hgweb: make 'summary' work with hidden changesets (issue3810)
Kevin Bullock <kbullock@ringworld.org>
parents:
18524
diff
changeset
|
644 |
for i in revs: |
6747
f6c00b17387c
use repo[changeid] to get a changectx
Matt Mackall <mpm@selenic.com>
parents:
6720
diff
changeset
|
645 |
ctx = web.repo[i] |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
646 |
n = ctx.node() |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
647 |
hn = hex(n) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
648 |
|
18319
e350ce798b63
hgweb: no do not use listinsert(0, ...)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18037
diff
changeset
|
649 |
l.append(tmpl( |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
650 |
'shortlogentry', |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
651 |
parity=parity.next(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
652 |
author=ctx.user(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
653 |
desc=ctx.description(), |
18581
3490c91a1fcb
templates: export extra as a dict to templates
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
18563
diff
changeset
|
654 |
extra=ctx.extra(), |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
655 |
date=ctx.date(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
656 |
rev=i, |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
657 |
node=hn, |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
658 |
tags=webutil.nodetagsdict(web.repo, n), |
13794
5c18a0bca26f
hgweb: add bookmark labels to monoblue theme (based on 270f57d35525)
Yuya Nishihara <yuya@tcha.org>
parents:
13597
diff
changeset
|
659 |
bookmarks=webutil.nodebookmarksdict(web.repo, n), |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
660 |
inbranch=webutil.nodeinbranch(web.repo, ctx), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
661 |
branches=webutil.nodebranchdict(web.repo, ctx))) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
662 |
|
18319
e350ce798b63
hgweb: no do not use listinsert(0, ...)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18037
diff
changeset
|
663 |
l.reverse() |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
664 |
yield l |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
665 |
|
12059
0de6cfdcaad8
webcommands: remove unncessary access to repo.changelog
Patrick Mezard <pmezard@gmail.com>
parents:
11332
diff
changeset
|
666 |
tip = web.repo['tip'] |
0de6cfdcaad8
webcommands: remove unncessary access to repo.changelog
Patrick Mezard <pmezard@gmail.com>
parents:
11332
diff
changeset
|
667 |
count = len(web.repo) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
668 |
start = max(0, count - web.maxchanges) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
669 |
end = min(count, start + web.maxchanges) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
670 |
|
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
671 |
return tmpl("summary", |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
672 |
desc=web.config("web", "description", "unknown"), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
673 |
owner=get_contact(web.config) or "unknown", |
12059
0de6cfdcaad8
webcommands: remove unncessary access to repo.changelog
Patrick Mezard <pmezard@gmail.com>
parents:
11332
diff
changeset
|
674 |
lastchange=tip.date(), |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
675 |
tags=tagentries, |
13924
ea726c97c1b6
hgweb: add bookmarks listing to summary page of gitweb/monoblue styles
Yuya Nishihara <yuya@tcha.org>
parents:
13923
diff
changeset
|
676 |
bookmarks=bookmarks, |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
677 |
branches=branches, |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
678 |
shortlog=changelist, |
12059
0de6cfdcaad8
webcommands: remove unncessary access to repo.changelog
Patrick Mezard <pmezard@gmail.com>
parents:
11332
diff
changeset
|
679 |
node=tip.hex(), |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
680 |
archives=web.archivelist("tip")) |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
681 |
|
24076
b53d2afd11fb
webcommands: define web commands using a decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23992
diff
changeset
|
682 |
@webcommand('filediff') |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5598
diff
changeset
|
683 |
def filediff(web, req, tmpl): |
7183
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
684 |
fctx, ctx = None, None |
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
685 |
try: |
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
686 |
fctx = webutil.filectx(web.repo, req) |
7280
810ca383da9c
remove unused variables
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7183
diff
changeset
|
687 |
except LookupError: |
7183
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
688 |
ctx = webutil.changectx(web.repo, req) |
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
689 |
path = webutil.cleanpath(web.repo, req.form['file'][0]) |
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
690 |
if path not in ctx.files(): |
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
691 |
raise |
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
692 |
|
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
693 |
if fctx is not None: |
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
694 |
n = fctx.node() |
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
695 |
path = fctx.path() |
16722
7bf48bc7de23
hgweb: fix filediff base calculation
Matt Mackall <mpm@selenic.com>
parents:
16469
diff
changeset
|
696 |
ctx = fctx.changectx() |
7183
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
697 |
else: |
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
698 |
n = ctx.node() |
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
699 |
# path already defined in except clause |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
700 |
|
7310
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7305
diff
changeset
|
701 |
parity = paritygen(web.stripecount) |
9402
5d49fdef6fd0
hgweb: show diff header line in raw diffs
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8842
diff
changeset
|
702 |
style = web.config('web', 'style', 'paper') |
5d49fdef6fd0
hgweb: show diff header line in raw diffs
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8842
diff
changeset
|
703 |
if 'style' in req.form: |
5d49fdef6fd0
hgweb: show diff header line in raw diffs
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8842
diff
changeset
|
704 |
style = req.form['style'][0] |
5d49fdef6fd0
hgweb: show diff header line in raw diffs
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8842
diff
changeset
|
705 |
|
17991
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17933
diff
changeset
|
706 |
diffs = webutil.diffs(web.repo, tmpl, ctx, None, [path], parity, style) |
7183
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
707 |
rename = fctx and webutil.renamelink(fctx) or [] |
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
708 |
ctx = fctx and fctx or ctx |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
709 |
return tmpl("filediff", |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
710 |
file=path, |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
711 |
node=hex(n), |
7183
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
712 |
rev=ctx.rev(), |
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
713 |
date=ctx.date(), |
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
714 |
desc=ctx.description(), |
18581
3490c91a1fcb
templates: export extra as a dict to templates
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
18563
diff
changeset
|
715 |
extra=ctx.extra(), |
7183
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
716 |
author=ctx.user(), |
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
717 |
rename=rename, |
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
718 |
branch=webutil.nodebranchnodefault(ctx), |
7671
06cf09c822c4
hgweb: simplify parents/children generation code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7637
diff
changeset
|
719 |
parent=webutil.parents(ctx), |
06cf09c822c4
hgweb: simplify parents/children generation code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7637
diff
changeset
|
720 |
child=webutil.children(ctx), |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
721 |
diff=diffs) |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
722 |
|
24076
b53d2afd11fb
webcommands: define web commands using a decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23992
diff
changeset
|
723 |
diff = webcommand('diff')(filediff) |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
724 |
|
24076
b53d2afd11fb
webcommands: define web commands using a decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23992
diff
changeset
|
725 |
@webcommand('comparison') |
17202
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
17146
diff
changeset
|
726 |
def comparison(web, req, tmpl): |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
17146
diff
changeset
|
727 |
ctx = webutil.changectx(web.repo, req) |
17289
f2d6b4f8e78c
hgweb: avoid traceback when file or node parameters are missing
Ross Lagerwall <rosslagerwall@gmail.com>
parents:
17261
diff
changeset
|
728 |
if 'file' not in req.form: |
f2d6b4f8e78c
hgweb: avoid traceback when file or node parameters are missing
Ross Lagerwall <rosslagerwall@gmail.com>
parents:
17261
diff
changeset
|
729 |
raise ErrorResponse(HTTP_NOT_FOUND, 'file not given') |
17202
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
17146
diff
changeset
|
730 |
path = webutil.cleanpath(web.repo, req.form['file'][0]) |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
17146
diff
changeset
|
731 |
rename = path in ctx and webutil.renamelink(ctx[path]) or [] |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
17146
diff
changeset
|
732 |
|
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
17146
diff
changeset
|
733 |
parsecontext = lambda v: v == 'full' and -1 or int(v) |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
17146
diff
changeset
|
734 |
if 'context' in req.form: |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
17146
diff
changeset
|
735 |
context = parsecontext(req.form['context'][0]) |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
17146
diff
changeset
|
736 |
else: |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
17146
diff
changeset
|
737 |
context = parsecontext(web.config('web', 'comparisoncontext', '5')) |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
17146
diff
changeset
|
738 |
|
17302
5c64ce6168da
hgweb: fixes traceback for invalid files by removing top-level template
wujek srujek <wujek.srujek@googlemail.com>
parents:
17289
diff
changeset
|
739 |
def filelines(f): |
19657
145636d31bb4
hgweb: import the whole util module in webcommands instead of just one function
Alexander Plavin <alexander@plav.in>
parents:
19656
diff
changeset
|
740 |
if util.binary(f.data()): |
17302
5c64ce6168da
hgweb: fixes traceback for invalid files by removing top-level template
wujek srujek <wujek.srujek@googlemail.com>
parents:
17289
diff
changeset
|
741 |
mt = mimetypes.guess_type(f.path())[0] |
5c64ce6168da
hgweb: fixes traceback for invalid files by removing top-level template
wujek srujek <wujek.srujek@googlemail.com>
parents:
17289
diff
changeset
|
742 |
if not mt: |
5c64ce6168da
hgweb: fixes traceback for invalid files by removing top-level template
wujek srujek <wujek.srujek@googlemail.com>
parents:
17289
diff
changeset
|
743 |
mt = 'application/octet-stream' |
5c64ce6168da
hgweb: fixes traceback for invalid files by removing top-level template
wujek srujek <wujek.srujek@googlemail.com>
parents:
17289
diff
changeset
|
744 |
return [_('(binary file %s, hash: %s)') % (mt, hex(f.filenode()))] |
5c64ce6168da
hgweb: fixes traceback for invalid files by removing top-level template
wujek srujek <wujek.srujek@googlemail.com>
parents:
17289
diff
changeset
|
745 |
return f.data().splitlines() |
5c64ce6168da
hgweb: fixes traceback for invalid files by removing top-level template
wujek srujek <wujek.srujek@googlemail.com>
parents:
17289
diff
changeset
|
746 |
|
21123
92fab48dfec1
hgweb: show revisions and hashes gotten from changelog in "comparison" page
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21121
diff
changeset
|
747 |
parent = ctx.p1() |
92fab48dfec1
hgweb: show revisions and hashes gotten from changelog in "comparison" page
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21121
diff
changeset
|
748 |
leftrev = parent.rev() |
92fab48dfec1
hgweb: show revisions and hashes gotten from changelog in "comparison" page
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21121
diff
changeset
|
749 |
leftnode = parent.node() |
92fab48dfec1
hgweb: show revisions and hashes gotten from changelog in "comparison" page
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21121
diff
changeset
|
750 |
rightrev = ctx.rev() |
92fab48dfec1
hgweb: show revisions and hashes gotten from changelog in "comparison" page
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21121
diff
changeset
|
751 |
rightnode = ctx.node() |
17302
5c64ce6168da
hgweb: fixes traceback for invalid files by removing top-level template
wujek srujek <wujek.srujek@googlemail.com>
parents:
17289
diff
changeset
|
752 |
if path in ctx: |
5c64ce6168da
hgweb: fixes traceback for invalid files by removing top-level template
wujek srujek <wujek.srujek@googlemail.com>
parents:
17289
diff
changeset
|
753 |
fctx = ctx[path] |
5c64ce6168da
hgweb: fixes traceback for invalid files by removing top-level template
wujek srujek <wujek.srujek@googlemail.com>
parents:
17289
diff
changeset
|
754 |
rightlines = filelines(fctx) |
21121
8c9e84b44221
hgweb: make "comparison" get parent from not filelog but changelog
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20761
diff
changeset
|
755 |
if path not in parent: |
17302
5c64ce6168da
hgweb: fixes traceback for invalid files by removing top-level template
wujek srujek <wujek.srujek@googlemail.com>
parents:
17289
diff
changeset
|
756 |
leftlines = () |
5c64ce6168da
hgweb: fixes traceback for invalid files by removing top-level template
wujek srujek <wujek.srujek@googlemail.com>
parents:
17289
diff
changeset
|
757 |
else: |
21121
8c9e84b44221
hgweb: make "comparison" get parent from not filelog but changelog
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20761
diff
changeset
|
758 |
pfctx = parent[path] |
17302
5c64ce6168da
hgweb: fixes traceback for invalid files by removing top-level template
wujek srujek <wujek.srujek@googlemail.com>
parents:
17289
diff
changeset
|
759 |
leftlines = filelines(pfctx) |
5c64ce6168da
hgweb: fixes traceback for invalid files by removing top-level template
wujek srujek <wujek.srujek@googlemail.com>
parents:
17289
diff
changeset
|
760 |
else: |
5c64ce6168da
hgweb: fixes traceback for invalid files by removing top-level template
wujek srujek <wujek.srujek@googlemail.com>
parents:
17289
diff
changeset
|
761 |
rightlines = () |
5c64ce6168da
hgweb: fixes traceback for invalid files by removing top-level template
wujek srujek <wujek.srujek@googlemail.com>
parents:
17289
diff
changeset
|
762 |
fctx = ctx.parents()[0][path] |
5c64ce6168da
hgweb: fixes traceback for invalid files by removing top-level template
wujek srujek <wujek.srujek@googlemail.com>
parents:
17289
diff
changeset
|
763 |
leftlines = filelines(fctx) |
5c64ce6168da
hgweb: fixes traceback for invalid files by removing top-level template
wujek srujek <wujek.srujek@googlemail.com>
parents:
17289
diff
changeset
|
764 |
|
5c64ce6168da
hgweb: fixes traceback for invalid files by removing top-level template
wujek srujek <wujek.srujek@googlemail.com>
parents:
17289
diff
changeset
|
765 |
comparison = webutil.compare(tmpl, context, leftlines, rightlines) |
17202
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
17146
diff
changeset
|
766 |
return tmpl('filecomparison', |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
17146
diff
changeset
|
767 |
file=path, |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
17146
diff
changeset
|
768 |
node=hex(ctx.node()), |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
17146
diff
changeset
|
769 |
rev=ctx.rev(), |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
17146
diff
changeset
|
770 |
date=ctx.date(), |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
17146
diff
changeset
|
771 |
desc=ctx.description(), |
18581
3490c91a1fcb
templates: export extra as a dict to templates
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
18563
diff
changeset
|
772 |
extra=ctx.extra(), |
17202
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
17146
diff
changeset
|
773 |
author=ctx.user(), |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
17146
diff
changeset
|
774 |
rename=rename, |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
17146
diff
changeset
|
775 |
branch=webutil.nodebranchnodefault(ctx), |
17303
06217d3cf8d9
hgweb: fixes invalid parents / children in comparison
wujek srujek <wujek.srujek@googlemail.com>
parents:
17302
diff
changeset
|
776 |
parent=webutil.parents(fctx), |
06217d3cf8d9
hgweb: fixes invalid parents / children in comparison
wujek srujek <wujek.srujek@googlemail.com>
parents:
17302
diff
changeset
|
777 |
child=webutil.children(fctx), |
17302
5c64ce6168da
hgweb: fixes traceback for invalid files by removing top-level template
wujek srujek <wujek.srujek@googlemail.com>
parents:
17289
diff
changeset
|
778 |
leftrev=leftrev, |
5c64ce6168da
hgweb: fixes traceback for invalid files by removing top-level template
wujek srujek <wujek.srujek@googlemail.com>
parents:
17289
diff
changeset
|
779 |
leftnode=hex(leftnode), |
5c64ce6168da
hgweb: fixes traceback for invalid files by removing top-level template
wujek srujek <wujek.srujek@googlemail.com>
parents:
17289
diff
changeset
|
780 |
rightrev=rightrev, |
5c64ce6168da
hgweb: fixes traceback for invalid files by removing top-level template
wujek srujek <wujek.srujek@googlemail.com>
parents:
17289
diff
changeset
|
781 |
rightnode=hex(rightnode), |
17202
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
17146
diff
changeset
|
782 |
comparison=comparison) |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
17146
diff
changeset
|
783 |
|
24076
b53d2afd11fb
webcommands: define web commands using a decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23992
diff
changeset
|
784 |
@webcommand('annotate') |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5598
diff
changeset
|
785 |
def annotate(web, req, tmpl): |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
786 |
fctx = webutil.filectx(web.repo, req) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
787 |
f = fctx.path() |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
788 |
parity = paritygen(web.stripecount) |
23689
4fedf2a9b538
webcommands.annotate: explicitly only honor whitespace diffopts
Siddharth Agarwal <sid0@fb.com>
parents:
23232
diff
changeset
|
789 |
diffopts = patch.difffeatureopts(web.repo.ui, untrusted=True, |
4fedf2a9b538
webcommands.annotate: explicitly only honor whitespace diffopts
Siddharth Agarwal <sid0@fb.com>
parents:
23232
diff
changeset
|
790 |
section='annotate', whitespace=True) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
791 |
|
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
792 |
def annotate(**map): |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
793 |
last = None |
19657
145636d31bb4
hgweb: import the whole util module in webcommands instead of just one function
Alexander Plavin <alexander@plav.in>
parents:
19656
diff
changeset
|
794 |
if util.binary(fctx.data()): |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
795 |
mt = (mimetypes.guess_type(fctx.path())[0] |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
796 |
or 'application/octet-stream') |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
797 |
lines = enumerate([((fctx.filectx(fctx.filerev()), 1), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
798 |
'(binary:%s)' % mt)]) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
799 |
else: |
15528
a84698badf0b
annotate: support diff whitespace filtering flags (issue3030)
Patrick Mezard <pmezard@gmail.com>
parents:
15004
diff
changeset
|
800 |
lines = enumerate(fctx.annotate(follow=True, linenumber=True, |
a84698badf0b
annotate: support diff whitespace filtering flags (issue3030)
Patrick Mezard <pmezard@gmail.com>
parents:
15004
diff
changeset
|
801 |
diffopts=diffopts)) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
802 |
for lineno, ((f, targetline), l) in lines: |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
803 |
fnode = f.filenode() |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
804 |
|
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
805 |
if last != fnode: |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
806 |
last = fnode |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
807 |
|
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
808 |
yield {"parity": parity.next(), |
14055
421d56a055fd
drop {short,hex}(ctx.node()) calls in favor of ctx methods
Alexander Solovyov <alexander@solovyov.net>
parents:
14043
diff
changeset
|
809 |
"node": f.hex(), |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
810 |
"rev": f.rev(), |
6564
ccc2481e3954
webcommands: pass full author to annotate, fix templates (issue 1054)
Patrick Mezard <pmezard@gmail.com>
parents:
6437
diff
changeset
|
811 |
"author": f.user(), |
6657
a51093361e1c
hgweb: show cset node and description when hovering over annotate prefix
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6564
diff
changeset
|
812 |
"desc": f.description(), |
18581
3490c91a1fcb
templates: export extra as a dict to templates
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
18563
diff
changeset
|
813 |
"extra": f.extra(), |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
814 |
"file": f.path(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
815 |
"targetline": targetline, |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
816 |
"line": l, |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
817 |
"lineid": "l%d" % (lineno + 1), |
13199
a38df1250945
hgweb: added revision date to annotate line data
Oli Thissen <oli@tonick.net>
parents:
12696
diff
changeset
|
818 |
"linenumber": "% 6d" % (lineno + 1), |
a38df1250945
hgweb: added revision date to annotate line data
Oli Thissen <oli@tonick.net>
parents:
12696
diff
changeset
|
819 |
"revdate": f.date()} |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
820 |
|
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
821 |
return tmpl("fileannotate", |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
822 |
file=f, |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
823 |
annotate=annotate, |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
824 |
path=webutil.up(f), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
825 |
rev=fctx.rev(), |
14055
421d56a055fd
drop {short,hex}(ctx.node()) calls in favor of ctx methods
Alexander Solovyov <alexander@solovyov.net>
parents:
14043
diff
changeset
|
826 |
node=fctx.hex(), |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
827 |
author=fctx.user(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
828 |
date=fctx.date(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
829 |
desc=fctx.description(), |
18581
3490c91a1fcb
templates: export extra as a dict to templates
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
18563
diff
changeset
|
830 |
extra=fctx.extra(), |
6434
62e0bb41e682
hgweb: minor improvements for new web style
Matt Mackall <mpm@selenic.com>
parents:
6410
diff
changeset
|
831 |
rename=webutil.renamelink(fctx), |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
832 |
branch=webutil.nodebranchnodefault(fctx), |
7671
06cf09c822c4
hgweb: simplify parents/children generation code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7637
diff
changeset
|
833 |
parent=webutil.parents(fctx), |
06cf09c822c4
hgweb: simplify parents/children generation code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7637
diff
changeset
|
834 |
child=webutil.children(fctx), |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
835 |
permissions=fctx.manifest().flags(f)) |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
836 |
|
24076
b53d2afd11fb
webcommands: define web commands using a decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23992
diff
changeset
|
837 |
@webcommand('filelog') |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5598
diff
changeset
|
838 |
def filelog(web, req, tmpl): |
7300
591767e6ea7a
hgweb: conditionally show file logs for deleted files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7288
diff
changeset
|
839 |
|
591767e6ea7a
hgweb: conditionally show file logs for deleted files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7288
diff
changeset
|
840 |
try: |
591767e6ea7a
hgweb: conditionally show file logs for deleted files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7288
diff
changeset
|
841 |
fctx = webutil.filectx(web.repo, req) |
591767e6ea7a
hgweb: conditionally show file logs for deleted files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7288
diff
changeset
|
842 |
f = fctx.path() |
591767e6ea7a
hgweb: conditionally show file logs for deleted files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7288
diff
changeset
|
843 |
fl = fctx.filelog() |
7633 | 844 |
except error.LookupError: |
7300
591767e6ea7a
hgweb: conditionally show file logs for deleted files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7288
diff
changeset
|
845 |
f = webutil.cleanpath(web.repo, req.form['file'][0]) |
591767e6ea7a
hgweb: conditionally show file logs for deleted files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7288
diff
changeset
|
846 |
fl = web.repo.file(f) |
591767e6ea7a
hgweb: conditionally show file logs for deleted files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7288
diff
changeset
|
847 |
numrevs = len(fl) |
591767e6ea7a
hgweb: conditionally show file logs for deleted files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7288
diff
changeset
|
848 |
if not numrevs: # file doesn't exist at all |
591767e6ea7a
hgweb: conditionally show file logs for deleted files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7288
diff
changeset
|
849 |
raise |
591767e6ea7a
hgweb: conditionally show file logs for deleted files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7288
diff
changeset
|
850 |
rev = webutil.changectx(web.repo, req).rev() |
7361
9fe97eea5510
linkrev: take a revision number rather than a hash
Matt Mackall <mpm@selenic.com>
parents:
7345
diff
changeset
|
851 |
first = fl.linkrev(0) |
7300
591767e6ea7a
hgweb: conditionally show file logs for deleted files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7288
diff
changeset
|
852 |
if rev < first: # current rev is from before file existed |
591767e6ea7a
hgweb: conditionally show file logs for deleted files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7288
diff
changeset
|
853 |
raise |
591767e6ea7a
hgweb: conditionally show file logs for deleted files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7288
diff
changeset
|
854 |
frev = numrevs - 1 |
7361
9fe97eea5510
linkrev: take a revision number rather than a hash
Matt Mackall <mpm@selenic.com>
parents:
7345
diff
changeset
|
855 |
while fl.linkrev(frev) > rev: |
7300
591767e6ea7a
hgweb: conditionally show file logs for deleted files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7288
diff
changeset
|
856 |
frev -= 1 |
7361
9fe97eea5510
linkrev: take a revision number rather than a hash
Matt Mackall <mpm@selenic.com>
parents:
7345
diff
changeset
|
857 |
fctx = web.repo.filectx(f, fl.linkrev(frev)) |
7300
591767e6ea7a
hgweb: conditionally show file logs for deleted files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7288
diff
changeset
|
858 |
|
10246
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
859 |
revcount = web.maxshortchanges |
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
860 |
if 'revcount' in req.form: |
20092
77acd8ce01ce
hgweb: ignore non numeric "revcount" parameter values (issue4091)
Isaac Jurado <diptongo@gmail.com>
parents:
20004
diff
changeset
|
861 |
try: |
77acd8ce01ce
hgweb: ignore non numeric "revcount" parameter values (issue4091)
Isaac Jurado <diptongo@gmail.com>
parents:
20004
diff
changeset
|
862 |
revcount = int(req.form.get('revcount', [revcount])[0]) |
77acd8ce01ce
hgweb: ignore non numeric "revcount" parameter values (issue4091)
Isaac Jurado <diptongo@gmail.com>
parents:
20004
diff
changeset
|
863 |
revcount = max(revcount, 1) |
77acd8ce01ce
hgweb: ignore non numeric "revcount" parameter values (issue4091)
Isaac Jurado <diptongo@gmail.com>
parents:
20004
diff
changeset
|
864 |
tmpl.defaults['sessionvars']['revcount'] = revcount |
77acd8ce01ce
hgweb: ignore non numeric "revcount" parameter values (issue4091)
Isaac Jurado <diptongo@gmail.com>
parents:
20004
diff
changeset
|
865 |
except ValueError: |
77acd8ce01ce
hgweb: ignore non numeric "revcount" parameter values (issue4091)
Isaac Jurado <diptongo@gmail.com>
parents:
20004
diff
changeset
|
866 |
pass |
10246
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
867 |
|
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
868 |
lessvars = copy.copy(tmpl.defaults['sessionvars']) |
13931
c3372529247f
hgweb: set minimum number of revision to display to 1 when revcount is 0
Md. O. Shayan <mdoshayan@gmail.com>
parents:
13924
diff
changeset
|
869 |
lessvars['revcount'] = max(revcount / 2, 1) |
10246
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
870 |
morevars = copy.copy(tmpl.defaults['sessionvars']) |
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
871 |
morevars['revcount'] = revcount * 2 |
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
872 |
|
7300
591767e6ea7a
hgweb: conditionally show file logs for deleted files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7288
diff
changeset
|
873 |
count = fctx.filerev() + 1 |
10246
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
874 |
start = max(0, fctx.filerev() - revcount + 1) # first rev on this page |
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
875 |
end = min(count, start + revcount) # last rev on this page |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
876 |
parity = paritygen(web.stripecount, offset=start - end) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
877 |
|
20022
d85dfe211c71
hgweb: always compute all entries and latestentry in filelog
Alexander Plavin <alexander@plav.in>
parents:
20021
diff
changeset
|
878 |
def entries(): |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
879 |
l = [] |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
880 |
|
7612
069b29656401
web: use the correct filectx in filelog
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7565
diff
changeset
|
881 |
repo = web.repo |
20023
2771e59afac4
hgweb: use semantically suitable filelog.revs in filelog
Alexander Plavin <alexander@plav.in>
parents:
20022
diff
changeset
|
882 |
revs = fctx.filelog().revs(start, end - 1) |
18402
bfba6d954108
hgweb: `limit` argument is actually `latestonly` renames and enforce
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18352
diff
changeset
|
883 |
for i in revs: |
7612
069b29656401
web: use the correct filectx in filelog
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7565
diff
changeset
|
884 |
iterfctx = fctx.filectx(i) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
885 |
|
18319
e350ce798b63
hgweb: no do not use listinsert(0, ...)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18037
diff
changeset
|
886 |
l.append({"parity": parity.next(), |
e350ce798b63
hgweb: no do not use listinsert(0, ...)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18037
diff
changeset
|
887 |
"filerev": i, |
e350ce798b63
hgweb: no do not use listinsert(0, ...)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18037
diff
changeset
|
888 |
"file": f, |
e350ce798b63
hgweb: no do not use listinsert(0, ...)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18037
diff
changeset
|
889 |
"node": iterfctx.hex(), |
e350ce798b63
hgweb: no do not use listinsert(0, ...)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18037
diff
changeset
|
890 |
"author": iterfctx.user(), |
e350ce798b63
hgweb: no do not use listinsert(0, ...)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18037
diff
changeset
|
891 |
"date": iterfctx.date(), |
e350ce798b63
hgweb: no do not use listinsert(0, ...)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18037
diff
changeset
|
892 |
"rename": webutil.renamelink(iterfctx), |
e350ce798b63
hgweb: no do not use listinsert(0, ...)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18037
diff
changeset
|
893 |
"parent": webutil.parents(iterfctx), |
e350ce798b63
hgweb: no do not use listinsert(0, ...)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18037
diff
changeset
|
894 |
"child": webutil.children(iterfctx), |
e350ce798b63
hgweb: no do not use listinsert(0, ...)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18037
diff
changeset
|
895 |
"desc": iterfctx.description(), |
18581
3490c91a1fcb
templates: export extra as a dict to templates
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
18563
diff
changeset
|
896 |
"extra": iterfctx.extra(), |
18319
e350ce798b63
hgweb: no do not use listinsert(0, ...)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18037
diff
changeset
|
897 |
"tags": webutil.nodetagsdict(repo, iterfctx.node()), |
e350ce798b63
hgweb: no do not use listinsert(0, ...)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18037
diff
changeset
|
898 |
"bookmarks": webutil.nodebookmarksdict( |
e350ce798b63
hgweb: no do not use listinsert(0, ...)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18037
diff
changeset
|
899 |
repo, iterfctx.node()), |
e350ce798b63
hgweb: no do not use listinsert(0, ...)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18037
diff
changeset
|
900 |
"branch": webutil.nodebranchnodefault(iterfctx), |
e350ce798b63
hgweb: no do not use listinsert(0, ...)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18037
diff
changeset
|
901 |
"inbranch": webutil.nodeinbranch(repo, iterfctx), |
e350ce798b63
hgweb: no do not use listinsert(0, ...)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18037
diff
changeset
|
902 |
"branches": webutil.nodebranchdict(repo, iterfctx)}) |
e350ce798b63
hgweb: no do not use listinsert(0, ...)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18037
diff
changeset
|
903 |
for e in reversed(l): |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
904 |
yield e |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
905 |
|
20022
d85dfe211c71
hgweb: always compute all entries and latestentry in filelog
Alexander Plavin <alexander@plav.in>
parents:
20021
diff
changeset
|
906 |
entries = list(entries()) |
d85dfe211c71
hgweb: always compute all entries and latestentry in filelog
Alexander Plavin <alexander@plav.in>
parents:
20021
diff
changeset
|
907 |
latestentry = entries[:1] |
d85dfe211c71
hgweb: always compute all entries and latestentry in filelog
Alexander Plavin <alexander@plav.in>
parents:
20021
diff
changeset
|
908 |
|
18409
e3f5cef11d6a
hgweb: pass repo object to revnav construction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18408
diff
changeset
|
909 |
revnav = webutil.filerevnav(web.repo, fctx.path()) |
e3f5cef11d6a
hgweb: pass repo object to revnav construction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18408
diff
changeset
|
910 |
nav = revnav.gen(end - 1, revcount, count) |
14055
421d56a055fd
drop {short,hex}(ctx.node()) calls in favor of ctx methods
Alexander Solovyov <alexander@solovyov.net>
parents:
14043
diff
changeset
|
911 |
return tmpl("filelog", file=f, node=fctx.hex(), nav=nav, |
20022
d85dfe211c71
hgweb: always compute all entries and latestentry in filelog
Alexander Plavin <alexander@plav.in>
parents:
20021
diff
changeset
|
912 |
entries=entries, |
d85dfe211c71
hgweb: always compute all entries and latestentry in filelog
Alexander Plavin <alexander@plav.in>
parents:
20021
diff
changeset
|
913 |
latestentry=latestentry, |
10246
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
914 |
revcount=revcount, morevars=morevars, lessvars=lessvars) |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
915 |
|
24076
b53d2afd11fb
webcommands: define web commands using a decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23992
diff
changeset
|
916 |
@webcommand('archive') |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5598
diff
changeset
|
917 |
def archive(web, req, tmpl): |
6669
782dbbdfb1d7
fix traceback in hgweb when URL doesn't end in one of the archive specs
Ali Saidi <saidi@eecs.umich.edu>
parents:
6368
diff
changeset
|
918 |
type_ = req.form.get('type', [None])[0] |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
919 |
allowed = web.configlist("web", "allow_archive") |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
920 |
key = req.form['node'][0] |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
921 |
|
7029
b84d27386285
hgweb: Respond with HTTP 403 for disabled archive types instead of 404
Rocco Rutte <pdmef@gmx.net>
parents:
6981
diff
changeset
|
922 |
if type_ not in web.archives: |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
923 |
msg = 'Unsupported archive type: %s' % type_ |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
924 |
raise ErrorResponse(HTTP_NOT_FOUND, msg) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
925 |
|
7029
b84d27386285
hgweb: Respond with HTTP 403 for disabled archive types instead of 404
Rocco Rutte <pdmef@gmx.net>
parents:
6981
diff
changeset
|
926 |
if not ((type_ in allowed or |
b84d27386285
hgweb: Respond with HTTP 403 for disabled archive types instead of 404
Rocco Rutte <pdmef@gmx.net>
parents:
6981
diff
changeset
|
927 |
web.configbool("web", "allow" + type_, False))): |
b84d27386285
hgweb: Respond with HTTP 403 for disabled archive types instead of 404
Rocco Rutte <pdmef@gmx.net>
parents:
6981
diff
changeset
|
928 |
msg = 'Archive type not allowed: %s' % type_ |
b84d27386285
hgweb: Respond with HTTP 403 for disabled archive types instead of 404
Rocco Rutte <pdmef@gmx.net>
parents:
6981
diff
changeset
|
929 |
raise ErrorResponse(HTTP_FORBIDDEN, msg) |
b84d27386285
hgweb: Respond with HTTP 403 for disabled archive types instead of 404
Rocco Rutte <pdmef@gmx.net>
parents:
6981
diff
changeset
|
930 |
|
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
931 |
reponame = re.sub(r"\W+", "-", os.path.basename(web.reponame)) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
932 |
cnode = web.repo.lookup(key) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
933 |
arch_version = key |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
934 |
if cnode == key or key == 'tip': |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
935 |
arch_version = short(cnode) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
936 |
name = "%s-%s" % (reponame, arch_version) |
18771
bb38f4f78104
hgweb: teach archive how to download a specific directory or file
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
18747
diff
changeset
|
937 |
|
bb38f4f78104
hgweb: teach archive how to download a specific directory or file
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
18747
diff
changeset
|
938 |
ctx = webutil.changectx(web.repo, req) |
bb38f4f78104
hgweb: teach archive how to download a specific directory or file
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
18747
diff
changeset
|
939 |
pats = [] |
23232
a0ccb66f344d
hgweb: fix a crash when using web.archivesubrepos
Matt Harbison <matt_harbison@yahoo.com>
parents:
22634
diff
changeset
|
940 |
matchfn = scmutil.match(ctx, []) |
18771
bb38f4f78104
hgweb: teach archive how to download a specific directory or file
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
18747
diff
changeset
|
941 |
file = req.form.get('file', None) |
bb38f4f78104
hgweb: teach archive how to download a specific directory or file
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
18747
diff
changeset
|
942 |
if file: |
18968
7d2a7f8e9da4
hgweb: respond HTTP_NOT_FOUND when an archive request does not match any files
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
18771
diff
changeset
|
943 |
pats = ['path:' + file[0]] |
7d2a7f8e9da4
hgweb: respond HTTP_NOT_FOUND when an archive request does not match any files
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
18771
diff
changeset
|
944 |
matchfn = scmutil.match(ctx, pats, default='path') |
7d2a7f8e9da4
hgweb: respond HTTP_NOT_FOUND when an archive request does not match any files
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
18771
diff
changeset
|
945 |
if pats: |
7d2a7f8e9da4
hgweb: respond HTTP_NOT_FOUND when an archive request does not match any files
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
18771
diff
changeset
|
946 |
files = [f for f in ctx.manifest().keys() if matchfn(f)] |
7d2a7f8e9da4
hgweb: respond HTTP_NOT_FOUND when an archive request does not match any files
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
18771
diff
changeset
|
947 |
if not files: |
7d2a7f8e9da4
hgweb: respond HTTP_NOT_FOUND when an archive request does not match any files
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
18771
diff
changeset
|
948 |
raise ErrorResponse(HTTP_NOT_FOUND, |
7d2a7f8e9da4
hgweb: respond HTTP_NOT_FOUND when an archive request does not match any files
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
18771
diff
changeset
|
949 |
'file(s) not found: %s' % file[0]) |
18771
bb38f4f78104
hgweb: teach archive how to download a specific directory or file
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
18747
diff
changeset
|
950 |
|
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
951 |
mimetype, artype, extension, encoding = web.archive_specs[type_] |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
952 |
headers = [ |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
953 |
('Content-Disposition', 'attachment; filename=%s%s' % (name, extension)) |
18347
853221386f48
hgweb: make type a mandatory parameter to request.respond
Mads Kiilerich <mads@kiilerich.com>
parents:
18319
diff
changeset
|
954 |
] |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
955 |
if encoding: |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
956 |
headers.append(('Content-Encoding', encoding)) |
18348
764a758780b6
hgweb: simplify wsgirequest header handling
Mads Kiilerich <mads@kiilerich.com>
parents:
18347
diff
changeset
|
957 |
req.headers.extend(headers) |
18347
853221386f48
hgweb: make type a mandatory parameter to request.respond
Mads Kiilerich <mads@kiilerich.com>
parents:
18319
diff
changeset
|
958 |
req.respond(HTTP_OK, mimetype) |
17933
8243dd66e0e3
webcommands: allow hgweb's archive to recurse into subrepos
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17322
diff
changeset
|
959 |
|
8243dd66e0e3
webcommands: allow hgweb's archive to recurse into subrepos
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17322
diff
changeset
|
960 |
archival.archive(web.repo, req, cnode, artype, prefix=name, |
18771
bb38f4f78104
hgweb: teach archive how to download a specific directory or file
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
18747
diff
changeset
|
961 |
matchfn=matchfn, |
17933
8243dd66e0e3
webcommands: allow hgweb's archive to recurse into subrepos
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17322
diff
changeset
|
962 |
subrepos=web.configbool("web", "archivesubrepos")) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
963 |
return [] |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
964 |
|
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
965 |
|
24076
b53d2afd11fb
webcommands: define web commands using a decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23992
diff
changeset
|
966 |
@webcommand('static') |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5598
diff
changeset
|
967 |
def static(web, req, tmpl): |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
968 |
fname = req.form['file'][0] |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
969 |
# a repo owner may set web.static in .hg/hgrc to get any file |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
970 |
# readable by the user running the CGI script |
7107
125c8fedcbe0
Allow hgweb to search for templates in more than one path.
Brendan Cully <brendan@kublai.com>
parents:
7102
diff
changeset
|
971 |
static = web.config("web", "static", None, untrusted=False) |
125c8fedcbe0
Allow hgweb to search for templates in more than one path.
Brendan Cully <brendan@kublai.com>
parents:
7102
diff
changeset
|
972 |
if not static: |
22634
e48a5d3996c2
templater: introduce templatepaths for getting paths searched for templates
Mads Kiilerich <madski@unity3d.com>
parents:
22199
diff
changeset
|
973 |
tp = web.templatepath or templater.templatepaths() |
7107
125c8fedcbe0
Allow hgweb to search for templates in more than one path.
Brendan Cully <brendan@kublai.com>
parents:
7102
diff
changeset
|
974 |
if isinstance(tp, str): |
125c8fedcbe0
Allow hgweb to search for templates in more than one path.
Brendan Cully <brendan@kublai.com>
parents:
7102
diff
changeset
|
975 |
tp = [tp] |
7288
9c399c53469d
Allow per-file shadowing of static directory in templatepath
Brendan Cully <brendan@kublai.com>
parents:
7280
diff
changeset
|
976 |
static = [os.path.join(p, 'static') for p in tp] |
18645
76ff3a715cf2
hgweb: simplify internal staticfile return codes
Mads Kiilerich <mads@kiilerich.com>
parents:
18581
diff
changeset
|
977 |
staticfile(static, fname, req) |
76ff3a715cf2
hgweb: simplify internal staticfile return codes
Mads Kiilerich <mads@kiilerich.com>
parents:
18581
diff
changeset
|
978 |
return [] |
6691
0dba955c2636
add graph page to hgweb
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6670
diff
changeset
|
979 |
|
24076
b53d2afd11fb
webcommands: define web commands using a decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23992
diff
changeset
|
980 |
@webcommand('graph') |
6691
0dba955c2636
add graph page to hgweb
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6670
diff
changeset
|
981 |
def graph(web, req, tmpl): |
10245
207b94f6b65d
hgweb: make graph page size equal to shortlog
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9404
diff
changeset
|
982 |
|
17318
7ac5800dbc8f
hgweb: fix graph view paging
Patrick Mezard <patrick@mezard.eu>
parents:
17303
diff
changeset
|
983 |
ctx = webutil.changectx(web.repo, req) |
7ac5800dbc8f
hgweb: fix graph view paging
Patrick Mezard <patrick@mezard.eu>
parents:
17303
diff
changeset
|
984 |
rev = ctx.rev() |
7ac5800dbc8f
hgweb: fix graph view paging
Patrick Mezard <patrick@mezard.eu>
parents:
17303
diff
changeset
|
985 |
|
6691
0dba955c2636
add graph page to hgweb
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6670
diff
changeset
|
986 |
bg_height = 39 |
10245
207b94f6b65d
hgweb: make graph page size equal to shortlog
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9404
diff
changeset
|
987 |
revcount = web.maxshortchanges |
7345
55651328dfcc
hgweb: fix up the less/more links on the graph page
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7332
diff
changeset
|
988 |
if 'revcount' in req.form: |
20092
77acd8ce01ce
hgweb: ignore non numeric "revcount" parameter values (issue4091)
Isaac Jurado <diptongo@gmail.com>
parents:
20004
diff
changeset
|
989 |
try: |
77acd8ce01ce
hgweb: ignore non numeric "revcount" parameter values (issue4091)
Isaac Jurado <diptongo@gmail.com>
parents:
20004
diff
changeset
|
990 |
revcount = int(req.form.get('revcount', [revcount])[0]) |
77acd8ce01ce
hgweb: ignore non numeric "revcount" parameter values (issue4091)
Isaac Jurado <diptongo@gmail.com>
parents:
20004
diff
changeset
|
991 |
revcount = max(revcount, 1) |
77acd8ce01ce
hgweb: ignore non numeric "revcount" parameter values (issue4091)
Isaac Jurado <diptongo@gmail.com>
parents:
20004
diff
changeset
|
992 |
tmpl.defaults['sessionvars']['revcount'] = revcount |
77acd8ce01ce
hgweb: ignore non numeric "revcount" parameter values (issue4091)
Isaac Jurado <diptongo@gmail.com>
parents:
20004
diff
changeset
|
993 |
except ValueError: |
77acd8ce01ce
hgweb: ignore non numeric "revcount" parameter values (issue4091)
Isaac Jurado <diptongo@gmail.com>
parents:
20004
diff
changeset
|
994 |
pass |
7345
55651328dfcc
hgweb: fix up the less/more links on the graph page
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7332
diff
changeset
|
995 |
|
55651328dfcc
hgweb: fix up the less/more links on the graph page
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7332
diff
changeset
|
996 |
lessvars = copy.copy(tmpl.defaults['sessionvars']) |
13931
c3372529247f
hgweb: set minimum number of revision to display to 1 when revcount is 0
Md. O. Shayan <mdoshayan@gmail.com>
parents:
13924
diff
changeset
|
997 |
lessvars['revcount'] = max(revcount / 2, 1) |
7345
55651328dfcc
hgweb: fix up the less/more links on the graph page
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7332
diff
changeset
|
998 |
morevars = copy.copy(tmpl.defaults['sessionvars']) |
55651328dfcc
hgweb: fix up the less/more links on the graph page
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7332
diff
changeset
|
999 |
morevars['revcount'] = revcount * 2 |
55651328dfcc
hgweb: fix up the less/more links on the graph page
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7332
diff
changeset
|
1000 |
|
17318
7ac5800dbc8f
hgweb: fix graph view paging
Patrick Mezard <patrick@mezard.eu>
parents:
17303
diff
changeset
|
1001 |
count = len(web.repo) |
7ac5800dbc8f
hgweb: fix graph view paging
Patrick Mezard <patrick@mezard.eu>
parents:
17303
diff
changeset
|
1002 |
pos = rev |
7ac5800dbc8f
hgweb: fix graph view paging
Patrick Mezard <patrick@mezard.eu>
parents:
17303
diff
changeset
|
1003 |
|
7ac5800dbc8f
hgweb: fix graph view paging
Patrick Mezard <patrick@mezard.eu>
parents:
17303
diff
changeset
|
1004 |
uprev = min(max(0, count - 1), rev + revcount) |
6691
0dba955c2636
add graph page to hgweb
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6670
diff
changeset
|
1005 |
downrev = max(0, rev - revcount) |
18409
e3f5cef11d6a
hgweb: pass repo object to revnav construction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18408
diff
changeset
|
1006 |
changenav = webutil.revnav(web.repo).gen(pos, revcount, count) |
6691
0dba955c2636
add graph page to hgweb
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6670
diff
changeset
|
1007 |
|
18428
8c10f760ca34
hgweb: walk the graph through the changelog
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18427
diff
changeset
|
1008 |
tree = [] |
19487
8cfa3a3664a5
hgweb: fix incorrect revisions count in graph (issue3977)
Alexander Plavin <me@aplavin.ru>
parents:
19486
diff
changeset
|
1009 |
if pos != -1: |
8cfa3a3664a5
hgweb: fix incorrect revisions count in graph (issue3977)
Alexander Plavin <me@aplavin.ru>
parents:
19486
diff
changeset
|
1010 |
allrevs = web.repo.changelog.revs(pos, 0) |
8cfa3a3664a5
hgweb: fix incorrect revisions count in graph (issue3977)
Alexander Plavin <me@aplavin.ru>
parents:
19486
diff
changeset
|
1011 |
revs = [] |
8cfa3a3664a5
hgweb: fix incorrect revisions count in graph (issue3977)
Alexander Plavin <me@aplavin.ru>
parents:
19486
diff
changeset
|
1012 |
for i in allrevs: |
8cfa3a3664a5
hgweb: fix incorrect revisions count in graph (issue3977)
Alexander Plavin <me@aplavin.ru>
parents:
19486
diff
changeset
|
1013 |
revs.append(i) |
8cfa3a3664a5
hgweb: fix incorrect revisions count in graph (issue3977)
Alexander Plavin <me@aplavin.ru>
parents:
19486
diff
changeset
|
1014 |
if len(revs) >= revcount: |
8cfa3a3664a5
hgweb: fix incorrect revisions count in graph (issue3977)
Alexander Plavin <me@aplavin.ru>
parents:
19486
diff
changeset
|
1015 |
break |
8cfa3a3664a5
hgweb: fix incorrect revisions count in graph (issue3977)
Alexander Plavin <me@aplavin.ru>
parents:
19486
diff
changeset
|
1016 |
|
20761
46f93b7660b6
webcommands: changed code to use lazy classes when calling dagwalker
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20678
diff
changeset
|
1017 |
# We have to feed a baseset to dagwalker as it is expecting smartset |
46f93b7660b6
webcommands: changed code to use lazy classes when calling dagwalker
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20678
diff
changeset
|
1018 |
# object. This does not have a big impact on hgweb performance itself |
46f93b7660b6
webcommands: changed code to use lazy classes when calling dagwalker
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20678
diff
changeset
|
1019 |
# since hgweb graphing code is not itself lazy yet. |
46f93b7660b6
webcommands: changed code to use lazy classes when calling dagwalker
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20678
diff
changeset
|
1020 |
dag = graphmod.dagwalker(web.repo, revset.baseset(revs)) |
46f93b7660b6
webcommands: changed code to use lazy classes when calling dagwalker
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20678
diff
changeset
|
1021 |
# As we said one line above... not lazy. |
18428
8c10f760ca34
hgweb: walk the graph through the changelog
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18427
diff
changeset
|
1022 |
tree = list(graphmod.colored(dag, web.repo)) |
16773
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
1023 |
|
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
1024 |
def getcolumns(tree): |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
1025 |
cols = 0 |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
1026 |
for (id, type, ctx, vtx, edges) in tree: |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
1027 |
if type != graphmod.CHANGESET: |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
1028 |
continue |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
1029 |
cols = max(cols, max([edge[0] for edge in edges] or [0]), |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
1030 |
max([edge[1] for edge in edges] or [0])) |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
1031 |
return cols |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
1032 |
|
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
1033 |
def graphdata(usetuples, **map): |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
1034 |
data = [] |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
1035 |
|
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
1036 |
row = 0 |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
1037 |
for (id, type, ctx, vtx, edges) in tree: |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
1038 |
if type != graphmod.CHANGESET: |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
1039 |
continue |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
1040 |
node = str(ctx) |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
1041 |
age = templatefilters.age(ctx.date()) |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
1042 |
desc = templatefilters.firstline(ctx.description()) |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
1043 |
desc = cgi.escape(templatefilters.nonempty(desc)) |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
1044 |
user = cgi.escape(templatefilters.person(ctx.user())) |
19879
5cbf413ce658
hgweb: escape branch names in graph view
Matt Mackall <mpm@selenic.com>
parents:
19499
diff
changeset
|
1045 |
branch = cgi.escape(ctx.branch()) |
16773
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
1046 |
try: |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
1047 |
branchnode = web.repo.branchtip(branch) |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
1048 |
except error.RepoLookupError: |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
1049 |
branchnode = None |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
1050 |
branch = branch, branchnode == ctx.node() |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
1051 |
|
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
1052 |
if usetuples: |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
1053 |
data.append((node, vtx, edges, desc, user, age, branch, |
19883
904061628dc4
hgweb: add escaping of tags and bookmarks in graph view
Matt Mackall <mpm@selenic.com>
parents:
19879
diff
changeset
|
1054 |
[cgi.escape(x) for x in ctx.tags()], |
904061628dc4
hgweb: add escaping of tags and bookmarks in graph view
Matt Mackall <mpm@selenic.com>
parents:
19879
diff
changeset
|
1055 |
[cgi.escape(x) for x in ctx.bookmarks()])) |
16773
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
1056 |
else: |
20678
da6bea33007b
webcommands: move from dict() construction to {} literals
Augie Fackler <raf@durin42.com>
parents:
20364
diff
changeset
|
1057 |
edgedata = [{'col': edge[0], 'nextcol': edge[1], |
da6bea33007b
webcommands: move from dict() construction to {} literals
Augie Fackler <raf@durin42.com>
parents:
20364
diff
changeset
|
1058 |
'color': (edge[2] - 1) % 6 + 1, |
da6bea33007b
webcommands: move from dict() construction to {} literals
Augie Fackler <raf@durin42.com>
parents:
20364
diff
changeset
|
1059 |
'width': edge[3], 'bcolor': edge[4]} |
16773
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
1060 |
for edge in edges] |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
1061 |
|
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
1062 |
data.append( |
20678
da6bea33007b
webcommands: move from dict() construction to {} literals
Augie Fackler <raf@durin42.com>
parents:
20364
diff
changeset
|
1063 |
{'node': node, |
da6bea33007b
webcommands: move from dict() construction to {} literals
Augie Fackler <raf@durin42.com>
parents:
20364
diff
changeset
|
1064 |
'col': vtx[0], |
da6bea33007b
webcommands: move from dict() construction to {} literals
Augie Fackler <raf@durin42.com>
parents:
20364
diff
changeset
|
1065 |
'color': (vtx[1] - 1) % 6 + 1, |
da6bea33007b
webcommands: move from dict() construction to {} literals
Augie Fackler <raf@durin42.com>
parents:
20364
diff
changeset
|
1066 |
'edges': edgedata, |
da6bea33007b
webcommands: move from dict() construction to {} literals
Augie Fackler <raf@durin42.com>
parents:
20364
diff
changeset
|
1067 |
'row': row, |
da6bea33007b
webcommands: move from dict() construction to {} literals
Augie Fackler <raf@durin42.com>
parents:
20364
diff
changeset
|
1068 |
'nextrow': row + 1, |
da6bea33007b
webcommands: move from dict() construction to {} literals
Augie Fackler <raf@durin42.com>
parents:
20364
diff
changeset
|
1069 |
'desc': desc, |
da6bea33007b
webcommands: move from dict() construction to {} literals
Augie Fackler <raf@durin42.com>
parents:
20364
diff
changeset
|
1070 |
'user': user, |
da6bea33007b
webcommands: move from dict() construction to {} literals
Augie Fackler <raf@durin42.com>
parents:
20364
diff
changeset
|
1071 |
'age': age, |
da6bea33007b
webcommands: move from dict() construction to {} literals
Augie Fackler <raf@durin42.com>
parents:
20364
diff
changeset
|
1072 |
'bookmarks': webutil.nodebookmarksdict( |
da6bea33007b
webcommands: move from dict() construction to {} literals
Augie Fackler <raf@durin42.com>
parents:
20364
diff
changeset
|
1073 |
web.repo, ctx.node()), |
da6bea33007b
webcommands: move from dict() construction to {} literals
Augie Fackler <raf@durin42.com>
parents:
20364
diff
changeset
|
1074 |
'branches': webutil.nodebranchdict(web.repo, ctx), |
da6bea33007b
webcommands: move from dict() construction to {} literals
Augie Fackler <raf@durin42.com>
parents:
20364
diff
changeset
|
1075 |
'inbranch': webutil.nodeinbranch(web.repo, ctx), |
da6bea33007b
webcommands: move from dict() construction to {} literals
Augie Fackler <raf@durin42.com>
parents:
20364
diff
changeset
|
1076 |
'tags': webutil.nodetagsdict(web.repo, ctx.node())}) |
16773
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
1077 |
|
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
1078 |
row += 1 |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
1079 |
|
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
1080 |
return data |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
1081 |
|
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
1082 |
cols = getcolumns(tree) |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
1083 |
rows = len(tree) |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
1084 |
canvasheight = (rows + 1) * bg_height - 27 |
6691
0dba955c2636
add graph page to hgweb
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6670
diff
changeset
|
1085 |
|
0dba955c2636
add graph page to hgweb
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6670
diff
changeset
|
1086 |
return tmpl('graph', rev=rev, revcount=revcount, uprev=uprev, |
7345
55651328dfcc
hgweb: fix up the less/more links on the graph page
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7332
diff
changeset
|
1087 |
lessvars=lessvars, morevars=morevars, downrev=downrev, |
16773
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
1088 |
cols=cols, rows=rows, |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
1089 |
canvaswidth=(cols + 1) * bg_height, |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
1090 |
truecanvasheight=rows * bg_height, |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
1091 |
canvasheight=canvasheight, bg_height=bg_height, |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
1092 |
jsdata=lambda **x: graphdata(True, **x), |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
1093 |
nodes=lambda **x: graphdata(False, **x), |
17318
7ac5800dbc8f
hgweb: fix graph view paging
Patrick Mezard <patrick@mezard.eu>
parents:
17303
diff
changeset
|
1094 |
node=ctx.hex(), changenav=changenav) |
12666
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
1095 |
|
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
1096 |
def _getdoc(e): |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
1097 |
doc = e[0].__doc__ |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
1098 |
if doc: |
16469
dd68c972d089
i18n: show localized messages for commands/extensions in hgweb help top (issue3383)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
16448
diff
changeset
|
1099 |
doc = _(doc).split('\n')[0] |
12666
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
1100 |
else: |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
1101 |
doc = _('(no help text available)') |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
1102 |
return doc |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
1103 |
|
24076
b53d2afd11fb
webcommands: define web commands using a decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23992
diff
changeset
|
1104 |
@webcommand('help') |
12666
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
1105 |
def help(web, req, tmpl): |
24081
ff42de48193c
webcommands: document "help" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24078
diff
changeset
|
1106 |
""" |
ff42de48193c
webcommands: document "help" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24078
diff
changeset
|
1107 |
/help[/{topic}] |
ff42de48193c
webcommands: document "help" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24078
diff
changeset
|
1108 |
--------------- |
ff42de48193c
webcommands: document "help" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24078
diff
changeset
|
1109 |
|
ff42de48193c
webcommands: document "help" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24078
diff
changeset
|
1110 |
Render help documentation. |
ff42de48193c
webcommands: document "help" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24078
diff
changeset
|
1111 |
|
ff42de48193c
webcommands: document "help" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24078
diff
changeset
|
1112 |
This web command is roughly equivalent to :hg:`help`. If a ``topic`` |
ff42de48193c
webcommands: document "help" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24078
diff
changeset
|
1113 |
is defined, that help topic will be rendered. If not, an index of |
ff42de48193c
webcommands: document "help" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24078
diff
changeset
|
1114 |
available help topics will be rendered. |
ff42de48193c
webcommands: document "help" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24078
diff
changeset
|
1115 |
|
ff42de48193c
webcommands: document "help" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24078
diff
changeset
|
1116 |
The ``help`` template will be rendered when requesting help for a topic. |
ff42de48193c
webcommands: document "help" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24078
diff
changeset
|
1117 |
``helptopics`` will be rendered for the index of help topics. |
ff42de48193c
webcommands: document "help" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24078
diff
changeset
|
1118 |
""" |
12666
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
1119 |
from mercurial import commands # avoid cycle |
24078
e44586d9c207
webcommands: move help import into help command handler
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24077
diff
changeset
|
1120 |
from mercurial import help as helpmod # avoid cycle |
12666
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
1121 |
|
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
1122 |
topicname = req.form.get('node', [None])[0] |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
1123 |
if not topicname: |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
1124 |
def topics(**map): |
22199
b3e51675f98e
cleanup: avoid _ for local unused tmp variables - that is reserved for i18n
Mads Kiilerich <madski@unity3d.com>
parents:
21123
diff
changeset
|
1125 |
for entries, summary, _doc in helpmod.helptable: |
17322
7124f984dc8d
help: use the first topic name from helptable, not the longest alias
Mads Kiilerich <mads@kiilerich.com>
parents:
17318
diff
changeset
|
1126 |
yield {'topic': entries[0], 'summary': summary} |
12666
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
1127 |
|
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
1128 |
early, other = [], [] |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
1129 |
primary = lambda s: s.split('|')[0] |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
1130 |
for c, e in commands.table.iteritems(): |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
1131 |
doc = _getdoc(e) |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
1132 |
if 'DEPRECATED' in doc or c.startswith('debug'): |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
1133 |
continue |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
1134 |
cmd = primary(c) |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
1135 |
if cmd.startswith('^'): |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
1136 |
early.append((cmd[1:], doc)) |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
1137 |
else: |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
1138 |
other.append((cmd, doc)) |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
1139 |
|
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
1140 |
early.sort() |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
1141 |
other.sort() |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
1142 |
|
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
1143 |
def earlycommands(**map): |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
1144 |
for c, doc in early: |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
1145 |
yield {'topic': c, 'summary': doc} |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
1146 |
|
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
1147 |
def othercommands(**map): |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
1148 |
for c, doc in other: |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
1149 |
yield {'topic': c, 'summary': doc} |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
1150 |
|
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
1151 |
return tmpl('helptopics', topics=topics, earlycommands=earlycommands, |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
1152 |
othercommands=othercommands, title='Index') |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
1153 |
|
12696
ef969e58a394
hgweb: another fix for the help termwidth bug
Matt Mackall <mpm@selenic.com>
parents:
12692
diff
changeset
|
1154 |
u = webutil.wsgiui() |
17146
6b40cc67ceb4
hgweb: show help with verbose sections included
Adrian Buehlmann <adrian@cadifra.com>
parents:
16773
diff
changeset
|
1155 |
u.verbose = True |
12666
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
1156 |
try: |
18747
f5db3092790f
hgweb: generate HTML documentation
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
18645
diff
changeset
|
1157 |
doc = helpmod.help_(u, topicname) |
12666
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
1158 |
except error.UnknownCommand: |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
1159 |
raise ErrorResponse(HTTP_NOT_FOUND) |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
1160 |
return tmpl('help', topic=topicname, doc=doc) |