annotate hgext3rd/topic/compat.py @ 6527:b9355f6f3093 stable 11.0.2

packaging: prepare evolve 11.0.2 and topic 1.0.2
author Anton Shestakov <av6@dwimlabs.net>
date Wed, 05 Jul 2023 14:33:09 -0300
parents f4ffe1e67a9b
children d13cfd9eb6c0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2922
66357d4d03b2 topic: centralize compatibility logic between hg versions into compat module
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
1 # Copyright 2017 FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
66357d4d03b2 topic: centralize compatibility logic between hg versions into compat module
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
2 #
66357d4d03b2 topic: centralize compatibility logic between hg versions into compat module
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
3 # This software may be used and distributed according to the terms of the
66357d4d03b2 topic: centralize compatibility logic between hg versions into compat module
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
4 # GNU General Public License version 2 or any later version.
66357d4d03b2 topic: centralize compatibility logic between hg versions into compat module
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
5 """
66357d4d03b2 topic: centralize compatibility logic between hg versions into compat module
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
6 Compatibility module
66357d4d03b2 topic: centralize compatibility logic between hg versions into compat module
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
7 """
66357d4d03b2 topic: centralize compatibility logic between hg versions into compat module
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
8 from __future__ import absolute_import
66357d4d03b2 topic: centralize compatibility logic between hg versions into compat module
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
9
6320
0c780d972350 topic: use check_incompatible_arguments() for --list with --clear or --rev
Anton Shestakov <av6@dwimlabs.net>
parents: 6318
diff changeset
10 from mercurial.i18n import _
3094
e11e018e8338 compat: add an abstraction for 'scmutil.cleanupnodes'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3064
diff changeset
11 from mercurial import (
5665
dd9dba7c1d00 compat: make topics compatible across change to cmdutil.commitstatus()
Martin von Zweigbergk <martinvonz@google.com>
parents: 5426
diff changeset
12 cmdutil,
6318
3e488afe62f5 topic: use compat.InputError for conflicting CLI flags
Anton Shestakov <av6@dwimlabs.net>
parents: 6305
diff changeset
13 error,
5665
dd9dba7c1d00 compat: make topics compatible across change to cmdutil.commitstatus()
Martin von Zweigbergk <martinvonz@google.com>
parents: 5426
diff changeset
14 extensions,
4743
92e3db149d7d py3: call branchmap.items() on py3 and continue to call iteritems() on py2
Martin von Zweigbergk <martinvonz@google.com>
parents: 3701
diff changeset
15 pycompat,
4957
e8302f760a54 compat: compatibility for cl.nodemap.get vs cl.index.get_rev
Anton Shestakov <av6@dwimlabs.net>
parents: 4810
diff changeset
16 util,
3094
e11e018e8338 compat: add an abstraction for 'scmutil.cleanupnodes'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3064
diff changeset
17 )
2922
66357d4d03b2 topic: centralize compatibility logic between hg versions into compat module
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
18
4743
92e3db149d7d py3: call branchmap.items() on py3 and continue to call iteritems() on py2
Martin von Zweigbergk <martinvonz@google.com>
parents: 3701
diff changeset
19 if pycompat.ispy3:
92e3db149d7d py3: call branchmap.items() on py3 and continue to call iteritems() on py2
Martin von Zweigbergk <martinvonz@google.com>
parents: 3701
diff changeset
20 def branchmapitems(branchmap):
92e3db149d7d py3: call branchmap.items() on py3 and continue to call iteritems() on py2
Martin von Zweigbergk <martinvonz@google.com>
parents: 3701
diff changeset
21 return branchmap.items()
92e3db149d7d py3: call branchmap.items() on py3 and continue to call iteritems() on py2
Martin von Zweigbergk <martinvonz@google.com>
parents: 3701
diff changeset
22 else:
4810
03690f8d2b0a python3: add ignore block around python 2 compatibility if branch
Raphaël Gomès <rgomes@octobus.net>
parents: 4743
diff changeset
23 # py3-transform: off
4743
92e3db149d7d py3: call branchmap.items() on py3 and continue to call iteritems() on py2
Martin von Zweigbergk <martinvonz@google.com>
parents: 3701
diff changeset
24 def branchmapitems(branchmap):
92e3db149d7d py3: call branchmap.items() on py3 and continue to call iteritems() on py2
Martin von Zweigbergk <martinvonz@google.com>
parents: 3701
diff changeset
25 return branchmap.iteritems()
4810
03690f8d2b0a python3: add ignore block around python 2 compatibility if branch
Raphaël Gomès <rgomes@octobus.net>
parents: 4743
diff changeset
26 # py3-transform: on
4957
e8302f760a54 compat: compatibility for cl.nodemap.get vs cl.index.get_rev
Anton Shestakov <av6@dwimlabs.net>
parents: 4810
diff changeset
27
6333
f4ffe1e67a9b topic: move compatibility for branchcache._entries to topic/compat.py
Anton Shestakov <av6@dwimlabs.net>
parents: 6322
diff changeset
28 def bcentries(branchcache):
f4ffe1e67a9b topic: move compatibility for branchcache._entries to topic/compat.py
Anton Shestakov <av6@dwimlabs.net>
parents: 6322
diff changeset
29 if util.safehasattr(branchcache, '_entries'):
f4ffe1e67a9b topic: move compatibility for branchcache._entries to topic/compat.py
Anton Shestakov <av6@dwimlabs.net>
parents: 6322
diff changeset
30 return branchcache._entries
f4ffe1e67a9b topic: move compatibility for branchcache._entries to topic/compat.py
Anton Shestakov <av6@dwimlabs.net>
parents: 6322
diff changeset
31 else:
f4ffe1e67a9b topic: move compatibility for branchcache._entries to topic/compat.py
Anton Shestakov <av6@dwimlabs.net>
parents: 6322
diff changeset
32 # hg <= 4.9 (624d6683c705+b137a6793c51)
f4ffe1e67a9b topic: move compatibility for branchcache._entries to topic/compat.py
Anton Shestakov <av6@dwimlabs.net>
parents: 6322
diff changeset
33 return branchcache
f4ffe1e67a9b topic: move compatibility for branchcache._entries to topic/compat.py
Anton Shestakov <av6@dwimlabs.net>
parents: 6322
diff changeset
34
4957
e8302f760a54 compat: compatibility for cl.nodemap.get vs cl.index.get_rev
Anton Shestakov <av6@dwimlabs.net>
parents: 4810
diff changeset
35 # nodemap.get and index.[has_node|rev|get_rev]
5193
a4d081923c81 compat: update hg-X.Y compat comments and test them
Anton Shestakov <av6@dwimlabs.net>
parents: 4963
diff changeset
36 # hg <= 5.2 (02802fa87b74)
4957
e8302f760a54 compat: compatibility for cl.nodemap.get vs cl.index.get_rev
Anton Shestakov <av6@dwimlabs.net>
parents: 4810
diff changeset
37 def getgetrev(cl):
e8302f760a54 compat: compatibility for cl.nodemap.get vs cl.index.get_rev
Anton Shestakov <av6@dwimlabs.net>
parents: 4810
diff changeset
38 """Returns index.get_rev or nodemap.get (for pre-5.3 Mercurial)."""
e8302f760a54 compat: compatibility for cl.nodemap.get vs cl.index.get_rev
Anton Shestakov <av6@dwimlabs.net>
parents: 4810
diff changeset
39 if util.safehasattr(cl.index, 'get_rev'):
e8302f760a54 compat: compatibility for cl.nodemap.get vs cl.index.get_rev
Anton Shestakov <av6@dwimlabs.net>
parents: 4810
diff changeset
40 return cl.index.get_rev
e8302f760a54 compat: compatibility for cl.nodemap.get vs cl.index.get_rev
Anton Shestakov <av6@dwimlabs.net>
parents: 4810
diff changeset
41 return cl.nodemap.get
5426
86736040b0ec topic: compatibility with sparse phaseroots and phasesets in 5.5
Joerg Sonnenberger <joerg@bec.de>
parents: 5193
diff changeset
42
86736040b0ec topic: compatibility with sparse phaseroots and phasesets in 5.5
Joerg Sonnenberger <joerg@bec.de>
parents: 5193
diff changeset
43 # hg <= 5.4 (e2d17974a869)
86736040b0ec topic: compatibility with sparse phaseroots and phasesets in 5.5
Joerg Sonnenberger <joerg@bec.de>
parents: 5193
diff changeset
44 def nonpublicphaseroots(repo):
86736040b0ec topic: compatibility with sparse phaseroots and phasesets in 5.5
Joerg Sonnenberger <joerg@bec.de>
parents: 5193
diff changeset
45 if util.safehasattr(repo._phasecache, 'nonpublicphaseroots'):
86736040b0ec topic: compatibility with sparse phaseroots and phasesets in 5.5
Joerg Sonnenberger <joerg@bec.de>
parents: 5193
diff changeset
46 return repo._phasecache.nonpublicphaseroots(repo)
86736040b0ec topic: compatibility with sparse phaseroots and phasesets in 5.5
Joerg Sonnenberger <joerg@bec.de>
parents: 5193
diff changeset
47 return set().union(
86736040b0ec topic: compatibility with sparse phaseroots and phasesets in 5.5
Joerg Sonnenberger <joerg@bec.de>
parents: 5193
diff changeset
48 *[roots for roots in repo._phasecache.phaseroots[1:] if roots]
86736040b0ec topic: compatibility with sparse phaseroots and phasesets in 5.5
Joerg Sonnenberger <joerg@bec.de>
parents: 5193
diff changeset
49 )
5665
dd9dba7c1d00 compat: make topics compatible across change to cmdutil.commitstatus()
Martin von Zweigbergk <martinvonz@google.com>
parents: 5426
diff changeset
50
dd9dba7c1d00 compat: make topics compatible across change to cmdutil.commitstatus()
Martin von Zweigbergk <martinvonz@google.com>
parents: 5426
diff changeset
51 def overridecommitstatus(overridefn):
dd9dba7c1d00 compat: make topics compatible across change to cmdutil.commitstatus()
Martin von Zweigbergk <martinvonz@google.com>
parents: 5426
diff changeset
52 if r'tip' in cmdutil.commitstatus.__code__.co_varnames:
dd9dba7c1d00 compat: make topics compatible across change to cmdutil.commitstatus()
Martin von Zweigbergk <martinvonz@google.com>
parents: 5426
diff changeset
53 extensions.wrapfunction(cmdutil, 'commitstatus', overridefn)
dd9dba7c1d00 compat: make topics compatible across change to cmdutil.commitstatus()
Martin von Zweigbergk <martinvonz@google.com>
parents: 5426
diff changeset
54 else:
dd9dba7c1d00 compat: make topics compatible across change to cmdutil.commitstatus()
Martin von Zweigbergk <martinvonz@google.com>
parents: 5426
diff changeset
55 # hg <= 5.6 (976b26bdd0d8)
dd9dba7c1d00 compat: make topics compatible across change to cmdutil.commitstatus()
Martin von Zweigbergk <martinvonz@google.com>
parents: 5426
diff changeset
56 def _override(orig, repo, node, branch, bheads=None, opts=None):
dd9dba7c1d00 compat: make topics compatible across change to cmdutil.commitstatus()
Martin von Zweigbergk <martinvonz@google.com>
parents: 5426
diff changeset
57 def _orig(repo, node, branch, bheads=None, tip=None, opts=None):
dd9dba7c1d00 compat: make topics compatible across change to cmdutil.commitstatus()
Martin von Zweigbergk <martinvonz@google.com>
parents: 5426
diff changeset
58 return orig(repo, node, branch, bheads=bheads, opts=opts)
dd9dba7c1d00 compat: make topics compatible across change to cmdutil.commitstatus()
Martin von Zweigbergk <martinvonz@google.com>
parents: 5426
diff changeset
59 return overridefn(_orig, repo, node, branch, bheads=bheads, tip=None, opts=opts)
dd9dba7c1d00 compat: make topics compatible across change to cmdutil.commitstatus()
Martin von Zweigbergk <martinvonz@google.com>
parents: 5426
diff changeset
60 extensions.wrapfunction(cmdutil, 'commitstatus', _override)
6318
3e488afe62f5 topic: use compat.InputError for conflicting CLI flags
Anton Shestakov <av6@dwimlabs.net>
parents: 6305
diff changeset
61
3e488afe62f5 topic: use compat.InputError for conflicting CLI flags
Anton Shestakov <av6@dwimlabs.net>
parents: 6305
diff changeset
62 if util.safehasattr(error, 'InputError'):
3e488afe62f5 topic: use compat.InputError for conflicting CLI flags
Anton Shestakov <av6@dwimlabs.net>
parents: 6305
diff changeset
63 InputError = error.InputError
3e488afe62f5 topic: use compat.InputError for conflicting CLI flags
Anton Shestakov <av6@dwimlabs.net>
parents: 6305
diff changeset
64 else:
3e488afe62f5 topic: use compat.InputError for conflicting CLI flags
Anton Shestakov <av6@dwimlabs.net>
parents: 6305
diff changeset
65 # hg <= 5.6 (8d72e29ad1e0)
3e488afe62f5 topic: use compat.InputError for conflicting CLI flags
Anton Shestakov <av6@dwimlabs.net>
parents: 6305
diff changeset
66 InputError = error.Abort
6320
0c780d972350 topic: use check_incompatible_arguments() for --list with --clear or --rev
Anton Shestakov <av6@dwimlabs.net>
parents: 6318
diff changeset
67
6321
58b856416d2e topic: use compat.StateError for aborting pushes that create new heads
Anton Shestakov <av6@dwimlabs.net>
parents: 6320
diff changeset
68 if util.safehasattr(error, 'StateError'):
58b856416d2e topic: use compat.StateError for aborting pushes that create new heads
Anton Shestakov <av6@dwimlabs.net>
parents: 6320
diff changeset
69 StateError = error.StateError
58b856416d2e topic: use compat.StateError for aborting pushes that create new heads
Anton Shestakov <av6@dwimlabs.net>
parents: 6320
diff changeset
70 else:
58b856416d2e topic: use compat.StateError for aborting pushes that create new heads
Anton Shestakov <av6@dwimlabs.net>
parents: 6320
diff changeset
71 # hg <= 5.6 (527ce85c2e60)
58b856416d2e topic: use compat.StateError for aborting pushes that create new heads
Anton Shestakov <av6@dwimlabs.net>
parents: 6320
diff changeset
72 StateError = error.Abort
58b856416d2e topic: use compat.StateError for aborting pushes that create new heads
Anton Shestakov <av6@dwimlabs.net>
parents: 6320
diff changeset
73
6322
57f9cdbf6a99 topic: use compat.CanceledError for user quit situations
Anton Shestakov <av6@dwimlabs.net>
parents: 6321
diff changeset
74 if util.safehasattr(error, 'CanceledError'):
57f9cdbf6a99 topic: use compat.CanceledError for user quit situations
Anton Shestakov <av6@dwimlabs.net>
parents: 6321
diff changeset
75 CanceledError = error.CanceledError
57f9cdbf6a99 topic: use compat.CanceledError for user quit situations
Anton Shestakov <av6@dwimlabs.net>
parents: 6321
diff changeset
76 else:
57f9cdbf6a99 topic: use compat.CanceledError for user quit situations
Anton Shestakov <av6@dwimlabs.net>
parents: 6321
diff changeset
77 # hg <= 5.6 (ac362d5a7893)
57f9cdbf6a99 topic: use compat.CanceledError for user quit situations
Anton Shestakov <av6@dwimlabs.net>
parents: 6321
diff changeset
78 CanceledError = error.Abort
57f9cdbf6a99 topic: use compat.CanceledError for user quit situations
Anton Shestakov <av6@dwimlabs.net>
parents: 6321
diff changeset
79
6320
0c780d972350 topic: use check_incompatible_arguments() for --list with --clear or --rev
Anton Shestakov <av6@dwimlabs.net>
parents: 6318
diff changeset
80 if util.safehasattr(cmdutil, 'check_at_most_one_arg'):
0c780d972350 topic: use check_incompatible_arguments() for --list with --clear or --rev
Anton Shestakov <av6@dwimlabs.net>
parents: 6318
diff changeset
81 def check_at_most_one_arg(opts, *args):
0c780d972350 topic: use check_incompatible_arguments() for --list with --clear or --rev
Anton Shestakov <av6@dwimlabs.net>
parents: 6318
diff changeset
82 return cmdutil.check_at_most_one_arg(opts, *args)
0c780d972350 topic: use check_incompatible_arguments() for --list with --clear or --rev
Anton Shestakov <av6@dwimlabs.net>
parents: 6318
diff changeset
83 else:
0c780d972350 topic: use check_incompatible_arguments() for --list with --clear or --rev
Anton Shestakov <av6@dwimlabs.net>
parents: 6318
diff changeset
84 # hg <= 5.2 (d587937600be)
0c780d972350 topic: use check_incompatible_arguments() for --list with --clear or --rev
Anton Shestakov <av6@dwimlabs.net>
parents: 6318
diff changeset
85 def check_at_most_one_arg(opts, *args):
0c780d972350 topic: use check_incompatible_arguments() for --list with --clear or --rev
Anton Shestakov <av6@dwimlabs.net>
parents: 6318
diff changeset
86 def to_display(name):
0c780d972350 topic: use check_incompatible_arguments() for --list with --clear or --rev
Anton Shestakov <av6@dwimlabs.net>
parents: 6318
diff changeset
87 return pycompat.sysbytes(name).replace(b'_', b'-')
0c780d972350 topic: use check_incompatible_arguments() for --list with --clear or --rev
Anton Shestakov <av6@dwimlabs.net>
parents: 6318
diff changeset
88
0c780d972350 topic: use check_incompatible_arguments() for --list with --clear or --rev
Anton Shestakov <av6@dwimlabs.net>
parents: 6318
diff changeset
89 previous = None
0c780d972350 topic: use check_incompatible_arguments() for --list with --clear or --rev
Anton Shestakov <av6@dwimlabs.net>
parents: 6318
diff changeset
90 for x in args:
0c780d972350 topic: use check_incompatible_arguments() for --list with --clear or --rev
Anton Shestakov <av6@dwimlabs.net>
parents: 6318
diff changeset
91 if opts.get(x):
0c780d972350 topic: use check_incompatible_arguments() for --list with --clear or --rev
Anton Shestakov <av6@dwimlabs.net>
parents: 6318
diff changeset
92 if previous:
0c780d972350 topic: use check_incompatible_arguments() for --list with --clear or --rev
Anton Shestakov <av6@dwimlabs.net>
parents: 6318
diff changeset
93 raise InputError(_(b'cannot specify both --%s and --%s')
0c780d972350 topic: use check_incompatible_arguments() for --list with --clear or --rev
Anton Shestakov <av6@dwimlabs.net>
parents: 6318
diff changeset
94 % (to_display(previous), to_display(x)))
0c780d972350 topic: use check_incompatible_arguments() for --list with --clear or --rev
Anton Shestakov <av6@dwimlabs.net>
parents: 6318
diff changeset
95 previous = x
0c780d972350 topic: use check_incompatible_arguments() for --list with --clear or --rev
Anton Shestakov <av6@dwimlabs.net>
parents: 6318
diff changeset
96 return previous
0c780d972350 topic: use check_incompatible_arguments() for --list with --clear or --rev
Anton Shestakov <av6@dwimlabs.net>
parents: 6318
diff changeset
97
0c780d972350 topic: use check_incompatible_arguments() for --list with --clear or --rev
Anton Shestakov <av6@dwimlabs.net>
parents: 6318
diff changeset
98 if util.safehasattr(cmdutil, 'check_incompatible_arguments'):
0c780d972350 topic: use check_incompatible_arguments() for --list with --clear or --rev
Anton Shestakov <av6@dwimlabs.net>
parents: 6318
diff changeset
99 code = cmdutil.check_incompatible_arguments.__code__
0c780d972350 topic: use check_incompatible_arguments() for --list with --clear or --rev
Anton Shestakov <av6@dwimlabs.net>
parents: 6318
diff changeset
100 if r'others' in code.co_varnames[:code.co_argcount]:
0c780d972350 topic: use check_incompatible_arguments() for --list with --clear or --rev
Anton Shestakov <av6@dwimlabs.net>
parents: 6318
diff changeset
101 def check_incompatible_arguments(opts, first, others):
0c780d972350 topic: use check_incompatible_arguments() for --list with --clear or --rev
Anton Shestakov <av6@dwimlabs.net>
parents: 6318
diff changeset
102 return cmdutil.check_incompatible_arguments(opts, first, others)
0c780d972350 topic: use check_incompatible_arguments() for --list with --clear or --rev
Anton Shestakov <av6@dwimlabs.net>
parents: 6318
diff changeset
103 else:
0c780d972350 topic: use check_incompatible_arguments() for --list with --clear or --rev
Anton Shestakov <av6@dwimlabs.net>
parents: 6318
diff changeset
104 # hg <= 5.3 (d4c1501225c4)
0c780d972350 topic: use check_incompatible_arguments() for --list with --clear or --rev
Anton Shestakov <av6@dwimlabs.net>
parents: 6318
diff changeset
105 def check_incompatible_arguments(opts, first, others):
0c780d972350 topic: use check_incompatible_arguments() for --list with --clear or --rev
Anton Shestakov <av6@dwimlabs.net>
parents: 6318
diff changeset
106 return cmdutil.check_incompatible_arguments(opts, first, *others)
0c780d972350 topic: use check_incompatible_arguments() for --list with --clear or --rev
Anton Shestakov <av6@dwimlabs.net>
parents: 6318
diff changeset
107 else:
0c780d972350 topic: use check_incompatible_arguments() for --list with --clear or --rev
Anton Shestakov <av6@dwimlabs.net>
parents: 6318
diff changeset
108 # hg <= 5.2 (023ad45e2fd2)
0c780d972350 topic: use check_incompatible_arguments() for --list with --clear or --rev
Anton Shestakov <av6@dwimlabs.net>
parents: 6318
diff changeset
109 def check_incompatible_arguments(opts, first, others):
0c780d972350 topic: use check_incompatible_arguments() for --list with --clear or --rev
Anton Shestakov <av6@dwimlabs.net>
parents: 6318
diff changeset
110 for other in others:
0c780d972350 topic: use check_incompatible_arguments() for --list with --clear or --rev
Anton Shestakov <av6@dwimlabs.net>
parents: 6318
diff changeset
111 check_at_most_one_arg(opts, first, other)