Mercurial > public > mercurial-scm > hg-stable
annotate mercurial/hgweb/webcommands.py @ 53040:cdd7bf612c7b stable tip
bundle-spec: properly format boolean parameter (issue6960)
This was breaking automatic clone bundle generation. This changeset fixes it and
add a test to catch it in the future.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Tue, 11 Mar 2025 02:29:42 +0100 |
parents | e627cc25b6f3 |
children |
rev | line source |
---|---|
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> |
46819
d4ba4d51f85f
contributor: change mentions of mpm to olivia
Rapha?l Gom?s <rgomes@octobus.net>
parents:
46417
diff
changeset
|
3 # Copyright 2005-2007 Olivia Mackall <olivia@selenic.com> |
5591
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 |
51901
f4733654f144
typing: add `from __future__ import annotations` to most files
Matt Harbison <matt_harbison@yahoo.com>
parents:
51900
diff
changeset
|
8 from __future__ import annotations |
27046
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27009
diff
changeset
|
9 |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27009
diff
changeset
|
10 import copy |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27009
diff
changeset
|
11 import mimetypes |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27009
diff
changeset
|
12 import os |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27009
diff
changeset
|
13 import re |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27009
diff
changeset
|
14 |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27009
diff
changeset
|
15 from ..i18n import _ |
37953
7fae76c2c564
hgweb: reuse graph node-related functions from templates
Anton Shestakov <av6@dwimlabs.net>
parents:
37946
diff
changeset
|
16 from ..node import hex, short |
27046
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27009
diff
changeset
|
17 |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27009
diff
changeset
|
18 from .common import ( |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27009
diff
changeset
|
19 ErrorResponse, |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27009
diff
changeset
|
20 HTTP_FORBIDDEN, |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27009
diff
changeset
|
21 HTTP_NOT_FOUND, |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27009
diff
changeset
|
22 get_contact, |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27009
diff
changeset
|
23 paritygen, |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27009
diff
changeset
|
24 staticfile, |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27009
diff
changeset
|
25 ) |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27009
diff
changeset
|
26 |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27009
diff
changeset
|
27 from .. import ( |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27009
diff
changeset
|
28 archival, |
32922
582080a4a812
dagop: move blockancestors() and blockdescendants() from context
Yuya Nishihara <yuya@tcha.org>
parents:
32599
diff
changeset
|
29 dagop, |
27046
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27009
diff
changeset
|
30 encoding, |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27009
diff
changeset
|
31 error, |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27009
diff
changeset
|
32 graphmod, |
34809
3a65012be661
webcommands: replace str(ctx) etc with pycompat.bytestr(ctx) etc
Augie Fackler <augie@google.com>
parents:
34695
diff
changeset
|
33 pycompat, |
27046
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27009
diff
changeset
|
34 revset, |
31044
0b8356705de6
revset: split language services to revsetlang module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
31043
diff
changeset
|
35 revsetlang, |
27046
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27009
diff
changeset
|
36 scmutil, |
31043
aea06029919e
revset: import set classes directly from smartset module
Yuya Nishihara <yuya@tcha.org>
parents:
30826
diff
changeset
|
37 smartset, |
37400
47aea60d114d
hgweb: fix search {entries} to not return results of template expansion
Yuya Nishihara <yuya@tcha.org>
parents:
37387
diff
changeset
|
38 templateutil, |
37087
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
37069
diff
changeset
|
39 ) |
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
37069
diff
changeset
|
40 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
41 from ..utils import stringutil |
27046
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27009
diff
changeset
|
42 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
43 from . import webutil |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
44 |
24076
b53d2afd11fb
webcommands: define web commands using a decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23992
diff
changeset
|
45 __all__ = [] |
24077
e8046ca0405d
webcommands: define a dict of available commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24076
diff
changeset
|
46 commands = {} |
24076
b53d2afd11fb
webcommands: define web commands using a decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23992
diff
changeset
|
47 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
48 |
49037
642e31cb55f0
py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents:
49004
diff
changeset
|
49 class webcommand: |
24076
b53d2afd11fb
webcommands: define web commands using a decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23992
diff
changeset
|
50 """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
|
51 |
b53d2afd11fb
webcommands: define web commands using a decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23992
diff
changeset
|
52 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
|
53 command should be accessible under. |
b53d2afd11fb
webcommands: define web commands using a decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23992
diff
changeset
|
54 |
36876
1f42d621f090
hgweb: support using new response object for web commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36871
diff
changeset
|
55 When called, functions receive as arguments a ``requestcontext``, |
1f42d621f090
hgweb: support using new response object for web commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36871
diff
changeset
|
56 ``wsgirequest``, and a templater instance for generatoring output. |
1f42d621f090
hgweb: support using new response object for web commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36871
diff
changeset
|
57 The functions should populate the ``rctx.res`` object with details |
1f42d621f090
hgweb: support using new response object for web commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36871
diff
changeset
|
58 about the HTTP response. |
1f42d621f090
hgweb: support using new response object for web commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36871
diff
changeset
|
59 |
36886
67fb0dca29bc
hgweb: always return iterable from @webcommand functions (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36882
diff
changeset
|
60 The function returns a generator to be consumed by the WSGI application. |
67fb0dca29bc
hgweb: always return iterable from @webcommand functions (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36882
diff
changeset
|
61 For most commands, this should be the result from |
36889
061635d4221c
hgweb: add a sendtemplate() helper function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36888
diff
changeset
|
62 ``web.res.sendresponse()``. Many commands will call ``web.sendtemplate()`` |
061635d4221c
hgweb: add a sendtemplate() helper function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36888
diff
changeset
|
63 to render a template. |
36876
1f42d621f090
hgweb: support using new response object for web commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36871
diff
changeset
|
64 |
24076
b53d2afd11fb
webcommands: define web commands using a decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23992
diff
changeset
|
65 Usage: |
5963
5be210afe1b8
hgweb: explicitly check if requested command exists
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5960
diff
changeset
|
66 |
24076
b53d2afd11fb
webcommands: define web commands using a decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23992
diff
changeset
|
67 @webcommand('mycommand') |
36893
4daa22071d5d
hgweb: stop passing req and tmpl into @webcommand functions (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36892
diff
changeset
|
68 def mycommand(web): |
24076
b53d2afd11fb
webcommands: define web commands using a decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23992
diff
changeset
|
69 pass |
b53d2afd11fb
webcommands: define web commands using a decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23992
diff
changeset
|
70 """ |
5963
5be210afe1b8
hgweb: explicitly check if requested command exists
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5960
diff
changeset
|
71 |
24076
b53d2afd11fb
webcommands: define web commands using a decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23992
diff
changeset
|
72 def __init__(self, name): |
b53d2afd11fb
webcommands: define web commands using a decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23992
diff
changeset
|
73 self.name = name |
b53d2afd11fb
webcommands: define web commands using a decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23992
diff
changeset
|
74 |
b53d2afd11fb
webcommands: define web commands using a decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23992
diff
changeset
|
75 def __call__(self, func): |
51672
99632adff795
py3: fix type of some elements of __all__ lists
Manuel Jacob <me@manueljacob.de>
parents:
51304
diff
changeset
|
76 __all__.append(pycompat.sysstr(self.name)) |
24077
e8046ca0405d
webcommands: define a dict of available commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24076
diff
changeset
|
77 commands[self.name] = func |
24076
b53d2afd11fb
webcommands: define web commands using a decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23992
diff
changeset
|
78 return func |
b53d2afd11fb
webcommands: define web commands using a decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23992
diff
changeset
|
79 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
80 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
81 @webcommand(b'log') |
36893
4daa22071d5d
hgweb: stop passing req and tmpl into @webcommand functions (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36892
diff
changeset
|
82 def log(web): |
24087
6f5b4393590c
webcommands: document "log" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24086
diff
changeset
|
83 """ |
6f5b4393590c
webcommands: document "log" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24086
diff
changeset
|
84 /log[/{revision}[/{path}]] |
6f5b4393590c
webcommands: document "log" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24086
diff
changeset
|
85 -------------------------- |
6f5b4393590c
webcommands: document "log" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24086
diff
changeset
|
86 |
6f5b4393590c
webcommands: document "log" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24086
diff
changeset
|
87 Show repository or file history. |
6f5b4393590c
webcommands: document "log" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24086
diff
changeset
|
88 |
6f5b4393590c
webcommands: document "log" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24086
diff
changeset
|
89 For URLs of the form ``/log/{revision}``, a list of changesets starting at |
6f5b4393590c
webcommands: document "log" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24086
diff
changeset
|
90 the specified changeset identifier is shown. If ``{revision}`` is not |
6f5b4393590c
webcommands: document "log" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24086
diff
changeset
|
91 defined, the default is ``tip``. This form is equivalent to the |
6f5b4393590c
webcommands: document "log" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24086
diff
changeset
|
92 ``changelog`` handler. |
6f5b4393590c
webcommands: document "log" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24086
diff
changeset
|
93 |
6f5b4393590c
webcommands: document "log" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24086
diff
changeset
|
94 For URLs of the form ``/log/{revision}/{file}``, the history for a specific |
6f5b4393590c
webcommands: document "log" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24086
diff
changeset
|
95 file will be shown. This form is equivalent to the ``filelog`` handler. |
6f5b4393590c
webcommands: document "log" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24086
diff
changeset
|
96 """ |
6f5b4393590c
webcommands: document "log" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24086
diff
changeset
|
97 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
98 if web.req.qsparams.get(b'file'): |
36893
4daa22071d5d
hgweb: stop passing req and tmpl into @webcommand functions (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36892
diff
changeset
|
99 return filelog(web) |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
100 else: |
36893
4daa22071d5d
hgweb: stop passing req and tmpl into @webcommand functions (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36892
diff
changeset
|
101 return changelog(web) |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
102 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
103 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
104 @webcommand(b'rawfile') |
36893
4daa22071d5d
hgweb: stop passing req and tmpl into @webcommand functions (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36892
diff
changeset
|
105 def rawfile(web): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
106 guessmime = web.configbool(b'web', b'guessmime') |
15004
d06b9c55ddab
hgweb: raw file mimetype guessing configurable, off by default (BC) (issue2923)
Matt Mackall <mpm@selenic.com>
parents:
14771
diff
changeset
|
107 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
108 path = webutil.cleanpath(web.repo, web.req.qsparams.get(b'file', b'')) |
5890
a0e20a5eba3c
hgweb: fast path for sending raw files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5600
diff
changeset
|
109 if not path: |
36893
4daa22071d5d
hgweb: stop passing req and tmpl into @webcommand functions (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36892
diff
changeset
|
110 return manifest(web) |
5890
a0e20a5eba3c
hgweb: fast path for sending raw files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5600
diff
changeset
|
111 |
a0e20a5eba3c
hgweb: fast path for sending raw files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5600
diff
changeset
|
112 try: |
36892
563fd95a6efb
hgweb: pass modern request type into various webutil functions (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
113 fctx = webutil.filectx(web.repo, web.req) |
25660
328739ea70c3
global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25602
diff
changeset
|
114 except error.LookupError as inst: |
6368
2c370f08c486
hgweb: better error messages
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6217
diff
changeset
|
115 try: |
36893
4daa22071d5d
hgweb: stop passing req and tmpl into @webcommand functions (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36892
diff
changeset
|
116 return manifest(web) |
6368
2c370f08c486
hgweb: better error messages
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6217
diff
changeset
|
117 except ErrorResponse: |
2c370f08c486
hgweb: better error messages
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6217
diff
changeset
|
118 raise inst |
5890
a0e20a5eba3c
hgweb: fast path for sending raw files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5600
diff
changeset
|
119 |
a0e20a5eba3c
hgweb: fast path for sending raw files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5600
diff
changeset
|
120 path = fctx.path() |
a0e20a5eba3c
hgweb: fast path for sending raw files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5600
diff
changeset
|
121 text = fctx.data() |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
122 mt = b'application/binary' |
15004
d06b9c55ddab
hgweb: raw file mimetype guessing configurable, off by default (BC) (issue2923)
Matt Mackall <mpm@selenic.com>
parents:
14771
diff
changeset
|
123 if guessmime: |
40158
9310037f0636
py3: pass str and return bytes from mimetypes.guess_type()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39810
diff
changeset
|
124 mt = mimetypes.guess_type(pycompat.fsdecode(path))[0] |
15004
d06b9c55ddab
hgweb: raw file mimetype guessing configurable, off by default (BC) (issue2923)
Matt Mackall <mpm@selenic.com>
parents:
14771
diff
changeset
|
125 if mt is None: |
37087
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
37069
diff
changeset
|
126 if stringutil.binary(text): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
127 mt = b'application/binary' |
24306
6ddc86eedc3b
style: kill ersatz if-else ternary operators
Jordi Guti?rrez Hermoso <jordigh@octave.org>
parents:
24177
diff
changeset
|
128 else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
129 mt = b'text/plain' |
40158
9310037f0636
py3: pass str and return bytes from mimetypes.guess_type()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39810
diff
changeset
|
130 else: |
9310037f0636
py3: pass str and return bytes from mimetypes.guess_type()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39810
diff
changeset
|
131 mt = pycompat.sysbytes(mt) |
9310037f0636
py3: pass str and return bytes from mimetypes.guess_type()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39810
diff
changeset
|
132 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
133 if mt.startswith(b'text/'): |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
134 mt += b'; charset="%s"' % encoding.encoding |
5890
a0e20a5eba3c
hgweb: fast path for sending raw files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5600
diff
changeset
|
135 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
136 web.res.headers[b'Content-Type'] = mt |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
137 filename = ( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
138 path.rpartition(b'/')[-1].replace(b'\\', b'\\\\').replace(b'"', b'\\"') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
139 ) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
140 web.res.headers[b'Content-Disposition'] = ( |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
141 b'inline; filename="%s"' % filename |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
142 ) |
36877
9fc3d814646e
hgweb: port most @webcommand to use modern response type
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36876
diff
changeset
|
143 web.res.setbodybytes(text) |
36886
67fb0dca29bc
hgweb: always return iterable from @webcommand functions (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36882
diff
changeset
|
144 return web.res.sendresponse() |
5890
a0e20a5eba3c
hgweb: fast path for sending raw files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5600
diff
changeset
|
145 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
146 |
36893
4daa22071d5d
hgweb: stop passing req and tmpl into @webcommand functions (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36892
diff
changeset
|
147 def _filerevision(web, fctx): |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
148 f = fctx.path() |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
149 text = fctx.data() |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
150 parity = paritygen(web.stripecount) |
39800
be0f32ca2671
hgweb: use heads() instead of headrevs()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39443
diff
changeset
|
151 ishead = fctx.filenode() in fctx.filelog().heads() |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
152 |
37087
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
37069
diff
changeset
|
153 if stringutil.binary(text): |
40158
9310037f0636
py3: pass str and return bytes from mimetypes.guess_type()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39810
diff
changeset
|
154 mt = pycompat.sysbytes( |
9310037f0636
py3: pass str and return bytes from mimetypes.guess_type()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39810
diff
changeset
|
155 mimetypes.guess_type(pycompat.fsdecode(f))[0] |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
156 or r'application/octet-stream' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
157 ) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
158 text = b'(binary:%s)' % mt |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
159 |
38093
aeccb08af311
hgweb: wrap {lines} of filerevision with mappinggenerator
Yuya Nishihara <yuya@tcha.org>
parents:
38076
diff
changeset
|
160 def lines(context): |
9136
31177742f54a
for calls expecting bool args, pass bool instead of int
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8842
diff
changeset
|
161 for lineno, t in enumerate(text.splitlines(True)): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
162 yield { |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
163 b"line": t, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
164 b"lineid": b"l%d" % (lineno + 1), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
165 b"linenumber": b"% 6d" % (lineno + 1), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
166 b"parity": next(parity), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
167 } |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
168 |
36889
061635d4221c
hgweb: add a sendtemplate() helper function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36888
diff
changeset
|
169 return web.sendtemplate( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
170 b'filerevision', |
36877
9fc3d814646e
hgweb: port most @webcommand to use modern response type
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36876
diff
changeset
|
171 file=f, |
9fc3d814646e
hgweb: port most @webcommand to use modern response type
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36876
diff
changeset
|
172 path=webutil.up(f), |
38093
aeccb08af311
hgweb: wrap {lines} of filerevision with mappinggenerator
Yuya Nishihara <yuya@tcha.org>
parents:
38076
diff
changeset
|
173 text=templateutil.mappinggenerator(lines), |
36892
563fd95a6efb
hgweb: pass modern request type into various webutil functions (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
174 symrev=webutil.symrevorshortnode(web.req, fctx), |
36877
9fc3d814646e
hgweb: port most @webcommand to use modern response type
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36876
diff
changeset
|
175 rename=webutil.renamelink(fctx), |
9fc3d814646e
hgweb: port most @webcommand to use modern response type
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36876
diff
changeset
|
176 permissions=fctx.manifest().flags(f), |
9fc3d814646e
hgweb: port most @webcommand to use modern response type
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36876
diff
changeset
|
177 ishead=int(ishead), |
51900
607e94e01851
format: add many "missing" comma
Matt Harbison <matt_harbison@yahoo.com>
parents:
51879
diff
changeset
|
178 **pycompat.strkwargs(webutil.commonentry(web.repo, fctx)), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
179 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
180 |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
181 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
182 @webcommand(b'file') |
36893
4daa22071d5d
hgweb: stop passing req and tmpl into @webcommand functions (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36892
diff
changeset
|
183 def file(web): |
24088
fe3ee31b039f
webcommands: document "file" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24087
diff
changeset
|
184 """ |
fe3ee31b039f
webcommands: document "file" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24087
diff
changeset
|
185 /file/{revision}[/{path}] |
fe3ee31b039f
webcommands: document "file" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24087
diff
changeset
|
186 ------------------------- |
fe3ee31b039f
webcommands: document "file" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24087
diff
changeset
|
187 |
fe3ee31b039f
webcommands: document "file" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24087
diff
changeset
|
188 Show information about a directory or file in the repository. |
fe3ee31b039f
webcommands: document "file" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24087
diff
changeset
|
189 |
fe3ee31b039f
webcommands: document "file" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24087
diff
changeset
|
190 Info about the ``path`` given as a URL parameter will be rendered. |
fe3ee31b039f
webcommands: document "file" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24087
diff
changeset
|
191 |
fe3ee31b039f
webcommands: document "file" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24087
diff
changeset
|
192 If ``path`` is a directory, information about the entries in that |
fe3ee31b039f
webcommands: document "file" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24087
diff
changeset
|
193 directory will be rendered. This form is equivalent to the ``manifest`` |
fe3ee31b039f
webcommands: document "file" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24087
diff
changeset
|
194 handler. |
fe3ee31b039f
webcommands: document "file" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24087
diff
changeset
|
195 |
fe3ee31b039f
webcommands: document "file" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24087
diff
changeset
|
196 If ``path`` is a file, information about that file will be shown via |
fe3ee31b039f
webcommands: document "file" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24087
diff
changeset
|
197 the ``filerevision`` template. |
fe3ee31b039f
webcommands: document "file" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24087
diff
changeset
|
198 |
fe3ee31b039f
webcommands: document "file" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24087
diff
changeset
|
199 If ``path`` is not defined, information about the root directory will |
fe3ee31b039f
webcommands: document "file" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24087
diff
changeset
|
200 be rendered. |
fe3ee31b039f
webcommands: document "file" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24087
diff
changeset
|
201 """ |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
202 if web.req.qsparams.get(b'style') == b'raw': |
36893
4daa22071d5d
hgweb: stop passing req and tmpl into @webcommand functions (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36892
diff
changeset
|
203 return rawfile(web) |
36878
89002d07a114
hgweb: remove one-off routing for file?style=raw
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36877
diff
changeset
|
204 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
205 path = webutil.cleanpath(web.repo, web.req.qsparams.get(b'file', b'')) |
6853
2ff0829bdae5
hgweb: do not use unassigned variables in exception handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6669
diff
changeset
|
206 if not path: |
36893
4daa22071d5d
hgweb: stop passing req and tmpl into @webcommand functions (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36892
diff
changeset
|
207 return manifest(web) |
6853
2ff0829bdae5
hgweb: do not use unassigned variables in exception handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6669
diff
changeset
|
208 try: |
36893
4daa22071d5d
hgweb: stop passing req and tmpl into @webcommand functions (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36892
diff
changeset
|
209 return _filerevision(web, webutil.filectx(web.repo, web.req)) |
25660
328739ea70c3
global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25602
diff
changeset
|
210 except error.LookupError as inst: |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
211 try: |
36893
4daa22071d5d
hgweb: stop passing req and tmpl into @webcommand functions (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36892
diff
changeset
|
212 return manifest(web) |
6853
2ff0829bdae5
hgweb: do not use unassigned variables in exception handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6669
diff
changeset
|
213 except ErrorResponse: |
2ff0829bdae5
hgweb: do not use unassigned variables in exception handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6669
diff
changeset
|
214 raise inst |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
215 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
216 |
36890
ece242db5000
hgweb: use templater on requestcontext instance
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36889
diff
changeset
|
217 def _search(web): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
218 MODE_REVISION = b'rev' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
219 MODE_KEYWORD = b'keyword' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
220 MODE_REVSET = b'revset' |
10247
e8c7410371e0
hgweb: add less/more links for search logs (issue1972)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10246
diff
changeset
|
221 |
19633
217f2b9acee0
hgweb: search() function supports direct pointing to revision
Alexander Plavin <alexander@plav.in>
parents:
19632
diff
changeset
|
222 def revsearch(ctx): |
217f2b9acee0
hgweb: search() function supports direct pointing to revision
Alexander Plavin <alexander@plav.in>
parents:
19632
diff
changeset
|
223 yield ctx |
217f2b9acee0
hgweb: search() function supports direct pointing to revision
Alexander Plavin <alexander@plav.in>
parents:
19632
diff
changeset
|
224 |
19632
299511aabf85
hgweb: pass arguments which a function depends on explicitly in search
Alexander Plavin <alexander@plav.in>
parents:
19631
diff
changeset
|
225 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
|
226 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
|
227 qw = lower(query).split() |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
228 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
229 def revgen(): |
18497
a58d8936647a
hgweb: prevent traceback during search when filtered (issue3783)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18478
diff
changeset
|
230 cl = web.repo.changelog |
49292
d44e3c45f0e4
py3: replace `pycompat.xrange` by `range`
Manuel Jacob <me@manueljacob.de>
parents:
49037
diff
changeset
|
231 for i in range(len(web.repo) - 1, 0, -100): |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
232 l = [] |
19491
e111d5e6bbbd
hgweb: fix duplication for some search queries
Alexander Plavin <me@aplavin.ru>
parents:
19487
diff
changeset
|
233 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
|
234 ctx = web.repo[j] |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
235 l.append(ctx) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
236 l.reverse() |
52669
e627cc25b6f3
pyupgrade: rewrite `yield` statements in a loop to `yield from`
Matt Harbison <matt_harbison@yahoo.com>
parents:
52663
diff
changeset
|
237 yield from l |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
238 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
239 for ctx in revgen(): |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
240 miss = 0 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
241 for q in qw: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
242 if not ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
243 q in lower(ctx.user()) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
244 or q in lower(ctx.description()) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
245 or q in lower(b" ".join(ctx.files())) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
246 ): |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
247 miss = 1 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
248 break |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
249 if miss: |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
250 continue |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
251 |
19533
9a020b354d93
hgweb: separate search itself and template generation
Alexander Plavin <alexander@plav.in>
parents:
19499
diff
changeset
|
252 yield ctx |
9a020b354d93
hgweb: separate search itself and template generation
Alexander Plavin <alexander@plav.in>
parents:
19499
diff
changeset
|
253 |
19722
bf15935b68a3
hgweb: add revset syntax support to search
Alexander Plavin <alexander@plav.in>
parents:
19657
diff
changeset
|
254 def revsetsearch(revs): |
bf15935b68a3
hgweb: add revset syntax support to search
Alexander Plavin <alexander@plav.in>
parents:
19657
diff
changeset
|
255 for r in revs: |
bf15935b68a3
hgweb: add revset syntax support to search
Alexander Plavin <alexander@plav.in>
parents:
19657
diff
changeset
|
256 yield web.repo[r] |
bf15935b68a3
hgweb: add revset syntax support to search
Alexander Plavin <alexander@plav.in>
parents:
19657
diff
changeset
|
257 |
19631
cf9e5e45c1d3
hgweb: add dynamic search function selection, depending on the query
Alexander Plavin <alexander@plav.in>
parents:
19534
diff
changeset
|
258 searchfuncs = { |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
259 MODE_REVISION: (revsearch, b'exact revision search'), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
260 MODE_KEYWORD: (keywordsearch, b'literal keyword search'), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
261 MODE_REVSET: (revsetsearch, b'revset expression search'), |
19631
cf9e5e45c1d3
hgweb: add dynamic search function selection, depending on the query
Alexander Plavin <alexander@plav.in>
parents:
19534
diff
changeset
|
262 } |
cf9e5e45c1d3
hgweb: add dynamic search function selection, depending on the query
Alexander Plavin <alexander@plav.in>
parents:
19534
diff
changeset
|
263 |
19632
299511aabf85
hgweb: pass arguments which a function depends on explicitly in search
Alexander Plavin <alexander@plav.in>
parents:
19631
diff
changeset
|
264 def getsearchmode(query): |
19633
217f2b9acee0
hgweb: search() function supports direct pointing to revision
Alexander Plavin <alexander@plav.in>
parents:
19632
diff
changeset
|
265 try: |
37387
83d537162894
hgweb: use revsymbol() to determine if query is a revision
Martin von Zweigbergk <martinvonz@google.com>
parents:
37363
diff
changeset
|
266 ctx = scmutil.revsymbol(web.repo, query) |
19633
217f2b9acee0
hgweb: search() function supports direct pointing to revision
Alexander Plavin <alexander@plav.in>
parents:
19632
diff
changeset
|
267 except (error.RepoError, error.LookupError): |
19722
bf15935b68a3
hgweb: add revset syntax support to search
Alexander Plavin <alexander@plav.in>
parents:
19657
diff
changeset
|
268 # 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
|
269 # 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
|
270 pass |
19633
217f2b9acee0
hgweb: search() function supports direct pointing to revision
Alexander Plavin <alexander@plav.in>
parents:
19632
diff
changeset
|
271 else: |
19656
60ce14e41faf
hgweb: add string constants for search mode names
Alexander Plavin <alexander@plav.in>
parents:
19634
diff
changeset
|
272 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
|
273 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
274 revdef = b'reverse(%s)' % query |
19722
bf15935b68a3
hgweb: add revset syntax support to search
Alexander Plavin <alexander@plav.in>
parents:
19657
diff
changeset
|
275 try: |
31044
0b8356705de6
revset: split language services to revsetlang module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
31043
diff
changeset
|
276 tree = revsetlang.parse(revdef) |
27009
f5faef7e9119
hgweb: unify import style of error classes
Yuya Nishihara <yuya@tcha.org>
parents:
26894
diff
changeset
|
277 except error.ParseError: |
19722
bf15935b68a3
hgweb: add revset syntax support to search
Alexander Plavin <alexander@plav.in>
parents:
19657
diff
changeset
|
278 # can't parse to a revset tree |
bf15935b68a3
hgweb: add revset syntax support to search
Alexander Plavin <alexander@plav.in>
parents:
19657
diff
changeset
|
279 return MODE_KEYWORD, query |
bf15935b68a3
hgweb: add revset syntax support to search
Alexander Plavin <alexander@plav.in>
parents:
19657
diff
changeset
|
280 |
31044
0b8356705de6
revset: split language services to revsetlang module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
31043
diff
changeset
|
281 if revsetlang.depth(tree) <= 2: |
19722
bf15935b68a3
hgweb: add revset syntax support to search
Alexander Plavin <alexander@plav.in>
parents:
19657
diff
changeset
|
282 # no revset syntax used |
bf15935b68a3
hgweb: add revset syntax support to search
Alexander Plavin <alexander@plav.in>
parents:
19657
diff
changeset
|
283 return MODE_KEYWORD, query |
bf15935b68a3
hgweb: add revset syntax support to search
Alexander Plavin <alexander@plav.in>
parents:
19657
diff
changeset
|
284 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
285 if any( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
286 (token, (value or b'')[:3]) == (b'string', b're:') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
287 for token, value, pos in revsetlang.tokenize(revdef) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
288 ): |
19722
bf15935b68a3
hgweb: add revset syntax support to search
Alexander Plavin <alexander@plav.in>
parents:
19657
diff
changeset
|
289 return MODE_KEYWORD, query |
bf15935b68a3
hgweb: add revset syntax support to search
Alexander Plavin <alexander@plav.in>
parents:
19657
diff
changeset
|
290 |
31044
0b8356705de6
revset: split language services to revsetlang module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
31043
diff
changeset
|
291 funcsused = revsetlang.funcsused(tree) |
19722
bf15935b68a3
hgweb: add revset syntax support to search
Alexander Plavin <alexander@plav.in>
parents:
19657
diff
changeset
|
292 if not funcsused.issubset(revset.safesymbols): |
bf15935b68a3
hgweb: add revset syntax support to search
Alexander Plavin <alexander@plav.in>
parents:
19657
diff
changeset
|
293 return MODE_KEYWORD, query |
bf15935b68a3
hgweb: add revset syntax support to search
Alexander Plavin <alexander@plav.in>
parents:
19657
diff
changeset
|
294 |
bf15935b68a3
hgweb: add revset syntax support to search
Alexander Plavin <alexander@plav.in>
parents:
19657
diff
changeset
|
295 try: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
296 mfunc = revset.match( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
297 web.repo.ui, revdef, lookup=revset.lookupfn(web.repo) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
298 ) |
24114
fafd9a1284cf
revset: make match function initiate query from full set by default
Yuya Nishihara <yuya@tcha.org>
parents:
24097
diff
changeset
|
299 revs = mfunc(web.repo) |
19722
bf15935b68a3
hgweb: add revset syntax support to search
Alexander Plavin <alexander@plav.in>
parents:
19657
diff
changeset
|
300 return MODE_REVSET, revs |
bf15935b68a3
hgweb: add revset syntax support to search
Alexander Plavin <alexander@plav.in>
parents:
19657
diff
changeset
|
301 # ParseError: wrongly placed tokens, wrongs arguments, etc |
bf15935b68a3
hgweb: add revset syntax support to search
Alexander Plavin <alexander@plav.in>
parents:
19657
diff
changeset
|
302 # 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
|
303 # Abort: bookmark/tag not exists |
bf15935b68a3
hgweb: add revset syntax support to search
Alexander Plavin <alexander@plav.in>
parents:
19657
diff
changeset
|
304 # LookupError: ambiguous identifier, e.g. in '(bc)' on a large repo |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
305 except ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
306 error.ParseError, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
307 error.RepoLookupError, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
308 error.Abort, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
309 LookupError, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
310 ): |
19722
bf15935b68a3
hgweb: add revset syntax support to search
Alexander Plavin <alexander@plav.in>
parents:
19657
diff
changeset
|
311 return MODE_KEYWORD, query |
bf15935b68a3
hgweb: add revset syntax support to search
Alexander Plavin <alexander@plav.in>
parents:
19657
diff
changeset
|
312 |
37400
47aea60d114d
hgweb: fix search {entries} to not return results of template expansion
Yuya Nishihara <yuya@tcha.org>
parents:
37387
diff
changeset
|
313 def changelist(context): |
19533
9a020b354d93
hgweb: separate search itself and template generation
Alexander Plavin <alexander@plav.in>
parents:
19499
diff
changeset
|
314 count = 0 |
9a020b354d93
hgweb: separate search itself and template generation
Alexander Plavin <alexander@plav.in>
parents:
19499
diff
changeset
|
315 |
19765
521c373ff134
hgweb: pass variable with current search mode name to the search template
Alexander Plavin <alexander@plav.in>
parents:
19738
diff
changeset
|
316 for ctx in searchfunc[0](funcarg): |
6659
bc553c6d1ef9
webcommands: fix increments lost by 894875eae49b
Andrew Beekhof <beekhof@gmail.com>
parents:
6657
diff
changeset
|
317 count += 1 |
39810
4f44f747f094
hgweb: use scmutil.binnode() to translate None to wdir hash (issue5988)
Yuya Nishihara <yuya@tcha.org>
parents:
39809
diff
changeset
|
318 n = scmutil.binnode(ctx) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
319 showtags = webutil.showtag(web.repo, b'changelogtag', n) |
37998
9482498b96b0
hgweb: remove unused argument 'tmpl' from listfilediffs()
Yuya Nishihara <yuya@tcha.org>
parents:
37956
diff
changeset
|
320 files = webutil.listfilediffs(ctx.files(), n, web.maxfiles) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
321 |
37022
c97b936d8bb5
templater: use named function to expand template against mapping dict (API)
Yuya Nishihara <yuya@tcha.org>
parents:
36983
diff
changeset
|
322 lm = webutil.commonentry(web.repo, ctx) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
323 lm.update( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
324 { |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
325 b'parity': next(parity), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
326 b'changelogtag': showtags, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
327 b'files': files, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
328 } |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
329 ) |
37400
47aea60d114d
hgweb: fix search {entries} to not return results of template expansion
Yuya Nishihara <yuya@tcha.org>
parents:
37387
diff
changeset
|
330 yield lm |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
331 |
10247
e8c7410371e0
hgweb: add less/more links for search logs (issue1972)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10246
diff
changeset
|
332 if count >= revcount: |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
333 break |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
334 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
335 query = web.req.qsparams[b'rev'] |
19418
55b9d98a1ef4
hgweb: move local changelist function to the beginning of the parent one
Alexander Plavin <me@aplavin.ru>
parents:
19396
diff
changeset
|
336 revcount = web.maxchanges |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
337 if b'revcount' in web.req.qsparams: |
20092
77acd8ce01ce
hgweb: ignore non numeric "revcount" parameter values (issue4091)
Isaac Jurado <diptongo@gmail.com>
parents:
20004
diff
changeset
|
338 try: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
339 revcount = int(web.req.qsparams.get(b'revcount', revcount)) |
20092
77acd8ce01ce
hgweb: ignore non numeric "revcount" parameter values (issue4091)
Isaac Jurado <diptongo@gmail.com>
parents:
20004
diff
changeset
|
340 revcount = max(revcount, 1) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
341 web.tmpl.defaults[b'sessionvars'][b'revcount'] = revcount |
20092
77acd8ce01ce
hgweb: ignore non numeric "revcount" parameter values (issue4091)
Isaac Jurado <diptongo@gmail.com>
parents:
20004
diff
changeset
|
342 except ValueError: |
77acd8ce01ce
hgweb: ignore non numeric "revcount" parameter values (issue4091)
Isaac Jurado <diptongo@gmail.com>
parents:
20004
diff
changeset
|
343 pass |
19418
55b9d98a1ef4
hgweb: move local changelist function to the beginning of the parent one
Alexander Plavin <me@aplavin.ru>
parents:
19396
diff
changeset
|
344 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
345 lessvars = copy.copy(web.tmpl.defaults[b'sessionvars']) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
346 lessvars[b'revcount'] = max(revcount // 2, 1) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
347 lessvars[b'rev'] = query |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
348 morevars = copy.copy(web.tmpl.defaults[b'sessionvars']) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
349 morevars[b'revcount'] = revcount * 2 |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
350 morevars[b'rev'] = query |
19418
55b9d98a1ef4
hgweb: move local changelist function to the beginning of the parent one
Alexander Plavin <me@aplavin.ru>
parents:
19396
diff
changeset
|
351 |
19632
299511aabf85
hgweb: pass arguments which a function depends on explicitly in search
Alexander Plavin <alexander@plav.in>
parents:
19631
diff
changeset
|
352 mode, funcarg = getsearchmode(query) |
19768
186f54d40fdd
hgweb: add link to force literal keyword search
Alexander Plavin <alexander@plav.in>
parents:
19765
diff
changeset
|
353 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
354 if b'forcekw' in web.req.qsparams: |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
355 showforcekw = b'' |
19768
186f54d40fdd
hgweb: add link to force literal keyword search
Alexander Plavin <alexander@plav.in>
parents:
19765
diff
changeset
|
356 showunforcekw = searchfuncs[mode][1] |
186f54d40fdd
hgweb: add link to force literal keyword search
Alexander Plavin <alexander@plav.in>
parents:
19765
diff
changeset
|
357 mode = MODE_KEYWORD |
186f54d40fdd
hgweb: add link to force literal keyword search
Alexander Plavin <alexander@plav.in>
parents:
19765
diff
changeset
|
358 funcarg = query |
186f54d40fdd
hgweb: add link to force literal keyword search
Alexander Plavin <alexander@plav.in>
parents:
19765
diff
changeset
|
359 else: |
186f54d40fdd
hgweb: add link to force literal keyword search
Alexander Plavin <alexander@plav.in>
parents:
19765
diff
changeset
|
360 if mode != MODE_KEYWORD: |
186f54d40fdd
hgweb: add link to force literal keyword search
Alexander Plavin <alexander@plav.in>
parents:
19765
diff
changeset
|
361 showforcekw = searchfuncs[MODE_KEYWORD][1] |
186f54d40fdd
hgweb: add link to force literal keyword search
Alexander Plavin <alexander@plav.in>
parents:
19765
diff
changeset
|
362 else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
363 showforcekw = b'' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
364 showunforcekw = b'' |
19768
186f54d40fdd
hgweb: add link to force literal keyword search
Alexander Plavin <alexander@plav.in>
parents:
19765
diff
changeset
|
365 |
19631
cf9e5e45c1d3
hgweb: add dynamic search function selection, depending on the query
Alexander Plavin <alexander@plav.in>
parents:
19534
diff
changeset
|
366 searchfunc = searchfuncs[mode] |
cf9e5e45c1d3
hgweb: add dynamic search function selection, depending on the query
Alexander Plavin <alexander@plav.in>
parents:
19534
diff
changeset
|
367 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
368 tip = web.repo[b'tip'] |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
369 parity = paritygen(web.stripecount) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
370 |
36889
061635d4221c
hgweb: add a sendtemplate() helper function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36888
diff
changeset
|
371 return web.sendtemplate( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
372 b'search', |
36877
9fc3d814646e
hgweb: port most @webcommand to use modern response type
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36876
diff
changeset
|
373 query=query, |
9fc3d814646e
hgweb: port most @webcommand to use modern response type
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36876
diff
changeset
|
374 node=tip.hex(), |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
375 symrev=b'tip', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
376 entries=templateutil.mappinggenerator(changelist, name=b'searchentry'), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
377 archives=web.archivelist(b'tip'), |
36877
9fc3d814646e
hgweb: port most @webcommand to use modern response type
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36876
diff
changeset
|
378 morevars=morevars, |
9fc3d814646e
hgweb: port most @webcommand to use modern response type
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36876
diff
changeset
|
379 lessvars=lessvars, |
9fc3d814646e
hgweb: port most @webcommand to use modern response type
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36876
diff
changeset
|
380 modedesc=searchfunc[1], |
9fc3d814646e
hgweb: port most @webcommand to use modern response type
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36876
diff
changeset
|
381 showforcekw=showforcekw, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
382 showunforcekw=showunforcekw, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
383 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
384 |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
385 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
386 @webcommand(b'changelog') |
36893
4daa22071d5d
hgweb: stop passing req and tmpl into @webcommand functions (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36892
diff
changeset
|
387 def changelog(web, shortlog=False): |
24089
f17773432782
webcommands: document "changelog" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24088
diff
changeset
|
388 """ |
f17773432782
webcommands: document "changelog" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24088
diff
changeset
|
389 /changelog[/{revision}] |
f17773432782
webcommands: document "changelog" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24088
diff
changeset
|
390 ----------------------- |
f17773432782
webcommands: document "changelog" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24088
diff
changeset
|
391 |
f17773432782
webcommands: document "changelog" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24088
diff
changeset
|
392 Show information about multiple changesets. |
f17773432782
webcommands: document "changelog" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24088
diff
changeset
|
393 |
f17773432782
webcommands: document "changelog" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24088
diff
changeset
|
394 If the optional ``revision`` URL argument is absent, information about |
f17773432782
webcommands: document "changelog" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24088
diff
changeset
|
395 all changesets starting at ``tip`` will be rendered. If the ``revision`` |
f17773432782
webcommands: document "changelog" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24088
diff
changeset
|
396 argument is present, changesets will be shown starting from the specified |
f17773432782
webcommands: document "changelog" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24088
diff
changeset
|
397 revision. |
f17773432782
webcommands: document "changelog" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24088
diff
changeset
|
398 |
f17773432782
webcommands: document "changelog" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24088
diff
changeset
|
399 If ``revision`` is absent, the ``rev`` query string argument may be |
f17773432782
webcommands: document "changelog" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24088
diff
changeset
|
400 defined. This will perform a search for changesets. |
f17773432782
webcommands: document "changelog" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24088
diff
changeset
|
401 |
f17773432782
webcommands: document "changelog" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24088
diff
changeset
|
402 The argument for ``rev`` can be a single revision, a revision set, |
f17773432782
webcommands: document "changelog" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24088
diff
changeset
|
403 or a literal keyword to search for in changeset data (equivalent to |
24867
6d97ca3f05ba
webcommands: fix typo in changelog documentation
Wagner Bruna <wbruna@softwareexpress.com.br>
parents:
24859
diff
changeset
|
404 :hg:`log -k`). |
24089
f17773432782
webcommands: document "changelog" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24088
diff
changeset
|
405 |
f17773432782
webcommands: document "changelog" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24088
diff
changeset
|
406 The ``revcount`` query string argument defines the maximum numbers of |
f17773432782
webcommands: document "changelog" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24088
diff
changeset
|
407 changesets to render. |
f17773432782
webcommands: document "changelog" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24088
diff
changeset
|
408 |
f17773432782
webcommands: document "changelog" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24088
diff
changeset
|
409 For non-searches, the ``changelog`` template will be rendered. |
f17773432782
webcommands: document "changelog" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24088
diff
changeset
|
410 """ |
10247
e8c7410371e0
hgweb: add less/more links for search logs (issue1972)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10246
diff
changeset
|
411 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
412 query = b'' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
413 if b'node' in web.req.qsparams: |
36892
563fd95a6efb
hgweb: pass modern request type into various webutil functions (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
414 ctx = webutil.changectx(web.repo, web.req) |
563fd95a6efb
hgweb: pass modern request type into various webutil functions (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
415 symrev = webutil.symrevorshortnode(web.req, ctx) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
416 elif b'rev' in web.req.qsparams: |
36890
ece242db5000
hgweb: use templater on requestcontext instance
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36889
diff
changeset
|
417 return _search(web) |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
418 else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
419 ctx = web.repo[b'tip'] |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
420 symrev = b'tip' |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
421 |
38780
ede3bf31fe63
hgweb: load revcount + 1 entries to fill nextentry in log page (issue5972)
Yuya Nishihara <yuya@tcha.org>
parents:
38768
diff
changeset
|
422 def changelist(maxcount): |
18427
56ca4443a343
hgweb: use changelog for iteration
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18409
diff
changeset
|
423 revs = [] |
19486
002b711a3e8a
hgweb: fix incorrect way to count revisions in log (issue3977)
Alexander Plavin <me@aplavin.ru>
parents:
19485
diff
changeset
|
424 if pos != -1: |
002b711a3e8a
hgweb: fix incorrect way to count revisions in log (issue3977)
Alexander Plavin <me@aplavin.ru>
parents:
19485
diff
changeset
|
425 revs = web.repo.changelog.revs(pos, 0) |
23745
513d47905114
hgweb: extract changelist entry generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23740
diff
changeset
|
426 |
52669
e627cc25b6f3
pyupgrade: rewrite `yield` statements in a loop to `yield from`
Matt Harbison <matt_harbison@yahoo.com>
parents:
52663
diff
changeset
|
427 yield from webutil.changelistentries(web, revs, maxcount, parity) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
428 |
24306
6ddc86eedc3b
style: kill ersatz if-else ternary operators
Jordi Guti?rrez Hermoso <jordigh@octave.org>
parents:
24177
diff
changeset
|
429 if shortlog: |
6ddc86eedc3b
style: kill ersatz if-else ternary operators
Jordi Guti?rrez Hermoso <jordigh@octave.org>
parents:
24177
diff
changeset
|
430 revcount = web.maxshortchanges |
6ddc86eedc3b
style: kill ersatz if-else ternary operators
Jordi Guti?rrez Hermoso <jordigh@octave.org>
parents:
24177
diff
changeset
|
431 else: |
6ddc86eedc3b
style: kill ersatz if-else ternary operators
Jordi Guti?rrez Hermoso <jordigh@octave.org>
parents:
24177
diff
changeset
|
432 revcount = web.maxchanges |
6ddc86eedc3b
style: kill ersatz if-else ternary operators
Jordi Guti?rrez Hermoso <jordigh@octave.org>
parents:
24177
diff
changeset
|
433 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
434 if b'revcount' in web.req.qsparams: |
20092
77acd8ce01ce
hgweb: ignore non numeric "revcount" parameter values (issue4091)
Isaac Jurado <diptongo@gmail.com>
parents:
20004
diff
changeset
|
435 try: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
436 revcount = int(web.req.qsparams.get(b'revcount', revcount)) |
20092
77acd8ce01ce
hgweb: ignore non numeric "revcount" parameter values (issue4091)
Isaac Jurado <diptongo@gmail.com>
parents:
20004
diff
changeset
|
437 revcount = max(revcount, 1) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
438 web.tmpl.defaults[b'sessionvars'][b'revcount'] = revcount |
20092
77acd8ce01ce
hgweb: ignore non numeric "revcount" parameter values (issue4091)
Isaac Jurado <diptongo@gmail.com>
parents:
20004
diff
changeset
|
439 except ValueError: |
77acd8ce01ce
hgweb: ignore non numeric "revcount" parameter values (issue4091)
Isaac Jurado <diptongo@gmail.com>
parents:
20004
diff
changeset
|
440 pass |
10246
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
441 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
442 lessvars = copy.copy(web.tmpl.defaults[b'sessionvars']) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
443 lessvars[b'revcount'] = max(revcount // 2, 1) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
444 morevars = copy.copy(web.tmpl.defaults[b'sessionvars']) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
445 morevars[b'revcount'] = revcount * 2 |
10246
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
446 |
12059
0de6cfdcaad8
webcommands: remove unncessary access to repo.changelog
Patrick Mezard <pmezard@gmail.com>
parents:
11332
diff
changeset
|
447 count = len(web.repo) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
448 pos = ctx.rev() |
19486
002b711a3e8a
hgweb: fix incorrect way to count revisions in log (issue3977)
Alexander Plavin <me@aplavin.ru>
parents:
19485
diff
changeset
|
449 parity = paritygen(web.stripecount) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
450 |
18409
e3f5cef11d6a
hgweb: pass repo object to revnav construction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18408
diff
changeset
|
451 changenav = webutil.revnav(web.repo).gen(pos, revcount, count) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
452 |
38780
ede3bf31fe63
hgweb: load revcount + 1 entries to fill nextentry in log page (issue5972)
Yuya Nishihara <yuya@tcha.org>
parents:
38768
diff
changeset
|
453 entries = list(changelist(revcount + 1)) |
19737
ab5442f45441
hgweb: always compute all entries and latestentry in changelog
Alexander Plavin <alexander@plav.in>
parents:
19735
diff
changeset
|
454 latestentry = entries[:1] |
19738
93b8544c4482
hgweb: add nextentry variable for easy pagination in changelog
Alexander Plavin <alexander@plav.in>
parents:
19737
diff
changeset
|
455 if len(entries) > revcount: |
93b8544c4482
hgweb: add nextentry variable for easy pagination in changelog
Alexander Plavin <alexander@plav.in>
parents:
19737
diff
changeset
|
456 nextentry = entries[-1:] |
93b8544c4482
hgweb: add nextentry variable for easy pagination in changelog
Alexander Plavin <alexander@plav.in>
parents:
19737
diff
changeset
|
457 entries = entries[:-1] |
93b8544c4482
hgweb: add nextentry variable for easy pagination in changelog
Alexander Plavin <alexander@plav.in>
parents:
19737
diff
changeset
|
458 else: |
93b8544c4482
hgweb: add nextentry variable for easy pagination in changelog
Alexander Plavin <alexander@plav.in>
parents:
19737
diff
changeset
|
459 nextentry = [] |
19737
ab5442f45441
hgweb: always compute all entries and latestentry in changelog
Alexander Plavin <alexander@plav.in>
parents:
19735
diff
changeset
|
460 |
36889
061635d4221c
hgweb: add a sendtemplate() helper function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36888
diff
changeset
|
461 return web.sendtemplate( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
462 b'shortlog' if shortlog else b'changelog', |
36877
9fc3d814646e
hgweb: port most @webcommand to use modern response type
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36876
diff
changeset
|
463 changenav=changenav, |
9fc3d814646e
hgweb: port most @webcommand to use modern response type
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36876
diff
changeset
|
464 node=ctx.hex(), |
9fc3d814646e
hgweb: port most @webcommand to use modern response type
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36876
diff
changeset
|
465 rev=pos, |
9fc3d814646e
hgweb: port most @webcommand to use modern response type
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36876
diff
changeset
|
466 symrev=symrev, |
9fc3d814646e
hgweb: port most @webcommand to use modern response type
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36876
diff
changeset
|
467 changesets=count, |
38094
d3b4c4769b5c
hgweb: wrap {entries}* of changelog with mappinglist
Yuya Nishihara <yuya@tcha.org>
parents:
38093
diff
changeset
|
468 entries=templateutil.mappinglist(entries), |
d3b4c4769b5c
hgweb: wrap {entries}* of changelog with mappinglist
Yuya Nishihara <yuya@tcha.org>
parents:
38093
diff
changeset
|
469 latestentry=templateutil.mappinglist(latestentry), |
d3b4c4769b5c
hgweb: wrap {entries}* of changelog with mappinglist
Yuya Nishihara <yuya@tcha.org>
parents:
38093
diff
changeset
|
470 nextentry=templateutil.mappinglist(nextentry), |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
471 archives=web.archivelist(b'tip'), |
36877
9fc3d814646e
hgweb: port most @webcommand to use modern response type
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36876
diff
changeset
|
472 revcount=revcount, |
9fc3d814646e
hgweb: port most @webcommand to use modern response type
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36876
diff
changeset
|
473 morevars=morevars, |
9fc3d814646e
hgweb: port most @webcommand to use modern response type
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36876
diff
changeset
|
474 lessvars=lessvars, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
475 query=query, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
476 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
477 |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
478 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
479 @webcommand(b'shortlog') |
36893
4daa22071d5d
hgweb: stop passing req and tmpl into @webcommand functions (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36892
diff
changeset
|
480 def shortlog(web): |
24086
2d8e93554822
webcommands: document "shortlog" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24085
diff
changeset
|
481 """ |
2d8e93554822
webcommands: document "shortlog" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24085
diff
changeset
|
482 /shortlog |
2d8e93554822
webcommands: document "shortlog" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24085
diff
changeset
|
483 --------- |
2d8e93554822
webcommands: document "shortlog" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24085
diff
changeset
|
484 |
2d8e93554822
webcommands: document "shortlog" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24085
diff
changeset
|
485 Show basic information about a set of changesets. |
2d8e93554822
webcommands: document "shortlog" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24085
diff
changeset
|
486 |
2d8e93554822
webcommands: document "shortlog" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24085
diff
changeset
|
487 This accepts the same parameters as the ``changelog`` handler. The only |
2d8e93554822
webcommands: document "shortlog" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24085
diff
changeset
|
488 difference is the ``shortlog`` template will be rendered instead of the |
2d8e93554822
webcommands: document "shortlog" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24085
diff
changeset
|
489 ``changelog`` template. |
2d8e93554822
webcommands: document "shortlog" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24085
diff
changeset
|
490 """ |
36893
4daa22071d5d
hgweb: stop passing req and tmpl into @webcommand functions (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36892
diff
changeset
|
491 return changelog(web, shortlog=True) |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
492 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
493 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
494 @webcommand(b'changeset') |
36893
4daa22071d5d
hgweb: stop passing req and tmpl into @webcommand functions (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36892
diff
changeset
|
495 def changeset(web): |
24085
0bf61eae67ab
webcommands: document "changeset" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24084
diff
changeset
|
496 """ |
0bf61eae67ab
webcommands: document "changeset" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24084
diff
changeset
|
497 /changeset[/{revision}] |
0bf61eae67ab
webcommands: document "changeset" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24084
diff
changeset
|
498 ----------------------- |
0bf61eae67ab
webcommands: document "changeset" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24084
diff
changeset
|
499 |
0bf61eae67ab
webcommands: document "changeset" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24084
diff
changeset
|
500 Show information about a single changeset. |
0bf61eae67ab
webcommands: document "changeset" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24084
diff
changeset
|
501 |
0bf61eae67ab
webcommands: document "changeset" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24084
diff
changeset
|
502 A URL path argument is the changeset identifier to show. See ``hg help |
0bf61eae67ab
webcommands: document "changeset" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24084
diff
changeset
|
503 revisions`` for possible values. If not defined, the ``tip`` changeset |
0bf61eae67ab
webcommands: document "changeset" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24084
diff
changeset
|
504 will be shown. |
0bf61eae67ab
webcommands: document "changeset" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24084
diff
changeset
|
505 |
0bf61eae67ab
webcommands: document "changeset" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24084
diff
changeset
|
506 The ``changeset`` template is rendered. Contents of the ``changesettag``, |
0bf61eae67ab
webcommands: document "changeset" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24084
diff
changeset
|
507 ``changesetbookmark``, ``filenodelink``, ``filenolink``, and the many |
0bf61eae67ab
webcommands: document "changeset" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24084
diff
changeset
|
508 templates related to diffs may all be used to produce the output. |
0bf61eae67ab
webcommands: document "changeset" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24084
diff
changeset
|
509 """ |
36892
563fd95a6efb
hgweb: pass modern request type into various webutil functions (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
510 ctx = webutil.changectx(web.repo, web.req) |
36889
061635d4221c
hgweb: add a sendtemplate() helper function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36888
diff
changeset
|
511 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
512 return web.sendtemplate(b'changeset', **webutil.changesetentry(web, ctx)) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
513 |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
514 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
515 rev = webcommand(b'rev')(changeset) |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
516 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
517 |
51304
f15cb5111a1e
pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50952
diff
changeset
|
518 def decodepath(path: bytes) -> bytes: |
16448
e6b45e9a75dc
hgweb: add hook for remapping repository path into virtual paths
Martin Geisler <mg@lazybytes.net>
parents:
16308
diff
changeset
|
519 """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
|
520 working copy. |
e6b45e9a75dc
hgweb: add hook for remapping repository path into virtual paths
Martin Geisler <mg@lazybytes.net>
parents:
16308
diff
changeset
|
521 |
e6b45e9a75dc
hgweb: add hook for remapping repository path into virtual paths
Martin Geisler <mg@lazybytes.net>
parents:
16308
diff
changeset
|
522 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
|
523 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
|
524 return path |
e6b45e9a75dc
hgweb: add hook for remapping repository path into virtual paths
Martin Geisler <mg@lazybytes.net>
parents:
16308
diff
changeset
|
525 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
526 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
527 @webcommand(b'manifest') |
36893
4daa22071d5d
hgweb: stop passing req and tmpl into @webcommand functions (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36892
diff
changeset
|
528 def manifest(web): |
24090
a86b2922ea30
webcommands: document "manifest" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24089
diff
changeset
|
529 """ |
a86b2922ea30
webcommands: document "manifest" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24089
diff
changeset
|
530 /manifest[/{revision}[/{path}]] |
a86b2922ea30
webcommands: document "manifest" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24089
diff
changeset
|
531 ------------------------------- |
a86b2922ea30
webcommands: document "manifest" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24089
diff
changeset
|
532 |
a86b2922ea30
webcommands: document "manifest" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24089
diff
changeset
|
533 Show information about a directory. |
a86b2922ea30
webcommands: document "manifest" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24089
diff
changeset
|
534 |
24868
9668c653eb9d
webcommands: fix description of manifest default behavior
Wagner Bruna <wbruna@softwareexpress.com.br>
parents:
24867
diff
changeset
|
535 If the URL path arguments are omitted, information about the root |
24090
a86b2922ea30
webcommands: document "manifest" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24089
diff
changeset
|
536 directory for the ``tip`` changeset will be shown. |
a86b2922ea30
webcommands: document "manifest" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24089
diff
changeset
|
537 |
a86b2922ea30
webcommands: document "manifest" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24089
diff
changeset
|
538 Because this handler can only show information for directories, it |
a86b2922ea30
webcommands: document "manifest" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24089
diff
changeset
|
539 is recommended to use the ``file`` handler instead, as it can handle both |
a86b2922ea30
webcommands: document "manifest" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24089
diff
changeset
|
540 directories and files. |
a86b2922ea30
webcommands: document "manifest" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24089
diff
changeset
|
541 |
a86b2922ea30
webcommands: document "manifest" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24089
diff
changeset
|
542 The ``manifest`` template will be rendered for this handler. |
a86b2922ea30
webcommands: document "manifest" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24089
diff
changeset
|
543 """ |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
544 if b'node' in web.req.qsparams: |
36892
563fd95a6efb
hgweb: pass modern request type into various webutil functions (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
545 ctx = webutil.changectx(web.repo, web.req) |
563fd95a6efb
hgweb: pass modern request type into various webutil functions (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
546 symrev = webutil.symrevorshortnode(web.req, ctx) |
25602
85fb416f2fa7
hgweb: provide symrev (symbolic revision) property to the templates
Anton Shestakov <av6@dwimlabs.net>
parents:
25251
diff
changeset
|
547 else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
548 ctx = web.repo[b'tip'] |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
549 symrev = b'tip' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
550 path = webutil.cleanpath(web.repo, web.req.qsparams.get(b'file', b'')) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
551 mf = ctx.manifest() |
39810
4f44f747f094
hgweb: use scmutil.binnode() to translate None to wdir hash (issue5988)
Yuya Nishihara <yuya@tcha.org>
parents:
39809
diff
changeset
|
552 node = scmutil.binnode(ctx) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
553 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
554 files = {} |
7305
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
555 dirs = {} |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
556 parity = paritygen(web.stripecount) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
557 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
558 if path and path[-1:] != b"/": |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
559 path += b"/" |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
560 l = len(path) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
561 abspath = b"/" + path |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
562 |
49004
f254fc73d956
global: bulk replace simple pycompat.iteritems(x) with x.items()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48966
diff
changeset
|
563 for full, n in mf.items(): |
16448
e6b45e9a75dc
hgweb: add hook for remapping repository path into virtual paths
Martin Geisler <mg@lazybytes.net>
parents:
16308
diff
changeset
|
564 # 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
|
565 # (repository) path |
e6b45e9a75dc
hgweb: add hook for remapping repository path into virtual paths
Martin Geisler <mg@lazybytes.net>
parents:
16308
diff
changeset
|
566 f = decodepath(full) |
e6b45e9a75dc
hgweb: add hook for remapping repository path into virtual paths
Martin Geisler <mg@lazybytes.net>
parents:
16308
diff
changeset
|
567 |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
568 if f[:l] != path: |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
569 continue |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
570 remain = f[l:] |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
571 elements = remain.split(b'/') |
7305
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
572 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
|
573 files[remain] = full |
7305
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
574 else: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
575 h = dirs # need to retain ref to dirs (root) |
7305
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
576 for elem in elements[0:-1]: |
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
577 if elem not in h: |
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
578 h[elem] = {} |
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
579 h = h[elem] |
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
580 if len(h) > 1: |
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
581 break |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
582 h[None] = None # denotes files present |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
583 |
7565
5f162f61e479
hgweb: fix problems with empty repositories
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7434
diff
changeset
|
584 if mf and not files and not dirs: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
585 raise ErrorResponse(HTTP_NOT_FOUND, b'path not found: ' + path) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
586 |
38095
17f7b44367bb
hgweb: wrap {fentries} and {dentries} of manifest with mappinggenerator
Yuya Nishihara <yuya@tcha.org>
parents:
38094
diff
changeset
|
587 def filelist(context): |
8209
a1a5a57efe90
replace util.sort with sorted built-in
Matt Mackall <mpm@selenic.com>
parents:
7966
diff
changeset
|
588 for f in sorted(files): |
7305
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
589 full = files[f] |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
590 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
591 fctx = ctx.filectx(full) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
592 yield { |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
593 b"file": full, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
594 b"parity": next(parity), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
595 b"basename": f, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
596 b"date": fctx.date(), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
597 b"size": fctx.size(), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
598 b"permissions": mf.flags(full), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
599 } |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
600 |
38095
17f7b44367bb
hgweb: wrap {fentries} and {dentries} of manifest with mappinggenerator
Yuya Nishihara <yuya@tcha.org>
parents:
38094
diff
changeset
|
601 def dirlist(context): |
8209
a1a5a57efe90
replace util.sort with sorted built-in
Matt Mackall <mpm@selenic.com>
parents:
7966
diff
changeset
|
602 for d in sorted(dirs): |
7305
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
603 emptydirs = [] |
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
604 h = dirs[d] |
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
605 while isinstance(h, dict) and len(h) == 1: |
36307
a748a5d1d7c3
webcommands: unpack contents of length-1 dict portably
Augie Fackler <augie@google.com>
parents:
36281
diff
changeset
|
606 k, v = next(iter(h.items())) |
7305
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
607 if v: |
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
608 emptydirs.append(k) |
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
609 h = v |
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
610 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
611 path = b"%s%s" % (abspath, d) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
612 yield { |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
613 b"parity": next(parity), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
614 b"path": path, |
48524
ea13dabbe168
pytype: stop excluding webcommands.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
46819
diff
changeset
|
615 # pytype: disable=wrong-arg-types |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
616 b"emptydirs": b"/".join(emptydirs), |
48524
ea13dabbe168
pytype: stop excluding webcommands.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
46819
diff
changeset
|
617 # pytype: enable=wrong-arg-types |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
618 b"basename": d, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
619 } |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
620 |
36889
061635d4221c
hgweb: add a sendtemplate() helper function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36888
diff
changeset
|
621 return web.sendtemplate( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
622 b'manifest', |
36877
9fc3d814646e
hgweb: port most @webcommand to use modern response type
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36876
diff
changeset
|
623 symrev=symrev, |
9fc3d814646e
hgweb: port most @webcommand to use modern response type
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36876
diff
changeset
|
624 path=abspath, |
9fc3d814646e
hgweb: port most @webcommand to use modern response type
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36876
diff
changeset
|
625 up=webutil.up(abspath), |
9fc3d814646e
hgweb: port most @webcommand to use modern response type
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36876
diff
changeset
|
626 upparity=next(parity), |
38095
17f7b44367bb
hgweb: wrap {fentries} and {dentries} of manifest with mappinggenerator
Yuya Nishihara <yuya@tcha.org>
parents:
38094
diff
changeset
|
627 fentries=templateutil.mappinggenerator(filelist), |
17f7b44367bb
hgweb: wrap {fentries} and {dentries} of manifest with mappinggenerator
Yuya Nishihara <yuya@tcha.org>
parents:
38094
diff
changeset
|
628 dentries=templateutil.mappinggenerator(dirlist), |
36877
9fc3d814646e
hgweb: port most @webcommand to use modern response type
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36876
diff
changeset
|
629 archives=web.archivelist(hex(node)), |
51900
607e94e01851
format: add many "missing" comma
Matt Harbison <matt_harbison@yahoo.com>
parents:
51879
diff
changeset
|
630 **pycompat.strkwargs(webutil.commonentry(web.repo, ctx)), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
631 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
632 |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
633 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
634 @webcommand(b'tags') |
36893
4daa22071d5d
hgweb: stop passing req and tmpl into @webcommand functions (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36892
diff
changeset
|
635 def tags(web): |
24084
ef06e2b1a3d1
webcommands: document "tags" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24083
diff
changeset
|
636 """ |
ef06e2b1a3d1
webcommands: document "tags" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24083
diff
changeset
|
637 /tags |
ef06e2b1a3d1
webcommands: document "tags" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24083
diff
changeset
|
638 ----- |
ef06e2b1a3d1
webcommands: document "tags" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24083
diff
changeset
|
639 |
ef06e2b1a3d1
webcommands: document "tags" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24083
diff
changeset
|
640 Show information about tags. |
ef06e2b1a3d1
webcommands: document "tags" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24083
diff
changeset
|
641 |
ef06e2b1a3d1
webcommands: document "tags" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24083
diff
changeset
|
642 No arguments are accepted. |
ef06e2b1a3d1
webcommands: document "tags" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24083
diff
changeset
|
643 |
ef06e2b1a3d1
webcommands: document "tags" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24083
diff
changeset
|
644 The ``tags`` template is rendered. |
ef06e2b1a3d1
webcommands: document "tags" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24083
diff
changeset
|
645 """ |
18029
109a6a9dcca8
hgweb: fix iterator reuse in atom feed generation
Matt Mackall <mpm@selenic.com>
parents:
17322
diff
changeset
|
646 i = list(reversed(web.repo.tagslist())) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
647 parity = paritygen(web.stripecount) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
648 |
38096
3c995af3066e
hgweb: wrap {entries}* of tags with mappinggenerator
Yuya Nishihara <yuya@tcha.org>
parents:
38095
diff
changeset
|
649 def entries(context, notip, latestonly): |
18402
bfba6d954108
hgweb: `limit` argument is actually `latestonly` renames and enforce
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18352
diff
changeset
|
650 t = i |
bfba6d954108
hgweb: `limit` argument is actually `latestonly` renames and enforce
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18352
diff
changeset
|
651 if notip: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
652 t = [(k, n) for k, n in i if k != b"tip"] |
18402
bfba6d954108
hgweb: `limit` argument is actually `latestonly` renames and enforce
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18352
diff
changeset
|
653 if latestonly: |
bfba6d954108
hgweb: `limit` argument is actually `latestonly` renames and enforce
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18352
diff
changeset
|
654 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
|
655 for k, n in t: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
656 yield { |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
657 b"parity": next(parity), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
658 b"tag": k, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
659 b"date": web.repo[n].date(), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
660 b"node": hex(n), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
661 } |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
662 |
36889
061635d4221c
hgweb: add a sendtemplate() helper function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36888
diff
changeset
|
663 return web.sendtemplate( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
664 b'tags', |
36877
9fc3d814646e
hgweb: port most @webcommand to use modern response type
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36876
diff
changeset
|
665 node=hex(web.repo.changelog.tip()), |
38096
3c995af3066e
hgweb: wrap {entries}* of tags with mappinggenerator
Yuya Nishihara <yuya@tcha.org>
parents:
38095
diff
changeset
|
666 entries=templateutil.mappinggenerator(entries, args=(False, False)), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
667 entriesnotip=templateutil.mappinggenerator(entries, args=(True, False)), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
668 latestentry=templateutil.mappinggenerator(entries, args=(True, True)), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
669 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
670 |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
671 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
672 @webcommand(b'bookmarks') |
36893
4daa22071d5d
hgweb: stop passing req and tmpl into @webcommand functions (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36892
diff
changeset
|
673 def bookmarks(web): |
24083
5fbb5217a6c8
webcommands: document "bookmarks" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24082
diff
changeset
|
674 """ |
5fbb5217a6c8
webcommands: document "bookmarks" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24082
diff
changeset
|
675 /bookmarks |
5fbb5217a6c8
webcommands: document "bookmarks" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24082
diff
changeset
|
676 ---------- |
5fbb5217a6c8
webcommands: document "bookmarks" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24082
diff
changeset
|
677 |
5fbb5217a6c8
webcommands: document "bookmarks" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24082
diff
changeset
|
678 Show information about bookmarks. |
5fbb5217a6c8
webcommands: document "bookmarks" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24082
diff
changeset
|
679 |
5fbb5217a6c8
webcommands: document "bookmarks" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24082
diff
changeset
|
680 No arguments are accepted. |
5fbb5217a6c8
webcommands: document "bookmarks" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24082
diff
changeset
|
681 |
5fbb5217a6c8
webcommands: document "bookmarks" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24082
diff
changeset
|
682 The ``bookmarks`` template is rendered. |
5fbb5217a6c8
webcommands: document "bookmarks" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24082
diff
changeset
|
683 """ |
18478
886936ecc21b
hgweb: don't attempt to show hidden bookmarks (issue3774)
Kevin Bullock <kbullock@ringworld.org>
parents:
18477
diff
changeset
|
684 i = [b for b in web.repo._bookmarks.items() if b[1] in web.repo] |
28711
06ae7a6daad0
hgweb: sort bookmarks in revlog order of their nodes
Anton Shestakov <av6@dwimlabs.net>
parents:
28710
diff
changeset
|
685 sortkey = lambda b: (web.repo[b[1]].rev(), b[0]) |
06ae7a6daad0
hgweb: sort bookmarks in revlog order of their nodes
Anton Shestakov <av6@dwimlabs.net>
parents:
28710
diff
changeset
|
686 i = sorted(i, key=sortkey, reverse=True) |
13597
38c9837b1f75
hgweb: add separate page with bookmarks listing
Alexander Solovyov <alexander@solovyov.net>
parents:
13596
diff
changeset
|
687 parity = paritygen(web.stripecount) |
38c9837b1f75
hgweb: add separate page with bookmarks listing
Alexander Solovyov <alexander@solovyov.net>
parents:
13596
diff
changeset
|
688 |
38167
edacd831afab
hgweb: wrap {entries}* of bookmarks with mappinggenerator
Yuya Nishihara <yuya@tcha.org>
parents:
38096
diff
changeset
|
689 def entries(context, latestonly): |
28710
ca0c0ca30c62
hgweb: sort bookmarks early
Anton Shestakov <av6@dwimlabs.net>
parents:
28212
diff
changeset
|
690 t = i |
18402
bfba6d954108
hgweb: `limit` argument is actually `latestonly` renames and enforce
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18352
diff
changeset
|
691 if latestonly: |
28710
ca0c0ca30c62
hgweb: sort bookmarks early
Anton Shestakov <av6@dwimlabs.net>
parents:
28212
diff
changeset
|
692 t = i[:1] |
18402
bfba6d954108
hgweb: `limit` argument is actually `latestonly` renames and enforce
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18352
diff
changeset
|
693 for k, n in t: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
694 yield { |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
695 b"parity": next(parity), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
696 b"bookmark": k, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
697 b"date": web.repo[n].date(), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
698 b"node": hex(n), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
699 } |
13597
38c9837b1f75
hgweb: add separate page with bookmarks listing
Alexander Solovyov <alexander@solovyov.net>
parents:
13596
diff
changeset
|
700 |
28712
80e922479891
hgweb: generate last change date for an empty atom-bookmarks feed (issue5022)
Anton Shestakov <av6@dwimlabs.net>
parents:
28711
diff
changeset
|
701 if i: |
80e922479891
hgweb: generate last change date for an empty atom-bookmarks feed (issue5022)
Anton Shestakov <av6@dwimlabs.net>
parents:
28711
diff
changeset
|
702 latestrev = i[0][1] |
80e922479891
hgweb: generate last change date for an empty atom-bookmarks feed (issue5022)
Anton Shestakov <av6@dwimlabs.net>
parents:
28711
diff
changeset
|
703 else: |
80e922479891
hgweb: generate last change date for an empty atom-bookmarks feed (issue5022)
Anton Shestakov <av6@dwimlabs.net>
parents:
28711
diff
changeset
|
704 latestrev = -1 |
38168
5e94d07b290a
hgweb: wrap {lastchange} of bookmarks with mappinglist
Yuya Nishihara <yuya@tcha.org>
parents:
38167
diff
changeset
|
705 lastdate = web.repo[latestrev].date() |
28712
80e922479891
hgweb: generate last change date for an empty atom-bookmarks feed (issue5022)
Anton Shestakov <av6@dwimlabs.net>
parents:
28711
diff
changeset
|
706 |
36889
061635d4221c
hgweb: add a sendtemplate() helper function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36888
diff
changeset
|
707 return web.sendtemplate( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
708 b'bookmarks', |
36877
9fc3d814646e
hgweb: port most @webcommand to use modern response type
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36876
diff
changeset
|
709 node=hex(web.repo.changelog.tip()), |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
710 lastchange=templateutil.mappinglist([{b'date': lastdate}]), |
38167
edacd831afab
hgweb: wrap {entries}* of bookmarks with mappinggenerator
Yuya Nishihara <yuya@tcha.org>
parents:
38096
diff
changeset
|
711 entries=templateutil.mappinggenerator(entries, args=(False,)), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
712 latestentry=templateutil.mappinggenerator(entries, args=(True,)), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
713 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
714 |
13597
38c9837b1f75
hgweb: add separate page with bookmarks listing
Alexander Solovyov <alexander@solovyov.net>
parents:
13596
diff
changeset
|
715 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
716 @webcommand(b'branches') |
36893
4daa22071d5d
hgweb: stop passing req and tmpl into @webcommand functions (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36892
diff
changeset
|
717 def branches(web): |
24082
32dabf811b39
webcommands: document "branches" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24081
diff
changeset
|
718 """ |
32dabf811b39
webcommands: document "branches" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24081
diff
changeset
|
719 /branches |
32dabf811b39
webcommands: document "branches" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24081
diff
changeset
|
720 --------- |
32dabf811b39
webcommands: document "branches" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24081
diff
changeset
|
721 |
32dabf811b39
webcommands: document "branches" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24081
diff
changeset
|
722 Show information about branches. |
32dabf811b39
webcommands: document "branches" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24081
diff
changeset
|
723 |
32dabf811b39
webcommands: document "branches" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24081
diff
changeset
|
724 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
|
725 |
32dabf811b39
webcommands: document "branches" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24081
diff
changeset
|
726 No arguments are accepted. |
32dabf811b39
webcommands: document "branches" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24081
diff
changeset
|
727 |
32dabf811b39
webcommands: document "branches" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24081
diff
changeset
|
728 The ``branches`` template is rendered. |
32dabf811b39
webcommands: document "branches" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24081
diff
changeset
|
729 """ |
26129
a103ecb8a04a
hgweb: move branchentries code from webcommands to webutil
Anton Shestakov <av6@dwimlabs.net>
parents:
25660
diff
changeset
|
730 entries = webutil.branchentries(web.repo, web.stripecount) |
a103ecb8a04a
hgweb: move branchentries code from webcommands to webutil
Anton Shestakov <av6@dwimlabs.net>
parents:
25660
diff
changeset
|
731 latestentry = webutil.branchentries(web.repo, web.stripecount, 1) |
36877
9fc3d814646e
hgweb: port most @webcommand to use modern response type
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36876
diff
changeset
|
732 |
36889
061635d4221c
hgweb: add a sendtemplate() helper function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36888
diff
changeset
|
733 return web.sendtemplate( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
734 b'branches', |
36877
9fc3d814646e
hgweb: port most @webcommand to use modern response type
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36876
diff
changeset
|
735 node=hex(web.repo.changelog.tip()), |
9fc3d814646e
hgweb: port most @webcommand to use modern response type
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36876
diff
changeset
|
736 entries=entries, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
737 latestentry=latestentry, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
738 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
739 |
8352
eefcb59d44d6
webcommands: add 'branches' command, similar to 'tags'
Sune Foldager <cryo@cyanite.org>
parents:
8236
diff
changeset
|
740 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
741 @webcommand(b'summary') |
36893
4daa22071d5d
hgweb: stop passing req and tmpl into @webcommand functions (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36892
diff
changeset
|
742 def summary(web): |
24091
6b6ec887c79b
webcommands: document "summary" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24090
diff
changeset
|
743 """ |
6b6ec887c79b
webcommands: document "summary" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24090
diff
changeset
|
744 /summary |
6b6ec887c79b
webcommands: document "summary" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24090
diff
changeset
|
745 -------- |
6b6ec887c79b
webcommands: document "summary" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24090
diff
changeset
|
746 |
6b6ec887c79b
webcommands: document "summary" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24090
diff
changeset
|
747 Show a summary of repository state. |
6b6ec887c79b
webcommands: document "summary" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24090
diff
changeset
|
748 |
6b6ec887c79b
webcommands: document "summary" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24090
diff
changeset
|
749 Information about the latest changesets, bookmarks, tags, and branches |
6b6ec887c79b
webcommands: document "summary" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24090
diff
changeset
|
750 is captured by this handler. |
6b6ec887c79b
webcommands: document "summary" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24090
diff
changeset
|
751 |
6b6ec887c79b
webcommands: document "summary" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24090
diff
changeset
|
752 The ``summary`` template is rendered. |
6b6ec887c79b
webcommands: document "summary" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24090
diff
changeset
|
753 """ |
17261
c0068b058fcd
webcommands: do not modify repo.tagslist()
Patrick Mezard <patrick@mezard.eu>
parents:
17202
diff
changeset
|
754 i = reversed(web.repo.tagslist()) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
755 |
37401
7d94fe3ea0ac
hgweb: fix summary {tags} and {shortlog} to not forcibly expand template
Yuya Nishihara <yuya@tcha.org>
parents:
37400
diff
changeset
|
756 def tagentries(context): |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
757 parity = paritygen(web.stripecount) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
758 count = 0 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
759 for k, n in i: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
760 if k == b"tip": # skip tip |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
761 continue |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
762 |
6659
bc553c6d1ef9
webcommands: fix increments lost by 894875eae49b
Andrew Beekhof <beekhof@gmail.com>
parents:
6657
diff
changeset
|
763 count += 1 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
764 if count > 10: # limit to 10 tags |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
765 break |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
766 |
37401
7d94fe3ea0ac
hgweb: fix summary {tags} and {shortlog} to not forcibly expand template
Yuya Nishihara <yuya@tcha.org>
parents:
37400
diff
changeset
|
767 yield { |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
768 b'parity': next(parity), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
769 b'tag': k, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
770 b'node': hex(n), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
771 b'date': web.repo[n].date(), |
37401
7d94fe3ea0ac
hgweb: fix summary {tags} and {shortlog} to not forcibly expand template
Yuya Nishihara <yuya@tcha.org>
parents:
37400
diff
changeset
|
772 } |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
773 |
38169
e4a43d261715
hgweb: wrap {bookmarks} of summary with mappinggenerator
Yuya Nishihara <yuya@tcha.org>
parents:
38168
diff
changeset
|
774 def bookmarks(context): |
13924
ea726c97c1b6
hgweb: add bookmarks listing to summary page of gitweb/monoblue styles
Yuya Nishihara <yuya@tcha.org>
parents:
13923
diff
changeset
|
775 parity = paritygen(web.stripecount) |
18563
6d098adc5a46
hgweb: make 'summary' work with hidden changesets (issue3810)
Kevin Bullock <kbullock@ringworld.org>
parents:
18524
diff
changeset
|
776 marks = [b for b in web.repo._bookmarks.items() if b[1] in web.repo] |
28711
06ae7a6daad0
hgweb: sort bookmarks in revlog order of their nodes
Anton Shestakov <av6@dwimlabs.net>
parents:
28710
diff
changeset
|
777 sortkey = lambda b: (web.repo[b[1]].rev(), b[0]) |
06ae7a6daad0
hgweb: sort bookmarks in revlog order of their nodes
Anton Shestakov <av6@dwimlabs.net>
parents:
28710
diff
changeset
|
778 marks = sorted(marks, key=sortkey, reverse=True) |
06ae7a6daad0
hgweb: sort bookmarks in revlog order of their nodes
Anton Shestakov <av6@dwimlabs.net>
parents:
28710
diff
changeset
|
779 for k, n in marks[:10]: # limit to 10 bookmarks |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
780 yield { |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
781 b'parity': next(parity), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
782 b'bookmark': k, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
783 b'date': web.repo[n].date(), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
784 b'node': hex(n), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
785 } |
13924
ea726c97c1b6
hgweb: add bookmarks listing to summary page of gitweb/monoblue styles
Yuya Nishihara <yuya@tcha.org>
parents:
13923
diff
changeset
|
786 |
37401
7d94fe3ea0ac
hgweb: fix summary {tags} and {shortlog} to not forcibly expand template
Yuya Nishihara <yuya@tcha.org>
parents:
37400
diff
changeset
|
787 def changelist(context): |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
788 parity = paritygen(web.stripecount, offset=start - end) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
789 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
|
790 revs = [] |
6d098adc5a46
hgweb: make 'summary' work with hidden changesets (issue3810)
Kevin Bullock <kbullock@ringworld.org>
parents:
18524
diff
changeset
|
791 if start < end: |
6d098adc5a46
hgweb: make 'summary' work with hidden changesets (issue3810)
Kevin Bullock <kbullock@ringworld.org>
parents:
18524
diff
changeset
|
792 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
|
793 for i in revs: |
6747
f6c00b17387c
use repo[changeid] to get a changectx
Matt Mackall <mpm@selenic.com>
parents:
6720
diff
changeset
|
794 ctx = web.repo[i] |
37022
c97b936d8bb5
templater: use named function to expand template against mapping dict (API)
Yuya Nishihara <yuya@tcha.org>
parents:
36983
diff
changeset
|
795 lm = webutil.commonentry(web.repo, ctx) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
796 lm[b'parity'] = next(parity) |
37401
7d94fe3ea0ac
hgweb: fix summary {tags} and {shortlog} to not forcibly expand template
Yuya Nishihara <yuya@tcha.org>
parents:
37400
diff
changeset
|
797 l.append(lm) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
798 |
52669
e627cc25b6f3
pyupgrade: rewrite `yield` statements in a loop to `yield from`
Matt Harbison <matt_harbison@yahoo.com>
parents:
52663
diff
changeset
|
799 yield from reversed(l) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
800 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
801 tip = web.repo[b'tip'] |
12059
0de6cfdcaad8
webcommands: remove unncessary access to repo.changelog
Patrick Mezard <pmezard@gmail.com>
parents:
11332
diff
changeset
|
802 count = len(web.repo) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
803 start = max(0, count - web.maxchanges) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
804 end = min(count, start + web.maxchanges) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
805 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
806 desc = web.config(b"web", b"description") |
34245
a6c18628dff1
configitems: register the 'web.description' config
Boris Feld <boris.feld@octobus.net>
parents:
34100
diff
changeset
|
807 if not desc: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
808 desc = b'unknown' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
809 labels = web.configlist(b'web', b'labels') |
36877
9fc3d814646e
hgweb: port most @webcommand to use modern response type
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36876
diff
changeset
|
810 |
36889
061635d4221c
hgweb: add a sendtemplate() helper function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36888
diff
changeset
|
811 return web.sendtemplate( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
812 b'summary', |
36877
9fc3d814646e
hgweb: port most @webcommand to use modern response type
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36876
diff
changeset
|
813 desc=desc, |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
814 owner=get_contact(web.config) or b'unknown', |
36877
9fc3d814646e
hgweb: port most @webcommand to use modern response type
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36876
diff
changeset
|
815 lastchange=tip.date(), |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
816 tags=templateutil.mappinggenerator(tagentries, name=b'tagentry'), |
38169
e4a43d261715
hgweb: wrap {bookmarks} of summary with mappinggenerator
Yuya Nishihara <yuya@tcha.org>
parents:
38168
diff
changeset
|
817 bookmarks=templateutil.mappinggenerator(bookmarks), |
36877
9fc3d814646e
hgweb: port most @webcommand to use modern response type
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36876
diff
changeset
|
818 branches=webutil.branchentries(web.repo, web.stripecount, 10), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
819 shortlog=templateutil.mappinggenerator( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
820 changelist, name=b'shortlogentry' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
821 ), |
36877
9fc3d814646e
hgweb: port most @webcommand to use modern response type
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36876
diff
changeset
|
822 node=tip.hex(), |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
823 symrev=b'tip', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
824 archives=web.archivelist(b'tip'), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
825 labels=templateutil.hybridlist(labels, name=b'label'), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
826 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
827 |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
828 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
829 @webcommand(b'filediff') |
36893
4daa22071d5d
hgweb: stop passing req and tmpl into @webcommand functions (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36892
diff
changeset
|
830 def filediff(web): |
24092
55dfea651b7f
webcommands: document "filediff" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24091
diff
changeset
|
831 """ |
55dfea651b7f
webcommands: document "filediff" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24091
diff
changeset
|
832 /diff/{revision}/{path} |
55dfea651b7f
webcommands: document "filediff" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24091
diff
changeset
|
833 ----------------------- |
55dfea651b7f
webcommands: document "filediff" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24091
diff
changeset
|
834 |
55dfea651b7f
webcommands: document "filediff" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24091
diff
changeset
|
835 Show how a file changed in a particular commit. |
55dfea651b7f
webcommands: document "filediff" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24091
diff
changeset
|
836 |
55dfea651b7f
webcommands: document "filediff" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24091
diff
changeset
|
837 The ``filediff`` template is rendered. |
55dfea651b7f
webcommands: document "filediff" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24091
diff
changeset
|
838 |
26781
1aee2ab0f902
spelling: trivial spell checking
Mads Kiilerich <madski@unity3d.com>
parents:
26136
diff
changeset
|
839 This handler is registered under both the ``/diff`` and ``/filediff`` |
24092
55dfea651b7f
webcommands: document "filediff" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24091
diff
changeset
|
840 paths. ``/diff`` is used in modern code. |
55dfea651b7f
webcommands: document "filediff" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24091
diff
changeset
|
841 """ |
7183
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
842 fctx, ctx = None, None |
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
843 try: |
36892
563fd95a6efb
hgweb: pass modern request type into various webutil functions (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
844 fctx = webutil.filectx(web.repo, web.req) |
7280
810ca383da9c
remove unused variables
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7183
diff
changeset
|
845 except LookupError: |
36892
563fd95a6efb
hgweb: pass modern request type into various webutil functions (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
846 ctx = webutil.changectx(web.repo, web.req) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
847 path = webutil.cleanpath(web.repo, web.req.qsparams[b'file']) |
7183
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
848 if path not in ctx.files(): |
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
849 raise |
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
850 |
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
851 if fctx is not None: |
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
852 path = fctx.path() |
16722
7bf48bc7de23
hgweb: fix filediff base calculation
Matt Mackall <mpm@selenic.com>
parents:
16469
diff
changeset
|
853 ctx = fctx.changectx() |
31099
abb92b3d370e
hgweb: explictly pass basectx in webutil.diffs
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31044
diff
changeset
|
854 basectx = ctx.p1() |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
855 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
856 style = web.config(b'web', b'style') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
857 if b'style' in web.req.qsparams: |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
858 style = web.req.qsparams[b'style'] |
9402
5d49fdef6fd0
hgweb: show diff header line in raw diffs
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8842
diff
changeset
|
859 |
36891
c68e79dcf21c
hgweb: don't redundantly pass templater with requestcontext (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36890
diff
changeset
|
860 diffs = webutil.diffs(web, ctx, basectx, [path], style) |
27160
c533435cbc37
webcommands: test that fctx is not None in filediff()
Anton Shestakov <av6@dwimlabs.net>
parents:
27159
diff
changeset
|
861 if fctx is not None: |
24306
6ddc86eedc3b
style: kill ersatz if-else ternary operators
Jordi Guti?rrez Hermoso <jordigh@octave.org>
parents:
24177
diff
changeset
|
862 rename = webutil.renamelink(fctx) |
6ddc86eedc3b
style: kill ersatz if-else ternary operators
Jordi Guti?rrez Hermoso <jordigh@octave.org>
parents:
24177
diff
changeset
|
863 ctx = fctx |
6ddc86eedc3b
style: kill ersatz if-else ternary operators
Jordi Guti?rrez Hermoso <jordigh@octave.org>
parents:
24177
diff
changeset
|
864 else: |
37946
2095331ff926
hgweb: wrap {rename} with mappinglist
Yuya Nishihara <yuya@tcha.org>
parents:
37698
diff
changeset
|
865 rename = templateutil.mappinglist([]) |
24306
6ddc86eedc3b
style: kill ersatz if-else ternary operators
Jordi Guti?rrez Hermoso <jordigh@octave.org>
parents:
24177
diff
changeset
|
866 ctx = ctx |
36877
9fc3d814646e
hgweb: port most @webcommand to use modern response type
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36876
diff
changeset
|
867 |
36889
061635d4221c
hgweb: add a sendtemplate() helper function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36888
diff
changeset
|
868 return web.sendtemplate( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
869 b'filediff', |
36877
9fc3d814646e
hgweb: port most @webcommand to use modern response type
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36876
diff
changeset
|
870 file=path, |
36892
563fd95a6efb
hgweb: pass modern request type into various webutil functions (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
871 symrev=webutil.symrevorshortnode(web.req, ctx), |
36877
9fc3d814646e
hgweb: port most @webcommand to use modern response type
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36876
diff
changeset
|
872 rename=rename, |
9fc3d814646e
hgweb: port most @webcommand to use modern response type
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36876
diff
changeset
|
873 diff=diffs, |
51900
607e94e01851
format: add many "missing" comma
Matt Harbison <matt_harbison@yahoo.com>
parents:
51879
diff
changeset
|
874 **pycompat.strkwargs(webutil.commonentry(web.repo, ctx)), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
875 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
876 |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
877 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
878 diff = webcommand(b'diff')(filediff) |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
879 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
880 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
881 @webcommand(b'comparison') |
36893
4daa22071d5d
hgweb: stop passing req and tmpl into @webcommand functions (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36892
diff
changeset
|
882 def comparison(web): |
24093
c8639f90a715
webcommands: document "comparison" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24092
diff
changeset
|
883 """ |
c8639f90a715
webcommands: document "comparison" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24092
diff
changeset
|
884 /comparison/{revision}/{path} |
c8639f90a715
webcommands: document "comparison" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24092
diff
changeset
|
885 ----------------------------- |
c8639f90a715
webcommands: document "comparison" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24092
diff
changeset
|
886 |
c8639f90a715
webcommands: document "comparison" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24092
diff
changeset
|
887 Show a comparison between the old and new versions of a file from changes |
c8639f90a715
webcommands: document "comparison" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24092
diff
changeset
|
888 made on a particular revision. |
c8639f90a715
webcommands: document "comparison" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24092
diff
changeset
|
889 |
c8639f90a715
webcommands: document "comparison" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24092
diff
changeset
|
890 This is similar to the ``diff`` handler. However, this form features |
c8639f90a715
webcommands: document "comparison" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24092
diff
changeset
|
891 a split or side-by-side diff rather than a unified diff. |
c8639f90a715
webcommands: document "comparison" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24092
diff
changeset
|
892 |
c8639f90a715
webcommands: document "comparison" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24092
diff
changeset
|
893 The ``context`` query string argument can be used to control the lines of |
c8639f90a715
webcommands: document "comparison" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24092
diff
changeset
|
894 context in the diff. |
c8639f90a715
webcommands: document "comparison" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24092
diff
changeset
|
895 |
c8639f90a715
webcommands: document "comparison" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24092
diff
changeset
|
896 The ``filecomparison`` template is rendered. |
c8639f90a715
webcommands: document "comparison" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24092
diff
changeset
|
897 """ |
36892
563fd95a6efb
hgweb: pass modern request type into various webutil functions (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
898 ctx = webutil.changectx(web.repo, web.req) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
899 if b'file' not in web.req.qsparams: |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
900 raise ErrorResponse(HTTP_NOT_FOUND, b'file not given') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
901 path = webutil.cleanpath(web.repo, web.req.qsparams[b'file']) |
17202
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
17146
diff
changeset
|
902 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
903 parsecontext = lambda v: v == b'full' and -1 or int(v) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
904 if b'context' in web.req.qsparams: |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
905 context = parsecontext(web.req.qsparams[b'context']) |
17202
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
17146
diff
changeset
|
906 else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
907 context = parsecontext(web.config(b'web', b'comparisoncontext')) |
17202
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
17146
diff
changeset
|
908 |
17302
5c64ce6168da
hgweb: fixes traceback for invalid files by removing top-level template
wujek srujek <wujek.srujek@googlemail.com>
parents:
17289
diff
changeset
|
909 def filelines(f): |
32189 | 910 if f.isbinary(): |
40158
9310037f0636
py3: pass str and return bytes from mimetypes.guess_type()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39810
diff
changeset
|
911 mt = pycompat.sysbytes( |
9310037f0636
py3: pass str and return bytes from mimetypes.guess_type()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39810
diff
changeset
|
912 mimetypes.guess_type(pycompat.fsdecode(f.path()))[0] |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
913 or r'application/octet-stream' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
914 ) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
915 return [_(b'(binary file %s, hash: %s)') % (mt, hex(f.filenode()))] |
17302
5c64ce6168da
hgweb: fixes traceback for invalid files by removing top-level template
wujek srujek <wujek.srujek@googlemail.com>
parents:
17289
diff
changeset
|
916 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
|
917 |
27158
522ffc189671
webcommands: get correct parents when comparing a removed file (issue4962)
Anton Shestakov <av6@dwimlabs.net>
parents:
27081
diff
changeset
|
918 fctx = None |
21123
92fab48dfec1
hgweb: show revisions and hashes gotten from changelog in "comparison" page
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21121
diff
changeset
|
919 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
|
920 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
|
921 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
|
922 rightrev = ctx.rev() |
39810
4f44f747f094
hgweb: use scmutil.binnode() to translate None to wdir hash (issue5988)
Yuya Nishihara <yuya@tcha.org>
parents:
39809
diff
changeset
|
923 rightnode = scmutil.binnode(ctx) |
17302
5c64ce6168da
hgweb: fixes traceback for invalid files by removing top-level template
wujek srujek <wujek.srujek@googlemail.com>
parents:
17289
diff
changeset
|
924 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
|
925 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
|
926 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
|
927 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
|
928 leftlines = () |
5c64ce6168da
hgweb: fixes traceback for invalid files by removing top-level template
wujek srujek <wujek.srujek@googlemail.com>
parents:
17289
diff
changeset
|
929 else: |
21121
8c9e84b44221
hgweb: make "comparison" get parent from not filelog but changelog
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20761
diff
changeset
|
930 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
|
931 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
|
932 else: |
5c64ce6168da
hgweb: fixes traceback for invalid files by removing top-level template
wujek srujek <wujek.srujek@googlemail.com>
parents:
17289
diff
changeset
|
933 rightlines = () |
41419
0bd56c291359
cleanup: use p1() and p2() instead of parents()[0] and parents()[1]
Martin von Zweigbergk <martinvonz@google.com>
parents:
40953
diff
changeset
|
934 pfctx = ctx.p1()[path] |
27158
522ffc189671
webcommands: get correct parents when comparing a removed file (issue4962)
Anton Shestakov <av6@dwimlabs.net>
parents:
27081
diff
changeset
|
935 leftlines = filelines(pfctx) |
17302
5c64ce6168da
hgweb: fixes traceback for invalid files by removing top-level template
wujek srujek <wujek.srujek@googlemail.com>
parents:
17289
diff
changeset
|
936 |
38036
623dc2651d26
hgweb: drop unused argument 'tmpl' from webutil.compare()
Yuya Nishihara <yuya@tcha.org>
parents:
37998
diff
changeset
|
937 comparison = webutil.compare(context, leftlines, rightlines) |
27158
522ffc189671
webcommands: get correct parents when comparing a removed file (issue4962)
Anton Shestakov <av6@dwimlabs.net>
parents:
27081
diff
changeset
|
938 if fctx is not None: |
27159
7e10b860c174
webcommands: stop using ersatz if-else ternary operator for rename variable
Anton Shestakov <av6@dwimlabs.net>
parents:
27158
diff
changeset
|
939 rename = webutil.renamelink(fctx) |
27158
522ffc189671
webcommands: get correct parents when comparing a removed file (issue4962)
Anton Shestakov <av6@dwimlabs.net>
parents:
27081
diff
changeset
|
940 ctx = fctx |
522ffc189671
webcommands: get correct parents when comparing a removed file (issue4962)
Anton Shestakov <av6@dwimlabs.net>
parents:
27081
diff
changeset
|
941 else: |
37946
2095331ff926
hgweb: wrap {rename} with mappinglist
Yuya Nishihara <yuya@tcha.org>
parents:
37698
diff
changeset
|
942 rename = templateutil.mappinglist([]) |
27158
522ffc189671
webcommands: get correct parents when comparing a removed file (issue4962)
Anton Shestakov <av6@dwimlabs.net>
parents:
27081
diff
changeset
|
943 ctx = ctx |
36877
9fc3d814646e
hgweb: port most @webcommand to use modern response type
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36876
diff
changeset
|
944 |
36889
061635d4221c
hgweb: add a sendtemplate() helper function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36888
diff
changeset
|
945 return web.sendtemplate( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
946 b'filecomparison', |
36877
9fc3d814646e
hgweb: port most @webcommand to use modern response type
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36876
diff
changeset
|
947 file=path, |
36892
563fd95a6efb
hgweb: pass modern request type into various webutil functions (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
948 symrev=webutil.symrevorshortnode(web.req, ctx), |
36877
9fc3d814646e
hgweb: port most @webcommand to use modern response type
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36876
diff
changeset
|
949 rename=rename, |
9fc3d814646e
hgweb: port most @webcommand to use modern response type
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36876
diff
changeset
|
950 leftrev=leftrev, |
9fc3d814646e
hgweb: port most @webcommand to use modern response type
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36876
diff
changeset
|
951 leftnode=hex(leftnode), |
9fc3d814646e
hgweb: port most @webcommand to use modern response type
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36876
diff
changeset
|
952 rightrev=rightrev, |
9fc3d814646e
hgweb: port most @webcommand to use modern response type
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36876
diff
changeset
|
953 rightnode=hex(rightnode), |
9fc3d814646e
hgweb: port most @webcommand to use modern response type
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36876
diff
changeset
|
954 comparison=comparison, |
51900
607e94e01851
format: add many "missing" comma
Matt Harbison <matt_harbison@yahoo.com>
parents:
51879
diff
changeset
|
955 **pycompat.strkwargs(webutil.commonentry(web.repo, ctx)), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
956 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
957 |
17202
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
17146
diff
changeset
|
958 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
959 @webcommand(b'annotate') |
36893
4daa22071d5d
hgweb: stop passing req and tmpl into @webcommand functions (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36892
diff
changeset
|
960 def annotate(web): |
24094
9c810d46a093
webcommands: document "annotate" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24093
diff
changeset
|
961 """ |
9c810d46a093
webcommands: document "annotate" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24093
diff
changeset
|
962 /annotate/{revision}/{path} |
9c810d46a093
webcommands: document "annotate" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24093
diff
changeset
|
963 --------------------------- |
9c810d46a093
webcommands: document "annotate" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24093
diff
changeset
|
964 |
9c810d46a093
webcommands: document "annotate" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24093
diff
changeset
|
965 Show changeset information for each line in a file. |
9c810d46a093
webcommands: document "annotate" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24093
diff
changeset
|
966 |
34391
f6492f482c60
hgweb: query string arguments to control whitespace for annotate
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34253
diff
changeset
|
967 The ``ignorews``, ``ignorewsamount``, ``ignorewseol``, and |
f6492f482c60
hgweb: query string arguments to control whitespace for annotate
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34253
diff
changeset
|
968 ``ignoreblanklines`` query string arguments have the same meaning as |
34404
407ebe7a9b93
hgweb: use parsebool for parsing diff query string options
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34392
diff
changeset
|
969 their ``[annotate]`` config equivalents. It uses the hgrc boolean |
407ebe7a9b93
hgweb: use parsebool for parsing diff query string options
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34392
diff
changeset
|
970 parsing logic to interpret the value. e.g. ``0`` and ``false`` are |
407ebe7a9b93
hgweb: use parsebool for parsing diff query string options
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34392
diff
changeset
|
971 false and ``1`` and ``true`` are true. If not defined, the server |
407ebe7a9b93
hgweb: use parsebool for parsing diff query string options
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34392
diff
changeset
|
972 default settings are used. |
34391
f6492f482c60
hgweb: query string arguments to control whitespace for annotate
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34253
diff
changeset
|
973 |
24094
9c810d46a093
webcommands: document "annotate" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24093
diff
changeset
|
974 The ``fileannotate`` template is rendered. |
9c810d46a093
webcommands: document "annotate" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24093
diff
changeset
|
975 """ |
36892
563fd95a6efb
hgweb: pass modern request type into various webutil functions (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
976 fctx = webutil.filectx(web.repo, web.req) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
977 f = fctx.path() |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
978 parity = paritygen(web.stripecount) |
39800
be0f32ca2671
hgweb: use heads() instead of headrevs()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39443
diff
changeset
|
979 ishead = fctx.filenode() in fctx.filelog().heads() |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
980 |
30252
4ed8bb8a153f
hgweb: cache fctx.parents() in annotate command (issue5414)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30081
diff
changeset
|
981 # parents() is called once per line and several lines likely belong to |
4ed8bb8a153f
hgweb: cache fctx.parents() in annotate command (issue5414)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30081
diff
changeset
|
982 # same revision. So it is worth caching. |
4ed8bb8a153f
hgweb: cache fctx.parents() in annotate command (issue5414)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30081
diff
changeset
|
983 # TODO there are still redundant operations within basefilectx.parents() |
4ed8bb8a153f
hgweb: cache fctx.parents() in annotate command (issue5414)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30081
diff
changeset
|
984 # and from the fctx.annotate() call itself that could be cached. |
4ed8bb8a153f
hgweb: cache fctx.parents() in annotate command (issue5414)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30081
diff
changeset
|
985 parentscache = {} |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
986 |
38171
8e9ce73ceb15
hgweb: wrap {parents} of {annotate} with mappinggenerator
Yuya Nishihara <yuya@tcha.org>
parents:
38170
diff
changeset
|
987 def parents(context, f): |
30252
4ed8bb8a153f
hgweb: cache fctx.parents() in annotate command (issue5414)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30081
diff
changeset
|
988 rev = f.rev() |
4ed8bb8a153f
hgweb: cache fctx.parents() in annotate command (issue5414)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30081
diff
changeset
|
989 if rev not in parentscache: |
4ed8bb8a153f
hgweb: cache fctx.parents() in annotate command (issue5414)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30081
diff
changeset
|
990 parentscache[rev] = [] |
4ed8bb8a153f
hgweb: cache fctx.parents() in annotate command (issue5414)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30081
diff
changeset
|
991 for p in f.parents(): |
4ed8bb8a153f
hgweb: cache fctx.parents() in annotate command (issue5414)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30081
diff
changeset
|
992 entry = { |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
993 b'node': p.hex(), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
994 b'rev': p.rev(), |
30252
4ed8bb8a153f
hgweb: cache fctx.parents() in annotate command (issue5414)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30081
diff
changeset
|
995 } |
4ed8bb8a153f
hgweb: cache fctx.parents() in annotate command (issue5414)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30081
diff
changeset
|
996 parentscache[rev].append(entry) |
4ed8bb8a153f
hgweb: cache fctx.parents() in annotate command (issue5414)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30081
diff
changeset
|
997 |
4ed8bb8a153f
hgweb: cache fctx.parents() in annotate command (issue5414)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30081
diff
changeset
|
998 for p in parentscache[rev]: |
4ed8bb8a153f
hgweb: cache fctx.parents() in annotate command (issue5414)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30081
diff
changeset
|
999 yield p |
29522
9c37df347485
hgweb: add link to parents of annotated revision in annotate view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
29471
diff
changeset
|
1000 |
38170
3e6253438bf9
hgweb: wrap {annotate} with mappinggenerator
Yuya Nishihara <yuya@tcha.org>
parents:
38169
diff
changeset
|
1001 def annotate(context): |
32189 | 1002 if fctx.isbinary(): |
40158
9310037f0636
py3: pass str and return bytes from mimetypes.guess_type()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39810
diff
changeset
|
1003 mt = pycompat.sysbytes( |
9310037f0636
py3: pass str and return bytes from mimetypes.guess_type()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39810
diff
changeset
|
1004 mimetypes.guess_type(pycompat.fsdecode(fctx.path()))[0] |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
1005 or r'application/octet-stream' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
1006 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
1007 lines = [ |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
1008 dagop.annotateline( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
1009 fctx=fctx.filectx(fctx.filerev()), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
1010 lineno=1, |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1011 text=b'(binary:%s)' % mt, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
1012 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
1013 ] |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
1014 else: |
36892
563fd95a6efb
hgweb: pass modern request type into various webutil functions (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
1015 lines = webutil.annotate(web.req, fctx, web.repo.ui) |
30081
dd0ff715a82c
hgweb: make fctx.annotate a separated function so it could be wrapped
Jun Wu <quark@fb.com>
parents:
29572
diff
changeset
|
1016 |
29388
f694e20193f2
hgweb: display blamed revision once per block in annotate view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
29382
diff
changeset
|
1017 previousrev = None |
29572
d86b54d9bb0c
paper: make different blocks of annotated lines have different colors
Anton Shestakov <av6@dwimlabs.net>
parents:
29538
diff
changeset
|
1018 blockparitygen = paritygen(1) |
37069
b33b91ca2ec2
annotate: pack line content into annotateline object (API)
Yuya Nishihara <yuya@tcha.org>
parents:
37022
diff
changeset
|
1019 for lineno, aline in enumerate(lines): |
34433
2e32c6a31cc7
annotate: introduce attr for storing per-line annotate data
Siddharth Agarwal <sid0@fb.com>
parents:
34404
diff
changeset
|
1020 f = aline.fctx |
29388
f694e20193f2
hgweb: display blamed revision once per block in annotate view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
29382
diff
changeset
|
1021 rev = f.rev() |
29572
d86b54d9bb0c
paper: make different blocks of annotated lines have different colors
Anton Shestakov <av6@dwimlabs.net>
parents:
29538
diff
changeset
|
1022 if rev != previousrev: |
d86b54d9bb0c
paper: make different blocks of annotated lines have different colors
Anton Shestakov <av6@dwimlabs.net>
parents:
29538
diff
changeset
|
1023 blockhead = True |
d86b54d9bb0c
paper: make different blocks of annotated lines have different colors
Anton Shestakov <av6@dwimlabs.net>
parents:
29538
diff
changeset
|
1024 blockparity = next(blockparitygen) |
d86b54d9bb0c
paper: make different blocks of annotated lines have different colors
Anton Shestakov <av6@dwimlabs.net>
parents:
29538
diff
changeset
|
1025 else: |
d86b54d9bb0c
paper: make different blocks of annotated lines have different colors
Anton Shestakov <av6@dwimlabs.net>
parents:
29538
diff
changeset
|
1026 blockhead = None |
29388
f694e20193f2
hgweb: display blamed revision once per block in annotate view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
29382
diff
changeset
|
1027 previousrev = rev |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
1028 yield { |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1029 b"parity": next(parity), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1030 b"node": f.hex(), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1031 b"rev": rev, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1032 b"author": f.user(), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1033 b"parents": templateutil.mappinggenerator(parents, args=(f,)), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1034 b"desc": f.description(), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1035 b"extra": f.extra(), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1036 b"file": f.path(), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1037 b"blockhead": blockhead, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1038 b"blockparity": blockparity, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1039 b"targetline": aline.lineno, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1040 b"line": aline.text, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1041 b"lineno": lineno + 1, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1042 b"lineid": b"l%d" % (lineno + 1), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1043 b"linenumber": b"% 6d" % (lineno + 1), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1044 b"revdate": f.date(), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
1045 } |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
1046 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1047 diffopts = webutil.difffeatureopts(web.req, web.repo.ui, b'annotate') |
50938
d8c8a923ee9b
hgweb: use sysstr to get attribute on diff option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49928
diff
changeset
|
1048 diffopts = { |
d8c8a923ee9b
hgweb: use sysstr to get attribute on diff option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49928
diff
changeset
|
1049 k: getattr(diffopts, pycompat.sysstr(k)) for k in diffopts.defaults |
d8c8a923ee9b
hgweb: use sysstr to get attribute on diff option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49928
diff
changeset
|
1050 } |
34392
6797f1fbc642
hgweb: add HTML elements to control whitespace settings for annotate
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34391
diff
changeset
|
1051 |
36889
061635d4221c
hgweb: add a sendtemplate() helper function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36888
diff
changeset
|
1052 return web.sendtemplate( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1053 b'fileannotate', |
36877
9fc3d814646e
hgweb: port most @webcommand to use modern response type
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36876
diff
changeset
|
1054 file=f, |
38170
3e6253438bf9
hgweb: wrap {annotate} with mappinggenerator
Yuya Nishihara <yuya@tcha.org>
parents:
38169
diff
changeset
|
1055 annotate=templateutil.mappinggenerator(annotate), |
36877
9fc3d814646e
hgweb: port most @webcommand to use modern response type
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36876
diff
changeset
|
1056 path=webutil.up(f), |
36892
563fd95a6efb
hgweb: pass modern request type into various webutil functions (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
1057 symrev=webutil.symrevorshortnode(web.req, fctx), |
36877
9fc3d814646e
hgweb: port most @webcommand to use modern response type
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36876
diff
changeset
|
1058 rename=webutil.renamelink(fctx), |
9fc3d814646e
hgweb: port most @webcommand to use modern response type
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36876
diff
changeset
|
1059 permissions=fctx.manifest().flags(f), |
9fc3d814646e
hgweb: port most @webcommand to use modern response type
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36876
diff
changeset
|
1060 ishead=int(ishead), |
38172
d32f07069dd1
hgweb: wrap {diffopts} of annotate by hybriddict()
Yuya Nishihara <yuya@tcha.org>
parents:
38171
diff
changeset
|
1061 diffopts=templateutil.hybriddict(diffopts), |
51900
607e94e01851
format: add many "missing" comma
Matt Harbison <matt_harbison@yahoo.com>
parents:
51879
diff
changeset
|
1062 **pycompat.strkwargs(webutil.commonentry(web.repo, fctx)), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
1063 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
1064 |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
1065 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1066 @webcommand(b'filelog') |
36893
4daa22071d5d
hgweb: stop passing req and tmpl into @webcommand functions (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36892
diff
changeset
|
1067 def filelog(web): |
24095
1f48b157dccf
webcommands: document "filelog" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24094
diff
changeset
|
1068 """ |
1f48b157dccf
webcommands: document "filelog" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24094
diff
changeset
|
1069 /filelog/{revision}/{path} |
1f48b157dccf
webcommands: document "filelog" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24094
diff
changeset
|
1070 -------------------------- |
1f48b157dccf
webcommands: document "filelog" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24094
diff
changeset
|
1071 |
1f48b157dccf
webcommands: document "filelog" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24094
diff
changeset
|
1072 Show information about the history of a file in the repository. |
1f48b157dccf
webcommands: document "filelog" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24094
diff
changeset
|
1073 |
1f48b157dccf
webcommands: document "filelog" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24094
diff
changeset
|
1074 The ``revcount`` query string argument can be defined to control the |
1f48b157dccf
webcommands: document "filelog" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24094
diff
changeset
|
1075 maximum number of entries to show. |
1f48b157dccf
webcommands: document "filelog" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24094
diff
changeset
|
1076 |
1f48b157dccf
webcommands: document "filelog" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24094
diff
changeset
|
1077 The ``filelog`` template will be rendered. |
1f48b157dccf
webcommands: document "filelog" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24094
diff
changeset
|
1078 """ |
7300
591767e6ea7a
hgweb: conditionally show file logs for deleted files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7288
diff
changeset
|
1079 |
591767e6ea7a
hgweb: conditionally show file logs for deleted files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7288
diff
changeset
|
1080 try: |
36892
563fd95a6efb
hgweb: pass modern request type into various webutil functions (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
1081 fctx = webutil.filectx(web.repo, web.req) |
7300
591767e6ea7a
hgweb: conditionally show file logs for deleted files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7288
diff
changeset
|
1082 f = fctx.path() |
591767e6ea7a
hgweb: conditionally show file logs for deleted files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7288
diff
changeset
|
1083 fl = fctx.filelog() |
7633 | 1084 except error.LookupError: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1085 f = webutil.cleanpath(web.repo, web.req.qsparams[b'file']) |
7300
591767e6ea7a
hgweb: conditionally show file logs for deleted files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7288
diff
changeset
|
1086 fl = web.repo.file(f) |
591767e6ea7a
hgweb: conditionally show file logs for deleted files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7288
diff
changeset
|
1087 numrevs = len(fl) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
1088 if not numrevs: # file doesn't exist at all |
7300
591767e6ea7a
hgweb: conditionally show file logs for deleted files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7288
diff
changeset
|
1089 raise |
36892
563fd95a6efb
hgweb: pass modern request type into various webutil functions (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
1090 rev = webutil.changectx(web.repo, web.req).rev() |
7361
9fe97eea5510
linkrev: take a revision number rather than a hash
Matt Mackall <mpm@selenic.com>
parents:
7345
diff
changeset
|
1091 first = fl.linkrev(0) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
1092 if rev < first: # current rev is from before file existed |
7300
591767e6ea7a
hgweb: conditionally show file logs for deleted files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7288
diff
changeset
|
1093 raise |
591767e6ea7a
hgweb: conditionally show file logs for deleted files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7288
diff
changeset
|
1094 frev = numrevs - 1 |
7361
9fe97eea5510
linkrev: take a revision number rather than a hash
Matt Mackall <mpm@selenic.com>
parents:
7345
diff
changeset
|
1095 while fl.linkrev(frev) > rev: |
7300
591767e6ea7a
hgweb: conditionally show file logs for deleted files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7288
diff
changeset
|
1096 frev -= 1 |
7361
9fe97eea5510
linkrev: take a revision number rather than a hash
Matt Mackall <mpm@selenic.com>
parents:
7345
diff
changeset
|
1097 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
|
1098 |
10246
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
1099 revcount = web.maxshortchanges |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1100 if b'revcount' in web.req.qsparams: |
20092
77acd8ce01ce
hgweb: ignore non numeric "revcount" parameter values (issue4091)
Isaac Jurado <diptongo@gmail.com>
parents:
20004
diff
changeset
|
1101 try: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1102 revcount = int(web.req.qsparams.get(b'revcount', revcount)) |
20092
77acd8ce01ce
hgweb: ignore non numeric "revcount" parameter values (issue4091)
Isaac Jurado <diptongo@gmail.com>
parents:
20004
diff
changeset
|
1103 revcount = max(revcount, 1) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1104 web.tmpl.defaults[b'sessionvars'][b'revcount'] = revcount |
20092
77acd8ce01ce
hgweb: ignore non numeric "revcount" parameter values (issue4091)
Isaac Jurado <diptongo@gmail.com>
parents:
20004
diff
changeset
|
1105 except ValueError: |
77acd8ce01ce
hgweb: ignore non numeric "revcount" parameter values (issue4091)
Isaac Jurado <diptongo@gmail.com>
parents:
20004
diff
changeset
|
1106 pass |
10246
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
1107 |
36892
563fd95a6efb
hgweb: pass modern request type into various webutil functions (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
1108 lrange = webutil.linerange(web.req) |
31670
5e6d44511317
hgweb: handle a "linerange" request parameter in filelog command
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31666
diff
changeset
|
1109 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1110 lessvars = copy.copy(web.tmpl.defaults[b'sessionvars']) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1111 lessvars[b'revcount'] = max(revcount // 2, 1) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1112 morevars = copy.copy(web.tmpl.defaults[b'sessionvars']) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1113 morevars[b'revcount'] = revcount * 2 |
10246
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
1114 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1115 patch = b'patch' in web.req.qsparams |
31666
f36dc643ffdc
hgweb: add a "patch" query parameter to filelog command
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31665
diff
changeset
|
1116 if patch: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1117 lessvars[b'patch'] = morevars[b'patch'] = web.req.qsparams[b'patch'] |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1118 descend = b'descend' in web.req.qsparams |
31939
604d31507f86
hgweb: handle a "descend" query parameter in filelog command
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31732
diff
changeset
|
1119 if descend: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1120 lessvars[b'descend'] = morevars[b'descend'] = web.req.qsparams[ |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1121 b'descend' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1122 ] |
31666
f36dc643ffdc
hgweb: add a "patch" query parameter to filelog command
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31665
diff
changeset
|
1123 |
7300
591767e6ea7a
hgweb: conditionally show file logs for deleted files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7288
diff
changeset
|
1124 count = fctx.filerev() + 1 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
1125 start = max(0, count - revcount) # first rev on this page |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
1126 end = min(count, start + revcount) # last rev on this page |
30825
4deb7c1a07ab
hgweb: restore ascending iteration on revs in filelog web command
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
30816
diff
changeset
|
1127 parity = paritygen(web.stripecount, offset=start - end) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
1128 |
30816
96f811bceb85
hgweb: build the "entries" list directly in filelog command
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
30734
diff
changeset
|
1129 repo = web.repo |
37363
d3a2344446e6
hgweb: don't include hidden revisions in /filelog/ view
Martin von Zweigbergk <martinvonz@google.com>
parents:
37087
diff
changeset
|
1130 filelog = fctx.filelog() |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
1131 revs = [ |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
1132 filerev |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
1133 for filerev in filelog.revs(start, end - 1) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
1134 if filelog.linkrev(filerev) in repo |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
1135 ] |
30816
96f811bceb85
hgweb: build the "entries" list directly in filelog command
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
30734
diff
changeset
|
1136 entries = [] |
31666
f36dc643ffdc
hgweb: add a "patch" query parameter to filelog command
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31665
diff
changeset
|
1137 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1138 diffstyle = web.config(b'web', b'style') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1139 if b'style' in web.req.qsparams: |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1140 diffstyle = web.req.qsparams[b'style'] |
31666
f36dc643ffdc
hgweb: add a "patch" query parameter to filelog command
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31665
diff
changeset
|
1141 |
31672
e540846c67e0
hgweb: filter diff hunks when 'linerange' and 'patch' are specified in filelog
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31670
diff
changeset
|
1142 def diff(fctx, linerange=None): |
31666
f36dc643ffdc
hgweb: add a "patch" query parameter to filelog command
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31665
diff
changeset
|
1143 ctx = fctx.changectx() |
f36dc643ffdc
hgweb: add a "patch" query parameter to filelog command
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31665
diff
changeset
|
1144 basectx = ctx.p1() |
f36dc643ffdc
hgweb: add a "patch" query parameter to filelog command
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31665
diff
changeset
|
1145 path = fctx.path() |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
1146 return webutil.diffs( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
1147 web, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
1148 ctx, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
1149 basectx, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
1150 [path], |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
1151 diffstyle, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
1152 linerange=linerange, |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1153 lineidprefix=b'%s-' % ctx.hex()[:12], |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
1154 ) |
31666
f36dc643ffdc
hgweb: add a "patch" query parameter to filelog command
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31665
diff
changeset
|
1155 |
31670
5e6d44511317
hgweb: handle a "linerange" request parameter in filelog command
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31666
diff
changeset
|
1156 linerange = None |
5e6d44511317
hgweb: handle a "linerange" request parameter in filelog command
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31666
diff
changeset
|
1157 if lrange is not None: |
46417
914ca0a98518
typing: add an assertion to mercurial/hgweb/webcommands.py to help pytype
Matt Harbison <matt_harbison@yahoo.com>
parents:
45398
diff
changeset
|
1158 assert lrange is not None # help pytype (!?) |
31670
5e6d44511317
hgweb: handle a "linerange" request parameter in filelog command
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31666
diff
changeset
|
1159 linerange = webutil.formatlinerange(*lrange) |
5e6d44511317
hgweb: handle a "linerange" request parameter in filelog command
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31666
diff
changeset
|
1160 # deactivate numeric nav links when linerange is specified as this |
5e6d44511317
hgweb: handle a "linerange" request parameter in filelog command
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31666
diff
changeset
|
1161 # would required a dedicated "revnav" class |
37698
7738ae638b62
hgweb: wrap {changenav} and {nav} with mappinglist
Yuya Nishihara <yuya@tcha.org>
parents:
37674
diff
changeset
|
1162 nav = templateutil.mappinglist([]) |
31939
604d31507f86
hgweb: handle a "descend" query parameter in filelog command
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31732
diff
changeset
|
1163 if descend: |
32922
582080a4a812
dagop: move blockancestors() and blockdescendants() from context
Yuya Nishihara <yuya@tcha.org>
parents:
32599
diff
changeset
|
1164 it = dagop.blockdescendants(fctx, *lrange) |
31939
604d31507f86
hgweb: handle a "descend" query parameter in filelog command
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31732
diff
changeset
|
1165 else: |
32922
582080a4a812
dagop: move blockancestors() and blockdescendants() from context
Yuya Nishihara <yuya@tcha.org>
parents:
32599
diff
changeset
|
1166 it = dagop.blockancestors(fctx, *lrange) |
31939
604d31507f86
hgweb: handle a "descend" query parameter in filelog command
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31732
diff
changeset
|
1167 for i, (c, lr) in enumerate(it, 1): |
31670
5e6d44511317
hgweb: handle a "linerange" request parameter in filelog command
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31666
diff
changeset
|
1168 diffs = None |
5e6d44511317
hgweb: handle a "linerange" request parameter in filelog command
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31666
diff
changeset
|
1169 if patch: |
31672
e540846c67e0
hgweb: filter diff hunks when 'linerange' and 'patch' are specified in filelog
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31670
diff
changeset
|
1170 diffs = diff(c, linerange=lr) |
31670
5e6d44511317
hgweb: handle a "linerange" request parameter in filelog command
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31666
diff
changeset
|
1171 # follow renames accross filtered (not in range) revisions |
5e6d44511317
hgweb: handle a "linerange" request parameter in filelog command
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31666
diff
changeset
|
1172 path = c.path() |
38173
220058198be6
hgweb: don't use dict(key=value) to build a mapping dict in filelog
Yuya Nishihara <yuya@tcha.org>
parents:
38172
diff
changeset
|
1173 lm = webutil.commonentry(repo, c) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
1174 lm.update( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
1175 { |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1176 b'parity': next(parity), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1177 b'filerev': c.rev(), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1178 b'file': path, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1179 b'diff': diffs, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1180 b'linerange': webutil.formatlinerange(*lr), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1181 b'rename': templateutil.mappinglist([]), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
1182 } |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
1183 ) |
38173
220058198be6
hgweb: don't use dict(key=value) to build a mapping dict in filelog
Yuya Nishihara <yuya@tcha.org>
parents:
38172
diff
changeset
|
1184 entries.append(lm) |
31670
5e6d44511317
hgweb: handle a "linerange" request parameter in filelog command
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31666
diff
changeset
|
1185 if i == revcount: |
5e6d44511317
hgweb: handle a "linerange" request parameter in filelog command
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31666
diff
changeset
|
1186 break |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1187 lessvars[b'linerange'] = webutil.formatlinerange(*lrange) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1188 morevars[b'linerange'] = lessvars[b'linerange'] |
31670
5e6d44511317
hgweb: handle a "linerange" request parameter in filelog command
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31666
diff
changeset
|
1189 else: |
5e6d44511317
hgweb: handle a "linerange" request parameter in filelog command
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31666
diff
changeset
|
1190 for i in revs: |
5e6d44511317
hgweb: handle a "linerange" request parameter in filelog command
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31666
diff
changeset
|
1191 iterfctx = fctx.filectx(i) |
5e6d44511317
hgweb: handle a "linerange" request parameter in filelog command
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31666
diff
changeset
|
1192 diffs = None |
5e6d44511317
hgweb: handle a "linerange" request parameter in filelog command
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31666
diff
changeset
|
1193 if patch: |
5e6d44511317
hgweb: handle a "linerange" request parameter in filelog command
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31666
diff
changeset
|
1194 diffs = diff(iterfctx) |
38173
220058198be6
hgweb: don't use dict(key=value) to build a mapping dict in filelog
Yuya Nishihara <yuya@tcha.org>
parents:
38172
diff
changeset
|
1195 lm = webutil.commonentry(repo, iterfctx) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
1196 lm.update( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
1197 { |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1198 b'parity': next(parity), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1199 b'filerev': i, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1200 b'file': f, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1201 b'diff': diffs, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1202 b'rename': webutil.renamelink(iterfctx), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
1203 } |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
1204 ) |
38173
220058198be6
hgweb: don't use dict(key=value) to build a mapping dict in filelog
Yuya Nishihara <yuya@tcha.org>
parents:
38172
diff
changeset
|
1205 entries.append(lm) |
31670
5e6d44511317
hgweb: handle a "linerange" request parameter in filelog command
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31666
diff
changeset
|
1206 entries.reverse() |
5e6d44511317
hgweb: handle a "linerange" request parameter in filelog command
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31666
diff
changeset
|
1207 revnav = webutil.filerevnav(web.repo, fctx.path()) |
5e6d44511317
hgweb: handle a "linerange" request parameter in filelog command
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31666
diff
changeset
|
1208 nav = revnav.gen(end - 1, revcount, count) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
1209 |
20022
d85dfe211c71
hgweb: always compute all entries and latestentry in filelog
Alexander Plavin <alexander@plav.in>
parents:
20021
diff
changeset
|
1210 latestentry = entries[:1] |
d85dfe211c71
hgweb: always compute all entries and latestentry in filelog
Alexander Plavin <alexander@plav.in>
parents:
20021
diff
changeset
|
1211 |
36889
061635d4221c
hgweb: add a sendtemplate() helper function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36888
diff
changeset
|
1212 return web.sendtemplate( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1213 b'filelog', |
36876
1f42d621f090
hgweb: support using new response object for web commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36871
diff
changeset
|
1214 file=f, |
1f42d621f090
hgweb: support using new response object for web commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36871
diff
changeset
|
1215 nav=nav, |
36892
563fd95a6efb
hgweb: pass modern request type into various webutil functions (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
1216 symrev=webutil.symrevorshortnode(web.req, fctx), |
38174
53cc81a8caf6
hgweb: wrap {entries}* of filelog with mappinglist
Yuya Nishihara <yuya@tcha.org>
parents:
38173
diff
changeset
|
1217 entries=templateutil.mappinglist(entries), |
36876
1f42d621f090
hgweb: support using new response object for web commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36871
diff
changeset
|
1218 descend=descend, |
1f42d621f090
hgweb: support using new response object for web commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36871
diff
changeset
|
1219 patch=patch, |
38174
53cc81a8caf6
hgweb: wrap {entries}* of filelog with mappinglist
Yuya Nishihara <yuya@tcha.org>
parents:
38173
diff
changeset
|
1220 latestentry=templateutil.mappinglist(latestentry), |
36876
1f42d621f090
hgweb: support using new response object for web commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36871
diff
changeset
|
1221 linerange=linerange, |
1f42d621f090
hgweb: support using new response object for web commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36871
diff
changeset
|
1222 revcount=revcount, |
1f42d621f090
hgweb: support using new response object for web commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36871
diff
changeset
|
1223 morevars=morevars, |
1f42d621f090
hgweb: support using new response object for web commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36871
diff
changeset
|
1224 lessvars=lessvars, |
51900
607e94e01851
format: add many "missing" comma
Matt Harbison <matt_harbison@yahoo.com>
parents:
51879
diff
changeset
|
1225 **pycompat.strkwargs(webutil.commonentry(web.repo, fctx)), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
1226 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
1227 |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
1228 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1229 @webcommand(b'archive') |
36893
4daa22071d5d
hgweb: stop passing req and tmpl into @webcommand functions (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36892
diff
changeset
|
1230 def archive(web): |
24096
bb8b6d44fe1d
webcommands: document "archive" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24095
diff
changeset
|
1231 """ |
bb8b6d44fe1d
webcommands: document "archive" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24095
diff
changeset
|
1232 /archive/{revision}.{format}[/{path}] |
bb8b6d44fe1d
webcommands: document "archive" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24095
diff
changeset
|
1233 ------------------------------------- |
bb8b6d44fe1d
webcommands: document "archive" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24095
diff
changeset
|
1234 |
bb8b6d44fe1d
webcommands: document "archive" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24095
diff
changeset
|
1235 Obtain an archive of repository content. |
bb8b6d44fe1d
webcommands: document "archive" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24095
diff
changeset
|
1236 |
bb8b6d44fe1d
webcommands: document "archive" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24095
diff
changeset
|
1237 The content and type of the archive is defined by a URL path parameter. |
bb8b6d44fe1d
webcommands: document "archive" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24095
diff
changeset
|
1238 ``format`` is the file extension of the archive type to be generated. e.g. |
bb8b6d44fe1d
webcommands: document "archive" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24095
diff
changeset
|
1239 ``zip`` or ``tar.bz2``. Not all archive types may be allowed by your |
bb8b6d44fe1d
webcommands: document "archive" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24095
diff
changeset
|
1240 server configuration. |
bb8b6d44fe1d
webcommands: document "archive" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24095
diff
changeset
|
1241 |
bb8b6d44fe1d
webcommands: document "archive" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24095
diff
changeset
|
1242 The optional ``path`` URL parameter controls content to include in the |
bb8b6d44fe1d
webcommands: document "archive" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24095
diff
changeset
|
1243 archive. If omitted, every file in the specified revision is present in the |
bb8b6d44fe1d
webcommands: document "archive" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24095
diff
changeset
|
1244 archive. If included, only the specified file or contents of the specified |
bb8b6d44fe1d
webcommands: document "archive" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24095
diff
changeset
|
1245 directory will be included in the archive. |
bb8b6d44fe1d
webcommands: document "archive" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24095
diff
changeset
|
1246 |
bb8b6d44fe1d
webcommands: document "archive" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24095
diff
changeset
|
1247 No template is used for this handler. Raw, binary content is generated. |
bb8b6d44fe1d
webcommands: document "archive" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24095
diff
changeset
|
1248 """ |
bb8b6d44fe1d
webcommands: document "archive" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24095
diff
changeset
|
1249 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1250 type_ = web.req.qsparams.get(b'type') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1251 allowed = web.configlist(b"web", b"allow-archive") |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1252 key = web.req.qsparams[b'node'] |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
1253 |
37512
aac97d043e6d
hgweb: drop archivespecs from requestcontext
Yuya Nishihara <yuya@tcha.org>
parents:
37510
diff
changeset
|
1254 if type_ not in webutil.archivespecs: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1255 msg = b'Unsupported archive type: %s' % stringutil.pprint(type_) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
1256 raise ErrorResponse(HTTP_NOT_FOUND, msg) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
1257 |
52663
dc36535a5edc
style: drop extraneous parentheses
Matt Harbison <matt_harbison@yahoo.com>
parents:
51901
diff
changeset
|
1258 if not (type_ in allowed or web.configbool(b"web", b"allow" + type_)): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1259 msg = b'Archive type not allowed: %s' % type_ |
7029
b84d27386285
hgweb: Respond with HTTP 403 for disabled archive types instead of 404
Rocco Rutte <pdmef@gmx.net>
parents:
6981
diff
changeset
|
1260 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
|
1261 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1262 reponame = re.sub(br"\W+", b"-", os.path.basename(web.reponame)) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
1263 cnode = web.repo.lookup(key) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
1264 arch_version = key |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1265 if cnode == key or key == b'tip': |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
1266 arch_version = short(cnode) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1267 name = b"%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
|
1268 |
36892
563fd95a6efb
hgweb: pass modern request type into various webutil functions (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
1269 ctx = webutil.changectx(web.repo, web.req) |
34100
08346a8fa65f
cleanup: rename "matchfn" to "match" where obviously a matcher
Martin von Zweigbergk <martinvonz@google.com>
parents:
33554
diff
changeset
|
1270 match = scmutil.match(ctx, []) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1271 file = web.req.qsparams.get(b'file') |
18771
bb38f4f78104
hgweb: teach archive how to download a specific directory or file
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
18747
diff
changeset
|
1272 if file: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1273 pats = [b'path:' + file] |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1274 match = scmutil.match(ctx, pats, default=b'path') |
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
|
1275 if pats: |
34100
08346a8fa65f
cleanup: rename "matchfn" to "match" where obviously a matcher
Martin von Zweigbergk <martinvonz@google.com>
parents:
33554
diff
changeset
|
1276 files = [f for f in ctx.manifest().keys() if match(f)] |
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
|
1277 if not files: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
1278 raise ErrorResponse( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1279 HTTP_NOT_FOUND, b'file(s) not found: %s' % file |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
1280 ) |
18771
bb38f4f78104
hgweb: teach archive how to download a specific directory or file
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
18747
diff
changeset
|
1281 |
37512
aac97d043e6d
hgweb: drop archivespecs from requestcontext
Yuya Nishihara <yuya@tcha.org>
parents:
37510
diff
changeset
|
1282 mimetype, artype, extension, encoding = webutil.archivespecs[type_] |
36882
97f44b0720e2
hgweb: port archive command to modern response API
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36881
diff
changeset
|
1283 |
49928
fda5a4b853ab
hgweb: skip body creation of HEAD for most requests
Joerg Sonnenberger <joerg@bec.de>
parents:
49292
diff
changeset
|
1284 if web.req.method == b'HEAD': |
fda5a4b853ab
hgweb: skip body creation of HEAD for most requests
Joerg Sonnenberger <joerg@bec.de>
parents:
49292
diff
changeset
|
1285 return [] |
fda5a4b853ab
hgweb: skip body creation of HEAD for most requests
Joerg Sonnenberger <joerg@bec.de>
parents:
49292
diff
changeset
|
1286 |
51879
3b8d92f71d92
archive: defer opening the output until a file is matched
Joerg Sonnenberger <joerg@bec.de>
parents:
51875
diff
changeset
|
1287 def open_archive(): |
3b8d92f71d92
archive: defer opening the output until a file is matched
Joerg Sonnenberger <joerg@bec.de>
parents:
51875
diff
changeset
|
1288 """Open the output "file" for the archiver. |
3b8d92f71d92
archive: defer opening the output until a file is matched
Joerg Sonnenberger <joerg@bec.de>
parents:
51875
diff
changeset
|
1289 |
3b8d92f71d92
archive: defer opening the output until a file is matched
Joerg Sonnenberger <joerg@bec.de>
parents:
51875
diff
changeset
|
1290 This function starts the streaming response. Error reporting |
3b8d92f71d92
archive: defer opening the output until a file is matched
Joerg Sonnenberger <joerg@bec.de>
parents:
51875
diff
changeset
|
1291 after this point will result in short writes without proper |
3b8d92f71d92
archive: defer opening the output until a file is matched
Joerg Sonnenberger <joerg@bec.de>
parents:
51875
diff
changeset
|
1292 diagnostics to the client. |
3b8d92f71d92
archive: defer opening the output until a file is matched
Joerg Sonnenberger <joerg@bec.de>
parents:
51875
diff
changeset
|
1293 """ |
3b8d92f71d92
archive: defer opening the output until a file is matched
Joerg Sonnenberger <joerg@bec.de>
parents:
51875
diff
changeset
|
1294 web.res.headers[b'Content-Type'] = mimetype |
3b8d92f71d92
archive: defer opening the output until a file is matched
Joerg Sonnenberger <joerg@bec.de>
parents:
51875
diff
changeset
|
1295 web.res.headers[ |
3b8d92f71d92
archive: defer opening the output until a file is matched
Joerg Sonnenberger <joerg@bec.de>
parents:
51875
diff
changeset
|
1296 b'Content-Disposition' |
3b8d92f71d92
archive: defer opening the output until a file is matched
Joerg Sonnenberger <joerg@bec.de>
parents:
51875
diff
changeset
|
1297 ] = b'attachment; filename=%s%s' % ( |
3b8d92f71d92
archive: defer opening the output until a file is matched
Joerg Sonnenberger <joerg@bec.de>
parents:
51875
diff
changeset
|
1298 name, |
3b8d92f71d92
archive: defer opening the output until a file is matched
Joerg Sonnenberger <joerg@bec.de>
parents:
51875
diff
changeset
|
1299 extension, |
3b8d92f71d92
archive: defer opening the output until a file is matched
Joerg Sonnenberger <joerg@bec.de>
parents:
51875
diff
changeset
|
1300 ) |
36881
16499427f6de
hgweb: refactor fake file object proxy for archiving
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36879
diff
changeset
|
1301 |
51879
3b8d92f71d92
archive: defer opening the output until a file is matched
Joerg Sonnenberger <joerg@bec.de>
parents:
51875
diff
changeset
|
1302 if encoding: |
3b8d92f71d92
archive: defer opening the output until a file is matched
Joerg Sonnenberger <joerg@bec.de>
parents:
51875
diff
changeset
|
1303 web.res.headers[b'Content-Encoding'] = encoding |
3b8d92f71d92
archive: defer opening the output until a file is matched
Joerg Sonnenberger <joerg@bec.de>
parents:
51875
diff
changeset
|
1304 |
3b8d92f71d92
archive: defer opening the output until a file is matched
Joerg Sonnenberger <joerg@bec.de>
parents:
51875
diff
changeset
|
1305 web.res.setbodywillwrite() |
3b8d92f71d92
archive: defer opening the output until a file is matched
Joerg Sonnenberger <joerg@bec.de>
parents:
51875
diff
changeset
|
1306 if list(web.res.sendresponse()): |
3b8d92f71d92
archive: defer opening the output until a file is matched
Joerg Sonnenberger <joerg@bec.de>
parents:
51875
diff
changeset
|
1307 raise error.ProgrammingError( |
3b8d92f71d92
archive: defer opening the output until a file is matched
Joerg Sonnenberger <joerg@bec.de>
parents:
51875
diff
changeset
|
1308 b'sendresponse() should not emit data if writing later' |
3b8d92f71d92
archive: defer opening the output until a file is matched
Joerg Sonnenberger <joerg@bec.de>
parents:
51875
diff
changeset
|
1309 ) |
3b8d92f71d92
archive: defer opening the output until a file is matched
Joerg Sonnenberger <joerg@bec.de>
parents:
51875
diff
changeset
|
1310 |
3b8d92f71d92
archive: defer opening the output until a file is matched
Joerg Sonnenberger <joerg@bec.de>
parents:
51875
diff
changeset
|
1311 return web.res.getbodyfile() |
3b8d92f71d92
archive: defer opening the output until a file is matched
Joerg Sonnenberger <joerg@bec.de>
parents:
51875
diff
changeset
|
1312 |
3b8d92f71d92
archive: defer opening the output until a file is matched
Joerg Sonnenberger <joerg@bec.de>
parents:
51875
diff
changeset
|
1313 total = archival.archive( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
1314 web.repo, |
51879
3b8d92f71d92
archive: defer opening the output until a file is matched
Joerg Sonnenberger <joerg@bec.de>
parents:
51875
diff
changeset
|
1315 open_archive, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
1316 cnode, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
1317 artype, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
1318 prefix=name, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
1319 match=match, |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1320 subrepos=web.configbool(b"web", b"archivesubrepos"), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
1321 ) |
51879
3b8d92f71d92
archive: defer opening the output until a file is matched
Joerg Sonnenberger <joerg@bec.de>
parents:
51875
diff
changeset
|
1322 if total == 0: |
3b8d92f71d92
archive: defer opening the output until a file is matched
Joerg Sonnenberger <joerg@bec.de>
parents:
51875
diff
changeset
|
1323 raise ErrorResponse(HTTP_NOT_FOUND, b'no files found in changeset') |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
1324 |
36886
67fb0dca29bc
hgweb: always return iterable from @webcommand functions (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36882
diff
changeset
|
1325 return [] |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
1326 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
1327 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1328 @webcommand(b'static') |
36893
4daa22071d5d
hgweb: stop passing req and tmpl into @webcommand functions (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36892
diff
changeset
|
1329 def static(web): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1330 fname = web.req.qsparams[b'file'] |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
1331 # 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
|
1332 # readable by the user running the CGI script |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1333 static = web.config(b"web", b"static", untrusted=False) |
45398
dc9fe90bdbd5
hgweb: let staticfile() look up path from default location unless provided
Martin von Zweigbergk <martinvonz@google.com>
parents:
45397
diff
changeset
|
1334 staticfile(web.templatepath, static, fname, web.res) |
36886
67fb0dca29bc
hgweb: always return iterable from @webcommand functions (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36882
diff
changeset
|
1335 return web.res.sendresponse() |
6691
0dba955c2636
add graph page to hgweb
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6670
diff
changeset
|
1336 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
1337 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1338 @webcommand(b'graph') |
36893
4daa22071d5d
hgweb: stop passing req and tmpl into @webcommand functions (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36892
diff
changeset
|
1339 def graph(web): |
24097
8e04a73b5502
webcommands: document "graph" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24096
diff
changeset
|
1340 """ |
8e04a73b5502
webcommands: document "graph" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24096
diff
changeset
|
1341 /graph[/{revision}] |
8e04a73b5502
webcommands: document "graph" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24096
diff
changeset
|
1342 ------------------- |
8e04a73b5502
webcommands: document "graph" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24096
diff
changeset
|
1343 |
8e04a73b5502
webcommands: document "graph" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24096
diff
changeset
|
1344 Show information about the graphical topology of the repository. |
8e04a73b5502
webcommands: document "graph" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24096
diff
changeset
|
1345 |
8e04a73b5502
webcommands: document "graph" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24096
diff
changeset
|
1346 Information rendered by this handler can be used to create visual |
8e04a73b5502
webcommands: document "graph" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24096
diff
changeset
|
1347 representations of repository topology. |
8e04a73b5502
webcommands: document "graph" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24096
diff
changeset
|
1348 |
35418
0fe5d99804bb
hgweb: update graph function docstring
Anton Shestakov <av6@dwimlabs.net>
parents:
35416
diff
changeset
|
1349 The ``revision`` URL parameter controls the starting changeset. If it's |
0fe5d99804bb
hgweb: update graph function docstring
Anton Shestakov <av6@dwimlabs.net>
parents:
35416
diff
changeset
|
1350 absent, the default is ``tip``. |
24097
8e04a73b5502
webcommands: document "graph" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24096
diff
changeset
|
1351 |
8e04a73b5502
webcommands: document "graph" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24096
diff
changeset
|
1352 The ``revcount`` query string argument can define the number of changesets |
8e04a73b5502
webcommands: document "graph" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24096
diff
changeset
|
1353 to show information for. |
8e04a73b5502
webcommands: document "graph" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24096
diff
changeset
|
1354 |
35418
0fe5d99804bb
hgweb: update graph function docstring
Anton Shestakov <av6@dwimlabs.net>
parents:
35416
diff
changeset
|
1355 The ``graphtop`` query string argument can specify the starting changeset |
0fe5d99804bb
hgweb: update graph function docstring
Anton Shestakov <av6@dwimlabs.net>
parents:
35416
diff
changeset
|
1356 for producing ``jsdata`` variable that is used for rendering graph in |
0fe5d99804bb
hgweb: update graph function docstring
Anton Shestakov <av6@dwimlabs.net>
parents:
35416
diff
changeset
|
1357 JavaScript. By default it has the same value as ``revision``. |
0fe5d99804bb
hgweb: update graph function docstring
Anton Shestakov <av6@dwimlabs.net>
parents:
35416
diff
changeset
|
1358 |
24097
8e04a73b5502
webcommands: document "graph" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24096
diff
changeset
|
1359 This handler will render the ``graph`` template. |
8e04a73b5502
webcommands: document "graph" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24096
diff
changeset
|
1360 """ |
10245
207b94f6b65d
hgweb: make graph page size equal to shortlog
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9404
diff
changeset
|
1361 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1362 if b'node' in web.req.qsparams: |
36892
563fd95a6efb
hgweb: pass modern request type into various webutil functions (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
1363 ctx = webutil.changectx(web.repo, web.req) |
563fd95a6efb
hgweb: pass modern request type into various webutil functions (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
1364 symrev = webutil.symrevorshortnode(web.req, ctx) |
25602
85fb416f2fa7
hgweb: provide symrev (symbolic revision) property to the templates
Anton Shestakov <av6@dwimlabs.net>
parents:
25251
diff
changeset
|
1365 else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1366 ctx = web.repo[b'tip'] |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1367 symrev = b'tip' |
17318
7ac5800dbc8f
hgweb: fix graph view paging
Patrick Mezard <patrick@mezard.eu>
parents:
17303
diff
changeset
|
1368 rev = ctx.rev() |
7ac5800dbc8f
hgweb: fix graph view paging
Patrick Mezard <patrick@mezard.eu>
parents:
17303
diff
changeset
|
1369 |
6691
0dba955c2636
add graph page to hgweb
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6670
diff
changeset
|
1370 bg_height = 39 |
10245
207b94f6b65d
hgweb: make graph page size equal to shortlog
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9404
diff
changeset
|
1371 revcount = web.maxshortchanges |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1372 if b'revcount' in web.req.qsparams: |
20092
77acd8ce01ce
hgweb: ignore non numeric "revcount" parameter values (issue4091)
Isaac Jurado <diptongo@gmail.com>
parents:
20004
diff
changeset
|
1373 try: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1374 revcount = int(web.req.qsparams.get(b'revcount', revcount)) |
20092
77acd8ce01ce
hgweb: ignore non numeric "revcount" parameter values (issue4091)
Isaac Jurado <diptongo@gmail.com>
parents:
20004
diff
changeset
|
1375 revcount = max(revcount, 1) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1376 web.tmpl.defaults[b'sessionvars'][b'revcount'] = revcount |
20092
77acd8ce01ce
hgweb: ignore non numeric "revcount" parameter values (issue4091)
Isaac Jurado <diptongo@gmail.com>
parents:
20004
diff
changeset
|
1377 except ValueError: |
77acd8ce01ce
hgweb: ignore non numeric "revcount" parameter values (issue4091)
Isaac Jurado <diptongo@gmail.com>
parents:
20004
diff
changeset
|
1378 pass |
7345
55651328dfcc
hgweb: fix up the less/more links on the graph page
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7332
diff
changeset
|
1379 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1380 lessvars = copy.copy(web.tmpl.defaults[b'sessionvars']) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1381 lessvars[b'revcount'] = max(revcount // 2, 1) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1382 morevars = copy.copy(web.tmpl.defaults[b'sessionvars']) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1383 morevars[b'revcount'] = revcount * 2 |
7345
55651328dfcc
hgweb: fix up the less/more links on the graph page
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7332
diff
changeset
|
1384 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1385 graphtop = web.req.qsparams.get(b'graphtop', ctx.hex()) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1386 graphvars = copy.copy(web.tmpl.defaults[b'sessionvars']) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1387 graphvars[b'graphtop'] = graphtop |
35416
f84b01257e06
hgweb: render next pages on /graph incrementally
Anton Shestakov <av6@dwimlabs.net>
parents:
35415
diff
changeset
|
1388 |
17318
7ac5800dbc8f
hgweb: fix graph view paging
Patrick Mezard <patrick@mezard.eu>
parents:
17303
diff
changeset
|
1389 count = len(web.repo) |
7ac5800dbc8f
hgweb: fix graph view paging
Patrick Mezard <patrick@mezard.eu>
parents:
17303
diff
changeset
|
1390 pos = rev |
7ac5800dbc8f
hgweb: fix graph view paging
Patrick Mezard <patrick@mezard.eu>
parents:
17303
diff
changeset
|
1391 |
7ac5800dbc8f
hgweb: fix graph view paging
Patrick Mezard <patrick@mezard.eu>
parents:
17303
diff
changeset
|
1392 uprev = min(max(0, count - 1), rev + revcount) |
6691
0dba955c2636
add graph page to hgweb
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6670
diff
changeset
|
1393 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
|
1394 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
|
1395 |
18428
8c10f760ca34
hgweb: walk the graph through the changelog
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18427
diff
changeset
|
1396 tree = [] |
35416
f84b01257e06
hgweb: render next pages on /graph incrementally
Anton Shestakov <av6@dwimlabs.net>
parents:
35415
diff
changeset
|
1397 nextentry = [] |
f84b01257e06
hgweb: render next pages on /graph incrementally
Anton Shestakov <av6@dwimlabs.net>
parents:
35415
diff
changeset
|
1398 lastrev = 0 |
19487
8cfa3a3664a5
hgweb: fix incorrect revisions count in graph (issue3977)
Alexander Plavin <me@aplavin.ru>
parents:
19486
diff
changeset
|
1399 if pos != -1: |
8cfa3a3664a5
hgweb: fix incorrect revisions count in graph (issue3977)
Alexander Plavin <me@aplavin.ru>
parents:
19486
diff
changeset
|
1400 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
|
1401 revs = [] |
8cfa3a3664a5
hgweb: fix incorrect revisions count in graph (issue3977)
Alexander Plavin <me@aplavin.ru>
parents:
19486
diff
changeset
|
1402 for i in allrevs: |
8cfa3a3664a5
hgweb: fix incorrect revisions count in graph (issue3977)
Alexander Plavin <me@aplavin.ru>
parents:
19486
diff
changeset
|
1403 revs.append(i) |
35416
f84b01257e06
hgweb: render next pages on /graph incrementally
Anton Shestakov <av6@dwimlabs.net>
parents:
35415
diff
changeset
|
1404 if len(revs) >= revcount + 1: |
19487
8cfa3a3664a5
hgweb: fix incorrect revisions count in graph (issue3977)
Alexander Plavin <me@aplavin.ru>
parents:
19486
diff
changeset
|
1405 break |
8cfa3a3664a5
hgweb: fix incorrect revisions count in graph (issue3977)
Alexander Plavin <me@aplavin.ru>
parents:
19486
diff
changeset
|
1406 |
35416
f84b01257e06
hgweb: render next pages on /graph incrementally
Anton Shestakov <av6@dwimlabs.net>
parents:
35415
diff
changeset
|
1407 if len(revs) > revcount: |
f84b01257e06
hgweb: render next pages on /graph incrementally
Anton Shestakov <av6@dwimlabs.net>
parents:
35415
diff
changeset
|
1408 nextentry = [webutil.commonentry(web.repo, web.repo[revs[-1]])] |
f84b01257e06
hgweb: render next pages on /graph incrementally
Anton Shestakov <av6@dwimlabs.net>
parents:
35415
diff
changeset
|
1409 revs = revs[:-1] |
f84b01257e06
hgweb: render next pages on /graph incrementally
Anton Shestakov <av6@dwimlabs.net>
parents:
35415
diff
changeset
|
1410 |
f84b01257e06
hgweb: render next pages on /graph incrementally
Anton Shestakov <av6@dwimlabs.net>
parents:
35415
diff
changeset
|
1411 lastrev = revs[-1] |
f84b01257e06
hgweb: render next pages on /graph incrementally
Anton Shestakov <av6@dwimlabs.net>
parents:
35415
diff
changeset
|
1412 |
20761
46f93b7660b6
webcommands: changed code to use lazy classes when calling dagwalker
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20678
diff
changeset
|
1413 # 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
|
1414 # 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
|
1415 # since hgweb graphing code is not itself lazy yet. |
31043
aea06029919e
revset: import set classes directly from smartset module
Yuya Nishihara <yuya@tcha.org>
parents:
30826
diff
changeset
|
1416 dag = graphmod.dagwalker(web.repo, smartset.baseset(revs)) |
20761
46f93b7660b6
webcommands: changed code to use lazy classes when calling dagwalker
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20678
diff
changeset
|
1417 # As we said one line above... not lazy. |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
1418 tree = list( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
1419 item |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
1420 for item in graphmod.colored(dag, web.repo) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
1421 if item[1] == graphmod.CHANGESET |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
1422 ) |
16773
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
1423 |
35416
f84b01257e06
hgweb: render next pages on /graph incrementally
Anton Shestakov <av6@dwimlabs.net>
parents:
35415
diff
changeset
|
1424 def fulltree(): |
f84b01257e06
hgweb: render next pages on /graph incrementally
Anton Shestakov <av6@dwimlabs.net>
parents:
35415
diff
changeset
|
1425 pos = web.repo[graphtop].rev() |
f84b01257e06
hgweb: render next pages on /graph incrementally
Anton Shestakov <av6@dwimlabs.net>
parents:
35415
diff
changeset
|
1426 tree = [] |
f84b01257e06
hgweb: render next pages on /graph incrementally
Anton Shestakov <av6@dwimlabs.net>
parents:
35415
diff
changeset
|
1427 if pos != -1: |
f84b01257e06
hgweb: render next pages on /graph incrementally
Anton Shestakov <av6@dwimlabs.net>
parents:
35415
diff
changeset
|
1428 revs = web.repo.changelog.revs(pos, lastrev) |
f84b01257e06
hgweb: render next pages on /graph incrementally
Anton Shestakov <av6@dwimlabs.net>
parents:
35415
diff
changeset
|
1429 dag = graphmod.dagwalker(web.repo, smartset.baseset(revs)) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
1430 tree = list( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
1431 item |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
1432 for item in graphmod.colored(dag, web.repo) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
1433 if item[1] == graphmod.CHANGESET |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
1434 ) |
35416
f84b01257e06
hgweb: render next pages on /graph incrementally
Anton Shestakov <av6@dwimlabs.net>
parents:
35415
diff
changeset
|
1435 return tree |
f84b01257e06
hgweb: render next pages on /graph incrementally
Anton Shestakov <av6@dwimlabs.net>
parents:
35415
diff
changeset
|
1436 |
38221
215021e506e2
hgweb: adapt {jsdata} of graph to mappinggenerator
Yuya Nishihara <yuya@tcha.org>
parents:
38220
diff
changeset
|
1437 def jsdata(context): |
51762
ca7bde5dbafb
black: format the codebase with 23.3.0
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51759
diff
changeset
|
1438 for id, type, ctx, vtx, edges in fulltree(): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
1439 yield { |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1440 b'node': pycompat.bytestr(ctx), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1441 b'graphnode': webutil.getgraphnode(web.repo, ctx), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1442 b'vertex': vtx, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1443 b'edges': edges, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
1444 } |
16773
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
1445 |
38222
fb5803f4fb87
hgweb: wrap {nodes} of graph with mappinggenerator
Yuya Nishihara <yuya@tcha.org>
parents:
38221
diff
changeset
|
1446 def nodes(context): |
35534
acd8a2454b47
monoblue: make actual changeset entries have backgrounds on /graph
Anton Shestakov <av6@dwimlabs.net>
parents:
35418
diff
changeset
|
1447 parity = paritygen(web.stripecount) |
35415
a48af4993aa0
hgweb: split graphdata() into jsdata() and nodes()
Anton Shestakov <av6@dwimlabs.net>
parents:
35414
diff
changeset
|
1448 for row, (id, type, ctx, vtx, edges) in enumerate(tree): |
a48af4993aa0
hgweb: split graphdata() into jsdata() and nodes()
Anton Shestakov <av6@dwimlabs.net>
parents:
35414
diff
changeset
|
1449 entry = webutil.commonentry(web.repo, ctx) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
1450 edgedata = [ |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
1451 { |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1452 b'col': edge[0], |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1453 b'nextcol': edge[1], |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1454 b'color': (edge[2] - 1) % 6 + 1, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1455 b'width': edge[3], |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1456 b'bcolor': edge[4], |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
1457 } |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
1458 for edge in edges |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
1459 ] |
16773
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
1460 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
1461 entry.update( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
1462 { |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1463 b'col': vtx[0], |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1464 b'color': (vtx[1] - 1) % 6 + 1, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1465 b'parity': next(parity), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1466 b'edges': templateutil.mappinglist(edgedata), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1467 b'row': row, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1468 b'nextrow': row + 1, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
1469 } |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
1470 ) |
35119
23bba755cf80
hgweb: use webutil.commonentry() for nodes (but not for jsdata yet) in /graph
Anton Shestakov <av6@dwimlabs.net>
parents:
35118
diff
changeset
|
1471 |
35415
a48af4993aa0
hgweb: split graphdata() into jsdata() and nodes()
Anton Shestakov <av6@dwimlabs.net>
parents:
35414
diff
changeset
|
1472 yield entry |
16773
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
1473 |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
1474 rows = len(tree) |
6691
0dba955c2636
add graph page to hgweb
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6670
diff
changeset
|
1475 |
36889
061635d4221c
hgweb: add a sendtemplate() helper function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36888
diff
changeset
|
1476 return web.sendtemplate( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1477 b'graph', |
36877
9fc3d814646e
hgweb: port most @webcommand to use modern response type
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36876
diff
changeset
|
1478 rev=rev, |
9fc3d814646e
hgweb: port most @webcommand to use modern response type
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36876
diff
changeset
|
1479 symrev=symrev, |
9fc3d814646e
hgweb: port most @webcommand to use modern response type
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36876
diff
changeset
|
1480 revcount=revcount, |
9fc3d814646e
hgweb: port most @webcommand to use modern response type
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36876
diff
changeset
|
1481 uprev=uprev, |
9fc3d814646e
hgweb: port most @webcommand to use modern response type
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36876
diff
changeset
|
1482 lessvars=lessvars, |
9fc3d814646e
hgweb: port most @webcommand to use modern response type
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36876
diff
changeset
|
1483 morevars=morevars, |
9fc3d814646e
hgweb: port most @webcommand to use modern response type
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36876
diff
changeset
|
1484 downrev=downrev, |
9fc3d814646e
hgweb: port most @webcommand to use modern response type
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36876
diff
changeset
|
1485 graphvars=graphvars, |
9fc3d814646e
hgweb: port most @webcommand to use modern response type
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36876
diff
changeset
|
1486 rows=rows, |
9fc3d814646e
hgweb: port most @webcommand to use modern response type
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36876
diff
changeset
|
1487 bg_height=bg_height, |
9fc3d814646e
hgweb: port most @webcommand to use modern response type
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36876
diff
changeset
|
1488 changesets=count, |
38220
b10a9ace2738
hgweb: wrap {nextentry} of graph with mappinglist
Yuya Nishihara <yuya@tcha.org>
parents:
38174
diff
changeset
|
1489 nextentry=templateutil.mappinglist(nextentry), |
38221
215021e506e2
hgweb: adapt {jsdata} of graph to mappinggenerator
Yuya Nishihara <yuya@tcha.org>
parents:
38220
diff
changeset
|
1490 jsdata=templateutil.mappinggenerator(jsdata), |
38222
fb5803f4fb87
hgweb: wrap {nodes} of graph with mappinggenerator
Yuya Nishihara <yuya@tcha.org>
parents:
38221
diff
changeset
|
1491 nodes=templateutil.mappinggenerator(nodes), |
36877
9fc3d814646e
hgweb: port most @webcommand to use modern response type
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36876
diff
changeset
|
1492 node=ctx.hex(), |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1493 archives=web.archivelist(b'tip'), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
1494 changenav=changenav, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
1495 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
1496 |
12666
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
1497 |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
1498 def _getdoc(e): |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
1499 doc = e[0].__doc__ |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
1500 if doc: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1501 doc = _(doc).partition(b'\n')[0] |
12666
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
1502 else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1503 doc = _(b'(no help text available)') |
12666
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
1504 return doc |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
1505 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
1506 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1507 @webcommand(b'help') |
36893
4daa22071d5d
hgweb: stop passing req and tmpl into @webcommand functions (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36892
diff
changeset
|
1508 def help(web): |
24081
ff42de48193c
webcommands: document "help" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24078
diff
changeset
|
1509 """ |
ff42de48193c
webcommands: document "help" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24078
diff
changeset
|
1510 /help[/{topic}] |
ff42de48193c
webcommands: document "help" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24078
diff
changeset
|
1511 --------------- |
ff42de48193c
webcommands: document "help" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24078
diff
changeset
|
1512 |
ff42de48193c
webcommands: document "help" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24078
diff
changeset
|
1513 Render help documentation. |
ff42de48193c
webcommands: document "help" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24078
diff
changeset
|
1514 |
ff42de48193c
webcommands: document "help" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24078
diff
changeset
|
1515 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
|
1516 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
|
1517 available help topics will be rendered. |
ff42de48193c
webcommands: document "help" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24078
diff
changeset
|
1518 |
ff42de48193c
webcommands: document "help" web command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24078
diff
changeset
|
1519 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
|
1520 ``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
|
1521 """ |
27046
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27009
diff
changeset
|
1522 from .. import commands, 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
|
1523 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1524 topicname = web.req.qsparams.get(b'node') |
12666
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
1525 if not topicname: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
1526 |
38224
0b932b43868f
hgweb: wrap {topics}es of help with mappinggenerator or mappinglist
Yuya Nishihara <yuya@tcha.org>
parents:
38223
diff
changeset
|
1527 def topics(context): |
40292
9c6473d2038b
help: splitting the topics by category
Rodrigo Damazio <rdamazio@google.com>
parents:
40248
diff
changeset
|
1528 for h in helpmod.helptable: |
9c6473d2038b
help: splitting the topics by category
Rodrigo Damazio <rdamazio@google.com>
parents:
40248
diff
changeset
|
1529 entries, summary, _doc = h[0:3] |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1530 yield {b'topic': entries[0], b'summary': summary} |
12666
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
1531 |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
1532 early, other = [], [] |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1533 primary = lambda s: s.partition(b'|')[0] |
49004
f254fc73d956
global: bulk replace simple pycompat.iteritems(x) with x.items()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48966
diff
changeset
|
1534 for c, e in commands.table.items(): |
12666
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
1535 doc = _getdoc(e) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1536 if b'DEPRECATED' in doc or c.startswith(b'debug'): |
12666
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
1537 continue |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
1538 cmd = primary(c) |
40295
fa88170c10bb
help: adding a proper declaration for shortlist/basic commands (API)
Rodrigo Damazio <rdamazio@google.com>
parents:
40292
diff
changeset
|
1539 if getattr(e[0], 'helpbasic', False): |
fa88170c10bb
help: adding a proper declaration for shortlist/basic commands (API)
Rodrigo Damazio <rdamazio@google.com>
parents:
40292
diff
changeset
|
1540 early.append((cmd, doc)) |
12666
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
1541 else: |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
1542 other.append((cmd, doc)) |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
1543 |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
1544 early.sort() |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
1545 other.sort() |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
1546 |
38225
c3df415037cd
hgweb: wrap {earlycommands} and {othercommands} of help with mappinggenerator
Yuya Nishihara <yuya@tcha.org>
parents:
38224
diff
changeset
|
1547 def earlycommands(context): |
12666
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
1548 for c, doc in early: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1549 yield {b'topic': c, b'summary': doc} |
12666
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
1550 |
38225
c3df415037cd
hgweb: wrap {earlycommands} and {othercommands} of help with mappinggenerator
Yuya Nishihara <yuya@tcha.org>
parents:
38224
diff
changeset
|
1551 def othercommands(context): |
12666
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
1552 for c, doc in other: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1553 yield {b'topic': c, b'summary': doc} |
12666
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
1554 |
36889
061635d4221c
hgweb: add a sendtemplate() helper function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36888
diff
changeset
|
1555 return web.sendtemplate( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1556 b'helptopics', |
38224
0b932b43868f
hgweb: wrap {topics}es of help with mappinggenerator or mappinglist
Yuya Nishihara <yuya@tcha.org>
parents:
38223
diff
changeset
|
1557 topics=templateutil.mappinggenerator(topics), |
38225
c3df415037cd
hgweb: wrap {earlycommands} and {othercommands} of help with mappinggenerator
Yuya Nishihara <yuya@tcha.org>
parents:
38224
diff
changeset
|
1558 earlycommands=templateutil.mappinggenerator(earlycommands), |
c3df415037cd
hgweb: wrap {earlycommands} and {othercommands} of help with mappinggenerator
Yuya Nishihara <yuya@tcha.org>
parents:
38224
diff
changeset
|
1559 othercommands=templateutil.mappinggenerator(othercommands), |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1560 title=b'Index', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
1561 ) |
12666
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
1562 |
27581
3aa6a8135557
hgweb: support rendering sub-topic indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27294
diff
changeset
|
1563 # Render an index of sub-topics. |
3aa6a8135557
hgweb: support rendering sub-topic indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27294
diff
changeset
|
1564 if topicname in helpmod.subtopics: |
3aa6a8135557
hgweb: support rendering sub-topic indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27294
diff
changeset
|
1565 topics = [] |
3aa6a8135557
hgweb: support rendering sub-topic indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27294
diff
changeset
|
1566 for entries, summary, _doc in helpmod.subtopics[topicname]: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
1567 topics.append( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
1568 { |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1569 b'topic': b'%s.%s' % (topicname, entries[0]), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1570 b'basename': entries[0], |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1571 b'summary': summary, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
1572 } |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
1573 ) |
27581
3aa6a8135557
hgweb: support rendering sub-topic indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27294
diff
changeset
|
1574 |
36889
061635d4221c
hgweb: add a sendtemplate() helper function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36888
diff
changeset
|
1575 return web.sendtemplate( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1576 b'helptopics', |
38224
0b932b43868f
hgweb: wrap {topics}es of help with mappinggenerator or mappinglist
Yuya Nishihara <yuya@tcha.org>
parents:
38223
diff
changeset
|
1577 topics=templateutil.mappinglist(topics), |
36877
9fc3d814646e
hgweb: port most @webcommand to use modern response type
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36876
diff
changeset
|
1578 title=topicname, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
1579 subindex=True, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
1580 ) |
27581
3aa6a8135557
hgweb: support rendering sub-topic indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27294
diff
changeset
|
1581 |
30564
d83ca854fa21
ui: factor out ui.load() to create a ui without loading configs (API)
Yuya Nishihara <yuya@tcha.org>
parents:
30252
diff
changeset
|
1582 u = webutil.wsgiui.load() |
17146
6b40cc67ceb4
hgweb: show help with verbose sections included
Adrian Buehlmann <adrian@cadifra.com>
parents:
16773
diff
changeset
|
1583 u.verbose = True |
27582
8f8f3b13252d
hgweb: support rendering a sub-topic
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27581
diff
changeset
|
1584 |
8f8f3b13252d
hgweb: support rendering a sub-topic
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27581
diff
changeset
|
1585 # Render a page from a sub-topic. |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1586 if b'.' in topicname: |
27582
8f8f3b13252d
hgweb: support rendering a sub-topic
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27581
diff
changeset
|
1587 # TODO implement support for rendering sections, like |
8f8f3b13252d
hgweb: support rendering a sub-topic
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27581
diff
changeset
|
1588 # `hg help` works. |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1589 topic, subtopic = topicname.split(b'.', 1) |
27582
8f8f3b13252d
hgweb: support rendering a sub-topic
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27581
diff
changeset
|
1590 if topic not in helpmod.subtopics: |
8f8f3b13252d
hgweb: support rendering a sub-topic
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27581
diff
changeset
|
1591 raise ErrorResponse(HTTP_NOT_FOUND) |
8f8f3b13252d
hgweb: support rendering a sub-topic
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27581
diff
changeset
|
1592 else: |
8f8f3b13252d
hgweb: support rendering a sub-topic
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27581
diff
changeset
|
1593 topic = topicname |
8f8f3b13252d
hgweb: support rendering a sub-topic
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27581
diff
changeset
|
1594 subtopic = None |
8f8f3b13252d
hgweb: support rendering a sub-topic
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27581
diff
changeset
|
1595 |
12666
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
1596 try: |
32599
1b90036f42f0
help: pass commands module by argument
Yuya Nishihara <yuya@tcha.org>
parents:
32189
diff
changeset
|
1597 doc = helpmod.help_(u, commands, topic, subtopic=subtopic) |
36281
0ef50a5e3ae1
hgweb: translate Abort in help command to 404 error
Yuya Nishihara <yuya@tcha.org>
parents:
35566
diff
changeset
|
1598 except error.Abort: |
12666
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
1599 raise ErrorResponse(HTTP_NOT_FOUND) |
36877
9fc3d814646e
hgweb: port most @webcommand to use modern response type
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36876
diff
changeset
|
1600 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1601 return web.sendtemplate(b'help', topic=topicname, doc=doc) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41419
diff
changeset
|
1602 |
24859
64e3f97bdf08
i18n: extract doc string of each web commands as translatable one
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24712
diff
changeset
|
1603 |
64e3f97bdf08
i18n: extract doc string of each web commands as translatable one
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24712
diff
changeset
|
1604 # tell hggettext to extract docstrings from these functions: |
64e3f97bdf08
i18n: extract doc string of each web commands as translatable one
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24712
diff
changeset
|
1605 i18nfunctions = commands.values() |