Mercurial > hgsubversion
annotate hgsubversion/compathacks.py @ 1602:6a6ce9d9da35 default tip
compathacks: make memfilectx construction compatible with hg5.0
'copied' in memfilectx was renamed to 'copysource' in 550a172a603b9ed in core
mercurial.
author | Pulkit Goyal <pulkit@yandex-team.ru> |
---|---|
date | Fri, 19 Apr 2019 16:28:39 +0300 |
parents | 5d8603f080c5 |
children |
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). |
1602
6a6ce9d9da35
compathacks: make memfilectx construction compatible with hg5.0
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
1601
diff
changeset
|
29 and also API change by 550a172a603b9e (first in 5.0) |
1218
68e6927fa387
compathacks: add wrapper for memfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents:
1103
diff
changeset
|
30 """ |
68e6927fa387
compathacks: add wrapper for memfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents:
1103
diff
changeset
|
31 from mercurial import context |
68e6927fa387
compathacks: add wrapper for memfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents:
1103
diff
changeset
|
32 try: |
1549
8410a978c650
compathacks: be compatible with upstream 8a0cac20a1ad memfilectx change
Jun Wu <quark@fb.com>
parents:
1405
diff
changeset
|
33 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
|
34 islink=islink, isexec=isexec, copied=copied, |
8410a978c650
compathacks: be compatible with upstream 8a0cac20a1ad memfilectx change
Jun Wu <quark@fb.com>
parents:
1405
diff
changeset
|
35 changectx=memctx) |
1218
68e6927fa387
compathacks: add wrapper for memfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents:
1103
diff
changeset
|
36 except TypeError: |
1602
6a6ce9d9da35
compathacks: make memfilectx construction compatible with hg5.0
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
1601
diff
changeset
|
37 try: |
6a6ce9d9da35
compathacks: make memfilectx construction compatible with hg5.0
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
1601
diff
changeset
|
38 return context.memfilectx(repo=repo, path=path, data=data, |
6a6ce9d9da35
compathacks: make memfilectx construction compatible with hg5.0
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
1601
diff
changeset
|
39 islink=islink, isexec=isexec, |
6a6ce9d9da35
compathacks: make memfilectx construction compatible with hg5.0
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
1601
diff
changeset
|
40 copied=copied) |
6a6ce9d9da35
compathacks: make memfilectx construction compatible with hg5.0
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
1601
diff
changeset
|
41 except TypeError: |
6a6ce9d9da35
compathacks: make memfilectx construction compatible with hg5.0
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
1601
diff
changeset
|
42 return context.memfilectx(repo=repo, changectx=memctx, |
6a6ce9d9da35
compathacks: make memfilectx construction compatible with hg5.0
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
1601
diff
changeset
|
43 path=path, data=data, |
6a6ce9d9da35
compathacks: make memfilectx construction compatible with hg5.0
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
1601
diff
changeset
|
44 islink=islink, isexec=isexec, |
6a6ce9d9da35
compathacks: make memfilectx construction compatible with hg5.0
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
1601
diff
changeset
|
45 copysource=copied) |
1237
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
46 |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
47 def filectxfn_deleted(memctx, path): |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
48 """ |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
49 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
|
50 |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
51 Call as: |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
52 |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
53 if path_missing: |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
54 return compathacks.filectxfn_deleted(memctx, 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 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
|
57 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
|
58 IOError. |
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 if getattr(memctx, '_returnnoneformissingfiles', False): |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
61 return None |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
62 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
|
63 |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
64 def filectxfn_deleted_reraise(memctx): |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
65 """ |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
66 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
|
67 |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
68 Call as: |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
69 |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
70 try: |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
71 # 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
|
72 except IOError: |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
73 return compathacks.filectxfn_deleted_reraise(memctx) |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
74 |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
75 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
|
76 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
|
77 IOError. |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
78 """ |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
79 exc_info = sys.exc_info() |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
80 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
|
81 getattr(memctx, '_returnnoneformissingfiles', False)): |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
82 return None |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
83 # preserve traceback info |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
84 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
|
85 |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
86 # copied from hg 3.8 |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
87 class _funcregistrarbase(object): |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
88 """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
|
89 |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
90 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
|
91 |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
92 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
|
93 for example:: |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
94 |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
95 class keyword(_funcregistrarbase): |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
96 _docformat = ":%s: %s" |
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 This should be used as below: |
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 keyword = registrar.keyword() |
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 @keyword('bar') |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
103 def barfunc(*args, **kwargs): |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
104 '''Explanation of bar keyword .... |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
105 ''' |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
106 pass |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
107 |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
108 In this case: |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
109 |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
110 - '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
|
111 - 'barfunc.__doc__' becomes ":bar: Explanation of bar keyword" |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
112 """ |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
113 def __init__(self, table=None): |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
114 if table is None: |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
115 self._table = {} |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
116 else: |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
117 self._table = table |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
118 |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
119 def __call__(self, decl, *args, **kwargs): |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
120 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
|
121 |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
122 def _doregister(self, func, decl, *args, **kwargs): |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
123 name = self._getname(decl) |
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 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
|
126 doc = func.__doc__.strip() |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
127 func._origdoc = doc |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
128 func.__doc__ = self._formatdoc(decl, doc) |
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 self._table[name] = func |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
131 self._extrasetup(name, func, *args, **kwargs) |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
132 |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
133 return func |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
134 |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
135 def _parsefuncdecl(self, decl): |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
136 """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
|
137 """ |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
138 i = decl.find('(') |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
139 if i >= 0: |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
140 return decl[:i] |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
141 else: |
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 def _getname(self, decl): |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
145 """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
|
146 |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
147 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
|
148 descriptive 'decl' string than just a name. |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
149 """ |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
150 return decl |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
151 |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
152 _docformat = None |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
153 |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
154 def _formatdoc(self, decl, doc): |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
155 """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
|
156 |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
157 'doc' is '__doc__.strip()' of the registered function. |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
158 """ |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
159 return self._docformat % (decl, doc) |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
160 |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
161 def _extrasetup(self, name, func): |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
162 """Execute exra setup for registered function, if needed |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
163 """ |
c5b7fb8911c0
compathacks: copy _funcregistrarbase for older mercurial
Sean Farley <sean@farley.io>
parents:
1237
diff
changeset
|
164 pass |
1572
51e105c7f0c6
compathacks: deal with removed aliases in mercurial.util
Augie Fackler <raf@durin42.com>
parents:
1549
diff
changeset
|
165 |
51e105c7f0c6
compathacks: deal with removed aliases in mercurial.util
Augie Fackler <raf@durin42.com>
parents:
1549
diff
changeset
|
166 try: |
51e105c7f0c6
compathacks: deal with removed aliases in mercurial.util
Augie Fackler <raf@durin42.com>
parents:
1549
diff
changeset
|
167 binary = util.binary |
51e105c7f0c6
compathacks: deal with removed aliases in mercurial.util
Augie Fackler <raf@durin42.com>
parents:
1549
diff
changeset
|
168 except AttributeError: |
51e105c7f0c6
compathacks: deal with removed aliases in mercurial.util
Augie Fackler <raf@durin42.com>
parents:
1549
diff
changeset
|
169 from mercurial.utils import stringutil |
51e105c7f0c6
compathacks: deal with removed aliases in mercurial.util
Augie Fackler <raf@durin42.com>
parents:
1549
diff
changeset
|
170 binary = stringutil.binary |
51e105c7f0c6
compathacks: deal with removed aliases in mercurial.util
Augie Fackler <raf@durin42.com>
parents:
1549
diff
changeset
|
171 |
51e105c7f0c6
compathacks: deal with removed aliases in mercurial.util
Augie Fackler <raf@durin42.com>
parents:
1549
diff
changeset
|
172 try: |
51e105c7f0c6
compathacks: deal with removed aliases in mercurial.util
Augie Fackler <raf@durin42.com>
parents:
1549
diff
changeset
|
173 datestr = util.datestr |
51e105c7f0c6
compathacks: deal with removed aliases in mercurial.util
Augie Fackler <raf@durin42.com>
parents:
1549
diff
changeset
|
174 except AttributeError: |
51e105c7f0c6
compathacks: deal with removed aliases in mercurial.util
Augie Fackler <raf@durin42.com>
parents:
1549
diff
changeset
|
175 from mercurial.utils import dateutil |
51e105c7f0c6
compathacks: deal with removed aliases in mercurial.util
Augie Fackler <raf@durin42.com>
parents:
1549
diff
changeset
|
176 datestr = dateutil.datestr |