Mercurial > hgsubversion
annotate hgsubversion/compathacks.py @ 1601:5d8603f080c5
compathacks: add compat code for ui.makeprogress() deprecation
ui.makeprogress() is deprecated and will be dropped in 5.1. This patch adds
compat code for that. The compat code is plain copy of compat code available in
evolve extension.
author | Pulkit Goyal <pulkit@yandex-team.ru> |
---|---|
date | Mon, 04 Feb 2019 20:56:39 +0300 |
parents | 7bb6562feb85 |
children | 6a6ce9d9da35 |
rev | line source |
---|---|
1139
d1bd52202c6d
compathacks: specify for generic compatibility hacks
Sean Farley <sean.michael.farley@gmail.com>
parents:
1138
diff
changeset
|
1 """Functions to work around API changes.""" |
1103
6e1dbf6cbc92
compathacks: new module to collect hacks to work around hg internals changing
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
2 |
1237
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
3 import errno |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
4 import sys |
1103
6e1dbf6cbc92
compathacks: new module to collect hacks to work around hg internals changing
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
5 |
1601
5d8603f080c5
compathacks: add compat code for ui.makeprogress() deprecation
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
1599
diff
changeset
|
6 from mercurial import ui as uimod, util |
5d8603f080c5
compathacks: add compat code for ui.makeprogress() deprecation
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
1599
diff
changeset
|
7 |
5d8603f080c5
compathacks: add compat code for ui.makeprogress() deprecation
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
1599
diff
changeset
|
8 # ui.makeprogress will be dropped after hg-5.1 |
5d8603f080c5
compathacks: add compat code for ui.makeprogress() deprecation
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
1599
diff
changeset
|
9 if util.safehasattr(uimod.ui, 'makeprogress'): |
5d8603f080c5
compathacks: add compat code for ui.makeprogress() deprecation
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
1599
diff
changeset
|
10 def progress(ui, topic, pos, item="", unit="", total=None): |
5d8603f080c5
compathacks: add compat code for ui.makeprogress() deprecation
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
1599
diff
changeset
|
11 progress = ui.makeprogress(topic, unit, total) |
5d8603f080c5
compathacks: add compat code for ui.makeprogress() deprecation
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
1599
diff
changeset
|
12 if pos is not None: |
5d8603f080c5
compathacks: add compat code for ui.makeprogress() deprecation
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
1599
diff
changeset
|
13 progress.update(pos, item=item) |
5d8603f080c5
compathacks: add compat code for ui.makeprogress() deprecation
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
1599
diff
changeset
|
14 else: |
5d8603f080c5
compathacks: add compat code for ui.makeprogress() deprecation
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
1599
diff
changeset
|
15 progress.complete() |
5d8603f080c5
compathacks: add compat code for ui.makeprogress() deprecation
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
1599
diff
changeset
|
16 else: |
5d8603f080c5
compathacks: add compat code for ui.makeprogress() deprecation
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
1599
diff
changeset
|
17 def progress(ui, topic, pos, item="", unit="", total=None): |
5d8603f080c5
compathacks: add compat code for ui.makeprogress() deprecation
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
1599
diff
changeset
|
18 ui.progress(topic, pos, item="", unit="", total=None) |
1405
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
19 |
1218
68e6927fa387
compathacks: add wrapper for memfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents:
1103
diff
changeset
|
20 def pickle_load(f): |
68e6927fa387
compathacks: add wrapper for memfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents:
1103
diff
changeset
|
21 import cPickle as pickle |
68e6927fa387
compathacks: add wrapper for memfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents:
1103
diff
changeset
|
22 f.seek(0) |
68e6927fa387
compathacks: add wrapper for memfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents:
1103
diff
changeset
|
23 return pickle.load(f) |
68e6927fa387
compathacks: add wrapper for memfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents:
1103
diff
changeset
|
24 |
1549
8410a978c650
compathacks: be compatible with upstream 8a0cac20a1ad memfilectx change
Jun Wu <quark@fb.com>
parents:
1405
diff
changeset
|
25 def makememfilectx(repo, memctx, path, data, islink, isexec, copied): |
1218
68e6927fa387
compathacks: add wrapper for memfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents:
1103
diff
changeset
|
26 """Return a memfilectx |
68e6927fa387
compathacks: add wrapper for memfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents:
1103
diff
changeset
|
27 |
1549
8410a978c650
compathacks: be compatible with upstream 8a0cac20a1ad memfilectx change
Jun Wu <quark@fb.com>
parents:
1405
diff
changeset
|
28 Works around API change by 8a0cac20a1ad (first in 4.5). |
1218
68e6927fa387
compathacks: add wrapper for memfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents:
1103
diff
changeset
|
29 """ |
68e6927fa387
compathacks: add wrapper for memfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents:
1103
diff
changeset
|
30 from mercurial import context |
68e6927fa387
compathacks: add wrapper for memfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents:
1103
diff
changeset
|
31 try: |
1549
8410a978c650
compathacks: be compatible with upstream 8a0cac20a1ad memfilectx change
Jun Wu <quark@fb.com>
parents:
1405
diff
changeset
|
32 return context.memfilectx(repo=repo, path=path, data=data, |
8410a978c650
compathacks: be compatible with upstream 8a0cac20a1ad memfilectx change
Jun Wu <quark@fb.com>
parents:
1405
diff
changeset
|
33 islink=islink, isexec=isexec, copied=copied, |
8410a978c650
compathacks: be compatible with upstream 8a0cac20a1ad memfilectx change
Jun Wu <quark@fb.com>
parents:
1405
diff
changeset
|
34 changectx=memctx) |
1218
68e6927fa387
compathacks: add wrapper for memfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents:
1103
diff
changeset
|
35 except TypeError: |
1549
8410a978c650
compathacks: be compatible with upstream 8a0cac20a1ad memfilectx change
Jun Wu <quark@fb.com>
parents:
1405
diff
changeset
|
36 return context.memfilectx(repo=repo, path=path, data=data, |
8410a978c650
compathacks: be compatible with upstream 8a0cac20a1ad memfilectx change
Jun Wu <quark@fb.com>
parents:
1405
diff
changeset
|
37 islink=islink, isexec=isexec, copied=copied) |
1237
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
38 |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
39 def filectxfn_deleted(memctx, path): |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
40 """ |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
41 Return None or raise an IOError as necessary if path is deleted. |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
42 |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
43 Call as: |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
44 |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
45 if path_missing: |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
46 return compathacks.filectxfn_deleted(memctx, path) |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
47 |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
48 Works around filectxfn's contract changing between 3.1 and 3.2: 3.2 onwards, |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
49 for deleted files, filectxfn should return None rather than returning |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
50 IOError. |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
51 """ |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
52 if getattr(memctx, '_returnnoneformissingfiles', False): |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
53 return None |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
54 raise IOError(errno.ENOENT, '%s is deleted' % path) |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
55 |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
56 def filectxfn_deleted_reraise(memctx): |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
57 """ |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
58 Return None or reraise exc as necessary. |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
59 |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
60 Call as: |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
61 |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
62 try: |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
63 # code that raises IOError if the path is missing |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
64 except IOError: |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
65 return compathacks.filectxfn_deleted_reraise(memctx) |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
66 |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
67 Works around filectxfn's contract changing between 3.1 and 3.2: 3.2 onwards, |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
68 for deleted files, filectxfn should return None rather than returning |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
69 IOError. |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
70 """ |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
71 exc_info = sys.exc_info() |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
72 if (exc_info[1].errno == errno.ENOENT and |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
73 getattr(memctx, '_returnnoneformissingfiles', False)): |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
74 return None |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
75 # preserve traceback info |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
76 raise exc_info[0], exc_info[1], exc_info[2] |
1405
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
77 |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
78 # copied from hg 3.8 |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
79 class _funcregistrarbase(object): |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
80 """Base of decorator to register a fuction for specific purpose |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
81 |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
82 This decorator stores decorated functions into own dict 'table'. |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
83 |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
84 The least derived class can be defined by overriding 'formatdoc', |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
85 for example:: |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
86 |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
87 class keyword(_funcregistrarbase): |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
88 _docformat = ":%s: %s" |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
89 |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
90 This should be used as below: |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
91 |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
92 keyword = registrar.keyword() |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
93 |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
94 @keyword('bar') |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
95 def barfunc(*args, **kwargs): |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
96 '''Explanation of bar keyword .... |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
97 ''' |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
98 pass |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
99 |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
100 In this case: |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
101 |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
102 - 'barfunc' is stored as 'bar' in '_table' of an instance 'keyword' above |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
103 - 'barfunc.__doc__' becomes ":bar: Explanation of bar keyword" |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
104 """ |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
105 def __init__(self, table=None): |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
106 if table is None: |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
107 self._table = {} |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
108 else: |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
109 self._table = table |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
110 |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
111 def __call__(self, decl, *args, **kwargs): |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
112 return lambda func: self._doregister(func, decl, *args, **kwargs) |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
113 |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
114 def _doregister(self, func, decl, *args, **kwargs): |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
115 name = self._getname(decl) |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
116 |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
117 if func.__doc__ and not util.safehasattr(func, '_origdoc'): |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
118 doc = func.__doc__.strip() |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
119 func._origdoc = doc |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
120 func.__doc__ = self._formatdoc(decl, doc) |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
121 |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
122 self._table[name] = func |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
123 self._extrasetup(name, func, *args, **kwargs) |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
124 |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
125 return func |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
126 |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
127 def _parsefuncdecl(self, decl): |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
128 """Parse function declaration and return the name of function in it |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
129 """ |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
130 i = decl.find('(') |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
131 if i >= 0: |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
132 return decl[:i] |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
133 else: |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
134 return decl |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
135 |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
136 def _getname(self, decl): |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
137 """Return the name of the registered function from decl |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
138 |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
139 Derived class should override this, if it allows more |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
140 descriptive 'decl' string than just a name. |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
141 """ |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
142 return decl |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
143 |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
144 _docformat = None |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
145 |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
146 def _formatdoc(self, decl, doc): |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
147 """Return formatted document of the registered function for help |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
148 |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
149 'doc' is '__doc__.strip()' of the registered function. |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
150 """ |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
151 return self._docformat % (decl, doc) |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
152 |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
153 def _extrasetup(self, name, func): |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
154 """Execute exra setup for registered function, if needed |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
155 """ |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
156 pass |
1572
51e105c7f0c6
compathacks: deal with removed aliases in mercurial.util
Augie Fackler <raf@durin42.com>
parents:
1549
diff
changeset
|
157 |
51e105c7f0c6
compathacks: deal with removed aliases in mercurial.util
Augie Fackler <raf@durin42.com>
parents:
1549
diff
changeset
|
158 try: |
51e105c7f0c6
compathacks: deal with removed aliases in mercurial.util
Augie Fackler <raf@durin42.com>
parents:
1549
diff
changeset
|
159 binary = util.binary |
51e105c7f0c6
compathacks: deal with removed aliases in mercurial.util
Augie Fackler <raf@durin42.com>
parents:
1549
diff
changeset
|
160 except AttributeError: |
51e105c7f0c6
compathacks: deal with removed aliases in mercurial.util
Augie Fackler <raf@durin42.com>
parents:
1549
diff
changeset
|
161 from mercurial.utils import stringutil |
51e105c7f0c6
compathacks: deal with removed aliases in mercurial.util
Augie Fackler <raf@durin42.com>
parents:
1549
diff
changeset
|
162 binary = stringutil.binary |
51e105c7f0c6
compathacks: deal with removed aliases in mercurial.util
Augie Fackler <raf@durin42.com>
parents:
1549
diff
changeset
|
163 |
51e105c7f0c6
compathacks: deal with removed aliases in mercurial.util
Augie Fackler <raf@durin42.com>
parents:
1549
diff
changeset
|
164 try: |
51e105c7f0c6
compathacks: deal with removed aliases in mercurial.util
Augie Fackler <raf@durin42.com>
parents:
1549
diff
changeset
|
165 datestr = util.datestr |
51e105c7f0c6
compathacks: deal with removed aliases in mercurial.util
Augie Fackler <raf@durin42.com>
parents:
1549
diff
changeset
|
166 except AttributeError: |
51e105c7f0c6
compathacks: deal with removed aliases in mercurial.util
Augie Fackler <raf@durin42.com>
parents:
1549
diff
changeset
|
167 from mercurial.utils import dateutil |
51e105c7f0c6
compathacks: deal with removed aliases in mercurial.util
Augie Fackler <raf@durin42.com>
parents:
1549
diff
changeset
|
168 datestr = dateutil.datestr |