Mercurial > hg
annotate mercurial/templatekw.py @ 35616:706aa203b396
fileset: add a lightweight file filtering language
This patch was inspired by one that Jun Wu authored for the fb-experimental
repo, to avoid using matcher for efficiency[1]. We want a way to specify what
files will be converted to LFS at commit time. And per discussion, we also want
to specify what files to skip, text diff, or merge in another config option.
The current `lfs.threshold` config option could not satisfy complex needs. I'm
putting it in a core package because Augie floated the idea of also using it for
narrow and sparse.
Yuya suggested farming out to fileset.parse(), which added support for more
symbols. The only fileset element not supported here is 'negate'. (List isn't
supported by filesets either.) I also changed the 'always' token to the 'all()'
predicate for consistency, and introduced 'none()' to improve readability in a
future tracked file based config. The extension operator was changed from '.'
to '**', to match how recursive path globs are specified. Finally, I changed
the path matcher from '/' to 'path:' at Yuya's suggestion, for consistency with
matcher. Unfortunately, ':' is currently reserved in filesets, so this has to
be quoted to be processed as a string instead of a symbol[2]. We should
probably revisit that, because it's seriously ugly. But it's only used by an
experimental extension, and I think using a file based config for LFS may drive
some more tweaks, so I'm settling for this for now.
I reserved all of the glob characters in fileset except '.' and '_' for the
extension test because those are likely valid extension characters.
Sample filter settings:
all() # everything
size(">20MB") # larger than 20MB
!**.txt # except for .txt files
**.zip | **.tar.gz | **.7z # some types of compressed files
"path:bin" # files under "bin" in the project root
[1] https://www.mercurial-scm.org/pipermail/mercurial-devel/2017-December/109387.html
[2] https://www.mercurial-scm.org/pipermail/mercurial-devel/2018-January/109729.html
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Wed, 10 Jan 2018 22:23:34 -0500 |
parents | 9b3f95d9783d |
children | c8e2d6ed1f9e |
rev | line source |
---|---|
10053
5c5c6295533d
cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
1 # templatekw.py - common changeset template keywords |
5c5c6295533d
cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
2 # |
5c5c6295533d
cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
3 # Copyright 2005-2009 Matt Mackall <mpm@selenic.com> |
5c5c6295533d
cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
4 # |
5c5c6295533d
cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
5 # This software may be used and distributed according to the terms of the |
10264 | 6 # GNU General Public License version 2 or any later version. |
10053
5c5c6295533d
cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
7 |
25984
c57509e88922
templatekw: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25740
diff
changeset
|
8 from __future__ import absolute_import |
c57509e88922
templatekw: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25740
diff
changeset
|
9 |
31807
e6eb86b154c5
templater: provide loop counter as "index" keyword
Yuya Nishihara <yuya@tcha.org>
parents:
31699
diff
changeset
|
10 from .i18n import _ |
32658
55ff67ffcead
scmutil: introduce binnode(ctx) as paired function with intrev(ctx)
Yuya Nishihara <yuya@tcha.org>
parents:
32656
diff
changeset
|
11 from .node import ( |
55ff67ffcead
scmutil: introduce binnode(ctx) as paired function with intrev(ctx)
Yuya Nishihara <yuya@tcha.org>
parents:
32656
diff
changeset
|
12 hex, |
55ff67ffcead
scmutil: introduce binnode(ctx) as paired function with intrev(ctx)
Yuya Nishihara <yuya@tcha.org>
parents:
32656
diff
changeset
|
13 nullid, |
55ff67ffcead
scmutil: introduce binnode(ctx) as paired function with intrev(ctx)
Yuya Nishihara <yuya@tcha.org>
parents:
32656
diff
changeset
|
14 ) |
55ff67ffcead
scmutil: introduce binnode(ctx) as paired function with intrev(ctx)
Yuya Nishihara <yuya@tcha.org>
parents:
32656
diff
changeset
|
15 |
25984
c57509e88922
templatekw: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25740
diff
changeset
|
16 from . import ( |
28239
7279e0132347
templatekw: workaround for utf-8 round-trip of {desc}
Yuya Nishihara <yuya@tcha.org>
parents:
28178
diff
changeset
|
17 encoding, |
25984
c57509e88922
templatekw: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25740
diff
changeset
|
18 error, |
c57509e88922
templatekw: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25740
diff
changeset
|
19 hbisect, |
35212
c7b45db8f317
log: translate column labels at once (issue5750)
Yuya Nishihara <yuya@tcha.org>
parents:
35143
diff
changeset
|
20 i18n, |
32879
1858fc2327ef
template: add predecessors template
Boris Feld <boris.feld@octobus.net>
parents:
32658
diff
changeset
|
21 obsutil, |
25984
c57509e88922
templatekw: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25740
diff
changeset
|
22 patch, |
32972
26e710f0468f
py3: convert keys of kwargs in template keywords functions to bytes
Pulkit Goyal <7895pulkit@gmail.com>
parents:
32970
diff
changeset
|
23 pycompat, |
28539
119702a8b415
templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
24 registrar, |
25984
c57509e88922
templatekw: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25740
diff
changeset
|
25 scmutil, |
c57509e88922
templatekw: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25740
diff
changeset
|
26 util, |
c57509e88922
templatekw: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25740
diff
changeset
|
27 ) |
10053
5c5c6295533d
cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
28 |
31879
868ec199cad0
templater: rewrite doc of _hybrid class as docstring
Yuya Nishihara <yuya@tcha.org>
parents:
31850
diff
changeset
|
29 class _hybrid(object): |
868ec199cad0
templater: rewrite doc of _hybrid class as docstring
Yuya Nishihara <yuya@tcha.org>
parents:
31850
diff
changeset
|
30 """Wrapper for list or dict to support legacy template |
17631
0b241d7a8c62
templating: make new-style templating features work with command line lists
Matt Mackall <mpm@selenic.com>
parents:
17358
diff
changeset
|
31 |
31879
868ec199cad0
templater: rewrite doc of _hybrid class as docstring
Yuya Nishihara <yuya@tcha.org>
parents:
31850
diff
changeset
|
32 This class allows us to handle both: |
868ec199cad0
templater: rewrite doc of _hybrid class as docstring
Yuya Nishihara <yuya@tcha.org>
parents:
31850
diff
changeset
|
33 - "{files}" (legacy command-line-specific list hack) and |
868ec199cad0
templater: rewrite doc of _hybrid class as docstring
Yuya Nishihara <yuya@tcha.org>
parents:
31850
diff
changeset
|
34 - "{files % '{file}\n'}" (hgweb-style with inlining and function support) |
868ec199cad0
templater: rewrite doc of _hybrid class as docstring
Yuya Nishihara <yuya@tcha.org>
parents:
31850
diff
changeset
|
35 and to access raw values: |
868ec199cad0
templater: rewrite doc of _hybrid class as docstring
Yuya Nishihara <yuya@tcha.org>
parents:
31850
diff
changeset
|
36 - "{ifcontains(file, files, ...)}", "{ifcontains(key, extras, ...)}" |
868ec199cad0
templater: rewrite doc of _hybrid class as docstring
Yuya Nishihara <yuya@tcha.org>
parents:
31850
diff
changeset
|
37 - "{get(extras, key)}" |
31882
ba5b74f780d5
templater: make _hybrid provide more list/dict-like methods
Yuya Nishihara <yuya@tcha.org>
parents:
31881
diff
changeset
|
38 - "{files|json}" |
31879
868ec199cad0
templater: rewrite doc of _hybrid class as docstring
Yuya Nishihara <yuya@tcha.org>
parents:
31850
diff
changeset
|
39 """ |
868ec199cad0
templater: rewrite doc of _hybrid class as docstring
Yuya Nishihara <yuya@tcha.org>
parents:
31850
diff
changeset
|
40 |
34581
ee0d74083a22
templater: store revisions as ints so min/max won't compare them as strings
Yuya Nishihara <yuya@tcha.org>
parents:
34541
diff
changeset
|
41 def __init__(self, gen, values, makemap, joinfmt, keytype=None): |
31923
68c910fa9ee2
templatekw: add default implementation of _hybrid.gen
Yuya Nishihara <yuya@tcha.org>
parents:
31882
diff
changeset
|
42 if gen is not None: |
34425
12bfecd0ffe6
formatter: fix default list/dict generator to be evaluated more than once
Yuya Nishihara <yuya@tcha.org>
parents:
34330
diff
changeset
|
43 self.gen = gen # generator or function returning generator |
31881
31dad7a5b4ed
templater: hide private variable of _hybrid
Yuya Nishihara <yuya@tcha.org>
parents:
31880
diff
changeset
|
44 self._values = values |
24239
31f9b1b16d1e
templatekw: keep raw list or dict in _hybrid object
Yuya Nishihara <yuya@tcha.org>
parents:
24238
diff
changeset
|
45 self._makemap = makemap |
29669
bdc81970853d
templatekw: change joinfmt to a mandatory argument of _hybrid object
Yuya Nishihara <yuya@tcha.org>
parents:
29624
diff
changeset
|
46 self.joinfmt = joinfmt |
34581
ee0d74083a22
templater: store revisions as ints so min/max won't compare them as strings
Yuya Nishihara <yuya@tcha.org>
parents:
34541
diff
changeset
|
47 self.keytype = keytype # hint for 'x in y' where type(x) is unresolved |
31923
68c910fa9ee2
templatekw: add default implementation of _hybrid.gen
Yuya Nishihara <yuya@tcha.org>
parents:
31882
diff
changeset
|
48 def gen(self): |
34425
12bfecd0ffe6
formatter: fix default list/dict generator to be evaluated more than once
Yuya Nishihara <yuya@tcha.org>
parents:
34330
diff
changeset
|
49 """Default generator to stringify this as {join(self, ' ')}""" |
34328
dd28b1f55eb8
templatekw: just pass underlying value (or key) to joinfmt() function
Yuya Nishihara <yuya@tcha.org>
parents:
34327
diff
changeset
|
50 for i, x in enumerate(self._values): |
31923
68c910fa9ee2
templatekw: add default implementation of _hybrid.gen
Yuya Nishihara <yuya@tcha.org>
parents:
31882
diff
changeset
|
51 if i > 0: |
68c910fa9ee2
templatekw: add default implementation of _hybrid.gen
Yuya Nishihara <yuya@tcha.org>
parents:
31882
diff
changeset
|
52 yield ' ' |
34328
dd28b1f55eb8
templatekw: just pass underlying value (or key) to joinfmt() function
Yuya Nishihara <yuya@tcha.org>
parents:
34327
diff
changeset
|
53 yield self.joinfmt(x) |
27891
ac8c0ee5c3b8
templater: make _hybrid not callable to avoid conflicting semantics
Yuya Nishihara <yuya@tcha.org>
parents:
27215
diff
changeset
|
54 def itermaps(self): |
24239
31f9b1b16d1e
templatekw: keep raw list or dict in _hybrid object
Yuya Nishihara <yuya@tcha.org>
parents:
24238
diff
changeset
|
55 makemap = self._makemap |
31881
31dad7a5b4ed
templater: hide private variable of _hybrid
Yuya Nishihara <yuya@tcha.org>
parents:
31880
diff
changeset
|
56 for x in self._values: |
24239
31f9b1b16d1e
templatekw: keep raw list or dict in _hybrid object
Yuya Nishihara <yuya@tcha.org>
parents:
24238
diff
changeset
|
57 yield makemap(x) |
24240
bd504d90588d
templater: implement _hybrid.__contains__ so that ifcontains can accept dict
Yuya Nishihara <yuya@tcha.org>
parents:
24239
diff
changeset
|
58 def __contains__(self, x): |
31881
31dad7a5b4ed
templater: hide private variable of _hybrid
Yuya Nishihara <yuya@tcha.org>
parents:
31880
diff
changeset
|
59 return x in self._values |
33414
16ed67164002
templatekw: export ui.paths as {peerpaths}
Yuya Nishihara <yuya@tcha.org>
parents:
33276
diff
changeset
|
60 def __getitem__(self, key): |
16ed67164002
templatekw: export ui.paths as {peerpaths}
Yuya Nishihara <yuya@tcha.org>
parents:
33276
diff
changeset
|
61 return self._values[key] |
22393
293930a1fa0a
templater: implement __len__ for _hybrid
Anton Shestakov <engored@ya.ru>
parents:
21897
diff
changeset
|
62 def __len__(self): |
31881
31dad7a5b4ed
templater: hide private variable of _hybrid
Yuya Nishihara <yuya@tcha.org>
parents:
31880
diff
changeset
|
63 return len(self._values) |
31882
ba5b74f780d5
templater: make _hybrid provide more list/dict-like methods
Yuya Nishihara <yuya@tcha.org>
parents:
31881
diff
changeset
|
64 def __iter__(self): |
ba5b74f780d5
templater: make _hybrid provide more list/dict-like methods
Yuya Nishihara <yuya@tcha.org>
parents:
31881
diff
changeset
|
65 return iter(self._values) |
24241
e7baf88c29c3
templatekw: forward _hybrid.get to raw values so that get(extras, key) works
Yuya Nishihara <yuya@tcha.org>
parents:
24240
diff
changeset
|
66 def __getattr__(self, name): |
31882
ba5b74f780d5
templater: make _hybrid provide more list/dict-like methods
Yuya Nishihara <yuya@tcha.org>
parents:
31881
diff
changeset
|
67 if name not in ('get', 'items', 'iteritems', 'iterkeys', 'itervalues', |
ba5b74f780d5
templater: make _hybrid provide more list/dict-like methods
Yuya Nishihara <yuya@tcha.org>
parents:
31881
diff
changeset
|
68 'keys', 'values'): |
24241
e7baf88c29c3
templatekw: forward _hybrid.get to raw values so that get(extras, key) works
Yuya Nishihara <yuya@tcha.org>
parents:
24240
diff
changeset
|
69 raise AttributeError(name) |
31881
31dad7a5b4ed
templater: hide private variable of _hybrid
Yuya Nishihara <yuya@tcha.org>
parents:
31880
diff
changeset
|
70 return getattr(self._values, name) |
17631
0b241d7a8c62
templating: make new-style templating features work with command line lists
Matt Mackall <mpm@selenic.com>
parents:
17358
diff
changeset
|
71 |
34330
89aec1834a86
templatekw: add new-style template expansion to {manifest}
Yuya Nishihara <yuya@tcha.org>
parents:
34328
diff
changeset
|
72 class _mappable(object): |
89aec1834a86
templatekw: add new-style template expansion to {manifest}
Yuya Nishihara <yuya@tcha.org>
parents:
34328
diff
changeset
|
73 """Wrapper for non-list/dict object to support map operation |
89aec1834a86
templatekw: add new-style template expansion to {manifest}
Yuya Nishihara <yuya@tcha.org>
parents:
34328
diff
changeset
|
74 |
89aec1834a86
templatekw: add new-style template expansion to {manifest}
Yuya Nishihara <yuya@tcha.org>
parents:
34328
diff
changeset
|
75 This class allows us to handle both: |
89aec1834a86
templatekw: add new-style template expansion to {manifest}
Yuya Nishihara <yuya@tcha.org>
parents:
34328
diff
changeset
|
76 - "{manifest}" |
89aec1834a86
templatekw: add new-style template expansion to {manifest}
Yuya Nishihara <yuya@tcha.org>
parents:
34328
diff
changeset
|
77 - "{manifest % '{rev}:{node}'}" |
34535
78590585c0db
templater: add dot operator to easily access a sub item
Yuya Nishihara <yuya@tcha.org>
parents:
34534
diff
changeset
|
78 - "{manifest.rev}" |
34330
89aec1834a86
templatekw: add new-style template expansion to {manifest}
Yuya Nishihara <yuya@tcha.org>
parents:
34328
diff
changeset
|
79 |
89aec1834a86
templatekw: add new-style template expansion to {manifest}
Yuya Nishihara <yuya@tcha.org>
parents:
34328
diff
changeset
|
80 Unlike a _hybrid, this does not simulate the behavior of the underling |
89aec1834a86
templatekw: add new-style template expansion to {manifest}
Yuya Nishihara <yuya@tcha.org>
parents:
34328
diff
changeset
|
81 value. Use unwrapvalue() or unwraphybrid() to obtain the inner object. |
89aec1834a86
templatekw: add new-style template expansion to {manifest}
Yuya Nishihara <yuya@tcha.org>
parents:
34328
diff
changeset
|
82 """ |
89aec1834a86
templatekw: add new-style template expansion to {manifest}
Yuya Nishihara <yuya@tcha.org>
parents:
34328
diff
changeset
|
83 |
34534
b3073e175c17
templater: wrap get/min/max result so map operation can apply to element
Yuya Nishihara <yuya@tcha.org>
parents:
34425
diff
changeset
|
84 def __init__(self, gen, key, value, makemap): |
b3073e175c17
templater: wrap get/min/max result so map operation can apply to element
Yuya Nishihara <yuya@tcha.org>
parents:
34425
diff
changeset
|
85 if gen is not None: |
b3073e175c17
templater: wrap get/min/max result so map operation can apply to element
Yuya Nishihara <yuya@tcha.org>
parents:
34425
diff
changeset
|
86 self.gen = gen # generator or function returning generator |
b3073e175c17
templater: wrap get/min/max result so map operation can apply to element
Yuya Nishihara <yuya@tcha.org>
parents:
34425
diff
changeset
|
87 self._key = key |
34330
89aec1834a86
templatekw: add new-style template expansion to {manifest}
Yuya Nishihara <yuya@tcha.org>
parents:
34328
diff
changeset
|
88 self._value = value # may be generator of strings |
89aec1834a86
templatekw: add new-style template expansion to {manifest}
Yuya Nishihara <yuya@tcha.org>
parents:
34328
diff
changeset
|
89 self._makemap = makemap |
89aec1834a86
templatekw: add new-style template expansion to {manifest}
Yuya Nishihara <yuya@tcha.org>
parents:
34328
diff
changeset
|
90 |
34534
b3073e175c17
templater: wrap get/min/max result so map operation can apply to element
Yuya Nishihara <yuya@tcha.org>
parents:
34425
diff
changeset
|
91 def gen(self): |
b3073e175c17
templater: wrap get/min/max result so map operation can apply to element
Yuya Nishihara <yuya@tcha.org>
parents:
34425
diff
changeset
|
92 yield pycompat.bytestr(self._value) |
b3073e175c17
templater: wrap get/min/max result so map operation can apply to element
Yuya Nishihara <yuya@tcha.org>
parents:
34425
diff
changeset
|
93 |
34330
89aec1834a86
templatekw: add new-style template expansion to {manifest}
Yuya Nishihara <yuya@tcha.org>
parents:
34328
diff
changeset
|
94 def tomap(self): |
34534
b3073e175c17
templater: wrap get/min/max result so map operation can apply to element
Yuya Nishihara <yuya@tcha.org>
parents:
34425
diff
changeset
|
95 return self._makemap(self._key) |
34330
89aec1834a86
templatekw: add new-style template expansion to {manifest}
Yuya Nishihara <yuya@tcha.org>
parents:
34328
diff
changeset
|
96 |
89aec1834a86
templatekw: add new-style template expansion to {manifest}
Yuya Nishihara <yuya@tcha.org>
parents:
34328
diff
changeset
|
97 def itermaps(self): |
89aec1834a86
templatekw: add new-style template expansion to {manifest}
Yuya Nishihara <yuya@tcha.org>
parents:
34328
diff
changeset
|
98 yield self.tomap() |
89aec1834a86
templatekw: add new-style template expansion to {manifest}
Yuya Nishihara <yuya@tcha.org>
parents:
34328
diff
changeset
|
99 |
31925
5b2241e84982
templatekw: add public function to wrap a dict by _hybrid object
Yuya Nishihara <yuya@tcha.org>
parents:
31924
diff
changeset
|
100 def hybriddict(data, key='key', value='value', fmt='%s=%s', gen=None): |
5b2241e84982
templatekw: add public function to wrap a dict by _hybrid object
Yuya Nishihara <yuya@tcha.org>
parents:
31924
diff
changeset
|
101 """Wrap data to support both dict-like and string-like operations""" |
5b2241e84982
templatekw: add public function to wrap a dict by _hybrid object
Yuya Nishihara <yuya@tcha.org>
parents:
31924
diff
changeset
|
102 return _hybrid(gen, data, lambda k: {key: k, value: data[k]}, |
34328
dd28b1f55eb8
templatekw: just pass underlying value (or key) to joinfmt() function
Yuya Nishihara <yuya@tcha.org>
parents:
34327
diff
changeset
|
103 lambda k: fmt % (k, data[k])) |
31925
5b2241e84982
templatekw: add public function to wrap a dict by _hybrid object
Yuya Nishihara <yuya@tcha.org>
parents:
31924
diff
changeset
|
104 |
31924
21f129354dd0
templatekw: add public function to wrap a list by _hybrid object
Yuya Nishihara <yuya@tcha.org>
parents:
31923
diff
changeset
|
105 def hybridlist(data, name, fmt='%s', gen=None): |
21f129354dd0
templatekw: add public function to wrap a list by _hybrid object
Yuya Nishihara <yuya@tcha.org>
parents:
31923
diff
changeset
|
106 """Wrap data to support both list-like and string-like operations""" |
34328
dd28b1f55eb8
templatekw: just pass underlying value (or key) to joinfmt() function
Yuya Nishihara <yuya@tcha.org>
parents:
34327
diff
changeset
|
107 return _hybrid(gen, data, lambda x: {name: x}, lambda x: fmt % x) |
31924
21f129354dd0
templatekw: add public function to wrap a list by _hybrid object
Yuya Nishihara <yuya@tcha.org>
parents:
31923
diff
changeset
|
108 |
31880
a0f2d83f8083
templater: remove __iter__() from _hybrid, resolve it explicitly
Yuya Nishihara <yuya@tcha.org>
parents:
31879
diff
changeset
|
109 def unwraphybrid(thing): |
a0f2d83f8083
templater: remove __iter__() from _hybrid, resolve it explicitly
Yuya Nishihara <yuya@tcha.org>
parents:
31879
diff
changeset
|
110 """Return an object which can be stringified possibly by using a legacy |
a0f2d83f8083
templater: remove __iter__() from _hybrid, resolve it explicitly
Yuya Nishihara <yuya@tcha.org>
parents:
31879
diff
changeset
|
111 template""" |
34425
12bfecd0ffe6
formatter: fix default list/dict generator to be evaluated more than once
Yuya Nishihara <yuya@tcha.org>
parents:
34330
diff
changeset
|
112 gen = getattr(thing, 'gen', None) |
12bfecd0ffe6
formatter: fix default list/dict generator to be evaluated more than once
Yuya Nishihara <yuya@tcha.org>
parents:
34330
diff
changeset
|
113 if gen is None: |
31880
a0f2d83f8083
templater: remove __iter__() from _hybrid, resolve it explicitly
Yuya Nishihara <yuya@tcha.org>
parents:
31879
diff
changeset
|
114 return thing |
34425
12bfecd0ffe6
formatter: fix default list/dict generator to be evaluated more than once
Yuya Nishihara <yuya@tcha.org>
parents:
34330
diff
changeset
|
115 if callable(gen): |
12bfecd0ffe6
formatter: fix default list/dict generator to be evaluated more than once
Yuya Nishihara <yuya@tcha.org>
parents:
34330
diff
changeset
|
116 return gen() |
12bfecd0ffe6
formatter: fix default list/dict generator to be evaluated more than once
Yuya Nishihara <yuya@tcha.org>
parents:
34330
diff
changeset
|
117 return gen |
31880
a0f2d83f8083
templater: remove __iter__() from _hybrid, resolve it explicitly
Yuya Nishihara <yuya@tcha.org>
parents:
31879
diff
changeset
|
118 |
34330
89aec1834a86
templatekw: add new-style template expansion to {manifest}
Yuya Nishihara <yuya@tcha.org>
parents:
34328
diff
changeset
|
119 def unwrapvalue(thing): |
89aec1834a86
templatekw: add new-style template expansion to {manifest}
Yuya Nishihara <yuya@tcha.org>
parents:
34328
diff
changeset
|
120 """Move the inner value object out of the wrapper""" |
89aec1834a86
templatekw: add new-style template expansion to {manifest}
Yuya Nishihara <yuya@tcha.org>
parents:
34328
diff
changeset
|
121 if not util.safehasattr(thing, '_value'): |
89aec1834a86
templatekw: add new-style template expansion to {manifest}
Yuya Nishihara <yuya@tcha.org>
parents:
34328
diff
changeset
|
122 return thing |
89aec1834a86
templatekw: add new-style template expansion to {manifest}
Yuya Nishihara <yuya@tcha.org>
parents:
34328
diff
changeset
|
123 return thing._value |
89aec1834a86
templatekw: add new-style template expansion to {manifest}
Yuya Nishihara <yuya@tcha.org>
parents:
34328
diff
changeset
|
124 |
34534
b3073e175c17
templater: wrap get/min/max result so map operation can apply to element
Yuya Nishihara <yuya@tcha.org>
parents:
34425
diff
changeset
|
125 def wraphybridvalue(container, key, value): |
b3073e175c17
templater: wrap get/min/max result so map operation can apply to element
Yuya Nishihara <yuya@tcha.org>
parents:
34425
diff
changeset
|
126 """Wrap an element of hybrid container to be mappable |
b3073e175c17
templater: wrap get/min/max result so map operation can apply to element
Yuya Nishihara <yuya@tcha.org>
parents:
34425
diff
changeset
|
127 |
b3073e175c17
templater: wrap get/min/max result so map operation can apply to element
Yuya Nishihara <yuya@tcha.org>
parents:
34425
diff
changeset
|
128 The key is passed to the makemap function of the given container, which |
b3073e175c17
templater: wrap get/min/max result so map operation can apply to element
Yuya Nishihara <yuya@tcha.org>
parents:
34425
diff
changeset
|
129 should be an item generated by iter(container). |
b3073e175c17
templater: wrap get/min/max result so map operation can apply to element
Yuya Nishihara <yuya@tcha.org>
parents:
34425
diff
changeset
|
130 """ |
b3073e175c17
templater: wrap get/min/max result so map operation can apply to element
Yuya Nishihara <yuya@tcha.org>
parents:
34425
diff
changeset
|
131 makemap = getattr(container, '_makemap', None) |
b3073e175c17
templater: wrap get/min/max result so map operation can apply to element
Yuya Nishihara <yuya@tcha.org>
parents:
34425
diff
changeset
|
132 if makemap is None: |
b3073e175c17
templater: wrap get/min/max result so map operation can apply to element
Yuya Nishihara <yuya@tcha.org>
parents:
34425
diff
changeset
|
133 return value |
b3073e175c17
templater: wrap get/min/max result so map operation can apply to element
Yuya Nishihara <yuya@tcha.org>
parents:
34425
diff
changeset
|
134 if util.safehasattr(value, '_makemap'): |
b3073e175c17
templater: wrap get/min/max result so map operation can apply to element
Yuya Nishihara <yuya@tcha.org>
parents:
34425
diff
changeset
|
135 # a nested hybrid list/dict, which has its own way of map operation |
b3073e175c17
templater: wrap get/min/max result so map operation can apply to element
Yuya Nishihara <yuya@tcha.org>
parents:
34425
diff
changeset
|
136 return value |
b3073e175c17
templater: wrap get/min/max result so map operation can apply to element
Yuya Nishihara <yuya@tcha.org>
parents:
34425
diff
changeset
|
137 return _mappable(None, key, value, makemap) |
b3073e175c17
templater: wrap get/min/max result so map operation can apply to element
Yuya Nishihara <yuya@tcha.org>
parents:
34425
diff
changeset
|
138 |
32038
3920b5970f95
templatekw: factor out showdict() helper
Yuya Nishihara <yuya@tcha.org>
parents:
32037
diff
changeset
|
139 def showdict(name, data, mapping, plural=None, key='key', value='value', |
3920b5970f95
templatekw: factor out showdict() helper
Yuya Nishihara <yuya@tcha.org>
parents:
32037
diff
changeset
|
140 fmt='%s=%s', separator=' '): |
3920b5970f95
templatekw: factor out showdict() helper
Yuya Nishihara <yuya@tcha.org>
parents:
32037
diff
changeset
|
141 c = [{key: k, value: v} for k, v in data.iteritems()] |
3920b5970f95
templatekw: factor out showdict() helper
Yuya Nishihara <yuya@tcha.org>
parents:
32037
diff
changeset
|
142 f = _showlist(name, c, mapping, plural, separator) |
3920b5970f95
templatekw: factor out showdict() helper
Yuya Nishihara <yuya@tcha.org>
parents:
32037
diff
changeset
|
143 return hybriddict(data, key=key, value=value, fmt=fmt, gen=f) |
3920b5970f95
templatekw: factor out showdict() helper
Yuya Nishihara <yuya@tcha.org>
parents:
32037
diff
changeset
|
144 |
32037
e5eab0fe69ee
templatekw: have showlist() take mapping dict with no **kwargs expansion (API)
Yuya Nishihara <yuya@tcha.org>
parents:
32036
diff
changeset
|
145 def showlist(name, values, mapping, plural=None, element=None, separator=' '): |
17631
0b241d7a8c62
templating: make new-style templating features work with command line lists
Matt Mackall <mpm@selenic.com>
parents:
17358
diff
changeset
|
146 if not element: |
0b241d7a8c62
templating: make new-style templating features work with command line lists
Matt Mackall <mpm@selenic.com>
parents:
17358
diff
changeset
|
147 element = name |
32036
8bcc8c9b4e9f
templatekw: change _showlist() to take mapping dict with no **kwargs expansion
Yuya Nishihara <yuya@tcha.org>
parents:
32035
diff
changeset
|
148 f = _showlist(name, values, mapping, plural, separator) |
31924
21f129354dd0
templatekw: add public function to wrap a list by _hybrid object
Yuya Nishihara <yuya@tcha.org>
parents:
31923
diff
changeset
|
149 return hybridlist(values, name=element, gen=f) |
17631
0b241d7a8c62
templating: make new-style templating features work with command line lists
Matt Mackall <mpm@selenic.com>
parents:
17358
diff
changeset
|
150 |
32036
8bcc8c9b4e9f
templatekw: change _showlist() to take mapping dict with no **kwargs expansion
Yuya Nishihara <yuya@tcha.org>
parents:
32035
diff
changeset
|
151 def _showlist(name, values, mapping, plural=None, separator=' '): |
10053
5c5c6295533d
cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
152 '''expand set of values. |
5c5c6295533d
cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
153 name is name of key in template map. |
5c5c6295533d
cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
154 values is list of strings or dicts. |
5c5c6295533d
cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
155 plural is plural of name, if not simply name + 's'. |
25726
b44e483726d3
templatekw: allow the caller of showlist() to specify the join() separator
Matt Harbison <matt_harbison@yahoo.com>
parents:
25724
diff
changeset
|
156 separator is used to join values as a string |
10053
5c5c6295533d
cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
157 |
5c5c6295533d
cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
158 expansion works like this, given name 'foo'. |
5c5c6295533d
cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
159 |
5c5c6295533d
cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
160 if values is empty, expand 'no_foos'. |
5c5c6295533d
cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
161 |
5c5c6295533d
cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
162 if 'foo' not in template map, return values as a string, |
25726
b44e483726d3
templatekw: allow the caller of showlist() to specify the join() separator
Matt Harbison <matt_harbison@yahoo.com>
parents:
25724
diff
changeset
|
163 joined by 'separator'. |
10053
5c5c6295533d
cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
164 |
5c5c6295533d
cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
165 expand 'start_foos'. |
5c5c6295533d
cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
166 |
5c5c6295533d
cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
167 for each value, expand 'foo'. if 'last_foo' in template |
5c5c6295533d
cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
168 map, expand it instead of 'foo' for last key. |
5c5c6295533d
cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
169 |
5c5c6295533d
cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
170 expand 'end_foos'. |
5c5c6295533d
cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
171 ''' |
32035
f4ba33454b28
templatekw: rename 'args' to 'mapping' in showlist()
Yuya Nishihara <yuya@tcha.org>
parents:
32034
diff
changeset
|
172 templ = mapping['templ'] |
33017
c31d45623304
py3: convert kwargs' keys' to str using pycompat.strkwargs()
Pulkit Goyal <7895pulkit@gmail.com>
parents:
33015
diff
changeset
|
173 strmapping = pycompat.strkwargs(mapping) |
32034
579bbcb4322b
templatekw: eliminate unnecessary temporary variable 'names' from _showlist()
Yuya Nishihara <yuya@tcha.org>
parents:
31925
diff
changeset
|
174 if not plural: |
579bbcb4322b
templatekw: eliminate unnecessary temporary variable 'names' from _showlist()
Yuya Nishihara <yuya@tcha.org>
parents:
31925
diff
changeset
|
175 plural = name + 's' |
10053
5c5c6295533d
cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
176 if not values: |
32034
579bbcb4322b
templatekw: eliminate unnecessary temporary variable 'names' from _showlist()
Yuya Nishihara <yuya@tcha.org>
parents:
31925
diff
changeset
|
177 noname = 'no_' + plural |
10053
5c5c6295533d
cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
178 if noname in templ: |
33017
c31d45623304
py3: convert kwargs' keys' to str using pycompat.strkwargs()
Pulkit Goyal <7895pulkit@gmail.com>
parents:
33015
diff
changeset
|
179 yield templ(noname, **strmapping) |
10053
5c5c6295533d
cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
180 return |
5c5c6295533d
cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
181 if name not in templ: |
32970
11c0bb4ccc76
py3: replace str with bytes in isinstance()
Pulkit Goyal <7895pulkit@gmail.com>
parents:
32911
diff
changeset
|
182 if isinstance(values[0], bytes): |
25726
b44e483726d3
templatekw: allow the caller of showlist() to specify the join() separator
Matt Harbison <matt_harbison@yahoo.com>
parents:
25724
diff
changeset
|
183 yield separator.join(values) |
10053
5c5c6295533d
cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
184 else: |
5c5c6295533d
cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
185 for v in values: |
33017
c31d45623304
py3: convert kwargs' keys' to str using pycompat.strkwargs()
Pulkit Goyal <7895pulkit@gmail.com>
parents:
33015
diff
changeset
|
186 yield dict(v, **strmapping) |
10053
5c5c6295533d
cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
187 return |
32034
579bbcb4322b
templatekw: eliminate unnecessary temporary variable 'names' from _showlist()
Yuya Nishihara <yuya@tcha.org>
parents:
31925
diff
changeset
|
188 startname = 'start_' + plural |
10053
5c5c6295533d
cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
189 if startname in templ: |
33017
c31d45623304
py3: convert kwargs' keys' to str using pycompat.strkwargs()
Pulkit Goyal <7895pulkit@gmail.com>
parents:
33015
diff
changeset
|
190 yield templ(startname, **strmapping) |
32035
f4ba33454b28
templatekw: rename 'args' to 'mapping' in showlist()
Yuya Nishihara <yuya@tcha.org>
parents:
32034
diff
changeset
|
191 vmapping = mapping.copy() |
10053
5c5c6295533d
cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
192 def one(v, tag=name): |
5c5c6295533d
cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
193 try: |
32035
f4ba33454b28
templatekw: rename 'args' to 'mapping' in showlist()
Yuya Nishihara <yuya@tcha.org>
parents:
32034
diff
changeset
|
194 vmapping.update(v) |
10053
5c5c6295533d
cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
195 except (AttributeError, ValueError): |
5c5c6295533d
cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
196 try: |
5c5c6295533d
cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
197 for a, b in v: |
32035
f4ba33454b28
templatekw: rename 'args' to 'mapping' in showlist()
Yuya Nishihara <yuya@tcha.org>
parents:
32034
diff
changeset
|
198 vmapping[a] = b |
10053
5c5c6295533d
cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
199 except ValueError: |
32035
f4ba33454b28
templatekw: rename 'args' to 'mapping' in showlist()
Yuya Nishihara <yuya@tcha.org>
parents:
32034
diff
changeset
|
200 vmapping[name] = v |
33017
c31d45623304
py3: convert kwargs' keys' to str using pycompat.strkwargs()
Pulkit Goyal <7895pulkit@gmail.com>
parents:
33015
diff
changeset
|
201 return templ(tag, **pycompat.strkwargs(vmapping)) |
10053
5c5c6295533d
cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
202 lastname = 'last_' + name |
5c5c6295533d
cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
203 if lastname in templ: |
5c5c6295533d
cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
204 last = values.pop() |
5c5c6295533d
cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
205 else: |
5c5c6295533d
cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
206 last = None |
5c5c6295533d
cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
207 for v in values: |
5c5c6295533d
cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
208 yield one(v) |
5c5c6295533d
cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
209 if last is not None: |
5c5c6295533d
cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
210 yield one(last, tag=lastname) |
32034
579bbcb4322b
templatekw: eliminate unnecessary temporary variable 'names' from _showlist()
Yuya Nishihara <yuya@tcha.org>
parents:
31925
diff
changeset
|
211 endname = 'end_' + plural |
10053
5c5c6295533d
cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
212 if endname in templ: |
33017
c31d45623304
py3: convert kwargs' keys' to str using pycompat.strkwargs()
Pulkit Goyal <7895pulkit@gmail.com>
parents:
33015
diff
changeset
|
213 yield templ(endname, **strmapping) |
10053
5c5c6295533d
cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
214 |
10056
1a114aca93fa
cmdutil: extract file changes closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents:
10055
diff
changeset
|
215 def getfiles(repo, ctx, revcache): |
1a114aca93fa
cmdutil: extract file changes closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents:
10055
diff
changeset
|
216 if 'files' not in revcache: |
25392
ed18f4acf435
templatekw: compare target context and its parent exactly (issue4690)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24676
diff
changeset
|
217 revcache['files'] = repo.status(ctx.p1(), ctx)[:3] |
10056
1a114aca93fa
cmdutil: extract file changes closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents:
10055
diff
changeset
|
218 return revcache['files'] |
1a114aca93fa
cmdutil: extract file changes closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents:
10055
diff
changeset
|
219 |
26482
d2e69584e330
templatekw: allow getlatesttags() to match a specific tag pattern
Matt Harbison <matt_harbison@yahoo.com>
parents:
26437
diff
changeset
|
220 def getlatesttags(repo, ctx, cache, pattern=None): |
10057
babc00a82c5e
cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents:
10056
diff
changeset
|
221 '''return date, distance and name for the latest tag of rev''' |
babc00a82c5e
cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents:
10056
diff
changeset
|
222 |
26482
d2e69584e330
templatekw: allow getlatesttags() to match a specific tag pattern
Matt Harbison <matt_harbison@yahoo.com>
parents:
26437
diff
changeset
|
223 cachename = 'latesttags' |
d2e69584e330
templatekw: allow getlatesttags() to match a specific tag pattern
Matt Harbison <matt_harbison@yahoo.com>
parents:
26437
diff
changeset
|
224 if pattern is not None: |
d2e69584e330
templatekw: allow getlatesttags() to match a specific tag pattern
Matt Harbison <matt_harbison@yahoo.com>
parents:
26437
diff
changeset
|
225 cachename += '-' + pattern |
d2e69584e330
templatekw: allow getlatesttags() to match a specific tag pattern
Matt Harbison <matt_harbison@yahoo.com>
parents:
26437
diff
changeset
|
226 match = util.stringmatcher(pattern)[2] |
d2e69584e330
templatekw: allow getlatesttags() to match a specific tag pattern
Matt Harbison <matt_harbison@yahoo.com>
parents:
26437
diff
changeset
|
227 else: |
d2e69584e330
templatekw: allow getlatesttags() to match a specific tag pattern
Matt Harbison <matt_harbison@yahoo.com>
parents:
26437
diff
changeset
|
228 match = util.always |
d2e69584e330
templatekw: allow getlatesttags() to match a specific tag pattern
Matt Harbison <matt_harbison@yahoo.com>
parents:
26437
diff
changeset
|
229 |
d2e69584e330
templatekw: allow getlatesttags() to match a specific tag pattern
Matt Harbison <matt_harbison@yahoo.com>
parents:
26437
diff
changeset
|
230 if cachename not in cache: |
10057
babc00a82c5e
cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents:
10056
diff
changeset
|
231 # Cache mapping from rev to a tuple with tag date, tag |
babc00a82c5e
cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents:
10056
diff
changeset
|
232 # distance and tag name |
26482
d2e69584e330
templatekw: allow getlatesttags() to match a specific tag pattern
Matt Harbison <matt_harbison@yahoo.com>
parents:
26437
diff
changeset
|
233 cache[cachename] = {-1: (0, 0, ['null'])} |
d2e69584e330
templatekw: allow getlatesttags() to match a specific tag pattern
Matt Harbison <matt_harbison@yahoo.com>
parents:
26437
diff
changeset
|
234 latesttags = cache[cachename] |
10057
babc00a82c5e
cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents:
10056
diff
changeset
|
235 |
babc00a82c5e
cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents:
10056
diff
changeset
|
236 rev = ctx.rev() |
babc00a82c5e
cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents:
10056
diff
changeset
|
237 todo = [rev] |
babc00a82c5e
cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents:
10056
diff
changeset
|
238 while todo: |
babc00a82c5e
cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents:
10056
diff
changeset
|
239 rev = todo.pop() |
babc00a82c5e
cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents:
10056
diff
changeset
|
240 if rev in latesttags: |
babc00a82c5e
cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents:
10056
diff
changeset
|
241 continue |
babc00a82c5e
cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents:
10056
diff
changeset
|
242 ctx = repo[rev] |
20218
0c22257388d6
templatekw: allow tagtypes other than global in getlatesttags
Andrew Shadura <andrew@shadura.me>
parents:
20183
diff
changeset
|
243 tags = [t for t in ctx.tags() |
26482
d2e69584e330
templatekw: allow getlatesttags() to match a specific tag pattern
Matt Harbison <matt_harbison@yahoo.com>
parents:
26437
diff
changeset
|
244 if (repo.tagtype(t) and repo.tagtype(t) != 'local' |
d2e69584e330
templatekw: allow getlatesttags() to match a specific tag pattern
Matt Harbison <matt_harbison@yahoo.com>
parents:
26437
diff
changeset
|
245 and match(t))] |
10057
babc00a82c5e
cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents:
10056
diff
changeset
|
246 if tags: |
25700
0fca47b206f6
templatekw: use a list of tags in getlatesttags() instead of joining them
Matt Harbison <matt_harbison@yahoo.com>
parents:
25663
diff
changeset
|
247 latesttags[rev] = ctx.date()[0], 0, [t for t in sorted(tags)] |
10057
babc00a82c5e
cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents:
10056
diff
changeset
|
248 continue |
babc00a82c5e
cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents:
10056
diff
changeset
|
249 try: |
33862
fb672eac2702
templatekw: choose {latesttag} by len(changes), not date (issue5659)
Martin von Zweigbergk <martinvonz@google.com>
parents:
33476
diff
changeset
|
250 ptags = [latesttags[p.rev()] for p in ctx.parents()] |
fb672eac2702
templatekw: choose {latesttag} by len(changes), not date (issue5659)
Martin von Zweigbergk <martinvonz@google.com>
parents:
33476
diff
changeset
|
251 if len(ptags) > 1: |
fb672eac2702
templatekw: choose {latesttag} by len(changes), not date (issue5659)
Martin von Zweigbergk <martinvonz@google.com>
parents:
33476
diff
changeset
|
252 if ptags[0][2] == ptags[1][2]: |
fb672eac2702
templatekw: choose {latesttag} by len(changes), not date (issue5659)
Martin von Zweigbergk <martinvonz@google.com>
parents:
33476
diff
changeset
|
253 # The tuples are laid out so the right one can be found by |
fb672eac2702
templatekw: choose {latesttag} by len(changes), not date (issue5659)
Martin von Zweigbergk <martinvonz@google.com>
parents:
33476
diff
changeset
|
254 # comparison in this case. |
fb672eac2702
templatekw: choose {latesttag} by len(changes), not date (issue5659)
Martin von Zweigbergk <martinvonz@google.com>
parents:
33476
diff
changeset
|
255 pdate, pdist, ptag = max(ptags) |
fb672eac2702
templatekw: choose {latesttag} by len(changes), not date (issue5659)
Martin von Zweigbergk <martinvonz@google.com>
parents:
33476
diff
changeset
|
256 else: |
fb672eac2702
templatekw: choose {latesttag} by len(changes), not date (issue5659)
Martin von Zweigbergk <martinvonz@google.com>
parents:
33476
diff
changeset
|
257 def key(x): |
fb672eac2702
templatekw: choose {latesttag} by len(changes), not date (issue5659)
Martin von Zweigbergk <martinvonz@google.com>
parents:
33476
diff
changeset
|
258 changessincetag = len(repo.revs('only(%d, %s)', |
fb672eac2702
templatekw: choose {latesttag} by len(changes), not date (issue5659)
Martin von Zweigbergk <martinvonz@google.com>
parents:
33476
diff
changeset
|
259 ctx.rev(), x[2][0])) |
fb672eac2702
templatekw: choose {latesttag} by len(changes), not date (issue5659)
Martin von Zweigbergk <martinvonz@google.com>
parents:
33476
diff
changeset
|
260 # Smallest number of changes since tag wins. Date is |
fb672eac2702
templatekw: choose {latesttag} by len(changes), not date (issue5659)
Martin von Zweigbergk <martinvonz@google.com>
parents:
33476
diff
changeset
|
261 # used as tiebreaker. |
fb672eac2702
templatekw: choose {latesttag} by len(changes), not date (issue5659)
Martin von Zweigbergk <martinvonz@google.com>
parents:
33476
diff
changeset
|
262 return [-changessincetag, x[0]] |
fb672eac2702
templatekw: choose {latesttag} by len(changes), not date (issue5659)
Martin von Zweigbergk <martinvonz@google.com>
parents:
33476
diff
changeset
|
263 pdate, pdist, ptag = max(ptags, key=key) |
fb672eac2702
templatekw: choose {latesttag} by len(changes), not date (issue5659)
Martin von Zweigbergk <martinvonz@google.com>
parents:
33476
diff
changeset
|
264 else: |
fb672eac2702
templatekw: choose {latesttag} by len(changes), not date (issue5659)
Martin von Zweigbergk <martinvonz@google.com>
parents:
33476
diff
changeset
|
265 pdate, pdist, ptag = ptags[0] |
10057
babc00a82c5e
cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents:
10056
diff
changeset
|
266 except KeyError: |
babc00a82c5e
cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents:
10056
diff
changeset
|
267 # Cache miss - recurse |
babc00a82c5e
cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents:
10056
diff
changeset
|
268 todo.append(rev) |
babc00a82c5e
cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents:
10056
diff
changeset
|
269 todo.extend(p.rev() for p in ctx.parents()) |
babc00a82c5e
cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents:
10056
diff
changeset
|
270 continue |
babc00a82c5e
cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents:
10056
diff
changeset
|
271 latesttags[rev] = pdate, pdist + 1, ptag |
babc00a82c5e
cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents:
10056
diff
changeset
|
272 return latesttags[rev] |
babc00a82c5e
cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents:
10056
diff
changeset
|
273 |
10060
f780b1098efc
templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents:
10058
diff
changeset
|
274 def getrenamedfn(repo, endrev=None): |
f780b1098efc
templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents:
10058
diff
changeset
|
275 rcache = {} |
f780b1098efc
templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents:
10058
diff
changeset
|
276 if endrev is None: |
f780b1098efc
templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents:
10058
diff
changeset
|
277 endrev = len(repo) |
f780b1098efc
templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents:
10058
diff
changeset
|
278 |
f780b1098efc
templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents:
10058
diff
changeset
|
279 def getrenamed(fn, rev): |
f780b1098efc
templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents:
10058
diff
changeset
|
280 '''looks up all renames for a file (up to endrev) the first |
f780b1098efc
templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents:
10058
diff
changeset
|
281 time the file is given. It indexes on the changerev and only |
f780b1098efc
templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents:
10058
diff
changeset
|
282 parses the manifest if linkrev != changerev. |
f780b1098efc
templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents:
10058
diff
changeset
|
283 Returns rename info for fn at changerev rev.''' |
f780b1098efc
templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents:
10058
diff
changeset
|
284 if fn not in rcache: |
f780b1098efc
templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents:
10058
diff
changeset
|
285 rcache[fn] = {} |
f780b1098efc
templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents:
10058
diff
changeset
|
286 fl = repo.file(fn) |
f780b1098efc
templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents:
10058
diff
changeset
|
287 for i in fl: |
f780b1098efc
templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents:
10058
diff
changeset
|
288 lr = fl.linkrev(i) |
f780b1098efc
templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents:
10058
diff
changeset
|
289 renamed = fl.renamed(fl.node(i)) |
f780b1098efc
templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents:
10058
diff
changeset
|
290 rcache[fn][lr] = renamed |
f780b1098efc
templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents:
10058
diff
changeset
|
291 if lr >= endrev: |
f780b1098efc
templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents:
10058
diff
changeset
|
292 break |
f780b1098efc
templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents:
10058
diff
changeset
|
293 if rev in rcache[fn]: |
f780b1098efc
templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents:
10058
diff
changeset
|
294 return rcache[fn][rev] |
f780b1098efc
templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents:
10058
diff
changeset
|
295 |
f780b1098efc
templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents:
10058
diff
changeset
|
296 # If linkrev != rev (i.e. rev not found in rcache) fallback to |
f780b1098efc
templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents:
10058
diff
changeset
|
297 # filectx logic. |
f780b1098efc
templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents:
10058
diff
changeset
|
298 try: |
f780b1098efc
templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents:
10058
diff
changeset
|
299 return repo[rev][fn].renamed() |
f780b1098efc
templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents:
10058
diff
changeset
|
300 except error.LookupError: |
f780b1098efc
templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents:
10058
diff
changeset
|
301 return None |
f780b1098efc
templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents:
10058
diff
changeset
|
302 |
f780b1098efc
templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents:
10058
diff
changeset
|
303 return getrenamed |
f780b1098efc
templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents:
10058
diff
changeset
|
304 |
35212
c7b45db8f317
log: translate column labels at once (issue5750)
Yuya Nishihara <yuya@tcha.org>
parents:
35143
diff
changeset
|
305 def getlogcolumns(): |
c7b45db8f317
log: translate column labels at once (issue5750)
Yuya Nishihara <yuya@tcha.org>
parents:
35143
diff
changeset
|
306 """Return a dict of log column labels""" |
c7b45db8f317
log: translate column labels at once (issue5750)
Yuya Nishihara <yuya@tcha.org>
parents:
35143
diff
changeset
|
307 _ = pycompat.identity # temporarily disable gettext |
c7b45db8f317
log: translate column labels at once (issue5750)
Yuya Nishihara <yuya@tcha.org>
parents:
35143
diff
changeset
|
308 # i18n: column positioning for "hg log" |
c7b45db8f317
log: translate column labels at once (issue5750)
Yuya Nishihara <yuya@tcha.org>
parents:
35143
diff
changeset
|
309 columns = _('bookmark: %s\n' |
c7b45db8f317
log: translate column labels at once (issue5750)
Yuya Nishihara <yuya@tcha.org>
parents:
35143
diff
changeset
|
310 'branch: %s\n' |
c7b45db8f317
log: translate column labels at once (issue5750)
Yuya Nishihara <yuya@tcha.org>
parents:
35143
diff
changeset
|
311 'changeset: %s\n' |
c7b45db8f317
log: translate column labels at once (issue5750)
Yuya Nishihara <yuya@tcha.org>
parents:
35143
diff
changeset
|
312 'copies: %s\n' |
c7b45db8f317
log: translate column labels at once (issue5750)
Yuya Nishihara <yuya@tcha.org>
parents:
35143
diff
changeset
|
313 'date: %s\n' |
c7b45db8f317
log: translate column labels at once (issue5750)
Yuya Nishihara <yuya@tcha.org>
parents:
35143
diff
changeset
|
314 'extra: %s=%s\n' |
c7b45db8f317
log: translate column labels at once (issue5750)
Yuya Nishihara <yuya@tcha.org>
parents:
35143
diff
changeset
|
315 'files+: %s\n' |
c7b45db8f317
log: translate column labels at once (issue5750)
Yuya Nishihara <yuya@tcha.org>
parents:
35143
diff
changeset
|
316 'files-: %s\n' |
c7b45db8f317
log: translate column labels at once (issue5750)
Yuya Nishihara <yuya@tcha.org>
parents:
35143
diff
changeset
|
317 'files: %s\n' |
c7b45db8f317
log: translate column labels at once (issue5750)
Yuya Nishihara <yuya@tcha.org>
parents:
35143
diff
changeset
|
318 'instability: %s\n' |
c7b45db8f317
log: translate column labels at once (issue5750)
Yuya Nishihara <yuya@tcha.org>
parents:
35143
diff
changeset
|
319 'manifest: %s\n' |
c7b45db8f317
log: translate column labels at once (issue5750)
Yuya Nishihara <yuya@tcha.org>
parents:
35143
diff
changeset
|
320 'obsolete: %s\n' |
c7b45db8f317
log: translate column labels at once (issue5750)
Yuya Nishihara <yuya@tcha.org>
parents:
35143
diff
changeset
|
321 'parent: %s\n' |
c7b45db8f317
log: translate column labels at once (issue5750)
Yuya Nishihara <yuya@tcha.org>
parents:
35143
diff
changeset
|
322 'phase: %s\n' |
c7b45db8f317
log: translate column labels at once (issue5750)
Yuya Nishihara <yuya@tcha.org>
parents:
35143
diff
changeset
|
323 'summary: %s\n' |
c7b45db8f317
log: translate column labels at once (issue5750)
Yuya Nishihara <yuya@tcha.org>
parents:
35143
diff
changeset
|
324 'tag: %s\n' |
c7b45db8f317
log: translate column labels at once (issue5750)
Yuya Nishihara <yuya@tcha.org>
parents:
35143
diff
changeset
|
325 'user: %s\n') |
c7b45db8f317
log: translate column labels at once (issue5750)
Yuya Nishihara <yuya@tcha.org>
parents:
35143
diff
changeset
|
326 return dict(zip([s.split(':', 1)[0] for s in columns.splitlines()], |
c7b45db8f317
log: translate column labels at once (issue5750)
Yuya Nishihara <yuya@tcha.org>
parents:
35143
diff
changeset
|
327 i18n._(columns).splitlines(True))) |
c7b45db8f317
log: translate column labels at once (issue5750)
Yuya Nishihara <yuya@tcha.org>
parents:
35143
diff
changeset
|
328 |
31171
1ec89cf0ea49
templatekw: move defaulttmpl constant from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents:
30833
diff
changeset
|
329 # default templates internally used for rendering of lists |
1ec89cf0ea49
templatekw: move defaulttmpl constant from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents:
30833
diff
changeset
|
330 defaulttempl = { |
1ec89cf0ea49
templatekw: move defaulttmpl constant from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents:
30833
diff
changeset
|
331 'parent': '{rev}:{node|formatnode} ', |
1ec89cf0ea49
templatekw: move defaulttmpl constant from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents:
30833
diff
changeset
|
332 'manifest': '{rev}:{node|formatnode}', |
1ec89cf0ea49
templatekw: move defaulttmpl constant from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents:
30833
diff
changeset
|
333 'file_copy': '{name} ({source})', |
1ec89cf0ea49
templatekw: move defaulttmpl constant from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents:
30833
diff
changeset
|
334 'envvar': '{key}={value}', |
1ec89cf0ea49
templatekw: move defaulttmpl constant from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents:
30833
diff
changeset
|
335 'extra': '{key}={value|stringescape}' |
1ec89cf0ea49
templatekw: move defaulttmpl constant from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents:
30833
diff
changeset
|
336 } |
1ec89cf0ea49
templatekw: move defaulttmpl constant from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents:
30833
diff
changeset
|
337 # filecopy is preserved for compatibility reasons |
1ec89cf0ea49
templatekw: move defaulttmpl constant from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents:
30833
diff
changeset
|
338 defaulttempl['filecopy'] = defaulttempl['file_copy'] |
1ec89cf0ea49
templatekw: move defaulttmpl constant from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents:
30833
diff
changeset
|
339 |
28539
119702a8b415
templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
340 # keywords are callables like: |
119702a8b415
templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
341 # fn(repo, ctx, templ, cache, revcache, **args) |
119702a8b415
templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
342 # with: |
119702a8b415
templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
343 # repo - current repository instance |
119702a8b415
templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
344 # ctx - the changectx being displayed |
119702a8b415
templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
345 # templ - the templater instance |
119702a8b415
templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
346 # cache - a cache dictionary for the whole templater run |
119702a8b415
templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
347 # revcache - a cache dictionary for the current revision |
119702a8b415
templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
348 keywords = {} |
10060
f780b1098efc
templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents:
10058
diff
changeset
|
349 |
28539
119702a8b415
templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
350 templatekeyword = registrar.templatekeyword(keywords) |
119702a8b415
templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
351 |
119702a8b415
templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
352 @templatekeyword('author') |
10055
e400a511e63a
cmdutil: extract repo dependent closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents:
10054
diff
changeset
|
353 def showauthor(repo, ctx, templ, **args): |
28539
119702a8b415
templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
354 """String. The unmodified author of the changeset.""" |
10054
1a85861f59af
cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents:
10053
diff
changeset
|
355 return ctx.user() |
1a85861f59af
cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents:
10053
diff
changeset
|
356 |
28539
119702a8b415
templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
357 @templatekeyword('bisect') |
15155
f4a8d754cd0a
templates: add 'bisect' keyword to return a cset's bisect status
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents:
14437
diff
changeset
|
358 def showbisect(repo, ctx, templ, **args): |
28539
119702a8b415
templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
359 """String. The changeset bisection status.""" |
15155
f4a8d754cd0a
templates: add 'bisect' keyword to return a cset's bisect status
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents:
14437
diff
changeset
|
360 return hbisect.label(repo, ctx.node()) |
f4a8d754cd0a
templates: add 'bisect' keyword to return a cset's bisect status
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents:
14437
diff
changeset
|
361 |
28539
119702a8b415
templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
362 @templatekeyword('branch') |
13156
d79fdff55627
template: add showbranch template for {branch}
Eric Eisner <ede@mit.edu>
parents:
13114
diff
changeset
|
363 def showbranch(**args): |
28539
119702a8b415
templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
364 """String. The name of the branch on which the changeset was |
13585
2e80d495592a
templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents:
13386
diff
changeset
|
365 committed. |
2e80d495592a
templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents:
13386
diff
changeset
|
366 """ |
32973
20ca19e6c74e
py3: use r'' to access values from kwargs where keys are str
Pulkit Goyal <7895pulkit@gmail.com>
parents:
32972
diff
changeset
|
367 return args[r'ctx'].branch() |
13156
d79fdff55627
template: add showbranch template for {branch}
Eric Eisner <ede@mit.edu>
parents:
13114
diff
changeset
|
368 |
28539
119702a8b415
templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
369 @templatekeyword('branches') |
10260
fe699ca08a45
templatekw: fix extras, manifest and showlist args (issue1989)
Patrick Mezard <pmezard@gmail.com>
parents:
10060
diff
changeset
|
370 def showbranches(**args): |
28539
119702a8b415
templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
371 """List of strings. The name of the branch on which the |
13585
2e80d495592a
templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents:
13386
diff
changeset
|
372 changeset was committed. Will be empty if the branch name was |
26437
4628b26f040e
templatekw: hide help of "branches" by DEPRECATED marker
Yuya Nishihara <yuya@tcha.org>
parents:
26436
diff
changeset
|
373 default. (DEPRECATED) |
13585
2e80d495592a
templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents:
13386
diff
changeset
|
374 """ |
32972
26e710f0468f
py3: convert keys of kwargs in template keywords functions to bytes
Pulkit Goyal <7895pulkit@gmail.com>
parents:
32970
diff
changeset
|
375 args = pycompat.byteskwargs(args) |
10260
fe699ca08a45
templatekw: fix extras, manifest and showlist args (issue1989)
Patrick Mezard <pmezard@gmail.com>
parents:
10060
diff
changeset
|
376 branch = args['ctx'].branch() |
10054
1a85861f59af
cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents:
10053
diff
changeset
|
377 if branch != 'default': |
32037
e5eab0fe69ee
templatekw: have showlist() take mapping dict with no **kwargs expansion (API)
Yuya Nishihara <yuya@tcha.org>
parents:
32036
diff
changeset
|
378 return showlist('branch', [branch], args, plural='branches') |
e5eab0fe69ee
templatekw: have showlist() take mapping dict with no **kwargs expansion (API)
Yuya Nishihara <yuya@tcha.org>
parents:
32036
diff
changeset
|
379 return showlist('branch', [], args, plural='branches') |
10054
1a85861f59af
cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents:
10053
diff
changeset
|
380 |
28539
119702a8b415
templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
381 @templatekeyword('bookmarks') |
13386
f78bc5ddbe4f
templater: add bookmarks to templates and default output
David Soria Parra <dsp@php.net>
parents:
13156
diff
changeset
|
382 def showbookmarks(**args): |
28539
119702a8b415
templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
383 """List of strings. Any bookmarks associated with the |
25348
f26efa4f0eff
templatekw: introduce active subkeyword from bookmarks keyword
Ryan McElroy <rmcelroy@fb.com>
parents:
25013
diff
changeset
|
384 changeset. Also sets 'active', the name of the active bookmark. |
13592
ad2ee188f4a5
templates: document missing keywords or filters
Patrick Mezard <pmezard@gmail.com>
parents:
13585
diff
changeset
|
385 """ |
32972
26e710f0468f
py3: convert keys of kwargs in template keywords functions to bytes
Pulkit Goyal <7895pulkit@gmail.com>
parents:
32970
diff
changeset
|
386 args = pycompat.byteskwargs(args) |
20520
5c65ee4193e1
template: add 'current' to scope during {bookmarks % ...}
Durham Goode <durham@fb.com>
parents:
20218
diff
changeset
|
387 repo = args['ctx']._repo |
13386
f78bc5ddbe4f
templater: add bookmarks to templates and default output
David Soria Parra <dsp@php.net>
parents:
13156
diff
changeset
|
388 bookmarks = args['ctx'].bookmarks() |
25348
f26efa4f0eff
templatekw: introduce active subkeyword from bookmarks keyword
Ryan McElroy <rmcelroy@fb.com>
parents:
25013
diff
changeset
|
389 active = repo._activebookmark |
f26efa4f0eff
templatekw: introduce active subkeyword from bookmarks keyword
Ryan McElroy <rmcelroy@fb.com>
parents:
25013
diff
changeset
|
390 makemap = lambda v: {'bookmark': v, 'active': active, 'current': active} |
32036
8bcc8c9b4e9f
templatekw: change _showlist() to take mapping dict with no **kwargs expansion
Yuya Nishihara <yuya@tcha.org>
parents:
32035
diff
changeset
|
391 f = _showlist('bookmark', bookmarks, args) |
34328
dd28b1f55eb8
templatekw: just pass underlying value (or key) to joinfmt() function
Yuya Nishihara <yuya@tcha.org>
parents:
34327
diff
changeset
|
392 return _hybrid(f, bookmarks, makemap, pycompat.identity) |
13386
f78bc5ddbe4f
templater: add bookmarks to templates and default output
David Soria Parra <dsp@php.net>
parents:
13156
diff
changeset
|
393 |
28539
119702a8b415
templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
394 @templatekeyword('children') |
11655
6faf015e0ba0
templates: 'children' keyword
Jason Harris <jason@jasonfharris.com>
parents:
10394
diff
changeset
|
395 def showchildren(**args): |
28539
119702a8b415
templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
396 """List of strings. The children of the changeset.""" |
32972
26e710f0468f
py3: convert keys of kwargs in template keywords functions to bytes
Pulkit Goyal <7895pulkit@gmail.com>
parents:
32970
diff
changeset
|
397 args = pycompat.byteskwargs(args) |
11655
6faf015e0ba0
templates: 'children' keyword
Jason Harris <jason@jasonfharris.com>
parents:
10394
diff
changeset
|
398 ctx = args['ctx'] |
6faf015e0ba0
templates: 'children' keyword
Jason Harris <jason@jasonfharris.com>
parents:
10394
diff
changeset
|
399 childrevs = ['%d:%s' % (cctx, cctx) for cctx in ctx.children()] |
32037
e5eab0fe69ee
templatekw: have showlist() take mapping dict with no **kwargs expansion (API)
Yuya Nishihara <yuya@tcha.org>
parents:
32036
diff
changeset
|
400 return showlist('children', childrevs, args, element='child') |
11655
6faf015e0ba0
templates: 'children' keyword
Jason Harris <jason@jasonfharris.com>
parents:
10394
diff
changeset
|
401 |
25013
277aba2c151a
templatekw: introduce activebookmark keyword
Ryan McElroy <rmcelroy@fb.com>
parents:
25012
diff
changeset
|
402 # Deprecated, but kept alive for help generation a purpose. |
28539
119702a8b415
templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
403 @templatekeyword('currentbookmark') |
21896
2b41ee1b5ea1
templatekw: add 'currentbookmark' keyword to show current bookmark easily
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20683
diff
changeset
|
404 def showcurrentbookmark(**args): |
34656
eb7fffdc6e5b
help: fix formatting of template keywords
Yuya Nishihara <yuya@tcha.org>
parents:
34581
diff
changeset
|
405 """String. The active bookmark, if it is associated with the changeset. |
eb7fffdc6e5b
help: fix formatting of template keywords
Yuya Nishihara <yuya@tcha.org>
parents:
34581
diff
changeset
|
406 (DEPRECATED)""" |
25013
277aba2c151a
templatekw: introduce activebookmark keyword
Ryan McElroy <rmcelroy@fb.com>
parents:
25012
diff
changeset
|
407 return showactivebookmark(**args) |
277aba2c151a
templatekw: introduce activebookmark keyword
Ryan McElroy <rmcelroy@fb.com>
parents:
25012
diff
changeset
|
408 |
28539
119702a8b415
templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
409 @templatekeyword('activebookmark') |
25013
277aba2c151a
templatekw: introduce activebookmark keyword
Ryan McElroy <rmcelroy@fb.com>
parents:
25012
diff
changeset
|
410 def showactivebookmark(**args): |
34656
eb7fffdc6e5b
help: fix formatting of template keywords
Yuya Nishihara <yuya@tcha.org>
parents:
34581
diff
changeset
|
411 """String. The active bookmark, if it is associated with the changeset.""" |
32973
20ca19e6c74e
py3: use r'' to access values from kwargs where keys are str
Pulkit Goyal <7895pulkit@gmail.com>
parents:
32972
diff
changeset
|
412 active = args[r'repo']._activebookmark |
20ca19e6c74e
py3: use r'' to access values from kwargs where keys are str
Pulkit Goyal <7895pulkit@gmail.com>
parents:
32972
diff
changeset
|
413 if active and active in args[r'ctx'].bookmarks(): |
25387
390a10b7843b
templatekw: display active bookmark more consistently (issue4552) (BC)
Ryan McElroy <rmcelroy@fb.com>
parents:
25348
diff
changeset
|
414 return active |
21896
2b41ee1b5ea1
templatekw: add 'currentbookmark' keyword to show current bookmark easily
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20683
diff
changeset
|
415 return '' |
2b41ee1b5ea1
templatekw: add 'currentbookmark' keyword to show current bookmark easily
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20683
diff
changeset
|
416 |
28539
119702a8b415
templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
417 @templatekeyword('date') |
10055
e400a511e63a
cmdutil: extract repo dependent closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents:
10054
diff
changeset
|
418 def showdate(repo, ctx, templ, **args): |
28539
119702a8b415
templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
419 """Date information. The date when the changeset was committed.""" |
10054
1a85861f59af
cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents:
10053
diff
changeset
|
420 return ctx.date() |
1a85861f59af
cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents:
10053
diff
changeset
|
421 |
28539
119702a8b415
templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
422 @templatekeyword('desc') |
10055
e400a511e63a
cmdutil: extract repo dependent closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents:
10054
diff
changeset
|
423 def showdescription(repo, ctx, templ, **args): |
28539
119702a8b415
templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
424 """String. The text of the changeset description.""" |
28239
7279e0132347
templatekw: workaround for utf-8 round-trip of {desc}
Yuya Nishihara <yuya@tcha.org>
parents:
28178
diff
changeset
|
425 s = ctx.description() |
7279e0132347
templatekw: workaround for utf-8 round-trip of {desc}
Yuya Nishihara <yuya@tcha.org>
parents:
28178
diff
changeset
|
426 if isinstance(s, encoding.localstr): |
7279e0132347
templatekw: workaround for utf-8 round-trip of {desc}
Yuya Nishihara <yuya@tcha.org>
parents:
28178
diff
changeset
|
427 # try hard to preserve utf-8 bytes |
7279e0132347
templatekw: workaround for utf-8 round-trip of {desc}
Yuya Nishihara <yuya@tcha.org>
parents:
28178
diff
changeset
|
428 return encoding.tolocal(encoding.fromlocal(s).strip()) |
7279e0132347
templatekw: workaround for utf-8 round-trip of {desc}
Yuya Nishihara <yuya@tcha.org>
parents:
28178
diff
changeset
|
429 else: |
7279e0132347
templatekw: workaround for utf-8 round-trip of {desc}
Yuya Nishihara <yuya@tcha.org>
parents:
28178
diff
changeset
|
430 return s.strip() |
10054
1a85861f59af
cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents:
10053
diff
changeset
|
431 |
28539
119702a8b415
templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
432 @templatekeyword('diffstat') |
10055
e400a511e63a
cmdutil: extract repo dependent closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents:
10054
diff
changeset
|
433 def showdiffstat(repo, ctx, templ, **args): |
28539
119702a8b415
templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
434 """String. Statistics of changes with the following format: |
13585
2e80d495592a
templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents:
13386
diff
changeset
|
435 "modified files: +added/-removed lines" |
2e80d495592a
templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents:
13386
diff
changeset
|
436 """ |
30811
cf1e15f91c90
templatekw: force noprefix=False to insure diffstat consistency (issue4755)
Matthieu Laneuville <mlaneuville@protonmail.com>
parents:
30712
diff
changeset
|
437 stats = patch.diffstatdata(util.iterlines(ctx.diff(noprefix=False))) |
14437
cbe13e6bdc34
patch: restore the previous output of 'diff --stat'
Steven Brown <StevenGBrown@gmail.com>
parents:
14403
diff
changeset
|
438 maxname, maxtotal, adds, removes, binary = patch.diffstatsum(stats) |
14403
2c9f5897d4b7
templatekw: use diffstatsum in diffstat keyword
Matt Mackall <mpm@selenic.com>
parents:
14318
diff
changeset
|
439 return '%s: +%s/-%s' % (len(stats), adds, removes) |
10055
e400a511e63a
cmdutil: extract repo dependent closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents:
10054
diff
changeset
|
440 |
30833
bd5e9647f646
templater: add '{envvars}' to access environment variables
Matt Harbison <matt_harbison@yahoo.com>
parents:
30811
diff
changeset
|
441 @templatekeyword('envvars') |
bd5e9647f646
templater: add '{envvars}' to access environment variables
Matt Harbison <matt_harbison@yahoo.com>
parents:
30811
diff
changeset
|
442 def showenvvars(repo, **args): |
bd5e9647f646
templater: add '{envvars}' to access environment variables
Matt Harbison <matt_harbison@yahoo.com>
parents:
30811
diff
changeset
|
443 """A dictionary of environment variables. (EXPERIMENTAL)""" |
32972
26e710f0468f
py3: convert keys of kwargs in template keywords functions to bytes
Pulkit Goyal <7895pulkit@gmail.com>
parents:
32970
diff
changeset
|
444 args = pycompat.byteskwargs(args) |
30833
bd5e9647f646
templater: add '{envvars}' to access environment variables
Matt Harbison <matt_harbison@yahoo.com>
parents:
30811
diff
changeset
|
445 env = repo.ui.exportableenviron() |
bd5e9647f646
templater: add '{envvars}' to access environment variables
Matt Harbison <matt_harbison@yahoo.com>
parents:
30811
diff
changeset
|
446 env = util.sortdict((k, env[k]) for k in sorted(env)) |
32038
3920b5970f95
templatekw: factor out showdict() helper
Yuya Nishihara <yuya@tcha.org>
parents:
32037
diff
changeset
|
447 return showdict('envvar', env, args, plural='envvars') |
30833
bd5e9647f646
templater: add '{envvars}' to access environment variables
Matt Harbison <matt_harbison@yahoo.com>
parents:
30811
diff
changeset
|
448 |
28539
119702a8b415
templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
449 @templatekeyword('extras') |
10260
fe699ca08a45
templatekw: fix extras, manifest and showlist args (issue1989)
Patrick Mezard <pmezard@gmail.com>
parents:
10060
diff
changeset
|
450 def showextras(**args): |
28539
119702a8b415
templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
451 """List of dicts with key, value entries of the 'extras' |
20015
ad27cdacc743
help: document about {extras} template keyword
Matthew Turk <matthewturk@gmail.com>
parents:
18970
diff
changeset
|
452 field of this changeset.""" |
32972
26e710f0468f
py3: convert keys of kwargs in template keywords functions to bytes
Pulkit Goyal <7895pulkit@gmail.com>
parents:
32970
diff
changeset
|
453 args = pycompat.byteskwargs(args) |
20183
de7e6c489412
template: modify showextras to return a hybrid
Matthew Turk <matthewturk@gmail.com>
parents:
20079
diff
changeset
|
454 extras = args['ctx'].extra() |
24237
9ad02823dc5b
templatekw: convert list of key/value pairs to sortdict
Yuya Nishihara <yuya@tcha.org>
parents:
24157
diff
changeset
|
455 extras = util.sortdict((k, extras[k]) for k in sorted(extras)) |
24238
49cee6d8573d
templatekw: give name to lambda that constructs variables map of templater
Yuya Nishihara <yuya@tcha.org>
parents:
24237
diff
changeset
|
456 makemap = lambda k: {'key': k, 'value': extras[k]} |
49cee6d8573d
templatekw: give name to lambda that constructs variables map of templater
Yuya Nishihara <yuya@tcha.org>
parents:
24237
diff
changeset
|
457 c = [makemap(k) for k in extras] |
32036
8bcc8c9b4e9f
templatekw: change _showlist() to take mapping dict with no **kwargs expansion
Yuya Nishihara <yuya@tcha.org>
parents:
32035
diff
changeset
|
458 f = _showlist('extra', c, args, plural='extras') |
24239
31f9b1b16d1e
templatekw: keep raw list or dict in _hybrid object
Yuya Nishihara <yuya@tcha.org>
parents:
24238
diff
changeset
|
459 return _hybrid(f, extras, makemap, |
34328
dd28b1f55eb8
templatekw: just pass underlying value (or key) to joinfmt() function
Yuya Nishihara <yuya@tcha.org>
parents:
34327
diff
changeset
|
460 lambda k: '%s=%s' % (k, util.escapestr(extras[k]))) |
10054
1a85861f59af
cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents:
10053
diff
changeset
|
461 |
28539
119702a8b415
templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
462 @templatekeyword('file_adds') |
10260
fe699ca08a45
templatekw: fix extras, manifest and showlist args (issue1989)
Patrick Mezard <pmezard@gmail.com>
parents:
10060
diff
changeset
|
463 def showfileadds(**args): |
28539
119702a8b415
templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
464 """List of strings. Files added by this changeset.""" |
32972
26e710f0468f
py3: convert keys of kwargs in template keywords functions to bytes
Pulkit Goyal <7895pulkit@gmail.com>
parents:
32970
diff
changeset
|
465 args = pycompat.byteskwargs(args) |
10260
fe699ca08a45
templatekw: fix extras, manifest and showlist args (issue1989)
Patrick Mezard <pmezard@gmail.com>
parents:
10060
diff
changeset
|
466 repo, ctx, revcache = args['repo'], args['ctx'], args['revcache'] |
32037
e5eab0fe69ee
templatekw: have showlist() take mapping dict with no **kwargs expansion (API)
Yuya Nishihara <yuya@tcha.org>
parents:
32036
diff
changeset
|
467 return showlist('file_add', getfiles(repo, ctx, revcache)[1], args, |
e5eab0fe69ee
templatekw: have showlist() take mapping dict with no **kwargs expansion (API)
Yuya Nishihara <yuya@tcha.org>
parents:
32036
diff
changeset
|
468 element='file') |
10056
1a114aca93fa
cmdutil: extract file changes closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents:
10055
diff
changeset
|
469 |
28539
119702a8b415
templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
470 @templatekeyword('file_copies') |
10260
fe699ca08a45
templatekw: fix extras, manifest and showlist args (issue1989)
Patrick Mezard <pmezard@gmail.com>
parents:
10060
diff
changeset
|
471 def showfilecopies(**args): |
28539
119702a8b415
templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
472 """List of strings. Files copied in this changeset with |
13585
2e80d495592a
templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents:
13386
diff
changeset
|
473 their sources. |
2e80d495592a
templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents:
13386
diff
changeset
|
474 """ |
32972
26e710f0468f
py3: convert keys of kwargs in template keywords functions to bytes
Pulkit Goyal <7895pulkit@gmail.com>
parents:
32970
diff
changeset
|
475 args = pycompat.byteskwargs(args) |
10394
4612cded5176
fix coding style (reported by pylint)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10282
diff
changeset
|
476 cache, ctx = args['cache'], args['ctx'] |
10260
fe699ca08a45
templatekw: fix extras, manifest and showlist args (issue1989)
Patrick Mezard <pmezard@gmail.com>
parents:
10060
diff
changeset
|
477 copies = args['revcache'].get('copies') |
10060
f780b1098efc
templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents:
10058
diff
changeset
|
478 if copies is None: |
f780b1098efc
templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents:
10058
diff
changeset
|
479 if 'getrenamed' not in cache: |
10260
fe699ca08a45
templatekw: fix extras, manifest and showlist args (issue1989)
Patrick Mezard <pmezard@gmail.com>
parents:
10060
diff
changeset
|
480 cache['getrenamed'] = getrenamedfn(args['repo']) |
10060
f780b1098efc
templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents:
10058
diff
changeset
|
481 copies = [] |
f780b1098efc
templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents:
10058
diff
changeset
|
482 getrenamed = cache['getrenamed'] |
f780b1098efc
templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents:
10058
diff
changeset
|
483 for fn in ctx.files(): |
f780b1098efc
templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents:
10058
diff
changeset
|
484 rename = getrenamed(fn, ctx.rev()) |
f780b1098efc
templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents:
10058
diff
changeset
|
485 if rename: |
f780b1098efc
templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents:
10058
diff
changeset
|
486 copies.append((fn, rename[0])) |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
487 |
24237
9ad02823dc5b
templatekw: convert list of key/value pairs to sortdict
Yuya Nishihara <yuya@tcha.org>
parents:
24157
diff
changeset
|
488 copies = util.sortdict(copies) |
32038
3920b5970f95
templatekw: factor out showdict() helper
Yuya Nishihara <yuya@tcha.org>
parents:
32037
diff
changeset
|
489 return showdict('file_copy', copies, args, plural='file_copies', |
3920b5970f95
templatekw: factor out showdict() helper
Yuya Nishihara <yuya@tcha.org>
parents:
32037
diff
changeset
|
490 key='name', value='source', fmt='%s (%s)') |
10060
f780b1098efc
templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents:
10058
diff
changeset
|
491 |
f780b1098efc
templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents:
10058
diff
changeset
|
492 # showfilecopiesswitch() displays file copies only if copy records are |
f780b1098efc
templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents:
10058
diff
changeset
|
493 # provided before calling the templater, usually with a --copies |
f780b1098efc
templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents:
10058
diff
changeset
|
494 # command line switch. |
28539
119702a8b415
templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
495 @templatekeyword('file_copies_switch') |
10260
fe699ca08a45
templatekw: fix extras, manifest and showlist args (issue1989)
Patrick Mezard <pmezard@gmail.com>
parents:
10060
diff
changeset
|
496 def showfilecopiesswitch(**args): |
28539
119702a8b415
templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
497 """List of strings. Like "file_copies" but displayed |
13585
2e80d495592a
templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents:
13386
diff
changeset
|
498 only if the --copied switch is set. |
2e80d495592a
templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents:
13386
diff
changeset
|
499 """ |
32972
26e710f0468f
py3: convert keys of kwargs in template keywords functions to bytes
Pulkit Goyal <7895pulkit@gmail.com>
parents:
32970
diff
changeset
|
500 args = pycompat.byteskwargs(args) |
10260
fe699ca08a45
templatekw: fix extras, manifest and showlist args (issue1989)
Patrick Mezard <pmezard@gmail.com>
parents:
10060
diff
changeset
|
501 copies = args['revcache'].get('copies') or [] |
24237
9ad02823dc5b
templatekw: convert list of key/value pairs to sortdict
Yuya Nishihara <yuya@tcha.org>
parents:
24157
diff
changeset
|
502 copies = util.sortdict(copies) |
32038
3920b5970f95
templatekw: factor out showdict() helper
Yuya Nishihara <yuya@tcha.org>
parents:
32037
diff
changeset
|
503 return showdict('file_copy', copies, args, plural='file_copies', |
3920b5970f95
templatekw: factor out showdict() helper
Yuya Nishihara <yuya@tcha.org>
parents:
32037
diff
changeset
|
504 key='name', value='source', fmt='%s (%s)') |
10058
c829563b3118
cmdutil: extract file copies closure into templatekw
Patrick Mezard <pmezard@gmail.com>
parents:
10057
diff
changeset
|
505 |
28539
119702a8b415
templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
506 @templatekeyword('file_dels') |
10260
fe699ca08a45
templatekw: fix extras, manifest and showlist args (issue1989)
Patrick Mezard <pmezard@gmail.com>
parents:
10060
diff
changeset
|
507 def showfiledels(**args): |
28539
119702a8b415
templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
508 """List of strings. Files removed by this changeset.""" |
32972
26e710f0468f
py3: convert keys of kwargs in template keywords functions to bytes
Pulkit Goyal <7895pulkit@gmail.com>
parents:
32970
diff
changeset
|
509 args = pycompat.byteskwargs(args) |
10260
fe699ca08a45
templatekw: fix extras, manifest and showlist args (issue1989)
Patrick Mezard <pmezard@gmail.com>
parents:
10060
diff
changeset
|
510 repo, ctx, revcache = args['repo'], args['ctx'], args['revcache'] |
32037
e5eab0fe69ee
templatekw: have showlist() take mapping dict with no **kwargs expansion (API)
Yuya Nishihara <yuya@tcha.org>
parents:
32036
diff
changeset
|
511 return showlist('file_del', getfiles(repo, ctx, revcache)[2], args, |
e5eab0fe69ee
templatekw: have showlist() take mapping dict with no **kwargs expansion (API)
Yuya Nishihara <yuya@tcha.org>
parents:
32036
diff
changeset
|
512 element='file') |
10056
1a114aca93fa
cmdutil: extract file changes closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents:
10055
diff
changeset
|
513 |
28539
119702a8b415
templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
514 @templatekeyword('file_mods') |
10260
fe699ca08a45
templatekw: fix extras, manifest and showlist args (issue1989)
Patrick Mezard <pmezard@gmail.com>
parents:
10060
diff
changeset
|
515 def showfilemods(**args): |
28539
119702a8b415
templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
516 """List of strings. Files modified by this changeset.""" |
32972
26e710f0468f
py3: convert keys of kwargs in template keywords functions to bytes
Pulkit Goyal <7895pulkit@gmail.com>
parents:
32970
diff
changeset
|
517 args = pycompat.byteskwargs(args) |
10260
fe699ca08a45
templatekw: fix extras, manifest and showlist args (issue1989)
Patrick Mezard <pmezard@gmail.com>
parents:
10060
diff
changeset
|
518 repo, ctx, revcache = args['repo'], args['ctx'], args['revcache'] |
32037
e5eab0fe69ee
templatekw: have showlist() take mapping dict with no **kwargs expansion (API)
Yuya Nishihara <yuya@tcha.org>
parents:
32036
diff
changeset
|
519 return showlist('file_mod', getfiles(repo, ctx, revcache)[0], args, |
e5eab0fe69ee
templatekw: have showlist() take mapping dict with no **kwargs expansion (API)
Yuya Nishihara <yuya@tcha.org>
parents:
32036
diff
changeset
|
520 element='file') |
10056
1a114aca93fa
cmdutil: extract file changes closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents:
10055
diff
changeset
|
521 |
28539
119702a8b415
templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
522 @templatekeyword('files') |
10260
fe699ca08a45
templatekw: fix extras, manifest and showlist args (issue1989)
Patrick Mezard <pmezard@gmail.com>
parents:
10060
diff
changeset
|
523 def showfiles(**args): |
28539
119702a8b415
templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
524 """List of strings. All files modified, added, or removed by this |
13585
2e80d495592a
templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents:
13386
diff
changeset
|
525 changeset. |
2e80d495592a
templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents:
13386
diff
changeset
|
526 """ |
32972
26e710f0468f
py3: convert keys of kwargs in template keywords functions to bytes
Pulkit Goyal <7895pulkit@gmail.com>
parents:
32970
diff
changeset
|
527 args = pycompat.byteskwargs(args) |
32037
e5eab0fe69ee
templatekw: have showlist() take mapping dict with no **kwargs expansion (API)
Yuya Nishihara <yuya@tcha.org>
parents:
32036
diff
changeset
|
528 return showlist('file', args['ctx'].files(), args) |
10054
1a85861f59af
cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents:
10053
diff
changeset
|
529 |
28539
119702a8b415
templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
530 @templatekeyword('graphnode') |
27214
60af96494a76
graphlog: extract "graphnode" template keyword that represents node symbol
Yuya Nishihara <yuya@tcha.org>
parents:
26486
diff
changeset
|
531 def showgraphnode(repo, ctx, **args): |
34656
eb7fffdc6e5b
help: fix formatting of template keywords
Yuya Nishihara <yuya@tcha.org>
parents:
34581
diff
changeset
|
532 """String. The character representing the changeset node in an ASCII |
eb7fffdc6e5b
help: fix formatting of template keywords
Yuya Nishihara <yuya@tcha.org>
parents:
34581
diff
changeset
|
533 revision graph.""" |
27215
5b8da5643a8a
templatekw: avoid slow creation of changectx objects in showgraphnode()
Yuya Nishihara <yuya@tcha.org>
parents:
27214
diff
changeset
|
534 wpnodes = repo.dirstate.parents() |
5b8da5643a8a
templatekw: avoid slow creation of changectx objects in showgraphnode()
Yuya Nishihara <yuya@tcha.org>
parents:
27214
diff
changeset
|
535 if wpnodes[1] == nullid: |
5b8da5643a8a
templatekw: avoid slow creation of changectx objects in showgraphnode()
Yuya Nishihara <yuya@tcha.org>
parents:
27214
diff
changeset
|
536 wpnodes = wpnodes[:1] |
27214
60af96494a76
graphlog: extract "graphnode" template keyword that represents node symbol
Yuya Nishihara <yuya@tcha.org>
parents:
26486
diff
changeset
|
537 if ctx.node() in wpnodes: |
60af96494a76
graphlog: extract "graphnode" template keyword that represents node symbol
Yuya Nishihara <yuya@tcha.org>
parents:
26486
diff
changeset
|
538 return '@' |
60af96494a76
graphlog: extract "graphnode" template keyword that represents node symbol
Yuya Nishihara <yuya@tcha.org>
parents:
26486
diff
changeset
|
539 elif ctx.obsolete(): |
60af96494a76
graphlog: extract "graphnode" template keyword that represents node symbol
Yuya Nishihara <yuya@tcha.org>
parents:
26486
diff
changeset
|
540 return 'x' |
35508
9b3f95d9783d
graphlog: add another graph node type, unstable, using character "*" (BC)
Anton Shestakov <av6@dwimlabs.net>
parents:
35212
diff
changeset
|
541 elif ctx.isunstable(): |
9b3f95d9783d
graphlog: add another graph node type, unstable, using character "*" (BC)
Anton Shestakov <av6@dwimlabs.net>
parents:
35212
diff
changeset
|
542 return '*' |
27214
60af96494a76
graphlog: extract "graphnode" template keyword that represents node symbol
Yuya Nishihara <yuya@tcha.org>
parents:
26486
diff
changeset
|
543 elif ctx.closesbranch(): |
60af96494a76
graphlog: extract "graphnode" template keyword that represents node symbol
Yuya Nishihara <yuya@tcha.org>
parents:
26486
diff
changeset
|
544 return '_' |
60af96494a76
graphlog: extract "graphnode" template keyword that represents node symbol
Yuya Nishihara <yuya@tcha.org>
parents:
26486
diff
changeset
|
545 else: |
60af96494a76
graphlog: extract "graphnode" template keyword that represents node symbol
Yuya Nishihara <yuya@tcha.org>
parents:
26486
diff
changeset
|
546 return 'o' |
60af96494a76
graphlog: extract "graphnode" template keyword that represents node symbol
Yuya Nishihara <yuya@tcha.org>
parents:
26486
diff
changeset
|
547 |
33858
6f6c87888b22
log: add a "graphwidth" template variable
Danny Hooper <hooper@google.com>
parents:
33851
diff
changeset
|
548 @templatekeyword('graphwidth') |
6f6c87888b22
log: add a "graphwidth" template variable
Danny Hooper <hooper@google.com>
parents:
33851
diff
changeset
|
549 def showgraphwidth(repo, ctx, templ, **args): |
6f6c87888b22
log: add a "graphwidth" template variable
Danny Hooper <hooper@google.com>
parents:
33851
diff
changeset
|
550 """Integer. The width of the graph drawn by 'log --graph' or zero.""" |
6f6c87888b22
log: add a "graphwidth" template variable
Danny Hooper <hooper@google.com>
parents:
33851
diff
changeset
|
551 # The value args['graphwidth'] will be this function, so we use an internal |
6f6c87888b22
log: add a "graphwidth" template variable
Danny Hooper <hooper@google.com>
parents:
33851
diff
changeset
|
552 # name to pass the value through props into this function. |
6f6c87888b22
log: add a "graphwidth" template variable
Danny Hooper <hooper@google.com>
parents:
33851
diff
changeset
|
553 return args.get('_graphwidth', 0) |
6f6c87888b22
log: add a "graphwidth" template variable
Danny Hooper <hooper@google.com>
parents:
33851
diff
changeset
|
554 |
31807
e6eb86b154c5
templater: provide loop counter as "index" keyword
Yuya Nishihara <yuya@tcha.org>
parents:
31699
diff
changeset
|
555 @templatekeyword('index') |
e6eb86b154c5
templater: provide loop counter as "index" keyword
Yuya Nishihara <yuya@tcha.org>
parents:
31699
diff
changeset
|
556 def showindex(**args): |
e6eb86b154c5
templater: provide loop counter as "index" keyword
Yuya Nishihara <yuya@tcha.org>
parents:
31699
diff
changeset
|
557 """Integer. The current iteration of the loop. (0 indexed)""" |
e6eb86b154c5
templater: provide loop counter as "index" keyword
Yuya Nishihara <yuya@tcha.org>
parents:
31699
diff
changeset
|
558 # just hosts documentation; should be overridden by template mapping |
e6eb86b154c5
templater: provide loop counter as "index" keyword
Yuya Nishihara <yuya@tcha.org>
parents:
31699
diff
changeset
|
559 raise error.Abort(_("can't use index in this context")) |
e6eb86b154c5
templater: provide loop counter as "index" keyword
Yuya Nishihara <yuya@tcha.org>
parents:
31699
diff
changeset
|
560 |
28539
119702a8b415
templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
561 @templatekeyword('latesttag') |
25727
b8245386ab40
templatekw: make {latesttag} a hybrid list
Matt Harbison <matt_harbison@yahoo.com>
parents:
25726
diff
changeset
|
562 def showlatesttag(**args): |
28539
119702a8b415
templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
563 """List of strings. The global tags on the most recent globally |
31850
f0d719e513fc
templatekw: clarify the result of {latesttag} when no tag exists
Matt Harbison <matt_harbison@yahoo.com>
parents:
31807
diff
changeset
|
564 tagged ancestor of this changeset. If no such tags exist, the list |
f0d719e513fc
templatekw: clarify the result of {latesttag} when no tag exists
Matt Harbison <matt_harbison@yahoo.com>
parents:
31807
diff
changeset
|
565 consists of the single string "null". |
13585
2e80d495592a
templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents:
13386
diff
changeset
|
566 """ |
26486
8a732c322ca7
templatekw: add {changes}, {distance} and {tag} to the {latesttag} keyword
Matt Harbison <matt_harbison@yahoo.com>
parents:
26484
diff
changeset
|
567 return showlatesttags(None, **args) |
10057
babc00a82c5e
cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents:
10056
diff
changeset
|
568 |
26484
93c80e7ed8c8
templatekw: introduce showlatesttags() to handle {latesttag} keywords
Matt Harbison <matt_harbison@yahoo.com>
parents:
26483
diff
changeset
|
569 def showlatesttags(pattern, **args): |
93c80e7ed8c8
templatekw: introduce showlatesttags() to handle {latesttag} keywords
Matt Harbison <matt_harbison@yahoo.com>
parents:
26483
diff
changeset
|
570 """helper method for the latesttag keyword and function""" |
32972
26e710f0468f
py3: convert keys of kwargs in template keywords functions to bytes
Pulkit Goyal <7895pulkit@gmail.com>
parents:
32970
diff
changeset
|
571 args = pycompat.byteskwargs(args) |
26484
93c80e7ed8c8
templatekw: introduce showlatesttags() to handle {latesttag} keywords
Matt Harbison <matt_harbison@yahoo.com>
parents:
26483
diff
changeset
|
572 repo, ctx = args['repo'], args['ctx'] |
93c80e7ed8c8
templatekw: introduce showlatesttags() to handle {latesttag} keywords
Matt Harbison <matt_harbison@yahoo.com>
parents:
26483
diff
changeset
|
573 cache = args['cache'] |
93c80e7ed8c8
templatekw: introduce showlatesttags() to handle {latesttag} keywords
Matt Harbison <matt_harbison@yahoo.com>
parents:
26483
diff
changeset
|
574 latesttags = getlatesttags(repo, ctx, cache, pattern) |
93c80e7ed8c8
templatekw: introduce showlatesttags() to handle {latesttag} keywords
Matt Harbison <matt_harbison@yahoo.com>
parents:
26483
diff
changeset
|
575 |
93c80e7ed8c8
templatekw: introduce showlatesttags() to handle {latesttag} keywords
Matt Harbison <matt_harbison@yahoo.com>
parents:
26483
diff
changeset
|
576 # latesttag[0] is an implementation detail for sorting csets on different |
93c80e7ed8c8
templatekw: introduce showlatesttags() to handle {latesttag} keywords
Matt Harbison <matt_harbison@yahoo.com>
parents:
26483
diff
changeset
|
577 # branches in a stable manner- it is the date the tagged cset was created, |
93c80e7ed8c8
templatekw: introduce showlatesttags() to handle {latesttag} keywords
Matt Harbison <matt_harbison@yahoo.com>
parents:
26483
diff
changeset
|
578 # not the date the tag was created. Therefore it isn't made visible here. |
93c80e7ed8c8
templatekw: introduce showlatesttags() to handle {latesttag} keywords
Matt Harbison <matt_harbison@yahoo.com>
parents:
26483
diff
changeset
|
579 makemap = lambda v: { |
93c80e7ed8c8
templatekw: introduce showlatesttags() to handle {latesttag} keywords
Matt Harbison <matt_harbison@yahoo.com>
parents:
26483
diff
changeset
|
580 'changes': _showchangessincetag, |
93c80e7ed8c8
templatekw: introduce showlatesttags() to handle {latesttag} keywords
Matt Harbison <matt_harbison@yahoo.com>
parents:
26483
diff
changeset
|
581 'distance': latesttags[1], |
93c80e7ed8c8
templatekw: introduce showlatesttags() to handle {latesttag} keywords
Matt Harbison <matt_harbison@yahoo.com>
parents:
26483
diff
changeset
|
582 'latesttag': v, # BC with {latesttag % '{latesttag}'} |
93c80e7ed8c8
templatekw: introduce showlatesttags() to handle {latesttag} keywords
Matt Harbison <matt_harbison@yahoo.com>
parents:
26483
diff
changeset
|
583 'tag': v |
93c80e7ed8c8
templatekw: introduce showlatesttags() to handle {latesttag} keywords
Matt Harbison <matt_harbison@yahoo.com>
parents:
26483
diff
changeset
|
584 } |
93c80e7ed8c8
templatekw: introduce showlatesttags() to handle {latesttag} keywords
Matt Harbison <matt_harbison@yahoo.com>
parents:
26483
diff
changeset
|
585 |
93c80e7ed8c8
templatekw: introduce showlatesttags() to handle {latesttag} keywords
Matt Harbison <matt_harbison@yahoo.com>
parents:
26483
diff
changeset
|
586 tags = latesttags[2] |
32036
8bcc8c9b4e9f
templatekw: change _showlist() to take mapping dict with no **kwargs expansion
Yuya Nishihara <yuya@tcha.org>
parents:
32035
diff
changeset
|
587 f = _showlist('latesttag', tags, args, separator=':') |
34328
dd28b1f55eb8
templatekw: just pass underlying value (or key) to joinfmt() function
Yuya Nishihara <yuya@tcha.org>
parents:
34327
diff
changeset
|
588 return _hybrid(f, tags, makemap, pycompat.identity) |
26484
93c80e7ed8c8
templatekw: introduce showlatesttags() to handle {latesttag} keywords
Matt Harbison <matt_harbison@yahoo.com>
parents:
26483
diff
changeset
|
589 |
28539
119702a8b415
templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
590 @templatekeyword('latesttagdistance') |
10057
babc00a82c5e
cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents:
10056
diff
changeset
|
591 def showlatesttagdistance(repo, ctx, templ, cache, **args): |
28539
119702a8b415
templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
592 """Integer. Longest path to the latest tag.""" |
10057
babc00a82c5e
cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents:
10056
diff
changeset
|
593 return getlatesttags(repo, ctx, cache)[1] |
babc00a82c5e
cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents:
10056
diff
changeset
|
594 |
28539
119702a8b415
templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
595 @templatekeyword('changessincelatesttag') |
25724
4474a750413f
templatekw: introduce the changessincelatesttag keyword
Matt Harbison <matt_harbison@yahoo.com>
parents:
25700
diff
changeset
|
596 def showchangessincelatesttag(repo, ctx, templ, cache, **args): |
28539
119702a8b415
templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
597 """Integer. All ancestors not in the latest tag.""" |
25724
4474a750413f
templatekw: introduce the changessincelatesttag keyword
Matt Harbison <matt_harbison@yahoo.com>
parents:
25700
diff
changeset
|
598 latesttag = getlatesttags(repo, ctx, cache)[2][0] |
26483
e94f93043a4e
templatekw: factor out the changessincetag calculation to a private method
Matt Harbison <matt_harbison@yahoo.com>
parents:
26482
diff
changeset
|
599 |
e94f93043a4e
templatekw: factor out the changessincetag calculation to a private method
Matt Harbison <matt_harbison@yahoo.com>
parents:
26482
diff
changeset
|
600 return _showchangessincetag(repo, ctx, tag=latesttag, **args) |
e94f93043a4e
templatekw: factor out the changessincetag calculation to a private method
Matt Harbison <matt_harbison@yahoo.com>
parents:
26482
diff
changeset
|
601 |
e94f93043a4e
templatekw: factor out the changessincetag calculation to a private method
Matt Harbison <matt_harbison@yahoo.com>
parents:
26482
diff
changeset
|
602 def _showchangessincetag(repo, ctx, **args): |
25724
4474a750413f
templatekw: introduce the changessincelatesttag keyword
Matt Harbison <matt_harbison@yahoo.com>
parents:
25700
diff
changeset
|
603 offset = 0 |
4474a750413f
templatekw: introduce the changessincelatesttag keyword
Matt Harbison <matt_harbison@yahoo.com>
parents:
25700
diff
changeset
|
604 revs = [ctx.rev()] |
32973
20ca19e6c74e
py3: use r'' to access values from kwargs where keys are str
Pulkit Goyal <7895pulkit@gmail.com>
parents:
32972
diff
changeset
|
605 tag = args[r'tag'] |
25724
4474a750413f
templatekw: introduce the changessincelatesttag keyword
Matt Harbison <matt_harbison@yahoo.com>
parents:
25700
diff
changeset
|
606 |
4474a750413f
templatekw: introduce the changessincelatesttag keyword
Matt Harbison <matt_harbison@yahoo.com>
parents:
25700
diff
changeset
|
607 # The only() revset doesn't currently support wdir() |
4474a750413f
templatekw: introduce the changessincelatesttag keyword
Matt Harbison <matt_harbison@yahoo.com>
parents:
25700
diff
changeset
|
608 if ctx.rev() is None: |
4474a750413f
templatekw: introduce the changessincelatesttag keyword
Matt Harbison <matt_harbison@yahoo.com>
parents:
25700
diff
changeset
|
609 offset = 1 |
4474a750413f
templatekw: introduce the changessincelatesttag keyword
Matt Harbison <matt_harbison@yahoo.com>
parents:
25700
diff
changeset
|
610 revs = [p.rev() for p in ctx.parents()] |
4474a750413f
templatekw: introduce the changessincelatesttag keyword
Matt Harbison <matt_harbison@yahoo.com>
parents:
25700
diff
changeset
|
611 |
26483
e94f93043a4e
templatekw: factor out the changessincetag calculation to a private method
Matt Harbison <matt_harbison@yahoo.com>
parents:
26482
diff
changeset
|
612 return len(repo.revs('only(%ld, %s)', revs, tag)) + offset |
25724
4474a750413f
templatekw: introduce the changessincelatesttag keyword
Matt Harbison <matt_harbison@yahoo.com>
parents:
25700
diff
changeset
|
613 |
28539
119702a8b415
templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
614 @templatekeyword('manifest') |
10260
fe699ca08a45
templatekw: fix extras, manifest and showlist args (issue1989)
Patrick Mezard <pmezard@gmail.com>
parents:
10060
diff
changeset
|
615 def showmanifest(**args): |
32973
20ca19e6c74e
py3: use r'' to access values from kwargs where keys are str
Pulkit Goyal <7895pulkit@gmail.com>
parents:
32972
diff
changeset
|
616 repo, ctx, templ = args[r'repo'], args[r'ctx'], args[r'templ'] |
24676
13c42a883e8b
templatekw: have {manifest} use ctx.manifestnode() for consistency
Yuya Nishihara <yuya@tcha.org>
parents:
24337
diff
changeset
|
617 mnode = ctx.manifestnode() |
25736
8854ca3fa675
templatekw: apply manifest template only if ctx.manifestnode() exists
Yuya Nishihara <yuya@tcha.org>
parents:
25727
diff
changeset
|
618 if mnode is None: |
8854ca3fa675
templatekw: apply manifest template only if ctx.manifestnode() exists
Yuya Nishihara <yuya@tcha.org>
parents:
25727
diff
changeset
|
619 # just avoid crash, we might want to use the 'ff...' hash in future |
8854ca3fa675
templatekw: apply manifest template only if ctx.manifestnode() exists
Yuya Nishihara <yuya@tcha.org>
parents:
25727
diff
changeset
|
620 return |
34330
89aec1834a86
templatekw: add new-style template expansion to {manifest}
Yuya Nishihara <yuya@tcha.org>
parents:
34328
diff
changeset
|
621 mrev = repo.manifestlog._revlog.rev(mnode) |
89aec1834a86
templatekw: add new-style template expansion to {manifest}
Yuya Nishihara <yuya@tcha.org>
parents:
34328
diff
changeset
|
622 mhex = hex(mnode) |
10055
e400a511e63a
cmdutil: extract repo dependent closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents:
10054
diff
changeset
|
623 args = args.copy() |
34330
89aec1834a86
templatekw: add new-style template expansion to {manifest}
Yuya Nishihara <yuya@tcha.org>
parents:
34328
diff
changeset
|
624 args.update({r'rev': mrev, r'node': mhex}) |
89aec1834a86
templatekw: add new-style template expansion to {manifest}
Yuya Nishihara <yuya@tcha.org>
parents:
34328
diff
changeset
|
625 f = templ('manifest', **args) |
89aec1834a86
templatekw: add new-style template expansion to {manifest}
Yuya Nishihara <yuya@tcha.org>
parents:
34328
diff
changeset
|
626 # TODO: perhaps 'ctx' should be dropped from mapping because manifest |
89aec1834a86
templatekw: add new-style template expansion to {manifest}
Yuya Nishihara <yuya@tcha.org>
parents:
34328
diff
changeset
|
627 # rev and node are completely different from changeset's. |
34534
b3073e175c17
templater: wrap get/min/max result so map operation can apply to element
Yuya Nishihara <yuya@tcha.org>
parents:
34425
diff
changeset
|
628 return _mappable(f, None, f, lambda x: {'rev': mrev, 'node': mhex}) |
10055
e400a511e63a
cmdutil: extract repo dependent closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents:
10054
diff
changeset
|
629 |
34847
e27f1f04c2cf
templatekw: introduce obsfate keyword
Boris Feld <boris.feld@octobus.net>
parents:
34657
diff
changeset
|
630 @templatekeyword('obsfate') |
e27f1f04c2cf
templatekw: introduce obsfate keyword
Boris Feld <boris.feld@octobus.net>
parents:
34657
diff
changeset
|
631 def showobsfate(**args): |
e27f1f04c2cf
templatekw: introduce obsfate keyword
Boris Feld <boris.feld@octobus.net>
parents:
34657
diff
changeset
|
632 # this function returns a list containing pre-formatted obsfate strings. |
e27f1f04c2cf
templatekw: introduce obsfate keyword
Boris Feld <boris.feld@octobus.net>
parents:
34657
diff
changeset
|
633 # |
e27f1f04c2cf
templatekw: introduce obsfate keyword
Boris Feld <boris.feld@octobus.net>
parents:
34657
diff
changeset
|
634 # This function will be replaced by templates fragments when we will have |
e27f1f04c2cf
templatekw: introduce obsfate keyword
Boris Feld <boris.feld@octobus.net>
parents:
34657
diff
changeset
|
635 # the verbosity templatekw available. |
e27f1f04c2cf
templatekw: introduce obsfate keyword
Boris Feld <boris.feld@octobus.net>
parents:
34657
diff
changeset
|
636 succsandmarkers = showsuccsandmarkers(**args) |
e27f1f04c2cf
templatekw: introduce obsfate keyword
Boris Feld <boris.feld@octobus.net>
parents:
34657
diff
changeset
|
637 |
35143
6fe99a8e266d
py3: fix args handling for obsfate template
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34993
diff
changeset
|
638 args = pycompat.byteskwargs(args) |
34847
e27f1f04c2cf
templatekw: introduce obsfate keyword
Boris Feld <boris.feld@octobus.net>
parents:
34657
diff
changeset
|
639 ui = args['ui'] |
e27f1f04c2cf
templatekw: introduce obsfate keyword
Boris Feld <boris.feld@octobus.net>
parents:
34657
diff
changeset
|
640 |
e27f1f04c2cf
templatekw: introduce obsfate keyword
Boris Feld <boris.feld@octobus.net>
parents:
34657
diff
changeset
|
641 values = [] |
e27f1f04c2cf
templatekw: introduce obsfate keyword
Boris Feld <boris.feld@octobus.net>
parents:
34657
diff
changeset
|
642 |
e27f1f04c2cf
templatekw: introduce obsfate keyword
Boris Feld <boris.feld@octobus.net>
parents:
34657
diff
changeset
|
643 for x in succsandmarkers: |
e27f1f04c2cf
templatekw: introduce obsfate keyword
Boris Feld <boris.feld@octobus.net>
parents:
34657
diff
changeset
|
644 values.append(obsutil.obsfateprinter(x['successors'], x['markers'], ui)) |
e27f1f04c2cf
templatekw: introduce obsfate keyword
Boris Feld <boris.feld@octobus.net>
parents:
34657
diff
changeset
|
645 |
e27f1f04c2cf
templatekw: introduce obsfate keyword
Boris Feld <boris.feld@octobus.net>
parents:
34657
diff
changeset
|
646 return showlist("fate", values, args) |
e27f1f04c2cf
templatekw: introduce obsfate keyword
Boris Feld <boris.feld@octobus.net>
parents:
34657
diff
changeset
|
647 |
27893
b42b2e86ef02
templatekw: move shownames() helper to be sorted alphabetically
Yuya Nishihara <yuya@tcha.org>
parents:
27891
diff
changeset
|
648 def shownames(namespace, **args): |
b42b2e86ef02
templatekw: move shownames() helper to be sorted alphabetically
Yuya Nishihara <yuya@tcha.org>
parents:
27891
diff
changeset
|
649 """helper method to generate a template keyword for a namespace""" |
32972
26e710f0468f
py3: convert keys of kwargs in template keywords functions to bytes
Pulkit Goyal <7895pulkit@gmail.com>
parents:
32970
diff
changeset
|
650 args = pycompat.byteskwargs(args) |
27893
b42b2e86ef02
templatekw: move shownames() helper to be sorted alphabetically
Yuya Nishihara <yuya@tcha.org>
parents:
27891
diff
changeset
|
651 ctx = args['ctx'] |
b42b2e86ef02
templatekw: move shownames() helper to be sorted alphabetically
Yuya Nishihara <yuya@tcha.org>
parents:
27891
diff
changeset
|
652 repo = ctx.repo() |
b42b2e86ef02
templatekw: move shownames() helper to be sorted alphabetically
Yuya Nishihara <yuya@tcha.org>
parents:
27891
diff
changeset
|
653 ns = repo.names[namespace] |
b42b2e86ef02
templatekw: move shownames() helper to be sorted alphabetically
Yuya Nishihara <yuya@tcha.org>
parents:
27891
diff
changeset
|
654 names = ns.names(repo, ctx.node()) |
32037
e5eab0fe69ee
templatekw: have showlist() take mapping dict with no **kwargs expansion (API)
Yuya Nishihara <yuya@tcha.org>
parents:
32036
diff
changeset
|
655 return showlist(ns.templatename, names, args, plural=namespace) |
27893
b42b2e86ef02
templatekw: move shownames() helper to be sorted alphabetically
Yuya Nishihara <yuya@tcha.org>
parents:
27891
diff
changeset
|
656 |
28539
119702a8b415
templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
657 @templatekeyword('namespaces') |
27894
a94f7eef3199
templatekw: add {namespaces} keyword
Yuya Nishihara <yuya@tcha.org>
parents:
27893
diff
changeset
|
658 def shownamespaces(**args): |
28539
119702a8b415
templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
659 """Dict of lists. Names attached to this changeset per |
27894
a94f7eef3199
templatekw: add {namespaces} keyword
Yuya Nishihara <yuya@tcha.org>
parents:
27893
diff
changeset
|
660 namespace.""" |
32972
26e710f0468f
py3: convert keys of kwargs in template keywords functions to bytes
Pulkit Goyal <7895pulkit@gmail.com>
parents:
32970
diff
changeset
|
661 args = pycompat.byteskwargs(args) |
27894
a94f7eef3199
templatekw: add {namespaces} keyword
Yuya Nishihara <yuya@tcha.org>
parents:
27893
diff
changeset
|
662 ctx = args['ctx'] |
a94f7eef3199
templatekw: add {namespaces} keyword
Yuya Nishihara <yuya@tcha.org>
parents:
27893
diff
changeset
|
663 repo = ctx.repo() |
33047
de8e3681c402
templatekw: expose color name in {namespaces} entries
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33017
diff
changeset
|
664 |
de8e3681c402
templatekw: expose color name in {namespaces} entries
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33017
diff
changeset
|
665 namespaces = util.sortdict() |
34541
0a0a72c043ac
templatekw: allow accessing to nested namespace item by its template name
Yuya Nishihara <yuya@tcha.org>
parents:
34540
diff
changeset
|
666 def makensmapfn(ns): |
0a0a72c043ac
templatekw: allow accessing to nested namespace item by its template name
Yuya Nishihara <yuya@tcha.org>
parents:
34540
diff
changeset
|
667 # 'name' for iterating over namespaces, templatename for local reference |
0a0a72c043ac
templatekw: allow accessing to nested namespace item by its template name
Yuya Nishihara <yuya@tcha.org>
parents:
34540
diff
changeset
|
668 return lambda v: {'name': v, ns.templatename: v} |
33047
de8e3681c402
templatekw: expose color name in {namespaces} entries
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33017
diff
changeset
|
669 |
de8e3681c402
templatekw: expose color name in {namespaces} entries
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33017
diff
changeset
|
670 for k, ns in repo.names.iteritems(): |
34541
0a0a72c043ac
templatekw: allow accessing to nested namespace item by its template name
Yuya Nishihara <yuya@tcha.org>
parents:
34540
diff
changeset
|
671 names = ns.names(repo, ctx.node()) |
0a0a72c043ac
templatekw: allow accessing to nested namespace item by its template name
Yuya Nishihara <yuya@tcha.org>
parents:
34540
diff
changeset
|
672 f = _showlist('name', names, args) |
0a0a72c043ac
templatekw: allow accessing to nested namespace item by its template name
Yuya Nishihara <yuya@tcha.org>
parents:
34540
diff
changeset
|
673 namespaces[k] = _hybrid(f, names, makensmapfn(ns), pycompat.identity) |
33047
de8e3681c402
templatekw: expose color name in {namespaces} entries
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33017
diff
changeset
|
674 |
32036
8bcc8c9b4e9f
templatekw: change _showlist() to take mapping dict with no **kwargs expansion
Yuya Nishihara <yuya@tcha.org>
parents:
32035
diff
changeset
|
675 f = _showlist('namespace', list(namespaces), args) |
33047
de8e3681c402
templatekw: expose color name in {namespaces} entries
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33017
diff
changeset
|
676 |
de8e3681c402
templatekw: expose color name in {namespaces} entries
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33017
diff
changeset
|
677 def makemap(ns): |
de8e3681c402
templatekw: expose color name in {namespaces} entries
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33017
diff
changeset
|
678 return { |
de8e3681c402
templatekw: expose color name in {namespaces} entries
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33017
diff
changeset
|
679 'namespace': ns, |
de8e3681c402
templatekw: expose color name in {namespaces} entries
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33017
diff
changeset
|
680 'names': namespaces[ns], |
34540
1c7c4445686f
templatekw: get rid of temporary dicts from shownamespaces()
Yuya Nishihara <yuya@tcha.org>
parents:
34539
diff
changeset
|
681 'builtin': repo.names[ns].builtin, |
1c7c4445686f
templatekw: get rid of temporary dicts from shownamespaces()
Yuya Nishihara <yuya@tcha.org>
parents:
34539
diff
changeset
|
682 'colorname': repo.names[ns].colorname, |
33047
de8e3681c402
templatekw: expose color name in {namespaces} entries
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33017
diff
changeset
|
683 } |
de8e3681c402
templatekw: expose color name in {namespaces} entries
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33017
diff
changeset
|
684 |
34328
dd28b1f55eb8
templatekw: just pass underlying value (or key) to joinfmt() function
Yuya Nishihara <yuya@tcha.org>
parents:
34327
diff
changeset
|
685 return _hybrid(f, namespaces, makemap, pycompat.identity) |
27894
a94f7eef3199
templatekw: add {namespaces} keyword
Yuya Nishihara <yuya@tcha.org>
parents:
27893
diff
changeset
|
686 |
28539
119702a8b415
templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
687 @templatekeyword('node') |
10055
e400a511e63a
cmdutil: extract repo dependent closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents:
10054
diff
changeset
|
688 def shownode(repo, ctx, templ, **args): |
28539
119702a8b415
templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
689 """String. The changeset identification hash, as a 40 hexadecimal |
13585
2e80d495592a
templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents:
13386
diff
changeset
|
690 digit string. |
2e80d495592a
templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents:
13386
diff
changeset
|
691 """ |
10054
1a85861f59af
cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents:
10053
diff
changeset
|
692 return ctx.hex() |
1a85861f59af
cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents:
10053
diff
changeset
|
693 |
31699
568c4e7437b2
templatekw: add an "obsolete" keyword
Denis Laxalde <denis@laxalde.org>
parents:
31452
diff
changeset
|
694 @templatekeyword('obsolete') |
568c4e7437b2
templatekw: add an "obsolete" keyword
Denis Laxalde <denis@laxalde.org>
parents:
31452
diff
changeset
|
695 def showobsolete(repo, ctx, templ, **args): |
34657
bfb6fd93b637
help: hide template keywords of obsolescence as they are still experimental
Yuya Nishihara <yuya@tcha.org>
parents:
34656
diff
changeset
|
696 """String. Whether the changeset is obsolete. (EXPERIMENTAL)""" |
31699
568c4e7437b2
templatekw: add an "obsolete" keyword
Denis Laxalde <denis@laxalde.org>
parents:
31452
diff
changeset
|
697 if ctx.obsolete(): |
568c4e7437b2
templatekw: add an "obsolete" keyword
Denis Laxalde <denis@laxalde.org>
parents:
31452
diff
changeset
|
698 return 'obsolete' |
568c4e7437b2
templatekw: add an "obsolete" keyword
Denis Laxalde <denis@laxalde.org>
parents:
31452
diff
changeset
|
699 return '' |
568c4e7437b2
templatekw: add an "obsolete" keyword
Denis Laxalde <denis@laxalde.org>
parents:
31452
diff
changeset
|
700 |
34539
f30e59703d98
templatekw: rename peerpaths to peerurls per naming convention (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
34538
diff
changeset
|
701 @templatekeyword('peerurls') |
f30e59703d98
templatekw: rename peerpaths to peerurls per naming convention (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
34538
diff
changeset
|
702 def showpeerurls(repo, **args): |
33414
16ed67164002
templatekw: export ui.paths as {peerpaths}
Yuya Nishihara <yuya@tcha.org>
parents:
33276
diff
changeset
|
703 """A dictionary of repository locations defined in the [paths] section |
34539
f30e59703d98
templatekw: rename peerpaths to peerurls per naming convention (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
34538
diff
changeset
|
704 of your configuration file.""" |
33414
16ed67164002
templatekw: export ui.paths as {peerpaths}
Yuya Nishihara <yuya@tcha.org>
parents:
33276
diff
changeset
|
705 # see commands.paths() for naming of dictionary keys |
34538
ac38e889b33a
templatekw: make experimental {peerpaths} return a single-level dict (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
34537
diff
changeset
|
706 paths = repo.ui.paths |
ac38e889b33a
templatekw: make experimental {peerpaths} return a single-level dict (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
34537
diff
changeset
|
707 urls = util.sortdict((k, p.rawloc) for k, p in sorted(paths.iteritems())) |
ac38e889b33a
templatekw: make experimental {peerpaths} return a single-level dict (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
34537
diff
changeset
|
708 def makemap(k): |
ac38e889b33a
templatekw: make experimental {peerpaths} return a single-level dict (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
34537
diff
changeset
|
709 p = paths[k] |
ac38e889b33a
templatekw: make experimental {peerpaths} return a single-level dict (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
34537
diff
changeset
|
710 d = {'name': k, 'url': p.rawloc} |
33414
16ed67164002
templatekw: export ui.paths as {peerpaths}
Yuya Nishihara <yuya@tcha.org>
parents:
33276
diff
changeset
|
711 d.update((o, v) for o, v in sorted(p.suboptions.iteritems())) |
34538
ac38e889b33a
templatekw: make experimental {peerpaths} return a single-level dict (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
34537
diff
changeset
|
712 return d |
ac38e889b33a
templatekw: make experimental {peerpaths} return a single-level dict (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
34537
diff
changeset
|
713 return _hybrid(None, urls, makemap, lambda k: '%s=%s' % (k, urls[k])) |
33414
16ed67164002
templatekw: export ui.paths as {peerpaths}
Yuya Nishihara <yuya@tcha.org>
parents:
33276
diff
changeset
|
714 |
32879
1858fc2327ef
template: add predecessors template
Boris Feld <boris.feld@octobus.net>
parents:
32658
diff
changeset
|
715 @templatekeyword("predecessors") |
1858fc2327ef
template: add predecessors template
Boris Feld <boris.feld@octobus.net>
parents:
32658
diff
changeset
|
716 def showpredecessors(repo, ctx, **args): |
34657
bfb6fd93b637
help: hide template keywords of obsolescence as they are still experimental
Yuya Nishihara <yuya@tcha.org>
parents:
34656
diff
changeset
|
717 """Returns the list if the closest visible successors. (EXPERIMENTAL)""" |
32879
1858fc2327ef
template: add predecessors template
Boris Feld <boris.feld@octobus.net>
parents:
32658
diff
changeset
|
718 predecessors = sorted(obsutil.closestpredecessors(repo, ctx.node())) |
1858fc2327ef
template: add predecessors template
Boris Feld <boris.feld@octobus.net>
parents:
32658
diff
changeset
|
719 predecessors = map(hex, predecessors) |
1858fc2327ef
template: add predecessors template
Boris Feld <boris.feld@octobus.net>
parents:
32658
diff
changeset
|
720 |
32910
498e9dcc5fa9
templatekw: populate all keywords depending on predecessor in map operation
Yuya Nishihara <yuya@tcha.org>
parents:
32909
diff
changeset
|
721 return _hybrid(None, predecessors, |
498e9dcc5fa9
templatekw: populate all keywords depending on predecessor in map operation
Yuya Nishihara <yuya@tcha.org>
parents:
32909
diff
changeset
|
722 lambda x: {'ctx': repo[x], 'revcache': {}}, |
34328
dd28b1f55eb8
templatekw: just pass underlying value (or key) to joinfmt() function
Yuya Nishihara <yuya@tcha.org>
parents:
34327
diff
changeset
|
723 lambda x: scmutil.formatchangeid(repo[x])) |
32879
1858fc2327ef
template: add predecessors template
Boris Feld <boris.feld@octobus.net>
parents:
32658
diff
changeset
|
724 |
33276
89796a25d4bb
template: add successors template
Boris Feld <boris.feld@octobus.net>
parents:
33048
diff
changeset
|
725 @templatekeyword("successorssets") |
89796a25d4bb
template: add successors template
Boris Feld <boris.feld@octobus.net>
parents:
33048
diff
changeset
|
726 def showsuccessorssets(repo, ctx, **args): |
34656
eb7fffdc6e5b
help: fix formatting of template keywords
Yuya Nishihara <yuya@tcha.org>
parents:
34581
diff
changeset
|
727 """Returns a string of sets of successors for a changectx. Format used |
eb7fffdc6e5b
help: fix formatting of template keywords
Yuya Nishihara <yuya@tcha.org>
parents:
34581
diff
changeset
|
728 is: [ctx1, ctx2], [ctx3] if ctx has been splitted into ctx1 and ctx2 |
34657
bfb6fd93b637
help: hide template keywords of obsolescence as they are still experimental
Yuya Nishihara <yuya@tcha.org>
parents:
34656
diff
changeset
|
729 while also diverged into ctx3. (EXPERIMENTAL)""" |
33276
89796a25d4bb
template: add successors template
Boris Feld <boris.feld@octobus.net>
parents:
33048
diff
changeset
|
730 if not ctx.obsolete(): |
89796a25d4bb
template: add successors template
Boris Feld <boris.feld@octobus.net>
parents:
33048
diff
changeset
|
731 return '' |
89796a25d4bb
template: add successors template
Boris Feld <boris.feld@octobus.net>
parents:
33048
diff
changeset
|
732 args = pycompat.byteskwargs(args) |
89796a25d4bb
template: add successors template
Boris Feld <boris.feld@octobus.net>
parents:
33048
diff
changeset
|
733 |
89796a25d4bb
template: add successors template
Boris Feld <boris.feld@octobus.net>
parents:
33048
diff
changeset
|
734 ssets = obsutil.successorssets(repo, ctx.node(), closest=True) |
89796a25d4bb
template: add successors template
Boris Feld <boris.feld@octobus.net>
parents:
33048
diff
changeset
|
735 ssets = [[hex(n) for n in ss] for ss in ssets] |
89796a25d4bb
template: add successors template
Boris Feld <boris.feld@octobus.net>
parents:
33048
diff
changeset
|
736 |
89796a25d4bb
template: add successors template
Boris Feld <boris.feld@octobus.net>
parents:
33048
diff
changeset
|
737 data = [] |
89796a25d4bb
template: add successors template
Boris Feld <boris.feld@octobus.net>
parents:
33048
diff
changeset
|
738 for ss in ssets: |
89796a25d4bb
template: add successors template
Boris Feld <boris.feld@octobus.net>
parents:
33048
diff
changeset
|
739 h = _hybrid(None, ss, lambda x: {'ctx': repo[x], 'revcache': {}}, |
34328
dd28b1f55eb8
templatekw: just pass underlying value (or key) to joinfmt() function
Yuya Nishihara <yuya@tcha.org>
parents:
34327
diff
changeset
|
740 lambda x: scmutil.formatchangeid(repo[x])) |
33276
89796a25d4bb
template: add successors template
Boris Feld <boris.feld@octobus.net>
parents:
33048
diff
changeset
|
741 data.append(h) |
89796a25d4bb
template: add successors template
Boris Feld <boris.feld@octobus.net>
parents:
33048
diff
changeset
|
742 |
89796a25d4bb
template: add successors template
Boris Feld <boris.feld@octobus.net>
parents:
33048
diff
changeset
|
743 # Format the successorssets |
89796a25d4bb
template: add successors template
Boris Feld <boris.feld@octobus.net>
parents:
33048
diff
changeset
|
744 def render(d): |
89796a25d4bb
template: add successors template
Boris Feld <boris.feld@octobus.net>
parents:
33048
diff
changeset
|
745 t = [] |
34425
12bfecd0ffe6
formatter: fix default list/dict generator to be evaluated more than once
Yuya Nishihara <yuya@tcha.org>
parents:
34330
diff
changeset
|
746 for i in d.gen(): |
33276
89796a25d4bb
template: add successors template
Boris Feld <boris.feld@octobus.net>
parents:
33048
diff
changeset
|
747 t.append(i) |
89796a25d4bb
template: add successors template
Boris Feld <boris.feld@octobus.net>
parents:
33048
diff
changeset
|
748 return "".join(t) |
89796a25d4bb
template: add successors template
Boris Feld <boris.feld@octobus.net>
parents:
33048
diff
changeset
|
749 |
89796a25d4bb
template: add successors template
Boris Feld <boris.feld@octobus.net>
parents:
33048
diff
changeset
|
750 def gen(data): |
89796a25d4bb
template: add successors template
Boris Feld <boris.feld@octobus.net>
parents:
33048
diff
changeset
|
751 yield "; ".join(render(d) for d in data) |
89796a25d4bb
template: add successors template
Boris Feld <boris.feld@octobus.net>
parents:
33048
diff
changeset
|
752 |
89796a25d4bb
template: add successors template
Boris Feld <boris.feld@octobus.net>
parents:
33048
diff
changeset
|
753 return _hybrid(gen(data), data, lambda x: {'successorset': x}, |
34328
dd28b1f55eb8
templatekw: just pass underlying value (or key) to joinfmt() function
Yuya Nishihara <yuya@tcha.org>
parents:
34327
diff
changeset
|
754 pycompat.identity) |
33276
89796a25d4bb
template: add successors template
Boris Feld <boris.feld@octobus.net>
parents:
33048
diff
changeset
|
755 |
33912
e278d6d2d7d2
template: add minimal obsfate template function
Boris Feld <boris.feld@octobus.net>
parents:
33865
diff
changeset
|
756 @templatekeyword("succsandmarkers") |
e278d6d2d7d2
template: add minimal obsfate template function
Boris Feld <boris.feld@octobus.net>
parents:
33865
diff
changeset
|
757 def showsuccsandmarkers(repo, ctx, **args): |
34656
eb7fffdc6e5b
help: fix formatting of template keywords
Yuya Nishihara <yuya@tcha.org>
parents:
34581
diff
changeset
|
758 """Returns a list of dict for each final successor of ctx. The dict |
eb7fffdc6e5b
help: fix formatting of template keywords
Yuya Nishihara <yuya@tcha.org>
parents:
34581
diff
changeset
|
759 contains successors node id in "successors" keys and the list of |
eb7fffdc6e5b
help: fix formatting of template keywords
Yuya Nishihara <yuya@tcha.org>
parents:
34581
diff
changeset
|
760 obs-markers from ctx to the set of successors in "markers". |
33912
e278d6d2d7d2
template: add minimal obsfate template function
Boris Feld <boris.feld@octobus.net>
parents:
33865
diff
changeset
|
761 (EXPERIMENTAL) |
e278d6d2d7d2
template: add minimal obsfate template function
Boris Feld <boris.feld@octobus.net>
parents:
33865
diff
changeset
|
762 """ |
e278d6d2d7d2
template: add minimal obsfate template function
Boris Feld <boris.feld@octobus.net>
parents:
33865
diff
changeset
|
763 |
e278d6d2d7d2
template: add minimal obsfate template function
Boris Feld <boris.feld@octobus.net>
parents:
33865
diff
changeset
|
764 values = obsutil.successorsandmarkers(repo, ctx) |
e278d6d2d7d2
template: add minimal obsfate template function
Boris Feld <boris.feld@octobus.net>
parents:
33865
diff
changeset
|
765 |
e278d6d2d7d2
template: add minimal obsfate template function
Boris Feld <boris.feld@octobus.net>
parents:
33865
diff
changeset
|
766 if values is None: |
e278d6d2d7d2
template: add minimal obsfate template function
Boris Feld <boris.feld@octobus.net>
parents:
33865
diff
changeset
|
767 values = [] |
e278d6d2d7d2
template: add minimal obsfate template function
Boris Feld <boris.feld@octobus.net>
parents:
33865
diff
changeset
|
768 |
e278d6d2d7d2
template: add minimal obsfate template function
Boris Feld <boris.feld@octobus.net>
parents:
33865
diff
changeset
|
769 # Format successors and markers to avoid exposing binary to templates |
e278d6d2d7d2
template: add minimal obsfate template function
Boris Feld <boris.feld@octobus.net>
parents:
33865
diff
changeset
|
770 data = [] |
e278d6d2d7d2
template: add minimal obsfate template function
Boris Feld <boris.feld@octobus.net>
parents:
33865
diff
changeset
|
771 for i in values: |
e278d6d2d7d2
template: add minimal obsfate template function
Boris Feld <boris.feld@octobus.net>
parents:
33865
diff
changeset
|
772 # Format successors |
e278d6d2d7d2
template: add minimal obsfate template function
Boris Feld <boris.feld@octobus.net>
parents:
33865
diff
changeset
|
773 successors = i['successors'] |
e278d6d2d7d2
template: add minimal obsfate template function
Boris Feld <boris.feld@octobus.net>
parents:
33865
diff
changeset
|
774 |
e278d6d2d7d2
template: add minimal obsfate template function
Boris Feld <boris.feld@octobus.net>
parents:
33865
diff
changeset
|
775 successors = [hex(n) for n in successors] |
e278d6d2d7d2
template: add minimal obsfate template function
Boris Feld <boris.feld@octobus.net>
parents:
33865
diff
changeset
|
776 successors = _hybrid(None, successors, |
e278d6d2d7d2
template: add minimal obsfate template function
Boris Feld <boris.feld@octobus.net>
parents:
33865
diff
changeset
|
777 lambda x: {'ctx': repo[x], 'revcache': {}}, |
34328
dd28b1f55eb8
templatekw: just pass underlying value (or key) to joinfmt() function
Yuya Nishihara <yuya@tcha.org>
parents:
34327
diff
changeset
|
778 lambda x: scmutil.formatchangeid(repo[x])) |
33912
e278d6d2d7d2
template: add minimal obsfate template function
Boris Feld <boris.feld@octobus.net>
parents:
33865
diff
changeset
|
779 |
e278d6d2d7d2
template: add minimal obsfate template function
Boris Feld <boris.feld@octobus.net>
parents:
33865
diff
changeset
|
780 # Format markers |
e278d6d2d7d2
template: add minimal obsfate template function
Boris Feld <boris.feld@octobus.net>
parents:
33865
diff
changeset
|
781 finalmarkers = [] |
e278d6d2d7d2
template: add minimal obsfate template function
Boris Feld <boris.feld@octobus.net>
parents:
33865
diff
changeset
|
782 for m in i['markers']: |
e278d6d2d7d2
template: add minimal obsfate template function
Boris Feld <boris.feld@octobus.net>
parents:
33865
diff
changeset
|
783 hexprec = hex(m[0]) |
e278d6d2d7d2
template: add minimal obsfate template function
Boris Feld <boris.feld@octobus.net>
parents:
33865
diff
changeset
|
784 hexsucs = tuple(hex(n) for n in m[1]) |
e278d6d2d7d2
template: add minimal obsfate template function
Boris Feld <boris.feld@octobus.net>
parents:
33865
diff
changeset
|
785 hexparents = None |
e278d6d2d7d2
template: add minimal obsfate template function
Boris Feld <boris.feld@octobus.net>
parents:
33865
diff
changeset
|
786 if m[5] is not None: |
e278d6d2d7d2
template: add minimal obsfate template function
Boris Feld <boris.feld@octobus.net>
parents:
33865
diff
changeset
|
787 hexparents = tuple(hex(n) for n in m[5]) |
e278d6d2d7d2
template: add minimal obsfate template function
Boris Feld <boris.feld@octobus.net>
parents:
33865
diff
changeset
|
788 newmarker = (hexprec, hexsucs) + m[2:5] + (hexparents,) + m[6:] |
e278d6d2d7d2
template: add minimal obsfate template function
Boris Feld <boris.feld@octobus.net>
parents:
33865
diff
changeset
|
789 finalmarkers.append(newmarker) |
e278d6d2d7d2
template: add minimal obsfate template function
Boris Feld <boris.feld@octobus.net>
parents:
33865
diff
changeset
|
790 |
e278d6d2d7d2
template: add minimal obsfate template function
Boris Feld <boris.feld@octobus.net>
parents:
33865
diff
changeset
|
791 data.append({'successors': successors, 'markers': finalmarkers}) |
e278d6d2d7d2
template: add minimal obsfate template function
Boris Feld <boris.feld@octobus.net>
parents:
33865
diff
changeset
|
792 |
e278d6d2d7d2
template: add minimal obsfate template function
Boris Feld <boris.feld@octobus.net>
parents:
33865
diff
changeset
|
793 f = _showlist('succsandmarkers', data, args) |
34328
dd28b1f55eb8
templatekw: just pass underlying value (or key) to joinfmt() function
Yuya Nishihara <yuya@tcha.org>
parents:
34327
diff
changeset
|
794 return _hybrid(f, data, lambda x: x, pycompat.identity) |
33912
e278d6d2d7d2
template: add minimal obsfate template function
Boris Feld <boris.feld@octobus.net>
parents:
33865
diff
changeset
|
795 |
28539
119702a8b415
templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
796 @templatekeyword('p1rev') |
17357
bd605568c5a0
templatekw: add p1rev, p1node, p2rev, p2node keywords
epriestley <hg@yghe.net>
parents:
17187
diff
changeset
|
797 def showp1rev(repo, ctx, templ, **args): |
28539
119702a8b415
templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
798 """Integer. The repository-local revision number of the changeset's |
17357
bd605568c5a0
templatekw: add p1rev, p1node, p2rev, p2node keywords
epriestley <hg@yghe.net>
parents:
17187
diff
changeset
|
799 first parent, or -1 if the changeset has no parents.""" |
bd605568c5a0
templatekw: add p1rev, p1node, p2rev, p2node keywords
epriestley <hg@yghe.net>
parents:
17187
diff
changeset
|
800 return ctx.p1().rev() |
17355
c25531ed58b0
templatekw: add parent1, parent1node, parent2, parent2node keywords
epriestley <hg@yghe.net>
parents:
17187
diff
changeset
|
801 |
28539
119702a8b415
templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
802 @templatekeyword('p2rev') |
17357
bd605568c5a0
templatekw: add p1rev, p1node, p2rev, p2node keywords
epriestley <hg@yghe.net>
parents:
17187
diff
changeset
|
803 def showp2rev(repo, ctx, templ, **args): |
28539
119702a8b415
templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
804 """Integer. The repository-local revision number of the changeset's |
17357
bd605568c5a0
templatekw: add p1rev, p1node, p2rev, p2node keywords
epriestley <hg@yghe.net>
parents:
17187
diff
changeset
|
805 second parent, or -1 if the changeset has no second parent.""" |
bd605568c5a0
templatekw: add p1rev, p1node, p2rev, p2node keywords
epriestley <hg@yghe.net>
parents:
17187
diff
changeset
|
806 return ctx.p2().rev() |
17355
c25531ed58b0
templatekw: add parent1, parent1node, parent2, parent2node keywords
epriestley <hg@yghe.net>
parents:
17187
diff
changeset
|
807 |
28539
119702a8b415
templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
808 @templatekeyword('p1node') |
17357
bd605568c5a0
templatekw: add p1rev, p1node, p2rev, p2node keywords
epriestley <hg@yghe.net>
parents:
17187
diff
changeset
|
809 def showp1node(repo, ctx, templ, **args): |
28539
119702a8b415
templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
810 """String. The identification hash of the changeset's first parent, |
17357
bd605568c5a0
templatekw: add p1rev, p1node, p2rev, p2node keywords
epriestley <hg@yghe.net>
parents:
17187
diff
changeset
|
811 as a 40 digit hexadecimal string. If the changeset has no parents, all |
bd605568c5a0
templatekw: add p1rev, p1node, p2rev, p2node keywords
epriestley <hg@yghe.net>
parents:
17187
diff
changeset
|
812 digits are 0.""" |
bd605568c5a0
templatekw: add p1rev, p1node, p2rev, p2node keywords
epriestley <hg@yghe.net>
parents:
17187
diff
changeset
|
813 return ctx.p1().hex() |
17355
c25531ed58b0
templatekw: add parent1, parent1node, parent2, parent2node keywords
epriestley <hg@yghe.net>
parents:
17187
diff
changeset
|
814 |
28539
119702a8b415
templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
815 @templatekeyword('p2node') |
17357
bd605568c5a0
templatekw: add p1rev, p1node, p2rev, p2node keywords
epriestley <hg@yghe.net>
parents:
17187
diff
changeset
|
816 def showp2node(repo, ctx, templ, **args): |
28539
119702a8b415
templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
817 """String. The identification hash of the changeset's second |
17357
bd605568c5a0
templatekw: add p1rev, p1node, p2rev, p2node keywords
epriestley <hg@yghe.net>
parents:
17187
diff
changeset
|
818 parent, as a 40 digit hexadecimal string. If the changeset has no second |
bd605568c5a0
templatekw: add p1rev, p1node, p2rev, p2node keywords
epriestley <hg@yghe.net>
parents:
17187
diff
changeset
|
819 parent, all digits are 0.""" |
bd605568c5a0
templatekw: add p1rev, p1node, p2rev, p2node keywords
epriestley <hg@yghe.net>
parents:
17187
diff
changeset
|
820 return ctx.p2().hex() |
17355
c25531ed58b0
templatekw: add parent1, parent1node, parent2, parent2node keywords
epriestley <hg@yghe.net>
parents:
17187
diff
changeset
|
821 |
28539
119702a8b415
templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
822 @templatekeyword('parents') |
26435
882b170ae616
templatekw: port implementation of showparents() from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents:
26434
diff
changeset
|
823 def showparents(**args): |
28539
119702a8b415
templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
824 """List of strings. The parents of the changeset in "rev:node" |
26434
0a823de8d7b7
templatekw: reorder stub of showparents() function
Yuya Nishihara <yuya@tcha.org>
parents:
26234
diff
changeset
|
825 format. If the changeset has only one "natural" parent (the predecessor |
0a823de8d7b7
templatekw: reorder stub of showparents() function
Yuya Nishihara <yuya@tcha.org>
parents:
26234
diff
changeset
|
826 revision) nothing is shown.""" |
32972
26e710f0468f
py3: convert keys of kwargs in template keywords functions to bytes
Pulkit Goyal <7895pulkit@gmail.com>
parents:
32970
diff
changeset
|
827 args = pycompat.byteskwargs(args) |
26435
882b170ae616
templatekw: port implementation of showparents() from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents:
26434
diff
changeset
|
828 repo = args['repo'] |
882b170ae616
templatekw: port implementation of showparents() from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents:
26434
diff
changeset
|
829 ctx = args['ctx'] |
28270
650c9f69a744
templatekw: switch ctx of list expression to rev of {parents} (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
28239
diff
changeset
|
830 pctxs = scmutil.meaningfulparents(repo, ctx) |
34581
ee0d74083a22
templater: store revisions as ints so min/max won't compare them as strings
Yuya Nishihara <yuya@tcha.org>
parents:
34541
diff
changeset
|
831 prevs = [p.rev() for p in pctxs] |
26435
882b170ae616
templatekw: port implementation of showparents() from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents:
26434
diff
changeset
|
832 parents = [[('rev', p.rev()), |
882b170ae616
templatekw: port implementation of showparents() from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents:
26434
diff
changeset
|
833 ('node', p.hex()), |
882b170ae616
templatekw: port implementation of showparents() from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents:
26434
diff
changeset
|
834 ('phase', p.phasestr())] |
28270
650c9f69a744
templatekw: switch ctx of list expression to rev of {parents} (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
28239
diff
changeset
|
835 for p in pctxs] |
32036
8bcc8c9b4e9f
templatekw: change _showlist() to take mapping dict with no **kwargs expansion
Yuya Nishihara <yuya@tcha.org>
parents:
32035
diff
changeset
|
836 f = _showlist('parent', parents, args) |
34581
ee0d74083a22
templater: store revisions as ints so min/max won't compare them as strings
Yuya Nishihara <yuya@tcha.org>
parents:
34541
diff
changeset
|
837 return _hybrid(f, prevs, lambda x: {'ctx': repo[x], 'revcache': {}}, |
ee0d74083a22
templater: store revisions as ints so min/max won't compare them as strings
Yuya Nishihara <yuya@tcha.org>
parents:
34541
diff
changeset
|
838 lambda x: scmutil.formatchangeid(repo[x]), keytype=int) |
26434
0a823de8d7b7
templatekw: reorder stub of showparents() function
Yuya Nishihara <yuya@tcha.org>
parents:
26234
diff
changeset
|
839 |
28539
119702a8b415
templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
840 @templatekeyword('phase') |
15422
042e11c4e416
phases: add a phase template keyword
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
15155
diff
changeset
|
841 def showphase(repo, ctx, templ, **args): |
28539
119702a8b415
templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
842 """String. The changeset phase name.""" |
15823
a1f818a2b50d
phases: ``{phase}`` template keyword display the phase name
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
15422
diff
changeset
|
843 return ctx.phasestr() |
a1f818a2b50d
phases: ``{phase}`` template keyword display the phase name
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
15422
diff
changeset
|
844 |
28539
119702a8b415
templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
845 @templatekeyword('phaseidx') |
15823
a1f818a2b50d
phases: ``{phase}`` template keyword display the phase name
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
15422
diff
changeset
|
846 def showphaseidx(repo, ctx, templ, **args): |
34991
29e6513856ee
help: hide phaseidx template keyword
Yuya Nishihara <yuya@tcha.org>
parents:
34847
diff
changeset
|
847 """Integer. The changeset phase index. (ADVANCED)""" |
15422
042e11c4e416
phases: add a phase template keyword
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
15155
diff
changeset
|
848 return ctx.phase() |
042e11c4e416
phases: add a phase template keyword
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
15155
diff
changeset
|
849 |
28539
119702a8b415
templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
850 @templatekeyword('rev') |
10055
e400a511e63a
cmdutil: extract repo dependent closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents:
10054
diff
changeset
|
851 def showrev(repo, ctx, templ, **args): |
28539
119702a8b415
templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
852 """Integer. The repository-local changeset revision number.""" |
32656
4bec8cce6a09
scmutil: pass ctx object to intrev()
Yuya Nishihara <yuya@tcha.org>
parents:
32038
diff
changeset
|
853 return scmutil.intrev(ctx) |
10054
1a85861f59af
cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents:
10053
diff
changeset
|
854 |
26234
e4609ec959f8
templater: switch ctx of list expression to rev of revset() (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
25984
diff
changeset
|
855 def showrevslist(name, revs, **args): |
e4609ec959f8
templater: switch ctx of list expression to rev of revset() (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
25984
diff
changeset
|
856 """helper to generate a list of revisions in which a mapped template will |
e4609ec959f8
templater: switch ctx of list expression to rev of revset() (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
25984
diff
changeset
|
857 be evaluated""" |
32972
26e710f0468f
py3: convert keys of kwargs in template keywords functions to bytes
Pulkit Goyal <7895pulkit@gmail.com>
parents:
32970
diff
changeset
|
858 args = pycompat.byteskwargs(args) |
26234
e4609ec959f8
templater: switch ctx of list expression to rev of revset() (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
25984
diff
changeset
|
859 repo = args['ctx'].repo() |
34581
ee0d74083a22
templater: store revisions as ints so min/max won't compare them as strings
Yuya Nishihara <yuya@tcha.org>
parents:
34541
diff
changeset
|
860 f = _showlist(name, ['%d' % r for r in revs], args) |
26234
e4609ec959f8
templater: switch ctx of list expression to rev of revset() (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
25984
diff
changeset
|
861 return _hybrid(f, revs, |
34581
ee0d74083a22
templater: store revisions as ints so min/max won't compare them as strings
Yuya Nishihara <yuya@tcha.org>
parents:
34541
diff
changeset
|
862 lambda x: {name: x, 'ctx': repo[x], 'revcache': {}}, |
ee0d74083a22
templater: store revisions as ints so min/max won't compare them as strings
Yuya Nishihara <yuya@tcha.org>
parents:
34541
diff
changeset
|
863 pycompat.identity, keytype=int) |
26234
e4609ec959f8
templater: switch ctx of list expression to rev of revset() (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
25984
diff
changeset
|
864 |
28539
119702a8b415
templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
865 @templatekeyword('subrepos') |
21897
764adc332f6e
templatekw: add 'subrepos' keyword to show updated subrepositories
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21896
diff
changeset
|
866 def showsubrepos(**args): |
28539
119702a8b415
templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
867 """List of strings. Updated subrepositories in the changeset.""" |
32972
26e710f0468f
py3: convert keys of kwargs in template keywords functions to bytes
Pulkit Goyal <7895pulkit@gmail.com>
parents:
32970
diff
changeset
|
868 args = pycompat.byteskwargs(args) |
21897
764adc332f6e
templatekw: add 'subrepos' keyword to show updated subrepositories
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21896
diff
changeset
|
869 ctx = args['ctx'] |
764adc332f6e
templatekw: add 'subrepos' keyword to show updated subrepositories
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21896
diff
changeset
|
870 substate = ctx.substate |
764adc332f6e
templatekw: add 'subrepos' keyword to show updated subrepositories
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21896
diff
changeset
|
871 if not substate: |
32037
e5eab0fe69ee
templatekw: have showlist() take mapping dict with no **kwargs expansion (API)
Yuya Nishihara <yuya@tcha.org>
parents:
32036
diff
changeset
|
872 return showlist('subrepo', [], args) |
21897
764adc332f6e
templatekw: add 'subrepos' keyword to show updated subrepositories
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21896
diff
changeset
|
873 psubstate = ctx.parents()[0].substate or {} |
764adc332f6e
templatekw: add 'subrepos' keyword to show updated subrepositories
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21896
diff
changeset
|
874 subrepos = [] |
764adc332f6e
templatekw: add 'subrepos' keyword to show updated subrepositories
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21896
diff
changeset
|
875 for sub in substate: |
764adc332f6e
templatekw: add 'subrepos' keyword to show updated subrepositories
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21896
diff
changeset
|
876 if sub not in psubstate or substate[sub] != psubstate[sub]: |
764adc332f6e
templatekw: add 'subrepos' keyword to show updated subrepositories
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21896
diff
changeset
|
877 subrepos.append(sub) # modified or newly added in ctx |
764adc332f6e
templatekw: add 'subrepos' keyword to show updated subrepositories
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21896
diff
changeset
|
878 for sub in psubstate: |
764adc332f6e
templatekw: add 'subrepos' keyword to show updated subrepositories
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21896
diff
changeset
|
879 if sub not in substate: |
764adc332f6e
templatekw: add 'subrepos' keyword to show updated subrepositories
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21896
diff
changeset
|
880 subrepos.append(sub) # removed in ctx |
32037
e5eab0fe69ee
templatekw: have showlist() take mapping dict with no **kwargs expansion (API)
Yuya Nishihara <yuya@tcha.org>
parents:
32036
diff
changeset
|
881 return showlist('subrepo', sorted(subrepos), args) |
21897
764adc332f6e
templatekw: add 'subrepos' keyword to show updated subrepositories
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21896
diff
changeset
|
882 |
23977
0870bb93573c
templatekw: re-add showtags() to list tags keyword up in online help
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
23737
diff
changeset
|
883 # don't remove "showtags" definition, even though namespaces will put |
0870bb93573c
templatekw: re-add showtags() to list tags keyword up in online help
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
23737
diff
changeset
|
884 # a helper function for "tags" keyword into "keywords" map automatically, |
0870bb93573c
templatekw: re-add showtags() to list tags keyword up in online help
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
23737
diff
changeset
|
885 # because online help text is built without namespaces initialization |
28539
119702a8b415
templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
886 @templatekeyword('tags') |
23977
0870bb93573c
templatekw: re-add showtags() to list tags keyword up in online help
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
23737
diff
changeset
|
887 def showtags(**args): |
28539
119702a8b415
templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
888 """List of strings. Any tags associated with the changeset.""" |
23977
0870bb93573c
templatekw: re-add showtags() to list tags keyword up in online help
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
23737
diff
changeset
|
889 return shownames('tags', **args) |
0870bb93573c
templatekw: re-add showtags() to list tags keyword up in online help
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
23737
diff
changeset
|
890 |
30088
d1f5f158768e
template: provide a termwidth keyword (issue5395)
Simon Farnsworth <simonfar@fb.com>
parents:
29669
diff
changeset
|
891 @templatekeyword('termwidth') |
33850
84a3e04e35b5
templatekw: rename termwidth() per convention
Yuya Nishihara <yuya@tcha.org>
parents:
33782
diff
changeset
|
892 def showtermwidth(repo, ctx, templ, **args): |
30088
d1f5f158768e
template: provide a termwidth keyword (issue5395)
Simon Farnsworth <simonfar@fb.com>
parents:
29669
diff
changeset
|
893 """Integer. The width of the current terminal.""" |
d1f5f158768e
template: provide a termwidth keyword (issue5395)
Simon Farnsworth <simonfar@fb.com>
parents:
29669
diff
changeset
|
894 return repo.ui.termwidth() |
d1f5f158768e
template: provide a termwidth keyword (issue5395)
Simon Farnsworth <simonfar@fb.com>
parents:
29669
diff
changeset
|
895 |
30712
5dde81de1e6d
templatekw: add a "troubles" template keyword
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
30375
diff
changeset
|
896 @templatekeyword('troubles') |
33709
511d6ae462f3
template: rename troubles templatekw into instabilities
Boris Feld <boris.feld@octobus.net>
parents:
33476
diff
changeset
|
897 def showtroubles(repo, **args): |
30712
5dde81de1e6d
templatekw: add a "troubles" template keyword
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
30375
diff
changeset
|
898 """List of strings. Evolution troubles affecting the changeset. |
33709
511d6ae462f3
template: rename troubles templatekw into instabilities
Boris Feld <boris.feld@octobus.net>
parents:
33476
diff
changeset
|
899 (DEPRECATED) |
511d6ae462f3
template: rename troubles templatekw into instabilities
Boris Feld <boris.feld@octobus.net>
parents:
33476
diff
changeset
|
900 """ |
511d6ae462f3
template: rename troubles templatekw into instabilities
Boris Feld <boris.feld@octobus.net>
parents:
33476
diff
changeset
|
901 msg = ("'troubles' is deprecated, " |
511d6ae462f3
template: rename troubles templatekw into instabilities
Boris Feld <boris.feld@octobus.net>
parents:
33476
diff
changeset
|
902 "use 'instabilities'") |
511d6ae462f3
template: rename troubles templatekw into instabilities
Boris Feld <boris.feld@octobus.net>
parents:
33476
diff
changeset
|
903 repo.ui.deprecwarn(msg, '4.4') |
511d6ae462f3
template: rename troubles templatekw into instabilities
Boris Feld <boris.feld@octobus.net>
parents:
33476
diff
changeset
|
904 |
511d6ae462f3
template: rename troubles templatekw into instabilities
Boris Feld <boris.feld@octobus.net>
parents:
33476
diff
changeset
|
905 return showinstabilities(repo=repo, **args) |
511d6ae462f3
template: rename troubles templatekw into instabilities
Boris Feld <boris.feld@octobus.net>
parents:
33476
diff
changeset
|
906 |
511d6ae462f3
template: rename troubles templatekw into instabilities
Boris Feld <boris.feld@octobus.net>
parents:
33476
diff
changeset
|
907 @templatekeyword('instabilities') |
511d6ae462f3
template: rename troubles templatekw into instabilities
Boris Feld <boris.feld@octobus.net>
parents:
33476
diff
changeset
|
908 def showinstabilities(**args): |
511d6ae462f3
template: rename troubles templatekw into instabilities
Boris Feld <boris.feld@octobus.net>
parents:
33476
diff
changeset
|
909 """List of strings. Evolution instabilities affecting the changeset. |
30712
5dde81de1e6d
templatekw: add a "troubles" template keyword
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
30375
diff
changeset
|
910 (EXPERIMENTAL) |
5dde81de1e6d
templatekw: add a "troubles" template keyword
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
30375
diff
changeset
|
911 """ |
32972
26e710f0468f
py3: convert keys of kwargs in template keywords functions to bytes
Pulkit Goyal <7895pulkit@gmail.com>
parents:
32970
diff
changeset
|
912 args = pycompat.byteskwargs(args) |
33851
7827fbbd0b06
templatekw: specify plural form of instability
Yuya Nishihara <yuya@tcha.org>
parents:
33850
diff
changeset
|
913 return showlist('instability', args['ctx'].instabilities(), args, |
7827fbbd0b06
templatekw: specify plural form of instability
Yuya Nishihara <yuya@tcha.org>
parents:
33850
diff
changeset
|
914 plural='instabilities') |
30712
5dde81de1e6d
templatekw: add a "troubles" template keyword
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
30375
diff
changeset
|
915 |
34993
625d5ebce066
templatekw: add verbosity keyword to select template by -q/-v/--debug flag
Yuya Nishihara <yuya@tcha.org>
parents:
34992
diff
changeset
|
916 @templatekeyword('verbosity') |
625d5ebce066
templatekw: add verbosity keyword to select template by -q/-v/--debug flag
Yuya Nishihara <yuya@tcha.org>
parents:
34992
diff
changeset
|
917 def showverbosity(ui, **args): |
625d5ebce066
templatekw: add verbosity keyword to select template by -q/-v/--debug flag
Yuya Nishihara <yuya@tcha.org>
parents:
34992
diff
changeset
|
918 """String. The current output verbosity in 'debug', 'quiet', 'verbose', |
625d5ebce066
templatekw: add verbosity keyword to select template by -q/-v/--debug flag
Yuya Nishihara <yuya@tcha.org>
parents:
34992
diff
changeset
|
919 or ''.""" |
625d5ebce066
templatekw: add verbosity keyword to select template by -q/-v/--debug flag
Yuya Nishihara <yuya@tcha.org>
parents:
34992
diff
changeset
|
920 # see cmdutil.changeset_templater for priority of these flags |
625d5ebce066
templatekw: add verbosity keyword to select template by -q/-v/--debug flag
Yuya Nishihara <yuya@tcha.org>
parents:
34992
diff
changeset
|
921 if ui.debugflag: |
625d5ebce066
templatekw: add verbosity keyword to select template by -q/-v/--debug flag
Yuya Nishihara <yuya@tcha.org>
parents:
34992
diff
changeset
|
922 return 'debug' |
625d5ebce066
templatekw: add verbosity keyword to select template by -q/-v/--debug flag
Yuya Nishihara <yuya@tcha.org>
parents:
34992
diff
changeset
|
923 elif ui.quiet: |
625d5ebce066
templatekw: add verbosity keyword to select template by -q/-v/--debug flag
Yuya Nishihara <yuya@tcha.org>
parents:
34992
diff
changeset
|
924 return 'quiet' |
625d5ebce066
templatekw: add verbosity keyword to select template by -q/-v/--debug flag
Yuya Nishihara <yuya@tcha.org>
parents:
34992
diff
changeset
|
925 elif ui.verbose: |
625d5ebce066
templatekw: add verbosity keyword to select template by -q/-v/--debug flag
Yuya Nishihara <yuya@tcha.org>
parents:
34992
diff
changeset
|
926 return 'verbose' |
625d5ebce066
templatekw: add verbosity keyword to select template by -q/-v/--debug flag
Yuya Nishihara <yuya@tcha.org>
parents:
34992
diff
changeset
|
927 return '' |
625d5ebce066
templatekw: add verbosity keyword to select template by -q/-v/--debug flag
Yuya Nishihara <yuya@tcha.org>
parents:
34992
diff
changeset
|
928 |
34992
e2fc6cec0eff
templatekw: move loadkeyword() to bottom
Yuya Nishihara <yuya@tcha.org>
parents:
34991
diff
changeset
|
929 def loadkeyword(ui, extname, registrarobj): |
e2fc6cec0eff
templatekw: move loadkeyword() to bottom
Yuya Nishihara <yuya@tcha.org>
parents:
34991
diff
changeset
|
930 """Load template keyword from specified registrarobj |
e2fc6cec0eff
templatekw: move loadkeyword() to bottom
Yuya Nishihara <yuya@tcha.org>
parents:
34991
diff
changeset
|
931 """ |
e2fc6cec0eff
templatekw: move loadkeyword() to bottom
Yuya Nishihara <yuya@tcha.org>
parents:
34991
diff
changeset
|
932 for name, func in registrarobj._table.iteritems(): |
e2fc6cec0eff
templatekw: move loadkeyword() to bottom
Yuya Nishihara <yuya@tcha.org>
parents:
34991
diff
changeset
|
933 keywords[name] = func |
e2fc6cec0eff
templatekw: move loadkeyword() to bottom
Yuya Nishihara <yuya@tcha.org>
parents:
34991
diff
changeset
|
934 |
13585
2e80d495592a
templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents:
13386
diff
changeset
|
935 # tell hggettext to extract docstrings from these functions: |
26436
a2291c9c85a1
templatekw: remove dockeywords hack
Yuya Nishihara <yuya@tcha.org>
parents:
26435
diff
changeset
|
936 i18nfunctions = keywords.values() |