annotate hggit/compat.py @ 1141:56a3fc2086b3

compat: find listdir function in compat module
author Kevin Bullock <kbullock@ringworld.org>
date Wed, 07 Feb 2018 22:42:32 -0600
parents 583ac3ddd54b
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
991
92d7702c19da compat: add method for backwards compatible passwordmgr
Sean Farley <sean@farley.io>
parents: 850
diff changeset
1 from mercurial import (
1139
8e03a8ba04af compat: find the right method to set active bookmark once
Kevin Bullock <kbullock@ringworld.org>
parents: 1130
diff changeset
2 bookmarks,
1104
e326b349eba6 compat: extract function for memfilectx signature variants
Kevin Bullock <kbullock@ringworld.org>
parents: 1093
diff changeset
3 context,
1140
583ac3ddd54b compat: extract function for differing phases.advanceboundary args
Kevin Bullock <kbullock@ringworld.org>
parents: 1139
diff changeset
4 phases,
991
92d7702c19da compat: add method for backwards compatible passwordmgr
Sean Farley <sean@farley.io>
parents: 850
diff changeset
5 url,
92d7702c19da compat: add method for backwards compatible passwordmgr
Sean Farley <sean@farley.io>
parents: 850
diff changeset
6 util as hgutil,
92d7702c19da compat: add method for backwards compatible passwordmgr
Sean Farley <sean@farley.io>
parents: 850
diff changeset
7 )
92d7702c19da compat: add method for backwards compatible passwordmgr
Sean Farley <sean@farley.io>
parents: 850
diff changeset
8
850
81c55f8629ba hg2git: audit path components during export (CVE-2014-9390)
Augie Fackler <raf@durin42.com>
parents:
diff changeset
9 try:
81c55f8629ba hg2git: audit path components during export (CVE-2014-9390)
Augie Fackler <raf@durin42.com>
parents:
diff changeset
10 from mercurial import encoding
81c55f8629ba hg2git: audit path components during export (CVE-2014-9390)
Augie Fackler <raf@durin42.com>
parents:
diff changeset
11 hfsignoreclean = encoding.hfsignoreclean
81c55f8629ba hg2git: audit path components during export (CVE-2014-9390)
Augie Fackler <raf@durin42.com>
parents:
diff changeset
12 except AttributeError:
81c55f8629ba hg2git: audit path components during export (CVE-2014-9390)
Augie Fackler <raf@durin42.com>
parents:
diff changeset
13 # compat with hg 3.2.1 and earlier, which doesn't have
81c55f8629ba hg2git: audit path components during export (CVE-2014-9390)
Augie Fackler <raf@durin42.com>
parents:
diff changeset
14 # hfsignoreclean (This was borrowed wholesale from hg 3.2.2.)
81c55f8629ba hg2git: audit path components during export (CVE-2014-9390)
Augie Fackler <raf@durin42.com>
parents:
diff changeset
15 _ignore = [unichr(int(x, 16)).encode("utf-8") for x in
81c55f8629ba hg2git: audit path components during export (CVE-2014-9390)
Augie Fackler <raf@durin42.com>
parents:
diff changeset
16 "200c 200d 200e 200f 202a 202b 202c 202d 202e "
81c55f8629ba hg2git: audit path components during export (CVE-2014-9390)
Augie Fackler <raf@durin42.com>
parents:
diff changeset
17 "206a 206b 206c 206d 206e 206f feff".split()]
81c55f8629ba hg2git: audit path components during export (CVE-2014-9390)
Augie Fackler <raf@durin42.com>
parents:
diff changeset
18 # verify the next function will work
81c55f8629ba hg2git: audit path components during export (CVE-2014-9390)
Augie Fackler <raf@durin42.com>
parents:
diff changeset
19 assert set([i[0] for i in _ignore]) == set(["\xe2", "\xef"])
81c55f8629ba hg2git: audit path components during export (CVE-2014-9390)
Augie Fackler <raf@durin42.com>
parents:
diff changeset
20
81c55f8629ba hg2git: audit path components during export (CVE-2014-9390)
Augie Fackler <raf@durin42.com>
parents:
diff changeset
21 def hfsignoreclean(s):
81c55f8629ba hg2git: audit path components during export (CVE-2014-9390)
Augie Fackler <raf@durin42.com>
parents:
diff changeset
22 """Remove codepoints ignored by HFS+ from s.
81c55f8629ba hg2git: audit path components during export (CVE-2014-9390)
Augie Fackler <raf@durin42.com>
parents:
diff changeset
23
81c55f8629ba hg2git: audit path components during export (CVE-2014-9390)
Augie Fackler <raf@durin42.com>
parents:
diff changeset
24 >>> hfsignoreclean(u'.h\u200cg'.encode('utf-8'))
81c55f8629ba hg2git: audit path components during export (CVE-2014-9390)
Augie Fackler <raf@durin42.com>
parents:
diff changeset
25 '.hg'
81c55f8629ba hg2git: audit path components during export (CVE-2014-9390)
Augie Fackler <raf@durin42.com>
parents:
diff changeset
26 >>> hfsignoreclean(u'.h\ufeffg'.encode('utf-8'))
81c55f8629ba hg2git: audit path components during export (CVE-2014-9390)
Augie Fackler <raf@durin42.com>
parents:
diff changeset
27 '.hg'
81c55f8629ba hg2git: audit path components during export (CVE-2014-9390)
Augie Fackler <raf@durin42.com>
parents:
diff changeset
28 """
81c55f8629ba hg2git: audit path components during export (CVE-2014-9390)
Augie Fackler <raf@durin42.com>
parents:
diff changeset
29 if "\xe2" in s or "\xef" in s:
81c55f8629ba hg2git: audit path components during export (CVE-2014-9390)
Augie Fackler <raf@durin42.com>
parents:
diff changeset
30 for c in _ignore:
81c55f8629ba hg2git: audit path components during export (CVE-2014-9390)
Augie Fackler <raf@durin42.com>
parents:
diff changeset
31 s = s.replace(c, '')
81c55f8629ba hg2git: audit path components during export (CVE-2014-9390)
Augie Fackler <raf@durin42.com>
parents:
diff changeset
32 return s
991
92d7702c19da compat: add method for backwards compatible passwordmgr
Sean Farley <sean@farley.io>
parents: 850
diff changeset
33
1088
c06d4656b77b shared: fix compatibility with hg < 4.2
Kevin Bullock <kbullock@ringworld.org>
parents: 1080
diff changeset
34 try:
c06d4656b77b shared: fix compatibility with hg < 4.2
Kevin Bullock <kbullock@ringworld.org>
parents: 1080
diff changeset
35 from mercurial import vfs as vfsmod
c06d4656b77b shared: fix compatibility with hg < 4.2
Kevin Bullock <kbullock@ringworld.org>
parents: 1080
diff changeset
36 hgvfs = vfsmod.vfs
c06d4656b77b shared: fix compatibility with hg < 4.2
Kevin Bullock <kbullock@ringworld.org>
parents: 1080
diff changeset
37 except ImportError:
c06d4656b77b shared: fix compatibility with hg < 4.2
Kevin Bullock <kbullock@ringworld.org>
parents: 1080
diff changeset
38 # vfsmod was extracted in hg 4.2
c06d4656b77b shared: fix compatibility with hg < 4.2
Kevin Bullock <kbullock@ringworld.org>
parents: 1080
diff changeset
39 from mercurial import scmutil
c06d4656b77b shared: fix compatibility with hg < 4.2
Kevin Bullock <kbullock@ringworld.org>
parents: 1080
diff changeset
40 hgvfs = scmutil.vfs
c06d4656b77b shared: fix compatibility with hg < 4.2
Kevin Bullock <kbullock@ringworld.org>
parents: 1080
diff changeset
41
1130
80664524802b compat: add compatibility for 4.6 mercurial.utils
Sean Farley <sean@farley.io>
parents: 1115
diff changeset
42 try:
80664524802b compat: add compatibility for 4.6 mercurial.utils
Sean Farley <sean@farley.io>
parents: 1115
diff changeset
43 from mercurial.utils import procutil, stringutil
80664524802b compat: add compatibility for 4.6 mercurial.utils
Sean Farley <sean@farley.io>
parents: 1115
diff changeset
44 sshargs = procutil.sshargs
80664524802b compat: add compatibility for 4.6 mercurial.utils
Sean Farley <sean@farley.io>
parents: 1115
diff changeset
45 shellquote = procutil.shellquote
80664524802b compat: add compatibility for 4.6 mercurial.utils
Sean Farley <sean@farley.io>
parents: 1115
diff changeset
46 quotecommand = procutil.quotecommand
80664524802b compat: add compatibility for 4.6 mercurial.utils
Sean Farley <sean@farley.io>
parents: 1115
diff changeset
47 binary = stringutil.binary
80664524802b compat: add compatibility for 4.6 mercurial.utils
Sean Farley <sean@farley.io>
parents: 1115
diff changeset
48 except ImportError:
80664524802b compat: add compatibility for 4.6 mercurial.utils
Sean Farley <sean@farley.io>
parents: 1115
diff changeset
49 # these were moved in 4.6
80664524802b compat: add compatibility for 4.6 mercurial.utils
Sean Farley <sean@farley.io>
parents: 1115
diff changeset
50 sshargs = hgutil.sshargs
80664524802b compat: add compatibility for 4.6 mercurial.utils
Sean Farley <sean@farley.io>
parents: 1115
diff changeset
51 shellquote = hgutil.shellquote
80664524802b compat: add compatibility for 4.6 mercurial.utils
Sean Farley <sean@farley.io>
parents: 1115
diff changeset
52 quotecommand = hgutil.quotecommand
80664524802b compat: add compatibility for 4.6 mercurial.utils
Sean Farley <sean@farley.io>
parents: 1115
diff changeset
53 binary = hgutil.binary
80664524802b compat: add compatibility for 4.6 mercurial.utils
Sean Farley <sean@farley.io>
parents: 1115
diff changeset
54
1115
8ed6c0cae9b8 cleanup: add some blank lines
Sean Farley <sean@farley.io>
parents: 1104
diff changeset
55
1088
c06d4656b77b shared: fix compatibility with hg < 4.2
Kevin Bullock <kbullock@ringworld.org>
parents: 1080
diff changeset
56 def gitvfs(repo):
c06d4656b77b shared: fix compatibility with hg < 4.2
Kevin Bullock <kbullock@ringworld.org>
parents: 1080
diff changeset
57 """return a vfs suitable to read git related data"""
c06d4656b77b shared: fix compatibility with hg < 4.2
Kevin Bullock <kbullock@ringworld.org>
parents: 1080
diff changeset
58 # Mercurial >= 3.3: repo.shared()
c06d4656b77b shared: fix compatibility with hg < 4.2
Kevin Bullock <kbullock@ringworld.org>
parents: 1080
diff changeset
59 if repo.sharedpath != repo.path:
c06d4656b77b shared: fix compatibility with hg < 4.2
Kevin Bullock <kbullock@ringworld.org>
parents: 1080
diff changeset
60 return hgvfs(repo.sharedpath)
c06d4656b77b shared: fix compatibility with hg < 4.2
Kevin Bullock <kbullock@ringworld.org>
parents: 1080
diff changeset
61 else:
c06d4656b77b shared: fix compatibility with hg < 4.2
Kevin Bullock <kbullock@ringworld.org>
parents: 1080
diff changeset
62 return repo.vfs
c06d4656b77b shared: fix compatibility with hg < 4.2
Kevin Bullock <kbullock@ringworld.org>
parents: 1080
diff changeset
63
1115
8ed6c0cae9b8 cleanup: add some blank lines
Sean Farley <sean@farley.io>
parents: 1104
diff changeset
64
1035
cfcd3032355c compat: remove unused argument
Kevin Bullock <kbullock@ringworld.org>
parents: 1005
diff changeset
65 def passwordmgr(ui):
991
92d7702c19da compat: add method for backwards compatible passwordmgr
Sean Farley <sean@farley.io>
parents: 850
diff changeset
66 try:
1036
da62ef0569bb compat: fix fallback for ui.passwordmgr
Kevin Bullock <kbullock@ringworld.org>
parents: 1035
diff changeset
67 realm = hgutil.urlreq.httppasswordmgrwithdefaultrealm()
da62ef0569bb compat: fix fallback for ui.passwordmgr
Kevin Bullock <kbullock@ringworld.org>
parents: 1035
diff changeset
68 return url.passwordmgr(ui, realm)
da62ef0569bb compat: fix fallback for ui.passwordmgr
Kevin Bullock <kbullock@ringworld.org>
parents: 1035
diff changeset
69 except (TypeError, AttributeError):
991
92d7702c19da compat: add method for backwards compatible passwordmgr
Sean Farley <sean@farley.io>
parents: 850
diff changeset
70 # compat with hg < 3.9
92d7702c19da compat: add method for backwards compatible passwordmgr
Sean Farley <sean@farley.io>
parents: 850
diff changeset
71 return url.passwordmgr(ui)
1005
31f52d62ae13 compat: add method for dulwich to return the symref
Sean Farley <sean@farley.io>
parents: 991
diff changeset
72
1139
8e03a8ba04af compat: find the right method to set active bookmark once
Kevin Bullock <kbullock@ringworld.org>
parents: 1130
diff changeset
73 # bookmarks.setcurrent was renamed to activate in hg 3.5
8e03a8ba04af compat: find the right method to set active bookmark once
Kevin Bullock <kbullock@ringworld.org>
parents: 1130
diff changeset
74 if hgutil.safehasattr(bookmarks, 'activate'):
8e03a8ba04af compat: find the right method to set active bookmark once
Kevin Bullock <kbullock@ringworld.org>
parents: 1130
diff changeset
75 activatebookmark = bookmarks.activate
8e03a8ba04af compat: find the right method to set active bookmark once
Kevin Bullock <kbullock@ringworld.org>
parents: 1130
diff changeset
76 else:
8e03a8ba04af compat: find the right method to set active bookmark once
Kevin Bullock <kbullock@ringworld.org>
parents: 1130
diff changeset
77 activatebookmark = bookmarks.setcurrent
8e03a8ba04af compat: find the right method to set active bookmark once
Kevin Bullock <kbullock@ringworld.org>
parents: 1130
diff changeset
78
1140
583ac3ddd54b compat: extract function for differing phases.advanceboundary args
Kevin Bullock <kbullock@ringworld.org>
parents: 1139
diff changeset
79 def advancephaseboundary(repo, tr, targetphase, nodes):
583ac3ddd54b compat: extract function for differing phases.advanceboundary args
Kevin Bullock <kbullock@ringworld.org>
parents: 1139
diff changeset
80 # hg 3.2 - advanceboundary uses transaction
583ac3ddd54b compat: extract function for differing phases.advanceboundary args
Kevin Bullock <kbullock@ringworld.org>
parents: 1139
diff changeset
81 try:
583ac3ddd54b compat: extract function for differing phases.advanceboundary args
Kevin Bullock <kbullock@ringworld.org>
parents: 1139
diff changeset
82 phases.advanceboundary(repo, tr, targetphase, nodes)
583ac3ddd54b compat: extract function for differing phases.advanceboundary args
Kevin Bullock <kbullock@ringworld.org>
parents: 1139
diff changeset
83 except TypeError:
583ac3ddd54b compat: extract function for differing phases.advanceboundary args
Kevin Bullock <kbullock@ringworld.org>
parents: 1139
diff changeset
84 phases.advanceboundary(repo, targetphase, nodes)
583ac3ddd54b compat: extract function for differing phases.advanceboundary args
Kevin Bullock <kbullock@ringworld.org>
parents: 1139
diff changeset
85
1141
56a3fc2086b3 compat: find listdir function in compat module
Kevin Bullock <kbullock@ringworld.org>
parents: 1140
diff changeset
86 # hg 4.3 - osutil moved, but mercurial.util re-exports listdir
56a3fc2086b3 compat: find listdir function in compat module
Kevin Bullock <kbullock@ringworld.org>
parents: 1140
diff changeset
87 if hgutil.safehasattr(hgutil, 'listdir'):
56a3fc2086b3 compat: find listdir function in compat module
Kevin Bullock <kbullock@ringworld.org>
parents: 1140
diff changeset
88 listdir = hgutil.listdir
56a3fc2086b3 compat: find listdir function in compat module
Kevin Bullock <kbullock@ringworld.org>
parents: 1140
diff changeset
89 else:
56a3fc2086b3 compat: find listdir function in compat module
Kevin Bullock <kbullock@ringworld.org>
parents: 1140
diff changeset
90 from mercurial import osutil
56a3fc2086b3 compat: find listdir function in compat module
Kevin Bullock <kbullock@ringworld.org>
parents: 1140
diff changeset
91 listdir = osutil.listdir
56a3fc2086b3 compat: find listdir function in compat module
Kevin Bullock <kbullock@ringworld.org>
parents: 1140
diff changeset
92
1092
3799bf885c1d compat: use newer read_pkt_refs from dulwich if possible
Sean Farley <sean@farley.io>
parents: 1088
diff changeset
93
3799bf885c1d compat: use newer read_pkt_refs from dulwich if possible
Sean Farley <sean@farley.io>
parents: 1088
diff changeset
94 try:
3799bf885c1d compat: use newer read_pkt_refs from dulwich if possible
Sean Farley <sean@farley.io>
parents: 1088
diff changeset
95 import dulwich.client
3799bf885c1d compat: use newer read_pkt_refs from dulwich if possible
Sean Farley <sean@farley.io>
parents: 1088
diff changeset
96 FetchPackResult = dulwich.client.FetchPackResult
3799bf885c1d compat: use newer read_pkt_refs from dulwich if possible
Sean Farley <sean@farley.io>
parents: 1088
diff changeset
97 read_pkt_refs = dulwich.client.read_pkt_refs
3799bf885c1d compat: use newer read_pkt_refs from dulwich if possible
Sean Farley <sean@farley.io>
parents: 1088
diff changeset
98 except (AttributeError, ImportError):
3799bf885c1d compat: use newer read_pkt_refs from dulwich if possible
Sean Farley <sean@farley.io>
parents: 1088
diff changeset
99 # older dulwich doesn't return the symref where remote HEAD points, so we
3799bf885c1d compat: use newer read_pkt_refs from dulwich if possible
Sean Farley <sean@farley.io>
parents: 1088
diff changeset
100 # monkey patch it here
3799bf885c1d compat: use newer read_pkt_refs from dulwich if possible
Sean Farley <sean@farley.io>
parents: 1088
diff changeset
101 from dulwich.errors import GitProtocolError
3799bf885c1d compat: use newer read_pkt_refs from dulwich if possible
Sean Farley <sean@farley.io>
parents: 1088
diff changeset
102 from dulwich.protocol import extract_capabilities
3799bf885c1d compat: use newer read_pkt_refs from dulwich if possible
Sean Farley <sean@farley.io>
parents: 1088
diff changeset
103
1093
8e61d7a29932 compat: add a stub FetchPackResult class for use with older dulwich
Sean Farley <sean@farley.io>
parents: 1092
diff changeset
104 class FetchPackResult(object):
8e61d7a29932 compat: add a stub FetchPackResult class for use with older dulwich
Sean Farley <sean@farley.io>
parents: 1092
diff changeset
105 """Result of a fetch-pack operation.
8e61d7a29932 compat: add a stub FetchPackResult class for use with older dulwich
Sean Farley <sean@farley.io>
parents: 1092
diff changeset
106 :var refs: Dictionary with all remote refs
8e61d7a29932 compat: add a stub FetchPackResult class for use with older dulwich
Sean Farley <sean@farley.io>
parents: 1092
diff changeset
107 :var symrefs: Dictionary with remote symrefs
8e61d7a29932 compat: add a stub FetchPackResult class for use with older dulwich
Sean Farley <sean@farley.io>
parents: 1092
diff changeset
108 :var agent: User agent string
8e61d7a29932 compat: add a stub FetchPackResult class for use with older dulwich
Sean Farley <sean@farley.io>
parents: 1092
diff changeset
109 """
1092
3799bf885c1d compat: use newer read_pkt_refs from dulwich if possible
Sean Farley <sean@farley.io>
parents: 1088
diff changeset
110
1093
8e61d7a29932 compat: add a stub FetchPackResult class for use with older dulwich
Sean Farley <sean@farley.io>
parents: 1092
diff changeset
111 def __init__(self, refs, symrefs, agent):
8e61d7a29932 compat: add a stub FetchPackResult class for use with older dulwich
Sean Farley <sean@farley.io>
parents: 1092
diff changeset
112 self.refs = refs
8e61d7a29932 compat: add a stub FetchPackResult class for use with older dulwich
Sean Farley <sean@farley.io>
parents: 1092
diff changeset
113 self.symrefs = symrefs
8e61d7a29932 compat: add a stub FetchPackResult class for use with older dulwich
Sean Farley <sean@farley.io>
parents: 1092
diff changeset
114 self.agent = agent
1005
31f52d62ae13 compat: add method for dulwich to return the symref
Sean Farley <sean@farley.io>
parents: 991
diff changeset
115
1092
3799bf885c1d compat: use newer read_pkt_refs from dulwich if possible
Sean Farley <sean@farley.io>
parents: 1088
diff changeset
116 def read_pkt_refs(proto):
3799bf885c1d compat: use newer read_pkt_refs from dulwich if possible
Sean Farley <sean@farley.io>
parents: 1088
diff changeset
117 server_capabilities = None
3799bf885c1d compat: use newer read_pkt_refs from dulwich if possible
Sean Farley <sean@farley.io>
parents: 1088
diff changeset
118 refs = {}
3799bf885c1d compat: use newer read_pkt_refs from dulwich if possible
Sean Farley <sean@farley.io>
parents: 1088
diff changeset
119 # Receive refs from server
3799bf885c1d compat: use newer read_pkt_refs from dulwich if possible
Sean Farley <sean@farley.io>
parents: 1088
diff changeset
120 for pkt in proto.read_pkt_seq():
3799bf885c1d compat: use newer read_pkt_refs from dulwich if possible
Sean Farley <sean@farley.io>
parents: 1088
diff changeset
121 (sha, ref) = pkt.rstrip('\n').split(None, 1)
3799bf885c1d compat: use newer read_pkt_refs from dulwich if possible
Sean Farley <sean@farley.io>
parents: 1088
diff changeset
122 if sha == 'ERR':
3799bf885c1d compat: use newer read_pkt_refs from dulwich if possible
Sean Farley <sean@farley.io>
parents: 1088
diff changeset
123 raise GitProtocolError(ref)
3799bf885c1d compat: use newer read_pkt_refs from dulwich if possible
Sean Farley <sean@farley.io>
parents: 1088
diff changeset
124 if server_capabilities is None:
3799bf885c1d compat: use newer read_pkt_refs from dulwich if possible
Sean Farley <sean@farley.io>
parents: 1088
diff changeset
125 (ref, server_capabilities) = extract_capabilities(ref)
3799bf885c1d compat: use newer read_pkt_refs from dulwich if possible
Sean Farley <sean@farley.io>
parents: 1088
diff changeset
126 symref = 'symref=HEAD:'
3799bf885c1d compat: use newer read_pkt_refs from dulwich if possible
Sean Farley <sean@farley.io>
parents: 1088
diff changeset
127 for cap in server_capabilities:
3799bf885c1d compat: use newer read_pkt_refs from dulwich if possible
Sean Farley <sean@farley.io>
parents: 1088
diff changeset
128 if cap.startswith(symref):
3799bf885c1d compat: use newer read_pkt_refs from dulwich if possible
Sean Farley <sean@farley.io>
parents: 1088
diff changeset
129 sha = cap.replace(symref, '')
3799bf885c1d compat: use newer read_pkt_refs from dulwich if possible
Sean Farley <sean@farley.io>
parents: 1088
diff changeset
130 refs[ref] = sha
1005
31f52d62ae13 compat: add method for dulwich to return the symref
Sean Farley <sean@farley.io>
parents: 991
diff changeset
131
1092
3799bf885c1d compat: use newer read_pkt_refs from dulwich if possible
Sean Farley <sean@farley.io>
parents: 1088
diff changeset
132 if len(refs) == 0:
3799bf885c1d compat: use newer read_pkt_refs from dulwich if possible
Sean Farley <sean@farley.io>
parents: 1088
diff changeset
133 return None, set([])
3799bf885c1d compat: use newer read_pkt_refs from dulwich if possible
Sean Farley <sean@farley.io>
parents: 1088
diff changeset
134 return refs, set(server_capabilities)
1061
a2eccdeed26d config: provide a central place to define and access defaults
Kevin Bullock <kbullock@ringworld.org>
parents: 1036
diff changeset
135
a2eccdeed26d config: provide a central place to define and access defaults
Kevin Bullock <kbullock@ringworld.org>
parents: 1036
diff changeset
136
1104
e326b349eba6 compat: extract function for memfilectx signature variants
Kevin Bullock <kbullock@ringworld.org>
parents: 1093
diff changeset
137 def memfilectx(repo, changectx, path, data, islink=False,
e326b349eba6 compat: extract function for memfilectx signature variants
Kevin Bullock <kbullock@ringworld.org>
parents: 1093
diff changeset
138 isexec=False, copied=None):
e326b349eba6 compat: extract function for memfilectx signature variants
Kevin Bullock <kbullock@ringworld.org>
parents: 1093
diff changeset
139 # Different versions of mercurial have different parameters to
e326b349eba6 compat: extract function for memfilectx signature variants
Kevin Bullock <kbullock@ringworld.org>
parents: 1093
diff changeset
140 # memfilectx. Try them from newest to oldest.
e326b349eba6 compat: extract function for memfilectx signature variants
Kevin Bullock <kbullock@ringworld.org>
parents: 1093
diff changeset
141 args_to_try = (
e326b349eba6 compat: extract function for memfilectx signature variants
Kevin Bullock <kbullock@ringworld.org>
parents: 1093
diff changeset
142 (repo, changectx, path, data), # hg 4.5+
e326b349eba6 compat: extract function for memfilectx signature variants
Kevin Bullock <kbullock@ringworld.org>
parents: 1093
diff changeset
143 (repo, path, data), # hg 3.1 - 4.5
e326b349eba6 compat: extract function for memfilectx signature variants
Kevin Bullock <kbullock@ringworld.org>
parents: 1093
diff changeset
144 (path, data), # hg < 3.1
e326b349eba6 compat: extract function for memfilectx signature variants
Kevin Bullock <kbullock@ringworld.org>
parents: 1093
diff changeset
145 )
e326b349eba6 compat: extract function for memfilectx signature variants
Kevin Bullock <kbullock@ringworld.org>
parents: 1093
diff changeset
146 for args in args_to_try:
e326b349eba6 compat: extract function for memfilectx signature variants
Kevin Bullock <kbullock@ringworld.org>
parents: 1093
diff changeset
147 try:
e326b349eba6 compat: extract function for memfilectx signature variants
Kevin Bullock <kbullock@ringworld.org>
parents: 1093
diff changeset
148 return context.memfilectx(*args,
e326b349eba6 compat: extract function for memfilectx signature variants
Kevin Bullock <kbullock@ringworld.org>
parents: 1093
diff changeset
149 islink=islink,
e326b349eba6 compat: extract function for memfilectx signature variants
Kevin Bullock <kbullock@ringworld.org>
parents: 1093
diff changeset
150 isexec=isexec,
e326b349eba6 compat: extract function for memfilectx signature variants
Kevin Bullock <kbullock@ringworld.org>
parents: 1093
diff changeset
151 copied=copied)
e326b349eba6 compat: extract function for memfilectx signature variants
Kevin Bullock <kbullock@ringworld.org>
parents: 1093
diff changeset
152 except TypeError as ex:
e326b349eba6 compat: extract function for memfilectx signature variants
Kevin Bullock <kbullock@ringworld.org>
parents: 1093
diff changeset
153 last_ex = ex
e326b349eba6 compat: extract function for memfilectx signature variants
Kevin Bullock <kbullock@ringworld.org>
parents: 1093
diff changeset
154 raise last_ex
e326b349eba6 compat: extract function for memfilectx signature variants
Kevin Bullock <kbullock@ringworld.org>
parents: 1093
diff changeset
155
e326b349eba6 compat: extract function for memfilectx signature variants
Kevin Bullock <kbullock@ringworld.org>
parents: 1093
diff changeset
156
1061
a2eccdeed26d config: provide a central place to define and access defaults
Kevin Bullock <kbullock@ringworld.org>
parents: 1036
diff changeset
157 CONFIG_DEFAULTS = {
1063
ae5759bf5bcd config: register git.blockdotgit
Kevin Bullock <kbullock@ringworld.org>
parents: 1062
diff changeset
158 'git': {
1066
ddae0045de4e config: register git.authors
Kevin Bullock <kbullock@ringworld.org>
parents: 1065
diff changeset
159 'authors': None,
1063
ae5759bf5bcd config: register git.blockdotgit
Kevin Bullock <kbullock@ringworld.org>
parents: 1062
diff changeset
160 'blockdotgit': True,
1073
03e7c9d1fbb6 config: register git.blockdothg
Kevin Bullock <kbullock@ringworld.org>
parents: 1072
diff changeset
161 'blockdothg': True,
1065
78dc28eb4245 config: register git.branch_bookmark_suffix
Kevin Bullock <kbullock@ringworld.org>
parents: 1064
diff changeset
162 'branch_bookmark_suffix': None,
1068
914e5477b17e config: register git.debugextrainmessage
Kevin Bullock <kbullock@ringworld.org>
parents: 1067
diff changeset
163 'debugextrainmessage': False, # test only -- do not document this!
1072
f7433379c04a config: register git.findcopiesharder
Kevin Bullock <kbullock@ringworld.org>
parents: 1071
diff changeset
164 'findcopiesharder': False,
1064
d37336a87b70 config: register git.intree
Kevin Bullock <kbullock@ringworld.org>
parents: 1063
diff changeset
165 'intree': None,
1069
88db6948a5a8 config: register git.mindate
Kevin Bullock <kbullock@ringworld.org>
parents: 1068
diff changeset
166 'mindate': None,
1080
d96f998a718f config: register defaults for phase-related config options
Kevin Bullock <kbullock@ringworld.org>
parents: 1073
diff changeset
167 'public': list,
1071
00baa6a2abc8 config: register git.renamelimit
Kevin Bullock <kbullock@ringworld.org>
parents: 1070
diff changeset
168 'renamelimit': 400,
1070
0b4144897f73 config: register git.similarity
Kevin Bullock <kbullock@ringworld.org>
parents: 1069
diff changeset
169 'similarity': 0,
1063
ae5759bf5bcd config: register git.blockdotgit
Kevin Bullock <kbullock@ringworld.org>
parents: 1062
diff changeset
170 },
1067
f4c2b42731ea config: register hggit.mapsavefrequency
Kevin Bullock <kbullock@ringworld.org>
parents: 1066
diff changeset
171 'hggit': {
f4c2b42731ea config: register hggit.mapsavefrequency
Kevin Bullock <kbullock@ringworld.org>
parents: 1066
diff changeset
172 'mapsavefrequency': 0,
1080
d96f998a718f config: register defaults for phase-related config options
Kevin Bullock <kbullock@ringworld.org>
parents: 1073
diff changeset
173 'usephases': False,
1067
f4c2b42731ea config: register hggit.mapsavefrequency
Kevin Bullock <kbullock@ringworld.org>
parents: 1066
diff changeset
174 }
1061
a2eccdeed26d config: provide a central place to define and access defaults
Kevin Bullock <kbullock@ringworld.org>
parents: 1036
diff changeset
175 }
a2eccdeed26d config: provide a central place to define and access defaults
Kevin Bullock <kbullock@ringworld.org>
parents: 1036
diff changeset
176
1062
c249de74742b compat: use config registrar if available
Kevin Bullock <kbullock@ringworld.org>
parents: 1061
diff changeset
177 hasconfigitems = False
c249de74742b compat: use config registrar if available
Kevin Bullock <kbullock@ringworld.org>
parents: 1061
diff changeset
178
1115
8ed6c0cae9b8 cleanup: add some blank lines
Sean Farley <sean@farley.io>
parents: 1104
diff changeset
179
1062
c249de74742b compat: use config registrar if available
Kevin Bullock <kbullock@ringworld.org>
parents: 1061
diff changeset
180 def registerconfigs(configitem):
c249de74742b compat: use config registrar if available
Kevin Bullock <kbullock@ringworld.org>
parents: 1061
diff changeset
181 global hasconfigitems
c249de74742b compat: use config registrar if available
Kevin Bullock <kbullock@ringworld.org>
parents: 1061
diff changeset
182 hasconfigitems = True
c249de74742b compat: use config registrar if available
Kevin Bullock <kbullock@ringworld.org>
parents: 1061
diff changeset
183 for section, items in CONFIG_DEFAULTS.iteritems():
c249de74742b compat: use config registrar if available
Kevin Bullock <kbullock@ringworld.org>
parents: 1061
diff changeset
184 for item, default in items.iteritems():
c249de74742b compat: use config registrar if available
Kevin Bullock <kbullock@ringworld.org>
parents: 1061
diff changeset
185 configitem(section, item, default=default)
c249de74742b compat: use config registrar if available
Kevin Bullock <kbullock@ringworld.org>
parents: 1061
diff changeset
186
1115
8ed6c0cae9b8 cleanup: add some blank lines
Sean Farley <sean@farley.io>
parents: 1104
diff changeset
187
1061
a2eccdeed26d config: provide a central place to define and access defaults
Kevin Bullock <kbullock@ringworld.org>
parents: 1036
diff changeset
188 def config(ui, subtype, section, item):
a2eccdeed26d config: provide a central place to define and access defaults
Kevin Bullock <kbullock@ringworld.org>
parents: 1036
diff changeset
189 if subtype == 'string':
a2eccdeed26d config: provide a central place to define and access defaults
Kevin Bullock <kbullock@ringworld.org>
parents: 1036
diff changeset
190 subtype = ''
a2eccdeed26d config: provide a central place to define and access defaults
Kevin Bullock <kbullock@ringworld.org>
parents: 1036
diff changeset
191 getconfig = getattr(ui, 'config' + subtype)
1062
c249de74742b compat: use config registrar if available
Kevin Bullock <kbullock@ringworld.org>
parents: 1061
diff changeset
192 if hasconfigitems:
c249de74742b compat: use config registrar if available
Kevin Bullock <kbullock@ringworld.org>
parents: 1061
diff changeset
193 return getconfig(section, item)
1061
a2eccdeed26d config: provide a central place to define and access defaults
Kevin Bullock <kbullock@ringworld.org>
parents: 1036
diff changeset
194 return getconfig(section, item, CONFIG_DEFAULTS[section][item])