author | Pierre-Yves David <pierre-yves.david@octobus.net> |
Wed, 10 Feb 2021 22:43:16 +0100 | |
branch | stable |
changeset 46369 | 0760282995cf |
parent 46015 | c1bb02738f96 |
child 48966 | 6000f5b25c9b |
permissions | -rw-r--r-- |
27583
37d50250b696
registrar: add funcregistrar class to register function for specific purpose
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
1 |
# registrar.py - utilities to register function for specific purpose |
37d50250b696
registrar: add funcregistrar class to register function for specific purpose
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
2 |
# |
37d50250b696
registrar: add funcregistrar class to register function for specific purpose
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
3 |
# Copyright FUJIWARA Katsunori <foozy@lares.dti.ne.jp> and others |
37d50250b696
registrar: add funcregistrar class to register function for specific purpose
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
4 |
# |
37d50250b696
registrar: add funcregistrar class to register function for specific purpose
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
5 |
# This software may be used and distributed according to the terms of the |
37d50250b696
registrar: add funcregistrar class to register function for specific purpose
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
6 |
# GNU General Public License version 2 or any later version. |
37d50250b696
registrar: add funcregistrar class to register function for specific purpose
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
7 |
|
37d50250b696
registrar: add funcregistrar class to register function for specific purpose
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
8 |
from __future__ import absolute_import |
37d50250b696
registrar: add funcregistrar class to register function for specific purpose
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
9 |
|
37d50250b696
registrar: add funcregistrar class to register function for specific purpose
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
10 |
from . import ( |
33139
c467d13334ee
configitems: add an official API for extensions to register config item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32378
diff
changeset
|
11 |
configitems, |
30613
b52e8a4f4c0f
registrar: raise a programming error on duplicated registering
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30342
diff
changeset
|
12 |
error, |
30059
6ffb7e0249f4
registrar: make format strings unicodes and not bytes
Augie Fackler <augie@google.com>
parents:
29937
diff
changeset
|
13 |
pycompat, |
27583
37d50250b696
registrar: add funcregistrar class to register function for specific purpose
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
14 |
util, |
37d50250b696
registrar: add funcregistrar class to register function for specific purpose
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
15 |
) |
37d50250b696
registrar: add funcregistrar class to register function for specific purpose
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
16 |
|
33139
c467d13334ee
configitems: add an official API for extensions to register config item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32378
diff
changeset
|
17 |
# unlike the other registered items, config options are neither functions or |
c467d13334ee
configitems: add an official API for extensions to register config item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32378
diff
changeset
|
18 |
# classes. Registering the option is just small function call. |
c467d13334ee
configitems: add an official API for extensions to register config item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32378
diff
changeset
|
19 |
# |
c467d13334ee
configitems: add an official API for extensions to register config item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32378
diff
changeset
|
20 |
# We still add the official API to the registrar module for consistency with |
c467d13334ee
configitems: add an official API for extensions to register config item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32378
diff
changeset
|
21 |
# the other items extensions want might to register. |
c467d13334ee
configitems: add an official API for extensions to register config item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32378
diff
changeset
|
22 |
configitem = configitems.getitemregister |
c467d13334ee
configitems: add an official API for extensions to register config item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32378
diff
changeset
|
23 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
24 |
|
28392
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
25 |
class _funcregistrarbase(object): |
30342
318a24b52eeb
spelling: fixes of non-dictionary words
Mads Kiilerich <madski@unity3d.com>
parents:
30059
diff
changeset
|
26 |
"""Base of decorator to register a function for specific purpose |
28392
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
27 |
|
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
28 |
This decorator stores decorated functions into own dict 'table'. |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
29 |
|
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
30 |
The least derived class can be defined by overriding 'formatdoc', |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
31 |
for example:: |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
32 |
|
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
33 |
class keyword(_funcregistrarbase): |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
34 |
_docformat = ":%s: %s" |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
35 |
|
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
36 |
This should be used as below: |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
37 |
|
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
38 |
keyword = registrar.keyword() |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
39 |
|
46015
c1bb02738f96
registrar: clarify the documentation about some byte strings being required
Matt Harbison <matt_harbison@yahoo.com>
parents:
45957
diff
changeset
|
40 |
@keyword(b'bar') |
28392
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
41 |
def barfunc(*args, **kwargs): |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
42 |
'''Explanation of bar keyword .... |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
43 |
''' |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
44 |
pass |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
45 |
|
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
46 |
In this case: |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
47 |
|
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
48 |
- 'barfunc' is stored as 'bar' in '_table' of an instance 'keyword' above |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
49 |
- 'barfunc.__doc__' becomes ":bar: Explanation of bar keyword" |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
50 |
""" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
51 |
|
28392
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
52 |
def __init__(self, table=None): |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
53 |
if table is None: |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
54 |
self._table = {} |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
55 |
else: |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
56 |
self._table = table |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
57 |
|
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
58 |
def __call__(self, decl, *args, **kwargs): |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
59 |
return lambda func: self._doregister(func, decl, *args, **kwargs) |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
60 |
|
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
61 |
def _doregister(self, func, decl, *args, **kwargs): |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
62 |
name = self._getname(decl) |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
63 |
|
30613
b52e8a4f4c0f
registrar: raise a programming error on duplicated registering
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30342
diff
changeset
|
64 |
if name in self._table: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
65 |
msg = b'duplicate registration for name: "%s"' % name |
30613
b52e8a4f4c0f
registrar: raise a programming error on duplicated registering
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30342
diff
changeset
|
66 |
raise error.ProgrammingError(msg) |
b52e8a4f4c0f
registrar: raise a programming error on duplicated registering
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30342
diff
changeset
|
67 |
|
43115
4aa72cdf616f
py3: delete b'' prefix from safehasattr arguments
Martin von Zweigbergk <martinvonz@google.com>
parents:
43077
diff
changeset
|
68 |
if func.__doc__ and not util.safehasattr(func, '_origdoc'): |
42596
83666f011679
py3: store _origdoc as str
Martin von Zweigbergk <martinvonz@google.com>
parents:
42370
diff
changeset
|
69 |
func._origdoc = func.__doc__.strip() |
83666f011679
py3: store _origdoc as str
Martin von Zweigbergk <martinvonz@google.com>
parents:
42370
diff
changeset
|
70 |
doc = pycompat.sysbytes(func._origdoc) |
31820
45761ef1bc93
py3: have registrar process docstrings in bytes
Yuya Nishihara <yuya@tcha.org>
parents:
30613
diff
changeset
|
71 |
func.__doc__ = pycompat.sysstr(self._formatdoc(decl, doc)) |
28392
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
72 |
|
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
73 |
self._table[name] = func |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
74 |
self._extrasetup(name, func, *args, **kwargs) |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
75 |
|
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
76 |
return func |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
77 |
|
41084
13f50ea8ac3b
registrar: add a method to merge registrar instances
Matt Harbison <matt_harbison@yahoo.com>
parents:
40490
diff
changeset
|
78 |
def _merge(self, registrarbase): |
13f50ea8ac3b
registrar: add a method to merge registrar instances
Matt Harbison <matt_harbison@yahoo.com>
parents:
40490
diff
changeset
|
79 |
"""Merge the entries of the given registrar object into this one. |
13f50ea8ac3b
registrar: add a method to merge registrar instances
Matt Harbison <matt_harbison@yahoo.com>
parents:
40490
diff
changeset
|
80 |
|
13f50ea8ac3b
registrar: add a method to merge registrar instances
Matt Harbison <matt_harbison@yahoo.com>
parents:
40490
diff
changeset
|
81 |
The other registrar object must not contain any entries already in the |
13f50ea8ac3b
registrar: add a method to merge registrar instances
Matt Harbison <matt_harbison@yahoo.com>
parents:
40490
diff
changeset
|
82 |
current one, or a ProgrammmingError is raised. Additionally, the types |
13f50ea8ac3b
registrar: add a method to merge registrar instances
Matt Harbison <matt_harbison@yahoo.com>
parents:
40490
diff
changeset
|
83 |
of the two registrars must match. |
13f50ea8ac3b
registrar: add a method to merge registrar instances
Matt Harbison <matt_harbison@yahoo.com>
parents:
40490
diff
changeset
|
84 |
""" |
41099
f8f61cf246f5
registrar: minor cleanup to the merge function
Matt Harbison <matt_harbison@yahoo.com>
parents:
41084
diff
changeset
|
85 |
if not isinstance(registrarbase, type(self)): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
86 |
msg = b"cannot merge different types of registrar" |
41084
13f50ea8ac3b
registrar: add a method to merge registrar instances
Matt Harbison <matt_harbison@yahoo.com>
parents:
40490
diff
changeset
|
87 |
raise error.ProgrammingError(msg) |
13f50ea8ac3b
registrar: add a method to merge registrar instances
Matt Harbison <matt_harbison@yahoo.com>
parents:
40490
diff
changeset
|
88 |
|
41099
f8f61cf246f5
registrar: minor cleanup to the merge function
Matt Harbison <matt_harbison@yahoo.com>
parents:
41084
diff
changeset
|
89 |
dups = set(registrarbase._table).intersection(self._table) |
41084
13f50ea8ac3b
registrar: add a method to merge registrar instances
Matt Harbison <matt_harbison@yahoo.com>
parents:
40490
diff
changeset
|
90 |
|
13f50ea8ac3b
registrar: add a method to merge registrar instances
Matt Harbison <matt_harbison@yahoo.com>
parents:
40490
diff
changeset
|
91 |
if dups: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
92 |
msg = b'duplicate registration for names: "%s"' % b'", "'.join(dups) |
41084
13f50ea8ac3b
registrar: add a method to merge registrar instances
Matt Harbison <matt_harbison@yahoo.com>
parents:
40490
diff
changeset
|
93 |
raise error.ProgrammingError(msg) |
13f50ea8ac3b
registrar: add a method to merge registrar instances
Matt Harbison <matt_harbison@yahoo.com>
parents:
40490
diff
changeset
|
94 |
|
13f50ea8ac3b
registrar: add a method to merge registrar instances
Matt Harbison <matt_harbison@yahoo.com>
parents:
40490
diff
changeset
|
95 |
self._table.update(registrarbase._table) |
13f50ea8ac3b
registrar: add a method to merge registrar instances
Matt Harbison <matt_harbison@yahoo.com>
parents:
40490
diff
changeset
|
96 |
|
28392
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
97 |
def _parsefuncdecl(self, decl): |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45880
diff
changeset
|
98 |
"""Parse function declaration and return the name of function in it""" |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
99 |
i = decl.find(b'(') |
28392
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
100 |
if i >= 0: |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
101 |
return decl[:i] |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
102 |
else: |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
103 |
return decl |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
104 |
|
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
105 |
def _getname(self, decl): |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
106 |
"""Return the name of the registered function from decl |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
107 |
|
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
108 |
Derived class should override this, if it allows more |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
109 |
descriptive 'decl' string than just a name. |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
110 |
""" |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
111 |
return decl |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
112 |
|
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
113 |
_docformat = None |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
114 |
|
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
115 |
def _formatdoc(self, decl, doc): |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
116 |
"""Return formatted document of the registered function for help |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
117 |
|
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
118 |
'doc' is '__doc__.strip()' of the registered function. |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
119 |
""" |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
120 |
return self._docformat % (decl, doc) |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
121 |
|
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
122 |
def _extrasetup(self, name, func): |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45880
diff
changeset
|
123 |
"""Execute extra setup for registered function, if needed""" |
28393
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
124 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
125 |
|
32377
ec84db232fc2
registrar: switch @command decorator to class
Yuya Nishihara <yuya@tcha.org>
parents:
32376
diff
changeset
|
126 |
class command(_funcregistrarbase): |
ec84db232fc2
registrar: switch @command decorator to class
Yuya Nishihara <yuya@tcha.org>
parents:
32376
diff
changeset
|
127 |
"""Decorator to register a command function to table |
32376
46ba2cdda476
registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
31886
diff
changeset
|
128 |
|
32377
ec84db232fc2
registrar: switch @command decorator to class
Yuya Nishihara <yuya@tcha.org>
parents:
32376
diff
changeset
|
129 |
This class receives a command table as its argument. The table should |
32376
46ba2cdda476
registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
31886
diff
changeset
|
130 |
be a dict. |
46ba2cdda476
registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
31886
diff
changeset
|
131 |
|
32377
ec84db232fc2
registrar: switch @command decorator to class
Yuya Nishihara <yuya@tcha.org>
parents:
32376
diff
changeset
|
132 |
The created object can be used as a decorator for adding commands to |
ec84db232fc2
registrar: switch @command decorator to class
Yuya Nishihara <yuya@tcha.org>
parents:
32376
diff
changeset
|
133 |
that command table. This accepts multiple arguments to define a command. |
32376
46ba2cdda476
registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
31886
diff
changeset
|
134 |
|
35130
b22a0d9e0a83
docs: add args/returns docs for some cmdutil, context, and registrar functions
rlevasseur@google.com
parents:
34896
diff
changeset
|
135 |
The first argument is the command name (as bytes). |
32376
46ba2cdda476
registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
31886
diff
changeset
|
136 |
|
35130
b22a0d9e0a83
docs: add args/returns docs for some cmdutil, context, and registrar functions
rlevasseur@google.com
parents:
34896
diff
changeset
|
137 |
The `options` keyword argument is an iterable of tuples defining command |
b22a0d9e0a83
docs: add args/returns docs for some cmdutil, context, and registrar functions
rlevasseur@google.com
parents:
34896
diff
changeset
|
138 |
arguments. See ``mercurial.fancyopts.fancyopts()`` for the format of each |
b22a0d9e0a83
docs: add args/returns docs for some cmdutil, context, and registrar functions
rlevasseur@google.com
parents:
34896
diff
changeset
|
139 |
tuple. |
32376
46ba2cdda476
registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
31886
diff
changeset
|
140 |
|
35130
b22a0d9e0a83
docs: add args/returns docs for some cmdutil, context, and registrar functions
rlevasseur@google.com
parents:
34896
diff
changeset
|
141 |
The `synopsis` argument defines a short, one line summary of how to use the |
32376
46ba2cdda476
registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
31886
diff
changeset
|
142 |
command. This shows up in the help output. |
46ba2cdda476
registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
31886
diff
changeset
|
143 |
|
35130
b22a0d9e0a83
docs: add args/returns docs for some cmdutil, context, and registrar functions
rlevasseur@google.com
parents:
34896
diff
changeset
|
144 |
There are three arguments that control what repository (if any) is found |
b22a0d9e0a83
docs: add args/returns docs for some cmdutil, context, and registrar functions
rlevasseur@google.com
parents:
34896
diff
changeset
|
145 |
and passed to the decorated function: `norepo`, `optionalrepo`, and |
b22a0d9e0a83
docs: add args/returns docs for some cmdutil, context, and registrar functions
rlevasseur@google.com
parents:
34896
diff
changeset
|
146 |
`inferrepo`. |
b22a0d9e0a83
docs: add args/returns docs for some cmdutil, context, and registrar functions
rlevasseur@google.com
parents:
34896
diff
changeset
|
147 |
|
b22a0d9e0a83
docs: add args/returns docs for some cmdutil, context, and registrar functions
rlevasseur@google.com
parents:
34896
diff
changeset
|
148 |
The `norepo` argument defines whether the command does not require a |
32376
46ba2cdda476
registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
31886
diff
changeset
|
149 |
local repository. Most commands operate against a repository, thus the |
35130
b22a0d9e0a83
docs: add args/returns docs for some cmdutil, context, and registrar functions
rlevasseur@google.com
parents:
34896
diff
changeset
|
150 |
default is False. When True, no repository will be passed. |
32376
46ba2cdda476
registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
31886
diff
changeset
|
151 |
|
35130
b22a0d9e0a83
docs: add args/returns docs for some cmdutil, context, and registrar functions
rlevasseur@google.com
parents:
34896
diff
changeset
|
152 |
The `optionalrepo` argument defines whether the command optionally requires |
b22a0d9e0a83
docs: add args/returns docs for some cmdutil, context, and registrar functions
rlevasseur@google.com
parents:
34896
diff
changeset
|
153 |
a local repository. If no repository can be found, None will be passed |
b22a0d9e0a83
docs: add args/returns docs for some cmdutil, context, and registrar functions
rlevasseur@google.com
parents:
34896
diff
changeset
|
154 |
to the decorated function. |
32376
46ba2cdda476
registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
31886
diff
changeset
|
155 |
|
35130
b22a0d9e0a83
docs: add args/returns docs for some cmdutil, context, and registrar functions
rlevasseur@google.com
parents:
34896
diff
changeset
|
156 |
The `inferrepo` argument defines whether to try to find a repository from |
b22a0d9e0a83
docs: add args/returns docs for some cmdutil, context, and registrar functions
rlevasseur@google.com
parents:
34896
diff
changeset
|
157 |
the command line arguments. If True, arguments will be examined for |
b22a0d9e0a83
docs: add args/returns docs for some cmdutil, context, and registrar functions
rlevasseur@google.com
parents:
34896
diff
changeset
|
158 |
potential repository locations. See ``findrepo()``. If a repository is |
b22a0d9e0a83
docs: add args/returns docs for some cmdutil, context, and registrar functions
rlevasseur@google.com
parents:
34896
diff
changeset
|
159 |
found, it will be used and passed to the decorated function. |
34781
fe987d0b9e1e
registrar: add support for storing the type of command in func object
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34437
diff
changeset
|
160 |
|
37716
dfc51a482031
registrar: replace "cmdtype" with an intent-based mechanism (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37229
diff
changeset
|
161 |
The `intents` argument defines a set of intended actions or capabilities |
dfc51a482031
registrar: replace "cmdtype" with an intent-based mechanism (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37229
diff
changeset
|
162 |
the command is taking. These intents can be used to affect the construction |
dfc51a482031
registrar: replace "cmdtype" with an intent-based mechanism (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37229
diff
changeset
|
163 |
of the repository object passed to the command. For example, commands |
dfc51a482031
registrar: replace "cmdtype" with an intent-based mechanism (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37229
diff
changeset
|
164 |
declaring that they are read-only could receive a repository that doesn't |
dfc51a482031
registrar: replace "cmdtype" with an intent-based mechanism (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37229
diff
changeset
|
165 |
have any methods allowing repository mutation. Other intents could be used |
dfc51a482031
registrar: replace "cmdtype" with an intent-based mechanism (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37229
diff
changeset
|
166 |
to prevent the command from running if the requested intent could not be |
dfc51a482031
registrar: replace "cmdtype" with an intent-based mechanism (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37229
diff
changeset
|
167 |
fulfilled. |
34781
fe987d0b9e1e
registrar: add support for storing the type of command in func object
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34437
diff
changeset
|
168 |
|
40291
170926caf44c
help: adding support for command categories
rdamazio@google.com
parents:
39159
diff
changeset
|
169 |
If `helpcategory` is set (usually to one of the constants in the help |
170926caf44c
help: adding support for command categories
rdamazio@google.com
parents:
39159
diff
changeset
|
170 |
module), the command will be displayed under that category in the help's |
170926caf44c
help: adding support for command categories
rdamazio@google.com
parents:
39159
diff
changeset
|
171 |
list of commands. |
170926caf44c
help: adding support for command categories
rdamazio@google.com
parents:
39159
diff
changeset
|
172 |
|
37716
dfc51a482031
registrar: replace "cmdtype" with an intent-based mechanism (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37229
diff
changeset
|
173 |
The following intents are defined: |
dfc51a482031
registrar: replace "cmdtype" with an intent-based mechanism (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37229
diff
changeset
|
174 |
|
dfc51a482031
registrar: replace "cmdtype" with an intent-based mechanism (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37229
diff
changeset
|
175 |
readonly |
dfc51a482031
registrar: replace "cmdtype" with an intent-based mechanism (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37229
diff
changeset
|
176 |
The command is read-only |
35130
b22a0d9e0a83
docs: add args/returns docs for some cmdutil, context, and registrar functions
rlevasseur@google.com
parents:
34896
diff
changeset
|
177 |
|
b22a0d9e0a83
docs: add args/returns docs for some cmdutil, context, and registrar functions
rlevasseur@google.com
parents:
34896
diff
changeset
|
178 |
The signature of the decorated function looks like this: |
b22a0d9e0a83
docs: add args/returns docs for some cmdutil, context, and registrar functions
rlevasseur@google.com
parents:
34896
diff
changeset
|
179 |
def cmd(ui[, repo] [, <args>] [, <options>]) |
b22a0d9e0a83
docs: add args/returns docs for some cmdutil, context, and registrar functions
rlevasseur@google.com
parents:
34896
diff
changeset
|
180 |
|
b22a0d9e0a83
docs: add args/returns docs for some cmdutil, context, and registrar functions
rlevasseur@google.com
parents:
34896
diff
changeset
|
181 |
`repo` is required if `norepo` is False. |
b22a0d9e0a83
docs: add args/returns docs for some cmdutil, context, and registrar functions
rlevasseur@google.com
parents:
34896
diff
changeset
|
182 |
`<args>` are positional args (or `*args`) arguments, of non-option |
b22a0d9e0a83
docs: add args/returns docs for some cmdutil, context, and registrar functions
rlevasseur@google.com
parents:
34896
diff
changeset
|
183 |
arguments from the command line. |
b22a0d9e0a83
docs: add args/returns docs for some cmdutil, context, and registrar functions
rlevasseur@google.com
parents:
34896
diff
changeset
|
184 |
`<options>` are keyword arguments (or `**options`) of option arguments |
b22a0d9e0a83
docs: add args/returns docs for some cmdutil, context, and registrar functions
rlevasseur@google.com
parents:
34896
diff
changeset
|
185 |
from the command line. |
b22a0d9e0a83
docs: add args/returns docs for some cmdutil, context, and registrar functions
rlevasseur@google.com
parents:
34896
diff
changeset
|
186 |
|
b22a0d9e0a83
docs: add args/returns docs for some cmdutil, context, and registrar functions
rlevasseur@google.com
parents:
34896
diff
changeset
|
187 |
See the WritingExtensions and MercurialApi documentation for more exhaustive |
b22a0d9e0a83
docs: add args/returns docs for some cmdutil, context, and registrar functions
rlevasseur@google.com
parents:
34896
diff
changeset
|
188 |
descriptions and examples. |
32376
46ba2cdda476
registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
31886
diff
changeset
|
189 |
""" |
32377
ec84db232fc2
registrar: switch @command decorator to class
Yuya Nishihara <yuya@tcha.org>
parents:
32376
diff
changeset
|
190 |
|
40291
170926caf44c
help: adding support for command categories
rdamazio@google.com
parents:
39159
diff
changeset
|
191 |
# Command categories for grouping them in help output. |
40490
444861dc1e55
help: displaying documented aliases by default
rdamazio@google.com
parents:
40295
diff
changeset
|
192 |
# These can also be specified for aliases, like: |
444861dc1e55
help: displaying documented aliases by default
rdamazio@google.com
parents:
40295
diff
changeset
|
193 |
# [alias] |
444861dc1e55
help: displaying documented aliases by default
rdamazio@google.com
parents:
40295
diff
changeset
|
194 |
# myalias = something |
444861dc1e55
help: displaying documented aliases by default
rdamazio@google.com
parents:
40295
diff
changeset
|
195 |
# myalias:category = repo |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
196 |
CATEGORY_REPO_CREATION = b'repo' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
197 |
CATEGORY_REMOTE_REPO_MANAGEMENT = b'remote' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
198 |
CATEGORY_COMMITTING = b'commit' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
199 |
CATEGORY_CHANGE_MANAGEMENT = b'management' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
200 |
CATEGORY_CHANGE_ORGANIZATION = b'organization' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
201 |
CATEGORY_FILE_CONTENTS = b'files' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
202 |
CATEGORY_CHANGE_NAVIGATION = b'navigation' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
203 |
CATEGORY_WORKING_DIRECTORY = b'wdir' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
204 |
CATEGORY_IMPORT_EXPORT = b'import' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
205 |
CATEGORY_MAINTENANCE = b'maintenance' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
206 |
CATEGORY_HELP = b'help' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
207 |
CATEGORY_MISC = b'misc' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
208 |
CATEGORY_NONE = b'none' |
40291
170926caf44c
help: adding support for command categories
rdamazio@google.com
parents:
39159
diff
changeset
|
209 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
210 |
def _doregister( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
211 |
self, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
212 |
func, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
213 |
name, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
214 |
options=(), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
215 |
synopsis=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
216 |
norepo=False, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
217 |
optionalrepo=False, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
218 |
inferrepo=False, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
219 |
intents=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
220 |
helpcategory=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
221 |
helpbasic=False, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
222 |
): |
32378
92de09a05d7f
registrar: unindent superfluous "if True" block
Yuya Nishihara <yuya@tcha.org>
parents:
32377
diff
changeset
|
223 |
func.norepo = norepo |
92de09a05d7f
registrar: unindent superfluous "if True" block
Yuya Nishihara <yuya@tcha.org>
parents:
32377
diff
changeset
|
224 |
func.optionalrepo = optionalrepo |
92de09a05d7f
registrar: unindent superfluous "if True" block
Yuya Nishihara <yuya@tcha.org>
parents:
32377
diff
changeset
|
225 |
func.inferrepo = inferrepo |
37716
dfc51a482031
registrar: replace "cmdtype" with an intent-based mechanism (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37229
diff
changeset
|
226 |
func.intents = intents or set() |
40291
170926caf44c
help: adding support for command categories
rdamazio@google.com
parents:
39159
diff
changeset
|
227 |
func.helpcategory = helpcategory |
40295
fa88170c10bb
help: adding a proper declaration for shortlist/basic commands (API)
Rodrigo Damazio <rdamazio@google.com>
parents:
40293
diff
changeset
|
228 |
func.helpbasic = helpbasic |
32378
92de09a05d7f
registrar: unindent superfluous "if True" block
Yuya Nishihara <yuya@tcha.org>
parents:
32377
diff
changeset
|
229 |
if synopsis: |
92de09a05d7f
registrar: unindent superfluous "if True" block
Yuya Nishihara <yuya@tcha.org>
parents:
32377
diff
changeset
|
230 |
self._table[name] = func, list(options), synopsis |
92de09a05d7f
registrar: unindent superfluous "if True" block
Yuya Nishihara <yuya@tcha.org>
parents:
32377
diff
changeset
|
231 |
else: |
92de09a05d7f
registrar: unindent superfluous "if True" block
Yuya Nishihara <yuya@tcha.org>
parents:
32377
diff
changeset
|
232 |
self._table[name] = func, list(options) |
92de09a05d7f
registrar: unindent superfluous "if True" block
Yuya Nishihara <yuya@tcha.org>
parents:
32377
diff
changeset
|
233 |
return func |
32376
46ba2cdda476
registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
31886
diff
changeset
|
234 |
|
45880
d7a508a75d72
strip: move into core
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
45417
diff
changeset
|
235 |
def rename(self, old, new): |
d7a508a75d72
strip: move into core
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
45417
diff
changeset
|
236 |
"""rename a command. Used to add aliases, debugstrip -> |
d7a508a75d72
strip: move into core
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
45417
diff
changeset
|
237 |
debugstrip|strip |
d7a508a75d72
strip: move into core
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
45417
diff
changeset
|
238 |
""" |
d7a508a75d72
strip: move into core
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
45417
diff
changeset
|
239 |
self._table[new] = self._table.pop(old) |
d7a508a75d72
strip: move into core
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
45417
diff
changeset
|
240 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
241 |
|
37716
dfc51a482031
registrar: replace "cmdtype" with an intent-based mechanism (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37229
diff
changeset
|
242 |
INTENT_READONLY = b'readonly' |
dfc51a482031
registrar: replace "cmdtype" with an intent-based mechanism (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37229
diff
changeset
|
243 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
244 |
|
28393
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
245 |
class revsetpredicate(_funcregistrarbase): |
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
246 |
"""Decorator to register revset predicate |
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
247 |
|
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
248 |
Usage:: |
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
249 |
|
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
250 |
revsetpredicate = registrar.revsetpredicate() |
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
251 |
|
46015
c1bb02738f96
registrar: clarify the documentation about some byte strings being required
Matt Harbison <matt_harbison@yahoo.com>
parents:
45957
diff
changeset
|
252 |
@revsetpredicate(b'mypredicate(arg1, arg2[, arg3])') |
28393
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
253 |
def mypredicatefunc(repo, subset, x): |
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
254 |
'''Explanation of this revset predicate .... |
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
255 |
''' |
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
256 |
pass |
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
257 |
|
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
258 |
The first string argument is used also in online help. |
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
259 |
|
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
260 |
Optional argument 'safe' indicates whether a predicate is safe for |
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
261 |
DoS attack (False by default). |
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
262 |
|
29937
91a95ad985d8
revset: add 'takeorder' attribute to mark functions that need ordering flag
Yuya Nishihara <yuya@tcha.org>
parents:
28695
diff
changeset
|
263 |
Optional argument 'takeorder' indicates whether a predicate function |
91a95ad985d8
revset: add 'takeorder' attribute to mark functions that need ordering flag
Yuya Nishihara <yuya@tcha.org>
parents:
28695
diff
changeset
|
264 |
takes ordering policy as the last argument. |
91a95ad985d8
revset: add 'takeorder' attribute to mark functions that need ordering flag
Yuya Nishihara <yuya@tcha.org>
parents:
28695
diff
changeset
|
265 |
|
34280
b0790bebfcf8
revset: move weight information to predicate
Jun Wu <quark@fb.com>
parents:
33725
diff
changeset
|
266 |
Optional argument 'weight' indicates the estimated run-time cost, useful |
b0790bebfcf8
revset: move weight information to predicate
Jun Wu <quark@fb.com>
parents:
33725
diff
changeset
|
267 |
for static optimization, default is 1. Higher weight means more expensive. |
b0790bebfcf8
revset: move weight information to predicate
Jun Wu <quark@fb.com>
parents:
33725
diff
changeset
|
268 |
Usually, revsets that are fast and return only one revision has a weight of |
b0790bebfcf8
revset: move weight information to predicate
Jun Wu <quark@fb.com>
parents:
33725
diff
changeset
|
269 |
0.5 (ex. a symbol); revsets with O(changelog) complexity and read only the |
b0790bebfcf8
revset: move weight information to predicate
Jun Wu <quark@fb.com>
parents:
33725
diff
changeset
|
270 |
changelog have weight 10 (ex. author); revsets reading manifest deltas have |
b0790bebfcf8
revset: move weight information to predicate
Jun Wu <quark@fb.com>
parents:
33725
diff
changeset
|
271 |
weight 30 (ex. adds); revset reading manifest contents have weight 100 |
b0790bebfcf8
revset: move weight information to predicate
Jun Wu <quark@fb.com>
parents:
33725
diff
changeset
|
272 |
(ex. contains). Note: those values are flexible. If the revset has a |
b0790bebfcf8
revset: move weight information to predicate
Jun Wu <quark@fb.com>
parents:
33725
diff
changeset
|
273 |
same big-O time complexity as 'contains', but with a smaller constant, it |
b0790bebfcf8
revset: move weight information to predicate
Jun Wu <quark@fb.com>
parents:
33725
diff
changeset
|
274 |
might have a weight of 90. |
b0790bebfcf8
revset: move weight information to predicate
Jun Wu <quark@fb.com>
parents:
33725
diff
changeset
|
275 |
|
28393
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
276 |
'revsetpredicate' instance in example above can be used to |
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
277 |
decorate multiple functions. |
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
278 |
|
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
279 |
Decorated functions are registered automatically at loading |
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
280 |
extension, if an instance named as 'revsetpredicate' is used for |
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
281 |
decorating in extension. |
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
282 |
|
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
283 |
Otherwise, explicit 'revset.loadpredicate()' is needed. |
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
284 |
""" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
285 |
|
28393
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
286 |
_getname = _funcregistrarbase._parsefuncdecl |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
287 |
_docformat = b"``%s``\n %s" |
28393
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
288 |
|
34280
b0790bebfcf8
revset: move weight information to predicate
Jun Wu <quark@fb.com>
parents:
33725
diff
changeset
|
289 |
def _extrasetup(self, name, func, safe=False, takeorder=False, weight=1): |
28393
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
290 |
func._safe = safe |
29937
91a95ad985d8
revset: add 'takeorder' attribute to mark functions that need ordering flag
Yuya Nishihara <yuya@tcha.org>
parents:
28695
diff
changeset
|
291 |
func._takeorder = takeorder |
34280
b0790bebfcf8
revset: move weight information to predicate
Jun Wu <quark@fb.com>
parents:
33725
diff
changeset
|
292 |
func._weight = weight |
28447
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
293 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
294 |
|
28447
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
295 |
class filesetpredicate(_funcregistrarbase): |
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
296 |
"""Decorator to register fileset predicate |
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
297 |
|
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
298 |
Usage:: |
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
299 |
|
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
300 |
filesetpredicate = registrar.filesetpredicate() |
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
301 |
|
46015
c1bb02738f96
registrar: clarify the documentation about some byte strings being required
Matt Harbison <matt_harbison@yahoo.com>
parents:
45957
diff
changeset
|
302 |
@filesetpredicate(b'mypredicate()') |
28447
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
303 |
def mypredicatefunc(mctx, x): |
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
304 |
'''Explanation of this fileset predicate .... |
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
305 |
''' |
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
306 |
pass |
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
307 |
|
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
308 |
The first string argument is used also in online help. |
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
309 |
|
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
310 |
Optional argument 'callstatus' indicates whether a predicate |
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
311 |
implies 'matchctx.status()' at runtime or not (False, by |
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
312 |
default). |
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
313 |
|
38869
7e7e2b2ff284
fileset: add stub for weight-based optimization
Yuya Nishihara <yuya@tcha.org>
parents:
38690
diff
changeset
|
314 |
Optional argument 'weight' indicates the estimated run-time cost, useful |
7e7e2b2ff284
fileset: add stub for weight-based optimization
Yuya Nishihara <yuya@tcha.org>
parents:
38690
diff
changeset
|
315 |
for static optimization, default is 1. Higher weight means more expensive. |
38902
61ab546b71c3
fileset: introduce weight constants for readability
Yuya Nishihara <yuya@tcha.org>
parents:
38870
diff
changeset
|
316 |
There are predefined weights in the 'filesetlang' module. |
38869
7e7e2b2ff284
fileset: add stub for weight-based optimization
Yuya Nishihara <yuya@tcha.org>
parents:
38690
diff
changeset
|
317 |
|
38870
bfd5def3fe02
fileset: roughly adjust weights of functions
Yuya Nishihara <yuya@tcha.org>
parents:
38869
diff
changeset
|
318 |
====== ============================================================= |
bfd5def3fe02
fileset: roughly adjust weights of functions
Yuya Nishihara <yuya@tcha.org>
parents:
38869
diff
changeset
|
319 |
Weight Description and examples |
bfd5def3fe02
fileset: roughly adjust weights of functions
Yuya Nishihara <yuya@tcha.org>
parents:
38869
diff
changeset
|
320 |
====== ============================================================= |
bfd5def3fe02
fileset: roughly adjust weights of functions
Yuya Nishihara <yuya@tcha.org>
parents:
38869
diff
changeset
|
321 |
0.5 basic match patterns (e.g. a symbol) |
bfd5def3fe02
fileset: roughly adjust weights of functions
Yuya Nishihara <yuya@tcha.org>
parents:
38869
diff
changeset
|
322 |
10 computing status (e.g. added()) or accessing a few files |
bfd5def3fe02
fileset: roughly adjust weights of functions
Yuya Nishihara <yuya@tcha.org>
parents:
38869
diff
changeset
|
323 |
30 reading file content for each (e.g. grep()) |
bfd5def3fe02
fileset: roughly adjust weights of functions
Yuya Nishihara <yuya@tcha.org>
parents:
38869
diff
changeset
|
324 |
50 scanning working directory (ignored()) |
bfd5def3fe02
fileset: roughly adjust weights of functions
Yuya Nishihara <yuya@tcha.org>
parents:
38869
diff
changeset
|
325 |
====== ============================================================= |
bfd5def3fe02
fileset: roughly adjust weights of functions
Yuya Nishihara <yuya@tcha.org>
parents:
38869
diff
changeset
|
326 |
|
28447
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
327 |
'filesetpredicate' instance in example above can be used to |
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
328 |
decorate multiple functions. |
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
329 |
|
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
330 |
Decorated functions are registered automatically at loading |
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
331 |
extension, if an instance named as 'filesetpredicate' is used for |
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
332 |
decorating in extension. |
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
333 |
|
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
334 |
Otherwise, explicit 'fileset.loadpredicate()' is needed. |
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
335 |
""" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
336 |
|
28447
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
337 |
_getname = _funcregistrarbase._parsefuncdecl |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
338 |
_docformat = b"``%s``\n %s" |
28447
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
339 |
|
38869
7e7e2b2ff284
fileset: add stub for weight-based optimization
Yuya Nishihara <yuya@tcha.org>
parents:
38690
diff
changeset
|
340 |
def _extrasetup(self, name, func, callstatus=False, weight=1): |
28447
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
341 |
func._callstatus = callstatus |
38869
7e7e2b2ff284
fileset: add stub for weight-based optimization
Yuya Nishihara <yuya@tcha.org>
parents:
38690
diff
changeset
|
342 |
func._weight = weight |
28538
009f58f1ea75
registrar: add templatekeyword to mark a function as template keyword (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28447
diff
changeset
|
343 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
344 |
|
28538
009f58f1ea75
registrar: add templatekeyword to mark a function as template keyword (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28447
diff
changeset
|
345 |
class _templateregistrarbase(_funcregistrarbase): |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45880
diff
changeset
|
346 |
"""Base of decorator to register functions as template specific one""" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
347 |
|
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
348 |
_docformat = b":%s: %s" |
28538
009f58f1ea75
registrar: add templatekeyword to mark a function as template keyword (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28447
diff
changeset
|
349 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
350 |
|
28538
009f58f1ea75
registrar: add templatekeyword to mark a function as template keyword (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28447
diff
changeset
|
351 |
class templatekeyword(_templateregistrarbase): |
009f58f1ea75
registrar: add templatekeyword to mark a function as template keyword (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28447
diff
changeset
|
352 |
"""Decorator to register template keyword |
009f58f1ea75
registrar: add templatekeyword to mark a function as template keyword (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28447
diff
changeset
|
353 |
|
009f58f1ea75
registrar: add templatekeyword to mark a function as template keyword (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28447
diff
changeset
|
354 |
Usage:: |
009f58f1ea75
registrar: add templatekeyword to mark a function as template keyword (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28447
diff
changeset
|
355 |
|
30342
318a24b52eeb
spelling: fixes of non-dictionary words
Mads Kiilerich <madski@unity3d.com>
parents:
30059
diff
changeset
|
356 |
templatekeyword = registrar.templatekeyword() |
28538
009f58f1ea75
registrar: add templatekeyword to mark a function as template keyword (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28447
diff
changeset
|
357 |
|
36475
e8d37838f5df
templatekw: add 'requires' flag to switch to exception-safe interface
Yuya Nishihara <yuya@tcha.org>
parents:
35130
diff
changeset
|
358 |
# new API (since Mercurial 4.6) |
46015
c1bb02738f96
registrar: clarify the documentation about some byte strings being required
Matt Harbison <matt_harbison@yahoo.com>
parents:
45957
diff
changeset
|
359 |
@templatekeyword(b'mykeyword', requires={b'repo', b'ctx'}) |
36475
e8d37838f5df
templatekw: add 'requires' flag to switch to exception-safe interface
Yuya Nishihara <yuya@tcha.org>
parents:
35130
diff
changeset
|
360 |
def mykeywordfunc(context, mapping): |
e8d37838f5df
templatekw: add 'requires' flag to switch to exception-safe interface
Yuya Nishihara <yuya@tcha.org>
parents:
35130
diff
changeset
|
361 |
'''Explanation of this template keyword .... |
e8d37838f5df
templatekw: add 'requires' flag to switch to exception-safe interface
Yuya Nishihara <yuya@tcha.org>
parents:
35130
diff
changeset
|
362 |
''' |
e8d37838f5df
templatekw: add 'requires' flag to switch to exception-safe interface
Yuya Nishihara <yuya@tcha.org>
parents:
35130
diff
changeset
|
363 |
pass |
e8d37838f5df
templatekw: add 'requires' flag to switch to exception-safe interface
Yuya Nishihara <yuya@tcha.org>
parents:
35130
diff
changeset
|
364 |
|
28538
009f58f1ea75
registrar: add templatekeyword to mark a function as template keyword (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28447
diff
changeset
|
365 |
The first string argument is used also in online help. |
009f58f1ea75
registrar: add templatekeyword to mark a function as template keyword (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28447
diff
changeset
|
366 |
|
36475
e8d37838f5df
templatekw: add 'requires' flag to switch to exception-safe interface
Yuya Nishihara <yuya@tcha.org>
parents:
35130
diff
changeset
|
367 |
Optional argument 'requires' should be a collection of resource names |
42370
de65ae32b82d
templatekw: change default value of 'requires' to ()
Yuya Nishihara <yuya@tcha.org>
parents:
42359
diff
changeset
|
368 |
which the template keyword depends on. |
36475
e8d37838f5df
templatekw: add 'requires' flag to switch to exception-safe interface
Yuya Nishihara <yuya@tcha.org>
parents:
35130
diff
changeset
|
369 |
|
28538
009f58f1ea75
registrar: add templatekeyword to mark a function as template keyword (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28447
diff
changeset
|
370 |
'templatekeyword' instance in example above can be used to |
009f58f1ea75
registrar: add templatekeyword to mark a function as template keyword (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28447
diff
changeset
|
371 |
decorate multiple functions. |
009f58f1ea75
registrar: add templatekeyword to mark a function as template keyword (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28447
diff
changeset
|
372 |
|
009f58f1ea75
registrar: add templatekeyword to mark a function as template keyword (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28447
diff
changeset
|
373 |
Decorated functions are registered automatically at loading |
009f58f1ea75
registrar: add templatekeyword to mark a function as template keyword (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28447
diff
changeset
|
374 |
extension, if an instance named as 'templatekeyword' is used for |
009f58f1ea75
registrar: add templatekeyword to mark a function as template keyword (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28447
diff
changeset
|
375 |
decorating in extension. |
009f58f1ea75
registrar: add templatekeyword to mark a function as template keyword (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28447
diff
changeset
|
376 |
|
009f58f1ea75
registrar: add templatekeyword to mark a function as template keyword (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28447
diff
changeset
|
377 |
Otherwise, explicit 'templatekw.loadkeyword()' is needed. |
009f58f1ea75
registrar: add templatekeyword to mark a function as template keyword (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28447
diff
changeset
|
378 |
""" |
28692
6b3b958daf03
registrar: add templatefilter to mark a function as template filter (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
379 |
|
42370
de65ae32b82d
templatekw: change default value of 'requires' to ()
Yuya Nishihara <yuya@tcha.org>
parents:
42359
diff
changeset
|
380 |
def _extrasetup(self, name, func, requires=()): |
36475
e8d37838f5df
templatekw: add 'requires' flag to switch to exception-safe interface
Yuya Nishihara <yuya@tcha.org>
parents:
35130
diff
changeset
|
381 |
func._requires = requires |
e8d37838f5df
templatekw: add 'requires' flag to switch to exception-safe interface
Yuya Nishihara <yuya@tcha.org>
parents:
35130
diff
changeset
|
382 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
383 |
|
28692
6b3b958daf03
registrar: add templatefilter to mark a function as template filter (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
384 |
class templatefilter(_templateregistrarbase): |
6b3b958daf03
registrar: add templatefilter to mark a function as template filter (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
385 |
"""Decorator to register template filer |
6b3b958daf03
registrar: add templatefilter to mark a function as template filter (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
386 |
|
6b3b958daf03
registrar: add templatefilter to mark a function as template filter (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
387 |
Usage:: |
6b3b958daf03
registrar: add templatefilter to mark a function as template filter (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
388 |
|
6b3b958daf03
registrar: add templatefilter to mark a function as template filter (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
389 |
templatefilter = registrar.templatefilter() |
6b3b958daf03
registrar: add templatefilter to mark a function as template filter (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
390 |
|
46015
c1bb02738f96
registrar: clarify the documentation about some byte strings being required
Matt Harbison <matt_harbison@yahoo.com>
parents:
45957
diff
changeset
|
391 |
@templatefilter(b'myfilter', intype=bytes) |
28692
6b3b958daf03
registrar: add templatefilter to mark a function as template filter (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
392 |
def myfilterfunc(text): |
6b3b958daf03
registrar: add templatefilter to mark a function as template filter (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
393 |
'''Explanation of this template filter .... |
6b3b958daf03
registrar: add templatefilter to mark a function as template filter (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
394 |
''' |
6b3b958daf03
registrar: add templatefilter to mark a function as template filter (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
395 |
pass |
6b3b958daf03
registrar: add templatefilter to mark a function as template filter (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
396 |
|
6b3b958daf03
registrar: add templatefilter to mark a function as template filter (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
397 |
The first string argument is used also in online help. |
6b3b958daf03
registrar: add templatefilter to mark a function as template filter (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
398 |
|
37224
54355c243042
templatefilters: allow declaration of input data type
Yuya Nishihara <yuya@tcha.org>
parents:
36928
diff
changeset
|
399 |
Optional argument 'intype' defines the type of the input argument, |
37229
9bcf096a2da2
templatefilters: declare input type as date where appropriate
Yuya Nishihara <yuya@tcha.org>
parents:
37224
diff
changeset
|
400 |
which should be (bytes, int, templateutil.date, or None for any.) |
37224
54355c243042
templatefilters: allow declaration of input data type
Yuya Nishihara <yuya@tcha.org>
parents:
36928
diff
changeset
|
401 |
|
28692
6b3b958daf03
registrar: add templatefilter to mark a function as template filter (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
402 |
'templatefilter' instance in example above can be used to |
6b3b958daf03
registrar: add templatefilter to mark a function as template filter (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
403 |
decorate multiple functions. |
6b3b958daf03
registrar: add templatefilter to mark a function as template filter (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
404 |
|
6b3b958daf03
registrar: add templatefilter to mark a function as template filter (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
405 |
Decorated functions are registered automatically at loading |
6b3b958daf03
registrar: add templatefilter to mark a function as template filter (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
406 |
extension, if an instance named as 'templatefilter' is used for |
6b3b958daf03
registrar: add templatefilter to mark a function as template filter (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
407 |
decorating in extension. |
6b3b958daf03
registrar: add templatefilter to mark a function as template filter (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
408 |
|
6b3b958daf03
registrar: add templatefilter to mark a function as template filter (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
409 |
Otherwise, explicit 'templatefilters.loadkeyword()' is needed. |
6b3b958daf03
registrar: add templatefilter to mark a function as template filter (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
410 |
""" |
28695
cc103bd0dbf9
registrar: add templatefunc to mark a function as template function (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28692
diff
changeset
|
411 |
|
37224
54355c243042
templatefilters: allow declaration of input data type
Yuya Nishihara <yuya@tcha.org>
parents:
36928
diff
changeset
|
412 |
def _extrasetup(self, name, func, intype=None): |
54355c243042
templatefilters: allow declaration of input data type
Yuya Nishihara <yuya@tcha.org>
parents:
36928
diff
changeset
|
413 |
func._intype = intype |
54355c243042
templatefilters: allow declaration of input data type
Yuya Nishihara <yuya@tcha.org>
parents:
36928
diff
changeset
|
414 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
415 |
|
28695
cc103bd0dbf9
registrar: add templatefunc to mark a function as template function (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28692
diff
changeset
|
416 |
class templatefunc(_templateregistrarbase): |
cc103bd0dbf9
registrar: add templatefunc to mark a function as template function (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28692
diff
changeset
|
417 |
"""Decorator to register template function |
cc103bd0dbf9
registrar: add templatefunc to mark a function as template function (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28692
diff
changeset
|
418 |
|
cc103bd0dbf9
registrar: add templatefunc to mark a function as template function (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28692
diff
changeset
|
419 |
Usage:: |
cc103bd0dbf9
registrar: add templatefunc to mark a function as template function (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28692
diff
changeset
|
420 |
|
cc103bd0dbf9
registrar: add templatefunc to mark a function as template function (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28692
diff
changeset
|
421 |
templatefunc = registrar.templatefunc() |
cc103bd0dbf9
registrar: add templatefunc to mark a function as template function (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28692
diff
changeset
|
422 |
|
46015
c1bb02738f96
registrar: clarify the documentation about some byte strings being required
Matt Harbison <matt_harbison@yahoo.com>
parents:
45957
diff
changeset
|
423 |
@templatefunc(b'myfunc(arg1, arg2[, arg3])', argspec=b'arg1 arg2 arg3', |
c1bb02738f96
registrar: clarify the documentation about some byte strings being required
Matt Harbison <matt_harbison@yahoo.com>
parents:
45957
diff
changeset
|
424 |
requires={b'ctx'}) |
28695
cc103bd0dbf9
registrar: add templatefunc to mark a function as template function (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28692
diff
changeset
|
425 |
def myfuncfunc(context, mapping, args): |
cc103bd0dbf9
registrar: add templatefunc to mark a function as template function (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28692
diff
changeset
|
426 |
'''Explanation of this template function .... |
cc103bd0dbf9
registrar: add templatefunc to mark a function as template function (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28692
diff
changeset
|
427 |
''' |
cc103bd0dbf9
registrar: add templatefunc to mark a function as template function (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28692
diff
changeset
|
428 |
pass |
cc103bd0dbf9
registrar: add templatefunc to mark a function as template function (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28692
diff
changeset
|
429 |
|
cc103bd0dbf9
registrar: add templatefunc to mark a function as template function (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28692
diff
changeset
|
430 |
The first string argument is used also in online help. |
cc103bd0dbf9
registrar: add templatefunc to mark a function as template function (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28692
diff
changeset
|
431 |
|
31886
bdda942f4b9c
templater: add support for keyword arguments
Yuya Nishihara <yuya@tcha.org>
parents:
31820
diff
changeset
|
432 |
If optional 'argspec' is defined, the function will receive 'args' as |
bdda942f4b9c
templater: add support for keyword arguments
Yuya Nishihara <yuya@tcha.org>
parents:
31820
diff
changeset
|
433 |
a dict of named arguments. Otherwise 'args' is a list of positional |
bdda942f4b9c
templater: add support for keyword arguments
Yuya Nishihara <yuya@tcha.org>
parents:
31820
diff
changeset
|
434 |
arguments. |
bdda942f4b9c
templater: add support for keyword arguments
Yuya Nishihara <yuya@tcha.org>
parents:
31820
diff
changeset
|
435 |
|
38433
aa98392eb5b0
templatefuncs: declare resource requirements for future use
Yuya Nishihara <yuya@tcha.org>
parents:
37716
diff
changeset
|
436 |
Optional argument 'requires' should be a collection of resource names |
aa98392eb5b0
templatefuncs: declare resource requirements for future use
Yuya Nishihara <yuya@tcha.org>
parents:
37716
diff
changeset
|
437 |
which the template function depends on. |
aa98392eb5b0
templatefuncs: declare resource requirements for future use
Yuya Nishihara <yuya@tcha.org>
parents:
37716
diff
changeset
|
438 |
|
28695
cc103bd0dbf9
registrar: add templatefunc to mark a function as template function (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28692
diff
changeset
|
439 |
'templatefunc' instance in example above can be used to |
cc103bd0dbf9
registrar: add templatefunc to mark a function as template function (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28692
diff
changeset
|
440 |
decorate multiple functions. |
cc103bd0dbf9
registrar: add templatefunc to mark a function as template function (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28692
diff
changeset
|
441 |
|
cc103bd0dbf9
registrar: add templatefunc to mark a function as template function (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28692
diff
changeset
|
442 |
Decorated functions are registered automatically at loading |
cc103bd0dbf9
registrar: add templatefunc to mark a function as template function (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28692
diff
changeset
|
443 |
extension, if an instance named as 'templatefunc' is used for |
cc103bd0dbf9
registrar: add templatefunc to mark a function as template function (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28692
diff
changeset
|
444 |
decorating in extension. |
cc103bd0dbf9
registrar: add templatefunc to mark a function as template function (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28692
diff
changeset
|
445 |
|
36928
521f6c7e1756
templater: split template functions to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36475
diff
changeset
|
446 |
Otherwise, explicit 'templatefuncs.loadfunction()' is needed. |
28695
cc103bd0dbf9
registrar: add templatefunc to mark a function as template function (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28692
diff
changeset
|
447 |
""" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
448 |
|
28695
cc103bd0dbf9
registrar: add templatefunc to mark a function as template function (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28692
diff
changeset
|
449 |
_getname = _funcregistrarbase._parsefuncdecl |
31886
bdda942f4b9c
templater: add support for keyword arguments
Yuya Nishihara <yuya@tcha.org>
parents:
31820
diff
changeset
|
450 |
|
38433
aa98392eb5b0
templatefuncs: declare resource requirements for future use
Yuya Nishihara <yuya@tcha.org>
parents:
37716
diff
changeset
|
451 |
def _extrasetup(self, name, func, argspec=None, requires=()): |
31886
bdda942f4b9c
templater: add support for keyword arguments
Yuya Nishihara <yuya@tcha.org>
parents:
31820
diff
changeset
|
452 |
func._argspec = argspec |
38433
aa98392eb5b0
templatefuncs: declare resource requirements for future use
Yuya Nishihara <yuya@tcha.org>
parents:
37716
diff
changeset
|
453 |
func._requires = requires |
33725
50c44dee741a
filemerge: move decorator definition for internal merge tools to registrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
33139
diff
changeset
|
454 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
455 |
|
33725
50c44dee741a
filemerge: move decorator definition for internal merge tools to registrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
33139
diff
changeset
|
456 |
class internalmerge(_funcregistrarbase): |
50c44dee741a
filemerge: move decorator definition for internal merge tools to registrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
33139
diff
changeset
|
457 |
"""Decorator to register in-process merge tool |
50c44dee741a
filemerge: move decorator definition for internal merge tools to registrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
33139
diff
changeset
|
458 |
|
50c44dee741a
filemerge: move decorator definition for internal merge tools to registrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
33139
diff
changeset
|
459 |
Usage:: |
50c44dee741a
filemerge: move decorator definition for internal merge tools to registrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
33139
diff
changeset
|
460 |
|
50c44dee741a
filemerge: move decorator definition for internal merge tools to registrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
33139
diff
changeset
|
461 |
internalmerge = registrar.internalmerge() |
50c44dee741a
filemerge: move decorator definition for internal merge tools to registrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
33139
diff
changeset
|
462 |
|
46015
c1bb02738f96
registrar: clarify the documentation about some byte strings being required
Matt Harbison <matt_harbison@yahoo.com>
parents:
45957
diff
changeset
|
463 |
@internalmerge(b'mymerge', internalmerge.mergeonly, |
39159
5d3b58472660
filemerge: set actual capabilities of internal merge tools
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
38969
diff
changeset
|
464 |
onfailure=None, precheck=None, |
5d3b58472660
filemerge: set actual capabilities of internal merge tools
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
38969
diff
changeset
|
465 |
binary=False, symlink=False): |
33725
50c44dee741a
filemerge: move decorator definition for internal merge tools to registrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
33139
diff
changeset
|
466 |
def mymergefunc(repo, mynode, orig, fcd, fco, fca, |
50c44dee741a
filemerge: move decorator definition for internal merge tools to registrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
33139
diff
changeset
|
467 |
toolconf, files, labels=None): |
50c44dee741a
filemerge: move decorator definition for internal merge tools to registrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
33139
diff
changeset
|
468 |
'''Explanation of this internal merge tool .... |
50c44dee741a
filemerge: move decorator definition for internal merge tools to registrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
33139
diff
changeset
|
469 |
''' |
50c44dee741a
filemerge: move decorator definition for internal merge tools to registrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
33139
diff
changeset
|
470 |
return 1, False # means "conflicted", "no deletion needed" |
50c44dee741a
filemerge: move decorator definition for internal merge tools to registrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
33139
diff
changeset
|
471 |
|
50c44dee741a
filemerge: move decorator definition for internal merge tools to registrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
33139
diff
changeset
|
472 |
The first string argument is used to compose actual merge tool name, |
50c44dee741a
filemerge: move decorator definition for internal merge tools to registrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
33139
diff
changeset
|
473 |
":name" and "internal:name" (the latter is historical one). |
50c44dee741a
filemerge: move decorator definition for internal merge tools to registrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
33139
diff
changeset
|
474 |
|
50c44dee741a
filemerge: move decorator definition for internal merge tools to registrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
33139
diff
changeset
|
475 |
The second argument is one of merge types below: |
50c44dee741a
filemerge: move decorator definition for internal merge tools to registrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
33139
diff
changeset
|
476 |
|
50c44dee741a
filemerge: move decorator definition for internal merge tools to registrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
33139
diff
changeset
|
477 |
========== ======== ======== ========= |
50c44dee741a
filemerge: move decorator definition for internal merge tools to registrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
33139
diff
changeset
|
478 |
merge type precheck premerge fullmerge |
50c44dee741a
filemerge: move decorator definition for internal merge tools to registrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
33139
diff
changeset
|
479 |
========== ======== ======== ========= |
50c44dee741a
filemerge: move decorator definition for internal merge tools to registrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
33139
diff
changeset
|
480 |
nomerge x x x |
50c44dee741a
filemerge: move decorator definition for internal merge tools to registrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
33139
diff
changeset
|
481 |
mergeonly o x o |
50c44dee741a
filemerge: move decorator definition for internal merge tools to registrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
33139
diff
changeset
|
482 |
fullmerge o o o |
50c44dee741a
filemerge: move decorator definition for internal merge tools to registrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
33139
diff
changeset
|
483 |
========== ======== ======== ========= |
50c44dee741a
filemerge: move decorator definition for internal merge tools to registrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
33139
diff
changeset
|
484 |
|
34437
c1fe66e89f57
registrar: fixing typo in comment
Saurabh Singh <singhsrb@fb.com>
parents:
34382
diff
changeset
|
485 |
Optional argument 'onfailure' is the format of warning message |
33725
50c44dee741a
filemerge: move decorator definition for internal merge tools to registrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
33139
diff
changeset
|
486 |
to be used at failure of merging (target filename is specified |
50c44dee741a
filemerge: move decorator definition for internal merge tools to registrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
33139
diff
changeset
|
487 |
at formatting). Or, None or so, if warning message should be |
50c44dee741a
filemerge: move decorator definition for internal merge tools to registrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
33139
diff
changeset
|
488 |
suppressed. |
50c44dee741a
filemerge: move decorator definition for internal merge tools to registrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
33139
diff
changeset
|
489 |
|
50c44dee741a
filemerge: move decorator definition for internal merge tools to registrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
33139
diff
changeset
|
490 |
Optional argument 'precheck' is the function to be used |
50c44dee741a
filemerge: move decorator definition for internal merge tools to registrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
33139
diff
changeset
|
491 |
before actual invocation of internal merge tool itself. |
50c44dee741a
filemerge: move decorator definition for internal merge tools to registrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
33139
diff
changeset
|
492 |
It takes as same arguments as internal merge tool does, other than |
50c44dee741a
filemerge: move decorator definition for internal merge tools to registrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
33139
diff
changeset
|
493 |
'files' and 'labels'. If it returns false value, merging is aborted |
50c44dee741a
filemerge: move decorator definition for internal merge tools to registrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
33139
diff
changeset
|
494 |
immediately (and file is marked as "unresolved"). |
50c44dee741a
filemerge: move decorator definition for internal merge tools to registrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
33139
diff
changeset
|
495 |
|
39159
5d3b58472660
filemerge: set actual capabilities of internal merge tools
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
38969
diff
changeset
|
496 |
Optional argument 'binary' is a binary files capability of internal |
5d3b58472660
filemerge: set actual capabilities of internal merge tools
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
38969
diff
changeset
|
497 |
merge tool. 'nomerge' merge type implies binary=True. |
5d3b58472660
filemerge: set actual capabilities of internal merge tools
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
38969
diff
changeset
|
498 |
|
5d3b58472660
filemerge: set actual capabilities of internal merge tools
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
38969
diff
changeset
|
499 |
Optional argument 'symlink' is a symlinks capability of inetrnal |
5d3b58472660
filemerge: set actual capabilities of internal merge tools
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
38969
diff
changeset
|
500 |
merge function. 'nomerge' merge type implies symlink=True. |
5d3b58472660
filemerge: set actual capabilities of internal merge tools
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
38969
diff
changeset
|
501 |
|
33725
50c44dee741a
filemerge: move decorator definition for internal merge tools to registrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
33139
diff
changeset
|
502 |
'internalmerge' instance in example above can be used to |
50c44dee741a
filemerge: move decorator definition for internal merge tools to registrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
33139
diff
changeset
|
503 |
decorate multiple functions. |
50c44dee741a
filemerge: move decorator definition for internal merge tools to registrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
33139
diff
changeset
|
504 |
|
50c44dee741a
filemerge: move decorator definition for internal merge tools to registrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
33139
diff
changeset
|
505 |
Decorated functions are registered automatically at loading |
50c44dee741a
filemerge: move decorator definition for internal merge tools to registrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
33139
diff
changeset
|
506 |
extension, if an instance named as 'internalmerge' is used for |
50c44dee741a
filemerge: move decorator definition for internal merge tools to registrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
33139
diff
changeset
|
507 |
decorating in extension. |
50c44dee741a
filemerge: move decorator definition for internal merge tools to registrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
33139
diff
changeset
|
508 |
|
50c44dee741a
filemerge: move decorator definition for internal merge tools to registrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
33139
diff
changeset
|
509 |
Otherwise, explicit 'filemerge.loadinternalmerge()' is needed. |
50c44dee741a
filemerge: move decorator definition for internal merge tools to registrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
33139
diff
changeset
|
510 |
""" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
511 |
|
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
512 |
_docformat = b"``:%s``\n %s" |
33725
50c44dee741a
filemerge: move decorator definition for internal merge tools to registrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
33139
diff
changeset
|
513 |
|
50c44dee741a
filemerge: move decorator definition for internal merge tools to registrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
33139
diff
changeset
|
514 |
# merge type definitions: |
50c44dee741a
filemerge: move decorator definition for internal merge tools to registrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
33139
diff
changeset
|
515 |
nomerge = None |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
516 |
mergeonly = b'mergeonly' # just the full merge, no premerge |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
517 |
fullmerge = b'fullmerge' # both premerge and merge |
33725
50c44dee741a
filemerge: move decorator definition for internal merge tools to registrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
33139
diff
changeset
|
518 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
519 |
def _extrasetup( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
520 |
self, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
521 |
name, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
522 |
func, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
523 |
mergetype, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
524 |
onfailure=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
525 |
precheck=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
526 |
binary=False, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
527 |
symlink=False, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
528 |
): |
33725
50c44dee741a
filemerge: move decorator definition for internal merge tools to registrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
33139
diff
changeset
|
529 |
func.mergetype = mergetype |
50c44dee741a
filemerge: move decorator definition for internal merge tools to registrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
33139
diff
changeset
|
530 |
func.onfailure = onfailure |
50c44dee741a
filemerge: move decorator definition for internal merge tools to registrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
33139
diff
changeset
|
531 |
func.precheck = precheck |
39159
5d3b58472660
filemerge: set actual capabilities of internal merge tools
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
38969
diff
changeset
|
532 |
|
5d3b58472660
filemerge: set actual capabilities of internal merge tools
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
38969
diff
changeset
|
533 |
binarycap = binary or mergetype == self.nomerge |
5d3b58472660
filemerge: set actual capabilities of internal merge tools
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
38969
diff
changeset
|
534 |
symlinkcap = symlink or mergetype == self.nomerge |
5d3b58472660
filemerge: set actual capabilities of internal merge tools
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
38969
diff
changeset
|
535 |
|
5d3b58472660
filemerge: set actual capabilities of internal merge tools
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
38969
diff
changeset
|
536 |
# actual capabilities, which this internal merge tool has |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
537 |
func.capabilities = {b"binary": binarycap, b"symlink": symlinkcap} |