##// END OF EJS Templates
localrepo: correct docstring of filectx()...
Yuya Nishihara -
r40754:5bcf264b default
parent child Browse files
Show More
@@ -1,3061 +1,3061 b''
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 sys
14 import sys
15 import time
15 import time
16 import weakref
16 import weakref
17
17
18 from .i18n import _
18 from .i18n import _
19 from .node import (
19 from .node import (
20 bin,
20 bin,
21 hex,
21 hex,
22 nullid,
22 nullid,
23 nullrev,
23 nullrev,
24 short,
24 short,
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 phases,
52 phases,
53 pushkey,
53 pushkey,
54 pycompat,
54 pycompat,
55 repository,
55 repository,
56 repoview,
56 repoview,
57 revset,
57 revset,
58 revsetlang,
58 revsetlang,
59 scmutil,
59 scmutil,
60 sparse,
60 sparse,
61 store as storemod,
61 store as storemod,
62 subrepoutil,
62 subrepoutil,
63 tags as tagsmod,
63 tags as tagsmod,
64 transaction,
64 transaction,
65 txnutil,
65 txnutil,
66 util,
66 util,
67 vfs as vfsmod,
67 vfs as vfsmod,
68 )
68 )
69 from .utils import (
69 from .utils import (
70 interfaceutil,
70 interfaceutil,
71 procutil,
71 procutil,
72 stringutil,
72 stringutil,
73 )
73 )
74
74
75 from .revlogutils import (
75 from .revlogutils import (
76 constants as revlogconst,
76 constants as revlogconst,
77 )
77 )
78
78
79 release = lockmod.release
79 release = lockmod.release
80 urlerr = util.urlerr
80 urlerr = util.urlerr
81 urlreq = util.urlreq
81 urlreq = util.urlreq
82
82
83 # set of (path, vfs-location) tuples. vfs-location is:
83 # set of (path, vfs-location) tuples. vfs-location is:
84 # - 'plain for vfs relative paths
84 # - 'plain for vfs relative paths
85 # - '' for svfs relative paths
85 # - '' for svfs relative paths
86 _cachedfiles = set()
86 _cachedfiles = set()
87
87
88 class _basefilecache(scmutil.filecache):
88 class _basefilecache(scmutil.filecache):
89 """All filecache usage on repo are done for logic that should be unfiltered
89 """All filecache usage on repo are done for logic that should be unfiltered
90 """
90 """
91 def __get__(self, repo, type=None):
91 def __get__(self, repo, type=None):
92 if repo is None:
92 if repo is None:
93 return self
93 return self
94 # proxy to unfiltered __dict__ since filtered repo has no entry
94 # proxy to unfiltered __dict__ since filtered repo has no entry
95 unfi = repo.unfiltered()
95 unfi = repo.unfiltered()
96 try:
96 try:
97 return unfi.__dict__[self.sname]
97 return unfi.__dict__[self.sname]
98 except KeyError:
98 except KeyError:
99 pass
99 pass
100 return super(_basefilecache, self).__get__(unfi, type)
100 return super(_basefilecache, self).__get__(unfi, type)
101
101
102 def set(self, repo, value):
102 def set(self, repo, value):
103 return super(_basefilecache, self).set(repo.unfiltered(), value)
103 return super(_basefilecache, self).set(repo.unfiltered(), value)
104
104
105 class repofilecache(_basefilecache):
105 class repofilecache(_basefilecache):
106 """filecache for files in .hg but outside of .hg/store"""
106 """filecache for files in .hg but outside of .hg/store"""
107 def __init__(self, *paths):
107 def __init__(self, *paths):
108 super(repofilecache, self).__init__(*paths)
108 super(repofilecache, self).__init__(*paths)
109 for path in paths:
109 for path in paths:
110 _cachedfiles.add((path, 'plain'))
110 _cachedfiles.add((path, 'plain'))
111
111
112 def join(self, obj, fname):
112 def join(self, obj, fname):
113 return obj.vfs.join(fname)
113 return obj.vfs.join(fname)
114
114
115 class storecache(_basefilecache):
115 class storecache(_basefilecache):
116 """filecache for files in the store"""
116 """filecache for files in the store"""
117 def __init__(self, *paths):
117 def __init__(self, *paths):
118 super(storecache, self).__init__(*paths)
118 super(storecache, self).__init__(*paths)
119 for path in paths:
119 for path in paths:
120 _cachedfiles.add((path, ''))
120 _cachedfiles.add((path, ''))
121
121
122 def join(self, obj, fname):
122 def join(self, obj, fname):
123 return obj.sjoin(fname)
123 return obj.sjoin(fname)
124
124
125 def isfilecached(repo, name):
125 def isfilecached(repo, name):
126 """check if a repo has already cached "name" filecache-ed property
126 """check if a repo has already cached "name" filecache-ed property
127
127
128 This returns (cachedobj-or-None, iscached) tuple.
128 This returns (cachedobj-or-None, iscached) tuple.
129 """
129 """
130 cacheentry = repo.unfiltered()._filecache.get(name, None)
130 cacheentry = repo.unfiltered()._filecache.get(name, None)
131 if not cacheentry:
131 if not cacheentry:
132 return None, False
132 return None, False
133 return cacheentry.obj, True
133 return cacheentry.obj, True
134
134
135 class unfilteredpropertycache(util.propertycache):
135 class unfilteredpropertycache(util.propertycache):
136 """propertycache that apply to unfiltered repo only"""
136 """propertycache that apply to unfiltered repo only"""
137
137
138 def __get__(self, repo, type=None):
138 def __get__(self, repo, type=None):
139 unfi = repo.unfiltered()
139 unfi = repo.unfiltered()
140 if unfi is repo:
140 if unfi is repo:
141 return super(unfilteredpropertycache, self).__get__(unfi)
141 return super(unfilteredpropertycache, self).__get__(unfi)
142 return getattr(unfi, self.name)
142 return getattr(unfi, self.name)
143
143
144 class filteredpropertycache(util.propertycache):
144 class filteredpropertycache(util.propertycache):
145 """propertycache that must take filtering in account"""
145 """propertycache that must take filtering in account"""
146
146
147 def cachevalue(self, obj, value):
147 def cachevalue(self, obj, value):
148 object.__setattr__(obj, self.name, value)
148 object.__setattr__(obj, self.name, value)
149
149
150
150
151 def hasunfilteredcache(repo, name):
151 def hasunfilteredcache(repo, name):
152 """check if a repo has an unfilteredpropertycache value for <name>"""
152 """check if a repo has an unfilteredpropertycache value for <name>"""
153 return name in vars(repo.unfiltered())
153 return name in vars(repo.unfiltered())
154
154
155 def unfilteredmethod(orig):
155 def unfilteredmethod(orig):
156 """decorate method that always need to be run on unfiltered version"""
156 """decorate method that always need to be run on unfiltered version"""
157 def wrapper(repo, *args, **kwargs):
157 def wrapper(repo, *args, **kwargs):
158 return orig(repo.unfiltered(), *args, **kwargs)
158 return orig(repo.unfiltered(), *args, **kwargs)
159 return wrapper
159 return wrapper
160
160
161 moderncaps = {'lookup', 'branchmap', 'pushkey', 'known', 'getbundle',
161 moderncaps = {'lookup', 'branchmap', 'pushkey', 'known', 'getbundle',
162 'unbundle'}
162 'unbundle'}
163 legacycaps = moderncaps.union({'changegroupsubset'})
163 legacycaps = moderncaps.union({'changegroupsubset'})
164
164
165 @interfaceutil.implementer(repository.ipeercommandexecutor)
165 @interfaceutil.implementer(repository.ipeercommandexecutor)
166 class localcommandexecutor(object):
166 class localcommandexecutor(object):
167 def __init__(self, peer):
167 def __init__(self, peer):
168 self._peer = peer
168 self._peer = peer
169 self._sent = False
169 self._sent = False
170 self._closed = False
170 self._closed = False
171
171
172 def __enter__(self):
172 def __enter__(self):
173 return self
173 return self
174
174
175 def __exit__(self, exctype, excvalue, exctb):
175 def __exit__(self, exctype, excvalue, exctb):
176 self.close()
176 self.close()
177
177
178 def callcommand(self, command, args):
178 def callcommand(self, command, args):
179 if self._sent:
179 if self._sent:
180 raise error.ProgrammingError('callcommand() cannot be used after '
180 raise error.ProgrammingError('callcommand() cannot be used after '
181 'sendcommands()')
181 'sendcommands()')
182
182
183 if self._closed:
183 if self._closed:
184 raise error.ProgrammingError('callcommand() cannot be used after '
184 raise error.ProgrammingError('callcommand() cannot be used after '
185 'close()')
185 'close()')
186
186
187 # We don't need to support anything fancy. Just call the named
187 # We don't need to support anything fancy. Just call the named
188 # method on the peer and return a resolved future.
188 # method on the peer and return a resolved future.
189 fn = getattr(self._peer, pycompat.sysstr(command))
189 fn = getattr(self._peer, pycompat.sysstr(command))
190
190
191 f = pycompat.futures.Future()
191 f = pycompat.futures.Future()
192
192
193 try:
193 try:
194 result = fn(**pycompat.strkwargs(args))
194 result = fn(**pycompat.strkwargs(args))
195 except Exception:
195 except Exception:
196 pycompat.future_set_exception_info(f, sys.exc_info()[1:])
196 pycompat.future_set_exception_info(f, sys.exc_info()[1:])
197 else:
197 else:
198 f.set_result(result)
198 f.set_result(result)
199
199
200 return f
200 return f
201
201
202 def sendcommands(self):
202 def sendcommands(self):
203 self._sent = True
203 self._sent = True
204
204
205 def close(self):
205 def close(self):
206 self._closed = True
206 self._closed = True
207
207
208 @interfaceutil.implementer(repository.ipeercommands)
208 @interfaceutil.implementer(repository.ipeercommands)
209 class localpeer(repository.peer):
209 class localpeer(repository.peer):
210 '''peer for a local repo; reflects only the most recent API'''
210 '''peer for a local repo; reflects only the most recent API'''
211
211
212 def __init__(self, repo, caps=None):
212 def __init__(self, repo, caps=None):
213 super(localpeer, self).__init__()
213 super(localpeer, self).__init__()
214
214
215 if caps is None:
215 if caps is None:
216 caps = moderncaps.copy()
216 caps = moderncaps.copy()
217 self._repo = repo.filtered('served')
217 self._repo = repo.filtered('served')
218 self.ui = repo.ui
218 self.ui = repo.ui
219 self._caps = repo._restrictcapabilities(caps)
219 self._caps = repo._restrictcapabilities(caps)
220
220
221 # Begin of _basepeer interface.
221 # Begin of _basepeer interface.
222
222
223 def url(self):
223 def url(self):
224 return self._repo.url()
224 return self._repo.url()
225
225
226 def local(self):
226 def local(self):
227 return self._repo
227 return self._repo
228
228
229 def peer(self):
229 def peer(self):
230 return self
230 return self
231
231
232 def canpush(self):
232 def canpush(self):
233 return True
233 return True
234
234
235 def close(self):
235 def close(self):
236 self._repo.close()
236 self._repo.close()
237
237
238 # End of _basepeer interface.
238 # End of _basepeer interface.
239
239
240 # Begin of _basewirecommands interface.
240 # Begin of _basewirecommands interface.
241
241
242 def branchmap(self):
242 def branchmap(self):
243 return self._repo.branchmap()
243 return self._repo.branchmap()
244
244
245 def capabilities(self):
245 def capabilities(self):
246 return self._caps
246 return self._caps
247
247
248 def clonebundles(self):
248 def clonebundles(self):
249 return self._repo.tryread('clonebundles.manifest')
249 return self._repo.tryread('clonebundles.manifest')
250
250
251 def debugwireargs(self, one, two, three=None, four=None, five=None):
251 def debugwireargs(self, one, two, three=None, four=None, five=None):
252 """Used to test argument passing over the wire"""
252 """Used to test argument passing over the wire"""
253 return "%s %s %s %s %s" % (one, two, pycompat.bytestr(three),
253 return "%s %s %s %s %s" % (one, two, pycompat.bytestr(three),
254 pycompat.bytestr(four),
254 pycompat.bytestr(four),
255 pycompat.bytestr(five))
255 pycompat.bytestr(five))
256
256
257 def getbundle(self, source, heads=None, common=None, bundlecaps=None,
257 def getbundle(self, source, heads=None, common=None, bundlecaps=None,
258 **kwargs):
258 **kwargs):
259 chunks = exchange.getbundlechunks(self._repo, source, heads=heads,
259 chunks = exchange.getbundlechunks(self._repo, source, heads=heads,
260 common=common, bundlecaps=bundlecaps,
260 common=common, bundlecaps=bundlecaps,
261 **kwargs)[1]
261 **kwargs)[1]
262 cb = util.chunkbuffer(chunks)
262 cb = util.chunkbuffer(chunks)
263
263
264 if exchange.bundle2requested(bundlecaps):
264 if exchange.bundle2requested(bundlecaps):
265 # When requesting a bundle2, getbundle returns a stream to make the
265 # When requesting a bundle2, getbundle returns a stream to make the
266 # wire level function happier. We need to build a proper object
266 # wire level function happier. We need to build a proper object
267 # from it in local peer.
267 # from it in local peer.
268 return bundle2.getunbundler(self.ui, cb)
268 return bundle2.getunbundler(self.ui, cb)
269 else:
269 else:
270 return changegroup.getunbundler('01', cb, None)
270 return changegroup.getunbundler('01', cb, None)
271
271
272 def heads(self):
272 def heads(self):
273 return self._repo.heads()
273 return self._repo.heads()
274
274
275 def known(self, nodes):
275 def known(self, nodes):
276 return self._repo.known(nodes)
276 return self._repo.known(nodes)
277
277
278 def listkeys(self, namespace):
278 def listkeys(self, namespace):
279 return self._repo.listkeys(namespace)
279 return self._repo.listkeys(namespace)
280
280
281 def lookup(self, key):
281 def lookup(self, key):
282 return self._repo.lookup(key)
282 return self._repo.lookup(key)
283
283
284 def pushkey(self, namespace, key, old, new):
284 def pushkey(self, namespace, key, old, new):
285 return self._repo.pushkey(namespace, key, old, new)
285 return self._repo.pushkey(namespace, key, old, new)
286
286
287 def stream_out(self):
287 def stream_out(self):
288 raise error.Abort(_('cannot perform stream clone against local '
288 raise error.Abort(_('cannot perform stream clone against local '
289 'peer'))
289 'peer'))
290
290
291 def unbundle(self, bundle, heads, url):
291 def unbundle(self, bundle, heads, url):
292 """apply a bundle on a repo
292 """apply a bundle on a repo
293
293
294 This function handles the repo locking itself."""
294 This function handles the repo locking itself."""
295 try:
295 try:
296 try:
296 try:
297 bundle = exchange.readbundle(self.ui, bundle, None)
297 bundle = exchange.readbundle(self.ui, bundle, None)
298 ret = exchange.unbundle(self._repo, bundle, heads, 'push', url)
298 ret = exchange.unbundle(self._repo, bundle, heads, 'push', url)
299 if util.safehasattr(ret, 'getchunks'):
299 if util.safehasattr(ret, 'getchunks'):
300 # This is a bundle20 object, turn it into an unbundler.
300 # This is a bundle20 object, turn it into an unbundler.
301 # This little dance should be dropped eventually when the
301 # This little dance should be dropped eventually when the
302 # API is finally improved.
302 # API is finally improved.
303 stream = util.chunkbuffer(ret.getchunks())
303 stream = util.chunkbuffer(ret.getchunks())
304 ret = bundle2.getunbundler(self.ui, stream)
304 ret = bundle2.getunbundler(self.ui, stream)
305 return ret
305 return ret
306 except Exception as exc:
306 except Exception as exc:
307 # If the exception contains output salvaged from a bundle2
307 # If the exception contains output salvaged from a bundle2
308 # reply, we need to make sure it is printed before continuing
308 # reply, we need to make sure it is printed before continuing
309 # to fail. So we build a bundle2 with such output and consume
309 # to fail. So we build a bundle2 with such output and consume
310 # it directly.
310 # it directly.
311 #
311 #
312 # This is not very elegant but allows a "simple" solution for
312 # This is not very elegant but allows a "simple" solution for
313 # issue4594
313 # issue4594
314 output = getattr(exc, '_bundle2salvagedoutput', ())
314 output = getattr(exc, '_bundle2salvagedoutput', ())
315 if output:
315 if output:
316 bundler = bundle2.bundle20(self._repo.ui)
316 bundler = bundle2.bundle20(self._repo.ui)
317 for out in output:
317 for out in output:
318 bundler.addpart(out)
318 bundler.addpart(out)
319 stream = util.chunkbuffer(bundler.getchunks())
319 stream = util.chunkbuffer(bundler.getchunks())
320 b = bundle2.getunbundler(self.ui, stream)
320 b = bundle2.getunbundler(self.ui, stream)
321 bundle2.processbundle(self._repo, b)
321 bundle2.processbundle(self._repo, b)
322 raise
322 raise
323 except error.PushRaced as exc:
323 except error.PushRaced as exc:
324 raise error.ResponseError(_('push failed:'),
324 raise error.ResponseError(_('push failed:'),
325 stringutil.forcebytestr(exc))
325 stringutil.forcebytestr(exc))
326
326
327 # End of _basewirecommands interface.
327 # End of _basewirecommands interface.
328
328
329 # Begin of peer interface.
329 # Begin of peer interface.
330
330
331 def commandexecutor(self):
331 def commandexecutor(self):
332 return localcommandexecutor(self)
332 return localcommandexecutor(self)
333
333
334 # End of peer interface.
334 # End of peer interface.
335
335
336 @interfaceutil.implementer(repository.ipeerlegacycommands)
336 @interfaceutil.implementer(repository.ipeerlegacycommands)
337 class locallegacypeer(localpeer):
337 class locallegacypeer(localpeer):
338 '''peer extension which implements legacy methods too; used for tests with
338 '''peer extension which implements legacy methods too; used for tests with
339 restricted capabilities'''
339 restricted capabilities'''
340
340
341 def __init__(self, repo):
341 def __init__(self, repo):
342 super(locallegacypeer, self).__init__(repo, caps=legacycaps)
342 super(locallegacypeer, self).__init__(repo, caps=legacycaps)
343
343
344 # Begin of baselegacywirecommands interface.
344 # Begin of baselegacywirecommands interface.
345
345
346 def between(self, pairs):
346 def between(self, pairs):
347 return self._repo.between(pairs)
347 return self._repo.between(pairs)
348
348
349 def branches(self, nodes):
349 def branches(self, nodes):
350 return self._repo.branches(nodes)
350 return self._repo.branches(nodes)
351
351
352 def changegroup(self, nodes, source):
352 def changegroup(self, nodes, source):
353 outgoing = discovery.outgoing(self._repo, missingroots=nodes,
353 outgoing = discovery.outgoing(self._repo, missingroots=nodes,
354 missingheads=self._repo.heads())
354 missingheads=self._repo.heads())
355 return changegroup.makechangegroup(self._repo, outgoing, '01', source)
355 return changegroup.makechangegroup(self._repo, outgoing, '01', source)
356
356
357 def changegroupsubset(self, bases, heads, source):
357 def changegroupsubset(self, bases, heads, source):
358 outgoing = discovery.outgoing(self._repo, missingroots=bases,
358 outgoing = discovery.outgoing(self._repo, missingroots=bases,
359 missingheads=heads)
359 missingheads=heads)
360 return changegroup.makechangegroup(self._repo, outgoing, '01', source)
360 return changegroup.makechangegroup(self._repo, outgoing, '01', source)
361
361
362 # End of baselegacywirecommands interface.
362 # End of baselegacywirecommands interface.
363
363
364 # Increment the sub-version when the revlog v2 format changes to lock out old
364 # Increment the sub-version when the revlog v2 format changes to lock out old
365 # clients.
365 # clients.
366 REVLOGV2_REQUIREMENT = 'exp-revlogv2.0'
366 REVLOGV2_REQUIREMENT = 'exp-revlogv2.0'
367
367
368 # A repository with the sparserevlog feature will have delta chains that
368 # A repository with the sparserevlog feature will have delta chains that
369 # can spread over a larger span. Sparse reading cuts these large spans into
369 # can spread over a larger span. Sparse reading cuts these large spans into
370 # pieces, so that each piece isn't too big.
370 # pieces, so that each piece isn't too big.
371 # Without the sparserevlog capability, reading from the repository could use
371 # Without the sparserevlog capability, reading from the repository could use
372 # huge amounts of memory, because the whole span would be read at once,
372 # huge amounts of memory, because the whole span would be read at once,
373 # including all the intermediate revisions that aren't pertinent for the chain.
373 # including all the intermediate revisions that aren't pertinent for the chain.
374 # This is why once a repository has enabled sparse-read, it becomes required.
374 # This is why once a repository has enabled sparse-read, it becomes required.
375 SPARSEREVLOG_REQUIREMENT = 'sparserevlog'
375 SPARSEREVLOG_REQUIREMENT = 'sparserevlog'
376
376
377 # Functions receiving (ui, features) that extensions can register to impact
377 # Functions receiving (ui, features) that extensions can register to impact
378 # the ability to load repositories with custom requirements. Only
378 # the ability to load repositories with custom requirements. Only
379 # functions defined in loaded extensions are called.
379 # functions defined in loaded extensions are called.
380 #
380 #
381 # The function receives a set of requirement strings that the repository
381 # The function receives a set of requirement strings that the repository
382 # is capable of opening. Functions will typically add elements to the
382 # is capable of opening. Functions will typically add elements to the
383 # set to reflect that the extension knows how to handle that requirements.
383 # set to reflect that the extension knows how to handle that requirements.
384 featuresetupfuncs = set()
384 featuresetupfuncs = set()
385
385
386 def makelocalrepository(baseui, path, intents=None):
386 def makelocalrepository(baseui, path, intents=None):
387 """Create a local repository object.
387 """Create a local repository object.
388
388
389 Given arguments needed to construct a local repository, this function
389 Given arguments needed to construct a local repository, this function
390 performs various early repository loading functionality (such as
390 performs various early repository loading functionality (such as
391 reading the ``.hg/requires`` and ``.hg/hgrc`` files), validates that
391 reading the ``.hg/requires`` and ``.hg/hgrc`` files), validates that
392 the repository can be opened, derives a type suitable for representing
392 the repository can be opened, derives a type suitable for representing
393 that repository, and returns an instance of it.
393 that repository, and returns an instance of it.
394
394
395 The returned object conforms to the ``repository.completelocalrepository``
395 The returned object conforms to the ``repository.completelocalrepository``
396 interface.
396 interface.
397
397
398 The repository type is derived by calling a series of factory functions
398 The repository type is derived by calling a series of factory functions
399 for each aspect/interface of the final repository. These are defined by
399 for each aspect/interface of the final repository. These are defined by
400 ``REPO_INTERFACES``.
400 ``REPO_INTERFACES``.
401
401
402 Each factory function is called to produce a type implementing a specific
402 Each factory function is called to produce a type implementing a specific
403 interface. The cumulative list of returned types will be combined into a
403 interface. The cumulative list of returned types will be combined into a
404 new type and that type will be instantiated to represent the local
404 new type and that type will be instantiated to represent the local
405 repository.
405 repository.
406
406
407 The factory functions each receive various state that may be consulted
407 The factory functions each receive various state that may be consulted
408 as part of deriving a type.
408 as part of deriving a type.
409
409
410 Extensions should wrap these factory functions to customize repository type
410 Extensions should wrap these factory functions to customize repository type
411 creation. Note that an extension's wrapped function may be called even if
411 creation. Note that an extension's wrapped function may be called even if
412 that extension is not loaded for the repo being constructed. Extensions
412 that extension is not loaded for the repo being constructed. Extensions
413 should check if their ``__name__`` appears in the
413 should check if their ``__name__`` appears in the
414 ``extensionmodulenames`` set passed to the factory function and no-op if
414 ``extensionmodulenames`` set passed to the factory function and no-op if
415 not.
415 not.
416 """
416 """
417 ui = baseui.copy()
417 ui = baseui.copy()
418 # Prevent copying repo configuration.
418 # Prevent copying repo configuration.
419 ui.copy = baseui.copy
419 ui.copy = baseui.copy
420
420
421 # Working directory VFS rooted at repository root.
421 # Working directory VFS rooted at repository root.
422 wdirvfs = vfsmod.vfs(path, expandpath=True, realpath=True)
422 wdirvfs = vfsmod.vfs(path, expandpath=True, realpath=True)
423
423
424 # Main VFS for .hg/ directory.
424 # Main VFS for .hg/ directory.
425 hgpath = wdirvfs.join(b'.hg')
425 hgpath = wdirvfs.join(b'.hg')
426 hgvfs = vfsmod.vfs(hgpath, cacheaudited=True)
426 hgvfs = vfsmod.vfs(hgpath, cacheaudited=True)
427
427
428 # The .hg/ path should exist and should be a directory. All other
428 # The .hg/ path should exist and should be a directory. All other
429 # cases are errors.
429 # cases are errors.
430 if not hgvfs.isdir():
430 if not hgvfs.isdir():
431 try:
431 try:
432 hgvfs.stat()
432 hgvfs.stat()
433 except OSError as e:
433 except OSError as e:
434 if e.errno != errno.ENOENT:
434 if e.errno != errno.ENOENT:
435 raise
435 raise
436
436
437 raise error.RepoError(_(b'repository %s not found') % path)
437 raise error.RepoError(_(b'repository %s not found') % path)
438
438
439 # .hg/requires file contains a newline-delimited list of
439 # .hg/requires file contains a newline-delimited list of
440 # features/capabilities the opener (us) must have in order to use
440 # features/capabilities the opener (us) must have in order to use
441 # the repository. This file was introduced in Mercurial 0.9.2,
441 # the repository. This file was introduced in Mercurial 0.9.2,
442 # which means very old repositories may not have one. We assume
442 # which means very old repositories may not have one. We assume
443 # a missing file translates to no requirements.
443 # a missing file translates to no requirements.
444 try:
444 try:
445 requirements = set(hgvfs.read(b'requires').splitlines())
445 requirements = set(hgvfs.read(b'requires').splitlines())
446 except IOError as e:
446 except IOError as e:
447 if e.errno != errno.ENOENT:
447 if e.errno != errno.ENOENT:
448 raise
448 raise
449 requirements = set()
449 requirements = set()
450
450
451 # The .hg/hgrc file may load extensions or contain config options
451 # The .hg/hgrc file may load extensions or contain config options
452 # that influence repository construction. Attempt to load it and
452 # that influence repository construction. Attempt to load it and
453 # process any new extensions that it may have pulled in.
453 # process any new extensions that it may have pulled in.
454 if loadhgrc(ui, wdirvfs, hgvfs, requirements):
454 if loadhgrc(ui, wdirvfs, hgvfs, requirements):
455 afterhgrcload(ui, wdirvfs, hgvfs, requirements)
455 afterhgrcload(ui, wdirvfs, hgvfs, requirements)
456 extensions.loadall(ui)
456 extensions.loadall(ui)
457
457
458 # Set of module names of extensions loaded for this repository.
458 # Set of module names of extensions loaded for this repository.
459 extensionmodulenames = {m.__name__ for n, m in extensions.extensions(ui)}
459 extensionmodulenames = {m.__name__ for n, m in extensions.extensions(ui)}
460
460
461 supportedrequirements = gathersupportedrequirements(ui)
461 supportedrequirements = gathersupportedrequirements(ui)
462
462
463 # We first validate the requirements are known.
463 # We first validate the requirements are known.
464 ensurerequirementsrecognized(requirements, supportedrequirements)
464 ensurerequirementsrecognized(requirements, supportedrequirements)
465
465
466 # Then we validate that the known set is reasonable to use together.
466 # Then we validate that the known set is reasonable to use together.
467 ensurerequirementscompatible(ui, requirements)
467 ensurerequirementscompatible(ui, requirements)
468
468
469 # TODO there are unhandled edge cases related to opening repositories with
469 # TODO there are unhandled edge cases related to opening repositories with
470 # shared storage. If storage is shared, we should also test for requirements
470 # shared storage. If storage is shared, we should also test for requirements
471 # compatibility in the pointed-to repo. This entails loading the .hg/hgrc in
471 # compatibility in the pointed-to repo. This entails loading the .hg/hgrc in
472 # that repo, as that repo may load extensions needed to open it. This is a
472 # that repo, as that repo may load extensions needed to open it. This is a
473 # bit complicated because we don't want the other hgrc to overwrite settings
473 # bit complicated because we don't want the other hgrc to overwrite settings
474 # in this hgrc.
474 # in this hgrc.
475 #
475 #
476 # This bug is somewhat mitigated by the fact that we copy the .hg/requires
476 # This bug is somewhat mitigated by the fact that we copy the .hg/requires
477 # file when sharing repos. But if a requirement is added after the share is
477 # file when sharing repos. But if a requirement is added after the share is
478 # performed, thereby introducing a new requirement for the opener, we may
478 # performed, thereby introducing a new requirement for the opener, we may
479 # will not see that and could encounter a run-time error interacting with
479 # will not see that and could encounter a run-time error interacting with
480 # that shared store since it has an unknown-to-us requirement.
480 # that shared store since it has an unknown-to-us requirement.
481
481
482 # At this point, we know we should be capable of opening the repository.
482 # At this point, we know we should be capable of opening the repository.
483 # Now get on with doing that.
483 # Now get on with doing that.
484
484
485 features = set()
485 features = set()
486
486
487 # The "store" part of the repository holds versioned data. How it is
487 # The "store" part of the repository holds versioned data. How it is
488 # accessed is determined by various requirements. The ``shared`` or
488 # accessed is determined by various requirements. The ``shared`` or
489 # ``relshared`` requirements indicate the store lives in the path contained
489 # ``relshared`` requirements indicate the store lives in the path contained
490 # in the ``.hg/sharedpath`` file. This is an absolute path for
490 # in the ``.hg/sharedpath`` file. This is an absolute path for
491 # ``shared`` and relative to ``.hg/`` for ``relshared``.
491 # ``shared`` and relative to ``.hg/`` for ``relshared``.
492 if b'shared' in requirements or b'relshared' in requirements:
492 if b'shared' in requirements or b'relshared' in requirements:
493 sharedpath = hgvfs.read(b'sharedpath').rstrip(b'\n')
493 sharedpath = hgvfs.read(b'sharedpath').rstrip(b'\n')
494 if b'relshared' in requirements:
494 if b'relshared' in requirements:
495 sharedpath = hgvfs.join(sharedpath)
495 sharedpath = hgvfs.join(sharedpath)
496
496
497 sharedvfs = vfsmod.vfs(sharedpath, realpath=True)
497 sharedvfs = vfsmod.vfs(sharedpath, realpath=True)
498
498
499 if not sharedvfs.exists():
499 if not sharedvfs.exists():
500 raise error.RepoError(_(b'.hg/sharedpath points to nonexistent '
500 raise error.RepoError(_(b'.hg/sharedpath points to nonexistent '
501 b'directory %s') % sharedvfs.base)
501 b'directory %s') % sharedvfs.base)
502
502
503 features.add(repository.REPO_FEATURE_SHARED_STORAGE)
503 features.add(repository.REPO_FEATURE_SHARED_STORAGE)
504
504
505 storebasepath = sharedvfs.base
505 storebasepath = sharedvfs.base
506 cachepath = sharedvfs.join(b'cache')
506 cachepath = sharedvfs.join(b'cache')
507 else:
507 else:
508 storebasepath = hgvfs.base
508 storebasepath = hgvfs.base
509 cachepath = hgvfs.join(b'cache')
509 cachepath = hgvfs.join(b'cache')
510
510
511 # The store has changed over time and the exact layout is dictated by
511 # The store has changed over time and the exact layout is dictated by
512 # requirements. The store interface abstracts differences across all
512 # requirements. The store interface abstracts differences across all
513 # of them.
513 # of them.
514 store = makestore(requirements, storebasepath,
514 store = makestore(requirements, storebasepath,
515 lambda base: vfsmod.vfs(base, cacheaudited=True))
515 lambda base: vfsmod.vfs(base, cacheaudited=True))
516 hgvfs.createmode = store.createmode
516 hgvfs.createmode = store.createmode
517
517
518 storevfs = store.vfs
518 storevfs = store.vfs
519 storevfs.options = resolvestorevfsoptions(ui, requirements, features)
519 storevfs.options = resolvestorevfsoptions(ui, requirements, features)
520
520
521 # The cache vfs is used to manage cache files.
521 # The cache vfs is used to manage cache files.
522 cachevfs = vfsmod.vfs(cachepath, cacheaudited=True)
522 cachevfs = vfsmod.vfs(cachepath, cacheaudited=True)
523 cachevfs.createmode = store.createmode
523 cachevfs.createmode = store.createmode
524
524
525 # Now resolve the type for the repository object. We do this by repeatedly
525 # Now resolve the type for the repository object. We do this by repeatedly
526 # calling a factory function to produces types for specific aspects of the
526 # calling a factory function to produces types for specific aspects of the
527 # repo's operation. The aggregate returned types are used as base classes
527 # repo's operation. The aggregate returned types are used as base classes
528 # for a dynamically-derived type, which will represent our new repository.
528 # for a dynamically-derived type, which will represent our new repository.
529
529
530 bases = []
530 bases = []
531 extrastate = {}
531 extrastate = {}
532
532
533 for iface, fn in REPO_INTERFACES:
533 for iface, fn in REPO_INTERFACES:
534 # We pass all potentially useful state to give extensions tons of
534 # We pass all potentially useful state to give extensions tons of
535 # flexibility.
535 # flexibility.
536 typ = fn()(ui=ui,
536 typ = fn()(ui=ui,
537 intents=intents,
537 intents=intents,
538 requirements=requirements,
538 requirements=requirements,
539 features=features,
539 features=features,
540 wdirvfs=wdirvfs,
540 wdirvfs=wdirvfs,
541 hgvfs=hgvfs,
541 hgvfs=hgvfs,
542 store=store,
542 store=store,
543 storevfs=storevfs,
543 storevfs=storevfs,
544 storeoptions=storevfs.options,
544 storeoptions=storevfs.options,
545 cachevfs=cachevfs,
545 cachevfs=cachevfs,
546 extensionmodulenames=extensionmodulenames,
546 extensionmodulenames=extensionmodulenames,
547 extrastate=extrastate,
547 extrastate=extrastate,
548 baseclasses=bases)
548 baseclasses=bases)
549
549
550 if not isinstance(typ, type):
550 if not isinstance(typ, type):
551 raise error.ProgrammingError('unable to construct type for %s' %
551 raise error.ProgrammingError('unable to construct type for %s' %
552 iface)
552 iface)
553
553
554 bases.append(typ)
554 bases.append(typ)
555
555
556 # type() allows you to use characters in type names that wouldn't be
556 # type() allows you to use characters in type names that wouldn't be
557 # recognized as Python symbols in source code. We abuse that to add
557 # recognized as Python symbols in source code. We abuse that to add
558 # rich information about our constructed repo.
558 # rich information about our constructed repo.
559 name = pycompat.sysstr(b'derivedrepo:%s<%s>' % (
559 name = pycompat.sysstr(b'derivedrepo:%s<%s>' % (
560 wdirvfs.base,
560 wdirvfs.base,
561 b','.join(sorted(requirements))))
561 b','.join(sorted(requirements))))
562
562
563 cls = type(name, tuple(bases), {})
563 cls = type(name, tuple(bases), {})
564
564
565 return cls(
565 return cls(
566 baseui=baseui,
566 baseui=baseui,
567 ui=ui,
567 ui=ui,
568 origroot=path,
568 origroot=path,
569 wdirvfs=wdirvfs,
569 wdirvfs=wdirvfs,
570 hgvfs=hgvfs,
570 hgvfs=hgvfs,
571 requirements=requirements,
571 requirements=requirements,
572 supportedrequirements=supportedrequirements,
572 supportedrequirements=supportedrequirements,
573 sharedpath=storebasepath,
573 sharedpath=storebasepath,
574 store=store,
574 store=store,
575 cachevfs=cachevfs,
575 cachevfs=cachevfs,
576 features=features,
576 features=features,
577 intents=intents)
577 intents=intents)
578
578
579 def loadhgrc(ui, wdirvfs, hgvfs, requirements):
579 def loadhgrc(ui, wdirvfs, hgvfs, requirements):
580 """Load hgrc files/content into a ui instance.
580 """Load hgrc files/content into a ui instance.
581
581
582 This is called during repository opening to load any additional
582 This is called during repository opening to load any additional
583 config files or settings relevant to the current repository.
583 config files or settings relevant to the current repository.
584
584
585 Returns a bool indicating whether any additional configs were loaded.
585 Returns a bool indicating whether any additional configs were loaded.
586
586
587 Extensions should monkeypatch this function to modify how per-repo
587 Extensions should monkeypatch this function to modify how per-repo
588 configs are loaded. For example, an extension may wish to pull in
588 configs are loaded. For example, an extension may wish to pull in
589 configs from alternate files or sources.
589 configs from alternate files or sources.
590 """
590 """
591 try:
591 try:
592 ui.readconfig(hgvfs.join(b'hgrc'), root=wdirvfs.base)
592 ui.readconfig(hgvfs.join(b'hgrc'), root=wdirvfs.base)
593 return True
593 return True
594 except IOError:
594 except IOError:
595 return False
595 return False
596
596
597 def afterhgrcload(ui, wdirvfs, hgvfs, requirements):
597 def afterhgrcload(ui, wdirvfs, hgvfs, requirements):
598 """Perform additional actions after .hg/hgrc is loaded.
598 """Perform additional actions after .hg/hgrc is loaded.
599
599
600 This function is called during repository loading immediately after
600 This function is called during repository loading immediately after
601 the .hg/hgrc file is loaded and before per-repo extensions are loaded.
601 the .hg/hgrc file is loaded and before per-repo extensions are loaded.
602
602
603 The function can be used to validate configs, automatically add
603 The function can be used to validate configs, automatically add
604 options (including extensions) based on requirements, etc.
604 options (including extensions) based on requirements, etc.
605 """
605 """
606
606
607 # Map of requirements to list of extensions to load automatically when
607 # Map of requirements to list of extensions to load automatically when
608 # requirement is present.
608 # requirement is present.
609 autoextensions = {
609 autoextensions = {
610 b'largefiles': [b'largefiles'],
610 b'largefiles': [b'largefiles'],
611 b'lfs': [b'lfs'],
611 b'lfs': [b'lfs'],
612 }
612 }
613
613
614 for requirement, names in sorted(autoextensions.items()):
614 for requirement, names in sorted(autoextensions.items()):
615 if requirement not in requirements:
615 if requirement not in requirements:
616 continue
616 continue
617
617
618 for name in names:
618 for name in names:
619 if not ui.hasconfig(b'extensions', name):
619 if not ui.hasconfig(b'extensions', name):
620 ui.setconfig(b'extensions', name, b'', source='autoload')
620 ui.setconfig(b'extensions', name, b'', source='autoload')
621
621
622 def gathersupportedrequirements(ui):
622 def gathersupportedrequirements(ui):
623 """Determine the complete set of recognized requirements."""
623 """Determine the complete set of recognized requirements."""
624 # Start with all requirements supported by this file.
624 # Start with all requirements supported by this file.
625 supported = set(localrepository._basesupported)
625 supported = set(localrepository._basesupported)
626
626
627 # Execute ``featuresetupfuncs`` entries if they belong to an extension
627 # Execute ``featuresetupfuncs`` entries if they belong to an extension
628 # relevant to this ui instance.
628 # relevant to this ui instance.
629 modules = {m.__name__ for n, m in extensions.extensions(ui)}
629 modules = {m.__name__ for n, m in extensions.extensions(ui)}
630
630
631 for fn in featuresetupfuncs:
631 for fn in featuresetupfuncs:
632 if fn.__module__ in modules:
632 if fn.__module__ in modules:
633 fn(ui, supported)
633 fn(ui, supported)
634
634
635 # Add derived requirements from registered compression engines.
635 # Add derived requirements from registered compression engines.
636 for name in util.compengines:
636 for name in util.compengines:
637 engine = util.compengines[name]
637 engine = util.compengines[name]
638 if engine.revlogheader():
638 if engine.revlogheader():
639 supported.add(b'exp-compression-%s' % name)
639 supported.add(b'exp-compression-%s' % name)
640
640
641 return supported
641 return supported
642
642
643 def ensurerequirementsrecognized(requirements, supported):
643 def ensurerequirementsrecognized(requirements, supported):
644 """Validate that a set of local requirements is recognized.
644 """Validate that a set of local requirements is recognized.
645
645
646 Receives a set of requirements. Raises an ``error.RepoError`` if there
646 Receives a set of requirements. Raises an ``error.RepoError`` if there
647 exists any requirement in that set that currently loaded code doesn't
647 exists any requirement in that set that currently loaded code doesn't
648 recognize.
648 recognize.
649
649
650 Returns a set of supported requirements.
650 Returns a set of supported requirements.
651 """
651 """
652 missing = set()
652 missing = set()
653
653
654 for requirement in requirements:
654 for requirement in requirements:
655 if requirement in supported:
655 if requirement in supported:
656 continue
656 continue
657
657
658 if not requirement or not requirement[0:1].isalnum():
658 if not requirement or not requirement[0:1].isalnum():
659 raise error.RequirementError(_(b'.hg/requires file is corrupt'))
659 raise error.RequirementError(_(b'.hg/requires file is corrupt'))
660
660
661 missing.add(requirement)
661 missing.add(requirement)
662
662
663 if missing:
663 if missing:
664 raise error.RequirementError(
664 raise error.RequirementError(
665 _(b'repository requires features unknown to this Mercurial: %s') %
665 _(b'repository requires features unknown to this Mercurial: %s') %
666 b' '.join(sorted(missing)),
666 b' '.join(sorted(missing)),
667 hint=_(b'see https://mercurial-scm.org/wiki/MissingRequirement '
667 hint=_(b'see https://mercurial-scm.org/wiki/MissingRequirement '
668 b'for more information'))
668 b'for more information'))
669
669
670 def ensurerequirementscompatible(ui, requirements):
670 def ensurerequirementscompatible(ui, requirements):
671 """Validates that a set of recognized requirements is mutually compatible.
671 """Validates that a set of recognized requirements is mutually compatible.
672
672
673 Some requirements may not be compatible with others or require
673 Some requirements may not be compatible with others or require
674 config options that aren't enabled. This function is called during
674 config options that aren't enabled. This function is called during
675 repository opening to ensure that the set of requirements needed
675 repository opening to ensure that the set of requirements needed
676 to open a repository is sane and compatible with config options.
676 to open a repository is sane and compatible with config options.
677
677
678 Extensions can monkeypatch this function to perform additional
678 Extensions can monkeypatch this function to perform additional
679 checking.
679 checking.
680
680
681 ``error.RepoError`` should be raised on failure.
681 ``error.RepoError`` should be raised on failure.
682 """
682 """
683 if b'exp-sparse' in requirements and not sparse.enabled:
683 if b'exp-sparse' in requirements and not sparse.enabled:
684 raise error.RepoError(_(b'repository is using sparse feature but '
684 raise error.RepoError(_(b'repository is using sparse feature but '
685 b'sparse is not enabled; enable the '
685 b'sparse is not enabled; enable the '
686 b'"sparse" extensions to access'))
686 b'"sparse" extensions to access'))
687
687
688 def makestore(requirements, path, vfstype):
688 def makestore(requirements, path, vfstype):
689 """Construct a storage object for a repository."""
689 """Construct a storage object for a repository."""
690 if b'store' in requirements:
690 if b'store' in requirements:
691 if b'fncache' in requirements:
691 if b'fncache' in requirements:
692 return storemod.fncachestore(path, vfstype,
692 return storemod.fncachestore(path, vfstype,
693 b'dotencode' in requirements)
693 b'dotencode' in requirements)
694
694
695 return storemod.encodedstore(path, vfstype)
695 return storemod.encodedstore(path, vfstype)
696
696
697 return storemod.basicstore(path, vfstype)
697 return storemod.basicstore(path, vfstype)
698
698
699 def resolvestorevfsoptions(ui, requirements, features):
699 def resolvestorevfsoptions(ui, requirements, features):
700 """Resolve the options to pass to the store vfs opener.
700 """Resolve the options to pass to the store vfs opener.
701
701
702 The returned dict is used to influence behavior of the storage layer.
702 The returned dict is used to influence behavior of the storage layer.
703 """
703 """
704 options = {}
704 options = {}
705
705
706 if b'treemanifest' in requirements:
706 if b'treemanifest' in requirements:
707 options[b'treemanifest'] = True
707 options[b'treemanifest'] = True
708
708
709 # experimental config: format.manifestcachesize
709 # experimental config: format.manifestcachesize
710 manifestcachesize = ui.configint(b'format', b'manifestcachesize')
710 manifestcachesize = ui.configint(b'format', b'manifestcachesize')
711 if manifestcachesize is not None:
711 if manifestcachesize is not None:
712 options[b'manifestcachesize'] = manifestcachesize
712 options[b'manifestcachesize'] = manifestcachesize
713
713
714 # In the absence of another requirement superseding a revlog-related
714 # In the absence of another requirement superseding a revlog-related
715 # requirement, we have to assume the repo is using revlog version 0.
715 # requirement, we have to assume the repo is using revlog version 0.
716 # This revlog format is super old and we don't bother trying to parse
716 # This revlog format is super old and we don't bother trying to parse
717 # opener options for it because those options wouldn't do anything
717 # opener options for it because those options wouldn't do anything
718 # meaningful on such old repos.
718 # meaningful on such old repos.
719 if b'revlogv1' in requirements or REVLOGV2_REQUIREMENT in requirements:
719 if b'revlogv1' in requirements or REVLOGV2_REQUIREMENT in requirements:
720 options.update(resolverevlogstorevfsoptions(ui, requirements, features))
720 options.update(resolverevlogstorevfsoptions(ui, requirements, features))
721
721
722 return options
722 return options
723
723
724 def resolverevlogstorevfsoptions(ui, requirements, features):
724 def resolverevlogstorevfsoptions(ui, requirements, features):
725 """Resolve opener options specific to revlogs."""
725 """Resolve opener options specific to revlogs."""
726
726
727 options = {}
727 options = {}
728 options[b'flagprocessors'] = {}
728 options[b'flagprocessors'] = {}
729
729
730 if b'revlogv1' in requirements:
730 if b'revlogv1' in requirements:
731 options[b'revlogv1'] = True
731 options[b'revlogv1'] = True
732 if REVLOGV2_REQUIREMENT in requirements:
732 if REVLOGV2_REQUIREMENT in requirements:
733 options[b'revlogv2'] = True
733 options[b'revlogv2'] = True
734
734
735 if b'generaldelta' in requirements:
735 if b'generaldelta' in requirements:
736 options[b'generaldelta'] = True
736 options[b'generaldelta'] = True
737
737
738 # experimental config: format.chunkcachesize
738 # experimental config: format.chunkcachesize
739 chunkcachesize = ui.configint(b'format', b'chunkcachesize')
739 chunkcachesize = ui.configint(b'format', b'chunkcachesize')
740 if chunkcachesize is not None:
740 if chunkcachesize is not None:
741 options[b'chunkcachesize'] = chunkcachesize
741 options[b'chunkcachesize'] = chunkcachesize
742
742
743 deltabothparents = ui.configbool(b'storage',
743 deltabothparents = ui.configbool(b'storage',
744 b'revlog.optimize-delta-parent-choice')
744 b'revlog.optimize-delta-parent-choice')
745 options[b'deltabothparents'] = deltabothparents
745 options[b'deltabothparents'] = deltabothparents
746
746
747 options[b'lazydeltabase'] = not scmutil.gddeltaconfig(ui)
747 options[b'lazydeltabase'] = not scmutil.gddeltaconfig(ui)
748
748
749 chainspan = ui.configbytes(b'experimental', b'maxdeltachainspan')
749 chainspan = ui.configbytes(b'experimental', b'maxdeltachainspan')
750 if 0 <= chainspan:
750 if 0 <= chainspan:
751 options[b'maxdeltachainspan'] = chainspan
751 options[b'maxdeltachainspan'] = chainspan
752
752
753 mmapindexthreshold = ui.configbytes(b'experimental',
753 mmapindexthreshold = ui.configbytes(b'experimental',
754 b'mmapindexthreshold')
754 b'mmapindexthreshold')
755 if mmapindexthreshold is not None:
755 if mmapindexthreshold is not None:
756 options[b'mmapindexthreshold'] = mmapindexthreshold
756 options[b'mmapindexthreshold'] = mmapindexthreshold
757
757
758 withsparseread = ui.configbool(b'experimental', b'sparse-read')
758 withsparseread = ui.configbool(b'experimental', b'sparse-read')
759 srdensitythres = float(ui.config(b'experimental',
759 srdensitythres = float(ui.config(b'experimental',
760 b'sparse-read.density-threshold'))
760 b'sparse-read.density-threshold'))
761 srmingapsize = ui.configbytes(b'experimental',
761 srmingapsize = ui.configbytes(b'experimental',
762 b'sparse-read.min-gap-size')
762 b'sparse-read.min-gap-size')
763 options[b'with-sparse-read'] = withsparseread
763 options[b'with-sparse-read'] = withsparseread
764 options[b'sparse-read-density-threshold'] = srdensitythres
764 options[b'sparse-read-density-threshold'] = srdensitythres
765 options[b'sparse-read-min-gap-size'] = srmingapsize
765 options[b'sparse-read-min-gap-size'] = srmingapsize
766
766
767 sparserevlog = SPARSEREVLOG_REQUIREMENT in requirements
767 sparserevlog = SPARSEREVLOG_REQUIREMENT in requirements
768 options[b'sparse-revlog'] = sparserevlog
768 options[b'sparse-revlog'] = sparserevlog
769 if sparserevlog:
769 if sparserevlog:
770 options[b'generaldelta'] = True
770 options[b'generaldelta'] = True
771
771
772 maxchainlen = None
772 maxchainlen = None
773 if sparserevlog:
773 if sparserevlog:
774 maxchainlen = revlogconst.SPARSE_REVLOG_MAX_CHAIN_LENGTH
774 maxchainlen = revlogconst.SPARSE_REVLOG_MAX_CHAIN_LENGTH
775 # experimental config: format.maxchainlen
775 # experimental config: format.maxchainlen
776 maxchainlen = ui.configint(b'format', b'maxchainlen', maxchainlen)
776 maxchainlen = ui.configint(b'format', b'maxchainlen', maxchainlen)
777 if maxchainlen is not None:
777 if maxchainlen is not None:
778 options[b'maxchainlen'] = maxchainlen
778 options[b'maxchainlen'] = maxchainlen
779
779
780 for r in requirements:
780 for r in requirements:
781 if r.startswith(b'exp-compression-'):
781 if r.startswith(b'exp-compression-'):
782 options[b'compengine'] = r[len(b'exp-compression-'):]
782 options[b'compengine'] = r[len(b'exp-compression-'):]
783
783
784 if repository.NARROW_REQUIREMENT in requirements:
784 if repository.NARROW_REQUIREMENT in requirements:
785 options[b'enableellipsis'] = True
785 options[b'enableellipsis'] = True
786
786
787 return options
787 return options
788
788
789 def makemain(**kwargs):
789 def makemain(**kwargs):
790 """Produce a type conforming to ``ilocalrepositorymain``."""
790 """Produce a type conforming to ``ilocalrepositorymain``."""
791 return localrepository
791 return localrepository
792
792
793 @interfaceutil.implementer(repository.ilocalrepositoryfilestorage)
793 @interfaceutil.implementer(repository.ilocalrepositoryfilestorage)
794 class revlogfilestorage(object):
794 class revlogfilestorage(object):
795 """File storage when using revlogs."""
795 """File storage when using revlogs."""
796
796
797 def file(self, path):
797 def file(self, path):
798 if path[0] == b'/':
798 if path[0] == b'/':
799 path = path[1:]
799 path = path[1:]
800
800
801 return filelog.filelog(self.svfs, path)
801 return filelog.filelog(self.svfs, path)
802
802
803 @interfaceutil.implementer(repository.ilocalrepositoryfilestorage)
803 @interfaceutil.implementer(repository.ilocalrepositoryfilestorage)
804 class revlognarrowfilestorage(object):
804 class revlognarrowfilestorage(object):
805 """File storage when using revlogs and narrow files."""
805 """File storage when using revlogs and narrow files."""
806
806
807 def file(self, path):
807 def file(self, path):
808 if path[0] == b'/':
808 if path[0] == b'/':
809 path = path[1:]
809 path = path[1:]
810
810
811 return filelog.narrowfilelog(self.svfs, path, self.narrowmatch())
811 return filelog.narrowfilelog(self.svfs, path, self.narrowmatch())
812
812
813 def makefilestorage(requirements, features, **kwargs):
813 def makefilestorage(requirements, features, **kwargs):
814 """Produce a type conforming to ``ilocalrepositoryfilestorage``."""
814 """Produce a type conforming to ``ilocalrepositoryfilestorage``."""
815 features.add(repository.REPO_FEATURE_REVLOG_FILE_STORAGE)
815 features.add(repository.REPO_FEATURE_REVLOG_FILE_STORAGE)
816 features.add(repository.REPO_FEATURE_STREAM_CLONE)
816 features.add(repository.REPO_FEATURE_STREAM_CLONE)
817
817
818 if repository.NARROW_REQUIREMENT in requirements:
818 if repository.NARROW_REQUIREMENT in requirements:
819 return revlognarrowfilestorage
819 return revlognarrowfilestorage
820 else:
820 else:
821 return revlogfilestorage
821 return revlogfilestorage
822
822
823 # List of repository interfaces and factory functions for them. Each
823 # List of repository interfaces and factory functions for them. Each
824 # will be called in order during ``makelocalrepository()`` to iteratively
824 # will be called in order during ``makelocalrepository()`` to iteratively
825 # derive the final type for a local repository instance. We capture the
825 # derive the final type for a local repository instance. We capture the
826 # function as a lambda so we don't hold a reference and the module-level
826 # function as a lambda so we don't hold a reference and the module-level
827 # functions can be wrapped.
827 # functions can be wrapped.
828 REPO_INTERFACES = [
828 REPO_INTERFACES = [
829 (repository.ilocalrepositorymain, lambda: makemain),
829 (repository.ilocalrepositorymain, lambda: makemain),
830 (repository.ilocalrepositoryfilestorage, lambda: makefilestorage),
830 (repository.ilocalrepositoryfilestorage, lambda: makefilestorage),
831 ]
831 ]
832
832
833 @interfaceutil.implementer(repository.ilocalrepositorymain)
833 @interfaceutil.implementer(repository.ilocalrepositorymain)
834 class localrepository(object):
834 class localrepository(object):
835 """Main class for representing local repositories.
835 """Main class for representing local repositories.
836
836
837 All local repositories are instances of this class.
837 All local repositories are instances of this class.
838
838
839 Constructed on its own, instances of this class are not usable as
839 Constructed on its own, instances of this class are not usable as
840 repository objects. To obtain a usable repository object, call
840 repository objects. To obtain a usable repository object, call
841 ``hg.repository()``, ``localrepo.instance()``, or
841 ``hg.repository()``, ``localrepo.instance()``, or
842 ``localrepo.makelocalrepository()``. The latter is the lowest-level.
842 ``localrepo.makelocalrepository()``. The latter is the lowest-level.
843 ``instance()`` adds support for creating new repositories.
843 ``instance()`` adds support for creating new repositories.
844 ``hg.repository()`` adds more extension integration, including calling
844 ``hg.repository()`` adds more extension integration, including calling
845 ``reposetup()``. Generally speaking, ``hg.repository()`` should be
845 ``reposetup()``. Generally speaking, ``hg.repository()`` should be
846 used.
846 used.
847 """
847 """
848
848
849 # obsolete experimental requirements:
849 # obsolete experimental requirements:
850 # - manifestv2: An experimental new manifest format that allowed
850 # - manifestv2: An experimental new manifest format that allowed
851 # for stem compression of long paths. Experiment ended up not
851 # for stem compression of long paths. Experiment ended up not
852 # being successful (repository sizes went up due to worse delta
852 # being successful (repository sizes went up due to worse delta
853 # chains), and the code was deleted in 4.6.
853 # chains), and the code was deleted in 4.6.
854 supportedformats = {
854 supportedformats = {
855 'revlogv1',
855 'revlogv1',
856 'generaldelta',
856 'generaldelta',
857 'treemanifest',
857 'treemanifest',
858 REVLOGV2_REQUIREMENT,
858 REVLOGV2_REQUIREMENT,
859 SPARSEREVLOG_REQUIREMENT,
859 SPARSEREVLOG_REQUIREMENT,
860 }
860 }
861 _basesupported = supportedformats | {
861 _basesupported = supportedformats | {
862 'store',
862 'store',
863 'fncache',
863 'fncache',
864 'shared',
864 'shared',
865 'relshared',
865 'relshared',
866 'dotencode',
866 'dotencode',
867 'exp-sparse',
867 'exp-sparse',
868 'internal-phase'
868 'internal-phase'
869 }
869 }
870
870
871 # list of prefix for file which can be written without 'wlock'
871 # list of prefix for file which can be written without 'wlock'
872 # Extensions should extend this list when needed
872 # Extensions should extend this list when needed
873 _wlockfreeprefix = {
873 _wlockfreeprefix = {
874 # We migh consider requiring 'wlock' for the next
874 # We migh consider requiring 'wlock' for the next
875 # two, but pretty much all the existing code assume
875 # two, but pretty much all the existing code assume
876 # wlock is not needed so we keep them excluded for
876 # wlock is not needed so we keep them excluded for
877 # now.
877 # now.
878 'hgrc',
878 'hgrc',
879 'requires',
879 'requires',
880 # XXX cache is a complicatged business someone
880 # XXX cache is a complicatged business someone
881 # should investigate this in depth at some point
881 # should investigate this in depth at some point
882 'cache/',
882 'cache/',
883 # XXX shouldn't be dirstate covered by the wlock?
883 # XXX shouldn't be dirstate covered by the wlock?
884 'dirstate',
884 'dirstate',
885 # XXX bisect was still a bit too messy at the time
885 # XXX bisect was still a bit too messy at the time
886 # this changeset was introduced. Someone should fix
886 # this changeset was introduced. Someone should fix
887 # the remainig bit and drop this line
887 # the remainig bit and drop this line
888 'bisect.state',
888 'bisect.state',
889 }
889 }
890
890
891 def __init__(self, baseui, ui, origroot, wdirvfs, hgvfs, requirements,
891 def __init__(self, baseui, ui, origroot, wdirvfs, hgvfs, requirements,
892 supportedrequirements, sharedpath, store, cachevfs,
892 supportedrequirements, sharedpath, store, cachevfs,
893 features, intents=None):
893 features, intents=None):
894 """Create a new local repository instance.
894 """Create a new local repository instance.
895
895
896 Most callers should use ``hg.repository()``, ``localrepo.instance()``,
896 Most callers should use ``hg.repository()``, ``localrepo.instance()``,
897 or ``localrepo.makelocalrepository()`` for obtaining a new repository
897 or ``localrepo.makelocalrepository()`` for obtaining a new repository
898 object.
898 object.
899
899
900 Arguments:
900 Arguments:
901
901
902 baseui
902 baseui
903 ``ui.ui`` instance that ``ui`` argument was based off of.
903 ``ui.ui`` instance that ``ui`` argument was based off of.
904
904
905 ui
905 ui
906 ``ui.ui`` instance for use by the repository.
906 ``ui.ui`` instance for use by the repository.
907
907
908 origroot
908 origroot
909 ``bytes`` path to working directory root of this repository.
909 ``bytes`` path to working directory root of this repository.
910
910
911 wdirvfs
911 wdirvfs
912 ``vfs.vfs`` rooted at the working directory.
912 ``vfs.vfs`` rooted at the working directory.
913
913
914 hgvfs
914 hgvfs
915 ``vfs.vfs`` rooted at .hg/
915 ``vfs.vfs`` rooted at .hg/
916
916
917 requirements
917 requirements
918 ``set`` of bytestrings representing repository opening requirements.
918 ``set`` of bytestrings representing repository opening requirements.
919
919
920 supportedrequirements
920 supportedrequirements
921 ``set`` of bytestrings representing repository requirements that we
921 ``set`` of bytestrings representing repository requirements that we
922 know how to open. May be a supetset of ``requirements``.
922 know how to open. May be a supetset of ``requirements``.
923
923
924 sharedpath
924 sharedpath
925 ``bytes`` Defining path to storage base directory. Points to a
925 ``bytes`` Defining path to storage base directory. Points to a
926 ``.hg/`` directory somewhere.
926 ``.hg/`` directory somewhere.
927
927
928 store
928 store
929 ``store.basicstore`` (or derived) instance providing access to
929 ``store.basicstore`` (or derived) instance providing access to
930 versioned storage.
930 versioned storage.
931
931
932 cachevfs
932 cachevfs
933 ``vfs.vfs`` used for cache files.
933 ``vfs.vfs`` used for cache files.
934
934
935 features
935 features
936 ``set`` of bytestrings defining features/capabilities of this
936 ``set`` of bytestrings defining features/capabilities of this
937 instance.
937 instance.
938
938
939 intents
939 intents
940 ``set`` of system strings indicating what this repo will be used
940 ``set`` of system strings indicating what this repo will be used
941 for.
941 for.
942 """
942 """
943 self.baseui = baseui
943 self.baseui = baseui
944 self.ui = ui
944 self.ui = ui
945 self.origroot = origroot
945 self.origroot = origroot
946 # vfs rooted at working directory.
946 # vfs rooted at working directory.
947 self.wvfs = wdirvfs
947 self.wvfs = wdirvfs
948 self.root = wdirvfs.base
948 self.root = wdirvfs.base
949 # vfs rooted at .hg/. Used to access most non-store paths.
949 # vfs rooted at .hg/. Used to access most non-store paths.
950 self.vfs = hgvfs
950 self.vfs = hgvfs
951 self.path = hgvfs.base
951 self.path = hgvfs.base
952 self.requirements = requirements
952 self.requirements = requirements
953 self.supported = supportedrequirements
953 self.supported = supportedrequirements
954 self.sharedpath = sharedpath
954 self.sharedpath = sharedpath
955 self.store = store
955 self.store = store
956 self.cachevfs = cachevfs
956 self.cachevfs = cachevfs
957 self.features = features
957 self.features = features
958
958
959 self.filtername = None
959 self.filtername = None
960
960
961 if (self.ui.configbool('devel', 'all-warnings') or
961 if (self.ui.configbool('devel', 'all-warnings') or
962 self.ui.configbool('devel', 'check-locks')):
962 self.ui.configbool('devel', 'check-locks')):
963 self.vfs.audit = self._getvfsward(self.vfs.audit)
963 self.vfs.audit = self._getvfsward(self.vfs.audit)
964 # A list of callback to shape the phase if no data were found.
964 # A list of callback to shape the phase if no data were found.
965 # Callback are in the form: func(repo, roots) --> processed root.
965 # Callback are in the form: func(repo, roots) --> processed root.
966 # This list it to be filled by extension during repo setup
966 # This list it to be filled by extension during repo setup
967 self._phasedefaults = []
967 self._phasedefaults = []
968
968
969 color.setup(self.ui)
969 color.setup(self.ui)
970
970
971 self.spath = self.store.path
971 self.spath = self.store.path
972 self.svfs = self.store.vfs
972 self.svfs = self.store.vfs
973 self.sjoin = self.store.join
973 self.sjoin = self.store.join
974 if (self.ui.configbool('devel', 'all-warnings') or
974 if (self.ui.configbool('devel', 'all-warnings') or
975 self.ui.configbool('devel', 'check-locks')):
975 self.ui.configbool('devel', 'check-locks')):
976 if util.safehasattr(self.svfs, 'vfs'): # this is filtervfs
976 if util.safehasattr(self.svfs, 'vfs'): # this is filtervfs
977 self.svfs.vfs.audit = self._getsvfsward(self.svfs.vfs.audit)
977 self.svfs.vfs.audit = self._getsvfsward(self.svfs.vfs.audit)
978 else: # standard vfs
978 else: # standard vfs
979 self.svfs.audit = self._getsvfsward(self.svfs.audit)
979 self.svfs.audit = self._getsvfsward(self.svfs.audit)
980
980
981 self._dirstatevalidatewarned = False
981 self._dirstatevalidatewarned = False
982
982
983 self._branchcaches = {}
983 self._branchcaches = {}
984 self._revbranchcache = None
984 self._revbranchcache = None
985 self._filterpats = {}
985 self._filterpats = {}
986 self._datafilters = {}
986 self._datafilters = {}
987 self._transref = self._lockref = self._wlockref = None
987 self._transref = self._lockref = self._wlockref = None
988
988
989 # A cache for various files under .hg/ that tracks file changes,
989 # A cache for various files under .hg/ that tracks file changes,
990 # (used by the filecache decorator)
990 # (used by the filecache decorator)
991 #
991 #
992 # Maps a property name to its util.filecacheentry
992 # Maps a property name to its util.filecacheentry
993 self._filecache = {}
993 self._filecache = {}
994
994
995 # hold sets of revision to be filtered
995 # hold sets of revision to be filtered
996 # should be cleared when something might have changed the filter value:
996 # should be cleared when something might have changed the filter value:
997 # - new changesets,
997 # - new changesets,
998 # - phase change,
998 # - phase change,
999 # - new obsolescence marker,
999 # - new obsolescence marker,
1000 # - working directory parent change,
1000 # - working directory parent change,
1001 # - bookmark changes
1001 # - bookmark changes
1002 self.filteredrevcache = {}
1002 self.filteredrevcache = {}
1003
1003
1004 # post-dirstate-status hooks
1004 # post-dirstate-status hooks
1005 self._postdsstatus = []
1005 self._postdsstatus = []
1006
1006
1007 # generic mapping between names and nodes
1007 # generic mapping between names and nodes
1008 self.names = namespaces.namespaces()
1008 self.names = namespaces.namespaces()
1009
1009
1010 # Key to signature value.
1010 # Key to signature value.
1011 self._sparsesignaturecache = {}
1011 self._sparsesignaturecache = {}
1012 # Signature to cached matcher instance.
1012 # Signature to cached matcher instance.
1013 self._sparsematchercache = {}
1013 self._sparsematchercache = {}
1014
1014
1015 def _getvfsward(self, origfunc):
1015 def _getvfsward(self, origfunc):
1016 """build a ward for self.vfs"""
1016 """build a ward for self.vfs"""
1017 rref = weakref.ref(self)
1017 rref = weakref.ref(self)
1018 def checkvfs(path, mode=None):
1018 def checkvfs(path, mode=None):
1019 ret = origfunc(path, mode=mode)
1019 ret = origfunc(path, mode=mode)
1020 repo = rref()
1020 repo = rref()
1021 if (repo is None
1021 if (repo is None
1022 or not util.safehasattr(repo, '_wlockref')
1022 or not util.safehasattr(repo, '_wlockref')
1023 or not util.safehasattr(repo, '_lockref')):
1023 or not util.safehasattr(repo, '_lockref')):
1024 return
1024 return
1025 if mode in (None, 'r', 'rb'):
1025 if mode in (None, 'r', 'rb'):
1026 return
1026 return
1027 if path.startswith(repo.path):
1027 if path.startswith(repo.path):
1028 # truncate name relative to the repository (.hg)
1028 # truncate name relative to the repository (.hg)
1029 path = path[len(repo.path) + 1:]
1029 path = path[len(repo.path) + 1:]
1030 if path.startswith('cache/'):
1030 if path.startswith('cache/'):
1031 msg = 'accessing cache with vfs instead of cachevfs: "%s"'
1031 msg = 'accessing cache with vfs instead of cachevfs: "%s"'
1032 repo.ui.develwarn(msg % path, stacklevel=2, config="cache-vfs")
1032 repo.ui.develwarn(msg % path, stacklevel=2, config="cache-vfs")
1033 if path.startswith('journal.'):
1033 if path.startswith('journal.'):
1034 # journal is covered by 'lock'
1034 # journal is covered by 'lock'
1035 if repo._currentlock(repo._lockref) is None:
1035 if repo._currentlock(repo._lockref) is None:
1036 repo.ui.develwarn('write with no lock: "%s"' % path,
1036 repo.ui.develwarn('write with no lock: "%s"' % path,
1037 stacklevel=2, config='check-locks')
1037 stacklevel=2, config='check-locks')
1038 elif repo._currentlock(repo._wlockref) is None:
1038 elif repo._currentlock(repo._wlockref) is None:
1039 # rest of vfs files are covered by 'wlock'
1039 # rest of vfs files are covered by 'wlock'
1040 #
1040 #
1041 # exclude special files
1041 # exclude special files
1042 for prefix in self._wlockfreeprefix:
1042 for prefix in self._wlockfreeprefix:
1043 if path.startswith(prefix):
1043 if path.startswith(prefix):
1044 return
1044 return
1045 repo.ui.develwarn('write with no wlock: "%s"' % path,
1045 repo.ui.develwarn('write with no wlock: "%s"' % path,
1046 stacklevel=2, config='check-locks')
1046 stacklevel=2, config='check-locks')
1047 return ret
1047 return ret
1048 return checkvfs
1048 return checkvfs
1049
1049
1050 def _getsvfsward(self, origfunc):
1050 def _getsvfsward(self, origfunc):
1051 """build a ward for self.svfs"""
1051 """build a ward for self.svfs"""
1052 rref = weakref.ref(self)
1052 rref = weakref.ref(self)
1053 def checksvfs(path, mode=None):
1053 def checksvfs(path, mode=None):
1054 ret = origfunc(path, mode=mode)
1054 ret = origfunc(path, mode=mode)
1055 repo = rref()
1055 repo = rref()
1056 if repo is None or not util.safehasattr(repo, '_lockref'):
1056 if repo is None or not util.safehasattr(repo, '_lockref'):
1057 return
1057 return
1058 if mode in (None, 'r', 'rb'):
1058 if mode in (None, 'r', 'rb'):
1059 return
1059 return
1060 if path.startswith(repo.sharedpath):
1060 if path.startswith(repo.sharedpath):
1061 # truncate name relative to the repository (.hg)
1061 # truncate name relative to the repository (.hg)
1062 path = path[len(repo.sharedpath) + 1:]
1062 path = path[len(repo.sharedpath) + 1:]
1063 if repo._currentlock(repo._lockref) is None:
1063 if repo._currentlock(repo._lockref) is None:
1064 repo.ui.develwarn('write with no lock: "%s"' % path,
1064 repo.ui.develwarn('write with no lock: "%s"' % path,
1065 stacklevel=3)
1065 stacklevel=3)
1066 return ret
1066 return ret
1067 return checksvfs
1067 return checksvfs
1068
1068
1069 def close(self):
1069 def close(self):
1070 self._writecaches()
1070 self._writecaches()
1071
1071
1072 def _writecaches(self):
1072 def _writecaches(self):
1073 if self._revbranchcache:
1073 if self._revbranchcache:
1074 self._revbranchcache.write()
1074 self._revbranchcache.write()
1075
1075
1076 def _restrictcapabilities(self, caps):
1076 def _restrictcapabilities(self, caps):
1077 if self.ui.configbool('experimental', 'bundle2-advertise'):
1077 if self.ui.configbool('experimental', 'bundle2-advertise'):
1078 caps = set(caps)
1078 caps = set(caps)
1079 capsblob = bundle2.encodecaps(bundle2.getrepocaps(self,
1079 capsblob = bundle2.encodecaps(bundle2.getrepocaps(self,
1080 role='client'))
1080 role='client'))
1081 caps.add('bundle2=' + urlreq.quote(capsblob))
1081 caps.add('bundle2=' + urlreq.quote(capsblob))
1082 return caps
1082 return caps
1083
1083
1084 def _writerequirements(self):
1084 def _writerequirements(self):
1085 scmutil.writerequires(self.vfs, self.requirements)
1085 scmutil.writerequires(self.vfs, self.requirements)
1086
1086
1087 # Don't cache auditor/nofsauditor, or you'll end up with reference cycle:
1087 # Don't cache auditor/nofsauditor, or you'll end up with reference cycle:
1088 # self -> auditor -> self._checknested -> self
1088 # self -> auditor -> self._checknested -> self
1089
1089
1090 @property
1090 @property
1091 def auditor(self):
1091 def auditor(self):
1092 # This is only used by context.workingctx.match in order to
1092 # This is only used by context.workingctx.match in order to
1093 # detect files in subrepos.
1093 # detect files in subrepos.
1094 return pathutil.pathauditor(self.root, callback=self._checknested)
1094 return pathutil.pathauditor(self.root, callback=self._checknested)
1095
1095
1096 @property
1096 @property
1097 def nofsauditor(self):
1097 def nofsauditor(self):
1098 # This is only used by context.basectx.match in order to detect
1098 # This is only used by context.basectx.match in order to detect
1099 # files in subrepos.
1099 # files in subrepos.
1100 return pathutil.pathauditor(self.root, callback=self._checknested,
1100 return pathutil.pathauditor(self.root, callback=self._checknested,
1101 realfs=False, cached=True)
1101 realfs=False, cached=True)
1102
1102
1103 def _checknested(self, path):
1103 def _checknested(self, path):
1104 """Determine if path is a legal nested repository."""
1104 """Determine if path is a legal nested repository."""
1105 if not path.startswith(self.root):
1105 if not path.startswith(self.root):
1106 return False
1106 return False
1107 subpath = path[len(self.root) + 1:]
1107 subpath = path[len(self.root) + 1:]
1108 normsubpath = util.pconvert(subpath)
1108 normsubpath = util.pconvert(subpath)
1109
1109
1110 # XXX: Checking against the current working copy is wrong in
1110 # XXX: Checking against the current working copy is wrong in
1111 # the sense that it can reject things like
1111 # the sense that it can reject things like
1112 #
1112 #
1113 # $ hg cat -r 10 sub/x.txt
1113 # $ hg cat -r 10 sub/x.txt
1114 #
1114 #
1115 # if sub/ is no longer a subrepository in the working copy
1115 # if sub/ is no longer a subrepository in the working copy
1116 # parent revision.
1116 # parent revision.
1117 #
1117 #
1118 # However, it can of course also allow things that would have
1118 # However, it can of course also allow things that would have
1119 # been rejected before, such as the above cat command if sub/
1119 # been rejected before, such as the above cat command if sub/
1120 # is a subrepository now, but was a normal directory before.
1120 # is a subrepository now, but was a normal directory before.
1121 # The old path auditor would have rejected by mistake since it
1121 # The old path auditor would have rejected by mistake since it
1122 # panics when it sees sub/.hg/.
1122 # panics when it sees sub/.hg/.
1123 #
1123 #
1124 # All in all, checking against the working copy seems sensible
1124 # All in all, checking against the working copy seems sensible
1125 # since we want to prevent access to nested repositories on
1125 # since we want to prevent access to nested repositories on
1126 # the filesystem *now*.
1126 # the filesystem *now*.
1127 ctx = self[None]
1127 ctx = self[None]
1128 parts = util.splitpath(subpath)
1128 parts = util.splitpath(subpath)
1129 while parts:
1129 while parts:
1130 prefix = '/'.join(parts)
1130 prefix = '/'.join(parts)
1131 if prefix in ctx.substate:
1131 if prefix in ctx.substate:
1132 if prefix == normsubpath:
1132 if prefix == normsubpath:
1133 return True
1133 return True
1134 else:
1134 else:
1135 sub = ctx.sub(prefix)
1135 sub = ctx.sub(prefix)
1136 return sub.checknested(subpath[len(prefix) + 1:])
1136 return sub.checknested(subpath[len(prefix) + 1:])
1137 else:
1137 else:
1138 parts.pop()
1138 parts.pop()
1139 return False
1139 return False
1140
1140
1141 def peer(self):
1141 def peer(self):
1142 return localpeer(self) # not cached to avoid reference cycle
1142 return localpeer(self) # not cached to avoid reference cycle
1143
1143
1144 def unfiltered(self):
1144 def unfiltered(self):
1145 """Return unfiltered version of the repository
1145 """Return unfiltered version of the repository
1146
1146
1147 Intended to be overwritten by filtered repo."""
1147 Intended to be overwritten by filtered repo."""
1148 return self
1148 return self
1149
1149
1150 def filtered(self, name, visibilityexceptions=None):
1150 def filtered(self, name, visibilityexceptions=None):
1151 """Return a filtered version of a repository"""
1151 """Return a filtered version of a repository"""
1152 cls = repoview.newtype(self.unfiltered().__class__)
1152 cls = repoview.newtype(self.unfiltered().__class__)
1153 return cls(self, name, visibilityexceptions)
1153 return cls(self, name, visibilityexceptions)
1154
1154
1155 @repofilecache('bookmarks', 'bookmarks.current')
1155 @repofilecache('bookmarks', 'bookmarks.current')
1156 def _bookmarks(self):
1156 def _bookmarks(self):
1157 return bookmarks.bmstore(self)
1157 return bookmarks.bmstore(self)
1158
1158
1159 @property
1159 @property
1160 def _activebookmark(self):
1160 def _activebookmark(self):
1161 return self._bookmarks.active
1161 return self._bookmarks.active
1162
1162
1163 # _phasesets depend on changelog. what we need is to call
1163 # _phasesets depend on changelog. what we need is to call
1164 # _phasecache.invalidate() if '00changelog.i' was changed, but it
1164 # _phasecache.invalidate() if '00changelog.i' was changed, but it
1165 # can't be easily expressed in filecache mechanism.
1165 # can't be easily expressed in filecache mechanism.
1166 @storecache('phaseroots', '00changelog.i')
1166 @storecache('phaseroots', '00changelog.i')
1167 def _phasecache(self):
1167 def _phasecache(self):
1168 return phases.phasecache(self, self._phasedefaults)
1168 return phases.phasecache(self, self._phasedefaults)
1169
1169
1170 @storecache('obsstore')
1170 @storecache('obsstore')
1171 def obsstore(self):
1171 def obsstore(self):
1172 return obsolete.makestore(self.ui, self)
1172 return obsolete.makestore(self.ui, self)
1173
1173
1174 @storecache('00changelog.i')
1174 @storecache('00changelog.i')
1175 def changelog(self):
1175 def changelog(self):
1176 return changelog.changelog(self.svfs,
1176 return changelog.changelog(self.svfs,
1177 trypending=txnutil.mayhavepending(self.root))
1177 trypending=txnutil.mayhavepending(self.root))
1178
1178
1179 @storecache('00manifest.i')
1179 @storecache('00manifest.i')
1180 def manifestlog(self):
1180 def manifestlog(self):
1181 rootstore = manifest.manifestrevlog(self.svfs)
1181 rootstore = manifest.manifestrevlog(self.svfs)
1182 return manifest.manifestlog(self.svfs, self, rootstore)
1182 return manifest.manifestlog(self.svfs, self, rootstore)
1183
1183
1184 @repofilecache('dirstate')
1184 @repofilecache('dirstate')
1185 def dirstate(self):
1185 def dirstate(self):
1186 return self._makedirstate()
1186 return self._makedirstate()
1187
1187
1188 def _makedirstate(self):
1188 def _makedirstate(self):
1189 """Extension point for wrapping the dirstate per-repo."""
1189 """Extension point for wrapping the dirstate per-repo."""
1190 sparsematchfn = lambda: sparse.matcher(self)
1190 sparsematchfn = lambda: sparse.matcher(self)
1191
1191
1192 return dirstate.dirstate(self.vfs, self.ui, self.root,
1192 return dirstate.dirstate(self.vfs, self.ui, self.root,
1193 self._dirstatevalidate, sparsematchfn)
1193 self._dirstatevalidate, sparsematchfn)
1194
1194
1195 def _dirstatevalidate(self, node):
1195 def _dirstatevalidate(self, node):
1196 try:
1196 try:
1197 self.changelog.rev(node)
1197 self.changelog.rev(node)
1198 return node
1198 return node
1199 except error.LookupError:
1199 except error.LookupError:
1200 if not self._dirstatevalidatewarned:
1200 if not self._dirstatevalidatewarned:
1201 self._dirstatevalidatewarned = True
1201 self._dirstatevalidatewarned = True
1202 self.ui.warn(_("warning: ignoring unknown"
1202 self.ui.warn(_("warning: ignoring unknown"
1203 " working parent %s!\n") % short(node))
1203 " working parent %s!\n") % short(node))
1204 return nullid
1204 return nullid
1205
1205
1206 @storecache(narrowspec.FILENAME)
1206 @storecache(narrowspec.FILENAME)
1207 def narrowpats(self):
1207 def narrowpats(self):
1208 """matcher patterns for this repository's narrowspec
1208 """matcher patterns for this repository's narrowspec
1209
1209
1210 A tuple of (includes, excludes).
1210 A tuple of (includes, excludes).
1211 """
1211 """
1212 return narrowspec.load(self)
1212 return narrowspec.load(self)
1213
1213
1214 @storecache(narrowspec.FILENAME)
1214 @storecache(narrowspec.FILENAME)
1215 def _narrowmatch(self):
1215 def _narrowmatch(self):
1216 if repository.NARROW_REQUIREMENT not in self.requirements:
1216 if repository.NARROW_REQUIREMENT not in self.requirements:
1217 return matchmod.always(self.root, '')
1217 return matchmod.always(self.root, '')
1218 include, exclude = self.narrowpats
1218 include, exclude = self.narrowpats
1219 return narrowspec.match(self.root, include=include, exclude=exclude)
1219 return narrowspec.match(self.root, include=include, exclude=exclude)
1220
1220
1221 def narrowmatch(self, match=None, includeexact=False):
1221 def narrowmatch(self, match=None, includeexact=False):
1222 """matcher corresponding the the repo's narrowspec
1222 """matcher corresponding the the repo's narrowspec
1223
1223
1224 If `match` is given, then that will be intersected with the narrow
1224 If `match` is given, then that will be intersected with the narrow
1225 matcher.
1225 matcher.
1226
1226
1227 If `includeexact` is True, then any exact matches from `match` will
1227 If `includeexact` is True, then any exact matches from `match` will
1228 be included even if they're outside the narrowspec.
1228 be included even if they're outside the narrowspec.
1229 """
1229 """
1230 if match:
1230 if match:
1231 if includeexact and not self._narrowmatch.always():
1231 if includeexact and not self._narrowmatch.always():
1232 # do not exclude explicitly-specified paths so that they can
1232 # do not exclude explicitly-specified paths so that they can
1233 # be warned later on
1233 # be warned later on
1234 em = matchmod.exact(match._root, match._cwd, match.files())
1234 em = matchmod.exact(match._root, match._cwd, match.files())
1235 nm = matchmod.unionmatcher([self._narrowmatch, em])
1235 nm = matchmod.unionmatcher([self._narrowmatch, em])
1236 return matchmod.intersectmatchers(match, nm)
1236 return matchmod.intersectmatchers(match, nm)
1237 return matchmod.intersectmatchers(match, self._narrowmatch)
1237 return matchmod.intersectmatchers(match, self._narrowmatch)
1238 return self._narrowmatch
1238 return self._narrowmatch
1239
1239
1240 def setnarrowpats(self, newincludes, newexcludes):
1240 def setnarrowpats(self, newincludes, newexcludes):
1241 narrowspec.save(self, newincludes, newexcludes)
1241 narrowspec.save(self, newincludes, newexcludes)
1242 self.invalidate(clearfilecache=True)
1242 self.invalidate(clearfilecache=True)
1243
1243
1244 def __getitem__(self, changeid):
1244 def __getitem__(self, changeid):
1245 if changeid is None:
1245 if changeid is None:
1246 return context.workingctx(self)
1246 return context.workingctx(self)
1247 if isinstance(changeid, context.basectx):
1247 if isinstance(changeid, context.basectx):
1248 return changeid
1248 return changeid
1249 if isinstance(changeid, slice):
1249 if isinstance(changeid, slice):
1250 # wdirrev isn't contiguous so the slice shouldn't include it
1250 # wdirrev isn't contiguous so the slice shouldn't include it
1251 return [self[i]
1251 return [self[i]
1252 for i in pycompat.xrange(*changeid.indices(len(self)))
1252 for i in pycompat.xrange(*changeid.indices(len(self)))
1253 if i not in self.changelog.filteredrevs]
1253 if i not in self.changelog.filteredrevs]
1254 try:
1254 try:
1255 if isinstance(changeid, int):
1255 if isinstance(changeid, int):
1256 node = self.changelog.node(changeid)
1256 node = self.changelog.node(changeid)
1257 rev = changeid
1257 rev = changeid
1258 elif changeid == 'null':
1258 elif changeid == 'null':
1259 node = nullid
1259 node = nullid
1260 rev = nullrev
1260 rev = nullrev
1261 elif changeid == 'tip':
1261 elif changeid == 'tip':
1262 node = self.changelog.tip()
1262 node = self.changelog.tip()
1263 rev = self.changelog.rev(node)
1263 rev = self.changelog.rev(node)
1264 elif changeid == '.':
1264 elif changeid == '.':
1265 # this is a hack to delay/avoid loading obsmarkers
1265 # this is a hack to delay/avoid loading obsmarkers
1266 # when we know that '.' won't be hidden
1266 # when we know that '.' won't be hidden
1267 node = self.dirstate.p1()
1267 node = self.dirstate.p1()
1268 rev = self.unfiltered().changelog.rev(node)
1268 rev = self.unfiltered().changelog.rev(node)
1269 elif len(changeid) == 20:
1269 elif len(changeid) == 20:
1270 try:
1270 try:
1271 node = changeid
1271 node = changeid
1272 rev = self.changelog.rev(changeid)
1272 rev = self.changelog.rev(changeid)
1273 except error.FilteredLookupError:
1273 except error.FilteredLookupError:
1274 changeid = hex(changeid) # for the error message
1274 changeid = hex(changeid) # for the error message
1275 raise
1275 raise
1276 except LookupError:
1276 except LookupError:
1277 # check if it might have come from damaged dirstate
1277 # check if it might have come from damaged dirstate
1278 #
1278 #
1279 # XXX we could avoid the unfiltered if we had a recognizable
1279 # XXX we could avoid the unfiltered if we had a recognizable
1280 # exception for filtered changeset access
1280 # exception for filtered changeset access
1281 if (self.local()
1281 if (self.local()
1282 and changeid in self.unfiltered().dirstate.parents()):
1282 and changeid in self.unfiltered().dirstate.parents()):
1283 msg = _("working directory has unknown parent '%s'!")
1283 msg = _("working directory has unknown parent '%s'!")
1284 raise error.Abort(msg % short(changeid))
1284 raise error.Abort(msg % short(changeid))
1285 changeid = hex(changeid) # for the error message
1285 changeid = hex(changeid) # for the error message
1286 raise
1286 raise
1287
1287
1288 elif len(changeid) == 40:
1288 elif len(changeid) == 40:
1289 node = bin(changeid)
1289 node = bin(changeid)
1290 rev = self.changelog.rev(node)
1290 rev = self.changelog.rev(node)
1291 else:
1291 else:
1292 raise error.ProgrammingError(
1292 raise error.ProgrammingError(
1293 "unsupported changeid '%s' of type %s" %
1293 "unsupported changeid '%s' of type %s" %
1294 (changeid, type(changeid)))
1294 (changeid, type(changeid)))
1295
1295
1296 return context.changectx(self, rev, node)
1296 return context.changectx(self, rev, node)
1297
1297
1298 except (error.FilteredIndexError, error.FilteredLookupError):
1298 except (error.FilteredIndexError, error.FilteredLookupError):
1299 raise error.FilteredRepoLookupError(_("filtered revision '%s'")
1299 raise error.FilteredRepoLookupError(_("filtered revision '%s'")
1300 % pycompat.bytestr(changeid))
1300 % pycompat.bytestr(changeid))
1301 except (IndexError, LookupError):
1301 except (IndexError, LookupError):
1302 raise error.RepoLookupError(
1302 raise error.RepoLookupError(
1303 _("unknown revision '%s'") % pycompat.bytestr(changeid))
1303 _("unknown revision '%s'") % pycompat.bytestr(changeid))
1304 except error.WdirUnsupported:
1304 except error.WdirUnsupported:
1305 return context.workingctx(self)
1305 return context.workingctx(self)
1306
1306
1307 def __contains__(self, changeid):
1307 def __contains__(self, changeid):
1308 """True if the given changeid exists
1308 """True if the given changeid exists
1309
1309
1310 error.AmbiguousPrefixLookupError is raised if an ambiguous node
1310 error.AmbiguousPrefixLookupError is raised if an ambiguous node
1311 specified.
1311 specified.
1312 """
1312 """
1313 try:
1313 try:
1314 self[changeid]
1314 self[changeid]
1315 return True
1315 return True
1316 except error.RepoLookupError:
1316 except error.RepoLookupError:
1317 return False
1317 return False
1318
1318
1319 def __nonzero__(self):
1319 def __nonzero__(self):
1320 return True
1320 return True
1321
1321
1322 __bool__ = __nonzero__
1322 __bool__ = __nonzero__
1323
1323
1324 def __len__(self):
1324 def __len__(self):
1325 # no need to pay the cost of repoview.changelog
1325 # no need to pay the cost of repoview.changelog
1326 unfi = self.unfiltered()
1326 unfi = self.unfiltered()
1327 return len(unfi.changelog)
1327 return len(unfi.changelog)
1328
1328
1329 def __iter__(self):
1329 def __iter__(self):
1330 return iter(self.changelog)
1330 return iter(self.changelog)
1331
1331
1332 def revs(self, expr, *args):
1332 def revs(self, expr, *args):
1333 '''Find revisions matching a revset.
1333 '''Find revisions matching a revset.
1334
1334
1335 The revset is specified as a string ``expr`` that may contain
1335 The revset is specified as a string ``expr`` that may contain
1336 %-formatting to escape certain types. See ``revsetlang.formatspec``.
1336 %-formatting to escape certain types. See ``revsetlang.formatspec``.
1337
1337
1338 Revset aliases from the configuration are not expanded. To expand
1338 Revset aliases from the configuration are not expanded. To expand
1339 user aliases, consider calling ``scmutil.revrange()`` or
1339 user aliases, consider calling ``scmutil.revrange()`` or
1340 ``repo.anyrevs([expr], user=True)``.
1340 ``repo.anyrevs([expr], user=True)``.
1341
1341
1342 Returns a revset.abstractsmartset, which is a list-like interface
1342 Returns a revset.abstractsmartset, which is a list-like interface
1343 that contains integer revisions.
1343 that contains integer revisions.
1344 '''
1344 '''
1345 expr = revsetlang.formatspec(expr, *args)
1345 expr = revsetlang.formatspec(expr, *args)
1346 m = revset.match(None, expr)
1346 m = revset.match(None, expr)
1347 return m(self)
1347 return m(self)
1348
1348
1349 def set(self, expr, *args):
1349 def set(self, expr, *args):
1350 '''Find revisions matching a revset and emit changectx instances.
1350 '''Find revisions matching a revset and emit changectx instances.
1351
1351
1352 This is a convenience wrapper around ``revs()`` that iterates the
1352 This is a convenience wrapper around ``revs()`` that iterates the
1353 result and is a generator of changectx instances.
1353 result and is a generator of changectx instances.
1354
1354
1355 Revset aliases from the configuration are not expanded. To expand
1355 Revset aliases from the configuration are not expanded. To expand
1356 user aliases, consider calling ``scmutil.revrange()``.
1356 user aliases, consider calling ``scmutil.revrange()``.
1357 '''
1357 '''
1358 for r in self.revs(expr, *args):
1358 for r in self.revs(expr, *args):
1359 yield self[r]
1359 yield self[r]
1360
1360
1361 def anyrevs(self, specs, user=False, localalias=None):
1361 def anyrevs(self, specs, user=False, localalias=None):
1362 '''Find revisions matching one of the given revsets.
1362 '''Find revisions matching one of the given revsets.
1363
1363
1364 Revset aliases from the configuration are not expanded by default. To
1364 Revset aliases from the configuration are not expanded by default. To
1365 expand user aliases, specify ``user=True``. To provide some local
1365 expand user aliases, specify ``user=True``. To provide some local
1366 definitions overriding user aliases, set ``localalias`` to
1366 definitions overriding user aliases, set ``localalias`` to
1367 ``{name: definitionstring}``.
1367 ``{name: definitionstring}``.
1368 '''
1368 '''
1369 if user:
1369 if user:
1370 m = revset.matchany(self.ui, specs,
1370 m = revset.matchany(self.ui, specs,
1371 lookup=revset.lookupfn(self),
1371 lookup=revset.lookupfn(self),
1372 localalias=localalias)
1372 localalias=localalias)
1373 else:
1373 else:
1374 m = revset.matchany(None, specs, localalias=localalias)
1374 m = revset.matchany(None, specs, localalias=localalias)
1375 return m(self)
1375 return m(self)
1376
1376
1377 def url(self):
1377 def url(self):
1378 return 'file:' + self.root
1378 return 'file:' + self.root
1379
1379
1380 def hook(self, name, throw=False, **args):
1380 def hook(self, name, throw=False, **args):
1381 """Call a hook, passing this repo instance.
1381 """Call a hook, passing this repo instance.
1382
1382
1383 This a convenience method to aid invoking hooks. Extensions likely
1383 This a convenience method to aid invoking hooks. Extensions likely
1384 won't call this unless they have registered a custom hook or are
1384 won't call this unless they have registered a custom hook or are
1385 replacing code that is expected to call a hook.
1385 replacing code that is expected to call a hook.
1386 """
1386 """
1387 return hook.hook(self.ui, self, name, throw, **args)
1387 return hook.hook(self.ui, self, name, throw, **args)
1388
1388
1389 @filteredpropertycache
1389 @filteredpropertycache
1390 def _tagscache(self):
1390 def _tagscache(self):
1391 '''Returns a tagscache object that contains various tags related
1391 '''Returns a tagscache object that contains various tags related
1392 caches.'''
1392 caches.'''
1393
1393
1394 # This simplifies its cache management by having one decorated
1394 # This simplifies its cache management by having one decorated
1395 # function (this one) and the rest simply fetch things from it.
1395 # function (this one) and the rest simply fetch things from it.
1396 class tagscache(object):
1396 class tagscache(object):
1397 def __init__(self):
1397 def __init__(self):
1398 # These two define the set of tags for this repository. tags
1398 # These two define the set of tags for this repository. tags
1399 # maps tag name to node; tagtypes maps tag name to 'global' or
1399 # maps tag name to node; tagtypes maps tag name to 'global' or
1400 # 'local'. (Global tags are defined by .hgtags across all
1400 # 'local'. (Global tags are defined by .hgtags across all
1401 # heads, and local tags are defined in .hg/localtags.)
1401 # heads, and local tags are defined in .hg/localtags.)
1402 # They constitute the in-memory cache of tags.
1402 # They constitute the in-memory cache of tags.
1403 self.tags = self.tagtypes = None
1403 self.tags = self.tagtypes = None
1404
1404
1405 self.nodetagscache = self.tagslist = None
1405 self.nodetagscache = self.tagslist = None
1406
1406
1407 cache = tagscache()
1407 cache = tagscache()
1408 cache.tags, cache.tagtypes = self._findtags()
1408 cache.tags, cache.tagtypes = self._findtags()
1409
1409
1410 return cache
1410 return cache
1411
1411
1412 def tags(self):
1412 def tags(self):
1413 '''return a mapping of tag to node'''
1413 '''return a mapping of tag to node'''
1414 t = {}
1414 t = {}
1415 if self.changelog.filteredrevs:
1415 if self.changelog.filteredrevs:
1416 tags, tt = self._findtags()
1416 tags, tt = self._findtags()
1417 else:
1417 else:
1418 tags = self._tagscache.tags
1418 tags = self._tagscache.tags
1419 for k, v in tags.iteritems():
1419 for k, v in tags.iteritems():
1420 try:
1420 try:
1421 # ignore tags to unknown nodes
1421 # ignore tags to unknown nodes
1422 self.changelog.rev(v)
1422 self.changelog.rev(v)
1423 t[k] = v
1423 t[k] = v
1424 except (error.LookupError, ValueError):
1424 except (error.LookupError, ValueError):
1425 pass
1425 pass
1426 return t
1426 return t
1427
1427
1428 def _findtags(self):
1428 def _findtags(self):
1429 '''Do the hard work of finding tags. Return a pair of dicts
1429 '''Do the hard work of finding tags. Return a pair of dicts
1430 (tags, tagtypes) where tags maps tag name to node, and tagtypes
1430 (tags, tagtypes) where tags maps tag name to node, and tagtypes
1431 maps tag name to a string like \'global\' or \'local\'.
1431 maps tag name to a string like \'global\' or \'local\'.
1432 Subclasses or extensions are free to add their own tags, but
1432 Subclasses or extensions are free to add their own tags, but
1433 should be aware that the returned dicts will be retained for the
1433 should be aware that the returned dicts will be retained for the
1434 duration of the localrepo object.'''
1434 duration of the localrepo object.'''
1435
1435
1436 # XXX what tagtype should subclasses/extensions use? Currently
1436 # XXX what tagtype should subclasses/extensions use? Currently
1437 # mq and bookmarks add tags, but do not set the tagtype at all.
1437 # mq and bookmarks add tags, but do not set the tagtype at all.
1438 # Should each extension invent its own tag type? Should there
1438 # Should each extension invent its own tag type? Should there
1439 # be one tagtype for all such "virtual" tags? Or is the status
1439 # be one tagtype for all such "virtual" tags? Or is the status
1440 # quo fine?
1440 # quo fine?
1441
1441
1442
1442
1443 # map tag name to (node, hist)
1443 # map tag name to (node, hist)
1444 alltags = tagsmod.findglobaltags(self.ui, self)
1444 alltags = tagsmod.findglobaltags(self.ui, self)
1445 # map tag name to tag type
1445 # map tag name to tag type
1446 tagtypes = dict((tag, 'global') for tag in alltags)
1446 tagtypes = dict((tag, 'global') for tag in alltags)
1447
1447
1448 tagsmod.readlocaltags(self.ui, self, alltags, tagtypes)
1448 tagsmod.readlocaltags(self.ui, self, alltags, tagtypes)
1449
1449
1450 # Build the return dicts. Have to re-encode tag names because
1450 # Build the return dicts. Have to re-encode tag names because
1451 # the tags module always uses UTF-8 (in order not to lose info
1451 # the tags module always uses UTF-8 (in order not to lose info
1452 # writing to the cache), but the rest of Mercurial wants them in
1452 # writing to the cache), but the rest of Mercurial wants them in
1453 # local encoding.
1453 # local encoding.
1454 tags = {}
1454 tags = {}
1455 for (name, (node, hist)) in alltags.iteritems():
1455 for (name, (node, hist)) in alltags.iteritems():
1456 if node != nullid:
1456 if node != nullid:
1457 tags[encoding.tolocal(name)] = node
1457 tags[encoding.tolocal(name)] = node
1458 tags['tip'] = self.changelog.tip()
1458 tags['tip'] = self.changelog.tip()
1459 tagtypes = dict([(encoding.tolocal(name), value)
1459 tagtypes = dict([(encoding.tolocal(name), value)
1460 for (name, value) in tagtypes.iteritems()])
1460 for (name, value) in tagtypes.iteritems()])
1461 return (tags, tagtypes)
1461 return (tags, tagtypes)
1462
1462
1463 def tagtype(self, tagname):
1463 def tagtype(self, tagname):
1464 '''
1464 '''
1465 return the type of the given tag. result can be:
1465 return the type of the given tag. result can be:
1466
1466
1467 'local' : a local tag
1467 'local' : a local tag
1468 'global' : a global tag
1468 'global' : a global tag
1469 None : tag does not exist
1469 None : tag does not exist
1470 '''
1470 '''
1471
1471
1472 return self._tagscache.tagtypes.get(tagname)
1472 return self._tagscache.tagtypes.get(tagname)
1473
1473
1474 def tagslist(self):
1474 def tagslist(self):
1475 '''return a list of tags ordered by revision'''
1475 '''return a list of tags ordered by revision'''
1476 if not self._tagscache.tagslist:
1476 if not self._tagscache.tagslist:
1477 l = []
1477 l = []
1478 for t, n in self.tags().iteritems():
1478 for t, n in self.tags().iteritems():
1479 l.append((self.changelog.rev(n), t, n))
1479 l.append((self.changelog.rev(n), t, n))
1480 self._tagscache.tagslist = [(t, n) for r, t, n in sorted(l)]
1480 self._tagscache.tagslist = [(t, n) for r, t, n in sorted(l)]
1481
1481
1482 return self._tagscache.tagslist
1482 return self._tagscache.tagslist
1483
1483
1484 def nodetags(self, node):
1484 def nodetags(self, node):
1485 '''return the tags associated with a node'''
1485 '''return the tags associated with a node'''
1486 if not self._tagscache.nodetagscache:
1486 if not self._tagscache.nodetagscache:
1487 nodetagscache = {}
1487 nodetagscache = {}
1488 for t, n in self._tagscache.tags.iteritems():
1488 for t, n in self._tagscache.tags.iteritems():
1489 nodetagscache.setdefault(n, []).append(t)
1489 nodetagscache.setdefault(n, []).append(t)
1490 for tags in nodetagscache.itervalues():
1490 for tags in nodetagscache.itervalues():
1491 tags.sort()
1491 tags.sort()
1492 self._tagscache.nodetagscache = nodetagscache
1492 self._tagscache.nodetagscache = nodetagscache
1493 return self._tagscache.nodetagscache.get(node, [])
1493 return self._tagscache.nodetagscache.get(node, [])
1494
1494
1495 def nodebookmarks(self, node):
1495 def nodebookmarks(self, node):
1496 """return the list of bookmarks pointing to the specified node"""
1496 """return the list of bookmarks pointing to the specified node"""
1497 return self._bookmarks.names(node)
1497 return self._bookmarks.names(node)
1498
1498
1499 def branchmap(self):
1499 def branchmap(self):
1500 '''returns a dictionary {branch: [branchheads]} with branchheads
1500 '''returns a dictionary {branch: [branchheads]} with branchheads
1501 ordered by increasing revision number'''
1501 ordered by increasing revision number'''
1502 branchmap.updatecache(self)
1502 branchmap.updatecache(self)
1503 return self._branchcaches[self.filtername]
1503 return self._branchcaches[self.filtername]
1504
1504
1505 @unfilteredmethod
1505 @unfilteredmethod
1506 def revbranchcache(self):
1506 def revbranchcache(self):
1507 if not self._revbranchcache:
1507 if not self._revbranchcache:
1508 self._revbranchcache = branchmap.revbranchcache(self.unfiltered())
1508 self._revbranchcache = branchmap.revbranchcache(self.unfiltered())
1509 return self._revbranchcache
1509 return self._revbranchcache
1510
1510
1511 def branchtip(self, branch, ignoremissing=False):
1511 def branchtip(self, branch, ignoremissing=False):
1512 '''return the tip node for a given branch
1512 '''return the tip node for a given branch
1513
1513
1514 If ignoremissing is True, then this method will not raise an error.
1514 If ignoremissing is True, then this method will not raise an error.
1515 This is helpful for callers that only expect None for a missing branch
1515 This is helpful for callers that only expect None for a missing branch
1516 (e.g. namespace).
1516 (e.g. namespace).
1517
1517
1518 '''
1518 '''
1519 try:
1519 try:
1520 return self.branchmap().branchtip(branch)
1520 return self.branchmap().branchtip(branch)
1521 except KeyError:
1521 except KeyError:
1522 if not ignoremissing:
1522 if not ignoremissing:
1523 raise error.RepoLookupError(_("unknown branch '%s'") % branch)
1523 raise error.RepoLookupError(_("unknown branch '%s'") % branch)
1524 else:
1524 else:
1525 pass
1525 pass
1526
1526
1527 def lookup(self, key):
1527 def lookup(self, key):
1528 return scmutil.revsymbol(self, key).node()
1528 return scmutil.revsymbol(self, key).node()
1529
1529
1530 def lookupbranch(self, key):
1530 def lookupbranch(self, key):
1531 if key in self.branchmap():
1531 if key in self.branchmap():
1532 return key
1532 return key
1533
1533
1534 return scmutil.revsymbol(self, key).branch()
1534 return scmutil.revsymbol(self, key).branch()
1535
1535
1536 def known(self, nodes):
1536 def known(self, nodes):
1537 cl = self.changelog
1537 cl = self.changelog
1538 nm = cl.nodemap
1538 nm = cl.nodemap
1539 filtered = cl.filteredrevs
1539 filtered = cl.filteredrevs
1540 result = []
1540 result = []
1541 for n in nodes:
1541 for n in nodes:
1542 r = nm.get(n)
1542 r = nm.get(n)
1543 resp = not (r is None or r in filtered)
1543 resp = not (r is None or r in filtered)
1544 result.append(resp)
1544 result.append(resp)
1545 return result
1545 return result
1546
1546
1547 def local(self):
1547 def local(self):
1548 return self
1548 return self
1549
1549
1550 def publishing(self):
1550 def publishing(self):
1551 # it's safe (and desirable) to trust the publish flag unconditionally
1551 # it's safe (and desirable) to trust the publish flag unconditionally
1552 # so that we don't finalize changes shared between users via ssh or nfs
1552 # so that we don't finalize changes shared between users via ssh or nfs
1553 return self.ui.configbool('phases', 'publish', untrusted=True)
1553 return self.ui.configbool('phases', 'publish', untrusted=True)
1554
1554
1555 def cancopy(self):
1555 def cancopy(self):
1556 # so statichttprepo's override of local() works
1556 # so statichttprepo's override of local() works
1557 if not self.local():
1557 if not self.local():
1558 return False
1558 return False
1559 if not self.publishing():
1559 if not self.publishing():
1560 return True
1560 return True
1561 # if publishing we can't copy if there is filtered content
1561 # if publishing we can't copy if there is filtered content
1562 return not self.filtered('visible').changelog.filteredrevs
1562 return not self.filtered('visible').changelog.filteredrevs
1563
1563
1564 def shared(self):
1564 def shared(self):
1565 '''the type of shared repository (None if not shared)'''
1565 '''the type of shared repository (None if not shared)'''
1566 if self.sharedpath != self.path:
1566 if self.sharedpath != self.path:
1567 return 'store'
1567 return 'store'
1568 return None
1568 return None
1569
1569
1570 def wjoin(self, f, *insidef):
1570 def wjoin(self, f, *insidef):
1571 return self.vfs.reljoin(self.root, f, *insidef)
1571 return self.vfs.reljoin(self.root, f, *insidef)
1572
1572
1573 def setparents(self, p1, p2=nullid):
1573 def setparents(self, p1, p2=nullid):
1574 with self.dirstate.parentchange():
1574 with self.dirstate.parentchange():
1575 copies = self.dirstate.setparents(p1, p2)
1575 copies = self.dirstate.setparents(p1, p2)
1576 pctx = self[p1]
1576 pctx = self[p1]
1577 if copies:
1577 if copies:
1578 # Adjust copy records, the dirstate cannot do it, it
1578 # Adjust copy records, the dirstate cannot do it, it
1579 # requires access to parents manifests. Preserve them
1579 # requires access to parents manifests. Preserve them
1580 # only for entries added to first parent.
1580 # only for entries added to first parent.
1581 for f in copies:
1581 for f in copies:
1582 if f not in pctx and copies[f] in pctx:
1582 if f not in pctx and copies[f] in pctx:
1583 self.dirstate.copy(copies[f], f)
1583 self.dirstate.copy(copies[f], f)
1584 if p2 == nullid:
1584 if p2 == nullid:
1585 for f, s in sorted(self.dirstate.copies().items()):
1585 for f, s in sorted(self.dirstate.copies().items()):
1586 if f not in pctx and s not in pctx:
1586 if f not in pctx and s not in pctx:
1587 self.dirstate.copy(None, f)
1587 self.dirstate.copy(None, f)
1588
1588
1589 def filectx(self, path, changeid=None, fileid=None, changectx=None):
1589 def filectx(self, path, changeid=None, fileid=None, changectx=None):
1590 """changeid can be a changeset revision, node, or tag.
1590 """changeid must be a changeset revision, if specified.
1591 fileid can be a file revision or node."""
1591 fileid can be a file revision or node."""
1592 return context.filectx(self, path, changeid, fileid,
1592 return context.filectx(self, path, changeid, fileid,
1593 changectx=changectx)
1593 changectx=changectx)
1594
1594
1595 def getcwd(self):
1595 def getcwd(self):
1596 return self.dirstate.getcwd()
1596 return self.dirstate.getcwd()
1597
1597
1598 def pathto(self, f, cwd=None):
1598 def pathto(self, f, cwd=None):
1599 return self.dirstate.pathto(f, cwd)
1599 return self.dirstate.pathto(f, cwd)
1600
1600
1601 def _loadfilter(self, filter):
1601 def _loadfilter(self, filter):
1602 if filter not in self._filterpats:
1602 if filter not in self._filterpats:
1603 l = []
1603 l = []
1604 for pat, cmd in self.ui.configitems(filter):
1604 for pat, cmd in self.ui.configitems(filter):
1605 if cmd == '!':
1605 if cmd == '!':
1606 continue
1606 continue
1607 mf = matchmod.match(self.root, '', [pat])
1607 mf = matchmod.match(self.root, '', [pat])
1608 fn = None
1608 fn = None
1609 params = cmd
1609 params = cmd
1610 for name, filterfn in self._datafilters.iteritems():
1610 for name, filterfn in self._datafilters.iteritems():
1611 if cmd.startswith(name):
1611 if cmd.startswith(name):
1612 fn = filterfn
1612 fn = filterfn
1613 params = cmd[len(name):].lstrip()
1613 params = cmd[len(name):].lstrip()
1614 break
1614 break
1615 if not fn:
1615 if not fn:
1616 fn = lambda s, c, **kwargs: procutil.filter(s, c)
1616 fn = lambda s, c, **kwargs: procutil.filter(s, c)
1617 # Wrap old filters not supporting keyword arguments
1617 # Wrap old filters not supporting keyword arguments
1618 if not pycompat.getargspec(fn)[2]:
1618 if not pycompat.getargspec(fn)[2]:
1619 oldfn = fn
1619 oldfn = fn
1620 fn = lambda s, c, **kwargs: oldfn(s, c)
1620 fn = lambda s, c, **kwargs: oldfn(s, c)
1621 l.append((mf, fn, params))
1621 l.append((mf, fn, params))
1622 self._filterpats[filter] = l
1622 self._filterpats[filter] = l
1623 return self._filterpats[filter]
1623 return self._filterpats[filter]
1624
1624
1625 def _filter(self, filterpats, filename, data):
1625 def _filter(self, filterpats, filename, data):
1626 for mf, fn, cmd in filterpats:
1626 for mf, fn, cmd in filterpats:
1627 if mf(filename):
1627 if mf(filename):
1628 self.ui.debug("filtering %s through %s\n" % (filename, cmd))
1628 self.ui.debug("filtering %s through %s\n" % (filename, cmd))
1629 data = fn(data, cmd, ui=self.ui, repo=self, filename=filename)
1629 data = fn(data, cmd, ui=self.ui, repo=self, filename=filename)
1630 break
1630 break
1631
1631
1632 return data
1632 return data
1633
1633
1634 @unfilteredpropertycache
1634 @unfilteredpropertycache
1635 def _encodefilterpats(self):
1635 def _encodefilterpats(self):
1636 return self._loadfilter('encode')
1636 return self._loadfilter('encode')
1637
1637
1638 @unfilteredpropertycache
1638 @unfilteredpropertycache
1639 def _decodefilterpats(self):
1639 def _decodefilterpats(self):
1640 return self._loadfilter('decode')
1640 return self._loadfilter('decode')
1641
1641
1642 def adddatafilter(self, name, filter):
1642 def adddatafilter(self, name, filter):
1643 self._datafilters[name] = filter
1643 self._datafilters[name] = filter
1644
1644
1645 def wread(self, filename):
1645 def wread(self, filename):
1646 if self.wvfs.islink(filename):
1646 if self.wvfs.islink(filename):
1647 data = self.wvfs.readlink(filename)
1647 data = self.wvfs.readlink(filename)
1648 else:
1648 else:
1649 data = self.wvfs.read(filename)
1649 data = self.wvfs.read(filename)
1650 return self._filter(self._encodefilterpats, filename, data)
1650 return self._filter(self._encodefilterpats, filename, data)
1651
1651
1652 def wwrite(self, filename, data, flags, backgroundclose=False, **kwargs):
1652 def wwrite(self, filename, data, flags, backgroundclose=False, **kwargs):
1653 """write ``data`` into ``filename`` in the working directory
1653 """write ``data`` into ``filename`` in the working directory
1654
1654
1655 This returns length of written (maybe decoded) data.
1655 This returns length of written (maybe decoded) data.
1656 """
1656 """
1657 data = self._filter(self._decodefilterpats, filename, data)
1657 data = self._filter(self._decodefilterpats, filename, data)
1658 if 'l' in flags:
1658 if 'l' in flags:
1659 self.wvfs.symlink(data, filename)
1659 self.wvfs.symlink(data, filename)
1660 else:
1660 else:
1661 self.wvfs.write(filename, data, backgroundclose=backgroundclose,
1661 self.wvfs.write(filename, data, backgroundclose=backgroundclose,
1662 **kwargs)
1662 **kwargs)
1663 if 'x' in flags:
1663 if 'x' in flags:
1664 self.wvfs.setflags(filename, False, True)
1664 self.wvfs.setflags(filename, False, True)
1665 else:
1665 else:
1666 self.wvfs.setflags(filename, False, False)
1666 self.wvfs.setflags(filename, False, False)
1667 return len(data)
1667 return len(data)
1668
1668
1669 def wwritedata(self, filename, data):
1669 def wwritedata(self, filename, data):
1670 return self._filter(self._decodefilterpats, filename, data)
1670 return self._filter(self._decodefilterpats, filename, data)
1671
1671
1672 def currenttransaction(self):
1672 def currenttransaction(self):
1673 """return the current transaction or None if non exists"""
1673 """return the current transaction or None if non exists"""
1674 if self._transref:
1674 if self._transref:
1675 tr = self._transref()
1675 tr = self._transref()
1676 else:
1676 else:
1677 tr = None
1677 tr = None
1678
1678
1679 if tr and tr.running():
1679 if tr and tr.running():
1680 return tr
1680 return tr
1681 return None
1681 return None
1682
1682
1683 def transaction(self, desc, report=None):
1683 def transaction(self, desc, report=None):
1684 if (self.ui.configbool('devel', 'all-warnings')
1684 if (self.ui.configbool('devel', 'all-warnings')
1685 or self.ui.configbool('devel', 'check-locks')):
1685 or self.ui.configbool('devel', 'check-locks')):
1686 if self._currentlock(self._lockref) is None:
1686 if self._currentlock(self._lockref) is None:
1687 raise error.ProgrammingError('transaction requires locking')
1687 raise error.ProgrammingError('transaction requires locking')
1688 tr = self.currenttransaction()
1688 tr = self.currenttransaction()
1689 if tr is not None:
1689 if tr is not None:
1690 return tr.nest(name=desc)
1690 return tr.nest(name=desc)
1691
1691
1692 # abort here if the journal already exists
1692 # abort here if the journal already exists
1693 if self.svfs.exists("journal"):
1693 if self.svfs.exists("journal"):
1694 raise error.RepoError(
1694 raise error.RepoError(
1695 _("abandoned transaction found"),
1695 _("abandoned transaction found"),
1696 hint=_("run 'hg recover' to clean up transaction"))
1696 hint=_("run 'hg recover' to clean up transaction"))
1697
1697
1698 idbase = "%.40f#%f" % (random.random(), time.time())
1698 idbase = "%.40f#%f" % (random.random(), time.time())
1699 ha = hex(hashlib.sha1(idbase).digest())
1699 ha = hex(hashlib.sha1(idbase).digest())
1700 txnid = 'TXN:' + ha
1700 txnid = 'TXN:' + ha
1701 self.hook('pretxnopen', throw=True, txnname=desc, txnid=txnid)
1701 self.hook('pretxnopen', throw=True, txnname=desc, txnid=txnid)
1702
1702
1703 self._writejournal(desc)
1703 self._writejournal(desc)
1704 renames = [(vfs, x, undoname(x)) for vfs, x in self._journalfiles()]
1704 renames = [(vfs, x, undoname(x)) for vfs, x in self._journalfiles()]
1705 if report:
1705 if report:
1706 rp = report
1706 rp = report
1707 else:
1707 else:
1708 rp = self.ui.warn
1708 rp = self.ui.warn
1709 vfsmap = {'plain': self.vfs, 'store': self.svfs} # root of .hg/
1709 vfsmap = {'plain': self.vfs, 'store': self.svfs} # root of .hg/
1710 # we must avoid cyclic reference between repo and transaction.
1710 # we must avoid cyclic reference between repo and transaction.
1711 reporef = weakref.ref(self)
1711 reporef = weakref.ref(self)
1712 # Code to track tag movement
1712 # Code to track tag movement
1713 #
1713 #
1714 # Since tags are all handled as file content, it is actually quite hard
1714 # Since tags are all handled as file content, it is actually quite hard
1715 # to track these movement from a code perspective. So we fallback to a
1715 # to track these movement from a code perspective. So we fallback to a
1716 # tracking at the repository level. One could envision to track changes
1716 # tracking at the repository level. One could envision to track changes
1717 # to the '.hgtags' file through changegroup apply but that fails to
1717 # to the '.hgtags' file through changegroup apply but that fails to
1718 # cope with case where transaction expose new heads without changegroup
1718 # cope with case where transaction expose new heads without changegroup
1719 # being involved (eg: phase movement).
1719 # being involved (eg: phase movement).
1720 #
1720 #
1721 # For now, We gate the feature behind a flag since this likely comes
1721 # For now, We gate the feature behind a flag since this likely comes
1722 # with performance impacts. The current code run more often than needed
1722 # with performance impacts. The current code run more often than needed
1723 # and do not use caches as much as it could. The current focus is on
1723 # and do not use caches as much as it could. The current focus is on
1724 # the behavior of the feature so we disable it by default. The flag
1724 # the behavior of the feature so we disable it by default. The flag
1725 # will be removed when we are happy with the performance impact.
1725 # will be removed when we are happy with the performance impact.
1726 #
1726 #
1727 # Once this feature is no longer experimental move the following
1727 # Once this feature is no longer experimental move the following
1728 # documentation to the appropriate help section:
1728 # documentation to the appropriate help section:
1729 #
1729 #
1730 # The ``HG_TAG_MOVED`` variable will be set if the transaction touched
1730 # The ``HG_TAG_MOVED`` variable will be set if the transaction touched
1731 # tags (new or changed or deleted tags). In addition the details of
1731 # tags (new or changed or deleted tags). In addition the details of
1732 # these changes are made available in a file at:
1732 # these changes are made available in a file at:
1733 # ``REPOROOT/.hg/changes/tags.changes``.
1733 # ``REPOROOT/.hg/changes/tags.changes``.
1734 # Make sure you check for HG_TAG_MOVED before reading that file as it
1734 # Make sure you check for HG_TAG_MOVED before reading that file as it
1735 # might exist from a previous transaction even if no tag were touched
1735 # might exist from a previous transaction even if no tag were touched
1736 # in this one. Changes are recorded in a line base format::
1736 # in this one. Changes are recorded in a line base format::
1737 #
1737 #
1738 # <action> <hex-node> <tag-name>\n
1738 # <action> <hex-node> <tag-name>\n
1739 #
1739 #
1740 # Actions are defined as follow:
1740 # Actions are defined as follow:
1741 # "-R": tag is removed,
1741 # "-R": tag is removed,
1742 # "+A": tag is added,
1742 # "+A": tag is added,
1743 # "-M": tag is moved (old value),
1743 # "-M": tag is moved (old value),
1744 # "+M": tag is moved (new value),
1744 # "+M": tag is moved (new value),
1745 tracktags = lambda x: None
1745 tracktags = lambda x: None
1746 # experimental config: experimental.hook-track-tags
1746 # experimental config: experimental.hook-track-tags
1747 shouldtracktags = self.ui.configbool('experimental', 'hook-track-tags')
1747 shouldtracktags = self.ui.configbool('experimental', 'hook-track-tags')
1748 if desc != 'strip' and shouldtracktags:
1748 if desc != 'strip' and shouldtracktags:
1749 oldheads = self.changelog.headrevs()
1749 oldheads = self.changelog.headrevs()
1750 def tracktags(tr2):
1750 def tracktags(tr2):
1751 repo = reporef()
1751 repo = reporef()
1752 oldfnodes = tagsmod.fnoderevs(repo.ui, repo, oldheads)
1752 oldfnodes = tagsmod.fnoderevs(repo.ui, repo, oldheads)
1753 newheads = repo.changelog.headrevs()
1753 newheads = repo.changelog.headrevs()
1754 newfnodes = tagsmod.fnoderevs(repo.ui, repo, newheads)
1754 newfnodes = tagsmod.fnoderevs(repo.ui, repo, newheads)
1755 # notes: we compare lists here.
1755 # notes: we compare lists here.
1756 # As we do it only once buiding set would not be cheaper
1756 # As we do it only once buiding set would not be cheaper
1757 changes = tagsmod.difftags(repo.ui, repo, oldfnodes, newfnodes)
1757 changes = tagsmod.difftags(repo.ui, repo, oldfnodes, newfnodes)
1758 if changes:
1758 if changes:
1759 tr2.hookargs['tag_moved'] = '1'
1759 tr2.hookargs['tag_moved'] = '1'
1760 with repo.vfs('changes/tags.changes', 'w',
1760 with repo.vfs('changes/tags.changes', 'w',
1761 atomictemp=True) as changesfile:
1761 atomictemp=True) as changesfile:
1762 # note: we do not register the file to the transaction
1762 # note: we do not register the file to the transaction
1763 # because we needs it to still exist on the transaction
1763 # because we needs it to still exist on the transaction
1764 # is close (for txnclose hooks)
1764 # is close (for txnclose hooks)
1765 tagsmod.writediff(changesfile, changes)
1765 tagsmod.writediff(changesfile, changes)
1766 def validate(tr2):
1766 def validate(tr2):
1767 """will run pre-closing hooks"""
1767 """will run pre-closing hooks"""
1768 # XXX the transaction API is a bit lacking here so we take a hacky
1768 # XXX the transaction API is a bit lacking here so we take a hacky
1769 # path for now
1769 # path for now
1770 #
1770 #
1771 # We cannot add this as a "pending" hooks since the 'tr.hookargs'
1771 # We cannot add this as a "pending" hooks since the 'tr.hookargs'
1772 # dict is copied before these run. In addition we needs the data
1772 # dict is copied before these run. In addition we needs the data
1773 # available to in memory hooks too.
1773 # available to in memory hooks too.
1774 #
1774 #
1775 # Moreover, we also need to make sure this runs before txnclose
1775 # Moreover, we also need to make sure this runs before txnclose
1776 # hooks and there is no "pending" mechanism that would execute
1776 # hooks and there is no "pending" mechanism that would execute
1777 # logic only if hooks are about to run.
1777 # logic only if hooks are about to run.
1778 #
1778 #
1779 # Fixing this limitation of the transaction is also needed to track
1779 # Fixing this limitation of the transaction is also needed to track
1780 # other families of changes (bookmarks, phases, obsolescence).
1780 # other families of changes (bookmarks, phases, obsolescence).
1781 #
1781 #
1782 # This will have to be fixed before we remove the experimental
1782 # This will have to be fixed before we remove the experimental
1783 # gating.
1783 # gating.
1784 tracktags(tr2)
1784 tracktags(tr2)
1785 repo = reporef()
1785 repo = reporef()
1786 if repo.ui.configbool('experimental', 'single-head-per-branch'):
1786 if repo.ui.configbool('experimental', 'single-head-per-branch'):
1787 scmutil.enforcesinglehead(repo, tr2, desc)
1787 scmutil.enforcesinglehead(repo, tr2, desc)
1788 if hook.hashook(repo.ui, 'pretxnclose-bookmark'):
1788 if hook.hashook(repo.ui, 'pretxnclose-bookmark'):
1789 for name, (old, new) in sorted(tr.changes['bookmarks'].items()):
1789 for name, (old, new) in sorted(tr.changes['bookmarks'].items()):
1790 args = tr.hookargs.copy()
1790 args = tr.hookargs.copy()
1791 args.update(bookmarks.preparehookargs(name, old, new))
1791 args.update(bookmarks.preparehookargs(name, old, new))
1792 repo.hook('pretxnclose-bookmark', throw=True,
1792 repo.hook('pretxnclose-bookmark', throw=True,
1793 txnname=desc,
1793 txnname=desc,
1794 **pycompat.strkwargs(args))
1794 **pycompat.strkwargs(args))
1795 if hook.hashook(repo.ui, 'pretxnclose-phase'):
1795 if hook.hashook(repo.ui, 'pretxnclose-phase'):
1796 cl = repo.unfiltered().changelog
1796 cl = repo.unfiltered().changelog
1797 for rev, (old, new) in tr.changes['phases'].items():
1797 for rev, (old, new) in tr.changes['phases'].items():
1798 args = tr.hookargs.copy()
1798 args = tr.hookargs.copy()
1799 node = hex(cl.node(rev))
1799 node = hex(cl.node(rev))
1800 args.update(phases.preparehookargs(node, old, new))
1800 args.update(phases.preparehookargs(node, old, new))
1801 repo.hook('pretxnclose-phase', throw=True, txnname=desc,
1801 repo.hook('pretxnclose-phase', throw=True, txnname=desc,
1802 **pycompat.strkwargs(args))
1802 **pycompat.strkwargs(args))
1803
1803
1804 repo.hook('pretxnclose', throw=True,
1804 repo.hook('pretxnclose', throw=True,
1805 txnname=desc, **pycompat.strkwargs(tr.hookargs))
1805 txnname=desc, **pycompat.strkwargs(tr.hookargs))
1806 def releasefn(tr, success):
1806 def releasefn(tr, success):
1807 repo = reporef()
1807 repo = reporef()
1808 if success:
1808 if success:
1809 # this should be explicitly invoked here, because
1809 # this should be explicitly invoked here, because
1810 # in-memory changes aren't written out at closing
1810 # in-memory changes aren't written out at closing
1811 # transaction, if tr.addfilegenerator (via
1811 # transaction, if tr.addfilegenerator (via
1812 # dirstate.write or so) isn't invoked while
1812 # dirstate.write or so) isn't invoked while
1813 # transaction running
1813 # transaction running
1814 repo.dirstate.write(None)
1814 repo.dirstate.write(None)
1815 else:
1815 else:
1816 # discard all changes (including ones already written
1816 # discard all changes (including ones already written
1817 # out) in this transaction
1817 # out) in this transaction
1818 narrowspec.restorebackup(self, 'journal.narrowspec')
1818 narrowspec.restorebackup(self, 'journal.narrowspec')
1819 repo.dirstate.restorebackup(None, 'journal.dirstate')
1819 repo.dirstate.restorebackup(None, 'journal.dirstate')
1820
1820
1821 repo.invalidate(clearfilecache=True)
1821 repo.invalidate(clearfilecache=True)
1822
1822
1823 tr = transaction.transaction(rp, self.svfs, vfsmap,
1823 tr = transaction.transaction(rp, self.svfs, vfsmap,
1824 "journal",
1824 "journal",
1825 "undo",
1825 "undo",
1826 aftertrans(renames),
1826 aftertrans(renames),
1827 self.store.createmode,
1827 self.store.createmode,
1828 validator=validate,
1828 validator=validate,
1829 releasefn=releasefn,
1829 releasefn=releasefn,
1830 checkambigfiles=_cachedfiles,
1830 checkambigfiles=_cachedfiles,
1831 name=desc)
1831 name=desc)
1832 tr.changes['origrepolen'] = len(self)
1832 tr.changes['origrepolen'] = len(self)
1833 tr.changes['obsmarkers'] = set()
1833 tr.changes['obsmarkers'] = set()
1834 tr.changes['phases'] = {}
1834 tr.changes['phases'] = {}
1835 tr.changes['bookmarks'] = {}
1835 tr.changes['bookmarks'] = {}
1836
1836
1837 tr.hookargs['txnid'] = txnid
1837 tr.hookargs['txnid'] = txnid
1838 # note: writing the fncache only during finalize mean that the file is
1838 # note: writing the fncache only during finalize mean that the file is
1839 # outdated when running hooks. As fncache is used for streaming clone,
1839 # outdated when running hooks. As fncache is used for streaming clone,
1840 # this is not expected to break anything that happen during the hooks.
1840 # this is not expected to break anything that happen during the hooks.
1841 tr.addfinalize('flush-fncache', self.store.write)
1841 tr.addfinalize('flush-fncache', self.store.write)
1842 def txnclosehook(tr2):
1842 def txnclosehook(tr2):
1843 """To be run if transaction is successful, will schedule a hook run
1843 """To be run if transaction is successful, will schedule a hook run
1844 """
1844 """
1845 # Don't reference tr2 in hook() so we don't hold a reference.
1845 # Don't reference tr2 in hook() so we don't hold a reference.
1846 # This reduces memory consumption when there are multiple
1846 # This reduces memory consumption when there are multiple
1847 # transactions per lock. This can likely go away if issue5045
1847 # transactions per lock. This can likely go away if issue5045
1848 # fixes the function accumulation.
1848 # fixes the function accumulation.
1849 hookargs = tr2.hookargs
1849 hookargs = tr2.hookargs
1850
1850
1851 def hookfunc():
1851 def hookfunc():
1852 repo = reporef()
1852 repo = reporef()
1853 if hook.hashook(repo.ui, 'txnclose-bookmark'):
1853 if hook.hashook(repo.ui, 'txnclose-bookmark'):
1854 bmchanges = sorted(tr.changes['bookmarks'].items())
1854 bmchanges = sorted(tr.changes['bookmarks'].items())
1855 for name, (old, new) in bmchanges:
1855 for name, (old, new) in bmchanges:
1856 args = tr.hookargs.copy()
1856 args = tr.hookargs.copy()
1857 args.update(bookmarks.preparehookargs(name, old, new))
1857 args.update(bookmarks.preparehookargs(name, old, new))
1858 repo.hook('txnclose-bookmark', throw=False,
1858 repo.hook('txnclose-bookmark', throw=False,
1859 txnname=desc, **pycompat.strkwargs(args))
1859 txnname=desc, **pycompat.strkwargs(args))
1860
1860
1861 if hook.hashook(repo.ui, 'txnclose-phase'):
1861 if hook.hashook(repo.ui, 'txnclose-phase'):
1862 cl = repo.unfiltered().changelog
1862 cl = repo.unfiltered().changelog
1863 phasemv = sorted(tr.changes['phases'].items())
1863 phasemv = sorted(tr.changes['phases'].items())
1864 for rev, (old, new) in phasemv:
1864 for rev, (old, new) in phasemv:
1865 args = tr.hookargs.copy()
1865 args = tr.hookargs.copy()
1866 node = hex(cl.node(rev))
1866 node = hex(cl.node(rev))
1867 args.update(phases.preparehookargs(node, old, new))
1867 args.update(phases.preparehookargs(node, old, new))
1868 repo.hook('txnclose-phase', throw=False, txnname=desc,
1868 repo.hook('txnclose-phase', throw=False, txnname=desc,
1869 **pycompat.strkwargs(args))
1869 **pycompat.strkwargs(args))
1870
1870
1871 repo.hook('txnclose', throw=False, txnname=desc,
1871 repo.hook('txnclose', throw=False, txnname=desc,
1872 **pycompat.strkwargs(hookargs))
1872 **pycompat.strkwargs(hookargs))
1873 reporef()._afterlock(hookfunc)
1873 reporef()._afterlock(hookfunc)
1874 tr.addfinalize('txnclose-hook', txnclosehook)
1874 tr.addfinalize('txnclose-hook', txnclosehook)
1875 # Include a leading "-" to make it happen before the transaction summary
1875 # Include a leading "-" to make it happen before the transaction summary
1876 # reports registered via scmutil.registersummarycallback() whose names
1876 # reports registered via scmutil.registersummarycallback() whose names
1877 # are 00-txnreport etc. That way, the caches will be warm when the
1877 # are 00-txnreport etc. That way, the caches will be warm when the
1878 # callbacks run.
1878 # callbacks run.
1879 tr.addpostclose('-warm-cache', self._buildcacheupdater(tr))
1879 tr.addpostclose('-warm-cache', self._buildcacheupdater(tr))
1880 def txnaborthook(tr2):
1880 def txnaborthook(tr2):
1881 """To be run if transaction is aborted
1881 """To be run if transaction is aborted
1882 """
1882 """
1883 reporef().hook('txnabort', throw=False, txnname=desc,
1883 reporef().hook('txnabort', throw=False, txnname=desc,
1884 **pycompat.strkwargs(tr2.hookargs))
1884 **pycompat.strkwargs(tr2.hookargs))
1885 tr.addabort('txnabort-hook', txnaborthook)
1885 tr.addabort('txnabort-hook', txnaborthook)
1886 # avoid eager cache invalidation. in-memory data should be identical
1886 # avoid eager cache invalidation. in-memory data should be identical
1887 # to stored data if transaction has no error.
1887 # to stored data if transaction has no error.
1888 tr.addpostclose('refresh-filecachestats', self._refreshfilecachestats)
1888 tr.addpostclose('refresh-filecachestats', self._refreshfilecachestats)
1889 self._transref = weakref.ref(tr)
1889 self._transref = weakref.ref(tr)
1890 scmutil.registersummarycallback(self, tr, desc)
1890 scmutil.registersummarycallback(self, tr, desc)
1891 return tr
1891 return tr
1892
1892
1893 def _journalfiles(self):
1893 def _journalfiles(self):
1894 return ((self.svfs, 'journal'),
1894 return ((self.svfs, 'journal'),
1895 (self.vfs, 'journal.dirstate'),
1895 (self.vfs, 'journal.dirstate'),
1896 (self.vfs, 'journal.branch'),
1896 (self.vfs, 'journal.branch'),
1897 (self.vfs, 'journal.desc'),
1897 (self.vfs, 'journal.desc'),
1898 (self.vfs, 'journal.bookmarks'),
1898 (self.vfs, 'journal.bookmarks'),
1899 (self.svfs, 'journal.phaseroots'))
1899 (self.svfs, 'journal.phaseroots'))
1900
1900
1901 def undofiles(self):
1901 def undofiles(self):
1902 return [(vfs, undoname(x)) for vfs, x in self._journalfiles()]
1902 return [(vfs, undoname(x)) for vfs, x in self._journalfiles()]
1903
1903
1904 @unfilteredmethod
1904 @unfilteredmethod
1905 def _writejournal(self, desc):
1905 def _writejournal(self, desc):
1906 self.dirstate.savebackup(None, 'journal.dirstate')
1906 self.dirstate.savebackup(None, 'journal.dirstate')
1907 narrowspec.savebackup(self, 'journal.narrowspec')
1907 narrowspec.savebackup(self, 'journal.narrowspec')
1908 self.vfs.write("journal.branch",
1908 self.vfs.write("journal.branch",
1909 encoding.fromlocal(self.dirstate.branch()))
1909 encoding.fromlocal(self.dirstate.branch()))
1910 self.vfs.write("journal.desc",
1910 self.vfs.write("journal.desc",
1911 "%d\n%s\n" % (len(self), desc))
1911 "%d\n%s\n" % (len(self), desc))
1912 self.vfs.write("journal.bookmarks",
1912 self.vfs.write("journal.bookmarks",
1913 self.vfs.tryread("bookmarks"))
1913 self.vfs.tryread("bookmarks"))
1914 self.svfs.write("journal.phaseroots",
1914 self.svfs.write("journal.phaseroots",
1915 self.svfs.tryread("phaseroots"))
1915 self.svfs.tryread("phaseroots"))
1916
1916
1917 def recover(self):
1917 def recover(self):
1918 with self.lock():
1918 with self.lock():
1919 if self.svfs.exists("journal"):
1919 if self.svfs.exists("journal"):
1920 self.ui.status(_("rolling back interrupted transaction\n"))
1920 self.ui.status(_("rolling back interrupted transaction\n"))
1921 vfsmap = {'': self.svfs,
1921 vfsmap = {'': self.svfs,
1922 'plain': self.vfs,}
1922 'plain': self.vfs,}
1923 transaction.rollback(self.svfs, vfsmap, "journal",
1923 transaction.rollback(self.svfs, vfsmap, "journal",
1924 self.ui.warn,
1924 self.ui.warn,
1925 checkambigfiles=_cachedfiles)
1925 checkambigfiles=_cachedfiles)
1926 self.invalidate()
1926 self.invalidate()
1927 return True
1927 return True
1928 else:
1928 else:
1929 self.ui.warn(_("no interrupted transaction available\n"))
1929 self.ui.warn(_("no interrupted transaction available\n"))
1930 return False
1930 return False
1931
1931
1932 def rollback(self, dryrun=False, force=False):
1932 def rollback(self, dryrun=False, force=False):
1933 wlock = lock = dsguard = None
1933 wlock = lock = dsguard = None
1934 try:
1934 try:
1935 wlock = self.wlock()
1935 wlock = self.wlock()
1936 lock = self.lock()
1936 lock = self.lock()
1937 if self.svfs.exists("undo"):
1937 if self.svfs.exists("undo"):
1938 dsguard = dirstateguard.dirstateguard(self, 'rollback')
1938 dsguard = dirstateguard.dirstateguard(self, 'rollback')
1939
1939
1940 return self._rollback(dryrun, force, dsguard)
1940 return self._rollback(dryrun, force, dsguard)
1941 else:
1941 else:
1942 self.ui.warn(_("no rollback information available\n"))
1942 self.ui.warn(_("no rollback information available\n"))
1943 return 1
1943 return 1
1944 finally:
1944 finally:
1945 release(dsguard, lock, wlock)
1945 release(dsguard, lock, wlock)
1946
1946
1947 @unfilteredmethod # Until we get smarter cache management
1947 @unfilteredmethod # Until we get smarter cache management
1948 def _rollback(self, dryrun, force, dsguard):
1948 def _rollback(self, dryrun, force, dsguard):
1949 ui = self.ui
1949 ui = self.ui
1950 try:
1950 try:
1951 args = self.vfs.read('undo.desc').splitlines()
1951 args = self.vfs.read('undo.desc').splitlines()
1952 (oldlen, desc, detail) = (int(args[0]), args[1], None)
1952 (oldlen, desc, detail) = (int(args[0]), args[1], None)
1953 if len(args) >= 3:
1953 if len(args) >= 3:
1954 detail = args[2]
1954 detail = args[2]
1955 oldtip = oldlen - 1
1955 oldtip = oldlen - 1
1956
1956
1957 if detail and ui.verbose:
1957 if detail and ui.verbose:
1958 msg = (_('repository tip rolled back to revision %d'
1958 msg = (_('repository tip rolled back to revision %d'
1959 ' (undo %s: %s)\n')
1959 ' (undo %s: %s)\n')
1960 % (oldtip, desc, detail))
1960 % (oldtip, desc, detail))
1961 else:
1961 else:
1962 msg = (_('repository tip rolled back to revision %d'
1962 msg = (_('repository tip rolled back to revision %d'
1963 ' (undo %s)\n')
1963 ' (undo %s)\n')
1964 % (oldtip, desc))
1964 % (oldtip, desc))
1965 except IOError:
1965 except IOError:
1966 msg = _('rolling back unknown transaction\n')
1966 msg = _('rolling back unknown transaction\n')
1967 desc = None
1967 desc = None
1968
1968
1969 if not force and self['.'] != self['tip'] and desc == 'commit':
1969 if not force and self['.'] != self['tip'] and desc == 'commit':
1970 raise error.Abort(
1970 raise error.Abort(
1971 _('rollback of last commit while not checked out '
1971 _('rollback of last commit while not checked out '
1972 'may lose data'), hint=_('use -f to force'))
1972 'may lose data'), hint=_('use -f to force'))
1973
1973
1974 ui.status(msg)
1974 ui.status(msg)
1975 if dryrun:
1975 if dryrun:
1976 return 0
1976 return 0
1977
1977
1978 parents = self.dirstate.parents()
1978 parents = self.dirstate.parents()
1979 self.destroying()
1979 self.destroying()
1980 vfsmap = {'plain': self.vfs, '': self.svfs}
1980 vfsmap = {'plain': self.vfs, '': self.svfs}
1981 transaction.rollback(self.svfs, vfsmap, 'undo', ui.warn,
1981 transaction.rollback(self.svfs, vfsmap, 'undo', ui.warn,
1982 checkambigfiles=_cachedfiles)
1982 checkambigfiles=_cachedfiles)
1983 if self.vfs.exists('undo.bookmarks'):
1983 if self.vfs.exists('undo.bookmarks'):
1984 self.vfs.rename('undo.bookmarks', 'bookmarks', checkambig=True)
1984 self.vfs.rename('undo.bookmarks', 'bookmarks', checkambig=True)
1985 if self.svfs.exists('undo.phaseroots'):
1985 if self.svfs.exists('undo.phaseroots'):
1986 self.svfs.rename('undo.phaseroots', 'phaseroots', checkambig=True)
1986 self.svfs.rename('undo.phaseroots', 'phaseroots', checkambig=True)
1987 self.invalidate()
1987 self.invalidate()
1988
1988
1989 parentgone = (parents[0] not in self.changelog.nodemap or
1989 parentgone = (parents[0] not in self.changelog.nodemap or
1990 parents[1] not in self.changelog.nodemap)
1990 parents[1] not in self.changelog.nodemap)
1991 if parentgone:
1991 if parentgone:
1992 # prevent dirstateguard from overwriting already restored one
1992 # prevent dirstateguard from overwriting already restored one
1993 dsguard.close()
1993 dsguard.close()
1994
1994
1995 narrowspec.restorebackup(self, 'undo.narrowspec')
1995 narrowspec.restorebackup(self, 'undo.narrowspec')
1996 self.dirstate.restorebackup(None, 'undo.dirstate')
1996 self.dirstate.restorebackup(None, 'undo.dirstate')
1997 try:
1997 try:
1998 branch = self.vfs.read('undo.branch')
1998 branch = self.vfs.read('undo.branch')
1999 self.dirstate.setbranch(encoding.tolocal(branch))
1999 self.dirstate.setbranch(encoding.tolocal(branch))
2000 except IOError:
2000 except IOError:
2001 ui.warn(_('named branch could not be reset: '
2001 ui.warn(_('named branch could not be reset: '
2002 'current branch is still \'%s\'\n')
2002 'current branch is still \'%s\'\n')
2003 % self.dirstate.branch())
2003 % self.dirstate.branch())
2004
2004
2005 parents = tuple([p.rev() for p in self[None].parents()])
2005 parents = tuple([p.rev() for p in self[None].parents()])
2006 if len(parents) > 1:
2006 if len(parents) > 1:
2007 ui.status(_('working directory now based on '
2007 ui.status(_('working directory now based on '
2008 'revisions %d and %d\n') % parents)
2008 'revisions %d and %d\n') % parents)
2009 else:
2009 else:
2010 ui.status(_('working directory now based on '
2010 ui.status(_('working directory now based on '
2011 'revision %d\n') % parents)
2011 'revision %d\n') % parents)
2012 mergemod.mergestate.clean(self, self['.'].node())
2012 mergemod.mergestate.clean(self, self['.'].node())
2013
2013
2014 # TODO: if we know which new heads may result from this rollback, pass
2014 # TODO: if we know which new heads may result from this rollback, pass
2015 # them to destroy(), which will prevent the branchhead cache from being
2015 # them to destroy(), which will prevent the branchhead cache from being
2016 # invalidated.
2016 # invalidated.
2017 self.destroyed()
2017 self.destroyed()
2018 return 0
2018 return 0
2019
2019
2020 def _buildcacheupdater(self, newtransaction):
2020 def _buildcacheupdater(self, newtransaction):
2021 """called during transaction to build the callback updating cache
2021 """called during transaction to build the callback updating cache
2022
2022
2023 Lives on the repository to help extension who might want to augment
2023 Lives on the repository to help extension who might want to augment
2024 this logic. For this purpose, the created transaction is passed to the
2024 this logic. For this purpose, the created transaction is passed to the
2025 method.
2025 method.
2026 """
2026 """
2027 # we must avoid cyclic reference between repo and transaction.
2027 # we must avoid cyclic reference between repo and transaction.
2028 reporef = weakref.ref(self)
2028 reporef = weakref.ref(self)
2029 def updater(tr):
2029 def updater(tr):
2030 repo = reporef()
2030 repo = reporef()
2031 repo.updatecaches(tr)
2031 repo.updatecaches(tr)
2032 return updater
2032 return updater
2033
2033
2034 @unfilteredmethod
2034 @unfilteredmethod
2035 def updatecaches(self, tr=None, full=False):
2035 def updatecaches(self, tr=None, full=False):
2036 """warm appropriate caches
2036 """warm appropriate caches
2037
2037
2038 If this function is called after a transaction closed. The transaction
2038 If this function is called after a transaction closed. The transaction
2039 will be available in the 'tr' argument. This can be used to selectively
2039 will be available in the 'tr' argument. This can be used to selectively
2040 update caches relevant to the changes in that transaction.
2040 update caches relevant to the changes in that transaction.
2041
2041
2042 If 'full' is set, make sure all caches the function knows about have
2042 If 'full' is set, make sure all caches the function knows about have
2043 up-to-date data. Even the ones usually loaded more lazily.
2043 up-to-date data. Even the ones usually loaded more lazily.
2044 """
2044 """
2045 if tr is not None and tr.hookargs.get('source') == 'strip':
2045 if tr is not None and tr.hookargs.get('source') == 'strip':
2046 # During strip, many caches are invalid but
2046 # During strip, many caches are invalid but
2047 # later call to `destroyed` will refresh them.
2047 # later call to `destroyed` will refresh them.
2048 return
2048 return
2049
2049
2050 if tr is None or tr.changes['origrepolen'] < len(self):
2050 if tr is None or tr.changes['origrepolen'] < len(self):
2051 # updating the unfiltered branchmap should refresh all the others,
2051 # updating the unfiltered branchmap should refresh all the others,
2052 self.ui.debug('updating the branch cache\n')
2052 self.ui.debug('updating the branch cache\n')
2053 branchmap.updatecache(self.filtered('served'))
2053 branchmap.updatecache(self.filtered('served'))
2054
2054
2055 if full:
2055 if full:
2056 rbc = self.revbranchcache()
2056 rbc = self.revbranchcache()
2057 for r in self.changelog:
2057 for r in self.changelog:
2058 rbc.branchinfo(r)
2058 rbc.branchinfo(r)
2059 rbc.write()
2059 rbc.write()
2060
2060
2061 # ensure the working copy parents are in the manifestfulltextcache
2061 # ensure the working copy parents are in the manifestfulltextcache
2062 for ctx in self['.'].parents():
2062 for ctx in self['.'].parents():
2063 ctx.manifest() # accessing the manifest is enough
2063 ctx.manifest() # accessing the manifest is enough
2064
2064
2065 def invalidatecaches(self):
2065 def invalidatecaches(self):
2066
2066
2067 if r'_tagscache' in vars(self):
2067 if r'_tagscache' in vars(self):
2068 # can't use delattr on proxy
2068 # can't use delattr on proxy
2069 del self.__dict__[r'_tagscache']
2069 del self.__dict__[r'_tagscache']
2070
2070
2071 self.unfiltered()._branchcaches.clear()
2071 self.unfiltered()._branchcaches.clear()
2072 self.invalidatevolatilesets()
2072 self.invalidatevolatilesets()
2073 self._sparsesignaturecache.clear()
2073 self._sparsesignaturecache.clear()
2074
2074
2075 def invalidatevolatilesets(self):
2075 def invalidatevolatilesets(self):
2076 self.filteredrevcache.clear()
2076 self.filteredrevcache.clear()
2077 obsolete.clearobscaches(self)
2077 obsolete.clearobscaches(self)
2078
2078
2079 def invalidatedirstate(self):
2079 def invalidatedirstate(self):
2080 '''Invalidates the dirstate, causing the next call to dirstate
2080 '''Invalidates the dirstate, causing the next call to dirstate
2081 to check if it was modified since the last time it was read,
2081 to check if it was modified since the last time it was read,
2082 rereading it if it has.
2082 rereading it if it has.
2083
2083
2084 This is different to dirstate.invalidate() that it doesn't always
2084 This is different to dirstate.invalidate() that it doesn't always
2085 rereads the dirstate. Use dirstate.invalidate() if you want to
2085 rereads the dirstate. Use dirstate.invalidate() if you want to
2086 explicitly read the dirstate again (i.e. restoring it to a previous
2086 explicitly read the dirstate again (i.e. restoring it to a previous
2087 known good state).'''
2087 known good state).'''
2088 if hasunfilteredcache(self, r'dirstate'):
2088 if hasunfilteredcache(self, r'dirstate'):
2089 for k in self.dirstate._filecache:
2089 for k in self.dirstate._filecache:
2090 try:
2090 try:
2091 delattr(self.dirstate, k)
2091 delattr(self.dirstate, k)
2092 except AttributeError:
2092 except AttributeError:
2093 pass
2093 pass
2094 delattr(self.unfiltered(), r'dirstate')
2094 delattr(self.unfiltered(), r'dirstate')
2095
2095
2096 def invalidate(self, clearfilecache=False):
2096 def invalidate(self, clearfilecache=False):
2097 '''Invalidates both store and non-store parts other than dirstate
2097 '''Invalidates both store and non-store parts other than dirstate
2098
2098
2099 If a transaction is running, invalidation of store is omitted,
2099 If a transaction is running, invalidation of store is omitted,
2100 because discarding in-memory changes might cause inconsistency
2100 because discarding in-memory changes might cause inconsistency
2101 (e.g. incomplete fncache causes unintentional failure, but
2101 (e.g. incomplete fncache causes unintentional failure, but
2102 redundant one doesn't).
2102 redundant one doesn't).
2103 '''
2103 '''
2104 unfiltered = self.unfiltered() # all file caches are stored unfiltered
2104 unfiltered = self.unfiltered() # all file caches are stored unfiltered
2105 for k in list(self._filecache.keys()):
2105 for k in list(self._filecache.keys()):
2106 # dirstate is invalidated separately in invalidatedirstate()
2106 # dirstate is invalidated separately in invalidatedirstate()
2107 if k == 'dirstate':
2107 if k == 'dirstate':
2108 continue
2108 continue
2109 if (k == 'changelog' and
2109 if (k == 'changelog' and
2110 self.currenttransaction() and
2110 self.currenttransaction() and
2111 self.changelog._delayed):
2111 self.changelog._delayed):
2112 # The changelog object may store unwritten revisions. We don't
2112 # The changelog object may store unwritten revisions. We don't
2113 # want to lose them.
2113 # want to lose them.
2114 # TODO: Solve the problem instead of working around it.
2114 # TODO: Solve the problem instead of working around it.
2115 continue
2115 continue
2116
2116
2117 if clearfilecache:
2117 if clearfilecache:
2118 del self._filecache[k]
2118 del self._filecache[k]
2119 try:
2119 try:
2120 delattr(unfiltered, k)
2120 delattr(unfiltered, k)
2121 except AttributeError:
2121 except AttributeError:
2122 pass
2122 pass
2123 self.invalidatecaches()
2123 self.invalidatecaches()
2124 if not self.currenttransaction():
2124 if not self.currenttransaction():
2125 # TODO: Changing contents of store outside transaction
2125 # TODO: Changing contents of store outside transaction
2126 # causes inconsistency. We should make in-memory store
2126 # causes inconsistency. We should make in-memory store
2127 # changes detectable, and abort if changed.
2127 # changes detectable, and abort if changed.
2128 self.store.invalidatecaches()
2128 self.store.invalidatecaches()
2129
2129
2130 def invalidateall(self):
2130 def invalidateall(self):
2131 '''Fully invalidates both store and non-store parts, causing the
2131 '''Fully invalidates both store and non-store parts, causing the
2132 subsequent operation to reread any outside changes.'''
2132 subsequent operation to reread any outside changes.'''
2133 # extension should hook this to invalidate its caches
2133 # extension should hook this to invalidate its caches
2134 self.invalidate()
2134 self.invalidate()
2135 self.invalidatedirstate()
2135 self.invalidatedirstate()
2136
2136
2137 @unfilteredmethod
2137 @unfilteredmethod
2138 def _refreshfilecachestats(self, tr):
2138 def _refreshfilecachestats(self, tr):
2139 """Reload stats of cached files so that they are flagged as valid"""
2139 """Reload stats of cached files so that they are flagged as valid"""
2140 for k, ce in self._filecache.items():
2140 for k, ce in self._filecache.items():
2141 k = pycompat.sysstr(k)
2141 k = pycompat.sysstr(k)
2142 if k == r'dirstate' or k not in self.__dict__:
2142 if k == r'dirstate' or k not in self.__dict__:
2143 continue
2143 continue
2144 ce.refresh()
2144 ce.refresh()
2145
2145
2146 def _lock(self, vfs, lockname, wait, releasefn, acquirefn, desc,
2146 def _lock(self, vfs, lockname, wait, releasefn, acquirefn, desc,
2147 inheritchecker=None, parentenvvar=None):
2147 inheritchecker=None, parentenvvar=None):
2148 parentlock = None
2148 parentlock = None
2149 # the contents of parentenvvar are used by the underlying lock to
2149 # the contents of parentenvvar are used by the underlying lock to
2150 # determine whether it can be inherited
2150 # determine whether it can be inherited
2151 if parentenvvar is not None:
2151 if parentenvvar is not None:
2152 parentlock = encoding.environ.get(parentenvvar)
2152 parentlock = encoding.environ.get(parentenvvar)
2153
2153
2154 timeout = 0
2154 timeout = 0
2155 warntimeout = 0
2155 warntimeout = 0
2156 if wait:
2156 if wait:
2157 timeout = self.ui.configint("ui", "timeout")
2157 timeout = self.ui.configint("ui", "timeout")
2158 warntimeout = self.ui.configint("ui", "timeout.warn")
2158 warntimeout = self.ui.configint("ui", "timeout.warn")
2159 # internal config: ui.signal-safe-lock
2159 # internal config: ui.signal-safe-lock
2160 signalsafe = self.ui.configbool('ui', 'signal-safe-lock')
2160 signalsafe = self.ui.configbool('ui', 'signal-safe-lock')
2161
2161
2162 l = lockmod.trylock(self.ui, vfs, lockname, timeout, warntimeout,
2162 l = lockmod.trylock(self.ui, vfs, lockname, timeout, warntimeout,
2163 releasefn=releasefn,
2163 releasefn=releasefn,
2164 acquirefn=acquirefn, desc=desc,
2164 acquirefn=acquirefn, desc=desc,
2165 inheritchecker=inheritchecker,
2165 inheritchecker=inheritchecker,
2166 parentlock=parentlock,
2166 parentlock=parentlock,
2167 signalsafe=signalsafe)
2167 signalsafe=signalsafe)
2168 return l
2168 return l
2169
2169
2170 def _afterlock(self, callback):
2170 def _afterlock(self, callback):
2171 """add a callback to be run when the repository is fully unlocked
2171 """add a callback to be run when the repository is fully unlocked
2172
2172
2173 The callback will be executed when the outermost lock is released
2173 The callback will be executed when the outermost lock is released
2174 (with wlock being higher level than 'lock')."""
2174 (with wlock being higher level than 'lock')."""
2175 for ref in (self._wlockref, self._lockref):
2175 for ref in (self._wlockref, self._lockref):
2176 l = ref and ref()
2176 l = ref and ref()
2177 if l and l.held:
2177 if l and l.held:
2178 l.postrelease.append(callback)
2178 l.postrelease.append(callback)
2179 break
2179 break
2180 else: # no lock have been found.
2180 else: # no lock have been found.
2181 callback()
2181 callback()
2182
2182
2183 def lock(self, wait=True):
2183 def lock(self, wait=True):
2184 '''Lock the repository store (.hg/store) and return a weak reference
2184 '''Lock the repository store (.hg/store) and return a weak reference
2185 to the lock. Use this before modifying the store (e.g. committing or
2185 to the lock. Use this before modifying the store (e.g. committing or
2186 stripping). If you are opening a transaction, get a lock as well.)
2186 stripping). If you are opening a transaction, get a lock as well.)
2187
2187
2188 If both 'lock' and 'wlock' must be acquired, ensure you always acquires
2188 If both 'lock' and 'wlock' must be acquired, ensure you always acquires
2189 'wlock' first to avoid a dead-lock hazard.'''
2189 'wlock' first to avoid a dead-lock hazard.'''
2190 l = self._currentlock(self._lockref)
2190 l = self._currentlock(self._lockref)
2191 if l is not None:
2191 if l is not None:
2192 l.lock()
2192 l.lock()
2193 return l
2193 return l
2194
2194
2195 l = self._lock(self.svfs, "lock", wait, None,
2195 l = self._lock(self.svfs, "lock", wait, None,
2196 self.invalidate, _('repository %s') % self.origroot)
2196 self.invalidate, _('repository %s') % self.origroot)
2197 self._lockref = weakref.ref(l)
2197 self._lockref = weakref.ref(l)
2198 return l
2198 return l
2199
2199
2200 def _wlockchecktransaction(self):
2200 def _wlockchecktransaction(self):
2201 if self.currenttransaction() is not None:
2201 if self.currenttransaction() is not None:
2202 raise error.LockInheritanceContractViolation(
2202 raise error.LockInheritanceContractViolation(
2203 'wlock cannot be inherited in the middle of a transaction')
2203 'wlock cannot be inherited in the middle of a transaction')
2204
2204
2205 def wlock(self, wait=True):
2205 def wlock(self, wait=True):
2206 '''Lock the non-store parts of the repository (everything under
2206 '''Lock the non-store parts of the repository (everything under
2207 .hg except .hg/store) and return a weak reference to the lock.
2207 .hg except .hg/store) and return a weak reference to the lock.
2208
2208
2209 Use this before modifying files in .hg.
2209 Use this before modifying files in .hg.
2210
2210
2211 If both 'lock' and 'wlock' must be acquired, ensure you always acquires
2211 If both 'lock' and 'wlock' must be acquired, ensure you always acquires
2212 'wlock' first to avoid a dead-lock hazard.'''
2212 'wlock' first to avoid a dead-lock hazard.'''
2213 l = self._wlockref and self._wlockref()
2213 l = self._wlockref and self._wlockref()
2214 if l is not None and l.held:
2214 if l is not None and l.held:
2215 l.lock()
2215 l.lock()
2216 return l
2216 return l
2217
2217
2218 # We do not need to check for non-waiting lock acquisition. Such
2218 # We do not need to check for non-waiting lock acquisition. Such
2219 # acquisition would not cause dead-lock as they would just fail.
2219 # acquisition would not cause dead-lock as they would just fail.
2220 if wait and (self.ui.configbool('devel', 'all-warnings')
2220 if wait and (self.ui.configbool('devel', 'all-warnings')
2221 or self.ui.configbool('devel', 'check-locks')):
2221 or self.ui.configbool('devel', 'check-locks')):
2222 if self._currentlock(self._lockref) is not None:
2222 if self._currentlock(self._lockref) is not None:
2223 self.ui.develwarn('"wlock" acquired after "lock"')
2223 self.ui.develwarn('"wlock" acquired after "lock"')
2224
2224
2225 def unlock():
2225 def unlock():
2226 if self.dirstate.pendingparentchange():
2226 if self.dirstate.pendingparentchange():
2227 self.dirstate.invalidate()
2227 self.dirstate.invalidate()
2228 else:
2228 else:
2229 self.dirstate.write(None)
2229 self.dirstate.write(None)
2230
2230
2231 self._filecache['dirstate'].refresh()
2231 self._filecache['dirstate'].refresh()
2232
2232
2233 l = self._lock(self.vfs, "wlock", wait, unlock,
2233 l = self._lock(self.vfs, "wlock", wait, unlock,
2234 self.invalidatedirstate, _('working directory of %s') %
2234 self.invalidatedirstate, _('working directory of %s') %
2235 self.origroot,
2235 self.origroot,
2236 inheritchecker=self._wlockchecktransaction,
2236 inheritchecker=self._wlockchecktransaction,
2237 parentenvvar='HG_WLOCK_LOCKER')
2237 parentenvvar='HG_WLOCK_LOCKER')
2238 self._wlockref = weakref.ref(l)
2238 self._wlockref = weakref.ref(l)
2239 return l
2239 return l
2240
2240
2241 def _currentlock(self, lockref):
2241 def _currentlock(self, lockref):
2242 """Returns the lock if it's held, or None if it's not."""
2242 """Returns the lock if it's held, or None if it's not."""
2243 if lockref is None:
2243 if lockref is None:
2244 return None
2244 return None
2245 l = lockref()
2245 l = lockref()
2246 if l is None or not l.held:
2246 if l is None or not l.held:
2247 return None
2247 return None
2248 return l
2248 return l
2249
2249
2250 def currentwlock(self):
2250 def currentwlock(self):
2251 """Returns the wlock if it's held, or None if it's not."""
2251 """Returns the wlock if it's held, or None if it's not."""
2252 return self._currentlock(self._wlockref)
2252 return self._currentlock(self._wlockref)
2253
2253
2254 def _filecommit(self, fctx, manifest1, manifest2, linkrev, tr, changelist):
2254 def _filecommit(self, fctx, manifest1, manifest2, linkrev, tr, changelist):
2255 """
2255 """
2256 commit an individual file as part of a larger transaction
2256 commit an individual file as part of a larger transaction
2257 """
2257 """
2258
2258
2259 fname = fctx.path()
2259 fname = fctx.path()
2260 fparent1 = manifest1.get(fname, nullid)
2260 fparent1 = manifest1.get(fname, nullid)
2261 fparent2 = manifest2.get(fname, nullid)
2261 fparent2 = manifest2.get(fname, nullid)
2262 if isinstance(fctx, context.filectx):
2262 if isinstance(fctx, context.filectx):
2263 node = fctx.filenode()
2263 node = fctx.filenode()
2264 if node in [fparent1, fparent2]:
2264 if node in [fparent1, fparent2]:
2265 self.ui.debug('reusing %s filelog entry\n' % fname)
2265 self.ui.debug('reusing %s filelog entry\n' % fname)
2266 if manifest1.flags(fname) != fctx.flags():
2266 if manifest1.flags(fname) != fctx.flags():
2267 changelist.append(fname)
2267 changelist.append(fname)
2268 return node
2268 return node
2269
2269
2270 flog = self.file(fname)
2270 flog = self.file(fname)
2271 meta = {}
2271 meta = {}
2272 copy = fctx.renamed()
2272 copy = fctx.renamed()
2273 if copy and copy[0] != fname:
2273 if copy and copy[0] != fname:
2274 # Mark the new revision of this file as a copy of another
2274 # Mark the new revision of this file as a copy of another
2275 # file. This copy data will effectively act as a parent
2275 # file. This copy data will effectively act as a parent
2276 # of this new revision. If this is a merge, the first
2276 # of this new revision. If this is a merge, the first
2277 # parent will be the nullid (meaning "look up the copy data")
2277 # parent will be the nullid (meaning "look up the copy data")
2278 # and the second one will be the other parent. For example:
2278 # and the second one will be the other parent. For example:
2279 #
2279 #
2280 # 0 --- 1 --- 3 rev1 changes file foo
2280 # 0 --- 1 --- 3 rev1 changes file foo
2281 # \ / rev2 renames foo to bar and changes it
2281 # \ / rev2 renames foo to bar and changes it
2282 # \- 2 -/ rev3 should have bar with all changes and
2282 # \- 2 -/ rev3 should have bar with all changes and
2283 # should record that bar descends from
2283 # should record that bar descends from
2284 # bar in rev2 and foo in rev1
2284 # bar in rev2 and foo in rev1
2285 #
2285 #
2286 # this allows this merge to succeed:
2286 # this allows this merge to succeed:
2287 #
2287 #
2288 # 0 --- 1 --- 3 rev4 reverts the content change from rev2
2288 # 0 --- 1 --- 3 rev4 reverts the content change from rev2
2289 # \ / merging rev3 and rev4 should use bar@rev2
2289 # \ / merging rev3 and rev4 should use bar@rev2
2290 # \- 2 --- 4 as the merge base
2290 # \- 2 --- 4 as the merge base
2291 #
2291 #
2292
2292
2293 cfname = copy[0]
2293 cfname = copy[0]
2294 crev = manifest1.get(cfname)
2294 crev = manifest1.get(cfname)
2295 newfparent = fparent2
2295 newfparent = fparent2
2296
2296
2297 if manifest2: # branch merge
2297 if manifest2: # branch merge
2298 if fparent2 == nullid or crev is None: # copied on remote side
2298 if fparent2 == nullid or crev is None: # copied on remote side
2299 if cfname in manifest2:
2299 if cfname in manifest2:
2300 crev = manifest2[cfname]
2300 crev = manifest2[cfname]
2301 newfparent = fparent1
2301 newfparent = fparent1
2302
2302
2303 # Here, we used to search backwards through history to try to find
2303 # Here, we used to search backwards through history to try to find
2304 # where the file copy came from if the source of a copy was not in
2304 # where the file copy came from if the source of a copy was not in
2305 # the parent directory. However, this doesn't actually make sense to
2305 # the parent directory. However, this doesn't actually make sense to
2306 # do (what does a copy from something not in your working copy even
2306 # do (what does a copy from something not in your working copy even
2307 # mean?) and it causes bugs (eg, issue4476). Instead, we will warn
2307 # mean?) and it causes bugs (eg, issue4476). Instead, we will warn
2308 # the user that copy information was dropped, so if they didn't
2308 # the user that copy information was dropped, so if they didn't
2309 # expect this outcome it can be fixed, but this is the correct
2309 # expect this outcome it can be fixed, but this is the correct
2310 # behavior in this circumstance.
2310 # behavior in this circumstance.
2311
2311
2312 if crev:
2312 if crev:
2313 self.ui.debug(" %s: copy %s:%s\n" % (fname, cfname, hex(crev)))
2313 self.ui.debug(" %s: copy %s:%s\n" % (fname, cfname, hex(crev)))
2314 meta["copy"] = cfname
2314 meta["copy"] = cfname
2315 meta["copyrev"] = hex(crev)
2315 meta["copyrev"] = hex(crev)
2316 fparent1, fparent2 = nullid, newfparent
2316 fparent1, fparent2 = nullid, newfparent
2317 else:
2317 else:
2318 self.ui.warn(_("warning: can't find ancestor for '%s' "
2318 self.ui.warn(_("warning: can't find ancestor for '%s' "
2319 "copied from '%s'!\n") % (fname, cfname))
2319 "copied from '%s'!\n") % (fname, cfname))
2320
2320
2321 elif fparent1 == nullid:
2321 elif fparent1 == nullid:
2322 fparent1, fparent2 = fparent2, nullid
2322 fparent1, fparent2 = fparent2, nullid
2323 elif fparent2 != nullid:
2323 elif fparent2 != nullid:
2324 # is one parent an ancestor of the other?
2324 # is one parent an ancestor of the other?
2325 fparentancestors = flog.commonancestorsheads(fparent1, fparent2)
2325 fparentancestors = flog.commonancestorsheads(fparent1, fparent2)
2326 if fparent1 in fparentancestors:
2326 if fparent1 in fparentancestors:
2327 fparent1, fparent2 = fparent2, nullid
2327 fparent1, fparent2 = fparent2, nullid
2328 elif fparent2 in fparentancestors:
2328 elif fparent2 in fparentancestors:
2329 fparent2 = nullid
2329 fparent2 = nullid
2330
2330
2331 # is the file changed?
2331 # is the file changed?
2332 text = fctx.data()
2332 text = fctx.data()
2333 if fparent2 != nullid or flog.cmp(fparent1, text) or meta:
2333 if fparent2 != nullid or flog.cmp(fparent1, text) or meta:
2334 changelist.append(fname)
2334 changelist.append(fname)
2335 return flog.add(text, meta, tr, linkrev, fparent1, fparent2)
2335 return flog.add(text, meta, tr, linkrev, fparent1, fparent2)
2336 # are just the flags changed during merge?
2336 # are just the flags changed during merge?
2337 elif fname in manifest1 and manifest1.flags(fname) != fctx.flags():
2337 elif fname in manifest1 and manifest1.flags(fname) != fctx.flags():
2338 changelist.append(fname)
2338 changelist.append(fname)
2339
2339
2340 return fparent1
2340 return fparent1
2341
2341
2342 def checkcommitpatterns(self, wctx, vdirs, match, status, fail):
2342 def checkcommitpatterns(self, wctx, vdirs, match, status, fail):
2343 """check for commit arguments that aren't committable"""
2343 """check for commit arguments that aren't committable"""
2344 if match.isexact() or match.prefix():
2344 if match.isexact() or match.prefix():
2345 matched = set(status.modified + status.added + status.removed)
2345 matched = set(status.modified + status.added + status.removed)
2346
2346
2347 for f in match.files():
2347 for f in match.files():
2348 f = self.dirstate.normalize(f)
2348 f = self.dirstate.normalize(f)
2349 if f == '.' or f in matched or f in wctx.substate:
2349 if f == '.' or f in matched or f in wctx.substate:
2350 continue
2350 continue
2351 if f in status.deleted:
2351 if f in status.deleted:
2352 fail(f, _('file not found!'))
2352 fail(f, _('file not found!'))
2353 if f in vdirs: # visited directory
2353 if f in vdirs: # visited directory
2354 d = f + '/'
2354 d = f + '/'
2355 for mf in matched:
2355 for mf in matched:
2356 if mf.startswith(d):
2356 if mf.startswith(d):
2357 break
2357 break
2358 else:
2358 else:
2359 fail(f, _("no match under directory!"))
2359 fail(f, _("no match under directory!"))
2360 elif f not in self.dirstate:
2360 elif f not in self.dirstate:
2361 fail(f, _("file not tracked!"))
2361 fail(f, _("file not tracked!"))
2362
2362
2363 @unfilteredmethod
2363 @unfilteredmethod
2364 def commit(self, text="", user=None, date=None, match=None, force=False,
2364 def commit(self, text="", user=None, date=None, match=None, force=False,
2365 editor=False, extra=None):
2365 editor=False, extra=None):
2366 """Add a new revision to current repository.
2366 """Add a new revision to current repository.
2367
2367
2368 Revision information is gathered from the working directory,
2368 Revision information is gathered from the working directory,
2369 match can be used to filter the committed files. If editor is
2369 match can be used to filter the committed files. If editor is
2370 supplied, it is called to get a commit message.
2370 supplied, it is called to get a commit message.
2371 """
2371 """
2372 if extra is None:
2372 if extra is None:
2373 extra = {}
2373 extra = {}
2374
2374
2375 def fail(f, msg):
2375 def fail(f, msg):
2376 raise error.Abort('%s: %s' % (f, msg))
2376 raise error.Abort('%s: %s' % (f, msg))
2377
2377
2378 if not match:
2378 if not match:
2379 match = matchmod.always(self.root, '')
2379 match = matchmod.always(self.root, '')
2380
2380
2381 if not force:
2381 if not force:
2382 vdirs = []
2382 vdirs = []
2383 match.explicitdir = vdirs.append
2383 match.explicitdir = vdirs.append
2384 match.bad = fail
2384 match.bad = fail
2385
2385
2386 wlock = lock = tr = None
2386 wlock = lock = tr = None
2387 try:
2387 try:
2388 wlock = self.wlock()
2388 wlock = self.wlock()
2389 lock = self.lock() # for recent changelog (see issue4368)
2389 lock = self.lock() # for recent changelog (see issue4368)
2390
2390
2391 wctx = self[None]
2391 wctx = self[None]
2392 merge = len(wctx.parents()) > 1
2392 merge = len(wctx.parents()) > 1
2393
2393
2394 if not force and merge and not match.always():
2394 if not force and merge and not match.always():
2395 raise error.Abort(_('cannot partially commit a merge '
2395 raise error.Abort(_('cannot partially commit a merge '
2396 '(do not specify files or patterns)'))
2396 '(do not specify files or patterns)'))
2397
2397
2398 status = self.status(match=match, clean=force)
2398 status = self.status(match=match, clean=force)
2399 if force:
2399 if force:
2400 status.modified.extend(status.clean) # mq may commit clean files
2400 status.modified.extend(status.clean) # mq may commit clean files
2401
2401
2402 # check subrepos
2402 # check subrepos
2403 subs, commitsubs, newstate = subrepoutil.precommit(
2403 subs, commitsubs, newstate = subrepoutil.precommit(
2404 self.ui, wctx, status, match, force=force)
2404 self.ui, wctx, status, match, force=force)
2405
2405
2406 # make sure all explicit patterns are matched
2406 # make sure all explicit patterns are matched
2407 if not force:
2407 if not force:
2408 self.checkcommitpatterns(wctx, vdirs, match, status, fail)
2408 self.checkcommitpatterns(wctx, vdirs, match, status, fail)
2409
2409
2410 cctx = context.workingcommitctx(self, status,
2410 cctx = context.workingcommitctx(self, status,
2411 text, user, date, extra)
2411 text, user, date, extra)
2412
2412
2413 # internal config: ui.allowemptycommit
2413 # internal config: ui.allowemptycommit
2414 allowemptycommit = (wctx.branch() != wctx.p1().branch()
2414 allowemptycommit = (wctx.branch() != wctx.p1().branch()
2415 or extra.get('close') or merge or cctx.files()
2415 or extra.get('close') or merge or cctx.files()
2416 or self.ui.configbool('ui', 'allowemptycommit'))
2416 or self.ui.configbool('ui', 'allowemptycommit'))
2417 if not allowemptycommit:
2417 if not allowemptycommit:
2418 return None
2418 return None
2419
2419
2420 if merge and cctx.deleted():
2420 if merge and cctx.deleted():
2421 raise error.Abort(_("cannot commit merge with missing files"))
2421 raise error.Abort(_("cannot commit merge with missing files"))
2422
2422
2423 ms = mergemod.mergestate.read(self)
2423 ms = mergemod.mergestate.read(self)
2424 mergeutil.checkunresolved(ms)
2424 mergeutil.checkunresolved(ms)
2425
2425
2426 if editor:
2426 if editor:
2427 cctx._text = editor(self, cctx, subs)
2427 cctx._text = editor(self, cctx, subs)
2428 edited = (text != cctx._text)
2428 edited = (text != cctx._text)
2429
2429
2430 # Save commit message in case this transaction gets rolled back
2430 # Save commit message in case this transaction gets rolled back
2431 # (e.g. by a pretxncommit hook). Leave the content alone on
2431 # (e.g. by a pretxncommit hook). Leave the content alone on
2432 # the assumption that the user will use the same editor again.
2432 # the assumption that the user will use the same editor again.
2433 msgfn = self.savecommitmessage(cctx._text)
2433 msgfn = self.savecommitmessage(cctx._text)
2434
2434
2435 # commit subs and write new state
2435 # commit subs and write new state
2436 if subs:
2436 if subs:
2437 for s in sorted(commitsubs):
2437 for s in sorted(commitsubs):
2438 sub = wctx.sub(s)
2438 sub = wctx.sub(s)
2439 self.ui.status(_('committing subrepository %s\n') %
2439 self.ui.status(_('committing subrepository %s\n') %
2440 subrepoutil.subrelpath(sub))
2440 subrepoutil.subrelpath(sub))
2441 sr = sub.commit(cctx._text, user, date)
2441 sr = sub.commit(cctx._text, user, date)
2442 newstate[s] = (newstate[s][0], sr)
2442 newstate[s] = (newstate[s][0], sr)
2443 subrepoutil.writestate(self, newstate)
2443 subrepoutil.writestate(self, newstate)
2444
2444
2445 p1, p2 = self.dirstate.parents()
2445 p1, p2 = self.dirstate.parents()
2446 hookp1, hookp2 = hex(p1), (p2 != nullid and hex(p2) or '')
2446 hookp1, hookp2 = hex(p1), (p2 != nullid and hex(p2) or '')
2447 try:
2447 try:
2448 self.hook("precommit", throw=True, parent1=hookp1,
2448 self.hook("precommit", throw=True, parent1=hookp1,
2449 parent2=hookp2)
2449 parent2=hookp2)
2450 tr = self.transaction('commit')
2450 tr = self.transaction('commit')
2451 ret = self.commitctx(cctx, True)
2451 ret = self.commitctx(cctx, True)
2452 except: # re-raises
2452 except: # re-raises
2453 if edited:
2453 if edited:
2454 self.ui.write(
2454 self.ui.write(
2455 _('note: commit message saved in %s\n') % msgfn)
2455 _('note: commit message saved in %s\n') % msgfn)
2456 raise
2456 raise
2457 # update bookmarks, dirstate and mergestate
2457 # update bookmarks, dirstate and mergestate
2458 bookmarks.update(self, [p1, p2], ret)
2458 bookmarks.update(self, [p1, p2], ret)
2459 cctx.markcommitted(ret)
2459 cctx.markcommitted(ret)
2460 ms.reset()
2460 ms.reset()
2461 tr.close()
2461 tr.close()
2462
2462
2463 finally:
2463 finally:
2464 lockmod.release(tr, lock, wlock)
2464 lockmod.release(tr, lock, wlock)
2465
2465
2466 def commithook(node=hex(ret), parent1=hookp1, parent2=hookp2):
2466 def commithook(node=hex(ret), parent1=hookp1, parent2=hookp2):
2467 # hack for command that use a temporary commit (eg: histedit)
2467 # hack for command that use a temporary commit (eg: histedit)
2468 # temporary commit got stripped before hook release
2468 # temporary commit got stripped before hook release
2469 if self.changelog.hasnode(ret):
2469 if self.changelog.hasnode(ret):
2470 self.hook("commit", node=node, parent1=parent1,
2470 self.hook("commit", node=node, parent1=parent1,
2471 parent2=parent2)
2471 parent2=parent2)
2472 self._afterlock(commithook)
2472 self._afterlock(commithook)
2473 return ret
2473 return ret
2474
2474
2475 @unfilteredmethod
2475 @unfilteredmethod
2476 def commitctx(self, ctx, error=False):
2476 def commitctx(self, ctx, error=False):
2477 """Add a new revision to current repository.
2477 """Add a new revision to current repository.
2478 Revision information is passed via the context argument.
2478 Revision information is passed via the context argument.
2479
2479
2480 ctx.files() should list all files involved in this commit, i.e.
2480 ctx.files() should list all files involved in this commit, i.e.
2481 modified/added/removed files. On merge, it may be wider than the
2481 modified/added/removed files. On merge, it may be wider than the
2482 ctx.files() to be committed, since any file nodes derived directly
2482 ctx.files() to be committed, since any file nodes derived directly
2483 from p1 or p2 are excluded from the committed ctx.files().
2483 from p1 or p2 are excluded from the committed ctx.files().
2484 """
2484 """
2485
2485
2486 tr = None
2486 tr = None
2487 p1, p2 = ctx.p1(), ctx.p2()
2487 p1, p2 = ctx.p1(), ctx.p2()
2488 user = ctx.user()
2488 user = ctx.user()
2489
2489
2490 lock = self.lock()
2490 lock = self.lock()
2491 try:
2491 try:
2492 tr = self.transaction("commit")
2492 tr = self.transaction("commit")
2493 trp = weakref.proxy(tr)
2493 trp = weakref.proxy(tr)
2494
2494
2495 if ctx.manifestnode():
2495 if ctx.manifestnode():
2496 # reuse an existing manifest revision
2496 # reuse an existing manifest revision
2497 self.ui.debug('reusing known manifest\n')
2497 self.ui.debug('reusing known manifest\n')
2498 mn = ctx.manifestnode()
2498 mn = ctx.manifestnode()
2499 files = ctx.files()
2499 files = ctx.files()
2500 elif ctx.files():
2500 elif ctx.files():
2501 m1ctx = p1.manifestctx()
2501 m1ctx = p1.manifestctx()
2502 m2ctx = p2.manifestctx()
2502 m2ctx = p2.manifestctx()
2503 mctx = m1ctx.copy()
2503 mctx = m1ctx.copy()
2504
2504
2505 m = mctx.read()
2505 m = mctx.read()
2506 m1 = m1ctx.read()
2506 m1 = m1ctx.read()
2507 m2 = m2ctx.read()
2507 m2 = m2ctx.read()
2508
2508
2509 # check in files
2509 # check in files
2510 added = []
2510 added = []
2511 changed = []
2511 changed = []
2512 removed = list(ctx.removed())
2512 removed = list(ctx.removed())
2513 linkrev = len(self)
2513 linkrev = len(self)
2514 self.ui.note(_("committing files:\n"))
2514 self.ui.note(_("committing files:\n"))
2515 for f in sorted(ctx.modified() + ctx.added()):
2515 for f in sorted(ctx.modified() + ctx.added()):
2516 self.ui.note(f + "\n")
2516 self.ui.note(f + "\n")
2517 try:
2517 try:
2518 fctx = ctx[f]
2518 fctx = ctx[f]
2519 if fctx is None:
2519 if fctx is None:
2520 removed.append(f)
2520 removed.append(f)
2521 else:
2521 else:
2522 added.append(f)
2522 added.append(f)
2523 m[f] = self._filecommit(fctx, m1, m2, linkrev,
2523 m[f] = self._filecommit(fctx, m1, m2, linkrev,
2524 trp, changed)
2524 trp, changed)
2525 m.setflag(f, fctx.flags())
2525 m.setflag(f, fctx.flags())
2526 except OSError as inst:
2526 except OSError as inst:
2527 self.ui.warn(_("trouble committing %s!\n") % f)
2527 self.ui.warn(_("trouble committing %s!\n") % f)
2528 raise
2528 raise
2529 except IOError as inst:
2529 except IOError as inst:
2530 errcode = getattr(inst, 'errno', errno.ENOENT)
2530 errcode = getattr(inst, 'errno', errno.ENOENT)
2531 if error or errcode and errcode != errno.ENOENT:
2531 if error or errcode and errcode != errno.ENOENT:
2532 self.ui.warn(_("trouble committing %s!\n") % f)
2532 self.ui.warn(_("trouble committing %s!\n") % f)
2533 raise
2533 raise
2534
2534
2535 # update manifest
2535 # update manifest
2536 removed = [f for f in sorted(removed) if f in m1 or f in m2]
2536 removed = [f for f in sorted(removed) if f in m1 or f in m2]
2537 drop = [f for f in removed if f in m]
2537 drop = [f for f in removed if f in m]
2538 for f in drop:
2538 for f in drop:
2539 del m[f]
2539 del m[f]
2540 files = changed + removed
2540 files = changed + removed
2541 md = None
2541 md = None
2542 if not files:
2542 if not files:
2543 # if no "files" actually changed in terms of the changelog,
2543 # if no "files" actually changed in terms of the changelog,
2544 # try hard to detect unmodified manifest entry so that the
2544 # try hard to detect unmodified manifest entry so that the
2545 # exact same commit can be reproduced later on convert.
2545 # exact same commit can be reproduced later on convert.
2546 md = m1.diff(m, scmutil.matchfiles(self, ctx.files()))
2546 md = m1.diff(m, scmutil.matchfiles(self, ctx.files()))
2547 if not files and md:
2547 if not files and md:
2548 self.ui.debug('not reusing manifest (no file change in '
2548 self.ui.debug('not reusing manifest (no file change in '
2549 'changelog, but manifest differs)\n')
2549 'changelog, but manifest differs)\n')
2550 if files or md:
2550 if files or md:
2551 self.ui.note(_("committing manifest\n"))
2551 self.ui.note(_("committing manifest\n"))
2552 # we're using narrowmatch here since it's already applied at
2552 # we're using narrowmatch here since it's already applied at
2553 # other stages (such as dirstate.walk), so we're already
2553 # other stages (such as dirstate.walk), so we're already
2554 # ignoring things outside of narrowspec in most cases. The
2554 # ignoring things outside of narrowspec in most cases. The
2555 # one case where we might have files outside the narrowspec
2555 # one case where we might have files outside the narrowspec
2556 # at this point is merges, and we already error out in the
2556 # at this point is merges, and we already error out in the
2557 # case where the merge has files outside of the narrowspec,
2557 # case where the merge has files outside of the narrowspec,
2558 # so this is safe.
2558 # so this is safe.
2559 mn = mctx.write(trp, linkrev,
2559 mn = mctx.write(trp, linkrev,
2560 p1.manifestnode(), p2.manifestnode(),
2560 p1.manifestnode(), p2.manifestnode(),
2561 added, drop, match=self.narrowmatch())
2561 added, drop, match=self.narrowmatch())
2562 else:
2562 else:
2563 self.ui.debug('reusing manifest form p1 (listed files '
2563 self.ui.debug('reusing manifest form p1 (listed files '
2564 'actually unchanged)\n')
2564 'actually unchanged)\n')
2565 mn = p1.manifestnode()
2565 mn = p1.manifestnode()
2566 else:
2566 else:
2567 self.ui.debug('reusing manifest from p1 (no file change)\n')
2567 self.ui.debug('reusing manifest from p1 (no file change)\n')
2568 mn = p1.manifestnode()
2568 mn = p1.manifestnode()
2569 files = []
2569 files = []
2570
2570
2571 # update changelog
2571 # update changelog
2572 self.ui.note(_("committing changelog\n"))
2572 self.ui.note(_("committing changelog\n"))
2573 self.changelog.delayupdate(tr)
2573 self.changelog.delayupdate(tr)
2574 n = self.changelog.add(mn, files, ctx.description(),
2574 n = self.changelog.add(mn, files, ctx.description(),
2575 trp, p1.node(), p2.node(),
2575 trp, p1.node(), p2.node(),
2576 user, ctx.date(), ctx.extra().copy())
2576 user, ctx.date(), ctx.extra().copy())
2577 xp1, xp2 = p1.hex(), p2 and p2.hex() or ''
2577 xp1, xp2 = p1.hex(), p2 and p2.hex() or ''
2578 self.hook('pretxncommit', throw=True, node=hex(n), parent1=xp1,
2578 self.hook('pretxncommit', throw=True, node=hex(n), parent1=xp1,
2579 parent2=xp2)
2579 parent2=xp2)
2580 # set the new commit is proper phase
2580 # set the new commit is proper phase
2581 targetphase = subrepoutil.newcommitphase(self.ui, ctx)
2581 targetphase = subrepoutil.newcommitphase(self.ui, ctx)
2582 if targetphase:
2582 if targetphase:
2583 # retract boundary do not alter parent changeset.
2583 # retract boundary do not alter parent changeset.
2584 # if a parent have higher the resulting phase will
2584 # if a parent have higher the resulting phase will
2585 # be compliant anyway
2585 # be compliant anyway
2586 #
2586 #
2587 # if minimal phase was 0 we don't need to retract anything
2587 # if minimal phase was 0 we don't need to retract anything
2588 phases.registernew(self, tr, targetphase, [n])
2588 phases.registernew(self, tr, targetphase, [n])
2589 tr.close()
2589 tr.close()
2590 return n
2590 return n
2591 finally:
2591 finally:
2592 if tr:
2592 if tr:
2593 tr.release()
2593 tr.release()
2594 lock.release()
2594 lock.release()
2595
2595
2596 @unfilteredmethod
2596 @unfilteredmethod
2597 def destroying(self):
2597 def destroying(self):
2598 '''Inform the repository that nodes are about to be destroyed.
2598 '''Inform the repository that nodes are about to be destroyed.
2599 Intended for use by strip and rollback, so there's a common
2599 Intended for use by strip and rollback, so there's a common
2600 place for anything that has to be done before destroying history.
2600 place for anything that has to be done before destroying history.
2601
2601
2602 This is mostly useful for saving state that is in memory and waiting
2602 This is mostly useful for saving state that is in memory and waiting
2603 to be flushed when the current lock is released. Because a call to
2603 to be flushed when the current lock is released. Because a call to
2604 destroyed is imminent, the repo will be invalidated causing those
2604 destroyed is imminent, the repo will be invalidated causing those
2605 changes to stay in memory (waiting for the next unlock), or vanish
2605 changes to stay in memory (waiting for the next unlock), or vanish
2606 completely.
2606 completely.
2607 '''
2607 '''
2608 # When using the same lock to commit and strip, the phasecache is left
2608 # When using the same lock to commit and strip, the phasecache is left
2609 # dirty after committing. Then when we strip, the repo is invalidated,
2609 # dirty after committing. Then when we strip, the repo is invalidated,
2610 # causing those changes to disappear.
2610 # causing those changes to disappear.
2611 if '_phasecache' in vars(self):
2611 if '_phasecache' in vars(self):
2612 self._phasecache.write()
2612 self._phasecache.write()
2613
2613
2614 @unfilteredmethod
2614 @unfilteredmethod
2615 def destroyed(self):
2615 def destroyed(self):
2616 '''Inform the repository that nodes have been destroyed.
2616 '''Inform the repository that nodes have been destroyed.
2617 Intended for use by strip and rollback, so there's a common
2617 Intended for use by strip and rollback, so there's a common
2618 place for anything that has to be done after destroying history.
2618 place for anything that has to be done after destroying history.
2619 '''
2619 '''
2620 # When one tries to:
2620 # When one tries to:
2621 # 1) destroy nodes thus calling this method (e.g. strip)
2621 # 1) destroy nodes thus calling this method (e.g. strip)
2622 # 2) use phasecache somewhere (e.g. commit)
2622 # 2) use phasecache somewhere (e.g. commit)
2623 #
2623 #
2624 # then 2) will fail because the phasecache contains nodes that were
2624 # then 2) will fail because the phasecache contains nodes that were
2625 # removed. We can either remove phasecache from the filecache,
2625 # removed. We can either remove phasecache from the filecache,
2626 # causing it to reload next time it is accessed, or simply filter
2626 # causing it to reload next time it is accessed, or simply filter
2627 # the removed nodes now and write the updated cache.
2627 # the removed nodes now and write the updated cache.
2628 self._phasecache.filterunknown(self)
2628 self._phasecache.filterunknown(self)
2629 self._phasecache.write()
2629 self._phasecache.write()
2630
2630
2631 # refresh all repository caches
2631 # refresh all repository caches
2632 self.updatecaches()
2632 self.updatecaches()
2633
2633
2634 # Ensure the persistent tag cache is updated. Doing it now
2634 # Ensure the persistent tag cache is updated. Doing it now
2635 # means that the tag cache only has to worry about destroyed
2635 # means that the tag cache only has to worry about destroyed
2636 # heads immediately after a strip/rollback. That in turn
2636 # heads immediately after a strip/rollback. That in turn
2637 # guarantees that "cachetip == currenttip" (comparing both rev
2637 # guarantees that "cachetip == currenttip" (comparing both rev
2638 # and node) always means no nodes have been added or destroyed.
2638 # and node) always means no nodes have been added or destroyed.
2639
2639
2640 # XXX this is suboptimal when qrefresh'ing: we strip the current
2640 # XXX this is suboptimal when qrefresh'ing: we strip the current
2641 # head, refresh the tag cache, then immediately add a new head.
2641 # head, refresh the tag cache, then immediately add a new head.
2642 # But I think doing it this way is necessary for the "instant
2642 # But I think doing it this way is necessary for the "instant
2643 # tag cache retrieval" case to work.
2643 # tag cache retrieval" case to work.
2644 self.invalidate()
2644 self.invalidate()
2645
2645
2646 def status(self, node1='.', node2=None, match=None,
2646 def status(self, node1='.', node2=None, match=None,
2647 ignored=False, clean=False, unknown=False,
2647 ignored=False, clean=False, unknown=False,
2648 listsubrepos=False):
2648 listsubrepos=False):
2649 '''a convenience method that calls node1.status(node2)'''
2649 '''a convenience method that calls node1.status(node2)'''
2650 return self[node1].status(node2, match, ignored, clean, unknown,
2650 return self[node1].status(node2, match, ignored, clean, unknown,
2651 listsubrepos)
2651 listsubrepos)
2652
2652
2653 def addpostdsstatus(self, ps):
2653 def addpostdsstatus(self, ps):
2654 """Add a callback to run within the wlock, at the point at which status
2654 """Add a callback to run within the wlock, at the point at which status
2655 fixups happen.
2655 fixups happen.
2656
2656
2657 On status completion, callback(wctx, status) will be called with the
2657 On status completion, callback(wctx, status) will be called with the
2658 wlock held, unless the dirstate has changed from underneath or the wlock
2658 wlock held, unless the dirstate has changed from underneath or the wlock
2659 couldn't be grabbed.
2659 couldn't be grabbed.
2660
2660
2661 Callbacks should not capture and use a cached copy of the dirstate --
2661 Callbacks should not capture and use a cached copy of the dirstate --
2662 it might change in the meanwhile. Instead, they should access the
2662 it might change in the meanwhile. Instead, they should access the
2663 dirstate via wctx.repo().dirstate.
2663 dirstate via wctx.repo().dirstate.
2664
2664
2665 This list is emptied out after each status run -- extensions should
2665 This list is emptied out after each status run -- extensions should
2666 make sure it adds to this list each time dirstate.status is called.
2666 make sure it adds to this list each time dirstate.status is called.
2667 Extensions should also make sure they don't call this for statuses
2667 Extensions should also make sure they don't call this for statuses
2668 that don't involve the dirstate.
2668 that don't involve the dirstate.
2669 """
2669 """
2670
2670
2671 # The list is located here for uniqueness reasons -- it is actually
2671 # The list is located here for uniqueness reasons -- it is actually
2672 # managed by the workingctx, but that isn't unique per-repo.
2672 # managed by the workingctx, but that isn't unique per-repo.
2673 self._postdsstatus.append(ps)
2673 self._postdsstatus.append(ps)
2674
2674
2675 def postdsstatus(self):
2675 def postdsstatus(self):
2676 """Used by workingctx to get the list of post-dirstate-status hooks."""
2676 """Used by workingctx to get the list of post-dirstate-status hooks."""
2677 return self._postdsstatus
2677 return self._postdsstatus
2678
2678
2679 def clearpostdsstatus(self):
2679 def clearpostdsstatus(self):
2680 """Used by workingctx to clear post-dirstate-status hooks."""
2680 """Used by workingctx to clear post-dirstate-status hooks."""
2681 del self._postdsstatus[:]
2681 del self._postdsstatus[:]
2682
2682
2683 def heads(self, start=None):
2683 def heads(self, start=None):
2684 if start is None:
2684 if start is None:
2685 cl = self.changelog
2685 cl = self.changelog
2686 headrevs = reversed(cl.headrevs())
2686 headrevs = reversed(cl.headrevs())
2687 return [cl.node(rev) for rev in headrevs]
2687 return [cl.node(rev) for rev in headrevs]
2688
2688
2689 heads = self.changelog.heads(start)
2689 heads = self.changelog.heads(start)
2690 # sort the output in rev descending order
2690 # sort the output in rev descending order
2691 return sorted(heads, key=self.changelog.rev, reverse=True)
2691 return sorted(heads, key=self.changelog.rev, reverse=True)
2692
2692
2693 def branchheads(self, branch=None, start=None, closed=False):
2693 def branchheads(self, branch=None, start=None, closed=False):
2694 '''return a (possibly filtered) list of heads for the given branch
2694 '''return a (possibly filtered) list of heads for the given branch
2695
2695
2696 Heads are returned in topological order, from newest to oldest.
2696 Heads are returned in topological order, from newest to oldest.
2697 If branch is None, use the dirstate branch.
2697 If branch is None, use the dirstate branch.
2698 If start is not None, return only heads reachable from start.
2698 If start is not None, return only heads reachable from start.
2699 If closed is True, return heads that are marked as closed as well.
2699 If closed is True, return heads that are marked as closed as well.
2700 '''
2700 '''
2701 if branch is None:
2701 if branch is None:
2702 branch = self[None].branch()
2702 branch = self[None].branch()
2703 branches = self.branchmap()
2703 branches = self.branchmap()
2704 if branch not in branches:
2704 if branch not in branches:
2705 return []
2705 return []
2706 # the cache returns heads ordered lowest to highest
2706 # the cache returns heads ordered lowest to highest
2707 bheads = list(reversed(branches.branchheads(branch, closed=closed)))
2707 bheads = list(reversed(branches.branchheads(branch, closed=closed)))
2708 if start is not None:
2708 if start is not None:
2709 # filter out the heads that cannot be reached from startrev
2709 # filter out the heads that cannot be reached from startrev
2710 fbheads = set(self.changelog.nodesbetween([start], bheads)[2])
2710 fbheads = set(self.changelog.nodesbetween([start], bheads)[2])
2711 bheads = [h for h in bheads if h in fbheads]
2711 bheads = [h for h in bheads if h in fbheads]
2712 return bheads
2712 return bheads
2713
2713
2714 def branches(self, nodes):
2714 def branches(self, nodes):
2715 if not nodes:
2715 if not nodes:
2716 nodes = [self.changelog.tip()]
2716 nodes = [self.changelog.tip()]
2717 b = []
2717 b = []
2718 for n in nodes:
2718 for n in nodes:
2719 t = n
2719 t = n
2720 while True:
2720 while True:
2721 p = self.changelog.parents(n)
2721 p = self.changelog.parents(n)
2722 if p[1] != nullid or p[0] == nullid:
2722 if p[1] != nullid or p[0] == nullid:
2723 b.append((t, n, p[0], p[1]))
2723 b.append((t, n, p[0], p[1]))
2724 break
2724 break
2725 n = p[0]
2725 n = p[0]
2726 return b
2726 return b
2727
2727
2728 def between(self, pairs):
2728 def between(self, pairs):
2729 r = []
2729 r = []
2730
2730
2731 for top, bottom in pairs:
2731 for top, bottom in pairs:
2732 n, l, i = top, [], 0
2732 n, l, i = top, [], 0
2733 f = 1
2733 f = 1
2734
2734
2735 while n != bottom and n != nullid:
2735 while n != bottom and n != nullid:
2736 p = self.changelog.parents(n)[0]
2736 p = self.changelog.parents(n)[0]
2737 if i == f:
2737 if i == f:
2738 l.append(n)
2738 l.append(n)
2739 f = f * 2
2739 f = f * 2
2740 n = p
2740 n = p
2741 i += 1
2741 i += 1
2742
2742
2743 r.append(l)
2743 r.append(l)
2744
2744
2745 return r
2745 return r
2746
2746
2747 def checkpush(self, pushop):
2747 def checkpush(self, pushop):
2748 """Extensions can override this function if additional checks have
2748 """Extensions can override this function if additional checks have
2749 to be performed before pushing, or call it if they override push
2749 to be performed before pushing, or call it if they override push
2750 command.
2750 command.
2751 """
2751 """
2752
2752
2753 @unfilteredpropertycache
2753 @unfilteredpropertycache
2754 def prepushoutgoinghooks(self):
2754 def prepushoutgoinghooks(self):
2755 """Return util.hooks consists of a pushop with repo, remote, outgoing
2755 """Return util.hooks consists of a pushop with repo, remote, outgoing
2756 methods, which are called before pushing changesets.
2756 methods, which are called before pushing changesets.
2757 """
2757 """
2758 return util.hooks()
2758 return util.hooks()
2759
2759
2760 def pushkey(self, namespace, key, old, new):
2760 def pushkey(self, namespace, key, old, new):
2761 try:
2761 try:
2762 tr = self.currenttransaction()
2762 tr = self.currenttransaction()
2763 hookargs = {}
2763 hookargs = {}
2764 if tr is not None:
2764 if tr is not None:
2765 hookargs.update(tr.hookargs)
2765 hookargs.update(tr.hookargs)
2766 hookargs = pycompat.strkwargs(hookargs)
2766 hookargs = pycompat.strkwargs(hookargs)
2767 hookargs[r'namespace'] = namespace
2767 hookargs[r'namespace'] = namespace
2768 hookargs[r'key'] = key
2768 hookargs[r'key'] = key
2769 hookargs[r'old'] = old
2769 hookargs[r'old'] = old
2770 hookargs[r'new'] = new
2770 hookargs[r'new'] = new
2771 self.hook('prepushkey', throw=True, **hookargs)
2771 self.hook('prepushkey', throw=True, **hookargs)
2772 except error.HookAbort as exc:
2772 except error.HookAbort as exc:
2773 self.ui.write_err(_("pushkey-abort: %s\n") % exc)
2773 self.ui.write_err(_("pushkey-abort: %s\n") % exc)
2774 if exc.hint:
2774 if exc.hint:
2775 self.ui.write_err(_("(%s)\n") % exc.hint)
2775 self.ui.write_err(_("(%s)\n") % exc.hint)
2776 return False
2776 return False
2777 self.ui.debug('pushing key for "%s:%s"\n' % (namespace, key))
2777 self.ui.debug('pushing key for "%s:%s"\n' % (namespace, key))
2778 ret = pushkey.push(self, namespace, key, old, new)
2778 ret = pushkey.push(self, namespace, key, old, new)
2779 def runhook():
2779 def runhook():
2780 self.hook('pushkey', namespace=namespace, key=key, old=old, new=new,
2780 self.hook('pushkey', namespace=namespace, key=key, old=old, new=new,
2781 ret=ret)
2781 ret=ret)
2782 self._afterlock(runhook)
2782 self._afterlock(runhook)
2783 return ret
2783 return ret
2784
2784
2785 def listkeys(self, namespace):
2785 def listkeys(self, namespace):
2786 self.hook('prelistkeys', throw=True, namespace=namespace)
2786 self.hook('prelistkeys', throw=True, namespace=namespace)
2787 self.ui.debug('listing keys for "%s"\n' % namespace)
2787 self.ui.debug('listing keys for "%s"\n' % namespace)
2788 values = pushkey.list(self, namespace)
2788 values = pushkey.list(self, namespace)
2789 self.hook('listkeys', namespace=namespace, values=values)
2789 self.hook('listkeys', namespace=namespace, values=values)
2790 return values
2790 return values
2791
2791
2792 def debugwireargs(self, one, two, three=None, four=None, five=None):
2792 def debugwireargs(self, one, two, three=None, four=None, five=None):
2793 '''used to test argument passing over the wire'''
2793 '''used to test argument passing over the wire'''
2794 return "%s %s %s %s %s" % (one, two, pycompat.bytestr(three),
2794 return "%s %s %s %s %s" % (one, two, pycompat.bytestr(three),
2795 pycompat.bytestr(four),
2795 pycompat.bytestr(four),
2796 pycompat.bytestr(five))
2796 pycompat.bytestr(five))
2797
2797
2798 def savecommitmessage(self, text):
2798 def savecommitmessage(self, text):
2799 fp = self.vfs('last-message.txt', 'wb')
2799 fp = self.vfs('last-message.txt', 'wb')
2800 try:
2800 try:
2801 fp.write(text)
2801 fp.write(text)
2802 finally:
2802 finally:
2803 fp.close()
2803 fp.close()
2804 return self.pathto(fp.name[len(self.root) + 1:])
2804 return self.pathto(fp.name[len(self.root) + 1:])
2805
2805
2806 # used to avoid circular references so destructors work
2806 # used to avoid circular references so destructors work
2807 def aftertrans(files):
2807 def aftertrans(files):
2808 renamefiles = [tuple(t) for t in files]
2808 renamefiles = [tuple(t) for t in files]
2809 def a():
2809 def a():
2810 for vfs, src, dest in renamefiles:
2810 for vfs, src, dest in renamefiles:
2811 # if src and dest refer to a same file, vfs.rename is a no-op,
2811 # if src and dest refer to a same file, vfs.rename is a no-op,
2812 # leaving both src and dest on disk. delete dest to make sure
2812 # leaving both src and dest on disk. delete dest to make sure
2813 # the rename couldn't be such a no-op.
2813 # the rename couldn't be such a no-op.
2814 vfs.tryunlink(dest)
2814 vfs.tryunlink(dest)
2815 try:
2815 try:
2816 vfs.rename(src, dest)
2816 vfs.rename(src, dest)
2817 except OSError: # journal file does not yet exist
2817 except OSError: # journal file does not yet exist
2818 pass
2818 pass
2819 return a
2819 return a
2820
2820
2821 def undoname(fn):
2821 def undoname(fn):
2822 base, name = os.path.split(fn)
2822 base, name = os.path.split(fn)
2823 assert name.startswith('journal')
2823 assert name.startswith('journal')
2824 return os.path.join(base, name.replace('journal', 'undo', 1))
2824 return os.path.join(base, name.replace('journal', 'undo', 1))
2825
2825
2826 def instance(ui, path, create, intents=None, createopts=None):
2826 def instance(ui, path, create, intents=None, createopts=None):
2827 localpath = util.urllocalpath(path)
2827 localpath = util.urllocalpath(path)
2828 if create:
2828 if create:
2829 createrepository(ui, localpath, createopts=createopts)
2829 createrepository(ui, localpath, createopts=createopts)
2830
2830
2831 return makelocalrepository(ui, localpath, intents=intents)
2831 return makelocalrepository(ui, localpath, intents=intents)
2832
2832
2833 def islocal(path):
2833 def islocal(path):
2834 return True
2834 return True
2835
2835
2836 def defaultcreateopts(ui, createopts=None):
2836 def defaultcreateopts(ui, createopts=None):
2837 """Populate the default creation options for a repository.
2837 """Populate the default creation options for a repository.
2838
2838
2839 A dictionary of explicitly requested creation options can be passed
2839 A dictionary of explicitly requested creation options can be passed
2840 in. Missing keys will be populated.
2840 in. Missing keys will be populated.
2841 """
2841 """
2842 createopts = dict(createopts or {})
2842 createopts = dict(createopts or {})
2843
2843
2844 if 'backend' not in createopts:
2844 if 'backend' not in createopts:
2845 # experimental config: storage.new-repo-backend
2845 # experimental config: storage.new-repo-backend
2846 createopts['backend'] = ui.config('storage', 'new-repo-backend')
2846 createopts['backend'] = ui.config('storage', 'new-repo-backend')
2847
2847
2848 return createopts
2848 return createopts
2849
2849
2850 def newreporequirements(ui, createopts):
2850 def newreporequirements(ui, createopts):
2851 """Determine the set of requirements for a new local repository.
2851 """Determine the set of requirements for a new local repository.
2852
2852
2853 Extensions can wrap this function to specify custom requirements for
2853 Extensions can wrap this function to specify custom requirements for
2854 new repositories.
2854 new repositories.
2855 """
2855 """
2856 # If the repo is being created from a shared repository, we copy
2856 # If the repo is being created from a shared repository, we copy
2857 # its requirements.
2857 # its requirements.
2858 if 'sharedrepo' in createopts:
2858 if 'sharedrepo' in createopts:
2859 requirements = set(createopts['sharedrepo'].requirements)
2859 requirements = set(createopts['sharedrepo'].requirements)
2860 if createopts.get('sharedrelative'):
2860 if createopts.get('sharedrelative'):
2861 requirements.add('relshared')
2861 requirements.add('relshared')
2862 else:
2862 else:
2863 requirements.add('shared')
2863 requirements.add('shared')
2864
2864
2865 return requirements
2865 return requirements
2866
2866
2867 if 'backend' not in createopts:
2867 if 'backend' not in createopts:
2868 raise error.ProgrammingError('backend key not present in createopts; '
2868 raise error.ProgrammingError('backend key not present in createopts; '
2869 'was defaultcreateopts() called?')
2869 'was defaultcreateopts() called?')
2870
2870
2871 if createopts['backend'] != 'revlogv1':
2871 if createopts['backend'] != 'revlogv1':
2872 raise error.Abort(_('unable to determine repository requirements for '
2872 raise error.Abort(_('unable to determine repository requirements for '
2873 'storage backend: %s') % createopts['backend'])
2873 'storage backend: %s') % createopts['backend'])
2874
2874
2875 requirements = {'revlogv1'}
2875 requirements = {'revlogv1'}
2876 if ui.configbool('format', 'usestore'):
2876 if ui.configbool('format', 'usestore'):
2877 requirements.add('store')
2877 requirements.add('store')
2878 if ui.configbool('format', 'usefncache'):
2878 if ui.configbool('format', 'usefncache'):
2879 requirements.add('fncache')
2879 requirements.add('fncache')
2880 if ui.configbool('format', 'dotencode'):
2880 if ui.configbool('format', 'dotencode'):
2881 requirements.add('dotencode')
2881 requirements.add('dotencode')
2882
2882
2883 compengine = ui.config('experimental', 'format.compression')
2883 compengine = ui.config('experimental', 'format.compression')
2884 if compengine not in util.compengines:
2884 if compengine not in util.compengines:
2885 raise error.Abort(_('compression engine %s defined by '
2885 raise error.Abort(_('compression engine %s defined by '
2886 'experimental.format.compression not available') %
2886 'experimental.format.compression not available') %
2887 compengine,
2887 compengine,
2888 hint=_('run "hg debuginstall" to list available '
2888 hint=_('run "hg debuginstall" to list available '
2889 'compression engines'))
2889 'compression engines'))
2890
2890
2891 # zlib is the historical default and doesn't need an explicit requirement.
2891 # zlib is the historical default and doesn't need an explicit requirement.
2892 if compengine != 'zlib':
2892 if compengine != 'zlib':
2893 requirements.add('exp-compression-%s' % compengine)
2893 requirements.add('exp-compression-%s' % compengine)
2894
2894
2895 if scmutil.gdinitconfig(ui):
2895 if scmutil.gdinitconfig(ui):
2896 requirements.add('generaldelta')
2896 requirements.add('generaldelta')
2897 if ui.configbool('experimental', 'treemanifest'):
2897 if ui.configbool('experimental', 'treemanifest'):
2898 requirements.add('treemanifest')
2898 requirements.add('treemanifest')
2899 # experimental config: format.sparse-revlog
2899 # experimental config: format.sparse-revlog
2900 if ui.configbool('format', 'sparse-revlog'):
2900 if ui.configbool('format', 'sparse-revlog'):
2901 requirements.add(SPARSEREVLOG_REQUIREMENT)
2901 requirements.add(SPARSEREVLOG_REQUIREMENT)
2902
2902
2903 revlogv2 = ui.config('experimental', 'revlogv2')
2903 revlogv2 = ui.config('experimental', 'revlogv2')
2904 if revlogv2 == 'enable-unstable-format-and-corrupt-my-data':
2904 if revlogv2 == 'enable-unstable-format-and-corrupt-my-data':
2905 requirements.remove('revlogv1')
2905 requirements.remove('revlogv1')
2906 # generaldelta is implied by revlogv2.
2906 # generaldelta is implied by revlogv2.
2907 requirements.discard('generaldelta')
2907 requirements.discard('generaldelta')
2908 requirements.add(REVLOGV2_REQUIREMENT)
2908 requirements.add(REVLOGV2_REQUIREMENT)
2909 # experimental config: format.internal-phase
2909 # experimental config: format.internal-phase
2910 if ui.configbool('format', 'internal-phase'):
2910 if ui.configbool('format', 'internal-phase'):
2911 requirements.add('internal-phase')
2911 requirements.add('internal-phase')
2912
2912
2913 if createopts.get('narrowfiles'):
2913 if createopts.get('narrowfiles'):
2914 requirements.add(repository.NARROW_REQUIREMENT)
2914 requirements.add(repository.NARROW_REQUIREMENT)
2915
2915
2916 if createopts.get('lfs'):
2916 if createopts.get('lfs'):
2917 requirements.add('lfs')
2917 requirements.add('lfs')
2918
2918
2919 return requirements
2919 return requirements
2920
2920
2921 def filterknowncreateopts(ui, createopts):
2921 def filterknowncreateopts(ui, createopts):
2922 """Filters a dict of repo creation options against options that are known.
2922 """Filters a dict of repo creation options against options that are known.
2923
2923
2924 Receives a dict of repo creation options and returns a dict of those
2924 Receives a dict of repo creation options and returns a dict of those
2925 options that we don't know how to handle.
2925 options that we don't know how to handle.
2926
2926
2927 This function is called as part of repository creation. If the
2927 This function is called as part of repository creation. If the
2928 returned dict contains any items, repository creation will not
2928 returned dict contains any items, repository creation will not
2929 be allowed, as it means there was a request to create a repository
2929 be allowed, as it means there was a request to create a repository
2930 with options not recognized by loaded code.
2930 with options not recognized by loaded code.
2931
2931
2932 Extensions can wrap this function to filter out creation options
2932 Extensions can wrap this function to filter out creation options
2933 they know how to handle.
2933 they know how to handle.
2934 """
2934 """
2935 known = {
2935 known = {
2936 'backend',
2936 'backend',
2937 'lfs',
2937 'lfs',
2938 'narrowfiles',
2938 'narrowfiles',
2939 'sharedrepo',
2939 'sharedrepo',
2940 'sharedrelative',
2940 'sharedrelative',
2941 'shareditems',
2941 'shareditems',
2942 'shallowfilestore',
2942 'shallowfilestore',
2943 }
2943 }
2944
2944
2945 return {k: v for k, v in createopts.items() if k not in known}
2945 return {k: v for k, v in createopts.items() if k not in known}
2946
2946
2947 def createrepository(ui, path, createopts=None):
2947 def createrepository(ui, path, createopts=None):
2948 """Create a new repository in a vfs.
2948 """Create a new repository in a vfs.
2949
2949
2950 ``path`` path to the new repo's working directory.
2950 ``path`` path to the new repo's working directory.
2951 ``createopts`` options for the new repository.
2951 ``createopts`` options for the new repository.
2952
2952
2953 The following keys for ``createopts`` are recognized:
2953 The following keys for ``createopts`` are recognized:
2954
2954
2955 backend
2955 backend
2956 The storage backend to use.
2956 The storage backend to use.
2957 lfs
2957 lfs
2958 Repository will be created with ``lfs`` requirement. The lfs extension
2958 Repository will be created with ``lfs`` requirement. The lfs extension
2959 will automatically be loaded when the repository is accessed.
2959 will automatically be loaded when the repository is accessed.
2960 narrowfiles
2960 narrowfiles
2961 Set up repository to support narrow file storage.
2961 Set up repository to support narrow file storage.
2962 sharedrepo
2962 sharedrepo
2963 Repository object from which storage should be shared.
2963 Repository object from which storage should be shared.
2964 sharedrelative
2964 sharedrelative
2965 Boolean indicating if the path to the shared repo should be
2965 Boolean indicating if the path to the shared repo should be
2966 stored as relative. By default, the pointer to the "parent" repo
2966 stored as relative. By default, the pointer to the "parent" repo
2967 is stored as an absolute path.
2967 is stored as an absolute path.
2968 shareditems
2968 shareditems
2969 Set of items to share to the new repository (in addition to storage).
2969 Set of items to share to the new repository (in addition to storage).
2970 shallowfilestore
2970 shallowfilestore
2971 Indicates that storage for files should be shallow (not all ancestor
2971 Indicates that storage for files should be shallow (not all ancestor
2972 revisions are known).
2972 revisions are known).
2973 """
2973 """
2974 createopts = defaultcreateopts(ui, createopts=createopts)
2974 createopts = defaultcreateopts(ui, createopts=createopts)
2975
2975
2976 unknownopts = filterknowncreateopts(ui, createopts)
2976 unknownopts = filterknowncreateopts(ui, createopts)
2977
2977
2978 if not isinstance(unknownopts, dict):
2978 if not isinstance(unknownopts, dict):
2979 raise error.ProgrammingError('filterknowncreateopts() did not return '
2979 raise error.ProgrammingError('filterknowncreateopts() did not return '
2980 'a dict')
2980 'a dict')
2981
2981
2982 if unknownopts:
2982 if unknownopts:
2983 raise error.Abort(_('unable to create repository because of unknown '
2983 raise error.Abort(_('unable to create repository because of unknown '
2984 'creation option: %s') %
2984 'creation option: %s') %
2985 ', '.join(sorted(unknownopts)),
2985 ', '.join(sorted(unknownopts)),
2986 hint=_('is a required extension not loaded?'))
2986 hint=_('is a required extension not loaded?'))
2987
2987
2988 requirements = newreporequirements(ui, createopts=createopts)
2988 requirements = newreporequirements(ui, createopts=createopts)
2989
2989
2990 wdirvfs = vfsmod.vfs(path, expandpath=True, realpath=True)
2990 wdirvfs = vfsmod.vfs(path, expandpath=True, realpath=True)
2991
2991
2992 hgvfs = vfsmod.vfs(wdirvfs.join(b'.hg'))
2992 hgvfs = vfsmod.vfs(wdirvfs.join(b'.hg'))
2993 if hgvfs.exists():
2993 if hgvfs.exists():
2994 raise error.RepoError(_('repository %s already exists') % path)
2994 raise error.RepoError(_('repository %s already exists') % path)
2995
2995
2996 if 'sharedrepo' in createopts:
2996 if 'sharedrepo' in createopts:
2997 sharedpath = createopts['sharedrepo'].sharedpath
2997 sharedpath = createopts['sharedrepo'].sharedpath
2998
2998
2999 if createopts.get('sharedrelative'):
2999 if createopts.get('sharedrelative'):
3000 try:
3000 try:
3001 sharedpath = os.path.relpath(sharedpath, hgvfs.base)
3001 sharedpath = os.path.relpath(sharedpath, hgvfs.base)
3002 except (IOError, ValueError) as e:
3002 except (IOError, ValueError) as e:
3003 # ValueError is raised on Windows if the drive letters differ
3003 # ValueError is raised on Windows if the drive letters differ
3004 # on each path.
3004 # on each path.
3005 raise error.Abort(_('cannot calculate relative path'),
3005 raise error.Abort(_('cannot calculate relative path'),
3006 hint=stringutil.forcebytestr(e))
3006 hint=stringutil.forcebytestr(e))
3007
3007
3008 if not wdirvfs.exists():
3008 if not wdirvfs.exists():
3009 wdirvfs.makedirs()
3009 wdirvfs.makedirs()
3010
3010
3011 hgvfs.makedir(notindexed=True)
3011 hgvfs.makedir(notindexed=True)
3012
3012
3013 if b'store' in requirements and 'sharedrepo' not in createopts:
3013 if b'store' in requirements and 'sharedrepo' not in createopts:
3014 hgvfs.mkdir(b'store')
3014 hgvfs.mkdir(b'store')
3015
3015
3016 # We create an invalid changelog outside the store so very old
3016 # We create an invalid changelog outside the store so very old
3017 # Mercurial versions (which didn't know about the requirements
3017 # Mercurial versions (which didn't know about the requirements
3018 # file) encounter an error on reading the changelog. This
3018 # file) encounter an error on reading the changelog. This
3019 # effectively locks out old clients and prevents them from
3019 # effectively locks out old clients and prevents them from
3020 # mucking with a repo in an unknown format.
3020 # mucking with a repo in an unknown format.
3021 #
3021 #
3022 # The revlog header has version 2, which won't be recognized by
3022 # The revlog header has version 2, which won't be recognized by
3023 # such old clients.
3023 # such old clients.
3024 hgvfs.append(b'00changelog.i',
3024 hgvfs.append(b'00changelog.i',
3025 b'\0\0\0\2 dummy changelog to prevent using the old repo '
3025 b'\0\0\0\2 dummy changelog to prevent using the old repo '
3026 b'layout')
3026 b'layout')
3027
3027
3028 scmutil.writerequires(hgvfs, requirements)
3028 scmutil.writerequires(hgvfs, requirements)
3029
3029
3030 # Write out file telling readers where to find the shared store.
3030 # Write out file telling readers where to find the shared store.
3031 if 'sharedrepo' in createopts:
3031 if 'sharedrepo' in createopts:
3032 hgvfs.write(b'sharedpath', sharedpath)
3032 hgvfs.write(b'sharedpath', sharedpath)
3033
3033
3034 if createopts.get('shareditems'):
3034 if createopts.get('shareditems'):
3035 shared = b'\n'.join(sorted(createopts['shareditems'])) + b'\n'
3035 shared = b'\n'.join(sorted(createopts['shareditems'])) + b'\n'
3036 hgvfs.write(b'shared', shared)
3036 hgvfs.write(b'shared', shared)
3037
3037
3038 def poisonrepository(repo):
3038 def poisonrepository(repo):
3039 """Poison a repository instance so it can no longer be used."""
3039 """Poison a repository instance so it can no longer be used."""
3040 # Perform any cleanup on the instance.
3040 # Perform any cleanup on the instance.
3041 repo.close()
3041 repo.close()
3042
3042
3043 # Our strategy is to replace the type of the object with one that
3043 # Our strategy is to replace the type of the object with one that
3044 # has all attribute lookups result in error.
3044 # has all attribute lookups result in error.
3045 #
3045 #
3046 # But we have to allow the close() method because some constructors
3046 # But we have to allow the close() method because some constructors
3047 # of repos call close() on repo references.
3047 # of repos call close() on repo references.
3048 class poisonedrepository(object):
3048 class poisonedrepository(object):
3049 def __getattribute__(self, item):
3049 def __getattribute__(self, item):
3050 if item == r'close':
3050 if item == r'close':
3051 return object.__getattribute__(self, item)
3051 return object.__getattribute__(self, item)
3052
3052
3053 raise error.ProgrammingError('repo instances should not be used '
3053 raise error.ProgrammingError('repo instances should not be used '
3054 'after unshare')
3054 'after unshare')
3055
3055
3056 def close(self):
3056 def close(self):
3057 pass
3057 pass
3058
3058
3059 # We may have a repoview, which intercepts __setattr__. So be sure
3059 # We may have a repoview, which intercepts __setattr__. So be sure
3060 # we operate at the lowest level possible.
3060 # we operate at the lowest level possible.
3061 object.__setattr__(repo, r'__class__', poisonedrepository)
3061 object.__setattr__(repo, r'__class__', poisonedrepository)
General Comments 0
You need to be logged in to leave comments. Login now