Show More
@@ -1,2339 +1,2336 | |||||
1 | # localrepo.py - read/write repository class for mercurial |
|
1 | # localrepo.py - read/write repository class for mercurial | |
2 | # |
|
2 | # | |
3 | # Copyright 2005-2007 Matt Mackall <mpm@selenic.com> |
|
3 | # Copyright 2005-2007 Matt Mackall <mpm@selenic.com> | |
4 | # |
|
4 | # | |
5 | # This software may be used and distributed according to the terms of the |
|
5 | # This software may be used and distributed according to the terms of the | |
6 | # GNU General Public License version 2 or any later version. |
|
6 | # GNU General Public License version 2 or any later version. | |
7 |
|
7 | |||
8 | from __future__ import absolute_import |
|
8 | from __future__ import absolute_import | |
9 |
|
9 | |||
10 | import errno |
|
10 | import errno | |
11 | import hashlib |
|
11 | import hashlib | |
12 | import os |
|
12 | import os | |
13 | import random |
|
13 | import random | |
14 | import time |
|
14 | import time | |
15 | import weakref |
|
15 | import weakref | |
16 |
|
16 | |||
17 | from .i18n import _ |
|
17 | from .i18n import _ | |
18 | from .node import ( |
|
18 | from .node import ( | |
19 | hex, |
|
19 | hex, | |
20 | nullid, |
|
20 | nullid, | |
21 | short, |
|
21 | short, | |
22 | ) |
|
22 | ) | |
23 | from .thirdparty.zope import ( |
|
23 | from .thirdparty.zope import ( | |
24 | interface as zi, |
|
24 | interface as zi, | |
25 | ) |
|
25 | ) | |
26 | from . import ( |
|
26 | from . import ( | |
27 | bookmarks, |
|
27 | bookmarks, | |
28 | branchmap, |
|
28 | branchmap, | |
29 | bundle2, |
|
29 | bundle2, | |
30 | changegroup, |
|
30 | changegroup, | |
31 | changelog, |
|
31 | changelog, | |
32 | color, |
|
32 | color, | |
33 | context, |
|
33 | context, | |
34 | dirstate, |
|
34 | dirstate, | |
35 | dirstateguard, |
|
35 | dirstateguard, | |
36 | discovery, |
|
36 | discovery, | |
37 | encoding, |
|
37 | encoding, | |
38 | error, |
|
38 | error, | |
39 | exchange, |
|
39 | exchange, | |
40 | extensions, |
|
40 | extensions, | |
41 | filelog, |
|
41 | filelog, | |
42 | hook, |
|
42 | hook, | |
43 | lock as lockmod, |
|
43 | lock as lockmod, | |
44 | manifest, |
|
44 | manifest, | |
45 | match as matchmod, |
|
45 | match as matchmod, | |
46 | merge as mergemod, |
|
46 | merge as mergemod, | |
47 | mergeutil, |
|
47 | mergeutil, | |
48 | namespaces, |
|
48 | namespaces, | |
49 | narrowspec, |
|
49 | narrowspec, | |
50 | obsolete, |
|
50 | obsolete, | |
51 | pathutil, |
|
51 | pathutil, | |
52 | peer, |
|
52 | peer, | |
53 | phases, |
|
53 | phases, | |
54 | pushkey, |
|
54 | pushkey, | |
55 | pycompat, |
|
55 | pycompat, | |
56 | repository, |
|
56 | repository, | |
57 | repoview, |
|
57 | repoview, | |
58 | revset, |
|
58 | revset, | |
59 | revsetlang, |
|
59 | revsetlang, | |
60 | scmutil, |
|
60 | scmutil, | |
61 | sparse, |
|
61 | sparse, | |
62 | store, |
|
62 | store, | |
63 | subrepoutil, |
|
63 | subrepoutil, | |
64 | tags as tagsmod, |
|
64 | tags as tagsmod, | |
65 | transaction, |
|
65 | transaction, | |
66 | txnutil, |
|
66 | txnutil, | |
67 | util, |
|
67 | util, | |
68 | vfs as vfsmod, |
|
68 | vfs as vfsmod, | |
69 | ) |
|
69 | ) | |
70 | from .utils import ( |
|
70 | from .utils import ( | |
71 | procutil, |
|
71 | procutil, | |
72 | stringutil, |
|
72 | stringutil, | |
73 | ) |
|
73 | ) | |
74 |
|
74 | |||
75 | release = lockmod.release |
|
75 | release = lockmod.release | |
76 | urlerr = util.urlerr |
|
76 | urlerr = util.urlerr | |
77 | urlreq = util.urlreq |
|
77 | urlreq = util.urlreq | |
78 |
|
78 | |||
79 | # set of (path, vfs-location) tuples. vfs-location is: |
|
79 | # set of (path, vfs-location) tuples. vfs-location is: | |
80 | # - 'plain for vfs relative paths |
|
80 | # - 'plain for vfs relative paths | |
81 | # - '' for svfs relative paths |
|
81 | # - '' for svfs relative paths | |
82 | _cachedfiles = set() |
|
82 | _cachedfiles = set() | |
83 |
|
83 | |||
84 | class _basefilecache(scmutil.filecache): |
|
84 | class _basefilecache(scmutil.filecache): | |
85 | """All filecache usage on repo are done for logic that should be unfiltered |
|
85 | """All filecache usage on repo are done for logic that should be unfiltered | |
86 | """ |
|
86 | """ | |
87 | def __get__(self, repo, type=None): |
|
87 | def __get__(self, repo, type=None): | |
88 | if repo is None: |
|
88 | if repo is None: | |
89 | return self |
|
89 | return self | |
90 | return super(_basefilecache, self).__get__(repo.unfiltered(), type) |
|
90 | return super(_basefilecache, self).__get__(repo.unfiltered(), type) | |
91 | def __set__(self, repo, value): |
|
91 | def __set__(self, repo, value): | |
92 | return super(_basefilecache, self).__set__(repo.unfiltered(), value) |
|
92 | return super(_basefilecache, self).__set__(repo.unfiltered(), value) | |
93 | def __delete__(self, repo): |
|
93 | def __delete__(self, repo): | |
94 | return super(_basefilecache, self).__delete__(repo.unfiltered()) |
|
94 | return super(_basefilecache, self).__delete__(repo.unfiltered()) | |
95 |
|
95 | |||
96 | class repofilecache(_basefilecache): |
|
96 | class repofilecache(_basefilecache): | |
97 | """filecache for files in .hg but outside of .hg/store""" |
|
97 | """filecache for files in .hg but outside of .hg/store""" | |
98 | def __init__(self, *paths): |
|
98 | def __init__(self, *paths): | |
99 | super(repofilecache, self).__init__(*paths) |
|
99 | super(repofilecache, self).__init__(*paths) | |
100 | for path in paths: |
|
100 | for path in paths: | |
101 | _cachedfiles.add((path, 'plain')) |
|
101 | _cachedfiles.add((path, 'plain')) | |
102 |
|
102 | |||
103 | def join(self, obj, fname): |
|
103 | def join(self, obj, fname): | |
104 | return obj.vfs.join(fname) |
|
104 | return obj.vfs.join(fname) | |
105 |
|
105 | |||
106 | class storecache(_basefilecache): |
|
106 | class storecache(_basefilecache): | |
107 | """filecache for files in the store""" |
|
107 | """filecache for files in the store""" | |
108 | def __init__(self, *paths): |
|
108 | def __init__(self, *paths): | |
109 | super(storecache, self).__init__(*paths) |
|
109 | super(storecache, self).__init__(*paths) | |
110 | for path in paths: |
|
110 | for path in paths: | |
111 | _cachedfiles.add((path, '')) |
|
111 | _cachedfiles.add((path, '')) | |
112 |
|
112 | |||
113 | def join(self, obj, fname): |
|
113 | def join(self, obj, fname): | |
114 | return obj.sjoin(fname) |
|
114 | return obj.sjoin(fname) | |
115 |
|
115 | |||
116 | def isfilecached(repo, name): |
|
116 | def isfilecached(repo, name): | |
117 | """check if a repo has already cached "name" filecache-ed property |
|
117 | """check if a repo has already cached "name" filecache-ed property | |
118 |
|
118 | |||
119 | This returns (cachedobj-or-None, iscached) tuple. |
|
119 | This returns (cachedobj-or-None, iscached) tuple. | |
120 | """ |
|
120 | """ | |
121 | cacheentry = repo.unfiltered()._filecache.get(name, None) |
|
121 | cacheentry = repo.unfiltered()._filecache.get(name, None) | |
122 | if not cacheentry: |
|
122 | if not cacheentry: | |
123 | return None, False |
|
123 | return None, False | |
124 | return cacheentry.obj, True |
|
124 | return cacheentry.obj, True | |
125 |
|
125 | |||
126 | class unfilteredpropertycache(util.propertycache): |
|
126 | class unfilteredpropertycache(util.propertycache): | |
127 | """propertycache that apply to unfiltered repo only""" |
|
127 | """propertycache that apply to unfiltered repo only""" | |
128 |
|
128 | |||
129 | def __get__(self, repo, type=None): |
|
129 | def __get__(self, repo, type=None): | |
130 | unfi = repo.unfiltered() |
|
130 | unfi = repo.unfiltered() | |
131 | if unfi is repo: |
|
131 | if unfi is repo: | |
132 | return super(unfilteredpropertycache, self).__get__(unfi) |
|
132 | return super(unfilteredpropertycache, self).__get__(unfi) | |
133 | return getattr(unfi, self.name) |
|
133 | return getattr(unfi, self.name) | |
134 |
|
134 | |||
135 | class filteredpropertycache(util.propertycache): |
|
135 | class filteredpropertycache(util.propertycache): | |
136 | """propertycache that must take filtering in account""" |
|
136 | """propertycache that must take filtering in account""" | |
137 |
|
137 | |||
138 | def cachevalue(self, obj, value): |
|
138 | def cachevalue(self, obj, value): | |
139 | object.__setattr__(obj, self.name, value) |
|
139 | object.__setattr__(obj, self.name, value) | |
140 |
|
140 | |||
141 |
|
141 | |||
142 | def hasunfilteredcache(repo, name): |
|
142 | def hasunfilteredcache(repo, name): | |
143 | """check if a repo has an unfilteredpropertycache value for <name>""" |
|
143 | """check if a repo has an unfilteredpropertycache value for <name>""" | |
144 | return name in vars(repo.unfiltered()) |
|
144 | return name in vars(repo.unfiltered()) | |
145 |
|
145 | |||
146 | def unfilteredmethod(orig): |
|
146 | def unfilteredmethod(orig): | |
147 | """decorate method that always need to be run on unfiltered version""" |
|
147 | """decorate method that always need to be run on unfiltered version""" | |
148 | def wrapper(repo, *args, **kwargs): |
|
148 | def wrapper(repo, *args, **kwargs): | |
149 | return orig(repo.unfiltered(), *args, **kwargs) |
|
149 | return orig(repo.unfiltered(), *args, **kwargs) | |
150 | return wrapper |
|
150 | return wrapper | |
151 |
|
151 | |||
152 | moderncaps = {'lookup', 'branchmap', 'pushkey', 'known', 'getbundle', |
|
152 | moderncaps = {'lookup', 'branchmap', 'pushkey', 'known', 'getbundle', | |
153 | 'unbundle'} |
|
153 | 'unbundle'} | |
154 | legacycaps = moderncaps.union({'changegroupsubset'}) |
|
154 | legacycaps = moderncaps.union({'changegroupsubset'}) | |
155 |
|
155 | |||
156 | class localpeer(repository.peer): |
|
156 | class localpeer(repository.peer): | |
157 | '''peer for a local repo; reflects only the most recent API''' |
|
157 | '''peer for a local repo; reflects only the most recent API''' | |
158 |
|
158 | |||
159 | def __init__(self, repo, caps=None): |
|
159 | def __init__(self, repo, caps=None): | |
160 | super(localpeer, self).__init__() |
|
160 | super(localpeer, self).__init__() | |
161 |
|
161 | |||
162 | if caps is None: |
|
162 | if caps is None: | |
163 | caps = moderncaps.copy() |
|
163 | caps = moderncaps.copy() | |
164 | self._repo = repo.filtered('served') |
|
164 | self._repo = repo.filtered('served') | |
165 | self._ui = repo.ui |
|
165 | self._ui = repo.ui | |
166 | self._caps = repo._restrictcapabilities(caps) |
|
166 | self._caps = repo._restrictcapabilities(caps) | |
167 |
|
167 | |||
168 | # Begin of _basepeer interface. |
|
168 | # Begin of _basepeer interface. | |
169 |
|
169 | |||
170 | @util.propertycache |
|
170 | @util.propertycache | |
171 | def ui(self): |
|
171 | def ui(self): | |
172 | return self._ui |
|
172 | return self._ui | |
173 |
|
173 | |||
174 | def url(self): |
|
174 | def url(self): | |
175 | return self._repo.url() |
|
175 | return self._repo.url() | |
176 |
|
176 | |||
177 | def local(self): |
|
177 | def local(self): | |
178 | return self._repo |
|
178 | return self._repo | |
179 |
|
179 | |||
180 | def peer(self): |
|
180 | def peer(self): | |
181 | return self |
|
181 | return self | |
182 |
|
182 | |||
183 | def canpush(self): |
|
183 | def canpush(self): | |
184 | return True |
|
184 | return True | |
185 |
|
185 | |||
186 | def close(self): |
|
186 | def close(self): | |
187 | self._repo.close() |
|
187 | self._repo.close() | |
188 |
|
188 | |||
189 | # End of _basepeer interface. |
|
189 | # End of _basepeer interface. | |
190 |
|
190 | |||
191 | # Begin of _basewirecommands interface. |
|
191 | # Begin of _basewirecommands interface. | |
192 |
|
192 | |||
193 | def branchmap(self): |
|
193 | def branchmap(self): | |
194 | return self._repo.branchmap() |
|
194 | return self._repo.branchmap() | |
195 |
|
195 | |||
196 | def capabilities(self): |
|
196 | def capabilities(self): | |
197 | return self._caps |
|
197 | return self._caps | |
198 |
|
198 | |||
199 | def debugwireargs(self, one, two, three=None, four=None, five=None): |
|
199 | def debugwireargs(self, one, two, three=None, four=None, five=None): | |
200 | """Used to test argument passing over the wire""" |
|
200 | """Used to test argument passing over the wire""" | |
201 | return "%s %s %s %s %s" % (one, two, pycompat.bytestr(three), |
|
201 | return "%s %s %s %s %s" % (one, two, pycompat.bytestr(three), | |
202 | pycompat.bytestr(four), |
|
202 | pycompat.bytestr(four), | |
203 | pycompat.bytestr(five)) |
|
203 | pycompat.bytestr(five)) | |
204 |
|
204 | |||
205 | def getbundle(self, source, heads=None, common=None, bundlecaps=None, |
|
205 | def getbundle(self, source, heads=None, common=None, bundlecaps=None, | |
206 | **kwargs): |
|
206 | **kwargs): | |
207 | chunks = exchange.getbundlechunks(self._repo, source, heads=heads, |
|
207 | chunks = exchange.getbundlechunks(self._repo, source, heads=heads, | |
208 | common=common, bundlecaps=bundlecaps, |
|
208 | common=common, bundlecaps=bundlecaps, | |
209 | **kwargs)[1] |
|
209 | **kwargs)[1] | |
210 | cb = util.chunkbuffer(chunks) |
|
210 | cb = util.chunkbuffer(chunks) | |
211 |
|
211 | |||
212 | if exchange.bundle2requested(bundlecaps): |
|
212 | if exchange.bundle2requested(bundlecaps): | |
213 | # When requesting a bundle2, getbundle returns a stream to make the |
|
213 | # When requesting a bundle2, getbundle returns a stream to make the | |
214 | # wire level function happier. We need to build a proper object |
|
214 | # wire level function happier. We need to build a proper object | |
215 | # from it in local peer. |
|
215 | # from it in local peer. | |
216 | return bundle2.getunbundler(self.ui, cb) |
|
216 | return bundle2.getunbundler(self.ui, cb) | |
217 | else: |
|
217 | else: | |
218 | return changegroup.getunbundler('01', cb, None) |
|
218 | return changegroup.getunbundler('01', cb, None) | |
219 |
|
219 | |||
220 | def heads(self): |
|
220 | def heads(self): | |
221 | return self._repo.heads() |
|
221 | return self._repo.heads() | |
222 |
|
222 | |||
223 | def known(self, nodes): |
|
223 | def known(self, nodes): | |
224 | return self._repo.known(nodes) |
|
224 | return self._repo.known(nodes) | |
225 |
|
225 | |||
226 | def listkeys(self, namespace): |
|
226 | def listkeys(self, namespace): | |
227 | return self._repo.listkeys(namespace) |
|
227 | return self._repo.listkeys(namespace) | |
228 |
|
228 | |||
229 | def lookup(self, key): |
|
229 | def lookup(self, key): | |
230 | return self._repo.lookup(key) |
|
230 | return self._repo.lookup(key) | |
231 |
|
231 | |||
232 | def pushkey(self, namespace, key, old, new): |
|
232 | def pushkey(self, namespace, key, old, new): | |
233 | return self._repo.pushkey(namespace, key, old, new) |
|
233 | return self._repo.pushkey(namespace, key, old, new) | |
234 |
|
234 | |||
235 | def stream_out(self): |
|
235 | def stream_out(self): | |
236 | raise error.Abort(_('cannot perform stream clone against local ' |
|
236 | raise error.Abort(_('cannot perform stream clone against local ' | |
237 | 'peer')) |
|
237 | 'peer')) | |
238 |
|
238 | |||
239 | def unbundle(self, cg, heads, url): |
|
239 | def unbundle(self, cg, heads, url): | |
240 | """apply a bundle on a repo |
|
240 | """apply a bundle on a repo | |
241 |
|
241 | |||
242 | This function handles the repo locking itself.""" |
|
242 | This function handles the repo locking itself.""" | |
243 | try: |
|
243 | try: | |
244 | try: |
|
244 | try: | |
245 | cg = exchange.readbundle(self.ui, cg, None) |
|
245 | cg = exchange.readbundle(self.ui, cg, None) | |
246 | ret = exchange.unbundle(self._repo, cg, heads, 'push', url) |
|
246 | ret = exchange.unbundle(self._repo, cg, heads, 'push', url) | |
247 | if util.safehasattr(ret, 'getchunks'): |
|
247 | if util.safehasattr(ret, 'getchunks'): | |
248 | # This is a bundle20 object, turn it into an unbundler. |
|
248 | # This is a bundle20 object, turn it into an unbundler. | |
249 | # This little dance should be dropped eventually when the |
|
249 | # This little dance should be dropped eventually when the | |
250 | # API is finally improved. |
|
250 | # API is finally improved. | |
251 | stream = util.chunkbuffer(ret.getchunks()) |
|
251 | stream = util.chunkbuffer(ret.getchunks()) | |
252 | ret = bundle2.getunbundler(self.ui, stream) |
|
252 | ret = bundle2.getunbundler(self.ui, stream) | |
253 | return ret |
|
253 | return ret | |
254 | except Exception as exc: |
|
254 | except Exception as exc: | |
255 | # If the exception contains output salvaged from a bundle2 |
|
255 | # If the exception contains output salvaged from a bundle2 | |
256 | # reply, we need to make sure it is printed before continuing |
|
256 | # reply, we need to make sure it is printed before continuing | |
257 | # to fail. So we build a bundle2 with such output and consume |
|
257 | # to fail. So we build a bundle2 with such output and consume | |
258 | # it directly. |
|
258 | # it directly. | |
259 | # |
|
259 | # | |
260 | # This is not very elegant but allows a "simple" solution for |
|
260 | # This is not very elegant but allows a "simple" solution for | |
261 | # issue4594 |
|
261 | # issue4594 | |
262 | output = getattr(exc, '_bundle2salvagedoutput', ()) |
|
262 | output = getattr(exc, '_bundle2salvagedoutput', ()) | |
263 | if output: |
|
263 | if output: | |
264 | bundler = bundle2.bundle20(self._repo.ui) |
|
264 | bundler = bundle2.bundle20(self._repo.ui) | |
265 | for out in output: |
|
265 | for out in output: | |
266 | bundler.addpart(out) |
|
266 | bundler.addpart(out) | |
267 | stream = util.chunkbuffer(bundler.getchunks()) |
|
267 | stream = util.chunkbuffer(bundler.getchunks()) | |
268 | b = bundle2.getunbundler(self.ui, stream) |
|
268 | b = bundle2.getunbundler(self.ui, stream) | |
269 | bundle2.processbundle(self._repo, b) |
|
269 | bundle2.processbundle(self._repo, b) | |
270 | raise |
|
270 | raise | |
271 | except error.PushRaced as exc: |
|
271 | except error.PushRaced as exc: | |
272 | raise error.ResponseError(_('push failed:'), |
|
272 | raise error.ResponseError(_('push failed:'), | |
273 | stringutil.forcebytestr(exc)) |
|
273 | stringutil.forcebytestr(exc)) | |
274 |
|
274 | |||
275 | # End of _basewirecommands interface. |
|
275 | # End of _basewirecommands interface. | |
276 |
|
276 | |||
277 | # Begin of peer interface. |
|
277 | # Begin of peer interface. | |
278 |
|
278 | |||
279 | def iterbatch(self): |
|
279 | def iterbatch(self): | |
280 | return peer.localiterbatcher(self) |
|
280 | return peer.localiterbatcher(self) | |
281 |
|
281 | |||
282 | # End of peer interface. |
|
282 | # End of peer interface. | |
283 |
|
283 | |||
284 | class locallegacypeer(repository.legacypeer, localpeer): |
|
284 | class locallegacypeer(repository.legacypeer, localpeer): | |
285 | '''peer extension which implements legacy methods too; used for tests with |
|
285 | '''peer extension which implements legacy methods too; used for tests with | |
286 | restricted capabilities''' |
|
286 | restricted capabilities''' | |
287 |
|
287 | |||
288 | def __init__(self, repo): |
|
288 | def __init__(self, repo): | |
289 | super(locallegacypeer, self).__init__(repo, caps=legacycaps) |
|
289 | super(locallegacypeer, self).__init__(repo, caps=legacycaps) | |
290 |
|
290 | |||
291 | # Begin of baselegacywirecommands interface. |
|
291 | # Begin of baselegacywirecommands interface. | |
292 |
|
292 | |||
293 | def between(self, pairs): |
|
293 | def between(self, pairs): | |
294 | return self._repo.between(pairs) |
|
294 | return self._repo.between(pairs) | |
295 |
|
295 | |||
296 | def branches(self, nodes): |
|
296 | def branches(self, nodes): | |
297 | return self._repo.branches(nodes) |
|
297 | return self._repo.branches(nodes) | |
298 |
|
298 | |||
299 | def changegroup(self, basenodes, source): |
|
299 | def changegroup(self, basenodes, source): | |
300 | outgoing = discovery.outgoing(self._repo, missingroots=basenodes, |
|
300 | outgoing = discovery.outgoing(self._repo, missingroots=basenodes, | |
301 | missingheads=self._repo.heads()) |
|
301 | missingheads=self._repo.heads()) | |
302 | return changegroup.makechangegroup(self._repo, outgoing, '01', source) |
|
302 | return changegroup.makechangegroup(self._repo, outgoing, '01', source) | |
303 |
|
303 | |||
304 | def changegroupsubset(self, bases, heads, source): |
|
304 | def changegroupsubset(self, bases, heads, source): | |
305 | outgoing = discovery.outgoing(self._repo, missingroots=bases, |
|
305 | outgoing = discovery.outgoing(self._repo, missingroots=bases, | |
306 | missingheads=heads) |
|
306 | missingheads=heads) | |
307 | return changegroup.makechangegroup(self._repo, outgoing, '01', source) |
|
307 | return changegroup.makechangegroup(self._repo, outgoing, '01', source) | |
308 |
|
308 | |||
309 | # End of baselegacywirecommands interface. |
|
309 | # End of baselegacywirecommands interface. | |
310 |
|
310 | |||
311 | # Increment the sub-version when the revlog v2 format changes to lock out old |
|
311 | # Increment the sub-version when the revlog v2 format changes to lock out old | |
312 | # clients. |
|
312 | # clients. | |
313 | REVLOGV2_REQUIREMENT = 'exp-revlogv2.0' |
|
313 | REVLOGV2_REQUIREMENT = 'exp-revlogv2.0' | |
314 |
|
314 | |||
315 | # Functions receiving (ui, features) that extensions can register to impact |
|
315 | # Functions receiving (ui, features) that extensions can register to impact | |
316 | # the ability to load repositories with custom requirements. Only |
|
316 | # the ability to load repositories with custom requirements. Only | |
317 | # functions defined in loaded extensions are called. |
|
317 | # functions defined in loaded extensions are called. | |
318 | # |
|
318 | # | |
319 | # The function receives a set of requirement strings that the repository |
|
319 | # The function receives a set of requirement strings that the repository | |
320 | # is capable of opening. Functions will typically add elements to the |
|
320 | # is capable of opening. Functions will typically add elements to the | |
321 | # set to reflect that the extension knows how to handle that requirements. |
|
321 | # set to reflect that the extension knows how to handle that requirements. | |
322 | featuresetupfuncs = set() |
|
322 | featuresetupfuncs = set() | |
323 |
|
323 | |||
324 | @zi.implementer(repository.completelocalrepository) |
|
324 | @zi.implementer(repository.completelocalrepository) | |
325 | class localrepository(object): |
|
325 | class localrepository(object): | |
326 |
|
326 | |||
327 | # obsolete experimental requirements: |
|
327 | # obsolete experimental requirements: | |
328 | # - manifestv2: An experimental new manifest format that allowed |
|
328 | # - manifestv2: An experimental new manifest format that allowed | |
329 | # for stem compression of long paths. Experiment ended up not |
|
329 | # for stem compression of long paths. Experiment ended up not | |
330 | # being successful (repository sizes went up due to worse delta |
|
330 | # being successful (repository sizes went up due to worse delta | |
331 | # chains), and the code was deleted in 4.6. |
|
331 | # chains), and the code was deleted in 4.6. | |
332 | supportedformats = { |
|
332 | supportedformats = { | |
333 | 'revlogv1', |
|
333 | 'revlogv1', | |
334 | 'generaldelta', |
|
334 | 'generaldelta', | |
335 | 'treemanifest', |
|
335 | 'treemanifest', | |
336 | REVLOGV2_REQUIREMENT, |
|
336 | REVLOGV2_REQUIREMENT, | |
337 | } |
|
337 | } | |
338 | _basesupported = supportedformats | { |
|
338 | _basesupported = supportedformats | { | |
339 | 'store', |
|
339 | 'store', | |
340 | 'fncache', |
|
340 | 'fncache', | |
341 | 'shared', |
|
341 | 'shared', | |
342 | 'relshared', |
|
342 | 'relshared', | |
343 | 'dotencode', |
|
343 | 'dotencode', | |
344 | 'exp-sparse', |
|
344 | 'exp-sparse', | |
345 | } |
|
345 | } | |
346 | openerreqs = { |
|
346 | openerreqs = { | |
347 | 'revlogv1', |
|
347 | 'revlogv1', | |
348 | 'generaldelta', |
|
348 | 'generaldelta', | |
349 | 'treemanifest', |
|
349 | 'treemanifest', | |
350 | } |
|
350 | } | |
351 |
|
351 | |||
352 | # list of prefix for file which can be written without 'wlock' |
|
352 | # list of prefix for file which can be written without 'wlock' | |
353 | # Extensions should extend this list when needed |
|
353 | # Extensions should extend this list when needed | |
354 | _wlockfreeprefix = { |
|
354 | _wlockfreeprefix = { | |
355 | # We migh consider requiring 'wlock' for the next |
|
355 | # We migh consider requiring 'wlock' for the next | |
356 | # two, but pretty much all the existing code assume |
|
356 | # two, but pretty much all the existing code assume | |
357 | # wlock is not needed so we keep them excluded for |
|
357 | # wlock is not needed so we keep them excluded for | |
358 | # now. |
|
358 | # now. | |
359 | 'hgrc', |
|
359 | 'hgrc', | |
360 | 'requires', |
|
360 | 'requires', | |
361 | # XXX cache is a complicatged business someone |
|
361 | # XXX cache is a complicatged business someone | |
362 | # should investigate this in depth at some point |
|
362 | # should investigate this in depth at some point | |
363 | 'cache/', |
|
363 | 'cache/', | |
364 | # XXX shouldn't be dirstate covered by the wlock? |
|
364 | # XXX shouldn't be dirstate covered by the wlock? | |
365 | 'dirstate', |
|
365 | 'dirstate', | |
366 | # XXX bisect was still a bit too messy at the time |
|
366 | # XXX bisect was still a bit too messy at the time | |
367 | # this changeset was introduced. Someone should fix |
|
367 | # this changeset was introduced. Someone should fix | |
368 | # the remainig bit and drop this line |
|
368 | # the remainig bit and drop this line | |
369 | 'bisect.state', |
|
369 | 'bisect.state', | |
370 | } |
|
370 | } | |
371 |
|
371 | |||
372 | def __init__(self, baseui, path, create=False): |
|
372 | def __init__(self, baseui, path, create=False): | |
373 | self.requirements = set() |
|
373 | self.requirements = set() | |
374 | self.filtername = None |
|
374 | self.filtername = None | |
375 | # wvfs: rooted at the repository root, used to access the working copy |
|
375 | # wvfs: rooted at the repository root, used to access the working copy | |
376 | self.wvfs = vfsmod.vfs(path, expandpath=True, realpath=True) |
|
376 | self.wvfs = vfsmod.vfs(path, expandpath=True, realpath=True) | |
377 | # vfs: rooted at .hg, used to access repo files outside of .hg/store |
|
377 | # vfs: rooted at .hg, used to access repo files outside of .hg/store | |
378 | self.vfs = None |
|
378 | self.vfs = None | |
379 | # svfs: usually rooted at .hg/store, used to access repository history |
|
379 | # svfs: usually rooted at .hg/store, used to access repository history | |
380 | # If this is a shared repository, this vfs may point to another |
|
380 | # If this is a shared repository, this vfs may point to another | |
381 | # repository's .hg/store directory. |
|
381 | # repository's .hg/store directory. | |
382 | self.svfs = None |
|
382 | self.svfs = None | |
383 | self.root = self.wvfs.base |
|
383 | self.root = self.wvfs.base | |
384 | self.path = self.wvfs.join(".hg") |
|
384 | self.path = self.wvfs.join(".hg") | |
385 | self.origroot = path |
|
385 | self.origroot = path | |
386 | # This is only used by context.workingctx.match in order to |
|
386 | # This is only used by context.workingctx.match in order to | |
387 | # detect files in subrepos. |
|
387 | # detect files in subrepos. | |
388 | self.auditor = pathutil.pathauditor( |
|
388 | self.auditor = pathutil.pathauditor( | |
389 | self.root, callback=self._checknested) |
|
389 | self.root, callback=self._checknested) | |
390 | # This is only used by context.basectx.match in order to detect |
|
390 | # This is only used by context.basectx.match in order to detect | |
391 | # files in subrepos. |
|
391 | # files in subrepos. | |
392 | self.nofsauditor = pathutil.pathauditor( |
|
392 | self.nofsauditor = pathutil.pathauditor( | |
393 | self.root, callback=self._checknested, realfs=False, cached=True) |
|
393 | self.root, callback=self._checknested, realfs=False, cached=True) | |
394 | self.baseui = baseui |
|
394 | self.baseui = baseui | |
395 | self.ui = baseui.copy() |
|
395 | self.ui = baseui.copy() | |
396 | self.ui.copy = baseui.copy # prevent copying repo configuration |
|
396 | self.ui.copy = baseui.copy # prevent copying repo configuration | |
397 | self.vfs = vfsmod.vfs(self.path, cacheaudited=True) |
|
397 | self.vfs = vfsmod.vfs(self.path, cacheaudited=True) | |
398 | if (self.ui.configbool('devel', 'all-warnings') or |
|
398 | if (self.ui.configbool('devel', 'all-warnings') or | |
399 | self.ui.configbool('devel', 'check-locks')): |
|
399 | self.ui.configbool('devel', 'check-locks')): | |
400 | self.vfs.audit = self._getvfsward(self.vfs.audit) |
|
400 | self.vfs.audit = self._getvfsward(self.vfs.audit) | |
401 | # A list of callback to shape the phase if no data were found. |
|
401 | # A list of callback to shape the phase if no data were found. | |
402 | # Callback are in the form: func(repo, roots) --> processed root. |
|
402 | # Callback are in the form: func(repo, roots) --> processed root. | |
403 | # This list it to be filled by extension during repo setup |
|
403 | # This list it to be filled by extension during repo setup | |
404 | self._phasedefaults = [] |
|
404 | self._phasedefaults = [] | |
405 | try: |
|
405 | try: | |
406 | self.ui.readconfig(self.vfs.join("hgrc"), self.root) |
|
406 | self.ui.readconfig(self.vfs.join("hgrc"), self.root) | |
407 | self._loadextensions() |
|
407 | self._loadextensions() | |
408 | except IOError: |
|
408 | except IOError: | |
409 | pass |
|
409 | pass | |
410 |
|
410 | |||
411 | if featuresetupfuncs: |
|
411 | if featuresetupfuncs: | |
412 | self.supported = set(self._basesupported) # use private copy |
|
412 | self.supported = set(self._basesupported) # use private copy | |
413 | extmods = set(m.__name__ for n, m |
|
413 | extmods = set(m.__name__ for n, m | |
414 | in extensions.extensions(self.ui)) |
|
414 | in extensions.extensions(self.ui)) | |
415 | for setupfunc in featuresetupfuncs: |
|
415 | for setupfunc in featuresetupfuncs: | |
416 | if setupfunc.__module__ in extmods: |
|
416 | if setupfunc.__module__ in extmods: | |
417 | setupfunc(self.ui, self.supported) |
|
417 | setupfunc(self.ui, self.supported) | |
418 | else: |
|
418 | else: | |
419 | self.supported = self._basesupported |
|
419 | self.supported = self._basesupported | |
420 | color.setup(self.ui) |
|
420 | color.setup(self.ui) | |
421 |
|
421 | |||
422 | # Add compression engines. |
|
422 | # Add compression engines. | |
423 | for name in util.compengines: |
|
423 | for name in util.compengines: | |
424 | engine = util.compengines[name] |
|
424 | engine = util.compengines[name] | |
425 | if engine.revlogheader(): |
|
425 | if engine.revlogheader(): | |
426 | self.supported.add('exp-compression-%s' % name) |
|
426 | self.supported.add('exp-compression-%s' % name) | |
427 |
|
427 | |||
428 | if not self.vfs.isdir(): |
|
428 | if not self.vfs.isdir(): | |
429 | if create: |
|
429 | if create: | |
430 | self.requirements = newreporequirements(self) |
|
430 | self.requirements = newreporequirements(self) | |
431 |
|
431 | |||
432 | if not self.wvfs.exists(): |
|
432 | if not self.wvfs.exists(): | |
433 | self.wvfs.makedirs() |
|
433 | self.wvfs.makedirs() | |
434 | self.vfs.makedir(notindexed=True) |
|
434 | self.vfs.makedir(notindexed=True) | |
435 |
|
435 | |||
436 | if 'store' in self.requirements: |
|
436 | if 'store' in self.requirements: | |
437 | self.vfs.mkdir("store") |
|
437 | self.vfs.mkdir("store") | |
438 |
|
438 | |||
439 | # create an invalid changelog |
|
439 | # create an invalid changelog | |
440 | self.vfs.append( |
|
440 | self.vfs.append( | |
441 | "00changelog.i", |
|
441 | "00changelog.i", | |
442 | '\0\0\0\2' # represents revlogv2 |
|
442 | '\0\0\0\2' # represents revlogv2 | |
443 | ' dummy changelog to prevent using the old repo layout' |
|
443 | ' dummy changelog to prevent using the old repo layout' | |
444 | ) |
|
444 | ) | |
445 | else: |
|
445 | else: | |
446 | raise error.RepoError(_("repository %s not found") % path) |
|
446 | raise error.RepoError(_("repository %s not found") % path) | |
447 | elif create: |
|
447 | elif create: | |
448 | raise error.RepoError(_("repository %s already exists") % path) |
|
448 | raise error.RepoError(_("repository %s already exists") % path) | |
449 | else: |
|
449 | else: | |
450 | try: |
|
450 | try: | |
451 | self.requirements = scmutil.readrequires( |
|
451 | self.requirements = scmutil.readrequires( | |
452 | self.vfs, self.supported) |
|
452 | self.vfs, self.supported) | |
453 | except IOError as inst: |
|
453 | except IOError as inst: | |
454 | if inst.errno != errno.ENOENT: |
|
454 | if inst.errno != errno.ENOENT: | |
455 | raise |
|
455 | raise | |
456 |
|
456 | |||
457 | cachepath = self.vfs.join('cache') |
|
457 | cachepath = self.vfs.join('cache') | |
458 | self.sharedpath = self.path |
|
458 | self.sharedpath = self.path | |
459 | try: |
|
459 | try: | |
460 | sharedpath = self.vfs.read("sharedpath").rstrip('\n') |
|
460 | sharedpath = self.vfs.read("sharedpath").rstrip('\n') | |
461 | if 'relshared' in self.requirements: |
|
461 | if 'relshared' in self.requirements: | |
462 | sharedpath = self.vfs.join(sharedpath) |
|
462 | sharedpath = self.vfs.join(sharedpath) | |
463 | vfs = vfsmod.vfs(sharedpath, realpath=True) |
|
463 | vfs = vfsmod.vfs(sharedpath, realpath=True) | |
464 | cachepath = vfs.join('cache') |
|
464 | cachepath = vfs.join('cache') | |
465 | s = vfs.base |
|
465 | s = vfs.base | |
466 | if not vfs.exists(): |
|
466 | if not vfs.exists(): | |
467 | raise error.RepoError( |
|
467 | raise error.RepoError( | |
468 | _('.hg/sharedpath points to nonexistent directory %s') % s) |
|
468 | _('.hg/sharedpath points to nonexistent directory %s') % s) | |
469 | self.sharedpath = s |
|
469 | self.sharedpath = s | |
470 | except IOError as inst: |
|
470 | except IOError as inst: | |
471 | if inst.errno != errno.ENOENT: |
|
471 | if inst.errno != errno.ENOENT: | |
472 | raise |
|
472 | raise | |
473 |
|
473 | |||
474 | if 'exp-sparse' in self.requirements and not sparse.enabled: |
|
474 | if 'exp-sparse' in self.requirements and not sparse.enabled: | |
475 | raise error.RepoError(_('repository is using sparse feature but ' |
|
475 | raise error.RepoError(_('repository is using sparse feature but ' | |
476 | 'sparse is not enabled; enable the ' |
|
476 | 'sparse is not enabled; enable the ' | |
477 | '"sparse" extensions to access')) |
|
477 | '"sparse" extensions to access')) | |
478 |
|
478 | |||
479 | self.store = store.store( |
|
479 | self.store = store.store( | |
480 | self.requirements, self.sharedpath, |
|
480 | self.requirements, self.sharedpath, | |
481 | lambda base: vfsmod.vfs(base, cacheaudited=True)) |
|
481 | lambda base: vfsmod.vfs(base, cacheaudited=True)) | |
482 | self.spath = self.store.path |
|
482 | self.spath = self.store.path | |
483 | self.svfs = self.store.vfs |
|
483 | self.svfs = self.store.vfs | |
484 | self.sjoin = self.store.join |
|
484 | self.sjoin = self.store.join | |
485 | self.vfs.createmode = self.store.createmode |
|
485 | self.vfs.createmode = self.store.createmode | |
486 | self.cachevfs = vfsmod.vfs(cachepath, cacheaudited=True) |
|
486 | self.cachevfs = vfsmod.vfs(cachepath, cacheaudited=True) | |
487 | self.cachevfs.createmode = self.store.createmode |
|
487 | self.cachevfs.createmode = self.store.createmode | |
488 | if (self.ui.configbool('devel', 'all-warnings') or |
|
488 | if (self.ui.configbool('devel', 'all-warnings') or | |
489 | self.ui.configbool('devel', 'check-locks')): |
|
489 | self.ui.configbool('devel', 'check-locks')): | |
490 | if util.safehasattr(self.svfs, 'vfs'): # this is filtervfs |
|
490 | if util.safehasattr(self.svfs, 'vfs'): # this is filtervfs | |
491 | self.svfs.vfs.audit = self._getsvfsward(self.svfs.vfs.audit) |
|
491 | self.svfs.vfs.audit = self._getsvfsward(self.svfs.vfs.audit) | |
492 | else: # standard vfs |
|
492 | else: # standard vfs | |
493 | self.svfs.audit = self._getsvfsward(self.svfs.audit) |
|
493 | self.svfs.audit = self._getsvfsward(self.svfs.audit) | |
494 | self._applyopenerreqs() |
|
494 | self._applyopenerreqs() | |
495 | if create: |
|
495 | if create: | |
496 | self._writerequirements() |
|
496 | self._writerequirements() | |
497 |
|
497 | |||
498 | self._dirstatevalidatewarned = False |
|
498 | self._dirstatevalidatewarned = False | |
499 |
|
499 | |||
500 | self._branchcaches = {} |
|
500 | self._branchcaches = {} | |
501 | self._revbranchcache = None |
|
501 | self._revbranchcache = None | |
502 | self._filterpats = {} |
|
502 | self._filterpats = {} | |
503 | self._datafilters = {} |
|
503 | self._datafilters = {} | |
504 | self._transref = self._lockref = self._wlockref = None |
|
504 | self._transref = self._lockref = self._wlockref = None | |
505 |
|
505 | |||
506 | # A cache for various files under .hg/ that tracks file changes, |
|
506 | # A cache for various files under .hg/ that tracks file changes, | |
507 | # (used by the filecache decorator) |
|
507 | # (used by the filecache decorator) | |
508 | # |
|
508 | # | |
509 | # Maps a property name to its util.filecacheentry |
|
509 | # Maps a property name to its util.filecacheentry | |
510 | self._filecache = {} |
|
510 | self._filecache = {} | |
511 |
|
511 | |||
512 | # hold sets of revision to be filtered |
|
512 | # hold sets of revision to be filtered | |
513 | # should be cleared when something might have changed the filter value: |
|
513 | # should be cleared when something might have changed the filter value: | |
514 | # - new changesets, |
|
514 | # - new changesets, | |
515 | # - phase change, |
|
515 | # - phase change, | |
516 | # - new obsolescence marker, |
|
516 | # - new obsolescence marker, | |
517 | # - working directory parent change, |
|
517 | # - working directory parent change, | |
518 | # - bookmark changes |
|
518 | # - bookmark changes | |
519 | self.filteredrevcache = {} |
|
519 | self.filteredrevcache = {} | |
520 |
|
520 | |||
521 | # post-dirstate-status hooks |
|
521 | # post-dirstate-status hooks | |
522 | self._postdsstatus = [] |
|
522 | self._postdsstatus = [] | |
523 |
|
523 | |||
524 | # generic mapping between names and nodes |
|
524 | # generic mapping between names and nodes | |
525 | self.names = namespaces.namespaces() |
|
525 | self.names = namespaces.namespaces() | |
526 |
|
526 | |||
527 | # Key to signature value. |
|
527 | # Key to signature value. | |
528 | self._sparsesignaturecache = {} |
|
528 | self._sparsesignaturecache = {} | |
529 | # Signature to cached matcher instance. |
|
529 | # Signature to cached matcher instance. | |
530 | self._sparsematchercache = {} |
|
530 | self._sparsematchercache = {} | |
531 |
|
531 | |||
532 | def _getvfsward(self, origfunc): |
|
532 | def _getvfsward(self, origfunc): | |
533 | """build a ward for self.vfs""" |
|
533 | """build a ward for self.vfs""" | |
534 | rref = weakref.ref(self) |
|
534 | rref = weakref.ref(self) | |
535 | def checkvfs(path, mode=None): |
|
535 | def checkvfs(path, mode=None): | |
536 | ret = origfunc(path, mode=mode) |
|
536 | ret = origfunc(path, mode=mode) | |
537 | repo = rref() |
|
537 | repo = rref() | |
538 | if (repo is None |
|
538 | if (repo is None | |
539 | or not util.safehasattr(repo, '_wlockref') |
|
539 | or not util.safehasattr(repo, '_wlockref') | |
540 | or not util.safehasattr(repo, '_lockref')): |
|
540 | or not util.safehasattr(repo, '_lockref')): | |
541 | return |
|
541 | return | |
542 | if mode in (None, 'r', 'rb'): |
|
542 | if mode in (None, 'r', 'rb'): | |
543 | return |
|
543 | return | |
544 | if path.startswith(repo.path): |
|
544 | if path.startswith(repo.path): | |
545 | # truncate name relative to the repository (.hg) |
|
545 | # truncate name relative to the repository (.hg) | |
546 | path = path[len(repo.path) + 1:] |
|
546 | path = path[len(repo.path) + 1:] | |
547 | if path.startswith('cache/'): |
|
547 | if path.startswith('cache/'): | |
548 | msg = 'accessing cache with vfs instead of cachevfs: "%s"' |
|
548 | msg = 'accessing cache with vfs instead of cachevfs: "%s"' | |
549 | repo.ui.develwarn(msg % path, stacklevel=2, config="cache-vfs") |
|
549 | repo.ui.develwarn(msg % path, stacklevel=2, config="cache-vfs") | |
550 | if path.startswith('journal.'): |
|
550 | if path.startswith('journal.'): | |
551 | # journal is covered by 'lock' |
|
551 | # journal is covered by 'lock' | |
552 | if repo._currentlock(repo._lockref) is None: |
|
552 | if repo._currentlock(repo._lockref) is None: | |
553 | repo.ui.develwarn('write with no lock: "%s"' % path, |
|
553 | repo.ui.develwarn('write with no lock: "%s"' % path, | |
554 | stacklevel=2, config='check-locks') |
|
554 | stacklevel=2, config='check-locks') | |
555 | elif repo._currentlock(repo._wlockref) is None: |
|
555 | elif repo._currentlock(repo._wlockref) is None: | |
556 | # rest of vfs files are covered by 'wlock' |
|
556 | # rest of vfs files are covered by 'wlock' | |
557 | # |
|
557 | # | |
558 | # exclude special files |
|
558 | # exclude special files | |
559 | for prefix in self._wlockfreeprefix: |
|
559 | for prefix in self._wlockfreeprefix: | |
560 | if path.startswith(prefix): |
|
560 | if path.startswith(prefix): | |
561 | return |
|
561 | return | |
562 | repo.ui.develwarn('write with no wlock: "%s"' % path, |
|
562 | repo.ui.develwarn('write with no wlock: "%s"' % path, | |
563 | stacklevel=2, config='check-locks') |
|
563 | stacklevel=2, config='check-locks') | |
564 | return ret |
|
564 | return ret | |
565 | return checkvfs |
|
565 | return checkvfs | |
566 |
|
566 | |||
567 | def _getsvfsward(self, origfunc): |
|
567 | def _getsvfsward(self, origfunc): | |
568 | """build a ward for self.svfs""" |
|
568 | """build a ward for self.svfs""" | |
569 | rref = weakref.ref(self) |
|
569 | rref = weakref.ref(self) | |
570 | def checksvfs(path, mode=None): |
|
570 | def checksvfs(path, mode=None): | |
571 | ret = origfunc(path, mode=mode) |
|
571 | ret = origfunc(path, mode=mode) | |
572 | repo = rref() |
|
572 | repo = rref() | |
573 | if repo is None or not util.safehasattr(repo, '_lockref'): |
|
573 | if repo is None or not util.safehasattr(repo, '_lockref'): | |
574 | return |
|
574 | return | |
575 | if mode in (None, 'r', 'rb'): |
|
575 | if mode in (None, 'r', 'rb'): | |
576 | return |
|
576 | return | |
577 | if path.startswith(repo.sharedpath): |
|
577 | if path.startswith(repo.sharedpath): | |
578 | # truncate name relative to the repository (.hg) |
|
578 | # truncate name relative to the repository (.hg) | |
579 | path = path[len(repo.sharedpath) + 1:] |
|
579 | path = path[len(repo.sharedpath) + 1:] | |
580 | if repo._currentlock(repo._lockref) is None: |
|
580 | if repo._currentlock(repo._lockref) is None: | |
581 | repo.ui.develwarn('write with no lock: "%s"' % path, |
|
581 | repo.ui.develwarn('write with no lock: "%s"' % path, | |
582 | stacklevel=3) |
|
582 | stacklevel=3) | |
583 | return ret |
|
583 | return ret | |
584 | return checksvfs |
|
584 | return checksvfs | |
585 |
|
585 | |||
586 | def close(self): |
|
586 | def close(self): | |
587 | self._writecaches() |
|
587 | self._writecaches() | |
588 |
|
588 | |||
589 | def _loadextensions(self): |
|
589 | def _loadextensions(self): | |
590 | extensions.loadall(self.ui) |
|
590 | extensions.loadall(self.ui) | |
591 |
|
591 | |||
592 | def _writecaches(self): |
|
592 | def _writecaches(self): | |
593 | if self._revbranchcache: |
|
593 | if self._revbranchcache: | |
594 | self._revbranchcache.write() |
|
594 | self._revbranchcache.write() | |
595 |
|
595 | |||
596 | def _restrictcapabilities(self, caps): |
|
596 | def _restrictcapabilities(self, caps): | |
597 | if self.ui.configbool('experimental', 'bundle2-advertise'): |
|
597 | if self.ui.configbool('experimental', 'bundle2-advertise'): | |
598 | caps = set(caps) |
|
598 | caps = set(caps) | |
599 | capsblob = bundle2.encodecaps(bundle2.getrepocaps(self, |
|
599 | capsblob = bundle2.encodecaps(bundle2.getrepocaps(self, | |
600 | role='client')) |
|
600 | role='client')) | |
601 | caps.add('bundle2=' + urlreq.quote(capsblob)) |
|
601 | caps.add('bundle2=' + urlreq.quote(capsblob)) | |
602 | return caps |
|
602 | return caps | |
603 |
|
603 | |||
604 | def _applyopenerreqs(self): |
|
604 | def _applyopenerreqs(self): | |
605 | self.svfs.options = dict((r, 1) for r in self.requirements |
|
605 | self.svfs.options = dict((r, 1) for r in self.requirements | |
606 | if r in self.openerreqs) |
|
606 | if r in self.openerreqs) | |
607 | # experimental config: format.chunkcachesize |
|
607 | # experimental config: format.chunkcachesize | |
608 | chunkcachesize = self.ui.configint('format', 'chunkcachesize') |
|
608 | chunkcachesize = self.ui.configint('format', 'chunkcachesize') | |
609 | if chunkcachesize is not None: |
|
609 | if chunkcachesize is not None: | |
610 | self.svfs.options['chunkcachesize'] = chunkcachesize |
|
610 | self.svfs.options['chunkcachesize'] = chunkcachesize | |
611 | # experimental config: format.maxchainlen |
|
611 | # experimental config: format.maxchainlen | |
612 | maxchainlen = self.ui.configint('format', 'maxchainlen') |
|
612 | maxchainlen = self.ui.configint('format', 'maxchainlen') | |
613 | if maxchainlen is not None: |
|
613 | if maxchainlen is not None: | |
614 | self.svfs.options['maxchainlen'] = maxchainlen |
|
614 | self.svfs.options['maxchainlen'] = maxchainlen | |
615 | # experimental config: format.manifestcachesize |
|
615 | # experimental config: format.manifestcachesize | |
616 | manifestcachesize = self.ui.configint('format', 'manifestcachesize') |
|
616 | manifestcachesize = self.ui.configint('format', 'manifestcachesize') | |
617 | if manifestcachesize is not None: |
|
617 | if manifestcachesize is not None: | |
618 | self.svfs.options['manifestcachesize'] = manifestcachesize |
|
618 | self.svfs.options['manifestcachesize'] = manifestcachesize | |
619 | # experimental config: format.aggressivemergedeltas |
|
619 | # experimental config: format.aggressivemergedeltas | |
620 | aggressivemergedeltas = self.ui.configbool('format', |
|
620 | aggressivemergedeltas = self.ui.configbool('format', | |
621 | 'aggressivemergedeltas') |
|
621 | 'aggressivemergedeltas') | |
622 | self.svfs.options['aggressivemergedeltas'] = aggressivemergedeltas |
|
622 | self.svfs.options['aggressivemergedeltas'] = aggressivemergedeltas | |
623 | self.svfs.options['lazydeltabase'] = not scmutil.gddeltaconfig(self.ui) |
|
623 | self.svfs.options['lazydeltabase'] = not scmutil.gddeltaconfig(self.ui) | |
624 | chainspan = self.ui.configbytes('experimental', 'maxdeltachainspan') |
|
624 | chainspan = self.ui.configbytes('experimental', 'maxdeltachainspan') | |
625 | if 0 <= chainspan: |
|
625 | if 0 <= chainspan: | |
626 | self.svfs.options['maxdeltachainspan'] = chainspan |
|
626 | self.svfs.options['maxdeltachainspan'] = chainspan | |
627 | mmapindexthreshold = self.ui.configbytes('experimental', |
|
627 | mmapindexthreshold = self.ui.configbytes('experimental', | |
628 | 'mmapindexthreshold') |
|
628 | 'mmapindexthreshold') | |
629 | if mmapindexthreshold is not None: |
|
629 | if mmapindexthreshold is not None: | |
630 | self.svfs.options['mmapindexthreshold'] = mmapindexthreshold |
|
630 | self.svfs.options['mmapindexthreshold'] = mmapindexthreshold | |
631 | withsparseread = self.ui.configbool('experimental', 'sparse-read') |
|
631 | withsparseread = self.ui.configbool('experimental', 'sparse-read') | |
632 | srdensitythres = float(self.ui.config('experimental', |
|
632 | srdensitythres = float(self.ui.config('experimental', | |
633 | 'sparse-read.density-threshold')) |
|
633 | 'sparse-read.density-threshold')) | |
634 | srmingapsize = self.ui.configbytes('experimental', |
|
634 | srmingapsize = self.ui.configbytes('experimental', | |
635 | 'sparse-read.min-gap-size') |
|
635 | 'sparse-read.min-gap-size') | |
636 | self.svfs.options['with-sparse-read'] = withsparseread |
|
636 | self.svfs.options['with-sparse-read'] = withsparseread | |
637 | self.svfs.options['sparse-read-density-threshold'] = srdensitythres |
|
637 | self.svfs.options['sparse-read-density-threshold'] = srdensitythres | |
638 | self.svfs.options['sparse-read-min-gap-size'] = srmingapsize |
|
638 | self.svfs.options['sparse-read-min-gap-size'] = srmingapsize | |
639 |
|
639 | |||
640 | for r in self.requirements: |
|
640 | for r in self.requirements: | |
641 | if r.startswith('exp-compression-'): |
|
641 | if r.startswith('exp-compression-'): | |
642 | self.svfs.options['compengine'] = r[len('exp-compression-'):] |
|
642 | self.svfs.options['compengine'] = r[len('exp-compression-'):] | |
643 |
|
643 | |||
644 | # TODO move "revlogv2" to openerreqs once finalized. |
|
644 | # TODO move "revlogv2" to openerreqs once finalized. | |
645 | if REVLOGV2_REQUIREMENT in self.requirements: |
|
645 | if REVLOGV2_REQUIREMENT in self.requirements: | |
646 | self.svfs.options['revlogv2'] = True |
|
646 | self.svfs.options['revlogv2'] = True | |
647 |
|
647 | |||
648 | def _writerequirements(self): |
|
648 | def _writerequirements(self): | |
649 | scmutil.writerequires(self.vfs, self.requirements) |
|
649 | scmutil.writerequires(self.vfs, self.requirements) | |
650 |
|
650 | |||
651 | def _checknested(self, path): |
|
651 | def _checknested(self, path): | |
652 | """Determine if path is a legal nested repository.""" |
|
652 | """Determine if path is a legal nested repository.""" | |
653 | if not path.startswith(self.root): |
|
653 | if not path.startswith(self.root): | |
654 | return False |
|
654 | return False | |
655 | subpath = path[len(self.root) + 1:] |
|
655 | subpath = path[len(self.root) + 1:] | |
656 | normsubpath = util.pconvert(subpath) |
|
656 | normsubpath = util.pconvert(subpath) | |
657 |
|
657 | |||
658 | # XXX: Checking against the current working copy is wrong in |
|
658 | # XXX: Checking against the current working copy is wrong in | |
659 | # the sense that it can reject things like |
|
659 | # the sense that it can reject things like | |
660 | # |
|
660 | # | |
661 | # $ hg cat -r 10 sub/x.txt |
|
661 | # $ hg cat -r 10 sub/x.txt | |
662 | # |
|
662 | # | |
663 | # if sub/ is no longer a subrepository in the working copy |
|
663 | # if sub/ is no longer a subrepository in the working copy | |
664 | # parent revision. |
|
664 | # parent revision. | |
665 | # |
|
665 | # | |
666 | # However, it can of course also allow things that would have |
|
666 | # However, it can of course also allow things that would have | |
667 | # been rejected before, such as the above cat command if sub/ |
|
667 | # been rejected before, such as the above cat command if sub/ | |
668 | # is a subrepository now, but was a normal directory before. |
|
668 | # is a subrepository now, but was a normal directory before. | |
669 | # The old path auditor would have rejected by mistake since it |
|
669 | # The old path auditor would have rejected by mistake since it | |
670 | # panics when it sees sub/.hg/. |
|
670 | # panics when it sees sub/.hg/. | |
671 | # |
|
671 | # | |
672 | # All in all, checking against the working copy seems sensible |
|
672 | # All in all, checking against the working copy seems sensible | |
673 | # since we want to prevent access to nested repositories on |
|
673 | # since we want to prevent access to nested repositories on | |
674 | # the filesystem *now*. |
|
674 | # the filesystem *now*. | |
675 | ctx = self[None] |
|
675 | ctx = self[None] | |
676 | parts = util.splitpath(subpath) |
|
676 | parts = util.splitpath(subpath) | |
677 | while parts: |
|
677 | while parts: | |
678 | prefix = '/'.join(parts) |
|
678 | prefix = '/'.join(parts) | |
679 | if prefix in ctx.substate: |
|
679 | if prefix in ctx.substate: | |
680 | if prefix == normsubpath: |
|
680 | if prefix == normsubpath: | |
681 | return True |
|
681 | return True | |
682 | else: |
|
682 | else: | |
683 | sub = ctx.sub(prefix) |
|
683 | sub = ctx.sub(prefix) | |
684 | return sub.checknested(subpath[len(prefix) + 1:]) |
|
684 | return sub.checknested(subpath[len(prefix) + 1:]) | |
685 | else: |
|
685 | else: | |
686 | parts.pop() |
|
686 | parts.pop() | |
687 | return False |
|
687 | return False | |
688 |
|
688 | |||
689 | def peer(self): |
|
689 | def peer(self): | |
690 | return localpeer(self) # not cached to avoid reference cycle |
|
690 | return localpeer(self) # not cached to avoid reference cycle | |
691 |
|
691 | |||
692 | def unfiltered(self): |
|
692 | def unfiltered(self): | |
693 | """Return unfiltered version of the repository |
|
693 | """Return unfiltered version of the repository | |
694 |
|
694 | |||
695 | Intended to be overwritten by filtered repo.""" |
|
695 | Intended to be overwritten by filtered repo.""" | |
696 | return self |
|
696 | return self | |
697 |
|
697 | |||
698 | def filtered(self, name, visibilityexceptions=None): |
|
698 | def filtered(self, name, visibilityexceptions=None): | |
699 | """Return a filtered version of a repository""" |
|
699 | """Return a filtered version of a repository""" | |
700 | cls = repoview.newtype(self.unfiltered().__class__) |
|
700 | cls = repoview.newtype(self.unfiltered().__class__) | |
701 | return cls(self, name, visibilityexceptions) |
|
701 | return cls(self, name, visibilityexceptions) | |
702 |
|
702 | |||
703 | @repofilecache('bookmarks', 'bookmarks.current') |
|
703 | @repofilecache('bookmarks', 'bookmarks.current') | |
704 | def _bookmarks(self): |
|
704 | def _bookmarks(self): | |
705 | return bookmarks.bmstore(self) |
|
705 | return bookmarks.bmstore(self) | |
706 |
|
706 | |||
707 | @property |
|
707 | @property | |
708 | def _activebookmark(self): |
|
708 | def _activebookmark(self): | |
709 | return self._bookmarks.active |
|
709 | return self._bookmarks.active | |
710 |
|
710 | |||
711 | # _phasesets depend on changelog. what we need is to call |
|
711 | # _phasesets depend on changelog. what we need is to call | |
712 | # _phasecache.invalidate() if '00changelog.i' was changed, but it |
|
712 | # _phasecache.invalidate() if '00changelog.i' was changed, but it | |
713 | # can't be easily expressed in filecache mechanism. |
|
713 | # can't be easily expressed in filecache mechanism. | |
714 | @storecache('phaseroots', '00changelog.i') |
|
714 | @storecache('phaseroots', '00changelog.i') | |
715 | def _phasecache(self): |
|
715 | def _phasecache(self): | |
716 | return phases.phasecache(self, self._phasedefaults) |
|
716 | return phases.phasecache(self, self._phasedefaults) | |
717 |
|
717 | |||
718 | @storecache('obsstore') |
|
718 | @storecache('obsstore') | |
719 | def obsstore(self): |
|
719 | def obsstore(self): | |
720 | return obsolete.makestore(self.ui, self) |
|
720 | return obsolete.makestore(self.ui, self) | |
721 |
|
721 | |||
722 | @storecache('00changelog.i') |
|
722 | @storecache('00changelog.i') | |
723 | def changelog(self): |
|
723 | def changelog(self): | |
724 | return changelog.changelog(self.svfs, |
|
724 | return changelog.changelog(self.svfs, | |
725 | trypending=txnutil.mayhavepending(self.root)) |
|
725 | trypending=txnutil.mayhavepending(self.root)) | |
726 |
|
726 | |||
727 | def _constructmanifest(self): |
|
727 | def _constructmanifest(self): | |
728 | # This is a temporary function while we migrate from manifest to |
|
728 | # This is a temporary function while we migrate from manifest to | |
729 | # manifestlog. It allows bundlerepo and unionrepo to intercept the |
|
729 | # manifestlog. It allows bundlerepo and unionrepo to intercept the | |
730 | # manifest creation. |
|
730 | # manifest creation. | |
731 | return manifest.manifestrevlog(self.svfs) |
|
731 | return manifest.manifestrevlog(self.svfs) | |
732 |
|
732 | |||
733 | @storecache('00manifest.i') |
|
733 | @storecache('00manifest.i') | |
734 | def manifestlog(self): |
|
734 | def manifestlog(self): | |
735 | return manifest.manifestlog(self.svfs, self) |
|
735 | return manifest.manifestlog(self.svfs, self) | |
736 |
|
736 | |||
737 | @repofilecache('dirstate') |
|
737 | @repofilecache('dirstate') | |
738 | def dirstate(self): |
|
738 | def dirstate(self): | |
739 | sparsematchfn = lambda: sparse.matcher(self) |
|
739 | sparsematchfn = lambda: sparse.matcher(self) | |
740 |
|
740 | |||
741 | return dirstate.dirstate(self.vfs, self.ui, self.root, |
|
741 | return dirstate.dirstate(self.vfs, self.ui, self.root, | |
742 | self._dirstatevalidate, sparsematchfn) |
|
742 | self._dirstatevalidate, sparsematchfn) | |
743 |
|
743 | |||
744 | def _dirstatevalidate(self, node): |
|
744 | def _dirstatevalidate(self, node): | |
745 | try: |
|
745 | try: | |
746 | self.changelog.rev(node) |
|
746 | self.changelog.rev(node) | |
747 | return node |
|
747 | return node | |
748 | except error.LookupError: |
|
748 | except error.LookupError: | |
749 | if not self._dirstatevalidatewarned: |
|
749 | if not self._dirstatevalidatewarned: | |
750 | self._dirstatevalidatewarned = True |
|
750 | self._dirstatevalidatewarned = True | |
751 | self.ui.warn(_("warning: ignoring unknown" |
|
751 | self.ui.warn(_("warning: ignoring unknown" | |
752 | " working parent %s!\n") % short(node)) |
|
752 | " working parent %s!\n") % short(node)) | |
753 | return nullid |
|
753 | return nullid | |
754 |
|
754 | |||
755 | @repofilecache(narrowspec.FILENAME) |
|
755 | @repofilecache(narrowspec.FILENAME) | |
756 | def narrowpats(self): |
|
756 | def narrowpats(self): | |
757 | """matcher patterns for this repository's narrowspec |
|
757 | """matcher patterns for this repository's narrowspec | |
758 |
|
758 | |||
759 | A tuple of (includes, excludes). |
|
759 | A tuple of (includes, excludes). | |
760 | """ |
|
760 | """ | |
761 | source = self |
|
761 | source = self | |
762 | if self.shared(): |
|
762 | if self.shared(): | |
763 | from . import hg |
|
763 | from . import hg | |
764 | source = hg.sharedreposource(self) |
|
764 | source = hg.sharedreposource(self) | |
765 | return narrowspec.load(source) |
|
765 | return narrowspec.load(source) | |
766 |
|
766 | |||
767 | @repofilecache(narrowspec.FILENAME) |
|
767 | @repofilecache(narrowspec.FILENAME) | |
768 | def _narrowmatch(self): |
|
768 | def _narrowmatch(self): | |
769 | if changegroup.NARROW_REQUIREMENT not in self.requirements: |
|
769 | if changegroup.NARROW_REQUIREMENT not in self.requirements: | |
770 | return matchmod.always(self.root, '') |
|
770 | return matchmod.always(self.root, '') | |
771 | include, exclude = self.narrowpats |
|
771 | include, exclude = self.narrowpats | |
772 | return narrowspec.match(self.root, include=include, exclude=exclude) |
|
772 | return narrowspec.match(self.root, include=include, exclude=exclude) | |
773 |
|
773 | |||
774 | # TODO(martinvonz): make this property-like instead? |
|
774 | # TODO(martinvonz): make this property-like instead? | |
775 | def narrowmatch(self): |
|
775 | def narrowmatch(self): | |
776 | return self._narrowmatch |
|
776 | return self._narrowmatch | |
777 |
|
777 | |||
778 | def setnarrowpats(self, newincludes, newexcludes): |
|
778 | def setnarrowpats(self, newincludes, newexcludes): | |
779 | target = self |
|
779 | target = self | |
780 | if self.shared(): |
|
780 | if self.shared(): | |
781 | from . import hg |
|
781 | from . import hg | |
782 | target = hg.sharedreposource(self) |
|
782 | target = hg.sharedreposource(self) | |
783 | narrowspec.save(target, newincludes, newexcludes) |
|
783 | narrowspec.save(target, newincludes, newexcludes) | |
784 | self.invalidate(clearfilecache=True) |
|
784 | self.invalidate(clearfilecache=True) | |
785 |
|
785 | |||
786 | def __getitem__(self, changeid): |
|
786 | def __getitem__(self, changeid): | |
787 | if changeid is None: |
|
787 | if changeid is None: | |
788 | return context.workingctx(self) |
|
788 | return context.workingctx(self) | |
789 | if isinstance(changeid, context.basectx): |
|
789 | if isinstance(changeid, context.basectx): | |
790 | return changeid |
|
790 | return changeid | |
791 | if isinstance(changeid, slice): |
|
791 | if isinstance(changeid, slice): | |
792 | # wdirrev isn't contiguous so the slice shouldn't include it |
|
792 | # wdirrev isn't contiguous so the slice shouldn't include it | |
793 | return [context.changectx(self, i) |
|
793 | return [context.changectx(self, i) | |
794 | for i in xrange(*changeid.indices(len(self))) |
|
794 | for i in xrange(*changeid.indices(len(self))) | |
795 | if i not in self.changelog.filteredrevs] |
|
795 | if i not in self.changelog.filteredrevs] | |
796 | try: |
|
796 | try: | |
797 | return context.changectx(self, changeid) |
|
797 | return context.changectx(self, changeid) | |
798 | except error.WdirUnsupported: |
|
798 | except error.WdirUnsupported: | |
799 | return context.workingctx(self) |
|
799 | return context.workingctx(self) | |
800 |
|
800 | |||
801 | def __contains__(self, changeid): |
|
801 | def __contains__(self, changeid): | |
802 | """True if the given changeid exists |
|
802 | """True if the given changeid exists | |
803 |
|
803 | |||
804 | error.LookupError is raised if an ambiguous node specified. |
|
804 | error.LookupError is raised if an ambiguous node specified. | |
805 | """ |
|
805 | """ | |
806 | try: |
|
806 | try: | |
807 | self[changeid] |
|
807 | self[changeid] | |
808 | return True |
|
808 | return True | |
809 | except error.RepoLookupError: |
|
809 | except error.RepoLookupError: | |
810 | return False |
|
810 | return False | |
811 |
|
811 | |||
812 | def __nonzero__(self): |
|
812 | def __nonzero__(self): | |
813 | return True |
|
813 | return True | |
814 |
|
814 | |||
815 | __bool__ = __nonzero__ |
|
815 | __bool__ = __nonzero__ | |
816 |
|
816 | |||
817 | def __len__(self): |
|
817 | def __len__(self): | |
818 | # no need to pay the cost of repoview.changelog |
|
818 | # no need to pay the cost of repoview.changelog | |
819 | unfi = self.unfiltered() |
|
819 | unfi = self.unfiltered() | |
820 | return len(unfi.changelog) |
|
820 | return len(unfi.changelog) | |
821 |
|
821 | |||
822 | def __iter__(self): |
|
822 | def __iter__(self): | |
823 | return iter(self.changelog) |
|
823 | return iter(self.changelog) | |
824 |
|
824 | |||
825 | def revs(self, expr, *args): |
|
825 | def revs(self, expr, *args): | |
826 | '''Find revisions matching a revset. |
|
826 | '''Find revisions matching a revset. | |
827 |
|
827 | |||
828 | The revset is specified as a string ``expr`` that may contain |
|
828 | The revset is specified as a string ``expr`` that may contain | |
829 | %-formatting to escape certain types. See ``revsetlang.formatspec``. |
|
829 | %-formatting to escape certain types. See ``revsetlang.formatspec``. | |
830 |
|
830 | |||
831 | Revset aliases from the configuration are not expanded. To expand |
|
831 | Revset aliases from the configuration are not expanded. To expand | |
832 | user aliases, consider calling ``scmutil.revrange()`` or |
|
832 | user aliases, consider calling ``scmutil.revrange()`` or | |
833 | ``repo.anyrevs([expr], user=True)``. |
|
833 | ``repo.anyrevs([expr], user=True)``. | |
834 |
|
834 | |||
835 | Returns a revset.abstractsmartset, which is a list-like interface |
|
835 | Returns a revset.abstractsmartset, which is a list-like interface | |
836 | that contains integer revisions. |
|
836 | that contains integer revisions. | |
837 | ''' |
|
837 | ''' | |
838 | expr = revsetlang.formatspec(expr, *args) |
|
838 | expr = revsetlang.formatspec(expr, *args) | |
839 | m = revset.match(None, expr) |
|
839 | m = revset.match(None, expr) | |
840 | return m(self) |
|
840 | return m(self) | |
841 |
|
841 | |||
842 | def set(self, expr, *args): |
|
842 | def set(self, expr, *args): | |
843 | '''Find revisions matching a revset and emit changectx instances. |
|
843 | '''Find revisions matching a revset and emit changectx instances. | |
844 |
|
844 | |||
845 | This is a convenience wrapper around ``revs()`` that iterates the |
|
845 | This is a convenience wrapper around ``revs()`` that iterates the | |
846 | result and is a generator of changectx instances. |
|
846 | result and is a generator of changectx instances. | |
847 |
|
847 | |||
848 | Revset aliases from the configuration are not expanded. To expand |
|
848 | Revset aliases from the configuration are not expanded. To expand | |
849 | user aliases, consider calling ``scmutil.revrange()``. |
|
849 | user aliases, consider calling ``scmutil.revrange()``. | |
850 | ''' |
|
850 | ''' | |
851 | for r in self.revs(expr, *args): |
|
851 | for r in self.revs(expr, *args): | |
852 | yield self[r] |
|
852 | yield self[r] | |
853 |
|
853 | |||
854 | def anyrevs(self, specs, user=False, localalias=None): |
|
854 | def anyrevs(self, specs, user=False, localalias=None): | |
855 | '''Find revisions matching one of the given revsets. |
|
855 | '''Find revisions matching one of the given revsets. | |
856 |
|
856 | |||
857 | Revset aliases from the configuration are not expanded by default. To |
|
857 | Revset aliases from the configuration are not expanded by default. To | |
858 | expand user aliases, specify ``user=True``. To provide some local |
|
858 | expand user aliases, specify ``user=True``. To provide some local | |
859 | definitions overriding user aliases, set ``localalias`` to |
|
859 | definitions overriding user aliases, set ``localalias`` to | |
860 | ``{name: definitionstring}``. |
|
860 | ``{name: definitionstring}``. | |
861 | ''' |
|
861 | ''' | |
862 | if user: |
|
862 | if user: | |
863 | m = revset.matchany(self.ui, specs, repo=self, |
|
863 | m = revset.matchany(self.ui, specs, repo=self, | |
864 | localalias=localalias) |
|
864 | localalias=localalias) | |
865 | else: |
|
865 | else: | |
866 | m = revset.matchany(None, specs, localalias=localalias) |
|
866 | m = revset.matchany(None, specs, localalias=localalias) | |
867 | return m(self) |
|
867 | return m(self) | |
868 |
|
868 | |||
869 | def url(self): |
|
869 | def url(self): | |
870 | return 'file:' + self.root |
|
870 | return 'file:' + self.root | |
871 |
|
871 | |||
872 | def hook(self, name, throw=False, **args): |
|
872 | def hook(self, name, throw=False, **args): | |
873 | """Call a hook, passing this repo instance. |
|
873 | """Call a hook, passing this repo instance. | |
874 |
|
874 | |||
875 | This a convenience method to aid invoking hooks. Extensions likely |
|
875 | This a convenience method to aid invoking hooks. Extensions likely | |
876 | won't call this unless they have registered a custom hook or are |
|
876 | won't call this unless they have registered a custom hook or are | |
877 | replacing code that is expected to call a hook. |
|
877 | replacing code that is expected to call a hook. | |
878 | """ |
|
878 | """ | |
879 | return hook.hook(self.ui, self, name, throw, **args) |
|
879 | return hook.hook(self.ui, self, name, throw, **args) | |
880 |
|
880 | |||
881 | @filteredpropertycache |
|
881 | @filteredpropertycache | |
882 | def _tagscache(self): |
|
882 | def _tagscache(self): | |
883 | '''Returns a tagscache object that contains various tags related |
|
883 | '''Returns a tagscache object that contains various tags related | |
884 | caches.''' |
|
884 | caches.''' | |
885 |
|
885 | |||
886 | # This simplifies its cache management by having one decorated |
|
886 | # This simplifies its cache management by having one decorated | |
887 | # function (this one) and the rest simply fetch things from it. |
|
887 | # function (this one) and the rest simply fetch things from it. | |
888 | class tagscache(object): |
|
888 | class tagscache(object): | |
889 | def __init__(self): |
|
889 | def __init__(self): | |
890 | # These two define the set of tags for this repository. tags |
|
890 | # These two define the set of tags for this repository. tags | |
891 | # maps tag name to node; tagtypes maps tag name to 'global' or |
|
891 | # maps tag name to node; tagtypes maps tag name to 'global' or | |
892 | # 'local'. (Global tags are defined by .hgtags across all |
|
892 | # 'local'. (Global tags are defined by .hgtags across all | |
893 | # heads, and local tags are defined in .hg/localtags.) |
|
893 | # heads, and local tags are defined in .hg/localtags.) | |
894 | # They constitute the in-memory cache of tags. |
|
894 | # They constitute the in-memory cache of tags. | |
895 | self.tags = self.tagtypes = None |
|
895 | self.tags = self.tagtypes = None | |
896 |
|
896 | |||
897 | self.nodetagscache = self.tagslist = None |
|
897 | self.nodetagscache = self.tagslist = None | |
898 |
|
898 | |||
899 | cache = tagscache() |
|
899 | cache = tagscache() | |
900 | cache.tags, cache.tagtypes = self._findtags() |
|
900 | cache.tags, cache.tagtypes = self._findtags() | |
901 |
|
901 | |||
902 | return cache |
|
902 | return cache | |
903 |
|
903 | |||
904 | def tags(self): |
|
904 | def tags(self): | |
905 | '''return a mapping of tag to node''' |
|
905 | '''return a mapping of tag to node''' | |
906 | t = {} |
|
906 | t = {} | |
907 | if self.changelog.filteredrevs: |
|
907 | if self.changelog.filteredrevs: | |
908 | tags, tt = self._findtags() |
|
908 | tags, tt = self._findtags() | |
909 | else: |
|
909 | else: | |
910 | tags = self._tagscache.tags |
|
910 | tags = self._tagscache.tags | |
911 | for k, v in tags.iteritems(): |
|
911 | for k, v in tags.iteritems(): | |
912 | try: |
|
912 | try: | |
913 | # ignore tags to unknown nodes |
|
913 | # ignore tags to unknown nodes | |
914 | self.changelog.rev(v) |
|
914 | self.changelog.rev(v) | |
915 | t[k] = v |
|
915 | t[k] = v | |
916 | except (error.LookupError, ValueError): |
|
916 | except (error.LookupError, ValueError): | |
917 | pass |
|
917 | pass | |
918 | return t |
|
918 | return t | |
919 |
|
919 | |||
920 | def _findtags(self): |
|
920 | def _findtags(self): | |
921 | '''Do the hard work of finding tags. Return a pair of dicts |
|
921 | '''Do the hard work of finding tags. Return a pair of dicts | |
922 | (tags, tagtypes) where tags maps tag name to node, and tagtypes |
|
922 | (tags, tagtypes) where tags maps tag name to node, and tagtypes | |
923 | maps tag name to a string like \'global\' or \'local\'. |
|
923 | maps tag name to a string like \'global\' or \'local\'. | |
924 | Subclasses or extensions are free to add their own tags, but |
|
924 | Subclasses or extensions are free to add their own tags, but | |
925 | should be aware that the returned dicts will be retained for the |
|
925 | should be aware that the returned dicts will be retained for the | |
926 | duration of the localrepo object.''' |
|
926 | duration of the localrepo object.''' | |
927 |
|
927 | |||
928 | # XXX what tagtype should subclasses/extensions use? Currently |
|
928 | # XXX what tagtype should subclasses/extensions use? Currently | |
929 | # mq and bookmarks add tags, but do not set the tagtype at all. |
|
929 | # mq and bookmarks add tags, but do not set the tagtype at all. | |
930 | # Should each extension invent its own tag type? Should there |
|
930 | # Should each extension invent its own tag type? Should there | |
931 | # be one tagtype for all such "virtual" tags? Or is the status |
|
931 | # be one tagtype for all such "virtual" tags? Or is the status | |
932 | # quo fine? |
|
932 | # quo fine? | |
933 |
|
933 | |||
934 |
|
934 | |||
935 | # map tag name to (node, hist) |
|
935 | # map tag name to (node, hist) | |
936 | alltags = tagsmod.findglobaltags(self.ui, self) |
|
936 | alltags = tagsmod.findglobaltags(self.ui, self) | |
937 | # map tag name to tag type |
|
937 | # map tag name to tag type | |
938 | tagtypes = dict((tag, 'global') for tag in alltags) |
|
938 | tagtypes = dict((tag, 'global') for tag in alltags) | |
939 |
|
939 | |||
940 | tagsmod.readlocaltags(self.ui, self, alltags, tagtypes) |
|
940 | tagsmod.readlocaltags(self.ui, self, alltags, tagtypes) | |
941 |
|
941 | |||
942 | # Build the return dicts. Have to re-encode tag names because |
|
942 | # Build the return dicts. Have to re-encode tag names because | |
943 | # the tags module always uses UTF-8 (in order not to lose info |
|
943 | # the tags module always uses UTF-8 (in order not to lose info | |
944 | # writing to the cache), but the rest of Mercurial wants them in |
|
944 | # writing to the cache), but the rest of Mercurial wants them in | |
945 | # local encoding. |
|
945 | # local encoding. | |
946 | tags = {} |
|
946 | tags = {} | |
947 | for (name, (node, hist)) in alltags.iteritems(): |
|
947 | for (name, (node, hist)) in alltags.iteritems(): | |
948 | if node != nullid: |
|
948 | if node != nullid: | |
949 | tags[encoding.tolocal(name)] = node |
|
949 | tags[encoding.tolocal(name)] = node | |
950 | tags['tip'] = self.changelog.tip() |
|
950 | tags['tip'] = self.changelog.tip() | |
951 | tagtypes = dict([(encoding.tolocal(name), value) |
|
951 | tagtypes = dict([(encoding.tolocal(name), value) | |
952 | for (name, value) in tagtypes.iteritems()]) |
|
952 | for (name, value) in tagtypes.iteritems()]) | |
953 | return (tags, tagtypes) |
|
953 | return (tags, tagtypes) | |
954 |
|
954 | |||
955 | def tagtype(self, tagname): |
|
955 | def tagtype(self, tagname): | |
956 | ''' |
|
956 | ''' | |
957 | return the type of the given tag. result can be: |
|
957 | return the type of the given tag. result can be: | |
958 |
|
958 | |||
959 | 'local' : a local tag |
|
959 | 'local' : a local tag | |
960 | 'global' : a global tag |
|
960 | 'global' : a global tag | |
961 | None : tag does not exist |
|
961 | None : tag does not exist | |
962 | ''' |
|
962 | ''' | |
963 |
|
963 | |||
964 | return self._tagscache.tagtypes.get(tagname) |
|
964 | return self._tagscache.tagtypes.get(tagname) | |
965 |
|
965 | |||
966 | def tagslist(self): |
|
966 | def tagslist(self): | |
967 | '''return a list of tags ordered by revision''' |
|
967 | '''return a list of tags ordered by revision''' | |
968 | if not self._tagscache.tagslist: |
|
968 | if not self._tagscache.tagslist: | |
969 | l = [] |
|
969 | l = [] | |
970 | for t, n in self.tags().iteritems(): |
|
970 | for t, n in self.tags().iteritems(): | |
971 | l.append((self.changelog.rev(n), t, n)) |
|
971 | l.append((self.changelog.rev(n), t, n)) | |
972 | self._tagscache.tagslist = [(t, n) for r, t, n in sorted(l)] |
|
972 | self._tagscache.tagslist = [(t, n) for r, t, n in sorted(l)] | |
973 |
|
973 | |||
974 | return self._tagscache.tagslist |
|
974 | return self._tagscache.tagslist | |
975 |
|
975 | |||
976 | def nodetags(self, node): |
|
976 | def nodetags(self, node): | |
977 | '''return the tags associated with a node''' |
|
977 | '''return the tags associated with a node''' | |
978 | if not self._tagscache.nodetagscache: |
|
978 | if not self._tagscache.nodetagscache: | |
979 | nodetagscache = {} |
|
979 | nodetagscache = {} | |
980 | for t, n in self._tagscache.tags.iteritems(): |
|
980 | for t, n in self._tagscache.tags.iteritems(): | |
981 | nodetagscache.setdefault(n, []).append(t) |
|
981 | nodetagscache.setdefault(n, []).append(t) | |
982 | for tags in nodetagscache.itervalues(): |
|
982 | for tags in nodetagscache.itervalues(): | |
983 | tags.sort() |
|
983 | tags.sort() | |
984 | self._tagscache.nodetagscache = nodetagscache |
|
984 | self._tagscache.nodetagscache = nodetagscache | |
985 | return self._tagscache.nodetagscache.get(node, []) |
|
985 | return self._tagscache.nodetagscache.get(node, []) | |
986 |
|
986 | |||
987 | def nodebookmarks(self, node): |
|
987 | def nodebookmarks(self, node): | |
988 | """return the list of bookmarks pointing to the specified node""" |
|
988 | """return the list of bookmarks pointing to the specified node""" | |
989 | marks = [] |
|
989 | marks = [] | |
990 | for bookmark, n in self._bookmarks.iteritems(): |
|
990 | for bookmark, n in self._bookmarks.iteritems(): | |
991 | if n == node: |
|
991 | if n == node: | |
992 | marks.append(bookmark) |
|
992 | marks.append(bookmark) | |
993 | return sorted(marks) |
|
993 | return sorted(marks) | |
994 |
|
994 | |||
995 | def branchmap(self): |
|
995 | def branchmap(self): | |
996 | '''returns a dictionary {branch: [branchheads]} with branchheads |
|
996 | '''returns a dictionary {branch: [branchheads]} with branchheads | |
997 | ordered by increasing revision number''' |
|
997 | ordered by increasing revision number''' | |
998 | branchmap.updatecache(self) |
|
998 | branchmap.updatecache(self) | |
999 | return self._branchcaches[self.filtername] |
|
999 | return self._branchcaches[self.filtername] | |
1000 |
|
1000 | |||
1001 | @unfilteredmethod |
|
1001 | @unfilteredmethod | |
1002 | def revbranchcache(self): |
|
1002 | def revbranchcache(self): | |
1003 | if not self._revbranchcache: |
|
1003 | if not self._revbranchcache: | |
1004 | self._revbranchcache = branchmap.revbranchcache(self.unfiltered()) |
|
1004 | self._revbranchcache = branchmap.revbranchcache(self.unfiltered()) | |
1005 | return self._revbranchcache |
|
1005 | return self._revbranchcache | |
1006 |
|
1006 | |||
1007 | def branchtip(self, branch, ignoremissing=False): |
|
1007 | def branchtip(self, branch, ignoremissing=False): | |
1008 | '''return the tip node for a given branch |
|
1008 | '''return the tip node for a given branch | |
1009 |
|
1009 | |||
1010 | If ignoremissing is True, then this method will not raise an error. |
|
1010 | If ignoremissing is True, then this method will not raise an error. | |
1011 | This is helpful for callers that only expect None for a missing branch |
|
1011 | This is helpful for callers that only expect None for a missing branch | |
1012 | (e.g. namespace). |
|
1012 | (e.g. namespace). | |
1013 |
|
1013 | |||
1014 | ''' |
|
1014 | ''' | |
1015 | try: |
|
1015 | try: | |
1016 | return self.branchmap().branchtip(branch) |
|
1016 | return self.branchmap().branchtip(branch) | |
1017 | except KeyError: |
|
1017 | except KeyError: | |
1018 | if not ignoremissing: |
|
1018 | if not ignoremissing: | |
1019 | raise error.RepoLookupError(_("unknown branch '%s'") % branch) |
|
1019 | raise error.RepoLookupError(_("unknown branch '%s'") % branch) | |
1020 | else: |
|
1020 | else: | |
1021 | pass |
|
1021 | pass | |
1022 |
|
1022 | |||
1023 | def lookup(self, key): |
|
1023 | def lookup(self, key): | |
1024 | return scmutil.revsymbol(self, key).node() |
|
1024 | return scmutil.revsymbol(self, key).node() | |
1025 |
|
1025 | |||
1026 | def lookupbranch(self, key, remote=None): |
|
1026 | def lookupbranch(self, key, remote=None): | |
1027 | repo = remote or self |
|
1027 | repo = remote or self | |
1028 | if key in repo.branchmap(): |
|
1028 | if key in repo.branchmap(): | |
1029 | return key |
|
1029 | return key | |
1030 |
|
1030 | |||
1031 | repo = (remote and remote.local()) and remote or self |
|
1031 | repo = (remote and remote.local()) and remote or self | |
1032 | return repo[key].branch() |
|
1032 | return repo[key].branch() | |
1033 |
|
1033 | |||
1034 | def known(self, nodes): |
|
1034 | def known(self, nodes): | |
1035 | cl = self.changelog |
|
1035 | cl = self.changelog | |
1036 | nm = cl.nodemap |
|
1036 | nm = cl.nodemap | |
1037 | filtered = cl.filteredrevs |
|
1037 | filtered = cl.filteredrevs | |
1038 | result = [] |
|
1038 | result = [] | |
1039 | for n in nodes: |
|
1039 | for n in nodes: | |
1040 | r = nm.get(n) |
|
1040 | r = nm.get(n) | |
1041 | resp = not (r is None or r in filtered) |
|
1041 | resp = not (r is None or r in filtered) | |
1042 | result.append(resp) |
|
1042 | result.append(resp) | |
1043 | return result |
|
1043 | return result | |
1044 |
|
1044 | |||
1045 | def local(self): |
|
1045 | def local(self): | |
1046 | return self |
|
1046 | return self | |
1047 |
|
1047 | |||
1048 | def publishing(self): |
|
1048 | def publishing(self): | |
1049 | # it's safe (and desirable) to trust the publish flag unconditionally |
|
1049 | # it's safe (and desirable) to trust the publish flag unconditionally | |
1050 | # so that we don't finalize changes shared between users via ssh or nfs |
|
1050 | # so that we don't finalize changes shared between users via ssh or nfs | |
1051 | return self.ui.configbool('phases', 'publish', untrusted=True) |
|
1051 | return self.ui.configbool('phases', 'publish', untrusted=True) | |
1052 |
|
1052 | |||
1053 | def cancopy(self): |
|
1053 | def cancopy(self): | |
1054 | # so statichttprepo's override of local() works |
|
1054 | # so statichttprepo's override of local() works | |
1055 | if not self.local(): |
|
1055 | if not self.local(): | |
1056 | return False |
|
1056 | return False | |
1057 | if not self.publishing(): |
|
1057 | if not self.publishing(): | |
1058 | return True |
|
1058 | return True | |
1059 | # if publishing we can't copy if there is filtered content |
|
1059 | # if publishing we can't copy if there is filtered content | |
1060 | return not self.filtered('visible').changelog.filteredrevs |
|
1060 | return not self.filtered('visible').changelog.filteredrevs | |
1061 |
|
1061 | |||
1062 | def shared(self): |
|
1062 | def shared(self): | |
1063 | '''the type of shared repository (None if not shared)''' |
|
1063 | '''the type of shared repository (None if not shared)''' | |
1064 | if self.sharedpath != self.path: |
|
1064 | if self.sharedpath != self.path: | |
1065 | return 'store' |
|
1065 | return 'store' | |
1066 | return None |
|
1066 | return None | |
1067 |
|
1067 | |||
1068 | def wjoin(self, f, *insidef): |
|
1068 | def wjoin(self, f, *insidef): | |
1069 | return self.vfs.reljoin(self.root, f, *insidef) |
|
1069 | return self.vfs.reljoin(self.root, f, *insidef) | |
1070 |
|
1070 | |||
1071 | def file(self, f): |
|
1071 | def file(self, f): | |
1072 | if f[0] == '/': |
|
1072 | if f[0] == '/': | |
1073 | f = f[1:] |
|
1073 | f = f[1:] | |
1074 | return filelog.filelog(self.svfs, f) |
|
1074 | return filelog.filelog(self.svfs, f) | |
1075 |
|
1075 | |||
1076 | def changectx(self, changeid): |
|
|||
1077 | return self[changeid] |
|
|||
1078 |
|
||||
1079 | def setparents(self, p1, p2=nullid): |
|
1076 | def setparents(self, p1, p2=nullid): | |
1080 | with self.dirstate.parentchange(): |
|
1077 | with self.dirstate.parentchange(): | |
1081 | copies = self.dirstate.setparents(p1, p2) |
|
1078 | copies = self.dirstate.setparents(p1, p2) | |
1082 | pctx = self[p1] |
|
1079 | pctx = self[p1] | |
1083 | if copies: |
|
1080 | if copies: | |
1084 | # Adjust copy records, the dirstate cannot do it, it |
|
1081 | # Adjust copy records, the dirstate cannot do it, it | |
1085 | # requires access to parents manifests. Preserve them |
|
1082 | # requires access to parents manifests. Preserve them | |
1086 | # only for entries added to first parent. |
|
1083 | # only for entries added to first parent. | |
1087 | for f in copies: |
|
1084 | for f in copies: | |
1088 | if f not in pctx and copies[f] in pctx: |
|
1085 | if f not in pctx and copies[f] in pctx: | |
1089 | self.dirstate.copy(copies[f], f) |
|
1086 | self.dirstate.copy(copies[f], f) | |
1090 | if p2 == nullid: |
|
1087 | if p2 == nullid: | |
1091 | for f, s in sorted(self.dirstate.copies().items()): |
|
1088 | for f, s in sorted(self.dirstate.copies().items()): | |
1092 | if f not in pctx and s not in pctx: |
|
1089 | if f not in pctx and s not in pctx: | |
1093 | self.dirstate.copy(None, f) |
|
1090 | self.dirstate.copy(None, f) | |
1094 |
|
1091 | |||
1095 | def filectx(self, path, changeid=None, fileid=None, changectx=None): |
|
1092 | def filectx(self, path, changeid=None, fileid=None, changectx=None): | |
1096 | """changeid can be a changeset revision, node, or tag. |
|
1093 | """changeid can be a changeset revision, node, or tag. | |
1097 | fileid can be a file revision or node.""" |
|
1094 | fileid can be a file revision or node.""" | |
1098 | return context.filectx(self, path, changeid, fileid, |
|
1095 | return context.filectx(self, path, changeid, fileid, | |
1099 | changectx=changectx) |
|
1096 | changectx=changectx) | |
1100 |
|
1097 | |||
1101 | def getcwd(self): |
|
1098 | def getcwd(self): | |
1102 | return self.dirstate.getcwd() |
|
1099 | return self.dirstate.getcwd() | |
1103 |
|
1100 | |||
1104 | def pathto(self, f, cwd=None): |
|
1101 | def pathto(self, f, cwd=None): | |
1105 | return self.dirstate.pathto(f, cwd) |
|
1102 | return self.dirstate.pathto(f, cwd) | |
1106 |
|
1103 | |||
1107 | def _loadfilter(self, filter): |
|
1104 | def _loadfilter(self, filter): | |
1108 | if filter not in self._filterpats: |
|
1105 | if filter not in self._filterpats: | |
1109 | l = [] |
|
1106 | l = [] | |
1110 | for pat, cmd in self.ui.configitems(filter): |
|
1107 | for pat, cmd in self.ui.configitems(filter): | |
1111 | if cmd == '!': |
|
1108 | if cmd == '!': | |
1112 | continue |
|
1109 | continue | |
1113 | mf = matchmod.match(self.root, '', [pat]) |
|
1110 | mf = matchmod.match(self.root, '', [pat]) | |
1114 | fn = None |
|
1111 | fn = None | |
1115 | params = cmd |
|
1112 | params = cmd | |
1116 | for name, filterfn in self._datafilters.iteritems(): |
|
1113 | for name, filterfn in self._datafilters.iteritems(): | |
1117 | if cmd.startswith(name): |
|
1114 | if cmd.startswith(name): | |
1118 | fn = filterfn |
|
1115 | fn = filterfn | |
1119 | params = cmd[len(name):].lstrip() |
|
1116 | params = cmd[len(name):].lstrip() | |
1120 | break |
|
1117 | break | |
1121 | if not fn: |
|
1118 | if not fn: | |
1122 | fn = lambda s, c, **kwargs: procutil.filter(s, c) |
|
1119 | fn = lambda s, c, **kwargs: procutil.filter(s, c) | |
1123 | # Wrap old filters not supporting keyword arguments |
|
1120 | # Wrap old filters not supporting keyword arguments | |
1124 | if not pycompat.getargspec(fn)[2]: |
|
1121 | if not pycompat.getargspec(fn)[2]: | |
1125 | oldfn = fn |
|
1122 | oldfn = fn | |
1126 | fn = lambda s, c, **kwargs: oldfn(s, c) |
|
1123 | fn = lambda s, c, **kwargs: oldfn(s, c) | |
1127 | l.append((mf, fn, params)) |
|
1124 | l.append((mf, fn, params)) | |
1128 | self._filterpats[filter] = l |
|
1125 | self._filterpats[filter] = l | |
1129 | return self._filterpats[filter] |
|
1126 | return self._filterpats[filter] | |
1130 |
|
1127 | |||
1131 | def _filter(self, filterpats, filename, data): |
|
1128 | def _filter(self, filterpats, filename, data): | |
1132 | for mf, fn, cmd in filterpats: |
|
1129 | for mf, fn, cmd in filterpats: | |
1133 | if mf(filename): |
|
1130 | if mf(filename): | |
1134 | self.ui.debug("filtering %s through %s\n" % (filename, cmd)) |
|
1131 | self.ui.debug("filtering %s through %s\n" % (filename, cmd)) | |
1135 | data = fn(data, cmd, ui=self.ui, repo=self, filename=filename) |
|
1132 | data = fn(data, cmd, ui=self.ui, repo=self, filename=filename) | |
1136 | break |
|
1133 | break | |
1137 |
|
1134 | |||
1138 | return data |
|
1135 | return data | |
1139 |
|
1136 | |||
1140 | @unfilteredpropertycache |
|
1137 | @unfilteredpropertycache | |
1141 | def _encodefilterpats(self): |
|
1138 | def _encodefilterpats(self): | |
1142 | return self._loadfilter('encode') |
|
1139 | return self._loadfilter('encode') | |
1143 |
|
1140 | |||
1144 | @unfilteredpropertycache |
|
1141 | @unfilteredpropertycache | |
1145 | def _decodefilterpats(self): |
|
1142 | def _decodefilterpats(self): | |
1146 | return self._loadfilter('decode') |
|
1143 | return self._loadfilter('decode') | |
1147 |
|
1144 | |||
1148 | def adddatafilter(self, name, filter): |
|
1145 | def adddatafilter(self, name, filter): | |
1149 | self._datafilters[name] = filter |
|
1146 | self._datafilters[name] = filter | |
1150 |
|
1147 | |||
1151 | def wread(self, filename): |
|
1148 | def wread(self, filename): | |
1152 | if self.wvfs.islink(filename): |
|
1149 | if self.wvfs.islink(filename): | |
1153 | data = self.wvfs.readlink(filename) |
|
1150 | data = self.wvfs.readlink(filename) | |
1154 | else: |
|
1151 | else: | |
1155 | data = self.wvfs.read(filename) |
|
1152 | data = self.wvfs.read(filename) | |
1156 | return self._filter(self._encodefilterpats, filename, data) |
|
1153 | return self._filter(self._encodefilterpats, filename, data) | |
1157 |
|
1154 | |||
1158 | def wwrite(self, filename, data, flags, backgroundclose=False, **kwargs): |
|
1155 | def wwrite(self, filename, data, flags, backgroundclose=False, **kwargs): | |
1159 | """write ``data`` into ``filename`` in the working directory |
|
1156 | """write ``data`` into ``filename`` in the working directory | |
1160 |
|
1157 | |||
1161 | This returns length of written (maybe decoded) data. |
|
1158 | This returns length of written (maybe decoded) data. | |
1162 | """ |
|
1159 | """ | |
1163 | data = self._filter(self._decodefilterpats, filename, data) |
|
1160 | data = self._filter(self._decodefilterpats, filename, data) | |
1164 | if 'l' in flags: |
|
1161 | if 'l' in flags: | |
1165 | self.wvfs.symlink(data, filename) |
|
1162 | self.wvfs.symlink(data, filename) | |
1166 | else: |
|
1163 | else: | |
1167 | self.wvfs.write(filename, data, backgroundclose=backgroundclose, |
|
1164 | self.wvfs.write(filename, data, backgroundclose=backgroundclose, | |
1168 | **kwargs) |
|
1165 | **kwargs) | |
1169 | if 'x' in flags: |
|
1166 | if 'x' in flags: | |
1170 | self.wvfs.setflags(filename, False, True) |
|
1167 | self.wvfs.setflags(filename, False, True) | |
1171 | else: |
|
1168 | else: | |
1172 | self.wvfs.setflags(filename, False, False) |
|
1169 | self.wvfs.setflags(filename, False, False) | |
1173 | return len(data) |
|
1170 | return len(data) | |
1174 |
|
1171 | |||
1175 | def wwritedata(self, filename, data): |
|
1172 | def wwritedata(self, filename, data): | |
1176 | return self._filter(self._decodefilterpats, filename, data) |
|
1173 | return self._filter(self._decodefilterpats, filename, data) | |
1177 |
|
1174 | |||
1178 | def currenttransaction(self): |
|
1175 | def currenttransaction(self): | |
1179 | """return the current transaction or None if non exists""" |
|
1176 | """return the current transaction or None if non exists""" | |
1180 | if self._transref: |
|
1177 | if self._transref: | |
1181 | tr = self._transref() |
|
1178 | tr = self._transref() | |
1182 | else: |
|
1179 | else: | |
1183 | tr = None |
|
1180 | tr = None | |
1184 |
|
1181 | |||
1185 | if tr and tr.running(): |
|
1182 | if tr and tr.running(): | |
1186 | return tr |
|
1183 | return tr | |
1187 | return None |
|
1184 | return None | |
1188 |
|
1185 | |||
1189 | def transaction(self, desc, report=None): |
|
1186 | def transaction(self, desc, report=None): | |
1190 | if (self.ui.configbool('devel', 'all-warnings') |
|
1187 | if (self.ui.configbool('devel', 'all-warnings') | |
1191 | or self.ui.configbool('devel', 'check-locks')): |
|
1188 | or self.ui.configbool('devel', 'check-locks')): | |
1192 | if self._currentlock(self._lockref) is None: |
|
1189 | if self._currentlock(self._lockref) is None: | |
1193 | raise error.ProgrammingError('transaction requires locking') |
|
1190 | raise error.ProgrammingError('transaction requires locking') | |
1194 | tr = self.currenttransaction() |
|
1191 | tr = self.currenttransaction() | |
1195 | if tr is not None: |
|
1192 | if tr is not None: | |
1196 | return tr.nest(name=desc) |
|
1193 | return tr.nest(name=desc) | |
1197 |
|
1194 | |||
1198 | # abort here if the journal already exists |
|
1195 | # abort here if the journal already exists | |
1199 | if self.svfs.exists("journal"): |
|
1196 | if self.svfs.exists("journal"): | |
1200 | raise error.RepoError( |
|
1197 | raise error.RepoError( | |
1201 | _("abandoned transaction found"), |
|
1198 | _("abandoned transaction found"), | |
1202 | hint=_("run 'hg recover' to clean up transaction")) |
|
1199 | hint=_("run 'hg recover' to clean up transaction")) | |
1203 |
|
1200 | |||
1204 | idbase = "%.40f#%f" % (random.random(), time.time()) |
|
1201 | idbase = "%.40f#%f" % (random.random(), time.time()) | |
1205 | ha = hex(hashlib.sha1(idbase).digest()) |
|
1202 | ha = hex(hashlib.sha1(idbase).digest()) | |
1206 | txnid = 'TXN:' + ha |
|
1203 | txnid = 'TXN:' + ha | |
1207 | self.hook('pretxnopen', throw=True, txnname=desc, txnid=txnid) |
|
1204 | self.hook('pretxnopen', throw=True, txnname=desc, txnid=txnid) | |
1208 |
|
1205 | |||
1209 | self._writejournal(desc) |
|
1206 | self._writejournal(desc) | |
1210 | renames = [(vfs, x, undoname(x)) for vfs, x in self._journalfiles()] |
|
1207 | renames = [(vfs, x, undoname(x)) for vfs, x in self._journalfiles()] | |
1211 | if report: |
|
1208 | if report: | |
1212 | rp = report |
|
1209 | rp = report | |
1213 | else: |
|
1210 | else: | |
1214 | rp = self.ui.warn |
|
1211 | rp = self.ui.warn | |
1215 | vfsmap = {'plain': self.vfs} # root of .hg/ |
|
1212 | vfsmap = {'plain': self.vfs} # root of .hg/ | |
1216 | # we must avoid cyclic reference between repo and transaction. |
|
1213 | # we must avoid cyclic reference between repo and transaction. | |
1217 | reporef = weakref.ref(self) |
|
1214 | reporef = weakref.ref(self) | |
1218 | # Code to track tag movement |
|
1215 | # Code to track tag movement | |
1219 | # |
|
1216 | # | |
1220 | # Since tags are all handled as file content, it is actually quite hard |
|
1217 | # Since tags are all handled as file content, it is actually quite hard | |
1221 | # to track these movement from a code perspective. So we fallback to a |
|
1218 | # to track these movement from a code perspective. So we fallback to a | |
1222 | # tracking at the repository level. One could envision to track changes |
|
1219 | # tracking at the repository level. One could envision to track changes | |
1223 | # to the '.hgtags' file through changegroup apply but that fails to |
|
1220 | # to the '.hgtags' file through changegroup apply but that fails to | |
1224 | # cope with case where transaction expose new heads without changegroup |
|
1221 | # cope with case where transaction expose new heads without changegroup | |
1225 | # being involved (eg: phase movement). |
|
1222 | # being involved (eg: phase movement). | |
1226 | # |
|
1223 | # | |
1227 | # For now, We gate the feature behind a flag since this likely comes |
|
1224 | # For now, We gate the feature behind a flag since this likely comes | |
1228 | # with performance impacts. The current code run more often than needed |
|
1225 | # with performance impacts. The current code run more often than needed | |
1229 | # and do not use caches as much as it could. The current focus is on |
|
1226 | # and do not use caches as much as it could. The current focus is on | |
1230 | # the behavior of the feature so we disable it by default. The flag |
|
1227 | # the behavior of the feature so we disable it by default. The flag | |
1231 | # will be removed when we are happy with the performance impact. |
|
1228 | # will be removed when we are happy with the performance impact. | |
1232 | # |
|
1229 | # | |
1233 | # Once this feature is no longer experimental move the following |
|
1230 | # Once this feature is no longer experimental move the following | |
1234 | # documentation to the appropriate help section: |
|
1231 | # documentation to the appropriate help section: | |
1235 | # |
|
1232 | # | |
1236 | # The ``HG_TAG_MOVED`` variable will be set if the transaction touched |
|
1233 | # The ``HG_TAG_MOVED`` variable will be set if the transaction touched | |
1237 | # tags (new or changed or deleted tags). In addition the details of |
|
1234 | # tags (new or changed or deleted tags). In addition the details of | |
1238 | # these changes are made available in a file at: |
|
1235 | # these changes are made available in a file at: | |
1239 | # ``REPOROOT/.hg/changes/tags.changes``. |
|
1236 | # ``REPOROOT/.hg/changes/tags.changes``. | |
1240 | # Make sure you check for HG_TAG_MOVED before reading that file as it |
|
1237 | # Make sure you check for HG_TAG_MOVED before reading that file as it | |
1241 | # might exist from a previous transaction even if no tag were touched |
|
1238 | # might exist from a previous transaction even if no tag were touched | |
1242 | # in this one. Changes are recorded in a line base format:: |
|
1239 | # in this one. Changes are recorded in a line base format:: | |
1243 | # |
|
1240 | # | |
1244 | # <action> <hex-node> <tag-name>\n |
|
1241 | # <action> <hex-node> <tag-name>\n | |
1245 | # |
|
1242 | # | |
1246 | # Actions are defined as follow: |
|
1243 | # Actions are defined as follow: | |
1247 | # "-R": tag is removed, |
|
1244 | # "-R": tag is removed, | |
1248 | # "+A": tag is added, |
|
1245 | # "+A": tag is added, | |
1249 | # "-M": tag is moved (old value), |
|
1246 | # "-M": tag is moved (old value), | |
1250 | # "+M": tag is moved (new value), |
|
1247 | # "+M": tag is moved (new value), | |
1251 | tracktags = lambda x: None |
|
1248 | tracktags = lambda x: None | |
1252 | # experimental config: experimental.hook-track-tags |
|
1249 | # experimental config: experimental.hook-track-tags | |
1253 | shouldtracktags = self.ui.configbool('experimental', 'hook-track-tags') |
|
1250 | shouldtracktags = self.ui.configbool('experimental', 'hook-track-tags') | |
1254 | if desc != 'strip' and shouldtracktags: |
|
1251 | if desc != 'strip' and shouldtracktags: | |
1255 | oldheads = self.changelog.headrevs() |
|
1252 | oldheads = self.changelog.headrevs() | |
1256 | def tracktags(tr2): |
|
1253 | def tracktags(tr2): | |
1257 | repo = reporef() |
|
1254 | repo = reporef() | |
1258 | oldfnodes = tagsmod.fnoderevs(repo.ui, repo, oldheads) |
|
1255 | oldfnodes = tagsmod.fnoderevs(repo.ui, repo, oldheads) | |
1259 | newheads = repo.changelog.headrevs() |
|
1256 | newheads = repo.changelog.headrevs() | |
1260 | newfnodes = tagsmod.fnoderevs(repo.ui, repo, newheads) |
|
1257 | newfnodes = tagsmod.fnoderevs(repo.ui, repo, newheads) | |
1261 | # notes: we compare lists here. |
|
1258 | # notes: we compare lists here. | |
1262 | # As we do it only once buiding set would not be cheaper |
|
1259 | # As we do it only once buiding set would not be cheaper | |
1263 | changes = tagsmod.difftags(repo.ui, repo, oldfnodes, newfnodes) |
|
1260 | changes = tagsmod.difftags(repo.ui, repo, oldfnodes, newfnodes) | |
1264 | if changes: |
|
1261 | if changes: | |
1265 | tr2.hookargs['tag_moved'] = '1' |
|
1262 | tr2.hookargs['tag_moved'] = '1' | |
1266 | with repo.vfs('changes/tags.changes', 'w', |
|
1263 | with repo.vfs('changes/tags.changes', 'w', | |
1267 | atomictemp=True) as changesfile: |
|
1264 | atomictemp=True) as changesfile: | |
1268 | # note: we do not register the file to the transaction |
|
1265 | # note: we do not register the file to the transaction | |
1269 | # because we needs it to still exist on the transaction |
|
1266 | # because we needs it to still exist on the transaction | |
1270 | # is close (for txnclose hooks) |
|
1267 | # is close (for txnclose hooks) | |
1271 | tagsmod.writediff(changesfile, changes) |
|
1268 | tagsmod.writediff(changesfile, changes) | |
1272 | def validate(tr2): |
|
1269 | def validate(tr2): | |
1273 | """will run pre-closing hooks""" |
|
1270 | """will run pre-closing hooks""" | |
1274 | # XXX the transaction API is a bit lacking here so we take a hacky |
|
1271 | # XXX the transaction API is a bit lacking here so we take a hacky | |
1275 | # path for now |
|
1272 | # path for now | |
1276 | # |
|
1273 | # | |
1277 | # We cannot add this as a "pending" hooks since the 'tr.hookargs' |
|
1274 | # We cannot add this as a "pending" hooks since the 'tr.hookargs' | |
1278 | # dict is copied before these run. In addition we needs the data |
|
1275 | # dict is copied before these run. In addition we needs the data | |
1279 | # available to in memory hooks too. |
|
1276 | # available to in memory hooks too. | |
1280 | # |
|
1277 | # | |
1281 | # Moreover, we also need to make sure this runs before txnclose |
|
1278 | # Moreover, we also need to make sure this runs before txnclose | |
1282 | # hooks and there is no "pending" mechanism that would execute |
|
1279 | # hooks and there is no "pending" mechanism that would execute | |
1283 | # logic only if hooks are about to run. |
|
1280 | # logic only if hooks are about to run. | |
1284 | # |
|
1281 | # | |
1285 | # Fixing this limitation of the transaction is also needed to track |
|
1282 | # Fixing this limitation of the transaction is also needed to track | |
1286 | # other families of changes (bookmarks, phases, obsolescence). |
|
1283 | # other families of changes (bookmarks, phases, obsolescence). | |
1287 | # |
|
1284 | # | |
1288 | # This will have to be fixed before we remove the experimental |
|
1285 | # This will have to be fixed before we remove the experimental | |
1289 | # gating. |
|
1286 | # gating. | |
1290 | tracktags(tr2) |
|
1287 | tracktags(tr2) | |
1291 | repo = reporef() |
|
1288 | repo = reporef() | |
1292 | if repo.ui.configbool('experimental', 'single-head-per-branch'): |
|
1289 | if repo.ui.configbool('experimental', 'single-head-per-branch'): | |
1293 | scmutil.enforcesinglehead(repo, tr2, desc) |
|
1290 | scmutil.enforcesinglehead(repo, tr2, desc) | |
1294 | if hook.hashook(repo.ui, 'pretxnclose-bookmark'): |
|
1291 | if hook.hashook(repo.ui, 'pretxnclose-bookmark'): | |
1295 | for name, (old, new) in sorted(tr.changes['bookmarks'].items()): |
|
1292 | for name, (old, new) in sorted(tr.changes['bookmarks'].items()): | |
1296 | args = tr.hookargs.copy() |
|
1293 | args = tr.hookargs.copy() | |
1297 | args.update(bookmarks.preparehookargs(name, old, new)) |
|
1294 | args.update(bookmarks.preparehookargs(name, old, new)) | |
1298 | repo.hook('pretxnclose-bookmark', throw=True, |
|
1295 | repo.hook('pretxnclose-bookmark', throw=True, | |
1299 | txnname=desc, |
|
1296 | txnname=desc, | |
1300 | **pycompat.strkwargs(args)) |
|
1297 | **pycompat.strkwargs(args)) | |
1301 | if hook.hashook(repo.ui, 'pretxnclose-phase'): |
|
1298 | if hook.hashook(repo.ui, 'pretxnclose-phase'): | |
1302 | cl = repo.unfiltered().changelog |
|
1299 | cl = repo.unfiltered().changelog | |
1303 | for rev, (old, new) in tr.changes['phases'].items(): |
|
1300 | for rev, (old, new) in tr.changes['phases'].items(): | |
1304 | args = tr.hookargs.copy() |
|
1301 | args = tr.hookargs.copy() | |
1305 | node = hex(cl.node(rev)) |
|
1302 | node = hex(cl.node(rev)) | |
1306 | args.update(phases.preparehookargs(node, old, new)) |
|
1303 | args.update(phases.preparehookargs(node, old, new)) | |
1307 | repo.hook('pretxnclose-phase', throw=True, txnname=desc, |
|
1304 | repo.hook('pretxnclose-phase', throw=True, txnname=desc, | |
1308 | **pycompat.strkwargs(args)) |
|
1305 | **pycompat.strkwargs(args)) | |
1309 |
|
1306 | |||
1310 | repo.hook('pretxnclose', throw=True, |
|
1307 | repo.hook('pretxnclose', throw=True, | |
1311 | txnname=desc, **pycompat.strkwargs(tr.hookargs)) |
|
1308 | txnname=desc, **pycompat.strkwargs(tr.hookargs)) | |
1312 | def releasefn(tr, success): |
|
1309 | def releasefn(tr, success): | |
1313 | repo = reporef() |
|
1310 | repo = reporef() | |
1314 | if success: |
|
1311 | if success: | |
1315 | # this should be explicitly invoked here, because |
|
1312 | # this should be explicitly invoked here, because | |
1316 | # in-memory changes aren't written out at closing |
|
1313 | # in-memory changes aren't written out at closing | |
1317 | # transaction, if tr.addfilegenerator (via |
|
1314 | # transaction, if tr.addfilegenerator (via | |
1318 | # dirstate.write or so) isn't invoked while |
|
1315 | # dirstate.write or so) isn't invoked while | |
1319 | # transaction running |
|
1316 | # transaction running | |
1320 | repo.dirstate.write(None) |
|
1317 | repo.dirstate.write(None) | |
1321 | else: |
|
1318 | else: | |
1322 | # discard all changes (including ones already written |
|
1319 | # discard all changes (including ones already written | |
1323 | # out) in this transaction |
|
1320 | # out) in this transaction | |
1324 | repo.dirstate.restorebackup(None, 'journal.dirstate') |
|
1321 | repo.dirstate.restorebackup(None, 'journal.dirstate') | |
1325 |
|
1322 | |||
1326 | repo.invalidate(clearfilecache=True) |
|
1323 | repo.invalidate(clearfilecache=True) | |
1327 |
|
1324 | |||
1328 | tr = transaction.transaction(rp, self.svfs, vfsmap, |
|
1325 | tr = transaction.transaction(rp, self.svfs, vfsmap, | |
1329 | "journal", |
|
1326 | "journal", | |
1330 | "undo", |
|
1327 | "undo", | |
1331 | aftertrans(renames), |
|
1328 | aftertrans(renames), | |
1332 | self.store.createmode, |
|
1329 | self.store.createmode, | |
1333 | validator=validate, |
|
1330 | validator=validate, | |
1334 | releasefn=releasefn, |
|
1331 | releasefn=releasefn, | |
1335 | checkambigfiles=_cachedfiles, |
|
1332 | checkambigfiles=_cachedfiles, | |
1336 | name=desc) |
|
1333 | name=desc) | |
1337 | tr.changes['revs'] = xrange(0, 0) |
|
1334 | tr.changes['revs'] = xrange(0, 0) | |
1338 | tr.changes['obsmarkers'] = set() |
|
1335 | tr.changes['obsmarkers'] = set() | |
1339 | tr.changes['phases'] = {} |
|
1336 | tr.changes['phases'] = {} | |
1340 | tr.changes['bookmarks'] = {} |
|
1337 | tr.changes['bookmarks'] = {} | |
1341 |
|
1338 | |||
1342 | tr.hookargs['txnid'] = txnid |
|
1339 | tr.hookargs['txnid'] = txnid | |
1343 | # note: writing the fncache only during finalize mean that the file is |
|
1340 | # note: writing the fncache only during finalize mean that the file is | |
1344 | # outdated when running hooks. As fncache is used for streaming clone, |
|
1341 | # outdated when running hooks. As fncache is used for streaming clone, | |
1345 | # this is not expected to break anything that happen during the hooks. |
|
1342 | # this is not expected to break anything that happen during the hooks. | |
1346 | tr.addfinalize('flush-fncache', self.store.write) |
|
1343 | tr.addfinalize('flush-fncache', self.store.write) | |
1347 | def txnclosehook(tr2): |
|
1344 | def txnclosehook(tr2): | |
1348 | """To be run if transaction is successful, will schedule a hook run |
|
1345 | """To be run if transaction is successful, will schedule a hook run | |
1349 | """ |
|
1346 | """ | |
1350 | # Don't reference tr2 in hook() so we don't hold a reference. |
|
1347 | # Don't reference tr2 in hook() so we don't hold a reference. | |
1351 | # This reduces memory consumption when there are multiple |
|
1348 | # This reduces memory consumption when there are multiple | |
1352 | # transactions per lock. This can likely go away if issue5045 |
|
1349 | # transactions per lock. This can likely go away if issue5045 | |
1353 | # fixes the function accumulation. |
|
1350 | # fixes the function accumulation. | |
1354 | hookargs = tr2.hookargs |
|
1351 | hookargs = tr2.hookargs | |
1355 |
|
1352 | |||
1356 | def hookfunc(): |
|
1353 | def hookfunc(): | |
1357 | repo = reporef() |
|
1354 | repo = reporef() | |
1358 | if hook.hashook(repo.ui, 'txnclose-bookmark'): |
|
1355 | if hook.hashook(repo.ui, 'txnclose-bookmark'): | |
1359 | bmchanges = sorted(tr.changes['bookmarks'].items()) |
|
1356 | bmchanges = sorted(tr.changes['bookmarks'].items()) | |
1360 | for name, (old, new) in bmchanges: |
|
1357 | for name, (old, new) in bmchanges: | |
1361 | args = tr.hookargs.copy() |
|
1358 | args = tr.hookargs.copy() | |
1362 | args.update(bookmarks.preparehookargs(name, old, new)) |
|
1359 | args.update(bookmarks.preparehookargs(name, old, new)) | |
1363 | repo.hook('txnclose-bookmark', throw=False, |
|
1360 | repo.hook('txnclose-bookmark', throw=False, | |
1364 | txnname=desc, **pycompat.strkwargs(args)) |
|
1361 | txnname=desc, **pycompat.strkwargs(args)) | |
1365 |
|
1362 | |||
1366 | if hook.hashook(repo.ui, 'txnclose-phase'): |
|
1363 | if hook.hashook(repo.ui, 'txnclose-phase'): | |
1367 | cl = repo.unfiltered().changelog |
|
1364 | cl = repo.unfiltered().changelog | |
1368 | phasemv = sorted(tr.changes['phases'].items()) |
|
1365 | phasemv = sorted(tr.changes['phases'].items()) | |
1369 | for rev, (old, new) in phasemv: |
|
1366 | for rev, (old, new) in phasemv: | |
1370 | args = tr.hookargs.copy() |
|
1367 | args = tr.hookargs.copy() | |
1371 | node = hex(cl.node(rev)) |
|
1368 | node = hex(cl.node(rev)) | |
1372 | args.update(phases.preparehookargs(node, old, new)) |
|
1369 | args.update(phases.preparehookargs(node, old, new)) | |
1373 | repo.hook('txnclose-phase', throw=False, txnname=desc, |
|
1370 | repo.hook('txnclose-phase', throw=False, txnname=desc, | |
1374 | **pycompat.strkwargs(args)) |
|
1371 | **pycompat.strkwargs(args)) | |
1375 |
|
1372 | |||
1376 | repo.hook('txnclose', throw=False, txnname=desc, |
|
1373 | repo.hook('txnclose', throw=False, txnname=desc, | |
1377 | **pycompat.strkwargs(hookargs)) |
|
1374 | **pycompat.strkwargs(hookargs)) | |
1378 | reporef()._afterlock(hookfunc) |
|
1375 | reporef()._afterlock(hookfunc) | |
1379 | tr.addfinalize('txnclose-hook', txnclosehook) |
|
1376 | tr.addfinalize('txnclose-hook', txnclosehook) | |
1380 | # Include a leading "-" to make it happen before the transaction summary |
|
1377 | # Include a leading "-" to make it happen before the transaction summary | |
1381 | # reports registered via scmutil.registersummarycallback() whose names |
|
1378 | # reports registered via scmutil.registersummarycallback() whose names | |
1382 | # are 00-txnreport etc. That way, the caches will be warm when the |
|
1379 | # are 00-txnreport etc. That way, the caches will be warm when the | |
1383 | # callbacks run. |
|
1380 | # callbacks run. | |
1384 | tr.addpostclose('-warm-cache', self._buildcacheupdater(tr)) |
|
1381 | tr.addpostclose('-warm-cache', self._buildcacheupdater(tr)) | |
1385 | def txnaborthook(tr2): |
|
1382 | def txnaborthook(tr2): | |
1386 | """To be run if transaction is aborted |
|
1383 | """To be run if transaction is aborted | |
1387 | """ |
|
1384 | """ | |
1388 | reporef().hook('txnabort', throw=False, txnname=desc, |
|
1385 | reporef().hook('txnabort', throw=False, txnname=desc, | |
1389 | **pycompat.strkwargs(tr2.hookargs)) |
|
1386 | **pycompat.strkwargs(tr2.hookargs)) | |
1390 | tr.addabort('txnabort-hook', txnaborthook) |
|
1387 | tr.addabort('txnabort-hook', txnaborthook) | |
1391 | # avoid eager cache invalidation. in-memory data should be identical |
|
1388 | # avoid eager cache invalidation. in-memory data should be identical | |
1392 | # to stored data if transaction has no error. |
|
1389 | # to stored data if transaction has no error. | |
1393 | tr.addpostclose('refresh-filecachestats', self._refreshfilecachestats) |
|
1390 | tr.addpostclose('refresh-filecachestats', self._refreshfilecachestats) | |
1394 | self._transref = weakref.ref(tr) |
|
1391 | self._transref = weakref.ref(tr) | |
1395 | scmutil.registersummarycallback(self, tr, desc) |
|
1392 | scmutil.registersummarycallback(self, tr, desc) | |
1396 | return tr |
|
1393 | return tr | |
1397 |
|
1394 | |||
1398 | def _journalfiles(self): |
|
1395 | def _journalfiles(self): | |
1399 | return ((self.svfs, 'journal'), |
|
1396 | return ((self.svfs, 'journal'), | |
1400 | (self.vfs, 'journal.dirstate'), |
|
1397 | (self.vfs, 'journal.dirstate'), | |
1401 | (self.vfs, 'journal.branch'), |
|
1398 | (self.vfs, 'journal.branch'), | |
1402 | (self.vfs, 'journal.desc'), |
|
1399 | (self.vfs, 'journal.desc'), | |
1403 | (self.vfs, 'journal.bookmarks'), |
|
1400 | (self.vfs, 'journal.bookmarks'), | |
1404 | (self.svfs, 'journal.phaseroots')) |
|
1401 | (self.svfs, 'journal.phaseroots')) | |
1405 |
|
1402 | |||
1406 | def undofiles(self): |
|
1403 | def undofiles(self): | |
1407 | return [(vfs, undoname(x)) for vfs, x in self._journalfiles()] |
|
1404 | return [(vfs, undoname(x)) for vfs, x in self._journalfiles()] | |
1408 |
|
1405 | |||
1409 | @unfilteredmethod |
|
1406 | @unfilteredmethod | |
1410 | def _writejournal(self, desc): |
|
1407 | def _writejournal(self, desc): | |
1411 | self.dirstate.savebackup(None, 'journal.dirstate') |
|
1408 | self.dirstate.savebackup(None, 'journal.dirstate') | |
1412 | self.vfs.write("journal.branch", |
|
1409 | self.vfs.write("journal.branch", | |
1413 | encoding.fromlocal(self.dirstate.branch())) |
|
1410 | encoding.fromlocal(self.dirstate.branch())) | |
1414 | self.vfs.write("journal.desc", |
|
1411 | self.vfs.write("journal.desc", | |
1415 | "%d\n%s\n" % (len(self), desc)) |
|
1412 | "%d\n%s\n" % (len(self), desc)) | |
1416 | self.vfs.write("journal.bookmarks", |
|
1413 | self.vfs.write("journal.bookmarks", | |
1417 | self.vfs.tryread("bookmarks")) |
|
1414 | self.vfs.tryread("bookmarks")) | |
1418 | self.svfs.write("journal.phaseroots", |
|
1415 | self.svfs.write("journal.phaseroots", | |
1419 | self.svfs.tryread("phaseroots")) |
|
1416 | self.svfs.tryread("phaseroots")) | |
1420 |
|
1417 | |||
1421 | def recover(self): |
|
1418 | def recover(self): | |
1422 | with self.lock(): |
|
1419 | with self.lock(): | |
1423 | if self.svfs.exists("journal"): |
|
1420 | if self.svfs.exists("journal"): | |
1424 | self.ui.status(_("rolling back interrupted transaction\n")) |
|
1421 | self.ui.status(_("rolling back interrupted transaction\n")) | |
1425 | vfsmap = {'': self.svfs, |
|
1422 | vfsmap = {'': self.svfs, | |
1426 | 'plain': self.vfs,} |
|
1423 | 'plain': self.vfs,} | |
1427 | transaction.rollback(self.svfs, vfsmap, "journal", |
|
1424 | transaction.rollback(self.svfs, vfsmap, "journal", | |
1428 | self.ui.warn, |
|
1425 | self.ui.warn, | |
1429 | checkambigfiles=_cachedfiles) |
|
1426 | checkambigfiles=_cachedfiles) | |
1430 | self.invalidate() |
|
1427 | self.invalidate() | |
1431 | return True |
|
1428 | return True | |
1432 | else: |
|
1429 | else: | |
1433 | self.ui.warn(_("no interrupted transaction available\n")) |
|
1430 | self.ui.warn(_("no interrupted transaction available\n")) | |
1434 | return False |
|
1431 | return False | |
1435 |
|
1432 | |||
1436 | def rollback(self, dryrun=False, force=False): |
|
1433 | def rollback(self, dryrun=False, force=False): | |
1437 | wlock = lock = dsguard = None |
|
1434 | wlock = lock = dsguard = None | |
1438 | try: |
|
1435 | try: | |
1439 | wlock = self.wlock() |
|
1436 | wlock = self.wlock() | |
1440 | lock = self.lock() |
|
1437 | lock = self.lock() | |
1441 | if self.svfs.exists("undo"): |
|
1438 | if self.svfs.exists("undo"): | |
1442 | dsguard = dirstateguard.dirstateguard(self, 'rollback') |
|
1439 | dsguard = dirstateguard.dirstateguard(self, 'rollback') | |
1443 |
|
1440 | |||
1444 | return self._rollback(dryrun, force, dsguard) |
|
1441 | return self._rollback(dryrun, force, dsguard) | |
1445 | else: |
|
1442 | else: | |
1446 | self.ui.warn(_("no rollback information available\n")) |
|
1443 | self.ui.warn(_("no rollback information available\n")) | |
1447 | return 1 |
|
1444 | return 1 | |
1448 | finally: |
|
1445 | finally: | |
1449 | release(dsguard, lock, wlock) |
|
1446 | release(dsguard, lock, wlock) | |
1450 |
|
1447 | |||
1451 | @unfilteredmethod # Until we get smarter cache management |
|
1448 | @unfilteredmethod # Until we get smarter cache management | |
1452 | def _rollback(self, dryrun, force, dsguard): |
|
1449 | def _rollback(self, dryrun, force, dsguard): | |
1453 | ui = self.ui |
|
1450 | ui = self.ui | |
1454 | try: |
|
1451 | try: | |
1455 | args = self.vfs.read('undo.desc').splitlines() |
|
1452 | args = self.vfs.read('undo.desc').splitlines() | |
1456 | (oldlen, desc, detail) = (int(args[0]), args[1], None) |
|
1453 | (oldlen, desc, detail) = (int(args[0]), args[1], None) | |
1457 | if len(args) >= 3: |
|
1454 | if len(args) >= 3: | |
1458 | detail = args[2] |
|
1455 | detail = args[2] | |
1459 | oldtip = oldlen - 1 |
|
1456 | oldtip = oldlen - 1 | |
1460 |
|
1457 | |||
1461 | if detail and ui.verbose: |
|
1458 | if detail and ui.verbose: | |
1462 | msg = (_('repository tip rolled back to revision %d' |
|
1459 | msg = (_('repository tip rolled back to revision %d' | |
1463 | ' (undo %s: %s)\n') |
|
1460 | ' (undo %s: %s)\n') | |
1464 | % (oldtip, desc, detail)) |
|
1461 | % (oldtip, desc, detail)) | |
1465 | else: |
|
1462 | else: | |
1466 | msg = (_('repository tip rolled back to revision %d' |
|
1463 | msg = (_('repository tip rolled back to revision %d' | |
1467 | ' (undo %s)\n') |
|
1464 | ' (undo %s)\n') | |
1468 | % (oldtip, desc)) |
|
1465 | % (oldtip, desc)) | |
1469 | except IOError: |
|
1466 | except IOError: | |
1470 | msg = _('rolling back unknown transaction\n') |
|
1467 | msg = _('rolling back unknown transaction\n') | |
1471 | desc = None |
|
1468 | desc = None | |
1472 |
|
1469 | |||
1473 | if not force and self['.'] != self['tip'] and desc == 'commit': |
|
1470 | if not force and self['.'] != self['tip'] and desc == 'commit': | |
1474 | raise error.Abort( |
|
1471 | raise error.Abort( | |
1475 | _('rollback of last commit while not checked out ' |
|
1472 | _('rollback of last commit while not checked out ' | |
1476 | 'may lose data'), hint=_('use -f to force')) |
|
1473 | 'may lose data'), hint=_('use -f to force')) | |
1477 |
|
1474 | |||
1478 | ui.status(msg) |
|
1475 | ui.status(msg) | |
1479 | if dryrun: |
|
1476 | if dryrun: | |
1480 | return 0 |
|
1477 | return 0 | |
1481 |
|
1478 | |||
1482 | parents = self.dirstate.parents() |
|
1479 | parents = self.dirstate.parents() | |
1483 | self.destroying() |
|
1480 | self.destroying() | |
1484 | vfsmap = {'plain': self.vfs, '': self.svfs} |
|
1481 | vfsmap = {'plain': self.vfs, '': self.svfs} | |
1485 | transaction.rollback(self.svfs, vfsmap, 'undo', ui.warn, |
|
1482 | transaction.rollback(self.svfs, vfsmap, 'undo', ui.warn, | |
1486 | checkambigfiles=_cachedfiles) |
|
1483 | checkambigfiles=_cachedfiles) | |
1487 | if self.vfs.exists('undo.bookmarks'): |
|
1484 | if self.vfs.exists('undo.bookmarks'): | |
1488 | self.vfs.rename('undo.bookmarks', 'bookmarks', checkambig=True) |
|
1485 | self.vfs.rename('undo.bookmarks', 'bookmarks', checkambig=True) | |
1489 | if self.svfs.exists('undo.phaseroots'): |
|
1486 | if self.svfs.exists('undo.phaseroots'): | |
1490 | self.svfs.rename('undo.phaseroots', 'phaseroots', checkambig=True) |
|
1487 | self.svfs.rename('undo.phaseroots', 'phaseroots', checkambig=True) | |
1491 | self.invalidate() |
|
1488 | self.invalidate() | |
1492 |
|
1489 | |||
1493 | parentgone = (parents[0] not in self.changelog.nodemap or |
|
1490 | parentgone = (parents[0] not in self.changelog.nodemap or | |
1494 | parents[1] not in self.changelog.nodemap) |
|
1491 | parents[1] not in self.changelog.nodemap) | |
1495 | if parentgone: |
|
1492 | if parentgone: | |
1496 | # prevent dirstateguard from overwriting already restored one |
|
1493 | # prevent dirstateguard from overwriting already restored one | |
1497 | dsguard.close() |
|
1494 | dsguard.close() | |
1498 |
|
1495 | |||
1499 | self.dirstate.restorebackup(None, 'undo.dirstate') |
|
1496 | self.dirstate.restorebackup(None, 'undo.dirstate') | |
1500 | try: |
|
1497 | try: | |
1501 | branch = self.vfs.read('undo.branch') |
|
1498 | branch = self.vfs.read('undo.branch') | |
1502 | self.dirstate.setbranch(encoding.tolocal(branch)) |
|
1499 | self.dirstate.setbranch(encoding.tolocal(branch)) | |
1503 | except IOError: |
|
1500 | except IOError: | |
1504 | ui.warn(_('named branch could not be reset: ' |
|
1501 | ui.warn(_('named branch could not be reset: ' | |
1505 | 'current branch is still \'%s\'\n') |
|
1502 | 'current branch is still \'%s\'\n') | |
1506 | % self.dirstate.branch()) |
|
1503 | % self.dirstate.branch()) | |
1507 |
|
1504 | |||
1508 | parents = tuple([p.rev() for p in self[None].parents()]) |
|
1505 | parents = tuple([p.rev() for p in self[None].parents()]) | |
1509 | if len(parents) > 1: |
|
1506 | if len(parents) > 1: | |
1510 | ui.status(_('working directory now based on ' |
|
1507 | ui.status(_('working directory now based on ' | |
1511 | 'revisions %d and %d\n') % parents) |
|
1508 | 'revisions %d and %d\n') % parents) | |
1512 | else: |
|
1509 | else: | |
1513 | ui.status(_('working directory now based on ' |
|
1510 | ui.status(_('working directory now based on ' | |
1514 | 'revision %d\n') % parents) |
|
1511 | 'revision %d\n') % parents) | |
1515 | mergemod.mergestate.clean(self, self['.'].node()) |
|
1512 | mergemod.mergestate.clean(self, self['.'].node()) | |
1516 |
|
1513 | |||
1517 | # TODO: if we know which new heads may result from this rollback, pass |
|
1514 | # TODO: if we know which new heads may result from this rollback, pass | |
1518 | # them to destroy(), which will prevent the branchhead cache from being |
|
1515 | # them to destroy(), which will prevent the branchhead cache from being | |
1519 | # invalidated. |
|
1516 | # invalidated. | |
1520 | self.destroyed() |
|
1517 | self.destroyed() | |
1521 | return 0 |
|
1518 | return 0 | |
1522 |
|
1519 | |||
1523 | def _buildcacheupdater(self, newtransaction): |
|
1520 | def _buildcacheupdater(self, newtransaction): | |
1524 | """called during transaction to build the callback updating cache |
|
1521 | """called during transaction to build the callback updating cache | |
1525 |
|
1522 | |||
1526 | Lives on the repository to help extension who might want to augment |
|
1523 | Lives on the repository to help extension who might want to augment | |
1527 | this logic. For this purpose, the created transaction is passed to the |
|
1524 | this logic. For this purpose, the created transaction is passed to the | |
1528 | method. |
|
1525 | method. | |
1529 | """ |
|
1526 | """ | |
1530 | # we must avoid cyclic reference between repo and transaction. |
|
1527 | # we must avoid cyclic reference between repo and transaction. | |
1531 | reporef = weakref.ref(self) |
|
1528 | reporef = weakref.ref(self) | |
1532 | def updater(tr): |
|
1529 | def updater(tr): | |
1533 | repo = reporef() |
|
1530 | repo = reporef() | |
1534 | repo.updatecaches(tr) |
|
1531 | repo.updatecaches(tr) | |
1535 | return updater |
|
1532 | return updater | |
1536 |
|
1533 | |||
1537 | @unfilteredmethod |
|
1534 | @unfilteredmethod | |
1538 | def updatecaches(self, tr=None, full=False): |
|
1535 | def updatecaches(self, tr=None, full=False): | |
1539 | """warm appropriate caches |
|
1536 | """warm appropriate caches | |
1540 |
|
1537 | |||
1541 | If this function is called after a transaction closed. The transaction |
|
1538 | If this function is called after a transaction closed. The transaction | |
1542 | will be available in the 'tr' argument. This can be used to selectively |
|
1539 | will be available in the 'tr' argument. This can be used to selectively | |
1543 | update caches relevant to the changes in that transaction. |
|
1540 | update caches relevant to the changes in that transaction. | |
1544 |
|
1541 | |||
1545 | If 'full' is set, make sure all caches the function knows about have |
|
1542 | If 'full' is set, make sure all caches the function knows about have | |
1546 | up-to-date data. Even the ones usually loaded more lazily. |
|
1543 | up-to-date data. Even the ones usually loaded more lazily. | |
1547 | """ |
|
1544 | """ | |
1548 | if tr is not None and tr.hookargs.get('source') == 'strip': |
|
1545 | if tr is not None and tr.hookargs.get('source') == 'strip': | |
1549 | # During strip, many caches are invalid but |
|
1546 | # During strip, many caches are invalid but | |
1550 | # later call to `destroyed` will refresh them. |
|
1547 | # later call to `destroyed` will refresh them. | |
1551 | return |
|
1548 | return | |
1552 |
|
1549 | |||
1553 | if tr is None or tr.changes['revs']: |
|
1550 | if tr is None or tr.changes['revs']: | |
1554 | # updating the unfiltered branchmap should refresh all the others, |
|
1551 | # updating the unfiltered branchmap should refresh all the others, | |
1555 | self.ui.debug('updating the branch cache\n') |
|
1552 | self.ui.debug('updating the branch cache\n') | |
1556 | branchmap.updatecache(self.filtered('served')) |
|
1553 | branchmap.updatecache(self.filtered('served')) | |
1557 |
|
1554 | |||
1558 | if full: |
|
1555 | if full: | |
1559 | rbc = self.revbranchcache() |
|
1556 | rbc = self.revbranchcache() | |
1560 | for r in self.changelog: |
|
1557 | for r in self.changelog: | |
1561 | rbc.branchinfo(r) |
|
1558 | rbc.branchinfo(r) | |
1562 | rbc.write() |
|
1559 | rbc.write() | |
1563 |
|
1560 | |||
1564 | def invalidatecaches(self): |
|
1561 | def invalidatecaches(self): | |
1565 |
|
1562 | |||
1566 | if '_tagscache' in vars(self): |
|
1563 | if '_tagscache' in vars(self): | |
1567 | # can't use delattr on proxy |
|
1564 | # can't use delattr on proxy | |
1568 | del self.__dict__['_tagscache'] |
|
1565 | del self.__dict__['_tagscache'] | |
1569 |
|
1566 | |||
1570 | self.unfiltered()._branchcaches.clear() |
|
1567 | self.unfiltered()._branchcaches.clear() | |
1571 | self.invalidatevolatilesets() |
|
1568 | self.invalidatevolatilesets() | |
1572 | self._sparsesignaturecache.clear() |
|
1569 | self._sparsesignaturecache.clear() | |
1573 |
|
1570 | |||
1574 | def invalidatevolatilesets(self): |
|
1571 | def invalidatevolatilesets(self): | |
1575 | self.filteredrevcache.clear() |
|
1572 | self.filteredrevcache.clear() | |
1576 | obsolete.clearobscaches(self) |
|
1573 | obsolete.clearobscaches(self) | |
1577 |
|
1574 | |||
1578 | def invalidatedirstate(self): |
|
1575 | def invalidatedirstate(self): | |
1579 | '''Invalidates the dirstate, causing the next call to dirstate |
|
1576 | '''Invalidates the dirstate, causing the next call to dirstate | |
1580 | to check if it was modified since the last time it was read, |
|
1577 | to check if it was modified since the last time it was read, | |
1581 | rereading it if it has. |
|
1578 | rereading it if it has. | |
1582 |
|
1579 | |||
1583 | This is different to dirstate.invalidate() that it doesn't always |
|
1580 | This is different to dirstate.invalidate() that it doesn't always | |
1584 | rereads the dirstate. Use dirstate.invalidate() if you want to |
|
1581 | rereads the dirstate. Use dirstate.invalidate() if you want to | |
1585 | explicitly read the dirstate again (i.e. restoring it to a previous |
|
1582 | explicitly read the dirstate again (i.e. restoring it to a previous | |
1586 | known good state).''' |
|
1583 | known good state).''' | |
1587 | if hasunfilteredcache(self, 'dirstate'): |
|
1584 | if hasunfilteredcache(self, 'dirstate'): | |
1588 | for k in self.dirstate._filecache: |
|
1585 | for k in self.dirstate._filecache: | |
1589 | try: |
|
1586 | try: | |
1590 | delattr(self.dirstate, k) |
|
1587 | delattr(self.dirstate, k) | |
1591 | except AttributeError: |
|
1588 | except AttributeError: | |
1592 | pass |
|
1589 | pass | |
1593 | delattr(self.unfiltered(), 'dirstate') |
|
1590 | delattr(self.unfiltered(), 'dirstate') | |
1594 |
|
1591 | |||
1595 | def invalidate(self, clearfilecache=False): |
|
1592 | def invalidate(self, clearfilecache=False): | |
1596 | '''Invalidates both store and non-store parts other than dirstate |
|
1593 | '''Invalidates both store and non-store parts other than dirstate | |
1597 |
|
1594 | |||
1598 | If a transaction is running, invalidation of store is omitted, |
|
1595 | If a transaction is running, invalidation of store is omitted, | |
1599 | because discarding in-memory changes might cause inconsistency |
|
1596 | because discarding in-memory changes might cause inconsistency | |
1600 | (e.g. incomplete fncache causes unintentional failure, but |
|
1597 | (e.g. incomplete fncache causes unintentional failure, but | |
1601 | redundant one doesn't). |
|
1598 | redundant one doesn't). | |
1602 | ''' |
|
1599 | ''' | |
1603 | unfiltered = self.unfiltered() # all file caches are stored unfiltered |
|
1600 | unfiltered = self.unfiltered() # all file caches are stored unfiltered | |
1604 | for k in list(self._filecache.keys()): |
|
1601 | for k in list(self._filecache.keys()): | |
1605 | # dirstate is invalidated separately in invalidatedirstate() |
|
1602 | # dirstate is invalidated separately in invalidatedirstate() | |
1606 | if k == 'dirstate': |
|
1603 | if k == 'dirstate': | |
1607 | continue |
|
1604 | continue | |
1608 | if (k == 'changelog' and |
|
1605 | if (k == 'changelog' and | |
1609 | self.currenttransaction() and |
|
1606 | self.currenttransaction() and | |
1610 | self.changelog._delayed): |
|
1607 | self.changelog._delayed): | |
1611 | # The changelog object may store unwritten revisions. We don't |
|
1608 | # The changelog object may store unwritten revisions. We don't | |
1612 | # want to lose them. |
|
1609 | # want to lose them. | |
1613 | # TODO: Solve the problem instead of working around it. |
|
1610 | # TODO: Solve the problem instead of working around it. | |
1614 | continue |
|
1611 | continue | |
1615 |
|
1612 | |||
1616 | if clearfilecache: |
|
1613 | if clearfilecache: | |
1617 | del self._filecache[k] |
|
1614 | del self._filecache[k] | |
1618 | try: |
|
1615 | try: | |
1619 | delattr(unfiltered, k) |
|
1616 | delattr(unfiltered, k) | |
1620 | except AttributeError: |
|
1617 | except AttributeError: | |
1621 | pass |
|
1618 | pass | |
1622 | self.invalidatecaches() |
|
1619 | self.invalidatecaches() | |
1623 | if not self.currenttransaction(): |
|
1620 | if not self.currenttransaction(): | |
1624 | # TODO: Changing contents of store outside transaction |
|
1621 | # TODO: Changing contents of store outside transaction | |
1625 | # causes inconsistency. We should make in-memory store |
|
1622 | # causes inconsistency. We should make in-memory store | |
1626 | # changes detectable, and abort if changed. |
|
1623 | # changes detectable, and abort if changed. | |
1627 | self.store.invalidatecaches() |
|
1624 | self.store.invalidatecaches() | |
1628 |
|
1625 | |||
1629 | def invalidateall(self): |
|
1626 | def invalidateall(self): | |
1630 | '''Fully invalidates both store and non-store parts, causing the |
|
1627 | '''Fully invalidates both store and non-store parts, causing the | |
1631 | subsequent operation to reread any outside changes.''' |
|
1628 | subsequent operation to reread any outside changes.''' | |
1632 | # extension should hook this to invalidate its caches |
|
1629 | # extension should hook this to invalidate its caches | |
1633 | self.invalidate() |
|
1630 | self.invalidate() | |
1634 | self.invalidatedirstate() |
|
1631 | self.invalidatedirstate() | |
1635 |
|
1632 | |||
1636 | @unfilteredmethod |
|
1633 | @unfilteredmethod | |
1637 | def _refreshfilecachestats(self, tr): |
|
1634 | def _refreshfilecachestats(self, tr): | |
1638 | """Reload stats of cached files so that they are flagged as valid""" |
|
1635 | """Reload stats of cached files so that they are flagged as valid""" | |
1639 | for k, ce in self._filecache.items(): |
|
1636 | for k, ce in self._filecache.items(): | |
1640 | k = pycompat.sysstr(k) |
|
1637 | k = pycompat.sysstr(k) | |
1641 | if k == r'dirstate' or k not in self.__dict__: |
|
1638 | if k == r'dirstate' or k not in self.__dict__: | |
1642 | continue |
|
1639 | continue | |
1643 | ce.refresh() |
|
1640 | ce.refresh() | |
1644 |
|
1641 | |||
1645 | def _lock(self, vfs, lockname, wait, releasefn, acquirefn, desc, |
|
1642 | def _lock(self, vfs, lockname, wait, releasefn, acquirefn, desc, | |
1646 | inheritchecker=None, parentenvvar=None): |
|
1643 | inheritchecker=None, parentenvvar=None): | |
1647 | parentlock = None |
|
1644 | parentlock = None | |
1648 | # the contents of parentenvvar are used by the underlying lock to |
|
1645 | # the contents of parentenvvar are used by the underlying lock to | |
1649 | # determine whether it can be inherited |
|
1646 | # determine whether it can be inherited | |
1650 | if parentenvvar is not None: |
|
1647 | if parentenvvar is not None: | |
1651 | parentlock = encoding.environ.get(parentenvvar) |
|
1648 | parentlock = encoding.environ.get(parentenvvar) | |
1652 |
|
1649 | |||
1653 | timeout = 0 |
|
1650 | timeout = 0 | |
1654 | warntimeout = 0 |
|
1651 | warntimeout = 0 | |
1655 | if wait: |
|
1652 | if wait: | |
1656 | timeout = self.ui.configint("ui", "timeout") |
|
1653 | timeout = self.ui.configint("ui", "timeout") | |
1657 | warntimeout = self.ui.configint("ui", "timeout.warn") |
|
1654 | warntimeout = self.ui.configint("ui", "timeout.warn") | |
1658 |
|
1655 | |||
1659 | l = lockmod.trylock(self.ui, vfs, lockname, timeout, warntimeout, |
|
1656 | l = lockmod.trylock(self.ui, vfs, lockname, timeout, warntimeout, | |
1660 | releasefn=releasefn, |
|
1657 | releasefn=releasefn, | |
1661 | acquirefn=acquirefn, desc=desc, |
|
1658 | acquirefn=acquirefn, desc=desc, | |
1662 | inheritchecker=inheritchecker, |
|
1659 | inheritchecker=inheritchecker, | |
1663 | parentlock=parentlock) |
|
1660 | parentlock=parentlock) | |
1664 | return l |
|
1661 | return l | |
1665 |
|
1662 | |||
1666 | def _afterlock(self, callback): |
|
1663 | def _afterlock(self, callback): | |
1667 | """add a callback to be run when the repository is fully unlocked |
|
1664 | """add a callback to be run when the repository is fully unlocked | |
1668 |
|
1665 | |||
1669 | The callback will be executed when the outermost lock is released |
|
1666 | The callback will be executed when the outermost lock is released | |
1670 | (with wlock being higher level than 'lock').""" |
|
1667 | (with wlock being higher level than 'lock').""" | |
1671 | for ref in (self._wlockref, self._lockref): |
|
1668 | for ref in (self._wlockref, self._lockref): | |
1672 | l = ref and ref() |
|
1669 | l = ref and ref() | |
1673 | if l and l.held: |
|
1670 | if l and l.held: | |
1674 | l.postrelease.append(callback) |
|
1671 | l.postrelease.append(callback) | |
1675 | break |
|
1672 | break | |
1676 | else: # no lock have been found. |
|
1673 | else: # no lock have been found. | |
1677 | callback() |
|
1674 | callback() | |
1678 |
|
1675 | |||
1679 | def lock(self, wait=True): |
|
1676 | def lock(self, wait=True): | |
1680 | '''Lock the repository store (.hg/store) and return a weak reference |
|
1677 | '''Lock the repository store (.hg/store) and return a weak reference | |
1681 | to the lock. Use this before modifying the store (e.g. committing or |
|
1678 | to the lock. Use this before modifying the store (e.g. committing or | |
1682 | stripping). If you are opening a transaction, get a lock as well.) |
|
1679 | stripping). If you are opening a transaction, get a lock as well.) | |
1683 |
|
1680 | |||
1684 | If both 'lock' and 'wlock' must be acquired, ensure you always acquires |
|
1681 | If both 'lock' and 'wlock' must be acquired, ensure you always acquires | |
1685 | 'wlock' first to avoid a dead-lock hazard.''' |
|
1682 | 'wlock' first to avoid a dead-lock hazard.''' | |
1686 | l = self._currentlock(self._lockref) |
|
1683 | l = self._currentlock(self._lockref) | |
1687 | if l is not None: |
|
1684 | if l is not None: | |
1688 | l.lock() |
|
1685 | l.lock() | |
1689 | return l |
|
1686 | return l | |
1690 |
|
1687 | |||
1691 | l = self._lock(self.svfs, "lock", wait, None, |
|
1688 | l = self._lock(self.svfs, "lock", wait, None, | |
1692 | self.invalidate, _('repository %s') % self.origroot) |
|
1689 | self.invalidate, _('repository %s') % self.origroot) | |
1693 | self._lockref = weakref.ref(l) |
|
1690 | self._lockref = weakref.ref(l) | |
1694 | return l |
|
1691 | return l | |
1695 |
|
1692 | |||
1696 | def _wlockchecktransaction(self): |
|
1693 | def _wlockchecktransaction(self): | |
1697 | if self.currenttransaction() is not None: |
|
1694 | if self.currenttransaction() is not None: | |
1698 | raise error.LockInheritanceContractViolation( |
|
1695 | raise error.LockInheritanceContractViolation( | |
1699 | 'wlock cannot be inherited in the middle of a transaction') |
|
1696 | 'wlock cannot be inherited in the middle of a transaction') | |
1700 |
|
1697 | |||
1701 | def wlock(self, wait=True): |
|
1698 | def wlock(self, wait=True): | |
1702 | '''Lock the non-store parts of the repository (everything under |
|
1699 | '''Lock the non-store parts of the repository (everything under | |
1703 | .hg except .hg/store) and return a weak reference to the lock. |
|
1700 | .hg except .hg/store) and return a weak reference to the lock. | |
1704 |
|
1701 | |||
1705 | Use this before modifying files in .hg. |
|
1702 | Use this before modifying files in .hg. | |
1706 |
|
1703 | |||
1707 | If both 'lock' and 'wlock' must be acquired, ensure you always acquires |
|
1704 | If both 'lock' and 'wlock' must be acquired, ensure you always acquires | |
1708 | 'wlock' first to avoid a dead-lock hazard.''' |
|
1705 | 'wlock' first to avoid a dead-lock hazard.''' | |
1709 | l = self._wlockref and self._wlockref() |
|
1706 | l = self._wlockref and self._wlockref() | |
1710 | if l is not None and l.held: |
|
1707 | if l is not None and l.held: | |
1711 | l.lock() |
|
1708 | l.lock() | |
1712 | return l |
|
1709 | return l | |
1713 |
|
1710 | |||
1714 | # We do not need to check for non-waiting lock acquisition. Such |
|
1711 | # We do not need to check for non-waiting lock acquisition. Such | |
1715 | # acquisition would not cause dead-lock as they would just fail. |
|
1712 | # acquisition would not cause dead-lock as they would just fail. | |
1716 | if wait and (self.ui.configbool('devel', 'all-warnings') |
|
1713 | if wait and (self.ui.configbool('devel', 'all-warnings') | |
1717 | or self.ui.configbool('devel', 'check-locks')): |
|
1714 | or self.ui.configbool('devel', 'check-locks')): | |
1718 | if self._currentlock(self._lockref) is not None: |
|
1715 | if self._currentlock(self._lockref) is not None: | |
1719 | self.ui.develwarn('"wlock" acquired after "lock"') |
|
1716 | self.ui.develwarn('"wlock" acquired after "lock"') | |
1720 |
|
1717 | |||
1721 | def unlock(): |
|
1718 | def unlock(): | |
1722 | if self.dirstate.pendingparentchange(): |
|
1719 | if self.dirstate.pendingparentchange(): | |
1723 | self.dirstate.invalidate() |
|
1720 | self.dirstate.invalidate() | |
1724 | else: |
|
1721 | else: | |
1725 | self.dirstate.write(None) |
|
1722 | self.dirstate.write(None) | |
1726 |
|
1723 | |||
1727 | self._filecache['dirstate'].refresh() |
|
1724 | self._filecache['dirstate'].refresh() | |
1728 |
|
1725 | |||
1729 | l = self._lock(self.vfs, "wlock", wait, unlock, |
|
1726 | l = self._lock(self.vfs, "wlock", wait, unlock, | |
1730 | self.invalidatedirstate, _('working directory of %s') % |
|
1727 | self.invalidatedirstate, _('working directory of %s') % | |
1731 | self.origroot, |
|
1728 | self.origroot, | |
1732 | inheritchecker=self._wlockchecktransaction, |
|
1729 | inheritchecker=self._wlockchecktransaction, | |
1733 | parentenvvar='HG_WLOCK_LOCKER') |
|
1730 | parentenvvar='HG_WLOCK_LOCKER') | |
1734 | self._wlockref = weakref.ref(l) |
|
1731 | self._wlockref = weakref.ref(l) | |
1735 | return l |
|
1732 | return l | |
1736 |
|
1733 | |||
1737 | def _currentlock(self, lockref): |
|
1734 | def _currentlock(self, lockref): | |
1738 | """Returns the lock if it's held, or None if it's not.""" |
|
1735 | """Returns the lock if it's held, or None if it's not.""" | |
1739 | if lockref is None: |
|
1736 | if lockref is None: | |
1740 | return None |
|
1737 | return None | |
1741 | l = lockref() |
|
1738 | l = lockref() | |
1742 | if l is None or not l.held: |
|
1739 | if l is None or not l.held: | |
1743 | return None |
|
1740 | return None | |
1744 | return l |
|
1741 | return l | |
1745 |
|
1742 | |||
1746 | def currentwlock(self): |
|
1743 | def currentwlock(self): | |
1747 | """Returns the wlock if it's held, or None if it's not.""" |
|
1744 | """Returns the wlock if it's held, or None if it's not.""" | |
1748 | return self._currentlock(self._wlockref) |
|
1745 | return self._currentlock(self._wlockref) | |
1749 |
|
1746 | |||
1750 | def _filecommit(self, fctx, manifest1, manifest2, linkrev, tr, changelist): |
|
1747 | def _filecommit(self, fctx, manifest1, manifest2, linkrev, tr, changelist): | |
1751 | """ |
|
1748 | """ | |
1752 | commit an individual file as part of a larger transaction |
|
1749 | commit an individual file as part of a larger transaction | |
1753 | """ |
|
1750 | """ | |
1754 |
|
1751 | |||
1755 | fname = fctx.path() |
|
1752 | fname = fctx.path() | |
1756 | fparent1 = manifest1.get(fname, nullid) |
|
1753 | fparent1 = manifest1.get(fname, nullid) | |
1757 | fparent2 = manifest2.get(fname, nullid) |
|
1754 | fparent2 = manifest2.get(fname, nullid) | |
1758 | if isinstance(fctx, context.filectx): |
|
1755 | if isinstance(fctx, context.filectx): | |
1759 | node = fctx.filenode() |
|
1756 | node = fctx.filenode() | |
1760 | if node in [fparent1, fparent2]: |
|
1757 | if node in [fparent1, fparent2]: | |
1761 | self.ui.debug('reusing %s filelog entry\n' % fname) |
|
1758 | self.ui.debug('reusing %s filelog entry\n' % fname) | |
1762 | if manifest1.flags(fname) != fctx.flags(): |
|
1759 | if manifest1.flags(fname) != fctx.flags(): | |
1763 | changelist.append(fname) |
|
1760 | changelist.append(fname) | |
1764 | return node |
|
1761 | return node | |
1765 |
|
1762 | |||
1766 | flog = self.file(fname) |
|
1763 | flog = self.file(fname) | |
1767 | meta = {} |
|
1764 | meta = {} | |
1768 | copy = fctx.renamed() |
|
1765 | copy = fctx.renamed() | |
1769 | if copy and copy[0] != fname: |
|
1766 | if copy and copy[0] != fname: | |
1770 | # Mark the new revision of this file as a copy of another |
|
1767 | # Mark the new revision of this file as a copy of another | |
1771 | # file. This copy data will effectively act as a parent |
|
1768 | # file. This copy data will effectively act as a parent | |
1772 | # of this new revision. If this is a merge, the first |
|
1769 | # of this new revision. If this is a merge, the first | |
1773 | # parent will be the nullid (meaning "look up the copy data") |
|
1770 | # parent will be the nullid (meaning "look up the copy data") | |
1774 | # and the second one will be the other parent. For example: |
|
1771 | # and the second one will be the other parent. For example: | |
1775 | # |
|
1772 | # | |
1776 | # 0 --- 1 --- 3 rev1 changes file foo |
|
1773 | # 0 --- 1 --- 3 rev1 changes file foo | |
1777 | # \ / rev2 renames foo to bar and changes it |
|
1774 | # \ / rev2 renames foo to bar and changes it | |
1778 | # \- 2 -/ rev3 should have bar with all changes and |
|
1775 | # \- 2 -/ rev3 should have bar with all changes and | |
1779 | # should record that bar descends from |
|
1776 | # should record that bar descends from | |
1780 | # bar in rev2 and foo in rev1 |
|
1777 | # bar in rev2 and foo in rev1 | |
1781 | # |
|
1778 | # | |
1782 | # this allows this merge to succeed: |
|
1779 | # this allows this merge to succeed: | |
1783 | # |
|
1780 | # | |
1784 | # 0 --- 1 --- 3 rev4 reverts the content change from rev2 |
|
1781 | # 0 --- 1 --- 3 rev4 reverts the content change from rev2 | |
1785 | # \ / merging rev3 and rev4 should use bar@rev2 |
|
1782 | # \ / merging rev3 and rev4 should use bar@rev2 | |
1786 | # \- 2 --- 4 as the merge base |
|
1783 | # \- 2 --- 4 as the merge base | |
1787 | # |
|
1784 | # | |
1788 |
|
1785 | |||
1789 | cfname = copy[0] |
|
1786 | cfname = copy[0] | |
1790 | crev = manifest1.get(cfname) |
|
1787 | crev = manifest1.get(cfname) | |
1791 | newfparent = fparent2 |
|
1788 | newfparent = fparent2 | |
1792 |
|
1789 | |||
1793 | if manifest2: # branch merge |
|
1790 | if manifest2: # branch merge | |
1794 | if fparent2 == nullid or crev is None: # copied on remote side |
|
1791 | if fparent2 == nullid or crev is None: # copied on remote side | |
1795 | if cfname in manifest2: |
|
1792 | if cfname in manifest2: | |
1796 | crev = manifest2[cfname] |
|
1793 | crev = manifest2[cfname] | |
1797 | newfparent = fparent1 |
|
1794 | newfparent = fparent1 | |
1798 |
|
1795 | |||
1799 | # Here, we used to search backwards through history to try to find |
|
1796 | # Here, we used to search backwards through history to try to find | |
1800 | # where the file copy came from if the source of a copy was not in |
|
1797 | # where the file copy came from if the source of a copy was not in | |
1801 | # the parent directory. However, this doesn't actually make sense to |
|
1798 | # the parent directory. However, this doesn't actually make sense to | |
1802 | # do (what does a copy from something not in your working copy even |
|
1799 | # do (what does a copy from something not in your working copy even | |
1803 | # mean?) and it causes bugs (eg, issue4476). Instead, we will warn |
|
1800 | # mean?) and it causes bugs (eg, issue4476). Instead, we will warn | |
1804 | # the user that copy information was dropped, so if they didn't |
|
1801 | # the user that copy information was dropped, so if they didn't | |
1805 | # expect this outcome it can be fixed, but this is the correct |
|
1802 | # expect this outcome it can be fixed, but this is the correct | |
1806 | # behavior in this circumstance. |
|
1803 | # behavior in this circumstance. | |
1807 |
|
1804 | |||
1808 | if crev: |
|
1805 | if crev: | |
1809 | self.ui.debug(" %s: copy %s:%s\n" % (fname, cfname, hex(crev))) |
|
1806 | self.ui.debug(" %s: copy %s:%s\n" % (fname, cfname, hex(crev))) | |
1810 | meta["copy"] = cfname |
|
1807 | meta["copy"] = cfname | |
1811 | meta["copyrev"] = hex(crev) |
|
1808 | meta["copyrev"] = hex(crev) | |
1812 | fparent1, fparent2 = nullid, newfparent |
|
1809 | fparent1, fparent2 = nullid, newfparent | |
1813 | else: |
|
1810 | else: | |
1814 | self.ui.warn(_("warning: can't find ancestor for '%s' " |
|
1811 | self.ui.warn(_("warning: can't find ancestor for '%s' " | |
1815 | "copied from '%s'!\n") % (fname, cfname)) |
|
1812 | "copied from '%s'!\n") % (fname, cfname)) | |
1816 |
|
1813 | |||
1817 | elif fparent1 == nullid: |
|
1814 | elif fparent1 == nullid: | |
1818 | fparent1, fparent2 = fparent2, nullid |
|
1815 | fparent1, fparent2 = fparent2, nullid | |
1819 | elif fparent2 != nullid: |
|
1816 | elif fparent2 != nullid: | |
1820 | # is one parent an ancestor of the other? |
|
1817 | # is one parent an ancestor of the other? | |
1821 | fparentancestors = flog.commonancestorsheads(fparent1, fparent2) |
|
1818 | fparentancestors = flog.commonancestorsheads(fparent1, fparent2) | |
1822 | if fparent1 in fparentancestors: |
|
1819 | if fparent1 in fparentancestors: | |
1823 | fparent1, fparent2 = fparent2, nullid |
|
1820 | fparent1, fparent2 = fparent2, nullid | |
1824 | elif fparent2 in fparentancestors: |
|
1821 | elif fparent2 in fparentancestors: | |
1825 | fparent2 = nullid |
|
1822 | fparent2 = nullid | |
1826 |
|
1823 | |||
1827 | # is the file changed? |
|
1824 | # is the file changed? | |
1828 | text = fctx.data() |
|
1825 | text = fctx.data() | |
1829 | if fparent2 != nullid or flog.cmp(fparent1, text) or meta: |
|
1826 | if fparent2 != nullid or flog.cmp(fparent1, text) or meta: | |
1830 | changelist.append(fname) |
|
1827 | changelist.append(fname) | |
1831 | return flog.add(text, meta, tr, linkrev, fparent1, fparent2) |
|
1828 | return flog.add(text, meta, tr, linkrev, fparent1, fparent2) | |
1832 | # are just the flags changed during merge? |
|
1829 | # are just the flags changed during merge? | |
1833 | elif fname in manifest1 and manifest1.flags(fname) != fctx.flags(): |
|
1830 | elif fname in manifest1 and manifest1.flags(fname) != fctx.flags(): | |
1834 | changelist.append(fname) |
|
1831 | changelist.append(fname) | |
1835 |
|
1832 | |||
1836 | return fparent1 |
|
1833 | return fparent1 | |
1837 |
|
1834 | |||
1838 | def checkcommitpatterns(self, wctx, vdirs, match, status, fail): |
|
1835 | def checkcommitpatterns(self, wctx, vdirs, match, status, fail): | |
1839 | """check for commit arguments that aren't committable""" |
|
1836 | """check for commit arguments that aren't committable""" | |
1840 | if match.isexact() or match.prefix(): |
|
1837 | if match.isexact() or match.prefix(): | |
1841 | matched = set(status.modified + status.added + status.removed) |
|
1838 | matched = set(status.modified + status.added + status.removed) | |
1842 |
|
1839 | |||
1843 | for f in match.files(): |
|
1840 | for f in match.files(): | |
1844 | f = self.dirstate.normalize(f) |
|
1841 | f = self.dirstate.normalize(f) | |
1845 | if f == '.' or f in matched or f in wctx.substate: |
|
1842 | if f == '.' or f in matched or f in wctx.substate: | |
1846 | continue |
|
1843 | continue | |
1847 | if f in status.deleted: |
|
1844 | if f in status.deleted: | |
1848 | fail(f, _('file not found!')) |
|
1845 | fail(f, _('file not found!')) | |
1849 | if f in vdirs: # visited directory |
|
1846 | if f in vdirs: # visited directory | |
1850 | d = f + '/' |
|
1847 | d = f + '/' | |
1851 | for mf in matched: |
|
1848 | for mf in matched: | |
1852 | if mf.startswith(d): |
|
1849 | if mf.startswith(d): | |
1853 | break |
|
1850 | break | |
1854 | else: |
|
1851 | else: | |
1855 | fail(f, _("no match under directory!")) |
|
1852 | fail(f, _("no match under directory!")) | |
1856 | elif f not in self.dirstate: |
|
1853 | elif f not in self.dirstate: | |
1857 | fail(f, _("file not tracked!")) |
|
1854 | fail(f, _("file not tracked!")) | |
1858 |
|
1855 | |||
1859 | @unfilteredmethod |
|
1856 | @unfilteredmethod | |
1860 | def commit(self, text="", user=None, date=None, match=None, force=False, |
|
1857 | def commit(self, text="", user=None, date=None, match=None, force=False, | |
1861 | editor=False, extra=None): |
|
1858 | editor=False, extra=None): | |
1862 | """Add a new revision to current repository. |
|
1859 | """Add a new revision to current repository. | |
1863 |
|
1860 | |||
1864 | Revision information is gathered from the working directory, |
|
1861 | Revision information is gathered from the working directory, | |
1865 | match can be used to filter the committed files. If editor is |
|
1862 | match can be used to filter the committed files. If editor is | |
1866 | supplied, it is called to get a commit message. |
|
1863 | supplied, it is called to get a commit message. | |
1867 | """ |
|
1864 | """ | |
1868 | if extra is None: |
|
1865 | if extra is None: | |
1869 | extra = {} |
|
1866 | extra = {} | |
1870 |
|
1867 | |||
1871 | def fail(f, msg): |
|
1868 | def fail(f, msg): | |
1872 | raise error.Abort('%s: %s' % (f, msg)) |
|
1869 | raise error.Abort('%s: %s' % (f, msg)) | |
1873 |
|
1870 | |||
1874 | if not match: |
|
1871 | if not match: | |
1875 | match = matchmod.always(self.root, '') |
|
1872 | match = matchmod.always(self.root, '') | |
1876 |
|
1873 | |||
1877 | if not force: |
|
1874 | if not force: | |
1878 | vdirs = [] |
|
1875 | vdirs = [] | |
1879 | match.explicitdir = vdirs.append |
|
1876 | match.explicitdir = vdirs.append | |
1880 | match.bad = fail |
|
1877 | match.bad = fail | |
1881 |
|
1878 | |||
1882 | wlock = lock = tr = None |
|
1879 | wlock = lock = tr = None | |
1883 | try: |
|
1880 | try: | |
1884 | wlock = self.wlock() |
|
1881 | wlock = self.wlock() | |
1885 | lock = self.lock() # for recent changelog (see issue4368) |
|
1882 | lock = self.lock() # for recent changelog (see issue4368) | |
1886 |
|
1883 | |||
1887 | wctx = self[None] |
|
1884 | wctx = self[None] | |
1888 | merge = len(wctx.parents()) > 1 |
|
1885 | merge = len(wctx.parents()) > 1 | |
1889 |
|
1886 | |||
1890 | if not force and merge and not match.always(): |
|
1887 | if not force and merge and not match.always(): | |
1891 | raise error.Abort(_('cannot partially commit a merge ' |
|
1888 | raise error.Abort(_('cannot partially commit a merge ' | |
1892 | '(do not specify files or patterns)')) |
|
1889 | '(do not specify files or patterns)')) | |
1893 |
|
1890 | |||
1894 | status = self.status(match=match, clean=force) |
|
1891 | status = self.status(match=match, clean=force) | |
1895 | if force: |
|
1892 | if force: | |
1896 | status.modified.extend(status.clean) # mq may commit clean files |
|
1893 | status.modified.extend(status.clean) # mq may commit clean files | |
1897 |
|
1894 | |||
1898 | # check subrepos |
|
1895 | # check subrepos | |
1899 | subs, commitsubs, newstate = subrepoutil.precommit( |
|
1896 | subs, commitsubs, newstate = subrepoutil.precommit( | |
1900 | self.ui, wctx, status, match, force=force) |
|
1897 | self.ui, wctx, status, match, force=force) | |
1901 |
|
1898 | |||
1902 | # make sure all explicit patterns are matched |
|
1899 | # make sure all explicit patterns are matched | |
1903 | if not force: |
|
1900 | if not force: | |
1904 | self.checkcommitpatterns(wctx, vdirs, match, status, fail) |
|
1901 | self.checkcommitpatterns(wctx, vdirs, match, status, fail) | |
1905 |
|
1902 | |||
1906 | cctx = context.workingcommitctx(self, status, |
|
1903 | cctx = context.workingcommitctx(self, status, | |
1907 | text, user, date, extra) |
|
1904 | text, user, date, extra) | |
1908 |
|
1905 | |||
1909 | # internal config: ui.allowemptycommit |
|
1906 | # internal config: ui.allowemptycommit | |
1910 | allowemptycommit = (wctx.branch() != wctx.p1().branch() |
|
1907 | allowemptycommit = (wctx.branch() != wctx.p1().branch() | |
1911 | or extra.get('close') or merge or cctx.files() |
|
1908 | or extra.get('close') or merge or cctx.files() | |
1912 | or self.ui.configbool('ui', 'allowemptycommit')) |
|
1909 | or self.ui.configbool('ui', 'allowemptycommit')) | |
1913 | if not allowemptycommit: |
|
1910 | if not allowemptycommit: | |
1914 | return None |
|
1911 | return None | |
1915 |
|
1912 | |||
1916 | if merge and cctx.deleted(): |
|
1913 | if merge and cctx.deleted(): | |
1917 | raise error.Abort(_("cannot commit merge with missing files")) |
|
1914 | raise error.Abort(_("cannot commit merge with missing files")) | |
1918 |
|
1915 | |||
1919 | ms = mergemod.mergestate.read(self) |
|
1916 | ms = mergemod.mergestate.read(self) | |
1920 | mergeutil.checkunresolved(ms) |
|
1917 | mergeutil.checkunresolved(ms) | |
1921 |
|
1918 | |||
1922 | if editor: |
|
1919 | if editor: | |
1923 | cctx._text = editor(self, cctx, subs) |
|
1920 | cctx._text = editor(self, cctx, subs) | |
1924 | edited = (text != cctx._text) |
|
1921 | edited = (text != cctx._text) | |
1925 |
|
1922 | |||
1926 | # Save commit message in case this transaction gets rolled back |
|
1923 | # Save commit message in case this transaction gets rolled back | |
1927 | # (e.g. by a pretxncommit hook). Leave the content alone on |
|
1924 | # (e.g. by a pretxncommit hook). Leave the content alone on | |
1928 | # the assumption that the user will use the same editor again. |
|
1925 | # the assumption that the user will use the same editor again. | |
1929 | msgfn = self.savecommitmessage(cctx._text) |
|
1926 | msgfn = self.savecommitmessage(cctx._text) | |
1930 |
|
1927 | |||
1931 | # commit subs and write new state |
|
1928 | # commit subs and write new state | |
1932 | if subs: |
|
1929 | if subs: | |
1933 | for s in sorted(commitsubs): |
|
1930 | for s in sorted(commitsubs): | |
1934 | sub = wctx.sub(s) |
|
1931 | sub = wctx.sub(s) | |
1935 | self.ui.status(_('committing subrepository %s\n') % |
|
1932 | self.ui.status(_('committing subrepository %s\n') % | |
1936 | subrepoutil.subrelpath(sub)) |
|
1933 | subrepoutil.subrelpath(sub)) | |
1937 | sr = sub.commit(cctx._text, user, date) |
|
1934 | sr = sub.commit(cctx._text, user, date) | |
1938 | newstate[s] = (newstate[s][0], sr) |
|
1935 | newstate[s] = (newstate[s][0], sr) | |
1939 | subrepoutil.writestate(self, newstate) |
|
1936 | subrepoutil.writestate(self, newstate) | |
1940 |
|
1937 | |||
1941 | p1, p2 = self.dirstate.parents() |
|
1938 | p1, p2 = self.dirstate.parents() | |
1942 | hookp1, hookp2 = hex(p1), (p2 != nullid and hex(p2) or '') |
|
1939 | hookp1, hookp2 = hex(p1), (p2 != nullid and hex(p2) or '') | |
1943 | try: |
|
1940 | try: | |
1944 | self.hook("precommit", throw=True, parent1=hookp1, |
|
1941 | self.hook("precommit", throw=True, parent1=hookp1, | |
1945 | parent2=hookp2) |
|
1942 | parent2=hookp2) | |
1946 | tr = self.transaction('commit') |
|
1943 | tr = self.transaction('commit') | |
1947 | ret = self.commitctx(cctx, True) |
|
1944 | ret = self.commitctx(cctx, True) | |
1948 | except: # re-raises |
|
1945 | except: # re-raises | |
1949 | if edited: |
|
1946 | if edited: | |
1950 | self.ui.write( |
|
1947 | self.ui.write( | |
1951 | _('note: commit message saved in %s\n') % msgfn) |
|
1948 | _('note: commit message saved in %s\n') % msgfn) | |
1952 | raise |
|
1949 | raise | |
1953 | # update bookmarks, dirstate and mergestate |
|
1950 | # update bookmarks, dirstate and mergestate | |
1954 | bookmarks.update(self, [p1, p2], ret) |
|
1951 | bookmarks.update(self, [p1, p2], ret) | |
1955 | cctx.markcommitted(ret) |
|
1952 | cctx.markcommitted(ret) | |
1956 | ms.reset() |
|
1953 | ms.reset() | |
1957 | tr.close() |
|
1954 | tr.close() | |
1958 |
|
1955 | |||
1959 | finally: |
|
1956 | finally: | |
1960 | lockmod.release(tr, lock, wlock) |
|
1957 | lockmod.release(tr, lock, wlock) | |
1961 |
|
1958 | |||
1962 | def commithook(node=hex(ret), parent1=hookp1, parent2=hookp2): |
|
1959 | def commithook(node=hex(ret), parent1=hookp1, parent2=hookp2): | |
1963 | # hack for command that use a temporary commit (eg: histedit) |
|
1960 | # hack for command that use a temporary commit (eg: histedit) | |
1964 | # temporary commit got stripped before hook release |
|
1961 | # temporary commit got stripped before hook release | |
1965 | if self.changelog.hasnode(ret): |
|
1962 | if self.changelog.hasnode(ret): | |
1966 | self.hook("commit", node=node, parent1=parent1, |
|
1963 | self.hook("commit", node=node, parent1=parent1, | |
1967 | parent2=parent2) |
|
1964 | parent2=parent2) | |
1968 | self._afterlock(commithook) |
|
1965 | self._afterlock(commithook) | |
1969 | return ret |
|
1966 | return ret | |
1970 |
|
1967 | |||
1971 | @unfilteredmethod |
|
1968 | @unfilteredmethod | |
1972 | def commitctx(self, ctx, error=False): |
|
1969 | def commitctx(self, ctx, error=False): | |
1973 | """Add a new revision to current repository. |
|
1970 | """Add a new revision to current repository. | |
1974 | Revision information is passed via the context argument. |
|
1971 | Revision information is passed via the context argument. | |
1975 | """ |
|
1972 | """ | |
1976 |
|
1973 | |||
1977 | tr = None |
|
1974 | tr = None | |
1978 | p1, p2 = ctx.p1(), ctx.p2() |
|
1975 | p1, p2 = ctx.p1(), ctx.p2() | |
1979 | user = ctx.user() |
|
1976 | user = ctx.user() | |
1980 |
|
1977 | |||
1981 | lock = self.lock() |
|
1978 | lock = self.lock() | |
1982 | try: |
|
1979 | try: | |
1983 | tr = self.transaction("commit") |
|
1980 | tr = self.transaction("commit") | |
1984 | trp = weakref.proxy(tr) |
|
1981 | trp = weakref.proxy(tr) | |
1985 |
|
1982 | |||
1986 | if ctx.manifestnode(): |
|
1983 | if ctx.manifestnode(): | |
1987 | # reuse an existing manifest revision |
|
1984 | # reuse an existing manifest revision | |
1988 | mn = ctx.manifestnode() |
|
1985 | mn = ctx.manifestnode() | |
1989 | files = ctx.files() |
|
1986 | files = ctx.files() | |
1990 | elif ctx.files(): |
|
1987 | elif ctx.files(): | |
1991 | m1ctx = p1.manifestctx() |
|
1988 | m1ctx = p1.manifestctx() | |
1992 | m2ctx = p2.manifestctx() |
|
1989 | m2ctx = p2.manifestctx() | |
1993 | mctx = m1ctx.copy() |
|
1990 | mctx = m1ctx.copy() | |
1994 |
|
1991 | |||
1995 | m = mctx.read() |
|
1992 | m = mctx.read() | |
1996 | m1 = m1ctx.read() |
|
1993 | m1 = m1ctx.read() | |
1997 | m2 = m2ctx.read() |
|
1994 | m2 = m2ctx.read() | |
1998 |
|
1995 | |||
1999 | # check in files |
|
1996 | # check in files | |
2000 | added = [] |
|
1997 | added = [] | |
2001 | changed = [] |
|
1998 | changed = [] | |
2002 | removed = list(ctx.removed()) |
|
1999 | removed = list(ctx.removed()) | |
2003 | linkrev = len(self) |
|
2000 | linkrev = len(self) | |
2004 | self.ui.note(_("committing files:\n")) |
|
2001 | self.ui.note(_("committing files:\n")) | |
2005 | for f in sorted(ctx.modified() + ctx.added()): |
|
2002 | for f in sorted(ctx.modified() + ctx.added()): | |
2006 | self.ui.note(f + "\n") |
|
2003 | self.ui.note(f + "\n") | |
2007 | try: |
|
2004 | try: | |
2008 | fctx = ctx[f] |
|
2005 | fctx = ctx[f] | |
2009 | if fctx is None: |
|
2006 | if fctx is None: | |
2010 | removed.append(f) |
|
2007 | removed.append(f) | |
2011 | else: |
|
2008 | else: | |
2012 | added.append(f) |
|
2009 | added.append(f) | |
2013 | m[f] = self._filecommit(fctx, m1, m2, linkrev, |
|
2010 | m[f] = self._filecommit(fctx, m1, m2, linkrev, | |
2014 | trp, changed) |
|
2011 | trp, changed) | |
2015 | m.setflag(f, fctx.flags()) |
|
2012 | m.setflag(f, fctx.flags()) | |
2016 | except OSError as inst: |
|
2013 | except OSError as inst: | |
2017 | self.ui.warn(_("trouble committing %s!\n") % f) |
|
2014 | self.ui.warn(_("trouble committing %s!\n") % f) | |
2018 | raise |
|
2015 | raise | |
2019 | except IOError as inst: |
|
2016 | except IOError as inst: | |
2020 | errcode = getattr(inst, 'errno', errno.ENOENT) |
|
2017 | errcode = getattr(inst, 'errno', errno.ENOENT) | |
2021 | if error or errcode and errcode != errno.ENOENT: |
|
2018 | if error or errcode and errcode != errno.ENOENT: | |
2022 | self.ui.warn(_("trouble committing %s!\n") % f) |
|
2019 | self.ui.warn(_("trouble committing %s!\n") % f) | |
2023 | raise |
|
2020 | raise | |
2024 |
|
2021 | |||
2025 | # update manifest |
|
2022 | # update manifest | |
2026 | self.ui.note(_("committing manifest\n")) |
|
2023 | self.ui.note(_("committing manifest\n")) | |
2027 | removed = [f for f in sorted(removed) if f in m1 or f in m2] |
|
2024 | removed = [f for f in sorted(removed) if f in m1 or f in m2] | |
2028 | drop = [f for f in removed if f in m] |
|
2025 | drop = [f for f in removed if f in m] | |
2029 | for f in drop: |
|
2026 | for f in drop: | |
2030 | del m[f] |
|
2027 | del m[f] | |
2031 | mn = mctx.write(trp, linkrev, |
|
2028 | mn = mctx.write(trp, linkrev, | |
2032 | p1.manifestnode(), p2.manifestnode(), |
|
2029 | p1.manifestnode(), p2.manifestnode(), | |
2033 | added, drop) |
|
2030 | added, drop) | |
2034 | files = changed + removed |
|
2031 | files = changed + removed | |
2035 | else: |
|
2032 | else: | |
2036 | mn = p1.manifestnode() |
|
2033 | mn = p1.manifestnode() | |
2037 | files = [] |
|
2034 | files = [] | |
2038 |
|
2035 | |||
2039 | # update changelog |
|
2036 | # update changelog | |
2040 | self.ui.note(_("committing changelog\n")) |
|
2037 | self.ui.note(_("committing changelog\n")) | |
2041 | self.changelog.delayupdate(tr) |
|
2038 | self.changelog.delayupdate(tr) | |
2042 | n = self.changelog.add(mn, files, ctx.description(), |
|
2039 | n = self.changelog.add(mn, files, ctx.description(), | |
2043 | trp, p1.node(), p2.node(), |
|
2040 | trp, p1.node(), p2.node(), | |
2044 | user, ctx.date(), ctx.extra().copy()) |
|
2041 | user, ctx.date(), ctx.extra().copy()) | |
2045 | xp1, xp2 = p1.hex(), p2 and p2.hex() or '' |
|
2042 | xp1, xp2 = p1.hex(), p2 and p2.hex() or '' | |
2046 | self.hook('pretxncommit', throw=True, node=hex(n), parent1=xp1, |
|
2043 | self.hook('pretxncommit', throw=True, node=hex(n), parent1=xp1, | |
2047 | parent2=xp2) |
|
2044 | parent2=xp2) | |
2048 | # set the new commit is proper phase |
|
2045 | # set the new commit is proper phase | |
2049 | targetphase = subrepoutil.newcommitphase(self.ui, ctx) |
|
2046 | targetphase = subrepoutil.newcommitphase(self.ui, ctx) | |
2050 | if targetphase: |
|
2047 | if targetphase: | |
2051 | # retract boundary do not alter parent changeset. |
|
2048 | # retract boundary do not alter parent changeset. | |
2052 | # if a parent have higher the resulting phase will |
|
2049 | # if a parent have higher the resulting phase will | |
2053 | # be compliant anyway |
|
2050 | # be compliant anyway | |
2054 | # |
|
2051 | # | |
2055 | # if minimal phase was 0 we don't need to retract anything |
|
2052 | # if minimal phase was 0 we don't need to retract anything | |
2056 | phases.registernew(self, tr, targetphase, [n]) |
|
2053 | phases.registernew(self, tr, targetphase, [n]) | |
2057 | tr.close() |
|
2054 | tr.close() | |
2058 | return n |
|
2055 | return n | |
2059 | finally: |
|
2056 | finally: | |
2060 | if tr: |
|
2057 | if tr: | |
2061 | tr.release() |
|
2058 | tr.release() | |
2062 | lock.release() |
|
2059 | lock.release() | |
2063 |
|
2060 | |||
2064 | @unfilteredmethod |
|
2061 | @unfilteredmethod | |
2065 | def destroying(self): |
|
2062 | def destroying(self): | |
2066 | '''Inform the repository that nodes are about to be destroyed. |
|
2063 | '''Inform the repository that nodes are about to be destroyed. | |
2067 | Intended for use by strip and rollback, so there's a common |
|
2064 | Intended for use by strip and rollback, so there's a common | |
2068 | place for anything that has to be done before destroying history. |
|
2065 | place for anything that has to be done before destroying history. | |
2069 |
|
2066 | |||
2070 | This is mostly useful for saving state that is in memory and waiting |
|
2067 | This is mostly useful for saving state that is in memory and waiting | |
2071 | to be flushed when the current lock is released. Because a call to |
|
2068 | to be flushed when the current lock is released. Because a call to | |
2072 | destroyed is imminent, the repo will be invalidated causing those |
|
2069 | destroyed is imminent, the repo will be invalidated causing those | |
2073 | changes to stay in memory (waiting for the next unlock), or vanish |
|
2070 | changes to stay in memory (waiting for the next unlock), or vanish | |
2074 | completely. |
|
2071 | completely. | |
2075 | ''' |
|
2072 | ''' | |
2076 | # When using the same lock to commit and strip, the phasecache is left |
|
2073 | # When using the same lock to commit and strip, the phasecache is left | |
2077 | # dirty after committing. Then when we strip, the repo is invalidated, |
|
2074 | # dirty after committing. Then when we strip, the repo is invalidated, | |
2078 | # causing those changes to disappear. |
|
2075 | # causing those changes to disappear. | |
2079 | if '_phasecache' in vars(self): |
|
2076 | if '_phasecache' in vars(self): | |
2080 | self._phasecache.write() |
|
2077 | self._phasecache.write() | |
2081 |
|
2078 | |||
2082 | @unfilteredmethod |
|
2079 | @unfilteredmethod | |
2083 | def destroyed(self): |
|
2080 | def destroyed(self): | |
2084 | '''Inform the repository that nodes have been destroyed. |
|
2081 | '''Inform the repository that nodes have been destroyed. | |
2085 | Intended for use by strip and rollback, so there's a common |
|
2082 | Intended for use by strip and rollback, so there's a common | |
2086 | place for anything that has to be done after destroying history. |
|
2083 | place for anything that has to be done after destroying history. | |
2087 | ''' |
|
2084 | ''' | |
2088 | # When one tries to: |
|
2085 | # When one tries to: | |
2089 | # 1) destroy nodes thus calling this method (e.g. strip) |
|
2086 | # 1) destroy nodes thus calling this method (e.g. strip) | |
2090 | # 2) use phasecache somewhere (e.g. commit) |
|
2087 | # 2) use phasecache somewhere (e.g. commit) | |
2091 | # |
|
2088 | # | |
2092 | # then 2) will fail because the phasecache contains nodes that were |
|
2089 | # then 2) will fail because the phasecache contains nodes that were | |
2093 | # removed. We can either remove phasecache from the filecache, |
|
2090 | # removed. We can either remove phasecache from the filecache, | |
2094 | # causing it to reload next time it is accessed, or simply filter |
|
2091 | # causing it to reload next time it is accessed, or simply filter | |
2095 | # the removed nodes now and write the updated cache. |
|
2092 | # the removed nodes now and write the updated cache. | |
2096 | self._phasecache.filterunknown(self) |
|
2093 | self._phasecache.filterunknown(self) | |
2097 | self._phasecache.write() |
|
2094 | self._phasecache.write() | |
2098 |
|
2095 | |||
2099 | # refresh all repository caches |
|
2096 | # refresh all repository caches | |
2100 | self.updatecaches() |
|
2097 | self.updatecaches() | |
2101 |
|
2098 | |||
2102 | # Ensure the persistent tag cache is updated. Doing it now |
|
2099 | # Ensure the persistent tag cache is updated. Doing it now | |
2103 | # means that the tag cache only has to worry about destroyed |
|
2100 | # means that the tag cache only has to worry about destroyed | |
2104 | # heads immediately after a strip/rollback. That in turn |
|
2101 | # heads immediately after a strip/rollback. That in turn | |
2105 | # guarantees that "cachetip == currenttip" (comparing both rev |
|
2102 | # guarantees that "cachetip == currenttip" (comparing both rev | |
2106 | # and node) always means no nodes have been added or destroyed. |
|
2103 | # and node) always means no nodes have been added or destroyed. | |
2107 |
|
2104 | |||
2108 | # XXX this is suboptimal when qrefresh'ing: we strip the current |
|
2105 | # XXX this is suboptimal when qrefresh'ing: we strip the current | |
2109 | # head, refresh the tag cache, then immediately add a new head. |
|
2106 | # head, refresh the tag cache, then immediately add a new head. | |
2110 | # But I think doing it this way is necessary for the "instant |
|
2107 | # But I think doing it this way is necessary for the "instant | |
2111 | # tag cache retrieval" case to work. |
|
2108 | # tag cache retrieval" case to work. | |
2112 | self.invalidate() |
|
2109 | self.invalidate() | |
2113 |
|
2110 | |||
2114 | def status(self, node1='.', node2=None, match=None, |
|
2111 | def status(self, node1='.', node2=None, match=None, | |
2115 | ignored=False, clean=False, unknown=False, |
|
2112 | ignored=False, clean=False, unknown=False, | |
2116 | listsubrepos=False): |
|
2113 | listsubrepos=False): | |
2117 | '''a convenience method that calls node1.status(node2)''' |
|
2114 | '''a convenience method that calls node1.status(node2)''' | |
2118 | return self[node1].status(node2, match, ignored, clean, unknown, |
|
2115 | return self[node1].status(node2, match, ignored, clean, unknown, | |
2119 | listsubrepos) |
|
2116 | listsubrepos) | |
2120 |
|
2117 | |||
2121 | def addpostdsstatus(self, ps): |
|
2118 | def addpostdsstatus(self, ps): | |
2122 | """Add a callback to run within the wlock, at the point at which status |
|
2119 | """Add a callback to run within the wlock, at the point at which status | |
2123 | fixups happen. |
|
2120 | fixups happen. | |
2124 |
|
2121 | |||
2125 | On status completion, callback(wctx, status) will be called with the |
|
2122 | On status completion, callback(wctx, status) will be called with the | |
2126 | wlock held, unless the dirstate has changed from underneath or the wlock |
|
2123 | wlock held, unless the dirstate has changed from underneath or the wlock | |
2127 | couldn't be grabbed. |
|
2124 | couldn't be grabbed. | |
2128 |
|
2125 | |||
2129 | Callbacks should not capture and use a cached copy of the dirstate -- |
|
2126 | Callbacks should not capture and use a cached copy of the dirstate -- | |
2130 | it might change in the meanwhile. Instead, they should access the |
|
2127 | it might change in the meanwhile. Instead, they should access the | |
2131 | dirstate via wctx.repo().dirstate. |
|
2128 | dirstate via wctx.repo().dirstate. | |
2132 |
|
2129 | |||
2133 | This list is emptied out after each status run -- extensions should |
|
2130 | This list is emptied out after each status run -- extensions should | |
2134 | make sure it adds to this list each time dirstate.status is called. |
|
2131 | make sure it adds to this list each time dirstate.status is called. | |
2135 | Extensions should also make sure they don't call this for statuses |
|
2132 | Extensions should also make sure they don't call this for statuses | |
2136 | that don't involve the dirstate. |
|
2133 | that don't involve the dirstate. | |
2137 | """ |
|
2134 | """ | |
2138 |
|
2135 | |||
2139 | # The list is located here for uniqueness reasons -- it is actually |
|
2136 | # The list is located here for uniqueness reasons -- it is actually | |
2140 | # managed by the workingctx, but that isn't unique per-repo. |
|
2137 | # managed by the workingctx, but that isn't unique per-repo. | |
2141 | self._postdsstatus.append(ps) |
|
2138 | self._postdsstatus.append(ps) | |
2142 |
|
2139 | |||
2143 | def postdsstatus(self): |
|
2140 | def postdsstatus(self): | |
2144 | """Used by workingctx to get the list of post-dirstate-status hooks.""" |
|
2141 | """Used by workingctx to get the list of post-dirstate-status hooks.""" | |
2145 | return self._postdsstatus |
|
2142 | return self._postdsstatus | |
2146 |
|
2143 | |||
2147 | def clearpostdsstatus(self): |
|
2144 | def clearpostdsstatus(self): | |
2148 | """Used by workingctx to clear post-dirstate-status hooks.""" |
|
2145 | """Used by workingctx to clear post-dirstate-status hooks.""" | |
2149 | del self._postdsstatus[:] |
|
2146 | del self._postdsstatus[:] | |
2150 |
|
2147 | |||
2151 | def heads(self, start=None): |
|
2148 | def heads(self, start=None): | |
2152 | if start is None: |
|
2149 | if start is None: | |
2153 | cl = self.changelog |
|
2150 | cl = self.changelog | |
2154 | headrevs = reversed(cl.headrevs()) |
|
2151 | headrevs = reversed(cl.headrevs()) | |
2155 | return [cl.node(rev) for rev in headrevs] |
|
2152 | return [cl.node(rev) for rev in headrevs] | |
2156 |
|
2153 | |||
2157 | heads = self.changelog.heads(start) |
|
2154 | heads = self.changelog.heads(start) | |
2158 | # sort the output in rev descending order |
|
2155 | # sort the output in rev descending order | |
2159 | return sorted(heads, key=self.changelog.rev, reverse=True) |
|
2156 | return sorted(heads, key=self.changelog.rev, reverse=True) | |
2160 |
|
2157 | |||
2161 | def branchheads(self, branch=None, start=None, closed=False): |
|
2158 | def branchheads(self, branch=None, start=None, closed=False): | |
2162 | '''return a (possibly filtered) list of heads for the given branch |
|
2159 | '''return a (possibly filtered) list of heads for the given branch | |
2163 |
|
2160 | |||
2164 | Heads are returned in topological order, from newest to oldest. |
|
2161 | Heads are returned in topological order, from newest to oldest. | |
2165 | If branch is None, use the dirstate branch. |
|
2162 | If branch is None, use the dirstate branch. | |
2166 | If start is not None, return only heads reachable from start. |
|
2163 | If start is not None, return only heads reachable from start. | |
2167 | If closed is True, return heads that are marked as closed as well. |
|
2164 | If closed is True, return heads that are marked as closed as well. | |
2168 | ''' |
|
2165 | ''' | |
2169 | if branch is None: |
|
2166 | if branch is None: | |
2170 | branch = self[None].branch() |
|
2167 | branch = self[None].branch() | |
2171 | branches = self.branchmap() |
|
2168 | branches = self.branchmap() | |
2172 | if branch not in branches: |
|
2169 | if branch not in branches: | |
2173 | return [] |
|
2170 | return [] | |
2174 | # the cache returns heads ordered lowest to highest |
|
2171 | # the cache returns heads ordered lowest to highest | |
2175 | bheads = list(reversed(branches.branchheads(branch, closed=closed))) |
|
2172 | bheads = list(reversed(branches.branchheads(branch, closed=closed))) | |
2176 | if start is not None: |
|
2173 | if start is not None: | |
2177 | # filter out the heads that cannot be reached from startrev |
|
2174 | # filter out the heads that cannot be reached from startrev | |
2178 | fbheads = set(self.changelog.nodesbetween([start], bheads)[2]) |
|
2175 | fbheads = set(self.changelog.nodesbetween([start], bheads)[2]) | |
2179 | bheads = [h for h in bheads if h in fbheads] |
|
2176 | bheads = [h for h in bheads if h in fbheads] | |
2180 | return bheads |
|
2177 | return bheads | |
2181 |
|
2178 | |||
2182 | def branches(self, nodes): |
|
2179 | def branches(self, nodes): | |
2183 | if not nodes: |
|
2180 | if not nodes: | |
2184 | nodes = [self.changelog.tip()] |
|
2181 | nodes = [self.changelog.tip()] | |
2185 | b = [] |
|
2182 | b = [] | |
2186 | for n in nodes: |
|
2183 | for n in nodes: | |
2187 | t = n |
|
2184 | t = n | |
2188 | while True: |
|
2185 | while True: | |
2189 | p = self.changelog.parents(n) |
|
2186 | p = self.changelog.parents(n) | |
2190 | if p[1] != nullid or p[0] == nullid: |
|
2187 | if p[1] != nullid or p[0] == nullid: | |
2191 | b.append((t, n, p[0], p[1])) |
|
2188 | b.append((t, n, p[0], p[1])) | |
2192 | break |
|
2189 | break | |
2193 | n = p[0] |
|
2190 | n = p[0] | |
2194 | return b |
|
2191 | return b | |
2195 |
|
2192 | |||
2196 | def between(self, pairs): |
|
2193 | def between(self, pairs): | |
2197 | r = [] |
|
2194 | r = [] | |
2198 |
|
2195 | |||
2199 | for top, bottom in pairs: |
|
2196 | for top, bottom in pairs: | |
2200 | n, l, i = top, [], 0 |
|
2197 | n, l, i = top, [], 0 | |
2201 | f = 1 |
|
2198 | f = 1 | |
2202 |
|
2199 | |||
2203 | while n != bottom and n != nullid: |
|
2200 | while n != bottom and n != nullid: | |
2204 | p = self.changelog.parents(n)[0] |
|
2201 | p = self.changelog.parents(n)[0] | |
2205 | if i == f: |
|
2202 | if i == f: | |
2206 | l.append(n) |
|
2203 | l.append(n) | |
2207 | f = f * 2 |
|
2204 | f = f * 2 | |
2208 | n = p |
|
2205 | n = p | |
2209 | i += 1 |
|
2206 | i += 1 | |
2210 |
|
2207 | |||
2211 | r.append(l) |
|
2208 | r.append(l) | |
2212 |
|
2209 | |||
2213 | return r |
|
2210 | return r | |
2214 |
|
2211 | |||
2215 | def checkpush(self, pushop): |
|
2212 | def checkpush(self, pushop): | |
2216 | """Extensions can override this function if additional checks have |
|
2213 | """Extensions can override this function if additional checks have | |
2217 | to be performed before pushing, or call it if they override push |
|
2214 | to be performed before pushing, or call it if they override push | |
2218 | command. |
|
2215 | command. | |
2219 | """ |
|
2216 | """ | |
2220 |
|
2217 | |||
2221 | @unfilteredpropertycache |
|
2218 | @unfilteredpropertycache | |
2222 | def prepushoutgoinghooks(self): |
|
2219 | def prepushoutgoinghooks(self): | |
2223 | """Return util.hooks consists of a pushop with repo, remote, outgoing |
|
2220 | """Return util.hooks consists of a pushop with repo, remote, outgoing | |
2224 | methods, which are called before pushing changesets. |
|
2221 | methods, which are called before pushing changesets. | |
2225 | """ |
|
2222 | """ | |
2226 | return util.hooks() |
|
2223 | return util.hooks() | |
2227 |
|
2224 | |||
2228 | def pushkey(self, namespace, key, old, new): |
|
2225 | def pushkey(self, namespace, key, old, new): | |
2229 | try: |
|
2226 | try: | |
2230 | tr = self.currenttransaction() |
|
2227 | tr = self.currenttransaction() | |
2231 | hookargs = {} |
|
2228 | hookargs = {} | |
2232 | if tr is not None: |
|
2229 | if tr is not None: | |
2233 | hookargs.update(tr.hookargs) |
|
2230 | hookargs.update(tr.hookargs) | |
2234 | hookargs = pycompat.strkwargs(hookargs) |
|
2231 | hookargs = pycompat.strkwargs(hookargs) | |
2235 | hookargs[r'namespace'] = namespace |
|
2232 | hookargs[r'namespace'] = namespace | |
2236 | hookargs[r'key'] = key |
|
2233 | hookargs[r'key'] = key | |
2237 | hookargs[r'old'] = old |
|
2234 | hookargs[r'old'] = old | |
2238 | hookargs[r'new'] = new |
|
2235 | hookargs[r'new'] = new | |
2239 | self.hook('prepushkey', throw=True, **hookargs) |
|
2236 | self.hook('prepushkey', throw=True, **hookargs) | |
2240 | except error.HookAbort as exc: |
|
2237 | except error.HookAbort as exc: | |
2241 | self.ui.write_err(_("pushkey-abort: %s\n") % exc) |
|
2238 | self.ui.write_err(_("pushkey-abort: %s\n") % exc) | |
2242 | if exc.hint: |
|
2239 | if exc.hint: | |
2243 | self.ui.write_err(_("(%s)\n") % exc.hint) |
|
2240 | self.ui.write_err(_("(%s)\n") % exc.hint) | |
2244 | return False |
|
2241 | return False | |
2245 | self.ui.debug('pushing key for "%s:%s"\n' % (namespace, key)) |
|
2242 | self.ui.debug('pushing key for "%s:%s"\n' % (namespace, key)) | |
2246 | ret = pushkey.push(self, namespace, key, old, new) |
|
2243 | ret = pushkey.push(self, namespace, key, old, new) | |
2247 | def runhook(): |
|
2244 | def runhook(): | |
2248 | self.hook('pushkey', namespace=namespace, key=key, old=old, new=new, |
|
2245 | self.hook('pushkey', namespace=namespace, key=key, old=old, new=new, | |
2249 | ret=ret) |
|
2246 | ret=ret) | |
2250 | self._afterlock(runhook) |
|
2247 | self._afterlock(runhook) | |
2251 | return ret |
|
2248 | return ret | |
2252 |
|
2249 | |||
2253 | def listkeys(self, namespace): |
|
2250 | def listkeys(self, namespace): | |
2254 | self.hook('prelistkeys', throw=True, namespace=namespace) |
|
2251 | self.hook('prelistkeys', throw=True, namespace=namespace) | |
2255 | self.ui.debug('listing keys for "%s"\n' % namespace) |
|
2252 | self.ui.debug('listing keys for "%s"\n' % namespace) | |
2256 | values = pushkey.list(self, namespace) |
|
2253 | values = pushkey.list(self, namespace) | |
2257 | self.hook('listkeys', namespace=namespace, values=values) |
|
2254 | self.hook('listkeys', namespace=namespace, values=values) | |
2258 | return values |
|
2255 | return values | |
2259 |
|
2256 | |||
2260 | def debugwireargs(self, one, two, three=None, four=None, five=None): |
|
2257 | def debugwireargs(self, one, two, three=None, four=None, five=None): | |
2261 | '''used to test argument passing over the wire''' |
|
2258 | '''used to test argument passing over the wire''' | |
2262 | return "%s %s %s %s %s" % (one, two, pycompat.bytestr(three), |
|
2259 | return "%s %s %s %s %s" % (one, two, pycompat.bytestr(three), | |
2263 | pycompat.bytestr(four), |
|
2260 | pycompat.bytestr(four), | |
2264 | pycompat.bytestr(five)) |
|
2261 | pycompat.bytestr(five)) | |
2265 |
|
2262 | |||
2266 | def savecommitmessage(self, text): |
|
2263 | def savecommitmessage(self, text): | |
2267 | fp = self.vfs('last-message.txt', 'wb') |
|
2264 | fp = self.vfs('last-message.txt', 'wb') | |
2268 | try: |
|
2265 | try: | |
2269 | fp.write(text) |
|
2266 | fp.write(text) | |
2270 | finally: |
|
2267 | finally: | |
2271 | fp.close() |
|
2268 | fp.close() | |
2272 | return self.pathto(fp.name[len(self.root) + 1:]) |
|
2269 | return self.pathto(fp.name[len(self.root) + 1:]) | |
2273 |
|
2270 | |||
2274 | # used to avoid circular references so destructors work |
|
2271 | # used to avoid circular references so destructors work | |
2275 | def aftertrans(files): |
|
2272 | def aftertrans(files): | |
2276 | renamefiles = [tuple(t) for t in files] |
|
2273 | renamefiles = [tuple(t) for t in files] | |
2277 | def a(): |
|
2274 | def a(): | |
2278 | for vfs, src, dest in renamefiles: |
|
2275 | for vfs, src, dest in renamefiles: | |
2279 | # if src and dest refer to a same file, vfs.rename is a no-op, |
|
2276 | # if src and dest refer to a same file, vfs.rename is a no-op, | |
2280 | # leaving both src and dest on disk. delete dest to make sure |
|
2277 | # leaving both src and dest on disk. delete dest to make sure | |
2281 | # the rename couldn't be such a no-op. |
|
2278 | # the rename couldn't be such a no-op. | |
2282 | vfs.tryunlink(dest) |
|
2279 | vfs.tryunlink(dest) | |
2283 | try: |
|
2280 | try: | |
2284 | vfs.rename(src, dest) |
|
2281 | vfs.rename(src, dest) | |
2285 | except OSError: # journal file does not yet exist |
|
2282 | except OSError: # journal file does not yet exist | |
2286 | pass |
|
2283 | pass | |
2287 | return a |
|
2284 | return a | |
2288 |
|
2285 | |||
2289 | def undoname(fn): |
|
2286 | def undoname(fn): | |
2290 | base, name = os.path.split(fn) |
|
2287 | base, name = os.path.split(fn) | |
2291 | assert name.startswith('journal') |
|
2288 | assert name.startswith('journal') | |
2292 | return os.path.join(base, name.replace('journal', 'undo', 1)) |
|
2289 | return os.path.join(base, name.replace('journal', 'undo', 1)) | |
2293 |
|
2290 | |||
2294 | def instance(ui, path, create): |
|
2291 | def instance(ui, path, create): | |
2295 | return localrepository(ui, util.urllocalpath(path), create) |
|
2292 | return localrepository(ui, util.urllocalpath(path), create) | |
2296 |
|
2293 | |||
2297 | def islocal(path): |
|
2294 | def islocal(path): | |
2298 | return True |
|
2295 | return True | |
2299 |
|
2296 | |||
2300 | def newreporequirements(repo): |
|
2297 | def newreporequirements(repo): | |
2301 | """Determine the set of requirements for a new local repository. |
|
2298 | """Determine the set of requirements for a new local repository. | |
2302 |
|
2299 | |||
2303 | Extensions can wrap this function to specify custom requirements for |
|
2300 | Extensions can wrap this function to specify custom requirements for | |
2304 | new repositories. |
|
2301 | new repositories. | |
2305 | """ |
|
2302 | """ | |
2306 | ui = repo.ui |
|
2303 | ui = repo.ui | |
2307 | requirements = {'revlogv1'} |
|
2304 | requirements = {'revlogv1'} | |
2308 | if ui.configbool('format', 'usestore'): |
|
2305 | if ui.configbool('format', 'usestore'): | |
2309 | requirements.add('store') |
|
2306 | requirements.add('store') | |
2310 | if ui.configbool('format', 'usefncache'): |
|
2307 | if ui.configbool('format', 'usefncache'): | |
2311 | requirements.add('fncache') |
|
2308 | requirements.add('fncache') | |
2312 | if ui.configbool('format', 'dotencode'): |
|
2309 | if ui.configbool('format', 'dotencode'): | |
2313 | requirements.add('dotencode') |
|
2310 | requirements.add('dotencode') | |
2314 |
|
2311 | |||
2315 | compengine = ui.config('experimental', 'format.compression') |
|
2312 | compengine = ui.config('experimental', 'format.compression') | |
2316 | if compengine not in util.compengines: |
|
2313 | if compengine not in util.compengines: | |
2317 | raise error.Abort(_('compression engine %s defined by ' |
|
2314 | raise error.Abort(_('compression engine %s defined by ' | |
2318 | 'experimental.format.compression not available') % |
|
2315 | 'experimental.format.compression not available') % | |
2319 | compengine, |
|
2316 | compengine, | |
2320 | hint=_('run "hg debuginstall" to list available ' |
|
2317 | hint=_('run "hg debuginstall" to list available ' | |
2321 | 'compression engines')) |
|
2318 | 'compression engines')) | |
2322 |
|
2319 | |||
2323 | # zlib is the historical default and doesn't need an explicit requirement. |
|
2320 | # zlib is the historical default and doesn't need an explicit requirement. | |
2324 | if compengine != 'zlib': |
|
2321 | if compengine != 'zlib': | |
2325 | requirements.add('exp-compression-%s' % compengine) |
|
2322 | requirements.add('exp-compression-%s' % compengine) | |
2326 |
|
2323 | |||
2327 | if scmutil.gdinitconfig(ui): |
|
2324 | if scmutil.gdinitconfig(ui): | |
2328 | requirements.add('generaldelta') |
|
2325 | requirements.add('generaldelta') | |
2329 | if ui.configbool('experimental', 'treemanifest'): |
|
2326 | if ui.configbool('experimental', 'treemanifest'): | |
2330 | requirements.add('treemanifest') |
|
2327 | requirements.add('treemanifest') | |
2331 |
|
2328 | |||
2332 | revlogv2 = ui.config('experimental', 'revlogv2') |
|
2329 | revlogv2 = ui.config('experimental', 'revlogv2') | |
2333 | if revlogv2 == 'enable-unstable-format-and-corrupt-my-data': |
|
2330 | if revlogv2 == 'enable-unstable-format-and-corrupt-my-data': | |
2334 | requirements.remove('revlogv1') |
|
2331 | requirements.remove('revlogv1') | |
2335 | # generaldelta is implied by revlogv2. |
|
2332 | # generaldelta is implied by revlogv2. | |
2336 | requirements.discard('generaldelta') |
|
2333 | requirements.discard('generaldelta') | |
2337 | requirements.add(REVLOGV2_REQUIREMENT) |
|
2334 | requirements.add(REVLOGV2_REQUIREMENT) | |
2338 |
|
2335 | |||
2339 | return requirements |
|
2336 | return requirements |
@@ -1,628 +1,622 | |||||
1 | # repository.py - Interfaces and base classes for repositories and peers. |
|
1 | # repository.py - Interfaces and base classes for repositories and peers. | |
2 | # |
|
2 | # | |
3 | # Copyright 2017 Gregory Szorc <gregory.szorc@gmail.com> |
|
3 | # Copyright 2017 Gregory Szorc <gregory.szorc@gmail.com> | |
4 | # |
|
4 | # | |
5 | # This software may be used and distributed according to the terms of the |
|
5 | # This software may be used and distributed according to the terms of the | |
6 | # GNU General Public License version 2 or any later version. |
|
6 | # GNU General Public License version 2 or any later version. | |
7 |
|
7 | |||
8 | from __future__ import absolute_import |
|
8 | from __future__ import absolute_import | |
9 |
|
9 | |||
10 | import abc |
|
10 | import abc | |
11 |
|
11 | |||
12 | from .i18n import _ |
|
12 | from .i18n import _ | |
13 | from .thirdparty.zope import ( |
|
13 | from .thirdparty.zope import ( | |
14 | interface as zi, |
|
14 | interface as zi, | |
15 | ) |
|
15 | ) | |
16 | from . import ( |
|
16 | from . import ( | |
17 | error, |
|
17 | error, | |
18 | ) |
|
18 | ) | |
19 |
|
19 | |||
20 | class _basepeer(object): |
|
20 | class _basepeer(object): | |
21 | """Represents a "connection" to a repository. |
|
21 | """Represents a "connection" to a repository. | |
22 |
|
22 | |||
23 | This is the base interface for representing a connection to a repository. |
|
23 | This is the base interface for representing a connection to a repository. | |
24 | It holds basic properties and methods applicable to all peer types. |
|
24 | It holds basic properties and methods applicable to all peer types. | |
25 |
|
25 | |||
26 | This is not a complete interface definition and should not be used |
|
26 | This is not a complete interface definition and should not be used | |
27 | outside of this module. |
|
27 | outside of this module. | |
28 | """ |
|
28 | """ | |
29 | __metaclass__ = abc.ABCMeta |
|
29 | __metaclass__ = abc.ABCMeta | |
30 |
|
30 | |||
31 | @abc.abstractproperty |
|
31 | @abc.abstractproperty | |
32 | def ui(self): |
|
32 | def ui(self): | |
33 | """ui.ui instance.""" |
|
33 | """ui.ui instance.""" | |
34 |
|
34 | |||
35 | @abc.abstractmethod |
|
35 | @abc.abstractmethod | |
36 | def url(self): |
|
36 | def url(self): | |
37 | """Returns a URL string representing this peer. |
|
37 | """Returns a URL string representing this peer. | |
38 |
|
38 | |||
39 | Currently, implementations expose the raw URL used to construct the |
|
39 | Currently, implementations expose the raw URL used to construct the | |
40 | instance. It may contain credentials as part of the URL. The |
|
40 | instance. It may contain credentials as part of the URL. The | |
41 | expectations of the value aren't well-defined and this could lead to |
|
41 | expectations of the value aren't well-defined and this could lead to | |
42 | data leakage. |
|
42 | data leakage. | |
43 |
|
43 | |||
44 | TODO audit/clean consumers and more clearly define the contents of this |
|
44 | TODO audit/clean consumers and more clearly define the contents of this | |
45 | value. |
|
45 | value. | |
46 | """ |
|
46 | """ | |
47 |
|
47 | |||
48 | @abc.abstractmethod |
|
48 | @abc.abstractmethod | |
49 | def local(self): |
|
49 | def local(self): | |
50 | """Returns a local repository instance. |
|
50 | """Returns a local repository instance. | |
51 |
|
51 | |||
52 | If the peer represents a local repository, returns an object that |
|
52 | If the peer represents a local repository, returns an object that | |
53 | can be used to interface with it. Otherwise returns ``None``. |
|
53 | can be used to interface with it. Otherwise returns ``None``. | |
54 | """ |
|
54 | """ | |
55 |
|
55 | |||
56 | @abc.abstractmethod |
|
56 | @abc.abstractmethod | |
57 | def peer(self): |
|
57 | def peer(self): | |
58 | """Returns an object conforming to this interface. |
|
58 | """Returns an object conforming to this interface. | |
59 |
|
59 | |||
60 | Most implementations will ``return self``. |
|
60 | Most implementations will ``return self``. | |
61 | """ |
|
61 | """ | |
62 |
|
62 | |||
63 | @abc.abstractmethod |
|
63 | @abc.abstractmethod | |
64 | def canpush(self): |
|
64 | def canpush(self): | |
65 | """Returns a boolean indicating if this peer can be pushed to.""" |
|
65 | """Returns a boolean indicating if this peer can be pushed to.""" | |
66 |
|
66 | |||
67 | @abc.abstractmethod |
|
67 | @abc.abstractmethod | |
68 | def close(self): |
|
68 | def close(self): | |
69 | """Close the connection to this peer. |
|
69 | """Close the connection to this peer. | |
70 |
|
70 | |||
71 | This is called when the peer will no longer be used. Resources |
|
71 | This is called when the peer will no longer be used. Resources | |
72 | associated with the peer should be cleaned up. |
|
72 | associated with the peer should be cleaned up. | |
73 | """ |
|
73 | """ | |
74 |
|
74 | |||
75 | class _basewirecommands(object): |
|
75 | class _basewirecommands(object): | |
76 | """Client-side interface for communicating over the wire protocol. |
|
76 | """Client-side interface for communicating over the wire protocol. | |
77 |
|
77 | |||
78 | This interface is used as a gateway to the Mercurial wire protocol. |
|
78 | This interface is used as a gateway to the Mercurial wire protocol. | |
79 | methods commonly call wire protocol commands of the same name. |
|
79 | methods commonly call wire protocol commands of the same name. | |
80 | """ |
|
80 | """ | |
81 | __metaclass__ = abc.ABCMeta |
|
81 | __metaclass__ = abc.ABCMeta | |
82 |
|
82 | |||
83 | @abc.abstractmethod |
|
83 | @abc.abstractmethod | |
84 | def branchmap(self): |
|
84 | def branchmap(self): | |
85 | """Obtain heads in named branches. |
|
85 | """Obtain heads in named branches. | |
86 |
|
86 | |||
87 | Returns a dict mapping branch name to an iterable of nodes that are |
|
87 | Returns a dict mapping branch name to an iterable of nodes that are | |
88 | heads on that branch. |
|
88 | heads on that branch. | |
89 | """ |
|
89 | """ | |
90 |
|
90 | |||
91 | @abc.abstractmethod |
|
91 | @abc.abstractmethod | |
92 | def capabilities(self): |
|
92 | def capabilities(self): | |
93 | """Obtain capabilities of the peer. |
|
93 | """Obtain capabilities of the peer. | |
94 |
|
94 | |||
95 | Returns a set of string capabilities. |
|
95 | Returns a set of string capabilities. | |
96 | """ |
|
96 | """ | |
97 |
|
97 | |||
98 | @abc.abstractmethod |
|
98 | @abc.abstractmethod | |
99 | def debugwireargs(self, one, two, three=None, four=None, five=None): |
|
99 | def debugwireargs(self, one, two, three=None, four=None, five=None): | |
100 | """Used to facilitate debugging of arguments passed over the wire.""" |
|
100 | """Used to facilitate debugging of arguments passed over the wire.""" | |
101 |
|
101 | |||
102 | @abc.abstractmethod |
|
102 | @abc.abstractmethod | |
103 | def getbundle(self, source, **kwargs): |
|
103 | def getbundle(self, source, **kwargs): | |
104 | """Obtain remote repository data as a bundle. |
|
104 | """Obtain remote repository data as a bundle. | |
105 |
|
105 | |||
106 | This command is how the bulk of repository data is transferred from |
|
106 | This command is how the bulk of repository data is transferred from | |
107 | the peer to the local repository |
|
107 | the peer to the local repository | |
108 |
|
108 | |||
109 | Returns a generator of bundle data. |
|
109 | Returns a generator of bundle data. | |
110 | """ |
|
110 | """ | |
111 |
|
111 | |||
112 | @abc.abstractmethod |
|
112 | @abc.abstractmethod | |
113 | def heads(self): |
|
113 | def heads(self): | |
114 | """Determine all known head revisions in the peer. |
|
114 | """Determine all known head revisions in the peer. | |
115 |
|
115 | |||
116 | Returns an iterable of binary nodes. |
|
116 | Returns an iterable of binary nodes. | |
117 | """ |
|
117 | """ | |
118 |
|
118 | |||
119 | @abc.abstractmethod |
|
119 | @abc.abstractmethod | |
120 | def known(self, nodes): |
|
120 | def known(self, nodes): | |
121 | """Determine whether multiple nodes are known. |
|
121 | """Determine whether multiple nodes are known. | |
122 |
|
122 | |||
123 | Accepts an iterable of nodes whose presence to check for. |
|
123 | Accepts an iterable of nodes whose presence to check for. | |
124 |
|
124 | |||
125 | Returns an iterable of booleans indicating of the corresponding node |
|
125 | Returns an iterable of booleans indicating of the corresponding node | |
126 | at that index is known to the peer. |
|
126 | at that index is known to the peer. | |
127 | """ |
|
127 | """ | |
128 |
|
128 | |||
129 | @abc.abstractmethod |
|
129 | @abc.abstractmethod | |
130 | def listkeys(self, namespace): |
|
130 | def listkeys(self, namespace): | |
131 | """Obtain all keys in a pushkey namespace. |
|
131 | """Obtain all keys in a pushkey namespace. | |
132 |
|
132 | |||
133 | Returns an iterable of key names. |
|
133 | Returns an iterable of key names. | |
134 | """ |
|
134 | """ | |
135 |
|
135 | |||
136 | @abc.abstractmethod |
|
136 | @abc.abstractmethod | |
137 | def lookup(self, key): |
|
137 | def lookup(self, key): | |
138 | """Resolve a value to a known revision. |
|
138 | """Resolve a value to a known revision. | |
139 |
|
139 | |||
140 | Returns a binary node of the resolved revision on success. |
|
140 | Returns a binary node of the resolved revision on success. | |
141 | """ |
|
141 | """ | |
142 |
|
142 | |||
143 | @abc.abstractmethod |
|
143 | @abc.abstractmethod | |
144 | def pushkey(self, namespace, key, old, new): |
|
144 | def pushkey(self, namespace, key, old, new): | |
145 | """Set a value using the ``pushkey`` protocol. |
|
145 | """Set a value using the ``pushkey`` protocol. | |
146 |
|
146 | |||
147 | Arguments correspond to the pushkey namespace and key to operate on and |
|
147 | Arguments correspond to the pushkey namespace and key to operate on and | |
148 | the old and new values for that key. |
|
148 | the old and new values for that key. | |
149 |
|
149 | |||
150 | Returns a string with the peer result. The value inside varies by the |
|
150 | Returns a string with the peer result. The value inside varies by the | |
151 | namespace. |
|
151 | namespace. | |
152 | """ |
|
152 | """ | |
153 |
|
153 | |||
154 | @abc.abstractmethod |
|
154 | @abc.abstractmethod | |
155 | def stream_out(self): |
|
155 | def stream_out(self): | |
156 | """Obtain streaming clone data. |
|
156 | """Obtain streaming clone data. | |
157 |
|
157 | |||
158 | Successful result should be a generator of data chunks. |
|
158 | Successful result should be a generator of data chunks. | |
159 | """ |
|
159 | """ | |
160 |
|
160 | |||
161 | @abc.abstractmethod |
|
161 | @abc.abstractmethod | |
162 | def unbundle(self, bundle, heads, url): |
|
162 | def unbundle(self, bundle, heads, url): | |
163 | """Transfer repository data to the peer. |
|
163 | """Transfer repository data to the peer. | |
164 |
|
164 | |||
165 | This is how the bulk of data during a push is transferred. |
|
165 | This is how the bulk of data during a push is transferred. | |
166 |
|
166 | |||
167 | Returns the integer number of heads added to the peer. |
|
167 | Returns the integer number of heads added to the peer. | |
168 | """ |
|
168 | """ | |
169 |
|
169 | |||
170 | class _baselegacywirecommands(object): |
|
170 | class _baselegacywirecommands(object): | |
171 | """Interface for implementing support for legacy wire protocol commands. |
|
171 | """Interface for implementing support for legacy wire protocol commands. | |
172 |
|
172 | |||
173 | Wire protocol commands transition to legacy status when they are no longer |
|
173 | Wire protocol commands transition to legacy status when they are no longer | |
174 | used by modern clients. To facilitate identifying which commands are |
|
174 | used by modern clients. To facilitate identifying which commands are | |
175 | legacy, the interfaces are split. |
|
175 | legacy, the interfaces are split. | |
176 | """ |
|
176 | """ | |
177 | __metaclass__ = abc.ABCMeta |
|
177 | __metaclass__ = abc.ABCMeta | |
178 |
|
178 | |||
179 | @abc.abstractmethod |
|
179 | @abc.abstractmethod | |
180 | def between(self, pairs): |
|
180 | def between(self, pairs): | |
181 | """Obtain nodes between pairs of nodes. |
|
181 | """Obtain nodes between pairs of nodes. | |
182 |
|
182 | |||
183 | ``pairs`` is an iterable of node pairs. |
|
183 | ``pairs`` is an iterable of node pairs. | |
184 |
|
184 | |||
185 | Returns an iterable of iterables of nodes corresponding to each |
|
185 | Returns an iterable of iterables of nodes corresponding to each | |
186 | requested pair. |
|
186 | requested pair. | |
187 | """ |
|
187 | """ | |
188 |
|
188 | |||
189 | @abc.abstractmethod |
|
189 | @abc.abstractmethod | |
190 | def branches(self, nodes): |
|
190 | def branches(self, nodes): | |
191 | """Obtain ancestor changesets of specific nodes back to a branch point. |
|
191 | """Obtain ancestor changesets of specific nodes back to a branch point. | |
192 |
|
192 | |||
193 | For each requested node, the peer finds the first ancestor node that is |
|
193 | For each requested node, the peer finds the first ancestor node that is | |
194 | a DAG root or is a merge. |
|
194 | a DAG root or is a merge. | |
195 |
|
195 | |||
196 | Returns an iterable of iterables with the resolved values for each node. |
|
196 | Returns an iterable of iterables with the resolved values for each node. | |
197 | """ |
|
197 | """ | |
198 |
|
198 | |||
199 | @abc.abstractmethod |
|
199 | @abc.abstractmethod | |
200 | def changegroup(self, nodes, kind): |
|
200 | def changegroup(self, nodes, kind): | |
201 | """Obtain a changegroup with data for descendants of specified nodes.""" |
|
201 | """Obtain a changegroup with data for descendants of specified nodes.""" | |
202 |
|
202 | |||
203 | @abc.abstractmethod |
|
203 | @abc.abstractmethod | |
204 | def changegroupsubset(self, bases, heads, kind): |
|
204 | def changegroupsubset(self, bases, heads, kind): | |
205 | pass |
|
205 | pass | |
206 |
|
206 | |||
207 | class peer(_basepeer, _basewirecommands): |
|
207 | class peer(_basepeer, _basewirecommands): | |
208 | """Unified interface and base class for peer repositories. |
|
208 | """Unified interface and base class for peer repositories. | |
209 |
|
209 | |||
210 | All peer instances must inherit from this class and conform to its |
|
210 | All peer instances must inherit from this class and conform to its | |
211 | interface. |
|
211 | interface. | |
212 | """ |
|
212 | """ | |
213 |
|
213 | |||
214 | @abc.abstractmethod |
|
214 | @abc.abstractmethod | |
215 | def iterbatch(self): |
|
215 | def iterbatch(self): | |
216 | """Obtain an object to be used for multiple method calls. |
|
216 | """Obtain an object to be used for multiple method calls. | |
217 |
|
217 | |||
218 | Various operations call several methods on peer instances. If each |
|
218 | Various operations call several methods on peer instances. If each | |
219 | method call were performed immediately and serially, this would |
|
219 | method call were performed immediately and serially, this would | |
220 | require round trips to remote peers and/or would slow down execution. |
|
220 | require round trips to remote peers and/or would slow down execution. | |
221 |
|
221 | |||
222 | Some peers have the ability to "batch" method calls to avoid costly |
|
222 | Some peers have the ability to "batch" method calls to avoid costly | |
223 | round trips or to facilitate concurrent execution. |
|
223 | round trips or to facilitate concurrent execution. | |
224 |
|
224 | |||
225 | This method returns an object that can be used to indicate intent to |
|
225 | This method returns an object that can be used to indicate intent to | |
226 | perform batched method calls. |
|
226 | perform batched method calls. | |
227 |
|
227 | |||
228 | The returned object is a proxy of this peer. It intercepts calls to |
|
228 | The returned object is a proxy of this peer. It intercepts calls to | |
229 | batchable methods and queues them instead of performing them |
|
229 | batchable methods and queues them instead of performing them | |
230 | immediately. This proxy object has a ``submit`` method that will |
|
230 | immediately. This proxy object has a ``submit`` method that will | |
231 | perform all queued batchable method calls. A ``results()`` method |
|
231 | perform all queued batchable method calls. A ``results()`` method | |
232 | exposes the results of queued/batched method calls. It is a generator |
|
232 | exposes the results of queued/batched method calls. It is a generator | |
233 | of results in the order they were called. |
|
233 | of results in the order they were called. | |
234 |
|
234 | |||
235 | Not all peers or wire protocol implementations may actually batch method |
|
235 | Not all peers or wire protocol implementations may actually batch method | |
236 | calls. However, they must all support this API. |
|
236 | calls. However, they must all support this API. | |
237 | """ |
|
237 | """ | |
238 |
|
238 | |||
239 | def capable(self, name): |
|
239 | def capable(self, name): | |
240 | """Determine support for a named capability. |
|
240 | """Determine support for a named capability. | |
241 |
|
241 | |||
242 | Returns ``False`` if capability not supported. |
|
242 | Returns ``False`` if capability not supported. | |
243 |
|
243 | |||
244 | Returns ``True`` if boolean capability is supported. Returns a string |
|
244 | Returns ``True`` if boolean capability is supported. Returns a string | |
245 | if capability support is non-boolean. |
|
245 | if capability support is non-boolean. | |
246 | """ |
|
246 | """ | |
247 | caps = self.capabilities() |
|
247 | caps = self.capabilities() | |
248 | if name in caps: |
|
248 | if name in caps: | |
249 | return True |
|
249 | return True | |
250 |
|
250 | |||
251 | name = '%s=' % name |
|
251 | name = '%s=' % name | |
252 | for cap in caps: |
|
252 | for cap in caps: | |
253 | if cap.startswith(name): |
|
253 | if cap.startswith(name): | |
254 | return cap[len(name):] |
|
254 | return cap[len(name):] | |
255 |
|
255 | |||
256 | return False |
|
256 | return False | |
257 |
|
257 | |||
258 | def requirecap(self, name, purpose): |
|
258 | def requirecap(self, name, purpose): | |
259 | """Require a capability to be present. |
|
259 | """Require a capability to be present. | |
260 |
|
260 | |||
261 | Raises a ``CapabilityError`` if the capability isn't present. |
|
261 | Raises a ``CapabilityError`` if the capability isn't present. | |
262 | """ |
|
262 | """ | |
263 | if self.capable(name): |
|
263 | if self.capable(name): | |
264 | return |
|
264 | return | |
265 |
|
265 | |||
266 | raise error.CapabilityError( |
|
266 | raise error.CapabilityError( | |
267 | _('cannot %s; remote repository does not support the %r ' |
|
267 | _('cannot %s; remote repository does not support the %r ' | |
268 | 'capability') % (purpose, name)) |
|
268 | 'capability') % (purpose, name)) | |
269 |
|
269 | |||
270 | class legacypeer(peer, _baselegacywirecommands): |
|
270 | class legacypeer(peer, _baselegacywirecommands): | |
271 | """peer but with support for legacy wire protocol commands.""" |
|
271 | """peer but with support for legacy wire protocol commands.""" | |
272 |
|
272 | |||
273 | class completelocalrepository(zi.Interface): |
|
273 | class completelocalrepository(zi.Interface): | |
274 | """Monolithic interface for local repositories. |
|
274 | """Monolithic interface for local repositories. | |
275 |
|
275 | |||
276 | This currently captures the reality of things - not how things should be. |
|
276 | This currently captures the reality of things - not how things should be. | |
277 | """ |
|
277 | """ | |
278 |
|
278 | |||
279 | supportedformats = zi.Attribute( |
|
279 | supportedformats = zi.Attribute( | |
280 | """Set of requirements that apply to stream clone. |
|
280 | """Set of requirements that apply to stream clone. | |
281 |
|
281 | |||
282 | This is actually a class attribute and is shared among all instances. |
|
282 | This is actually a class attribute and is shared among all instances. | |
283 | """) |
|
283 | """) | |
284 |
|
284 | |||
285 | openerreqs = zi.Attribute( |
|
285 | openerreqs = zi.Attribute( | |
286 | """Set of requirements that are passed to the opener. |
|
286 | """Set of requirements that are passed to the opener. | |
287 |
|
287 | |||
288 | This is actually a class attribute and is shared among all instances. |
|
288 | This is actually a class attribute and is shared among all instances. | |
289 | """) |
|
289 | """) | |
290 |
|
290 | |||
291 | supported = zi.Attribute( |
|
291 | supported = zi.Attribute( | |
292 | """Set of requirements that this repo is capable of opening.""") |
|
292 | """Set of requirements that this repo is capable of opening.""") | |
293 |
|
293 | |||
294 | requirements = zi.Attribute( |
|
294 | requirements = zi.Attribute( | |
295 | """Set of requirements this repo uses.""") |
|
295 | """Set of requirements this repo uses.""") | |
296 |
|
296 | |||
297 | filtername = zi.Attribute( |
|
297 | filtername = zi.Attribute( | |
298 | """Name of the repoview that is active on this repo.""") |
|
298 | """Name of the repoview that is active on this repo.""") | |
299 |
|
299 | |||
300 | wvfs = zi.Attribute( |
|
300 | wvfs = zi.Attribute( | |
301 | """VFS used to access the working directory.""") |
|
301 | """VFS used to access the working directory.""") | |
302 |
|
302 | |||
303 | vfs = zi.Attribute( |
|
303 | vfs = zi.Attribute( | |
304 | """VFS rooted at the .hg directory. |
|
304 | """VFS rooted at the .hg directory. | |
305 |
|
305 | |||
306 | Used to access repository data not in the store. |
|
306 | Used to access repository data not in the store. | |
307 | """) |
|
307 | """) | |
308 |
|
308 | |||
309 | svfs = zi.Attribute( |
|
309 | svfs = zi.Attribute( | |
310 | """VFS rooted at the store. |
|
310 | """VFS rooted at the store. | |
311 |
|
311 | |||
312 | Used to access repository data in the store. Typically .hg/store. |
|
312 | Used to access repository data in the store. Typically .hg/store. | |
313 | But can point elsewhere if the store is shared. |
|
313 | But can point elsewhere if the store is shared. | |
314 | """) |
|
314 | """) | |
315 |
|
315 | |||
316 | root = zi.Attribute( |
|
316 | root = zi.Attribute( | |
317 | """Path to the root of the working directory.""") |
|
317 | """Path to the root of the working directory.""") | |
318 |
|
318 | |||
319 | path = zi.Attribute( |
|
319 | path = zi.Attribute( | |
320 | """Path to the .hg directory.""") |
|
320 | """Path to the .hg directory.""") | |
321 |
|
321 | |||
322 | origroot = zi.Attribute( |
|
322 | origroot = zi.Attribute( | |
323 | """The filesystem path that was used to construct the repo.""") |
|
323 | """The filesystem path that was used to construct the repo.""") | |
324 |
|
324 | |||
325 | auditor = zi.Attribute( |
|
325 | auditor = zi.Attribute( | |
326 | """A pathauditor for the working directory. |
|
326 | """A pathauditor for the working directory. | |
327 |
|
327 | |||
328 | This checks if a path refers to a nested repository. |
|
328 | This checks if a path refers to a nested repository. | |
329 |
|
329 | |||
330 | Operates on the filesystem. |
|
330 | Operates on the filesystem. | |
331 | """) |
|
331 | """) | |
332 |
|
332 | |||
333 | nofsauditor = zi.Attribute( |
|
333 | nofsauditor = zi.Attribute( | |
334 | """A pathauditor for the working directory. |
|
334 | """A pathauditor for the working directory. | |
335 |
|
335 | |||
336 | This is like ``auditor`` except it doesn't do filesystem checks. |
|
336 | This is like ``auditor`` except it doesn't do filesystem checks. | |
337 | """) |
|
337 | """) | |
338 |
|
338 | |||
339 | baseui = zi.Attribute( |
|
339 | baseui = zi.Attribute( | |
340 | """Original ui instance passed into constructor.""") |
|
340 | """Original ui instance passed into constructor.""") | |
341 |
|
341 | |||
342 | ui = zi.Attribute( |
|
342 | ui = zi.Attribute( | |
343 | """Main ui instance for this instance.""") |
|
343 | """Main ui instance for this instance.""") | |
344 |
|
344 | |||
345 | sharedpath = zi.Attribute( |
|
345 | sharedpath = zi.Attribute( | |
346 | """Path to the .hg directory of the repo this repo was shared from.""") |
|
346 | """Path to the .hg directory of the repo this repo was shared from.""") | |
347 |
|
347 | |||
348 | store = zi.Attribute( |
|
348 | store = zi.Attribute( | |
349 | """A store instance.""") |
|
349 | """A store instance.""") | |
350 |
|
350 | |||
351 | spath = zi.Attribute( |
|
351 | spath = zi.Attribute( | |
352 | """Path to the store.""") |
|
352 | """Path to the store.""") | |
353 |
|
353 | |||
354 | sjoin = zi.Attribute( |
|
354 | sjoin = zi.Attribute( | |
355 | """Alias to self.store.join.""") |
|
355 | """Alias to self.store.join.""") | |
356 |
|
356 | |||
357 | cachevfs = zi.Attribute( |
|
357 | cachevfs = zi.Attribute( | |
358 | """A VFS used to access the cache directory. |
|
358 | """A VFS used to access the cache directory. | |
359 |
|
359 | |||
360 | Typically .hg/cache. |
|
360 | Typically .hg/cache. | |
361 | """) |
|
361 | """) | |
362 |
|
362 | |||
363 | filteredrevcache = zi.Attribute( |
|
363 | filteredrevcache = zi.Attribute( | |
364 | """Holds sets of revisions to be filtered.""") |
|
364 | """Holds sets of revisions to be filtered.""") | |
365 |
|
365 | |||
366 | names = zi.Attribute( |
|
366 | names = zi.Attribute( | |
367 | """A ``namespaces`` instance.""") |
|
367 | """A ``namespaces`` instance.""") | |
368 |
|
368 | |||
369 | def close(): |
|
369 | def close(): | |
370 | """Close the handle on this repository.""" |
|
370 | """Close the handle on this repository.""" | |
371 |
|
371 | |||
372 | def peer(): |
|
372 | def peer(): | |
373 | """Obtain an object conforming to the ``peer`` interface.""" |
|
373 | """Obtain an object conforming to the ``peer`` interface.""" | |
374 |
|
374 | |||
375 | def unfiltered(): |
|
375 | def unfiltered(): | |
376 | """Obtain an unfiltered/raw view of this repo.""" |
|
376 | """Obtain an unfiltered/raw view of this repo.""" | |
377 |
|
377 | |||
378 | def filtered(name, visibilityexceptions=None): |
|
378 | def filtered(name, visibilityexceptions=None): | |
379 | """Obtain a named view of this repository.""" |
|
379 | """Obtain a named view of this repository.""" | |
380 |
|
380 | |||
381 | obsstore = zi.Attribute( |
|
381 | obsstore = zi.Attribute( | |
382 | """A store of obsolescence data.""") |
|
382 | """A store of obsolescence data.""") | |
383 |
|
383 | |||
384 | changelog = zi.Attribute( |
|
384 | changelog = zi.Attribute( | |
385 | """A handle on the changelog revlog.""") |
|
385 | """A handle on the changelog revlog.""") | |
386 |
|
386 | |||
387 | manifestlog = zi.Attribute( |
|
387 | manifestlog = zi.Attribute( | |
388 | """A handle on the root manifest revlog.""") |
|
388 | """A handle on the root manifest revlog.""") | |
389 |
|
389 | |||
390 | dirstate = zi.Attribute( |
|
390 | dirstate = zi.Attribute( | |
391 | """Working directory state.""") |
|
391 | """Working directory state.""") | |
392 |
|
392 | |||
393 | narrowpats = zi.Attribute( |
|
393 | narrowpats = zi.Attribute( | |
394 | """Matcher patterns for this repository's narrowspec.""") |
|
394 | """Matcher patterns for this repository's narrowspec.""") | |
395 |
|
395 | |||
396 | def narrowmatch(): |
|
396 | def narrowmatch(): | |
397 | """Obtain a matcher for the narrowspec.""" |
|
397 | """Obtain a matcher for the narrowspec.""" | |
398 |
|
398 | |||
399 | def setnarrowpats(newincludes, newexcludes): |
|
399 | def setnarrowpats(newincludes, newexcludes): | |
400 | """Define the narrowspec for this repository.""" |
|
400 | """Define the narrowspec for this repository.""" | |
401 |
|
401 | |||
402 | def __getitem__(changeid): |
|
402 | def __getitem__(changeid): | |
403 | """Try to resolve a changectx.""" |
|
403 | """Try to resolve a changectx.""" | |
404 |
|
404 | |||
405 | def __contains__(changeid): |
|
405 | def __contains__(changeid): | |
406 | """Whether a changeset exists.""" |
|
406 | """Whether a changeset exists.""" | |
407 |
|
407 | |||
408 | def __nonzero__(): |
|
408 | def __nonzero__(): | |
409 | """Always returns True.""" |
|
409 | """Always returns True.""" | |
410 | return True |
|
410 | return True | |
411 |
|
411 | |||
412 | __bool__ = __nonzero__ |
|
412 | __bool__ = __nonzero__ | |
413 |
|
413 | |||
414 | def __len__(): |
|
414 | def __len__(): | |
415 | """Returns the number of changesets in the repo.""" |
|
415 | """Returns the number of changesets in the repo.""" | |
416 |
|
416 | |||
417 | def __iter__(): |
|
417 | def __iter__(): | |
418 | """Iterate over revisions in the changelog.""" |
|
418 | """Iterate over revisions in the changelog.""" | |
419 |
|
419 | |||
420 | def revs(expr, *args): |
|
420 | def revs(expr, *args): | |
421 | """Evaluate a revset. |
|
421 | """Evaluate a revset. | |
422 |
|
422 | |||
423 | Emits revisions. |
|
423 | Emits revisions. | |
424 | """ |
|
424 | """ | |
425 |
|
425 | |||
426 | def set(expr, *args): |
|
426 | def set(expr, *args): | |
427 | """Evaluate a revset. |
|
427 | """Evaluate a revset. | |
428 |
|
428 | |||
429 | Emits changectx instances. |
|
429 | Emits changectx instances. | |
430 | """ |
|
430 | """ | |
431 |
|
431 | |||
432 | def anyrevs(specs, user=False, localalias=None): |
|
432 | def anyrevs(specs, user=False, localalias=None): | |
433 | """Find revisions matching one of the given revsets.""" |
|
433 | """Find revisions matching one of the given revsets.""" | |
434 |
|
434 | |||
435 | def url(): |
|
435 | def url(): | |
436 | """Returns a string representing the location of this repo.""" |
|
436 | """Returns a string representing the location of this repo.""" | |
437 |
|
437 | |||
438 | def hook(name, throw=False, **args): |
|
438 | def hook(name, throw=False, **args): | |
439 | """Call a hook.""" |
|
439 | """Call a hook.""" | |
440 |
|
440 | |||
441 | def tags(): |
|
441 | def tags(): | |
442 | """Return a mapping of tag to node.""" |
|
442 | """Return a mapping of tag to node.""" | |
443 |
|
443 | |||
444 | def tagtype(tagname): |
|
444 | def tagtype(tagname): | |
445 | """Return the type of a given tag.""" |
|
445 | """Return the type of a given tag.""" | |
446 |
|
446 | |||
447 | def tagslist(): |
|
447 | def tagslist(): | |
448 | """Return a list of tags ordered by revision.""" |
|
448 | """Return a list of tags ordered by revision.""" | |
449 |
|
449 | |||
450 | def nodetags(node): |
|
450 | def nodetags(node): | |
451 | """Return the tags associated with a node.""" |
|
451 | """Return the tags associated with a node.""" | |
452 |
|
452 | |||
453 | def nodebookmarks(node): |
|
453 | def nodebookmarks(node): | |
454 | """Return the list of bookmarks pointing to the specified node.""" |
|
454 | """Return the list of bookmarks pointing to the specified node.""" | |
455 |
|
455 | |||
456 | def branchmap(): |
|
456 | def branchmap(): | |
457 | """Return a mapping of branch to heads in that branch.""" |
|
457 | """Return a mapping of branch to heads in that branch.""" | |
458 |
|
458 | |||
459 | def revbranchcache(): |
|
459 | def revbranchcache(): | |
460 | pass |
|
460 | pass | |
461 |
|
461 | |||
462 | def branchtip(branchtip, ignoremissing=False): |
|
462 | def branchtip(branchtip, ignoremissing=False): | |
463 | """Return the tip node for a given branch.""" |
|
463 | """Return the tip node for a given branch.""" | |
464 |
|
464 | |||
465 | def lookup(key): |
|
465 | def lookup(key): | |
466 | """Resolve the node for a revision.""" |
|
466 | """Resolve the node for a revision.""" | |
467 |
|
467 | |||
468 | def lookupbranch(key, remote=None): |
|
468 | def lookupbranch(key, remote=None): | |
469 | """Look up the branch name of the given revision or branch name.""" |
|
469 | """Look up the branch name of the given revision or branch name.""" | |
470 |
|
470 | |||
471 | def known(nodes): |
|
471 | def known(nodes): | |
472 | """Determine whether a series of nodes is known. |
|
472 | """Determine whether a series of nodes is known. | |
473 |
|
473 | |||
474 | Returns a list of bools. |
|
474 | Returns a list of bools. | |
475 | """ |
|
475 | """ | |
476 |
|
476 | |||
477 | def local(): |
|
477 | def local(): | |
478 | """Whether the repository is local.""" |
|
478 | """Whether the repository is local.""" | |
479 | return True |
|
479 | return True | |
480 |
|
480 | |||
481 | def publishing(): |
|
481 | def publishing(): | |
482 | """Whether the repository is a publishing repository.""" |
|
482 | """Whether the repository is a publishing repository.""" | |
483 |
|
483 | |||
484 | def cancopy(): |
|
484 | def cancopy(): | |
485 | pass |
|
485 | pass | |
486 |
|
486 | |||
487 | def shared(): |
|
487 | def shared(): | |
488 | """The type of shared repository or None.""" |
|
488 | """The type of shared repository or None.""" | |
489 |
|
489 | |||
490 | def wjoin(f, *insidef): |
|
490 | def wjoin(f, *insidef): | |
491 | """Calls self.vfs.reljoin(self.root, f, *insidef)""" |
|
491 | """Calls self.vfs.reljoin(self.root, f, *insidef)""" | |
492 |
|
492 | |||
493 | def file(f): |
|
493 | def file(f): | |
494 | """Obtain a filelog for a tracked path.""" |
|
494 | """Obtain a filelog for a tracked path.""" | |
495 |
|
495 | |||
496 | def changectx(changeid): |
|
|||
497 | """Obtains a changectx for a revision. |
|
|||
498 |
|
||||
499 | Identical to __getitem__. |
|
|||
500 | """ |
|
|||
501 |
|
||||
502 | def setparents(p1, p2): |
|
496 | def setparents(p1, p2): | |
503 | """Set the parent nodes of the working directory.""" |
|
497 | """Set the parent nodes of the working directory.""" | |
504 |
|
498 | |||
505 | def filectx(path, changeid=None, fileid=None): |
|
499 | def filectx(path, changeid=None, fileid=None): | |
506 | """Obtain a filectx for the given file revision.""" |
|
500 | """Obtain a filectx for the given file revision.""" | |
507 |
|
501 | |||
508 | def getcwd(): |
|
502 | def getcwd(): | |
509 | """Obtain the current working directory from the dirstate.""" |
|
503 | """Obtain the current working directory from the dirstate.""" | |
510 |
|
504 | |||
511 | def pathto(f, cwd=None): |
|
505 | def pathto(f, cwd=None): | |
512 | """Obtain the relative path to a file.""" |
|
506 | """Obtain the relative path to a file.""" | |
513 |
|
507 | |||
514 | def adddatafilter(name, fltr): |
|
508 | def adddatafilter(name, fltr): | |
515 | pass |
|
509 | pass | |
516 |
|
510 | |||
517 | def wread(filename): |
|
511 | def wread(filename): | |
518 | """Read a file from wvfs, using data filters.""" |
|
512 | """Read a file from wvfs, using data filters.""" | |
519 |
|
513 | |||
520 | def wwrite(filename, data, flags, backgroundclose=False, **kwargs): |
|
514 | def wwrite(filename, data, flags, backgroundclose=False, **kwargs): | |
521 | """Write data to a file in the wvfs, using data filters.""" |
|
515 | """Write data to a file in the wvfs, using data filters.""" | |
522 |
|
516 | |||
523 | def wwritedata(filename, data): |
|
517 | def wwritedata(filename, data): | |
524 | """Resolve data for writing to the wvfs, using data filters.""" |
|
518 | """Resolve data for writing to the wvfs, using data filters.""" | |
525 |
|
519 | |||
526 | def currenttransaction(): |
|
520 | def currenttransaction(): | |
527 | """Obtain the current transaction instance or None.""" |
|
521 | """Obtain the current transaction instance or None.""" | |
528 |
|
522 | |||
529 | def transaction(desc, report=None): |
|
523 | def transaction(desc, report=None): | |
530 | """Open a new transaction to write to the repository.""" |
|
524 | """Open a new transaction to write to the repository.""" | |
531 |
|
525 | |||
532 | def undofiles(): |
|
526 | def undofiles(): | |
533 | """Returns a list of (vfs, path) for files to undo transactions.""" |
|
527 | """Returns a list of (vfs, path) for files to undo transactions.""" | |
534 |
|
528 | |||
535 | def recover(): |
|
529 | def recover(): | |
536 | """Roll back an interrupted transaction.""" |
|
530 | """Roll back an interrupted transaction.""" | |
537 |
|
531 | |||
538 | def rollback(dryrun=False, force=False): |
|
532 | def rollback(dryrun=False, force=False): | |
539 | """Undo the last transaction. |
|
533 | """Undo the last transaction. | |
540 |
|
534 | |||
541 | DANGEROUS. |
|
535 | DANGEROUS. | |
542 | """ |
|
536 | """ | |
543 |
|
537 | |||
544 | def updatecaches(tr=None, full=False): |
|
538 | def updatecaches(tr=None, full=False): | |
545 | """Warm repo caches.""" |
|
539 | """Warm repo caches.""" | |
546 |
|
540 | |||
547 | def invalidatecaches(): |
|
541 | def invalidatecaches(): | |
548 | """Invalidate cached data due to the repository mutating.""" |
|
542 | """Invalidate cached data due to the repository mutating.""" | |
549 |
|
543 | |||
550 | def invalidatevolatilesets(): |
|
544 | def invalidatevolatilesets(): | |
551 | pass |
|
545 | pass | |
552 |
|
546 | |||
553 | def invalidatedirstate(): |
|
547 | def invalidatedirstate(): | |
554 | """Invalidate the dirstate.""" |
|
548 | """Invalidate the dirstate.""" | |
555 |
|
549 | |||
556 | def invalidate(clearfilecache=False): |
|
550 | def invalidate(clearfilecache=False): | |
557 | pass |
|
551 | pass | |
558 |
|
552 | |||
559 | def invalidateall(): |
|
553 | def invalidateall(): | |
560 | pass |
|
554 | pass | |
561 |
|
555 | |||
562 | def lock(wait=True): |
|
556 | def lock(wait=True): | |
563 | """Lock the repository store and return a lock instance.""" |
|
557 | """Lock the repository store and return a lock instance.""" | |
564 |
|
558 | |||
565 | def wlock(wait=True): |
|
559 | def wlock(wait=True): | |
566 | """Lock the non-store parts of the repository.""" |
|
560 | """Lock the non-store parts of the repository.""" | |
567 |
|
561 | |||
568 | def currentwlock(): |
|
562 | def currentwlock(): | |
569 | """Return the wlock if it's held or None.""" |
|
563 | """Return the wlock if it's held or None.""" | |
570 |
|
564 | |||
571 | def checkcommitpatterns(wctx, vdirs, match, status, fail): |
|
565 | def checkcommitpatterns(wctx, vdirs, match, status, fail): | |
572 | pass |
|
566 | pass | |
573 |
|
567 | |||
574 | def commit(text='', user=None, date=None, match=None, force=False, |
|
568 | def commit(text='', user=None, date=None, match=None, force=False, | |
575 | editor=False, extra=None): |
|
569 | editor=False, extra=None): | |
576 | """Add a new revision to the repository.""" |
|
570 | """Add a new revision to the repository.""" | |
577 |
|
571 | |||
578 | def commitctx(ctx, error=False): |
|
572 | def commitctx(ctx, error=False): | |
579 | """Commit a commitctx instance to the repository.""" |
|
573 | """Commit a commitctx instance to the repository.""" | |
580 |
|
574 | |||
581 | def destroying(): |
|
575 | def destroying(): | |
582 | """Inform the repository that nodes are about to be destroyed.""" |
|
576 | """Inform the repository that nodes are about to be destroyed.""" | |
583 |
|
577 | |||
584 | def destroyed(): |
|
578 | def destroyed(): | |
585 | """Inform the repository that nodes have been destroyed.""" |
|
579 | """Inform the repository that nodes have been destroyed.""" | |
586 |
|
580 | |||
587 | def status(node1='.', node2=None, match=None, ignored=False, |
|
581 | def status(node1='.', node2=None, match=None, ignored=False, | |
588 | clean=False, unknown=False, listsubrepos=False): |
|
582 | clean=False, unknown=False, listsubrepos=False): | |
589 | """Convenience method to call repo[x].status().""" |
|
583 | """Convenience method to call repo[x].status().""" | |
590 |
|
584 | |||
591 | def addpostdsstatus(ps): |
|
585 | def addpostdsstatus(ps): | |
592 | pass |
|
586 | pass | |
593 |
|
587 | |||
594 | def postdsstatus(): |
|
588 | def postdsstatus(): | |
595 | pass |
|
589 | pass | |
596 |
|
590 | |||
597 | def clearpostdsstatus(): |
|
591 | def clearpostdsstatus(): | |
598 | pass |
|
592 | pass | |
599 |
|
593 | |||
600 | def heads(start=None): |
|
594 | def heads(start=None): | |
601 | """Obtain list of nodes that are DAG heads.""" |
|
595 | """Obtain list of nodes that are DAG heads.""" | |
602 |
|
596 | |||
603 | def branchheads(branch=None, start=None, closed=False): |
|
597 | def branchheads(branch=None, start=None, closed=False): | |
604 | pass |
|
598 | pass | |
605 |
|
599 | |||
606 | def branches(nodes): |
|
600 | def branches(nodes): | |
607 | pass |
|
601 | pass | |
608 |
|
602 | |||
609 | def between(pairs): |
|
603 | def between(pairs): | |
610 | pass |
|
604 | pass | |
611 |
|
605 | |||
612 | def checkpush(pushop): |
|
606 | def checkpush(pushop): | |
613 | pass |
|
607 | pass | |
614 |
|
608 | |||
615 | prepushoutgoinghooks = zi.Attribute( |
|
609 | prepushoutgoinghooks = zi.Attribute( | |
616 | """util.hooks instance.""") |
|
610 | """util.hooks instance.""") | |
617 |
|
611 | |||
618 | def pushkey(namespace, key, old, new): |
|
612 | def pushkey(namespace, key, old, new): | |
619 | pass |
|
613 | pass | |
620 |
|
614 | |||
621 | def listkeys(namespace): |
|
615 | def listkeys(namespace): | |
622 | pass |
|
616 | pass | |
623 |
|
617 | |||
624 | def debugwireargs(one, two, three=None, four=None, five=None): |
|
618 | def debugwireargs(one, two, three=None, four=None, five=None): | |
625 | pass |
|
619 | pass | |
626 |
|
620 | |||
627 | def savecommitmessage(text): |
|
621 | def savecommitmessage(text): | |
628 | pass |
|
622 | pass |
General Comments 0
You need to be logged in to leave comments.
Login now