Mercurial > evolve
comparison hgext3rd/topic/compat.py @ 6360:e959390490c2
branching: merge with stable
author | Anton Shestakov <av6@dwimlabs.net> |
---|---|
date | Fri, 09 Dec 2022 15:01:59 +0400 |
parents | f4ffe1e67a9b |
children | d13cfd9eb6c0 |
comparison
equal
deleted
inserted
replaced
6359:cb9e77506cbc | 6360:e959390490c2 |
---|---|
5 """ | 5 """ |
6 Compatibility module | 6 Compatibility module |
7 """ | 7 """ |
8 from __future__ import absolute_import | 8 from __future__ import absolute_import |
9 | 9 |
10 from mercurial.i18n import _ | |
10 from mercurial import ( | 11 from mercurial import ( |
11 cmdutil, | 12 cmdutil, |
13 error, | |
12 extensions, | 14 extensions, |
13 pycompat, | 15 pycompat, |
14 registrar, | |
15 util, | 16 util, |
16 ) | 17 ) |
17 | 18 |
18 if pycompat.ispy3: | 19 if pycompat.ispy3: |
19 def branchmapitems(branchmap): | 20 def branchmapitems(branchmap): |
22 # py3-transform: off | 23 # py3-transform: off |
23 def branchmapitems(branchmap): | 24 def branchmapitems(branchmap): |
24 return branchmap.iteritems() | 25 return branchmap.iteritems() |
25 # py3-transform: on | 26 # py3-transform: on |
26 | 27 |
27 # help category compatibility | 28 def bcentries(branchcache): |
28 # hg <= 4.7 (c303d65d2e34) | 29 if util.safehasattr(branchcache, '_entries'): |
29 def helpcategorykwargs(categoryname): | 30 return branchcache._entries |
30 """Backwards-compatible specification of the helpategory argument.""" | 31 else: |
31 category = getattr(registrar.command, categoryname, None) | 32 # hg <= 4.9 (624d6683c705+b137a6793c51) |
32 if not category: | 33 return branchcache |
33 return {} | |
34 return {'helpcategory': category} | |
35 | 34 |
36 # nodemap.get and index.[has_node|rev|get_rev] | 35 # nodemap.get and index.[has_node|rev|get_rev] |
37 # hg <= 5.2 (02802fa87b74) | 36 # hg <= 5.2 (02802fa87b74) |
38 def getgetrev(cl): | 37 def getgetrev(cl): |
39 """Returns index.get_rev or nodemap.get (for pre-5.3 Mercurial).""" | 38 """Returns index.get_rev or nodemap.get (for pre-5.3 Mercurial).""" |
57 def _override(orig, repo, node, branch, bheads=None, opts=None): | 56 def _override(orig, repo, node, branch, bheads=None, opts=None): |
58 def _orig(repo, node, branch, bheads=None, tip=None, opts=None): | 57 def _orig(repo, node, branch, bheads=None, tip=None, opts=None): |
59 return orig(repo, node, branch, bheads=bheads, opts=opts) | 58 return orig(repo, node, branch, bheads=bheads, opts=opts) |
60 return overridefn(_orig, repo, node, branch, bheads=bheads, tip=None, opts=opts) | 59 return overridefn(_orig, repo, node, branch, bheads=bheads, tip=None, opts=opts) |
61 extensions.wrapfunction(cmdutil, 'commitstatus', _override) | 60 extensions.wrapfunction(cmdutil, 'commitstatus', _override) |
61 | |
62 if util.safehasattr(error, 'InputError'): | |
63 InputError = error.InputError | |
64 else: | |
65 # hg <= 5.6 (8d72e29ad1e0) | |
66 InputError = error.Abort | |
67 | |
68 if util.safehasattr(error, 'StateError'): | |
69 StateError = error.StateError | |
70 else: | |
71 # hg <= 5.6 (527ce85c2e60) | |
72 StateError = error.Abort | |
73 | |
74 if util.safehasattr(error, 'CanceledError'): | |
75 CanceledError = error.CanceledError | |
76 else: | |
77 # hg <= 5.6 (ac362d5a7893) | |
78 CanceledError = error.Abort | |
79 | |
80 if util.safehasattr(cmdutil, 'check_at_most_one_arg'): | |
81 def check_at_most_one_arg(opts, *args): | |
82 return cmdutil.check_at_most_one_arg(opts, *args) | |
83 else: | |
84 # hg <= 5.2 (d587937600be) | |
85 def check_at_most_one_arg(opts, *args): | |
86 def to_display(name): | |
87 return pycompat.sysbytes(name).replace(b'_', b'-') | |
88 | |
89 previous = None | |
90 for x in args: | |
91 if opts.get(x): | |
92 if previous: | |
93 raise InputError(_(b'cannot specify both --%s and --%s') | |
94 % (to_display(previous), to_display(x))) | |
95 previous = x | |
96 return previous | |
97 | |
98 if util.safehasattr(cmdutil, 'check_incompatible_arguments'): | |
99 code = cmdutil.check_incompatible_arguments.__code__ | |
100 if r'others' in code.co_varnames[:code.co_argcount]: | |
101 def check_incompatible_arguments(opts, first, others): | |
102 return cmdutil.check_incompatible_arguments(opts, first, others) | |
103 else: | |
104 # hg <= 5.3 (d4c1501225c4) | |
105 def check_incompatible_arguments(opts, first, others): | |
106 return cmdutil.check_incompatible_arguments(opts, first, *others) | |
107 else: | |
108 # hg <= 5.2 (023ad45e2fd2) | |
109 def check_incompatible_arguments(opts, first, others): | |
110 for other in others: | |
111 check_at_most_one_arg(opts, first, other) |