##// END OF EJS Templates
narrow: when writing treemanifests, skip inspecting directories outside narrow...
spectral -
r39704:24870f1b default
parent child Browse files
Show More
@@ -1,2530 +1,2537 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 hex,
20 hex,
21 nullid,
21 nullid,
22 short,
22 short,
23 )
23 )
24 from . import (
24 from . import (
25 bookmarks,
25 bookmarks,
26 branchmap,
26 branchmap,
27 bundle2,
27 bundle2,
28 changegroup,
28 changegroup,
29 changelog,
29 changelog,
30 color,
30 color,
31 context,
31 context,
32 dirstate,
32 dirstate,
33 dirstateguard,
33 dirstateguard,
34 discovery,
34 discovery,
35 encoding,
35 encoding,
36 error,
36 error,
37 exchange,
37 exchange,
38 extensions,
38 extensions,
39 filelog,
39 filelog,
40 hook,
40 hook,
41 lock as lockmod,
41 lock as lockmod,
42 manifest,
42 manifest,
43 match as matchmod,
43 match as matchmod,
44 merge as mergemod,
44 merge as mergemod,
45 mergeutil,
45 mergeutil,
46 namespaces,
46 namespaces,
47 narrowspec,
47 narrowspec,
48 obsolete,
48 obsolete,
49 pathutil,
49 pathutil,
50 phases,
50 phases,
51 pushkey,
51 pushkey,
52 pycompat,
52 pycompat,
53 repository,
53 repository,
54 repoview,
54 repoview,
55 revset,
55 revset,
56 revsetlang,
56 revsetlang,
57 scmutil,
57 scmutil,
58 sparse,
58 sparse,
59 store,
59 store,
60 subrepoutil,
60 subrepoutil,
61 tags as tagsmod,
61 tags as tagsmod,
62 transaction,
62 transaction,
63 txnutil,
63 txnutil,
64 util,
64 util,
65 vfs as vfsmod,
65 vfs as vfsmod,
66 )
66 )
67 from .utils import (
67 from .utils import (
68 interfaceutil,
68 interfaceutil,
69 procutil,
69 procutil,
70 stringutil,
70 stringutil,
71 )
71 )
72
72
73 from .revlogutils import (
73 from .revlogutils import (
74 constants as revlogconst,
74 constants as revlogconst,
75 )
75 )
76
76
77 release = lockmod.release
77 release = lockmod.release
78 urlerr = util.urlerr
78 urlerr = util.urlerr
79 urlreq = util.urlreq
79 urlreq = util.urlreq
80
80
81 # set of (path, vfs-location) tuples. vfs-location is:
81 # set of (path, vfs-location) tuples. vfs-location is:
82 # - 'plain for vfs relative paths
82 # - 'plain for vfs relative paths
83 # - '' for svfs relative paths
83 # - '' for svfs relative paths
84 _cachedfiles = set()
84 _cachedfiles = set()
85
85
86 class _basefilecache(scmutil.filecache):
86 class _basefilecache(scmutil.filecache):
87 """All filecache usage on repo are done for logic that should be unfiltered
87 """All filecache usage on repo are done for logic that should be unfiltered
88 """
88 """
89 def __get__(self, repo, type=None):
89 def __get__(self, repo, type=None):
90 if repo is None:
90 if repo is None:
91 return self
91 return self
92 return super(_basefilecache, self).__get__(repo.unfiltered(), type)
92 return super(_basefilecache, self).__get__(repo.unfiltered(), type)
93 def __set__(self, repo, value):
93 def __set__(self, repo, value):
94 return super(_basefilecache, self).__set__(repo.unfiltered(), value)
94 return super(_basefilecache, self).__set__(repo.unfiltered(), value)
95 def __delete__(self, repo):
95 def __delete__(self, repo):
96 return super(_basefilecache, self).__delete__(repo.unfiltered())
96 return super(_basefilecache, self).__delete__(repo.unfiltered())
97
97
98 class repofilecache(_basefilecache):
98 class repofilecache(_basefilecache):
99 """filecache for files in .hg but outside of .hg/store"""
99 """filecache for files in .hg but outside of .hg/store"""
100 def __init__(self, *paths):
100 def __init__(self, *paths):
101 super(repofilecache, self).__init__(*paths)
101 super(repofilecache, self).__init__(*paths)
102 for path in paths:
102 for path in paths:
103 _cachedfiles.add((path, 'plain'))
103 _cachedfiles.add((path, 'plain'))
104
104
105 def join(self, obj, fname):
105 def join(self, obj, fname):
106 return obj.vfs.join(fname)
106 return obj.vfs.join(fname)
107
107
108 class storecache(_basefilecache):
108 class storecache(_basefilecache):
109 """filecache for files in the store"""
109 """filecache for files in the store"""
110 def __init__(self, *paths):
110 def __init__(self, *paths):
111 super(storecache, self).__init__(*paths)
111 super(storecache, self).__init__(*paths)
112 for path in paths:
112 for path in paths:
113 _cachedfiles.add((path, ''))
113 _cachedfiles.add((path, ''))
114
114
115 def join(self, obj, fname):
115 def join(self, obj, fname):
116 return obj.sjoin(fname)
116 return obj.sjoin(fname)
117
117
118 def isfilecached(repo, name):
118 def isfilecached(repo, name):
119 """check if a repo has already cached "name" filecache-ed property
119 """check if a repo has already cached "name" filecache-ed property
120
120
121 This returns (cachedobj-or-None, iscached) tuple.
121 This returns (cachedobj-or-None, iscached) tuple.
122 """
122 """
123 cacheentry = repo.unfiltered()._filecache.get(name, None)
123 cacheentry = repo.unfiltered()._filecache.get(name, None)
124 if not cacheentry:
124 if not cacheentry:
125 return None, False
125 return None, False
126 return cacheentry.obj, True
126 return cacheentry.obj, True
127
127
128 class unfilteredpropertycache(util.propertycache):
128 class unfilteredpropertycache(util.propertycache):
129 """propertycache that apply to unfiltered repo only"""
129 """propertycache that apply to unfiltered repo only"""
130
130
131 def __get__(self, repo, type=None):
131 def __get__(self, repo, type=None):
132 unfi = repo.unfiltered()
132 unfi = repo.unfiltered()
133 if unfi is repo:
133 if unfi is repo:
134 return super(unfilteredpropertycache, self).__get__(unfi)
134 return super(unfilteredpropertycache, self).__get__(unfi)
135 return getattr(unfi, self.name)
135 return getattr(unfi, self.name)
136
136
137 class filteredpropertycache(util.propertycache):
137 class filteredpropertycache(util.propertycache):
138 """propertycache that must take filtering in account"""
138 """propertycache that must take filtering in account"""
139
139
140 def cachevalue(self, obj, value):
140 def cachevalue(self, obj, value):
141 object.__setattr__(obj, self.name, value)
141 object.__setattr__(obj, self.name, value)
142
142
143
143
144 def hasunfilteredcache(repo, name):
144 def hasunfilteredcache(repo, name):
145 """check if a repo has an unfilteredpropertycache value for <name>"""
145 """check if a repo has an unfilteredpropertycache value for <name>"""
146 return name in vars(repo.unfiltered())
146 return name in vars(repo.unfiltered())
147
147
148 def unfilteredmethod(orig):
148 def unfilteredmethod(orig):
149 """decorate method that always need to be run on unfiltered version"""
149 """decorate method that always need to be run on unfiltered version"""
150 def wrapper(repo, *args, **kwargs):
150 def wrapper(repo, *args, **kwargs):
151 return orig(repo.unfiltered(), *args, **kwargs)
151 return orig(repo.unfiltered(), *args, **kwargs)
152 return wrapper
152 return wrapper
153
153
154 moderncaps = {'lookup', 'branchmap', 'pushkey', 'known', 'getbundle',
154 moderncaps = {'lookup', 'branchmap', 'pushkey', 'known', 'getbundle',
155 'unbundle'}
155 'unbundle'}
156 legacycaps = moderncaps.union({'changegroupsubset'})
156 legacycaps = moderncaps.union({'changegroupsubset'})
157
157
158 @interfaceutil.implementer(repository.ipeercommandexecutor)
158 @interfaceutil.implementer(repository.ipeercommandexecutor)
159 class localcommandexecutor(object):
159 class localcommandexecutor(object):
160 def __init__(self, peer):
160 def __init__(self, peer):
161 self._peer = peer
161 self._peer = peer
162 self._sent = False
162 self._sent = False
163 self._closed = False
163 self._closed = False
164
164
165 def __enter__(self):
165 def __enter__(self):
166 return self
166 return self
167
167
168 def __exit__(self, exctype, excvalue, exctb):
168 def __exit__(self, exctype, excvalue, exctb):
169 self.close()
169 self.close()
170
170
171 def callcommand(self, command, args):
171 def callcommand(self, command, args):
172 if self._sent:
172 if self._sent:
173 raise error.ProgrammingError('callcommand() cannot be used after '
173 raise error.ProgrammingError('callcommand() cannot be used after '
174 'sendcommands()')
174 'sendcommands()')
175
175
176 if self._closed:
176 if self._closed:
177 raise error.ProgrammingError('callcommand() cannot be used after '
177 raise error.ProgrammingError('callcommand() cannot be used after '
178 'close()')
178 'close()')
179
179
180 # We don't need to support anything fancy. Just call the named
180 # We don't need to support anything fancy. Just call the named
181 # method on the peer and return a resolved future.
181 # method on the peer and return a resolved future.
182 fn = getattr(self._peer, pycompat.sysstr(command))
182 fn = getattr(self._peer, pycompat.sysstr(command))
183
183
184 f = pycompat.futures.Future()
184 f = pycompat.futures.Future()
185
185
186 try:
186 try:
187 result = fn(**pycompat.strkwargs(args))
187 result = fn(**pycompat.strkwargs(args))
188 except Exception:
188 except Exception:
189 pycompat.future_set_exception_info(f, sys.exc_info()[1:])
189 pycompat.future_set_exception_info(f, sys.exc_info()[1:])
190 else:
190 else:
191 f.set_result(result)
191 f.set_result(result)
192
192
193 return f
193 return f
194
194
195 def sendcommands(self):
195 def sendcommands(self):
196 self._sent = True
196 self._sent = True
197
197
198 def close(self):
198 def close(self):
199 self._closed = True
199 self._closed = True
200
200
201 @interfaceutil.implementer(repository.ipeercommands)
201 @interfaceutil.implementer(repository.ipeercommands)
202 class localpeer(repository.peer):
202 class localpeer(repository.peer):
203 '''peer for a local repo; reflects only the most recent API'''
203 '''peer for a local repo; reflects only the most recent API'''
204
204
205 def __init__(self, repo, caps=None):
205 def __init__(self, repo, caps=None):
206 super(localpeer, self).__init__()
206 super(localpeer, self).__init__()
207
207
208 if caps is None:
208 if caps is None:
209 caps = moderncaps.copy()
209 caps = moderncaps.copy()
210 self._repo = repo.filtered('served')
210 self._repo = repo.filtered('served')
211 self.ui = repo.ui
211 self.ui = repo.ui
212 self._caps = repo._restrictcapabilities(caps)
212 self._caps = repo._restrictcapabilities(caps)
213
213
214 # Begin of _basepeer interface.
214 # Begin of _basepeer interface.
215
215
216 def url(self):
216 def url(self):
217 return self._repo.url()
217 return self._repo.url()
218
218
219 def local(self):
219 def local(self):
220 return self._repo
220 return self._repo
221
221
222 def peer(self):
222 def peer(self):
223 return self
223 return self
224
224
225 def canpush(self):
225 def canpush(self):
226 return True
226 return True
227
227
228 def close(self):
228 def close(self):
229 self._repo.close()
229 self._repo.close()
230
230
231 # End of _basepeer interface.
231 # End of _basepeer interface.
232
232
233 # Begin of _basewirecommands interface.
233 # Begin of _basewirecommands interface.
234
234
235 def branchmap(self):
235 def branchmap(self):
236 return self._repo.branchmap()
236 return self._repo.branchmap()
237
237
238 def capabilities(self):
238 def capabilities(self):
239 return self._caps
239 return self._caps
240
240
241 def clonebundles(self):
241 def clonebundles(self):
242 return self._repo.tryread('clonebundles.manifest')
242 return self._repo.tryread('clonebundles.manifest')
243
243
244 def debugwireargs(self, one, two, three=None, four=None, five=None):
244 def debugwireargs(self, one, two, three=None, four=None, five=None):
245 """Used to test argument passing over the wire"""
245 """Used to test argument passing over the wire"""
246 return "%s %s %s %s %s" % (one, two, pycompat.bytestr(three),
246 return "%s %s %s %s %s" % (one, two, pycompat.bytestr(three),
247 pycompat.bytestr(four),
247 pycompat.bytestr(four),
248 pycompat.bytestr(five))
248 pycompat.bytestr(five))
249
249
250 def getbundle(self, source, heads=None, common=None, bundlecaps=None,
250 def getbundle(self, source, heads=None, common=None, bundlecaps=None,
251 **kwargs):
251 **kwargs):
252 chunks = exchange.getbundlechunks(self._repo, source, heads=heads,
252 chunks = exchange.getbundlechunks(self._repo, source, heads=heads,
253 common=common, bundlecaps=bundlecaps,
253 common=common, bundlecaps=bundlecaps,
254 **kwargs)[1]
254 **kwargs)[1]
255 cb = util.chunkbuffer(chunks)
255 cb = util.chunkbuffer(chunks)
256
256
257 if exchange.bundle2requested(bundlecaps):
257 if exchange.bundle2requested(bundlecaps):
258 # When requesting a bundle2, getbundle returns a stream to make the
258 # When requesting a bundle2, getbundle returns a stream to make the
259 # wire level function happier. We need to build a proper object
259 # wire level function happier. We need to build a proper object
260 # from it in local peer.
260 # from it in local peer.
261 return bundle2.getunbundler(self.ui, cb)
261 return bundle2.getunbundler(self.ui, cb)
262 else:
262 else:
263 return changegroup.getunbundler('01', cb, None)
263 return changegroup.getunbundler('01', cb, None)
264
264
265 def heads(self):
265 def heads(self):
266 return self._repo.heads()
266 return self._repo.heads()
267
267
268 def known(self, nodes):
268 def known(self, nodes):
269 return self._repo.known(nodes)
269 return self._repo.known(nodes)
270
270
271 def listkeys(self, namespace):
271 def listkeys(self, namespace):
272 return self._repo.listkeys(namespace)
272 return self._repo.listkeys(namespace)
273
273
274 def lookup(self, key):
274 def lookup(self, key):
275 return self._repo.lookup(key)
275 return self._repo.lookup(key)
276
276
277 def pushkey(self, namespace, key, old, new):
277 def pushkey(self, namespace, key, old, new):
278 return self._repo.pushkey(namespace, key, old, new)
278 return self._repo.pushkey(namespace, key, old, new)
279
279
280 def stream_out(self):
280 def stream_out(self):
281 raise error.Abort(_('cannot perform stream clone against local '
281 raise error.Abort(_('cannot perform stream clone against local '
282 'peer'))
282 'peer'))
283
283
284 def unbundle(self, bundle, heads, url):
284 def unbundle(self, bundle, heads, url):
285 """apply a bundle on a repo
285 """apply a bundle on a repo
286
286
287 This function handles the repo locking itself."""
287 This function handles the repo locking itself."""
288 try:
288 try:
289 try:
289 try:
290 bundle = exchange.readbundle(self.ui, bundle, None)
290 bundle = exchange.readbundle(self.ui, bundle, None)
291 ret = exchange.unbundle(self._repo, bundle, heads, 'push', url)
291 ret = exchange.unbundle(self._repo, bundle, heads, 'push', url)
292 if util.safehasattr(ret, 'getchunks'):
292 if util.safehasattr(ret, 'getchunks'):
293 # This is a bundle20 object, turn it into an unbundler.
293 # This is a bundle20 object, turn it into an unbundler.
294 # This little dance should be dropped eventually when the
294 # This little dance should be dropped eventually when the
295 # API is finally improved.
295 # API is finally improved.
296 stream = util.chunkbuffer(ret.getchunks())
296 stream = util.chunkbuffer(ret.getchunks())
297 ret = bundle2.getunbundler(self.ui, stream)
297 ret = bundle2.getunbundler(self.ui, stream)
298 return ret
298 return ret
299 except Exception as exc:
299 except Exception as exc:
300 # If the exception contains output salvaged from a bundle2
300 # If the exception contains output salvaged from a bundle2
301 # reply, we need to make sure it is printed before continuing
301 # reply, we need to make sure it is printed before continuing
302 # to fail. So we build a bundle2 with such output and consume
302 # to fail. So we build a bundle2 with such output and consume
303 # it directly.
303 # it directly.
304 #
304 #
305 # This is not very elegant but allows a "simple" solution for
305 # This is not very elegant but allows a "simple" solution for
306 # issue4594
306 # issue4594
307 output = getattr(exc, '_bundle2salvagedoutput', ())
307 output = getattr(exc, '_bundle2salvagedoutput', ())
308 if output:
308 if output:
309 bundler = bundle2.bundle20(self._repo.ui)
309 bundler = bundle2.bundle20(self._repo.ui)
310 for out in output:
310 for out in output:
311 bundler.addpart(out)
311 bundler.addpart(out)
312 stream = util.chunkbuffer(bundler.getchunks())
312 stream = util.chunkbuffer(bundler.getchunks())
313 b = bundle2.getunbundler(self.ui, stream)
313 b = bundle2.getunbundler(self.ui, stream)
314 bundle2.processbundle(self._repo, b)
314 bundle2.processbundle(self._repo, b)
315 raise
315 raise
316 except error.PushRaced as exc:
316 except error.PushRaced as exc:
317 raise error.ResponseError(_('push failed:'),
317 raise error.ResponseError(_('push failed:'),
318 stringutil.forcebytestr(exc))
318 stringutil.forcebytestr(exc))
319
319
320 # End of _basewirecommands interface.
320 # End of _basewirecommands interface.
321
321
322 # Begin of peer interface.
322 # Begin of peer interface.
323
323
324 def commandexecutor(self):
324 def commandexecutor(self):
325 return localcommandexecutor(self)
325 return localcommandexecutor(self)
326
326
327 # End of peer interface.
327 # End of peer interface.
328
328
329 @interfaceutil.implementer(repository.ipeerlegacycommands)
329 @interfaceutil.implementer(repository.ipeerlegacycommands)
330 class locallegacypeer(localpeer):
330 class locallegacypeer(localpeer):
331 '''peer extension which implements legacy methods too; used for tests with
331 '''peer extension which implements legacy methods too; used for tests with
332 restricted capabilities'''
332 restricted capabilities'''
333
333
334 def __init__(self, repo):
334 def __init__(self, repo):
335 super(locallegacypeer, self).__init__(repo, caps=legacycaps)
335 super(locallegacypeer, self).__init__(repo, caps=legacycaps)
336
336
337 # Begin of baselegacywirecommands interface.
337 # Begin of baselegacywirecommands interface.
338
338
339 def between(self, pairs):
339 def between(self, pairs):
340 return self._repo.between(pairs)
340 return self._repo.between(pairs)
341
341
342 def branches(self, nodes):
342 def branches(self, nodes):
343 return self._repo.branches(nodes)
343 return self._repo.branches(nodes)
344
344
345 def changegroup(self, nodes, source):
345 def changegroup(self, nodes, source):
346 outgoing = discovery.outgoing(self._repo, missingroots=nodes,
346 outgoing = discovery.outgoing(self._repo, missingroots=nodes,
347 missingheads=self._repo.heads())
347 missingheads=self._repo.heads())
348 return changegroup.makechangegroup(self._repo, outgoing, '01', source)
348 return changegroup.makechangegroup(self._repo, outgoing, '01', source)
349
349
350 def changegroupsubset(self, bases, heads, source):
350 def changegroupsubset(self, bases, heads, source):
351 outgoing = discovery.outgoing(self._repo, missingroots=bases,
351 outgoing = discovery.outgoing(self._repo, missingroots=bases,
352 missingheads=heads)
352 missingheads=heads)
353 return changegroup.makechangegroup(self._repo, outgoing, '01', source)
353 return changegroup.makechangegroup(self._repo, outgoing, '01', source)
354
354
355 # End of baselegacywirecommands interface.
355 # End of baselegacywirecommands interface.
356
356
357 # Increment the sub-version when the revlog v2 format changes to lock out old
357 # Increment the sub-version when the revlog v2 format changes to lock out old
358 # clients.
358 # clients.
359 REVLOGV2_REQUIREMENT = 'exp-revlogv2.0'
359 REVLOGV2_REQUIREMENT = 'exp-revlogv2.0'
360
360
361 # A repository with the sparserevlog feature will have delta chains that
361 # A repository with the sparserevlog feature will have delta chains that
362 # can spread over a larger span. Sparse reading cuts these large spans into
362 # can spread over a larger span. Sparse reading cuts these large spans into
363 # pieces, so that each piece isn't too big.
363 # pieces, so that each piece isn't too big.
364 # Without the sparserevlog capability, reading from the repository could use
364 # Without the sparserevlog capability, reading from the repository could use
365 # huge amounts of memory, because the whole span would be read at once,
365 # huge amounts of memory, because the whole span would be read at once,
366 # including all the intermediate revisions that aren't pertinent for the chain.
366 # including all the intermediate revisions that aren't pertinent for the chain.
367 # This is why once a repository has enabled sparse-read, it becomes required.
367 # This is why once a repository has enabled sparse-read, it becomes required.
368 SPARSEREVLOG_REQUIREMENT = 'sparserevlog'
368 SPARSEREVLOG_REQUIREMENT = 'sparserevlog'
369
369
370 # Functions receiving (ui, features) that extensions can register to impact
370 # Functions receiving (ui, features) that extensions can register to impact
371 # the ability to load repositories with custom requirements. Only
371 # the ability to load repositories with custom requirements. Only
372 # functions defined in loaded extensions are called.
372 # functions defined in loaded extensions are called.
373 #
373 #
374 # The function receives a set of requirement strings that the repository
374 # The function receives a set of requirement strings that the repository
375 # is capable of opening. Functions will typically add elements to the
375 # is capable of opening. Functions will typically add elements to the
376 # set to reflect that the extension knows how to handle that requirements.
376 # set to reflect that the extension knows how to handle that requirements.
377 featuresetupfuncs = set()
377 featuresetupfuncs = set()
378
378
379 @interfaceutil.implementer(repository.completelocalrepository)
379 @interfaceutil.implementer(repository.completelocalrepository)
380 class localrepository(object):
380 class localrepository(object):
381
381
382 # obsolete experimental requirements:
382 # obsolete experimental requirements:
383 # - manifestv2: An experimental new manifest format that allowed
383 # - manifestv2: An experimental new manifest format that allowed
384 # for stem compression of long paths. Experiment ended up not
384 # for stem compression of long paths. Experiment ended up not
385 # being successful (repository sizes went up due to worse delta
385 # being successful (repository sizes went up due to worse delta
386 # chains), and the code was deleted in 4.6.
386 # chains), and the code was deleted in 4.6.
387 supportedformats = {
387 supportedformats = {
388 'revlogv1',
388 'revlogv1',
389 'generaldelta',
389 'generaldelta',
390 'treemanifest',
390 'treemanifest',
391 REVLOGV2_REQUIREMENT,
391 REVLOGV2_REQUIREMENT,
392 SPARSEREVLOG_REQUIREMENT,
392 SPARSEREVLOG_REQUIREMENT,
393 }
393 }
394 _basesupported = supportedformats | {
394 _basesupported = supportedformats | {
395 'store',
395 'store',
396 'fncache',
396 'fncache',
397 'shared',
397 'shared',
398 'relshared',
398 'relshared',
399 'dotencode',
399 'dotencode',
400 'exp-sparse',
400 'exp-sparse',
401 'internal-phase'
401 'internal-phase'
402 }
402 }
403 openerreqs = {
403 openerreqs = {
404 'revlogv1',
404 'revlogv1',
405 'generaldelta',
405 'generaldelta',
406 'treemanifest',
406 'treemanifest',
407 }
407 }
408
408
409 # list of prefix for file which can be written without 'wlock'
409 # list of prefix for file which can be written without 'wlock'
410 # Extensions should extend this list when needed
410 # Extensions should extend this list when needed
411 _wlockfreeprefix = {
411 _wlockfreeprefix = {
412 # We migh consider requiring 'wlock' for the next
412 # We migh consider requiring 'wlock' for the next
413 # two, but pretty much all the existing code assume
413 # two, but pretty much all the existing code assume
414 # wlock is not needed so we keep them excluded for
414 # wlock is not needed so we keep them excluded for
415 # now.
415 # now.
416 'hgrc',
416 'hgrc',
417 'requires',
417 'requires',
418 # XXX cache is a complicatged business someone
418 # XXX cache is a complicatged business someone
419 # should investigate this in depth at some point
419 # should investigate this in depth at some point
420 'cache/',
420 'cache/',
421 # XXX shouldn't be dirstate covered by the wlock?
421 # XXX shouldn't be dirstate covered by the wlock?
422 'dirstate',
422 'dirstate',
423 # XXX bisect was still a bit too messy at the time
423 # XXX bisect was still a bit too messy at the time
424 # this changeset was introduced. Someone should fix
424 # this changeset was introduced. Someone should fix
425 # the remainig bit and drop this line
425 # the remainig bit and drop this line
426 'bisect.state',
426 'bisect.state',
427 }
427 }
428
428
429 def __init__(self, baseui, path, intents=None):
429 def __init__(self, baseui, path, intents=None):
430 """Create a new local repository instance.
430 """Create a new local repository instance.
431
431
432 Most callers should use ``hg.repository()`` or ``localrepo.instance()``
432 Most callers should use ``hg.repository()`` or ``localrepo.instance()``
433 for obtaining a new repository object.
433 for obtaining a new repository object.
434 """
434 """
435
435
436 self.requirements = set()
436 self.requirements = set()
437 self.filtername = None
437 self.filtername = None
438 # wvfs: rooted at the repository root, used to access the working copy
438 # wvfs: rooted at the repository root, used to access the working copy
439 self.wvfs = vfsmod.vfs(path, expandpath=True, realpath=True)
439 self.wvfs = vfsmod.vfs(path, expandpath=True, realpath=True)
440 # vfs: rooted at .hg, used to access repo files outside of .hg/store
440 # vfs: rooted at .hg, used to access repo files outside of .hg/store
441 self.vfs = None
441 self.vfs = None
442 # svfs: usually rooted at .hg/store, used to access repository history
442 # svfs: usually rooted at .hg/store, used to access repository history
443 # If this is a shared repository, this vfs may point to another
443 # If this is a shared repository, this vfs may point to another
444 # repository's .hg/store directory.
444 # repository's .hg/store directory.
445 self.svfs = None
445 self.svfs = None
446 self.root = self.wvfs.base
446 self.root = self.wvfs.base
447 self.path = self.wvfs.join(".hg")
447 self.path = self.wvfs.join(".hg")
448 self.origroot = path
448 self.origroot = path
449 self.baseui = baseui
449 self.baseui = baseui
450 self.ui = baseui.copy()
450 self.ui = baseui.copy()
451 self.ui.copy = baseui.copy # prevent copying repo configuration
451 self.ui.copy = baseui.copy # prevent copying repo configuration
452 self.vfs = vfsmod.vfs(self.path, cacheaudited=True)
452 self.vfs = vfsmod.vfs(self.path, cacheaudited=True)
453 if (self.ui.configbool('devel', 'all-warnings') or
453 if (self.ui.configbool('devel', 'all-warnings') or
454 self.ui.configbool('devel', 'check-locks')):
454 self.ui.configbool('devel', 'check-locks')):
455 self.vfs.audit = self._getvfsward(self.vfs.audit)
455 self.vfs.audit = self._getvfsward(self.vfs.audit)
456 # A list of callback to shape the phase if no data were found.
456 # A list of callback to shape the phase if no data were found.
457 # Callback are in the form: func(repo, roots) --> processed root.
457 # Callback are in the form: func(repo, roots) --> processed root.
458 # This list it to be filled by extension during repo setup
458 # This list it to be filled by extension during repo setup
459 self._phasedefaults = []
459 self._phasedefaults = []
460 try:
460 try:
461 self.ui.readconfig(self.vfs.join("hgrc"), self.root)
461 self.ui.readconfig(self.vfs.join("hgrc"), self.root)
462 self._loadextensions()
462 self._loadextensions()
463 except IOError:
463 except IOError:
464 pass
464 pass
465
465
466 if featuresetupfuncs:
466 if featuresetupfuncs:
467 self.supported = set(self._basesupported) # use private copy
467 self.supported = set(self._basesupported) # use private copy
468 extmods = set(m.__name__ for n, m
468 extmods = set(m.__name__ for n, m
469 in extensions.extensions(self.ui))
469 in extensions.extensions(self.ui))
470 for setupfunc in featuresetupfuncs:
470 for setupfunc in featuresetupfuncs:
471 if setupfunc.__module__ in extmods:
471 if setupfunc.__module__ in extmods:
472 setupfunc(self.ui, self.supported)
472 setupfunc(self.ui, self.supported)
473 else:
473 else:
474 self.supported = self._basesupported
474 self.supported = self._basesupported
475 color.setup(self.ui)
475 color.setup(self.ui)
476
476
477 # Add compression engines.
477 # Add compression engines.
478 for name in util.compengines:
478 for name in util.compengines:
479 engine = util.compengines[name]
479 engine = util.compengines[name]
480 if engine.revlogheader():
480 if engine.revlogheader():
481 self.supported.add('exp-compression-%s' % name)
481 self.supported.add('exp-compression-%s' % name)
482
482
483 if not self.vfs.isdir():
483 if not self.vfs.isdir():
484 try:
484 try:
485 self.vfs.stat()
485 self.vfs.stat()
486 except OSError as inst:
486 except OSError as inst:
487 if inst.errno != errno.ENOENT:
487 if inst.errno != errno.ENOENT:
488 raise
488 raise
489 raise error.RepoError(_("repository %s not found") % path)
489 raise error.RepoError(_("repository %s not found") % path)
490 else:
490 else:
491 try:
491 try:
492 self.requirements = scmutil.readrequires(
492 self.requirements = scmutil.readrequires(
493 self.vfs, self.supported)
493 self.vfs, self.supported)
494 except IOError as inst:
494 except IOError as inst:
495 if inst.errno != errno.ENOENT:
495 if inst.errno != errno.ENOENT:
496 raise
496 raise
497
497
498 cachepath = self.vfs.join('cache')
498 cachepath = self.vfs.join('cache')
499 self.sharedpath = self.path
499 self.sharedpath = self.path
500 try:
500 try:
501 sharedpath = self.vfs.read("sharedpath").rstrip('\n')
501 sharedpath = self.vfs.read("sharedpath").rstrip('\n')
502 if 'relshared' in self.requirements:
502 if 'relshared' in self.requirements:
503 sharedpath = self.vfs.join(sharedpath)
503 sharedpath = self.vfs.join(sharedpath)
504 vfs = vfsmod.vfs(sharedpath, realpath=True)
504 vfs = vfsmod.vfs(sharedpath, realpath=True)
505 cachepath = vfs.join('cache')
505 cachepath = vfs.join('cache')
506 s = vfs.base
506 s = vfs.base
507 if not vfs.exists():
507 if not vfs.exists():
508 raise error.RepoError(
508 raise error.RepoError(
509 _('.hg/sharedpath points to nonexistent directory %s') % s)
509 _('.hg/sharedpath points to nonexistent directory %s') % s)
510 self.sharedpath = s
510 self.sharedpath = s
511 except IOError as inst:
511 except IOError as inst:
512 if inst.errno != errno.ENOENT:
512 if inst.errno != errno.ENOENT:
513 raise
513 raise
514
514
515 if 'exp-sparse' in self.requirements and not sparse.enabled:
515 if 'exp-sparse' in self.requirements and not sparse.enabled:
516 raise error.RepoError(_('repository is using sparse feature but '
516 raise error.RepoError(_('repository is using sparse feature but '
517 'sparse is not enabled; enable the '
517 'sparse is not enabled; enable the '
518 '"sparse" extensions to access'))
518 '"sparse" extensions to access'))
519
519
520 self.store = store.store(
520 self.store = store.store(
521 self.requirements, self.sharedpath,
521 self.requirements, self.sharedpath,
522 lambda base: vfsmod.vfs(base, cacheaudited=True))
522 lambda base: vfsmod.vfs(base, cacheaudited=True))
523 self.spath = self.store.path
523 self.spath = self.store.path
524 self.svfs = self.store.vfs
524 self.svfs = self.store.vfs
525 self.sjoin = self.store.join
525 self.sjoin = self.store.join
526 self.vfs.createmode = self.store.createmode
526 self.vfs.createmode = self.store.createmode
527 self.cachevfs = vfsmod.vfs(cachepath, cacheaudited=True)
527 self.cachevfs = vfsmod.vfs(cachepath, cacheaudited=True)
528 self.cachevfs.createmode = self.store.createmode
528 self.cachevfs.createmode = self.store.createmode
529 if (self.ui.configbool('devel', 'all-warnings') or
529 if (self.ui.configbool('devel', 'all-warnings') or
530 self.ui.configbool('devel', 'check-locks')):
530 self.ui.configbool('devel', 'check-locks')):
531 if util.safehasattr(self.svfs, 'vfs'): # this is filtervfs
531 if util.safehasattr(self.svfs, 'vfs'): # this is filtervfs
532 self.svfs.vfs.audit = self._getsvfsward(self.svfs.vfs.audit)
532 self.svfs.vfs.audit = self._getsvfsward(self.svfs.vfs.audit)
533 else: # standard vfs
533 else: # standard vfs
534 self.svfs.audit = self._getsvfsward(self.svfs.audit)
534 self.svfs.audit = self._getsvfsward(self.svfs.audit)
535 self._applyopenerreqs()
535 self._applyopenerreqs()
536
536
537 self._dirstatevalidatewarned = False
537 self._dirstatevalidatewarned = False
538
538
539 self._branchcaches = {}
539 self._branchcaches = {}
540 self._revbranchcache = None
540 self._revbranchcache = None
541 self._filterpats = {}
541 self._filterpats = {}
542 self._datafilters = {}
542 self._datafilters = {}
543 self._transref = self._lockref = self._wlockref = None
543 self._transref = self._lockref = self._wlockref = None
544
544
545 # A cache for various files under .hg/ that tracks file changes,
545 # A cache for various files under .hg/ that tracks file changes,
546 # (used by the filecache decorator)
546 # (used by the filecache decorator)
547 #
547 #
548 # Maps a property name to its util.filecacheentry
548 # Maps a property name to its util.filecacheentry
549 self._filecache = {}
549 self._filecache = {}
550
550
551 # hold sets of revision to be filtered
551 # hold sets of revision to be filtered
552 # should be cleared when something might have changed the filter value:
552 # should be cleared when something might have changed the filter value:
553 # - new changesets,
553 # - new changesets,
554 # - phase change,
554 # - phase change,
555 # - new obsolescence marker,
555 # - new obsolescence marker,
556 # - working directory parent change,
556 # - working directory parent change,
557 # - bookmark changes
557 # - bookmark changes
558 self.filteredrevcache = {}
558 self.filteredrevcache = {}
559
559
560 # post-dirstate-status hooks
560 # post-dirstate-status hooks
561 self._postdsstatus = []
561 self._postdsstatus = []
562
562
563 # generic mapping between names and nodes
563 # generic mapping between names and nodes
564 self.names = namespaces.namespaces()
564 self.names = namespaces.namespaces()
565
565
566 # Key to signature value.
566 # Key to signature value.
567 self._sparsesignaturecache = {}
567 self._sparsesignaturecache = {}
568 # Signature to cached matcher instance.
568 # Signature to cached matcher instance.
569 self._sparsematchercache = {}
569 self._sparsematchercache = {}
570
570
571 def _getvfsward(self, origfunc):
571 def _getvfsward(self, origfunc):
572 """build a ward for self.vfs"""
572 """build a ward for self.vfs"""
573 rref = weakref.ref(self)
573 rref = weakref.ref(self)
574 def checkvfs(path, mode=None):
574 def checkvfs(path, mode=None):
575 ret = origfunc(path, mode=mode)
575 ret = origfunc(path, mode=mode)
576 repo = rref()
576 repo = rref()
577 if (repo is None
577 if (repo is None
578 or not util.safehasattr(repo, '_wlockref')
578 or not util.safehasattr(repo, '_wlockref')
579 or not util.safehasattr(repo, '_lockref')):
579 or not util.safehasattr(repo, '_lockref')):
580 return
580 return
581 if mode in (None, 'r', 'rb'):
581 if mode in (None, 'r', 'rb'):
582 return
582 return
583 if path.startswith(repo.path):
583 if path.startswith(repo.path):
584 # truncate name relative to the repository (.hg)
584 # truncate name relative to the repository (.hg)
585 path = path[len(repo.path) + 1:]
585 path = path[len(repo.path) + 1:]
586 if path.startswith('cache/'):
586 if path.startswith('cache/'):
587 msg = 'accessing cache with vfs instead of cachevfs: "%s"'
587 msg = 'accessing cache with vfs instead of cachevfs: "%s"'
588 repo.ui.develwarn(msg % path, stacklevel=2, config="cache-vfs")
588 repo.ui.develwarn(msg % path, stacklevel=2, config="cache-vfs")
589 if path.startswith('journal.'):
589 if path.startswith('journal.'):
590 # journal is covered by 'lock'
590 # journal is covered by 'lock'
591 if repo._currentlock(repo._lockref) is None:
591 if repo._currentlock(repo._lockref) is None:
592 repo.ui.develwarn('write with no lock: "%s"' % path,
592 repo.ui.develwarn('write with no lock: "%s"' % path,
593 stacklevel=2, config='check-locks')
593 stacklevel=2, config='check-locks')
594 elif repo._currentlock(repo._wlockref) is None:
594 elif repo._currentlock(repo._wlockref) is None:
595 # rest of vfs files are covered by 'wlock'
595 # rest of vfs files are covered by 'wlock'
596 #
596 #
597 # exclude special files
597 # exclude special files
598 for prefix in self._wlockfreeprefix:
598 for prefix in self._wlockfreeprefix:
599 if path.startswith(prefix):
599 if path.startswith(prefix):
600 return
600 return
601 repo.ui.develwarn('write with no wlock: "%s"' % path,
601 repo.ui.develwarn('write with no wlock: "%s"' % path,
602 stacklevel=2, config='check-locks')
602 stacklevel=2, config='check-locks')
603 return ret
603 return ret
604 return checkvfs
604 return checkvfs
605
605
606 def _getsvfsward(self, origfunc):
606 def _getsvfsward(self, origfunc):
607 """build a ward for self.svfs"""
607 """build a ward for self.svfs"""
608 rref = weakref.ref(self)
608 rref = weakref.ref(self)
609 def checksvfs(path, mode=None):
609 def checksvfs(path, mode=None):
610 ret = origfunc(path, mode=mode)
610 ret = origfunc(path, mode=mode)
611 repo = rref()
611 repo = rref()
612 if repo is None or not util.safehasattr(repo, '_lockref'):
612 if repo is None or not util.safehasattr(repo, '_lockref'):
613 return
613 return
614 if mode in (None, 'r', 'rb'):
614 if mode in (None, 'r', 'rb'):
615 return
615 return
616 if path.startswith(repo.sharedpath):
616 if path.startswith(repo.sharedpath):
617 # truncate name relative to the repository (.hg)
617 # truncate name relative to the repository (.hg)
618 path = path[len(repo.sharedpath) + 1:]
618 path = path[len(repo.sharedpath) + 1:]
619 if repo._currentlock(repo._lockref) is None:
619 if repo._currentlock(repo._lockref) is None:
620 repo.ui.develwarn('write with no lock: "%s"' % path,
620 repo.ui.develwarn('write with no lock: "%s"' % path,
621 stacklevel=3)
621 stacklevel=3)
622 return ret
622 return ret
623 return checksvfs
623 return checksvfs
624
624
625 def close(self):
625 def close(self):
626 self._writecaches()
626 self._writecaches()
627
627
628 def _loadextensions(self):
628 def _loadextensions(self):
629 extensions.loadall(self.ui)
629 extensions.loadall(self.ui)
630
630
631 def _writecaches(self):
631 def _writecaches(self):
632 if self._revbranchcache:
632 if self._revbranchcache:
633 self._revbranchcache.write()
633 self._revbranchcache.write()
634
634
635 def _restrictcapabilities(self, caps):
635 def _restrictcapabilities(self, caps):
636 if self.ui.configbool('experimental', 'bundle2-advertise'):
636 if self.ui.configbool('experimental', 'bundle2-advertise'):
637 caps = set(caps)
637 caps = set(caps)
638 capsblob = bundle2.encodecaps(bundle2.getrepocaps(self,
638 capsblob = bundle2.encodecaps(bundle2.getrepocaps(self,
639 role='client'))
639 role='client'))
640 caps.add('bundle2=' + urlreq.quote(capsblob))
640 caps.add('bundle2=' + urlreq.quote(capsblob))
641 return caps
641 return caps
642
642
643 def _applyopenerreqs(self):
643 def _applyopenerreqs(self):
644 self.svfs.options = dict((r, 1) for r in self.requirements
644 self.svfs.options = dict((r, 1) for r in self.requirements
645 if r in self.openerreqs)
645 if r in self.openerreqs)
646 # experimental config: format.chunkcachesize
646 # experimental config: format.chunkcachesize
647 chunkcachesize = self.ui.configint('format', 'chunkcachesize')
647 chunkcachesize = self.ui.configint('format', 'chunkcachesize')
648 if chunkcachesize is not None:
648 if chunkcachesize is not None:
649 self.svfs.options['chunkcachesize'] = chunkcachesize
649 self.svfs.options['chunkcachesize'] = chunkcachesize
650 # experimental config: format.manifestcachesize
650 # experimental config: format.manifestcachesize
651 manifestcachesize = self.ui.configint('format', 'manifestcachesize')
651 manifestcachesize = self.ui.configint('format', 'manifestcachesize')
652 if manifestcachesize is not None:
652 if manifestcachesize is not None:
653 self.svfs.options['manifestcachesize'] = manifestcachesize
653 self.svfs.options['manifestcachesize'] = manifestcachesize
654 deltabothparents = self.ui.configbool('storage',
654 deltabothparents = self.ui.configbool('storage',
655 'revlog.optimize-delta-parent-choice')
655 'revlog.optimize-delta-parent-choice')
656 self.svfs.options['deltabothparents'] = deltabothparents
656 self.svfs.options['deltabothparents'] = deltabothparents
657 self.svfs.options['lazydeltabase'] = not scmutil.gddeltaconfig(self.ui)
657 self.svfs.options['lazydeltabase'] = not scmutil.gddeltaconfig(self.ui)
658 chainspan = self.ui.configbytes('experimental', 'maxdeltachainspan')
658 chainspan = self.ui.configbytes('experimental', 'maxdeltachainspan')
659 if 0 <= chainspan:
659 if 0 <= chainspan:
660 self.svfs.options['maxdeltachainspan'] = chainspan
660 self.svfs.options['maxdeltachainspan'] = chainspan
661 mmapindexthreshold = self.ui.configbytes('experimental',
661 mmapindexthreshold = self.ui.configbytes('experimental',
662 'mmapindexthreshold')
662 'mmapindexthreshold')
663 if mmapindexthreshold is not None:
663 if mmapindexthreshold is not None:
664 self.svfs.options['mmapindexthreshold'] = mmapindexthreshold
664 self.svfs.options['mmapindexthreshold'] = mmapindexthreshold
665 withsparseread = self.ui.configbool('experimental', 'sparse-read')
665 withsparseread = self.ui.configbool('experimental', 'sparse-read')
666 srdensitythres = float(self.ui.config('experimental',
666 srdensitythres = float(self.ui.config('experimental',
667 'sparse-read.density-threshold'))
667 'sparse-read.density-threshold'))
668 srmingapsize = self.ui.configbytes('experimental',
668 srmingapsize = self.ui.configbytes('experimental',
669 'sparse-read.min-gap-size')
669 'sparse-read.min-gap-size')
670 self.svfs.options['with-sparse-read'] = withsparseread
670 self.svfs.options['with-sparse-read'] = withsparseread
671 self.svfs.options['sparse-read-density-threshold'] = srdensitythres
671 self.svfs.options['sparse-read-density-threshold'] = srdensitythres
672 self.svfs.options['sparse-read-min-gap-size'] = srmingapsize
672 self.svfs.options['sparse-read-min-gap-size'] = srmingapsize
673 sparserevlog = SPARSEREVLOG_REQUIREMENT in self.requirements
673 sparserevlog = SPARSEREVLOG_REQUIREMENT in self.requirements
674 self.svfs.options['sparse-revlog'] = sparserevlog
674 self.svfs.options['sparse-revlog'] = sparserevlog
675 if sparserevlog:
675 if sparserevlog:
676 self.svfs.options['generaldelta'] = True
676 self.svfs.options['generaldelta'] = True
677 maxchainlen = None
677 maxchainlen = None
678 if sparserevlog:
678 if sparserevlog:
679 maxchainlen = revlogconst.SPARSE_REVLOG_MAX_CHAIN_LENGTH
679 maxchainlen = revlogconst.SPARSE_REVLOG_MAX_CHAIN_LENGTH
680 # experimental config: format.maxchainlen
680 # experimental config: format.maxchainlen
681 maxchainlen = self.ui.configint('format', 'maxchainlen', maxchainlen)
681 maxchainlen = self.ui.configint('format', 'maxchainlen', maxchainlen)
682 if maxchainlen is not None:
682 if maxchainlen is not None:
683 self.svfs.options['maxchainlen'] = maxchainlen
683 self.svfs.options['maxchainlen'] = maxchainlen
684
684
685 for r in self.requirements:
685 for r in self.requirements:
686 if r.startswith('exp-compression-'):
686 if r.startswith('exp-compression-'):
687 self.svfs.options['compengine'] = r[len('exp-compression-'):]
687 self.svfs.options['compengine'] = r[len('exp-compression-'):]
688
688
689 # TODO move "revlogv2" to openerreqs once finalized.
689 # TODO move "revlogv2" to openerreqs once finalized.
690 if REVLOGV2_REQUIREMENT in self.requirements:
690 if REVLOGV2_REQUIREMENT in self.requirements:
691 self.svfs.options['revlogv2'] = True
691 self.svfs.options['revlogv2'] = True
692
692
693 def _writerequirements(self):
693 def _writerequirements(self):
694 scmutil.writerequires(self.vfs, self.requirements)
694 scmutil.writerequires(self.vfs, self.requirements)
695
695
696 # Don't cache auditor/nofsauditor, or you'll end up with reference cycle:
696 # Don't cache auditor/nofsauditor, or you'll end up with reference cycle:
697 # self -> auditor -> self._checknested -> self
697 # self -> auditor -> self._checknested -> self
698
698
699 @property
699 @property
700 def auditor(self):
700 def auditor(self):
701 # This is only used by context.workingctx.match in order to
701 # This is only used by context.workingctx.match in order to
702 # detect files in subrepos.
702 # detect files in subrepos.
703 return pathutil.pathauditor(self.root, callback=self._checknested)
703 return pathutil.pathauditor(self.root, callback=self._checknested)
704
704
705 @property
705 @property
706 def nofsauditor(self):
706 def nofsauditor(self):
707 # This is only used by context.basectx.match in order to detect
707 # This is only used by context.basectx.match in order to detect
708 # files in subrepos.
708 # files in subrepos.
709 return pathutil.pathauditor(self.root, callback=self._checknested,
709 return pathutil.pathauditor(self.root, callback=self._checknested,
710 realfs=False, cached=True)
710 realfs=False, cached=True)
711
711
712 def _checknested(self, path):
712 def _checknested(self, path):
713 """Determine if path is a legal nested repository."""
713 """Determine if path is a legal nested repository."""
714 if not path.startswith(self.root):
714 if not path.startswith(self.root):
715 return False
715 return False
716 subpath = path[len(self.root) + 1:]
716 subpath = path[len(self.root) + 1:]
717 normsubpath = util.pconvert(subpath)
717 normsubpath = util.pconvert(subpath)
718
718
719 # XXX: Checking against the current working copy is wrong in
719 # XXX: Checking against the current working copy is wrong in
720 # the sense that it can reject things like
720 # the sense that it can reject things like
721 #
721 #
722 # $ hg cat -r 10 sub/x.txt
722 # $ hg cat -r 10 sub/x.txt
723 #
723 #
724 # if sub/ is no longer a subrepository in the working copy
724 # if sub/ is no longer a subrepository in the working copy
725 # parent revision.
725 # parent revision.
726 #
726 #
727 # However, it can of course also allow things that would have
727 # However, it can of course also allow things that would have
728 # been rejected before, such as the above cat command if sub/
728 # been rejected before, such as the above cat command if sub/
729 # is a subrepository now, but was a normal directory before.
729 # is a subrepository now, but was a normal directory before.
730 # The old path auditor would have rejected by mistake since it
730 # The old path auditor would have rejected by mistake since it
731 # panics when it sees sub/.hg/.
731 # panics when it sees sub/.hg/.
732 #
732 #
733 # All in all, checking against the working copy seems sensible
733 # All in all, checking against the working copy seems sensible
734 # since we want to prevent access to nested repositories on
734 # since we want to prevent access to nested repositories on
735 # the filesystem *now*.
735 # the filesystem *now*.
736 ctx = self[None]
736 ctx = self[None]
737 parts = util.splitpath(subpath)
737 parts = util.splitpath(subpath)
738 while parts:
738 while parts:
739 prefix = '/'.join(parts)
739 prefix = '/'.join(parts)
740 if prefix in ctx.substate:
740 if prefix in ctx.substate:
741 if prefix == normsubpath:
741 if prefix == normsubpath:
742 return True
742 return True
743 else:
743 else:
744 sub = ctx.sub(prefix)
744 sub = ctx.sub(prefix)
745 return sub.checknested(subpath[len(prefix) + 1:])
745 return sub.checknested(subpath[len(prefix) + 1:])
746 else:
746 else:
747 parts.pop()
747 parts.pop()
748 return False
748 return False
749
749
750 def peer(self):
750 def peer(self):
751 return localpeer(self) # not cached to avoid reference cycle
751 return localpeer(self) # not cached to avoid reference cycle
752
752
753 def unfiltered(self):
753 def unfiltered(self):
754 """Return unfiltered version of the repository
754 """Return unfiltered version of the repository
755
755
756 Intended to be overwritten by filtered repo."""
756 Intended to be overwritten by filtered repo."""
757 return self
757 return self
758
758
759 def filtered(self, name, visibilityexceptions=None):
759 def filtered(self, name, visibilityexceptions=None):
760 """Return a filtered version of a repository"""
760 """Return a filtered version of a repository"""
761 cls = repoview.newtype(self.unfiltered().__class__)
761 cls = repoview.newtype(self.unfiltered().__class__)
762 return cls(self, name, visibilityexceptions)
762 return cls(self, name, visibilityexceptions)
763
763
764 @repofilecache('bookmarks', 'bookmarks.current')
764 @repofilecache('bookmarks', 'bookmarks.current')
765 def _bookmarks(self):
765 def _bookmarks(self):
766 return bookmarks.bmstore(self)
766 return bookmarks.bmstore(self)
767
767
768 @property
768 @property
769 def _activebookmark(self):
769 def _activebookmark(self):
770 return self._bookmarks.active
770 return self._bookmarks.active
771
771
772 # _phasesets depend on changelog. what we need is to call
772 # _phasesets depend on changelog. what we need is to call
773 # _phasecache.invalidate() if '00changelog.i' was changed, but it
773 # _phasecache.invalidate() if '00changelog.i' was changed, but it
774 # can't be easily expressed in filecache mechanism.
774 # can't be easily expressed in filecache mechanism.
775 @storecache('phaseroots', '00changelog.i')
775 @storecache('phaseroots', '00changelog.i')
776 def _phasecache(self):
776 def _phasecache(self):
777 return phases.phasecache(self, self._phasedefaults)
777 return phases.phasecache(self, self._phasedefaults)
778
778
779 @storecache('obsstore')
779 @storecache('obsstore')
780 def obsstore(self):
780 def obsstore(self):
781 return obsolete.makestore(self.ui, self)
781 return obsolete.makestore(self.ui, self)
782
782
783 @storecache('00changelog.i')
783 @storecache('00changelog.i')
784 def changelog(self):
784 def changelog(self):
785 return changelog.changelog(self.svfs,
785 return changelog.changelog(self.svfs,
786 trypending=txnutil.mayhavepending(self.root))
786 trypending=txnutil.mayhavepending(self.root))
787
787
788 def _constructmanifest(self):
788 def _constructmanifest(self):
789 # This is a temporary function while we migrate from manifest to
789 # This is a temporary function while we migrate from manifest to
790 # manifestlog. It allows bundlerepo and unionrepo to intercept the
790 # manifestlog. It allows bundlerepo and unionrepo to intercept the
791 # manifest creation.
791 # manifest creation.
792 return manifest.manifestrevlog(self.svfs)
792 return manifest.manifestrevlog(self.svfs)
793
793
794 @storecache('00manifest.i')
794 @storecache('00manifest.i')
795 def manifestlog(self):
795 def manifestlog(self):
796 return manifest.manifestlog(self.svfs, self)
796 return manifest.manifestlog(self.svfs, self)
797
797
798 @repofilecache('dirstate')
798 @repofilecache('dirstate')
799 def dirstate(self):
799 def dirstate(self):
800 return self._makedirstate()
800 return self._makedirstate()
801
801
802 def _makedirstate(self):
802 def _makedirstate(self):
803 """Extension point for wrapping the dirstate per-repo."""
803 """Extension point for wrapping the dirstate per-repo."""
804 sparsematchfn = lambda: sparse.matcher(self)
804 sparsematchfn = lambda: sparse.matcher(self)
805
805
806 return dirstate.dirstate(self.vfs, self.ui, self.root,
806 return dirstate.dirstate(self.vfs, self.ui, self.root,
807 self._dirstatevalidate, sparsematchfn)
807 self._dirstatevalidate, sparsematchfn)
808
808
809 def _dirstatevalidate(self, node):
809 def _dirstatevalidate(self, node):
810 try:
810 try:
811 self.changelog.rev(node)
811 self.changelog.rev(node)
812 return node
812 return node
813 except error.LookupError:
813 except error.LookupError:
814 if not self._dirstatevalidatewarned:
814 if not self._dirstatevalidatewarned:
815 self._dirstatevalidatewarned = True
815 self._dirstatevalidatewarned = True
816 self.ui.warn(_("warning: ignoring unknown"
816 self.ui.warn(_("warning: ignoring unknown"
817 " working parent %s!\n") % short(node))
817 " working parent %s!\n") % short(node))
818 return nullid
818 return nullid
819
819
820 @storecache(narrowspec.FILENAME)
820 @storecache(narrowspec.FILENAME)
821 def narrowpats(self):
821 def narrowpats(self):
822 """matcher patterns for this repository's narrowspec
822 """matcher patterns for this repository's narrowspec
823
823
824 A tuple of (includes, excludes).
824 A tuple of (includes, excludes).
825 """
825 """
826 source = self
826 source = self
827 if self.shared():
827 if self.shared():
828 from . import hg
828 from . import hg
829 source = hg.sharedreposource(self)
829 source = hg.sharedreposource(self)
830 return narrowspec.load(source)
830 return narrowspec.load(source)
831
831
832 @storecache(narrowspec.FILENAME)
832 @storecache(narrowspec.FILENAME)
833 def _narrowmatch(self):
833 def _narrowmatch(self):
834 if repository.NARROW_REQUIREMENT not in self.requirements:
834 if repository.NARROW_REQUIREMENT not in self.requirements:
835 return matchmod.always(self.root, '')
835 return matchmod.always(self.root, '')
836 include, exclude = self.narrowpats
836 include, exclude = self.narrowpats
837 return narrowspec.match(self.root, include=include, exclude=exclude)
837 return narrowspec.match(self.root, include=include, exclude=exclude)
838
838
839 # TODO(martinvonz): make this property-like instead?
839 # TODO(martinvonz): make this property-like instead?
840 def narrowmatch(self):
840 def narrowmatch(self):
841 return self._narrowmatch
841 return self._narrowmatch
842
842
843 def setnarrowpats(self, newincludes, newexcludes):
843 def setnarrowpats(self, newincludes, newexcludes):
844 narrowspec.save(self, newincludes, newexcludes)
844 narrowspec.save(self, newincludes, newexcludes)
845 self.invalidate(clearfilecache=True)
845 self.invalidate(clearfilecache=True)
846
846
847 def __getitem__(self, changeid):
847 def __getitem__(self, changeid):
848 if changeid is None:
848 if changeid is None:
849 return context.workingctx(self)
849 return context.workingctx(self)
850 if isinstance(changeid, context.basectx):
850 if isinstance(changeid, context.basectx):
851 return changeid
851 return changeid
852 if isinstance(changeid, slice):
852 if isinstance(changeid, slice):
853 # wdirrev isn't contiguous so the slice shouldn't include it
853 # wdirrev isn't contiguous so the slice shouldn't include it
854 return [context.changectx(self, i)
854 return [context.changectx(self, i)
855 for i in pycompat.xrange(*changeid.indices(len(self)))
855 for i in pycompat.xrange(*changeid.indices(len(self)))
856 if i not in self.changelog.filteredrevs]
856 if i not in self.changelog.filteredrevs]
857 try:
857 try:
858 return context.changectx(self, changeid)
858 return context.changectx(self, changeid)
859 except error.WdirUnsupported:
859 except error.WdirUnsupported:
860 return context.workingctx(self)
860 return context.workingctx(self)
861
861
862 def __contains__(self, changeid):
862 def __contains__(self, changeid):
863 """True if the given changeid exists
863 """True if the given changeid exists
864
864
865 error.AmbiguousPrefixLookupError is raised if an ambiguous node
865 error.AmbiguousPrefixLookupError is raised if an ambiguous node
866 specified.
866 specified.
867 """
867 """
868 try:
868 try:
869 self[changeid]
869 self[changeid]
870 return True
870 return True
871 except error.RepoLookupError:
871 except error.RepoLookupError:
872 return False
872 return False
873
873
874 def __nonzero__(self):
874 def __nonzero__(self):
875 return True
875 return True
876
876
877 __bool__ = __nonzero__
877 __bool__ = __nonzero__
878
878
879 def __len__(self):
879 def __len__(self):
880 # no need to pay the cost of repoview.changelog
880 # no need to pay the cost of repoview.changelog
881 unfi = self.unfiltered()
881 unfi = self.unfiltered()
882 return len(unfi.changelog)
882 return len(unfi.changelog)
883
883
884 def __iter__(self):
884 def __iter__(self):
885 return iter(self.changelog)
885 return iter(self.changelog)
886
886
887 def revs(self, expr, *args):
887 def revs(self, expr, *args):
888 '''Find revisions matching a revset.
888 '''Find revisions matching a revset.
889
889
890 The revset is specified as a string ``expr`` that may contain
890 The revset is specified as a string ``expr`` that may contain
891 %-formatting to escape certain types. See ``revsetlang.formatspec``.
891 %-formatting to escape certain types. See ``revsetlang.formatspec``.
892
892
893 Revset aliases from the configuration are not expanded. To expand
893 Revset aliases from the configuration are not expanded. To expand
894 user aliases, consider calling ``scmutil.revrange()`` or
894 user aliases, consider calling ``scmutil.revrange()`` or
895 ``repo.anyrevs([expr], user=True)``.
895 ``repo.anyrevs([expr], user=True)``.
896
896
897 Returns a revset.abstractsmartset, which is a list-like interface
897 Returns a revset.abstractsmartset, which is a list-like interface
898 that contains integer revisions.
898 that contains integer revisions.
899 '''
899 '''
900 expr = revsetlang.formatspec(expr, *args)
900 expr = revsetlang.formatspec(expr, *args)
901 m = revset.match(None, expr)
901 m = revset.match(None, expr)
902 return m(self)
902 return m(self)
903
903
904 def set(self, expr, *args):
904 def set(self, expr, *args):
905 '''Find revisions matching a revset and emit changectx instances.
905 '''Find revisions matching a revset and emit changectx instances.
906
906
907 This is a convenience wrapper around ``revs()`` that iterates the
907 This is a convenience wrapper around ``revs()`` that iterates the
908 result and is a generator of changectx instances.
908 result and is a generator of changectx instances.
909
909
910 Revset aliases from the configuration are not expanded. To expand
910 Revset aliases from the configuration are not expanded. To expand
911 user aliases, consider calling ``scmutil.revrange()``.
911 user aliases, consider calling ``scmutil.revrange()``.
912 '''
912 '''
913 for r in self.revs(expr, *args):
913 for r in self.revs(expr, *args):
914 yield self[r]
914 yield self[r]
915
915
916 def anyrevs(self, specs, user=False, localalias=None):
916 def anyrevs(self, specs, user=False, localalias=None):
917 '''Find revisions matching one of the given revsets.
917 '''Find revisions matching one of the given revsets.
918
918
919 Revset aliases from the configuration are not expanded by default. To
919 Revset aliases from the configuration are not expanded by default. To
920 expand user aliases, specify ``user=True``. To provide some local
920 expand user aliases, specify ``user=True``. To provide some local
921 definitions overriding user aliases, set ``localalias`` to
921 definitions overriding user aliases, set ``localalias`` to
922 ``{name: definitionstring}``.
922 ``{name: definitionstring}``.
923 '''
923 '''
924 if user:
924 if user:
925 m = revset.matchany(self.ui, specs,
925 m = revset.matchany(self.ui, specs,
926 lookup=revset.lookupfn(self),
926 lookup=revset.lookupfn(self),
927 localalias=localalias)
927 localalias=localalias)
928 else:
928 else:
929 m = revset.matchany(None, specs, localalias=localalias)
929 m = revset.matchany(None, specs, localalias=localalias)
930 return m(self)
930 return m(self)
931
931
932 def url(self):
932 def url(self):
933 return 'file:' + self.root
933 return 'file:' + self.root
934
934
935 def hook(self, name, throw=False, **args):
935 def hook(self, name, throw=False, **args):
936 """Call a hook, passing this repo instance.
936 """Call a hook, passing this repo instance.
937
937
938 This a convenience method to aid invoking hooks. Extensions likely
938 This a convenience method to aid invoking hooks. Extensions likely
939 won't call this unless they have registered a custom hook or are
939 won't call this unless they have registered a custom hook or are
940 replacing code that is expected to call a hook.
940 replacing code that is expected to call a hook.
941 """
941 """
942 return hook.hook(self.ui, self, name, throw, **args)
942 return hook.hook(self.ui, self, name, throw, **args)
943
943
944 @filteredpropertycache
944 @filteredpropertycache
945 def _tagscache(self):
945 def _tagscache(self):
946 '''Returns a tagscache object that contains various tags related
946 '''Returns a tagscache object that contains various tags related
947 caches.'''
947 caches.'''
948
948
949 # This simplifies its cache management by having one decorated
949 # This simplifies its cache management by having one decorated
950 # function (this one) and the rest simply fetch things from it.
950 # function (this one) and the rest simply fetch things from it.
951 class tagscache(object):
951 class tagscache(object):
952 def __init__(self):
952 def __init__(self):
953 # These two define the set of tags for this repository. tags
953 # These two define the set of tags for this repository. tags
954 # maps tag name to node; tagtypes maps tag name to 'global' or
954 # maps tag name to node; tagtypes maps tag name to 'global' or
955 # 'local'. (Global tags are defined by .hgtags across all
955 # 'local'. (Global tags are defined by .hgtags across all
956 # heads, and local tags are defined in .hg/localtags.)
956 # heads, and local tags are defined in .hg/localtags.)
957 # They constitute the in-memory cache of tags.
957 # They constitute the in-memory cache of tags.
958 self.tags = self.tagtypes = None
958 self.tags = self.tagtypes = None
959
959
960 self.nodetagscache = self.tagslist = None
960 self.nodetagscache = self.tagslist = None
961
961
962 cache = tagscache()
962 cache = tagscache()
963 cache.tags, cache.tagtypes = self._findtags()
963 cache.tags, cache.tagtypes = self._findtags()
964
964
965 return cache
965 return cache
966
966
967 def tags(self):
967 def tags(self):
968 '''return a mapping of tag to node'''
968 '''return a mapping of tag to node'''
969 t = {}
969 t = {}
970 if self.changelog.filteredrevs:
970 if self.changelog.filteredrevs:
971 tags, tt = self._findtags()
971 tags, tt = self._findtags()
972 else:
972 else:
973 tags = self._tagscache.tags
973 tags = self._tagscache.tags
974 for k, v in tags.iteritems():
974 for k, v in tags.iteritems():
975 try:
975 try:
976 # ignore tags to unknown nodes
976 # ignore tags to unknown nodes
977 self.changelog.rev(v)
977 self.changelog.rev(v)
978 t[k] = v
978 t[k] = v
979 except (error.LookupError, ValueError):
979 except (error.LookupError, ValueError):
980 pass
980 pass
981 return t
981 return t
982
982
983 def _findtags(self):
983 def _findtags(self):
984 '''Do the hard work of finding tags. Return a pair of dicts
984 '''Do the hard work of finding tags. Return a pair of dicts
985 (tags, tagtypes) where tags maps tag name to node, and tagtypes
985 (tags, tagtypes) where tags maps tag name to node, and tagtypes
986 maps tag name to a string like \'global\' or \'local\'.
986 maps tag name to a string like \'global\' or \'local\'.
987 Subclasses or extensions are free to add their own tags, but
987 Subclasses or extensions are free to add their own tags, but
988 should be aware that the returned dicts will be retained for the
988 should be aware that the returned dicts will be retained for the
989 duration of the localrepo object.'''
989 duration of the localrepo object.'''
990
990
991 # XXX what tagtype should subclasses/extensions use? Currently
991 # XXX what tagtype should subclasses/extensions use? Currently
992 # mq and bookmarks add tags, but do not set the tagtype at all.
992 # mq and bookmarks add tags, but do not set the tagtype at all.
993 # Should each extension invent its own tag type? Should there
993 # Should each extension invent its own tag type? Should there
994 # be one tagtype for all such "virtual" tags? Or is the status
994 # be one tagtype for all such "virtual" tags? Or is the status
995 # quo fine?
995 # quo fine?
996
996
997
997
998 # map tag name to (node, hist)
998 # map tag name to (node, hist)
999 alltags = tagsmod.findglobaltags(self.ui, self)
999 alltags = tagsmod.findglobaltags(self.ui, self)
1000 # map tag name to tag type
1000 # map tag name to tag type
1001 tagtypes = dict((tag, 'global') for tag in alltags)
1001 tagtypes = dict((tag, 'global') for tag in alltags)
1002
1002
1003 tagsmod.readlocaltags(self.ui, self, alltags, tagtypes)
1003 tagsmod.readlocaltags(self.ui, self, alltags, tagtypes)
1004
1004
1005 # Build the return dicts. Have to re-encode tag names because
1005 # Build the return dicts. Have to re-encode tag names because
1006 # the tags module always uses UTF-8 (in order not to lose info
1006 # the tags module always uses UTF-8 (in order not to lose info
1007 # writing to the cache), but the rest of Mercurial wants them in
1007 # writing to the cache), but the rest of Mercurial wants them in
1008 # local encoding.
1008 # local encoding.
1009 tags = {}
1009 tags = {}
1010 for (name, (node, hist)) in alltags.iteritems():
1010 for (name, (node, hist)) in alltags.iteritems():
1011 if node != nullid:
1011 if node != nullid:
1012 tags[encoding.tolocal(name)] = node
1012 tags[encoding.tolocal(name)] = node
1013 tags['tip'] = self.changelog.tip()
1013 tags['tip'] = self.changelog.tip()
1014 tagtypes = dict([(encoding.tolocal(name), value)
1014 tagtypes = dict([(encoding.tolocal(name), value)
1015 for (name, value) in tagtypes.iteritems()])
1015 for (name, value) in tagtypes.iteritems()])
1016 return (tags, tagtypes)
1016 return (tags, tagtypes)
1017
1017
1018 def tagtype(self, tagname):
1018 def tagtype(self, tagname):
1019 '''
1019 '''
1020 return the type of the given tag. result can be:
1020 return the type of the given tag. result can be:
1021
1021
1022 'local' : a local tag
1022 'local' : a local tag
1023 'global' : a global tag
1023 'global' : a global tag
1024 None : tag does not exist
1024 None : tag does not exist
1025 '''
1025 '''
1026
1026
1027 return self._tagscache.tagtypes.get(tagname)
1027 return self._tagscache.tagtypes.get(tagname)
1028
1028
1029 def tagslist(self):
1029 def tagslist(self):
1030 '''return a list of tags ordered by revision'''
1030 '''return a list of tags ordered by revision'''
1031 if not self._tagscache.tagslist:
1031 if not self._tagscache.tagslist:
1032 l = []
1032 l = []
1033 for t, n in self.tags().iteritems():
1033 for t, n in self.tags().iteritems():
1034 l.append((self.changelog.rev(n), t, n))
1034 l.append((self.changelog.rev(n), t, n))
1035 self._tagscache.tagslist = [(t, n) for r, t, n in sorted(l)]
1035 self._tagscache.tagslist = [(t, n) for r, t, n in sorted(l)]
1036
1036
1037 return self._tagscache.tagslist
1037 return self._tagscache.tagslist
1038
1038
1039 def nodetags(self, node):
1039 def nodetags(self, node):
1040 '''return the tags associated with a node'''
1040 '''return the tags associated with a node'''
1041 if not self._tagscache.nodetagscache:
1041 if not self._tagscache.nodetagscache:
1042 nodetagscache = {}
1042 nodetagscache = {}
1043 for t, n in self._tagscache.tags.iteritems():
1043 for t, n in self._tagscache.tags.iteritems():
1044 nodetagscache.setdefault(n, []).append(t)
1044 nodetagscache.setdefault(n, []).append(t)
1045 for tags in nodetagscache.itervalues():
1045 for tags in nodetagscache.itervalues():
1046 tags.sort()
1046 tags.sort()
1047 self._tagscache.nodetagscache = nodetagscache
1047 self._tagscache.nodetagscache = nodetagscache
1048 return self._tagscache.nodetagscache.get(node, [])
1048 return self._tagscache.nodetagscache.get(node, [])
1049
1049
1050 def nodebookmarks(self, node):
1050 def nodebookmarks(self, node):
1051 """return the list of bookmarks pointing to the specified node"""
1051 """return the list of bookmarks pointing to the specified node"""
1052 return self._bookmarks.names(node)
1052 return self._bookmarks.names(node)
1053
1053
1054 def branchmap(self):
1054 def branchmap(self):
1055 '''returns a dictionary {branch: [branchheads]} with branchheads
1055 '''returns a dictionary {branch: [branchheads]} with branchheads
1056 ordered by increasing revision number'''
1056 ordered by increasing revision number'''
1057 branchmap.updatecache(self)
1057 branchmap.updatecache(self)
1058 return self._branchcaches[self.filtername]
1058 return self._branchcaches[self.filtername]
1059
1059
1060 @unfilteredmethod
1060 @unfilteredmethod
1061 def revbranchcache(self):
1061 def revbranchcache(self):
1062 if not self._revbranchcache:
1062 if not self._revbranchcache:
1063 self._revbranchcache = branchmap.revbranchcache(self.unfiltered())
1063 self._revbranchcache = branchmap.revbranchcache(self.unfiltered())
1064 return self._revbranchcache
1064 return self._revbranchcache
1065
1065
1066 def branchtip(self, branch, ignoremissing=False):
1066 def branchtip(self, branch, ignoremissing=False):
1067 '''return the tip node for a given branch
1067 '''return the tip node for a given branch
1068
1068
1069 If ignoremissing is True, then this method will not raise an error.
1069 If ignoremissing is True, then this method will not raise an error.
1070 This is helpful for callers that only expect None for a missing branch
1070 This is helpful for callers that only expect None for a missing branch
1071 (e.g. namespace).
1071 (e.g. namespace).
1072
1072
1073 '''
1073 '''
1074 try:
1074 try:
1075 return self.branchmap().branchtip(branch)
1075 return self.branchmap().branchtip(branch)
1076 except KeyError:
1076 except KeyError:
1077 if not ignoremissing:
1077 if not ignoremissing:
1078 raise error.RepoLookupError(_("unknown branch '%s'") % branch)
1078 raise error.RepoLookupError(_("unknown branch '%s'") % branch)
1079 else:
1079 else:
1080 pass
1080 pass
1081
1081
1082 def lookup(self, key):
1082 def lookup(self, key):
1083 return scmutil.revsymbol(self, key).node()
1083 return scmutil.revsymbol(self, key).node()
1084
1084
1085 def lookupbranch(self, key):
1085 def lookupbranch(self, key):
1086 if key in self.branchmap():
1086 if key in self.branchmap():
1087 return key
1087 return key
1088
1088
1089 return scmutil.revsymbol(self, key).branch()
1089 return scmutil.revsymbol(self, key).branch()
1090
1090
1091 def known(self, nodes):
1091 def known(self, nodes):
1092 cl = self.changelog
1092 cl = self.changelog
1093 nm = cl.nodemap
1093 nm = cl.nodemap
1094 filtered = cl.filteredrevs
1094 filtered = cl.filteredrevs
1095 result = []
1095 result = []
1096 for n in nodes:
1096 for n in nodes:
1097 r = nm.get(n)
1097 r = nm.get(n)
1098 resp = not (r is None or r in filtered)
1098 resp = not (r is None or r in filtered)
1099 result.append(resp)
1099 result.append(resp)
1100 return result
1100 return result
1101
1101
1102 def local(self):
1102 def local(self):
1103 return self
1103 return self
1104
1104
1105 def publishing(self):
1105 def publishing(self):
1106 # it's safe (and desirable) to trust the publish flag unconditionally
1106 # it's safe (and desirable) to trust the publish flag unconditionally
1107 # so that we don't finalize changes shared between users via ssh or nfs
1107 # so that we don't finalize changes shared between users via ssh or nfs
1108 return self.ui.configbool('phases', 'publish', untrusted=True)
1108 return self.ui.configbool('phases', 'publish', untrusted=True)
1109
1109
1110 def cancopy(self):
1110 def cancopy(self):
1111 # so statichttprepo's override of local() works
1111 # so statichttprepo's override of local() works
1112 if not self.local():
1112 if not self.local():
1113 return False
1113 return False
1114 if not self.publishing():
1114 if not self.publishing():
1115 return True
1115 return True
1116 # if publishing we can't copy if there is filtered content
1116 # if publishing we can't copy if there is filtered content
1117 return not self.filtered('visible').changelog.filteredrevs
1117 return not self.filtered('visible').changelog.filteredrevs
1118
1118
1119 def shared(self):
1119 def shared(self):
1120 '''the type of shared repository (None if not shared)'''
1120 '''the type of shared repository (None if not shared)'''
1121 if self.sharedpath != self.path:
1121 if self.sharedpath != self.path:
1122 return 'store'
1122 return 'store'
1123 return None
1123 return None
1124
1124
1125 def wjoin(self, f, *insidef):
1125 def wjoin(self, f, *insidef):
1126 return self.vfs.reljoin(self.root, f, *insidef)
1126 return self.vfs.reljoin(self.root, f, *insidef)
1127
1127
1128 def file(self, f):
1128 def file(self, f):
1129 if f[0] == '/':
1129 if f[0] == '/':
1130 f = f[1:]
1130 f = f[1:]
1131 return filelog.filelog(self.svfs, f)
1131 return filelog.filelog(self.svfs, f)
1132
1132
1133 def setparents(self, p1, p2=nullid):
1133 def setparents(self, p1, p2=nullid):
1134 with self.dirstate.parentchange():
1134 with self.dirstate.parentchange():
1135 copies = self.dirstate.setparents(p1, p2)
1135 copies = self.dirstate.setparents(p1, p2)
1136 pctx = self[p1]
1136 pctx = self[p1]
1137 if copies:
1137 if copies:
1138 # Adjust copy records, the dirstate cannot do it, it
1138 # Adjust copy records, the dirstate cannot do it, it
1139 # requires access to parents manifests. Preserve them
1139 # requires access to parents manifests. Preserve them
1140 # only for entries added to first parent.
1140 # only for entries added to first parent.
1141 for f in copies:
1141 for f in copies:
1142 if f not in pctx and copies[f] in pctx:
1142 if f not in pctx and copies[f] in pctx:
1143 self.dirstate.copy(copies[f], f)
1143 self.dirstate.copy(copies[f], f)
1144 if p2 == nullid:
1144 if p2 == nullid:
1145 for f, s in sorted(self.dirstate.copies().items()):
1145 for f, s in sorted(self.dirstate.copies().items()):
1146 if f not in pctx and s not in pctx:
1146 if f not in pctx and s not in pctx:
1147 self.dirstate.copy(None, f)
1147 self.dirstate.copy(None, f)
1148
1148
1149 def filectx(self, path, changeid=None, fileid=None, changectx=None):
1149 def filectx(self, path, changeid=None, fileid=None, changectx=None):
1150 """changeid can be a changeset revision, node, or tag.
1150 """changeid can be a changeset revision, node, or tag.
1151 fileid can be a file revision or node."""
1151 fileid can be a file revision or node."""
1152 return context.filectx(self, path, changeid, fileid,
1152 return context.filectx(self, path, changeid, fileid,
1153 changectx=changectx)
1153 changectx=changectx)
1154
1154
1155 def getcwd(self):
1155 def getcwd(self):
1156 return self.dirstate.getcwd()
1156 return self.dirstate.getcwd()
1157
1157
1158 def pathto(self, f, cwd=None):
1158 def pathto(self, f, cwd=None):
1159 return self.dirstate.pathto(f, cwd)
1159 return self.dirstate.pathto(f, cwd)
1160
1160
1161 def _loadfilter(self, filter):
1161 def _loadfilter(self, filter):
1162 if filter not in self._filterpats:
1162 if filter not in self._filterpats:
1163 l = []
1163 l = []
1164 for pat, cmd in self.ui.configitems(filter):
1164 for pat, cmd in self.ui.configitems(filter):
1165 if cmd == '!':
1165 if cmd == '!':
1166 continue
1166 continue
1167 mf = matchmod.match(self.root, '', [pat])
1167 mf = matchmod.match(self.root, '', [pat])
1168 fn = None
1168 fn = None
1169 params = cmd
1169 params = cmd
1170 for name, filterfn in self._datafilters.iteritems():
1170 for name, filterfn in self._datafilters.iteritems():
1171 if cmd.startswith(name):
1171 if cmd.startswith(name):
1172 fn = filterfn
1172 fn = filterfn
1173 params = cmd[len(name):].lstrip()
1173 params = cmd[len(name):].lstrip()
1174 break
1174 break
1175 if not fn:
1175 if not fn:
1176 fn = lambda s, c, **kwargs: procutil.filter(s, c)
1176 fn = lambda s, c, **kwargs: procutil.filter(s, c)
1177 # Wrap old filters not supporting keyword arguments
1177 # Wrap old filters not supporting keyword arguments
1178 if not pycompat.getargspec(fn)[2]:
1178 if not pycompat.getargspec(fn)[2]:
1179 oldfn = fn
1179 oldfn = fn
1180 fn = lambda s, c, **kwargs: oldfn(s, c)
1180 fn = lambda s, c, **kwargs: oldfn(s, c)
1181 l.append((mf, fn, params))
1181 l.append((mf, fn, params))
1182 self._filterpats[filter] = l
1182 self._filterpats[filter] = l
1183 return self._filterpats[filter]
1183 return self._filterpats[filter]
1184
1184
1185 def _filter(self, filterpats, filename, data):
1185 def _filter(self, filterpats, filename, data):
1186 for mf, fn, cmd in filterpats:
1186 for mf, fn, cmd in filterpats:
1187 if mf(filename):
1187 if mf(filename):
1188 self.ui.debug("filtering %s through %s\n" % (filename, cmd))
1188 self.ui.debug("filtering %s through %s\n" % (filename, cmd))
1189 data = fn(data, cmd, ui=self.ui, repo=self, filename=filename)
1189 data = fn(data, cmd, ui=self.ui, repo=self, filename=filename)
1190 break
1190 break
1191
1191
1192 return data
1192 return data
1193
1193
1194 @unfilteredpropertycache
1194 @unfilteredpropertycache
1195 def _encodefilterpats(self):
1195 def _encodefilterpats(self):
1196 return self._loadfilter('encode')
1196 return self._loadfilter('encode')
1197
1197
1198 @unfilteredpropertycache
1198 @unfilteredpropertycache
1199 def _decodefilterpats(self):
1199 def _decodefilterpats(self):
1200 return self._loadfilter('decode')
1200 return self._loadfilter('decode')
1201
1201
1202 def adddatafilter(self, name, filter):
1202 def adddatafilter(self, name, filter):
1203 self._datafilters[name] = filter
1203 self._datafilters[name] = filter
1204
1204
1205 def wread(self, filename):
1205 def wread(self, filename):
1206 if self.wvfs.islink(filename):
1206 if self.wvfs.islink(filename):
1207 data = self.wvfs.readlink(filename)
1207 data = self.wvfs.readlink(filename)
1208 else:
1208 else:
1209 data = self.wvfs.read(filename)
1209 data = self.wvfs.read(filename)
1210 return self._filter(self._encodefilterpats, filename, data)
1210 return self._filter(self._encodefilterpats, filename, data)
1211
1211
1212 def wwrite(self, filename, data, flags, backgroundclose=False, **kwargs):
1212 def wwrite(self, filename, data, flags, backgroundclose=False, **kwargs):
1213 """write ``data`` into ``filename`` in the working directory
1213 """write ``data`` into ``filename`` in the working directory
1214
1214
1215 This returns length of written (maybe decoded) data.
1215 This returns length of written (maybe decoded) data.
1216 """
1216 """
1217 data = self._filter(self._decodefilterpats, filename, data)
1217 data = self._filter(self._decodefilterpats, filename, data)
1218 if 'l' in flags:
1218 if 'l' in flags:
1219 self.wvfs.symlink(data, filename)
1219 self.wvfs.symlink(data, filename)
1220 else:
1220 else:
1221 self.wvfs.write(filename, data, backgroundclose=backgroundclose,
1221 self.wvfs.write(filename, data, backgroundclose=backgroundclose,
1222 **kwargs)
1222 **kwargs)
1223 if 'x' in flags:
1223 if 'x' in flags:
1224 self.wvfs.setflags(filename, False, True)
1224 self.wvfs.setflags(filename, False, True)
1225 else:
1225 else:
1226 self.wvfs.setflags(filename, False, False)
1226 self.wvfs.setflags(filename, False, False)
1227 return len(data)
1227 return len(data)
1228
1228
1229 def wwritedata(self, filename, data):
1229 def wwritedata(self, filename, data):
1230 return self._filter(self._decodefilterpats, filename, data)
1230 return self._filter(self._decodefilterpats, filename, data)
1231
1231
1232 def currenttransaction(self):
1232 def currenttransaction(self):
1233 """return the current transaction or None if non exists"""
1233 """return the current transaction or None if non exists"""
1234 if self._transref:
1234 if self._transref:
1235 tr = self._transref()
1235 tr = self._transref()
1236 else:
1236 else:
1237 tr = None
1237 tr = None
1238
1238
1239 if tr and tr.running():
1239 if tr and tr.running():
1240 return tr
1240 return tr
1241 return None
1241 return None
1242
1242
1243 def transaction(self, desc, report=None):
1243 def transaction(self, desc, report=None):
1244 if (self.ui.configbool('devel', 'all-warnings')
1244 if (self.ui.configbool('devel', 'all-warnings')
1245 or self.ui.configbool('devel', 'check-locks')):
1245 or self.ui.configbool('devel', 'check-locks')):
1246 if self._currentlock(self._lockref) is None:
1246 if self._currentlock(self._lockref) is None:
1247 raise error.ProgrammingError('transaction requires locking')
1247 raise error.ProgrammingError('transaction requires locking')
1248 tr = self.currenttransaction()
1248 tr = self.currenttransaction()
1249 if tr is not None:
1249 if tr is not None:
1250 return tr.nest(name=desc)
1250 return tr.nest(name=desc)
1251
1251
1252 # abort here if the journal already exists
1252 # abort here if the journal already exists
1253 if self.svfs.exists("journal"):
1253 if self.svfs.exists("journal"):
1254 raise error.RepoError(
1254 raise error.RepoError(
1255 _("abandoned transaction found"),
1255 _("abandoned transaction found"),
1256 hint=_("run 'hg recover' to clean up transaction"))
1256 hint=_("run 'hg recover' to clean up transaction"))
1257
1257
1258 idbase = "%.40f#%f" % (random.random(), time.time())
1258 idbase = "%.40f#%f" % (random.random(), time.time())
1259 ha = hex(hashlib.sha1(idbase).digest())
1259 ha = hex(hashlib.sha1(idbase).digest())
1260 txnid = 'TXN:' + ha
1260 txnid = 'TXN:' + ha
1261 self.hook('pretxnopen', throw=True, txnname=desc, txnid=txnid)
1261 self.hook('pretxnopen', throw=True, txnname=desc, txnid=txnid)
1262
1262
1263 self._writejournal(desc)
1263 self._writejournal(desc)
1264 renames = [(vfs, x, undoname(x)) for vfs, x in self._journalfiles()]
1264 renames = [(vfs, x, undoname(x)) for vfs, x in self._journalfiles()]
1265 if report:
1265 if report:
1266 rp = report
1266 rp = report
1267 else:
1267 else:
1268 rp = self.ui.warn
1268 rp = self.ui.warn
1269 vfsmap = {'plain': self.vfs} # root of .hg/
1269 vfsmap = {'plain': self.vfs} # root of .hg/
1270 # we must avoid cyclic reference between repo and transaction.
1270 # we must avoid cyclic reference between repo and transaction.
1271 reporef = weakref.ref(self)
1271 reporef = weakref.ref(self)
1272 # Code to track tag movement
1272 # Code to track tag movement
1273 #
1273 #
1274 # Since tags are all handled as file content, it is actually quite hard
1274 # Since tags are all handled as file content, it is actually quite hard
1275 # to track these movement from a code perspective. So we fallback to a
1275 # to track these movement from a code perspective. So we fallback to a
1276 # tracking at the repository level. One could envision to track changes
1276 # tracking at the repository level. One could envision to track changes
1277 # to the '.hgtags' file through changegroup apply but that fails to
1277 # to the '.hgtags' file through changegroup apply but that fails to
1278 # cope with case where transaction expose new heads without changegroup
1278 # cope with case where transaction expose new heads without changegroup
1279 # being involved (eg: phase movement).
1279 # being involved (eg: phase movement).
1280 #
1280 #
1281 # For now, We gate the feature behind a flag since this likely comes
1281 # For now, We gate the feature behind a flag since this likely comes
1282 # with performance impacts. The current code run more often than needed
1282 # with performance impacts. The current code run more often than needed
1283 # and do not use caches as much as it could. The current focus is on
1283 # and do not use caches as much as it could. The current focus is on
1284 # the behavior of the feature so we disable it by default. The flag
1284 # the behavior of the feature so we disable it by default. The flag
1285 # will be removed when we are happy with the performance impact.
1285 # will be removed when we are happy with the performance impact.
1286 #
1286 #
1287 # Once this feature is no longer experimental move the following
1287 # Once this feature is no longer experimental move the following
1288 # documentation to the appropriate help section:
1288 # documentation to the appropriate help section:
1289 #
1289 #
1290 # The ``HG_TAG_MOVED`` variable will be set if the transaction touched
1290 # The ``HG_TAG_MOVED`` variable will be set if the transaction touched
1291 # tags (new or changed or deleted tags). In addition the details of
1291 # tags (new or changed or deleted tags). In addition the details of
1292 # these changes are made available in a file at:
1292 # these changes are made available in a file at:
1293 # ``REPOROOT/.hg/changes/tags.changes``.
1293 # ``REPOROOT/.hg/changes/tags.changes``.
1294 # Make sure you check for HG_TAG_MOVED before reading that file as it
1294 # Make sure you check for HG_TAG_MOVED before reading that file as it
1295 # might exist from a previous transaction even if no tag were touched
1295 # might exist from a previous transaction even if no tag were touched
1296 # in this one. Changes are recorded in a line base format::
1296 # in this one. Changes are recorded in a line base format::
1297 #
1297 #
1298 # <action> <hex-node> <tag-name>\n
1298 # <action> <hex-node> <tag-name>\n
1299 #
1299 #
1300 # Actions are defined as follow:
1300 # Actions are defined as follow:
1301 # "-R": tag is removed,
1301 # "-R": tag is removed,
1302 # "+A": tag is added,
1302 # "+A": tag is added,
1303 # "-M": tag is moved (old value),
1303 # "-M": tag is moved (old value),
1304 # "+M": tag is moved (new value),
1304 # "+M": tag is moved (new value),
1305 tracktags = lambda x: None
1305 tracktags = lambda x: None
1306 # experimental config: experimental.hook-track-tags
1306 # experimental config: experimental.hook-track-tags
1307 shouldtracktags = self.ui.configbool('experimental', 'hook-track-tags')
1307 shouldtracktags = self.ui.configbool('experimental', 'hook-track-tags')
1308 if desc != 'strip' and shouldtracktags:
1308 if desc != 'strip' and shouldtracktags:
1309 oldheads = self.changelog.headrevs()
1309 oldheads = self.changelog.headrevs()
1310 def tracktags(tr2):
1310 def tracktags(tr2):
1311 repo = reporef()
1311 repo = reporef()
1312 oldfnodes = tagsmod.fnoderevs(repo.ui, repo, oldheads)
1312 oldfnodes = tagsmod.fnoderevs(repo.ui, repo, oldheads)
1313 newheads = repo.changelog.headrevs()
1313 newheads = repo.changelog.headrevs()
1314 newfnodes = tagsmod.fnoderevs(repo.ui, repo, newheads)
1314 newfnodes = tagsmod.fnoderevs(repo.ui, repo, newheads)
1315 # notes: we compare lists here.
1315 # notes: we compare lists here.
1316 # As we do it only once buiding set would not be cheaper
1316 # As we do it only once buiding set would not be cheaper
1317 changes = tagsmod.difftags(repo.ui, repo, oldfnodes, newfnodes)
1317 changes = tagsmod.difftags(repo.ui, repo, oldfnodes, newfnodes)
1318 if changes:
1318 if changes:
1319 tr2.hookargs['tag_moved'] = '1'
1319 tr2.hookargs['tag_moved'] = '1'
1320 with repo.vfs('changes/tags.changes', 'w',
1320 with repo.vfs('changes/tags.changes', 'w',
1321 atomictemp=True) as changesfile:
1321 atomictemp=True) as changesfile:
1322 # note: we do not register the file to the transaction
1322 # note: we do not register the file to the transaction
1323 # because we needs it to still exist on the transaction
1323 # because we needs it to still exist on the transaction
1324 # is close (for txnclose hooks)
1324 # is close (for txnclose hooks)
1325 tagsmod.writediff(changesfile, changes)
1325 tagsmod.writediff(changesfile, changes)
1326 def validate(tr2):
1326 def validate(tr2):
1327 """will run pre-closing hooks"""
1327 """will run pre-closing hooks"""
1328 # XXX the transaction API is a bit lacking here so we take a hacky
1328 # XXX the transaction API is a bit lacking here so we take a hacky
1329 # path for now
1329 # path for now
1330 #
1330 #
1331 # We cannot add this as a "pending" hooks since the 'tr.hookargs'
1331 # We cannot add this as a "pending" hooks since the 'tr.hookargs'
1332 # dict is copied before these run. In addition we needs the data
1332 # dict is copied before these run. In addition we needs the data
1333 # available to in memory hooks too.
1333 # available to in memory hooks too.
1334 #
1334 #
1335 # Moreover, we also need to make sure this runs before txnclose
1335 # Moreover, we also need to make sure this runs before txnclose
1336 # hooks and there is no "pending" mechanism that would execute
1336 # hooks and there is no "pending" mechanism that would execute
1337 # logic only if hooks are about to run.
1337 # logic only if hooks are about to run.
1338 #
1338 #
1339 # Fixing this limitation of the transaction is also needed to track
1339 # Fixing this limitation of the transaction is also needed to track
1340 # other families of changes (bookmarks, phases, obsolescence).
1340 # other families of changes (bookmarks, phases, obsolescence).
1341 #
1341 #
1342 # This will have to be fixed before we remove the experimental
1342 # This will have to be fixed before we remove the experimental
1343 # gating.
1343 # gating.
1344 tracktags(tr2)
1344 tracktags(tr2)
1345 repo = reporef()
1345 repo = reporef()
1346 if repo.ui.configbool('experimental', 'single-head-per-branch'):
1346 if repo.ui.configbool('experimental', 'single-head-per-branch'):
1347 scmutil.enforcesinglehead(repo, tr2, desc)
1347 scmutil.enforcesinglehead(repo, tr2, desc)
1348 if hook.hashook(repo.ui, 'pretxnclose-bookmark'):
1348 if hook.hashook(repo.ui, 'pretxnclose-bookmark'):
1349 for name, (old, new) in sorted(tr.changes['bookmarks'].items()):
1349 for name, (old, new) in sorted(tr.changes['bookmarks'].items()):
1350 args = tr.hookargs.copy()
1350 args = tr.hookargs.copy()
1351 args.update(bookmarks.preparehookargs(name, old, new))
1351 args.update(bookmarks.preparehookargs(name, old, new))
1352 repo.hook('pretxnclose-bookmark', throw=True,
1352 repo.hook('pretxnclose-bookmark', throw=True,
1353 txnname=desc,
1353 txnname=desc,
1354 **pycompat.strkwargs(args))
1354 **pycompat.strkwargs(args))
1355 if hook.hashook(repo.ui, 'pretxnclose-phase'):
1355 if hook.hashook(repo.ui, 'pretxnclose-phase'):
1356 cl = repo.unfiltered().changelog
1356 cl = repo.unfiltered().changelog
1357 for rev, (old, new) in tr.changes['phases'].items():
1357 for rev, (old, new) in tr.changes['phases'].items():
1358 args = tr.hookargs.copy()
1358 args = tr.hookargs.copy()
1359 node = hex(cl.node(rev))
1359 node = hex(cl.node(rev))
1360 args.update(phases.preparehookargs(node, old, new))
1360 args.update(phases.preparehookargs(node, old, new))
1361 repo.hook('pretxnclose-phase', throw=True, txnname=desc,
1361 repo.hook('pretxnclose-phase', throw=True, txnname=desc,
1362 **pycompat.strkwargs(args))
1362 **pycompat.strkwargs(args))
1363
1363
1364 repo.hook('pretxnclose', throw=True,
1364 repo.hook('pretxnclose', throw=True,
1365 txnname=desc, **pycompat.strkwargs(tr.hookargs))
1365 txnname=desc, **pycompat.strkwargs(tr.hookargs))
1366 def releasefn(tr, success):
1366 def releasefn(tr, success):
1367 repo = reporef()
1367 repo = reporef()
1368 if success:
1368 if success:
1369 # this should be explicitly invoked here, because
1369 # this should be explicitly invoked here, because
1370 # in-memory changes aren't written out at closing
1370 # in-memory changes aren't written out at closing
1371 # transaction, if tr.addfilegenerator (via
1371 # transaction, if tr.addfilegenerator (via
1372 # dirstate.write or so) isn't invoked while
1372 # dirstate.write or so) isn't invoked while
1373 # transaction running
1373 # transaction running
1374 repo.dirstate.write(None)
1374 repo.dirstate.write(None)
1375 else:
1375 else:
1376 # discard all changes (including ones already written
1376 # discard all changes (including ones already written
1377 # out) in this transaction
1377 # out) in this transaction
1378 narrowspec.restorebackup(self, 'journal.narrowspec')
1378 narrowspec.restorebackup(self, 'journal.narrowspec')
1379 repo.dirstate.restorebackup(None, 'journal.dirstate')
1379 repo.dirstate.restorebackup(None, 'journal.dirstate')
1380
1380
1381 repo.invalidate(clearfilecache=True)
1381 repo.invalidate(clearfilecache=True)
1382
1382
1383 tr = transaction.transaction(rp, self.svfs, vfsmap,
1383 tr = transaction.transaction(rp, self.svfs, vfsmap,
1384 "journal",
1384 "journal",
1385 "undo",
1385 "undo",
1386 aftertrans(renames),
1386 aftertrans(renames),
1387 self.store.createmode,
1387 self.store.createmode,
1388 validator=validate,
1388 validator=validate,
1389 releasefn=releasefn,
1389 releasefn=releasefn,
1390 checkambigfiles=_cachedfiles,
1390 checkambigfiles=_cachedfiles,
1391 name=desc)
1391 name=desc)
1392 tr.changes['origrepolen'] = len(self)
1392 tr.changes['origrepolen'] = len(self)
1393 tr.changes['obsmarkers'] = set()
1393 tr.changes['obsmarkers'] = set()
1394 tr.changes['phases'] = {}
1394 tr.changes['phases'] = {}
1395 tr.changes['bookmarks'] = {}
1395 tr.changes['bookmarks'] = {}
1396
1396
1397 tr.hookargs['txnid'] = txnid
1397 tr.hookargs['txnid'] = txnid
1398 # note: writing the fncache only during finalize mean that the file is
1398 # note: writing the fncache only during finalize mean that the file is
1399 # outdated when running hooks. As fncache is used for streaming clone,
1399 # outdated when running hooks. As fncache is used for streaming clone,
1400 # this is not expected to break anything that happen during the hooks.
1400 # this is not expected to break anything that happen during the hooks.
1401 tr.addfinalize('flush-fncache', self.store.write)
1401 tr.addfinalize('flush-fncache', self.store.write)
1402 def txnclosehook(tr2):
1402 def txnclosehook(tr2):
1403 """To be run if transaction is successful, will schedule a hook run
1403 """To be run if transaction is successful, will schedule a hook run
1404 """
1404 """
1405 # Don't reference tr2 in hook() so we don't hold a reference.
1405 # Don't reference tr2 in hook() so we don't hold a reference.
1406 # This reduces memory consumption when there are multiple
1406 # This reduces memory consumption when there are multiple
1407 # transactions per lock. This can likely go away if issue5045
1407 # transactions per lock. This can likely go away if issue5045
1408 # fixes the function accumulation.
1408 # fixes the function accumulation.
1409 hookargs = tr2.hookargs
1409 hookargs = tr2.hookargs
1410
1410
1411 def hookfunc():
1411 def hookfunc():
1412 repo = reporef()
1412 repo = reporef()
1413 if hook.hashook(repo.ui, 'txnclose-bookmark'):
1413 if hook.hashook(repo.ui, 'txnclose-bookmark'):
1414 bmchanges = sorted(tr.changes['bookmarks'].items())
1414 bmchanges = sorted(tr.changes['bookmarks'].items())
1415 for name, (old, new) in bmchanges:
1415 for name, (old, new) in bmchanges:
1416 args = tr.hookargs.copy()
1416 args = tr.hookargs.copy()
1417 args.update(bookmarks.preparehookargs(name, old, new))
1417 args.update(bookmarks.preparehookargs(name, old, new))
1418 repo.hook('txnclose-bookmark', throw=False,
1418 repo.hook('txnclose-bookmark', throw=False,
1419 txnname=desc, **pycompat.strkwargs(args))
1419 txnname=desc, **pycompat.strkwargs(args))
1420
1420
1421 if hook.hashook(repo.ui, 'txnclose-phase'):
1421 if hook.hashook(repo.ui, 'txnclose-phase'):
1422 cl = repo.unfiltered().changelog
1422 cl = repo.unfiltered().changelog
1423 phasemv = sorted(tr.changes['phases'].items())
1423 phasemv = sorted(tr.changes['phases'].items())
1424 for rev, (old, new) in phasemv:
1424 for rev, (old, new) in phasemv:
1425 args = tr.hookargs.copy()
1425 args = tr.hookargs.copy()
1426 node = hex(cl.node(rev))
1426 node = hex(cl.node(rev))
1427 args.update(phases.preparehookargs(node, old, new))
1427 args.update(phases.preparehookargs(node, old, new))
1428 repo.hook('txnclose-phase', throw=False, txnname=desc,
1428 repo.hook('txnclose-phase', throw=False, txnname=desc,
1429 **pycompat.strkwargs(args))
1429 **pycompat.strkwargs(args))
1430
1430
1431 repo.hook('txnclose', throw=False, txnname=desc,
1431 repo.hook('txnclose', throw=False, txnname=desc,
1432 **pycompat.strkwargs(hookargs))
1432 **pycompat.strkwargs(hookargs))
1433 reporef()._afterlock(hookfunc)
1433 reporef()._afterlock(hookfunc)
1434 tr.addfinalize('txnclose-hook', txnclosehook)
1434 tr.addfinalize('txnclose-hook', txnclosehook)
1435 # Include a leading "-" to make it happen before the transaction summary
1435 # Include a leading "-" to make it happen before the transaction summary
1436 # reports registered via scmutil.registersummarycallback() whose names
1436 # reports registered via scmutil.registersummarycallback() whose names
1437 # are 00-txnreport etc. That way, the caches will be warm when the
1437 # are 00-txnreport etc. That way, the caches will be warm when the
1438 # callbacks run.
1438 # callbacks run.
1439 tr.addpostclose('-warm-cache', self._buildcacheupdater(tr))
1439 tr.addpostclose('-warm-cache', self._buildcacheupdater(tr))
1440 def txnaborthook(tr2):
1440 def txnaborthook(tr2):
1441 """To be run if transaction is aborted
1441 """To be run if transaction is aborted
1442 """
1442 """
1443 reporef().hook('txnabort', throw=False, txnname=desc,
1443 reporef().hook('txnabort', throw=False, txnname=desc,
1444 **pycompat.strkwargs(tr2.hookargs))
1444 **pycompat.strkwargs(tr2.hookargs))
1445 tr.addabort('txnabort-hook', txnaborthook)
1445 tr.addabort('txnabort-hook', txnaborthook)
1446 # avoid eager cache invalidation. in-memory data should be identical
1446 # avoid eager cache invalidation. in-memory data should be identical
1447 # to stored data if transaction has no error.
1447 # to stored data if transaction has no error.
1448 tr.addpostclose('refresh-filecachestats', self._refreshfilecachestats)
1448 tr.addpostclose('refresh-filecachestats', self._refreshfilecachestats)
1449 self._transref = weakref.ref(tr)
1449 self._transref = weakref.ref(tr)
1450 scmutil.registersummarycallback(self, tr, desc)
1450 scmutil.registersummarycallback(self, tr, desc)
1451 return tr
1451 return tr
1452
1452
1453 def _journalfiles(self):
1453 def _journalfiles(self):
1454 return ((self.svfs, 'journal'),
1454 return ((self.svfs, 'journal'),
1455 (self.vfs, 'journal.dirstate'),
1455 (self.vfs, 'journal.dirstate'),
1456 (self.vfs, 'journal.branch'),
1456 (self.vfs, 'journal.branch'),
1457 (self.vfs, 'journal.desc'),
1457 (self.vfs, 'journal.desc'),
1458 (self.vfs, 'journal.bookmarks'),
1458 (self.vfs, 'journal.bookmarks'),
1459 (self.svfs, 'journal.phaseroots'))
1459 (self.svfs, 'journal.phaseroots'))
1460
1460
1461 def undofiles(self):
1461 def undofiles(self):
1462 return [(vfs, undoname(x)) for vfs, x in self._journalfiles()]
1462 return [(vfs, undoname(x)) for vfs, x in self._journalfiles()]
1463
1463
1464 @unfilteredmethod
1464 @unfilteredmethod
1465 def _writejournal(self, desc):
1465 def _writejournal(self, desc):
1466 self.dirstate.savebackup(None, 'journal.dirstate')
1466 self.dirstate.savebackup(None, 'journal.dirstate')
1467 narrowspec.savebackup(self, 'journal.narrowspec')
1467 narrowspec.savebackup(self, 'journal.narrowspec')
1468 self.vfs.write("journal.branch",
1468 self.vfs.write("journal.branch",
1469 encoding.fromlocal(self.dirstate.branch()))
1469 encoding.fromlocal(self.dirstate.branch()))
1470 self.vfs.write("journal.desc",
1470 self.vfs.write("journal.desc",
1471 "%d\n%s\n" % (len(self), desc))
1471 "%d\n%s\n" % (len(self), desc))
1472 self.vfs.write("journal.bookmarks",
1472 self.vfs.write("journal.bookmarks",
1473 self.vfs.tryread("bookmarks"))
1473 self.vfs.tryread("bookmarks"))
1474 self.svfs.write("journal.phaseroots",
1474 self.svfs.write("journal.phaseroots",
1475 self.svfs.tryread("phaseroots"))
1475 self.svfs.tryread("phaseroots"))
1476
1476
1477 def recover(self):
1477 def recover(self):
1478 with self.lock():
1478 with self.lock():
1479 if self.svfs.exists("journal"):
1479 if self.svfs.exists("journal"):
1480 self.ui.status(_("rolling back interrupted transaction\n"))
1480 self.ui.status(_("rolling back interrupted transaction\n"))
1481 vfsmap = {'': self.svfs,
1481 vfsmap = {'': self.svfs,
1482 'plain': self.vfs,}
1482 'plain': self.vfs,}
1483 transaction.rollback(self.svfs, vfsmap, "journal",
1483 transaction.rollback(self.svfs, vfsmap, "journal",
1484 self.ui.warn,
1484 self.ui.warn,
1485 checkambigfiles=_cachedfiles)
1485 checkambigfiles=_cachedfiles)
1486 self.invalidate()
1486 self.invalidate()
1487 return True
1487 return True
1488 else:
1488 else:
1489 self.ui.warn(_("no interrupted transaction available\n"))
1489 self.ui.warn(_("no interrupted transaction available\n"))
1490 return False
1490 return False
1491
1491
1492 def rollback(self, dryrun=False, force=False):
1492 def rollback(self, dryrun=False, force=False):
1493 wlock = lock = dsguard = None
1493 wlock = lock = dsguard = None
1494 try:
1494 try:
1495 wlock = self.wlock()
1495 wlock = self.wlock()
1496 lock = self.lock()
1496 lock = self.lock()
1497 if self.svfs.exists("undo"):
1497 if self.svfs.exists("undo"):
1498 dsguard = dirstateguard.dirstateguard(self, 'rollback')
1498 dsguard = dirstateguard.dirstateguard(self, 'rollback')
1499
1499
1500 return self._rollback(dryrun, force, dsguard)
1500 return self._rollback(dryrun, force, dsguard)
1501 else:
1501 else:
1502 self.ui.warn(_("no rollback information available\n"))
1502 self.ui.warn(_("no rollback information available\n"))
1503 return 1
1503 return 1
1504 finally:
1504 finally:
1505 release(dsguard, lock, wlock)
1505 release(dsguard, lock, wlock)
1506
1506
1507 @unfilteredmethod # Until we get smarter cache management
1507 @unfilteredmethod # Until we get smarter cache management
1508 def _rollback(self, dryrun, force, dsguard):
1508 def _rollback(self, dryrun, force, dsguard):
1509 ui = self.ui
1509 ui = self.ui
1510 try:
1510 try:
1511 args = self.vfs.read('undo.desc').splitlines()
1511 args = self.vfs.read('undo.desc').splitlines()
1512 (oldlen, desc, detail) = (int(args[0]), args[1], None)
1512 (oldlen, desc, detail) = (int(args[0]), args[1], None)
1513 if len(args) >= 3:
1513 if len(args) >= 3:
1514 detail = args[2]
1514 detail = args[2]
1515 oldtip = oldlen - 1
1515 oldtip = oldlen - 1
1516
1516
1517 if detail and ui.verbose:
1517 if detail and ui.verbose:
1518 msg = (_('repository tip rolled back to revision %d'
1518 msg = (_('repository tip rolled back to revision %d'
1519 ' (undo %s: %s)\n')
1519 ' (undo %s: %s)\n')
1520 % (oldtip, desc, detail))
1520 % (oldtip, desc, detail))
1521 else:
1521 else:
1522 msg = (_('repository tip rolled back to revision %d'
1522 msg = (_('repository tip rolled back to revision %d'
1523 ' (undo %s)\n')
1523 ' (undo %s)\n')
1524 % (oldtip, desc))
1524 % (oldtip, desc))
1525 except IOError:
1525 except IOError:
1526 msg = _('rolling back unknown transaction\n')
1526 msg = _('rolling back unknown transaction\n')
1527 desc = None
1527 desc = None
1528
1528
1529 if not force and self['.'] != self['tip'] and desc == 'commit':
1529 if not force and self['.'] != self['tip'] and desc == 'commit':
1530 raise error.Abort(
1530 raise error.Abort(
1531 _('rollback of last commit while not checked out '
1531 _('rollback of last commit while not checked out '
1532 'may lose data'), hint=_('use -f to force'))
1532 'may lose data'), hint=_('use -f to force'))
1533
1533
1534 ui.status(msg)
1534 ui.status(msg)
1535 if dryrun:
1535 if dryrun:
1536 return 0
1536 return 0
1537
1537
1538 parents = self.dirstate.parents()
1538 parents = self.dirstate.parents()
1539 self.destroying()
1539 self.destroying()
1540 vfsmap = {'plain': self.vfs, '': self.svfs}
1540 vfsmap = {'plain': self.vfs, '': self.svfs}
1541 transaction.rollback(self.svfs, vfsmap, 'undo', ui.warn,
1541 transaction.rollback(self.svfs, vfsmap, 'undo', ui.warn,
1542 checkambigfiles=_cachedfiles)
1542 checkambigfiles=_cachedfiles)
1543 if self.vfs.exists('undo.bookmarks'):
1543 if self.vfs.exists('undo.bookmarks'):
1544 self.vfs.rename('undo.bookmarks', 'bookmarks', checkambig=True)
1544 self.vfs.rename('undo.bookmarks', 'bookmarks', checkambig=True)
1545 if self.svfs.exists('undo.phaseroots'):
1545 if self.svfs.exists('undo.phaseroots'):
1546 self.svfs.rename('undo.phaseroots', 'phaseroots', checkambig=True)
1546 self.svfs.rename('undo.phaseroots', 'phaseroots', checkambig=True)
1547 self.invalidate()
1547 self.invalidate()
1548
1548
1549 parentgone = (parents[0] not in self.changelog.nodemap or
1549 parentgone = (parents[0] not in self.changelog.nodemap or
1550 parents[1] not in self.changelog.nodemap)
1550 parents[1] not in self.changelog.nodemap)
1551 if parentgone:
1551 if parentgone:
1552 # prevent dirstateguard from overwriting already restored one
1552 # prevent dirstateguard from overwriting already restored one
1553 dsguard.close()
1553 dsguard.close()
1554
1554
1555 narrowspec.restorebackup(self, 'undo.narrowspec')
1555 narrowspec.restorebackup(self, 'undo.narrowspec')
1556 self.dirstate.restorebackup(None, 'undo.dirstate')
1556 self.dirstate.restorebackup(None, 'undo.dirstate')
1557 try:
1557 try:
1558 branch = self.vfs.read('undo.branch')
1558 branch = self.vfs.read('undo.branch')
1559 self.dirstate.setbranch(encoding.tolocal(branch))
1559 self.dirstate.setbranch(encoding.tolocal(branch))
1560 except IOError:
1560 except IOError:
1561 ui.warn(_('named branch could not be reset: '
1561 ui.warn(_('named branch could not be reset: '
1562 'current branch is still \'%s\'\n')
1562 'current branch is still \'%s\'\n')
1563 % self.dirstate.branch())
1563 % self.dirstate.branch())
1564
1564
1565 parents = tuple([p.rev() for p in self[None].parents()])
1565 parents = tuple([p.rev() for p in self[None].parents()])
1566 if len(parents) > 1:
1566 if len(parents) > 1:
1567 ui.status(_('working directory now based on '
1567 ui.status(_('working directory now based on '
1568 'revisions %d and %d\n') % parents)
1568 'revisions %d and %d\n') % parents)
1569 else:
1569 else:
1570 ui.status(_('working directory now based on '
1570 ui.status(_('working directory now based on '
1571 'revision %d\n') % parents)
1571 'revision %d\n') % parents)
1572 mergemod.mergestate.clean(self, self['.'].node())
1572 mergemod.mergestate.clean(self, self['.'].node())
1573
1573
1574 # TODO: if we know which new heads may result from this rollback, pass
1574 # TODO: if we know which new heads may result from this rollback, pass
1575 # them to destroy(), which will prevent the branchhead cache from being
1575 # them to destroy(), which will prevent the branchhead cache from being
1576 # invalidated.
1576 # invalidated.
1577 self.destroyed()
1577 self.destroyed()
1578 return 0
1578 return 0
1579
1579
1580 def _buildcacheupdater(self, newtransaction):
1580 def _buildcacheupdater(self, newtransaction):
1581 """called during transaction to build the callback updating cache
1581 """called during transaction to build the callback updating cache
1582
1582
1583 Lives on the repository to help extension who might want to augment
1583 Lives on the repository to help extension who might want to augment
1584 this logic. For this purpose, the created transaction is passed to the
1584 this logic. For this purpose, the created transaction is passed to the
1585 method.
1585 method.
1586 """
1586 """
1587 # we must avoid cyclic reference between repo and transaction.
1587 # we must avoid cyclic reference between repo and transaction.
1588 reporef = weakref.ref(self)
1588 reporef = weakref.ref(self)
1589 def updater(tr):
1589 def updater(tr):
1590 repo = reporef()
1590 repo = reporef()
1591 repo.updatecaches(tr)
1591 repo.updatecaches(tr)
1592 return updater
1592 return updater
1593
1593
1594 @unfilteredmethod
1594 @unfilteredmethod
1595 def updatecaches(self, tr=None, full=False):
1595 def updatecaches(self, tr=None, full=False):
1596 """warm appropriate caches
1596 """warm appropriate caches
1597
1597
1598 If this function is called after a transaction closed. The transaction
1598 If this function is called after a transaction closed. The transaction
1599 will be available in the 'tr' argument. This can be used to selectively
1599 will be available in the 'tr' argument. This can be used to selectively
1600 update caches relevant to the changes in that transaction.
1600 update caches relevant to the changes in that transaction.
1601
1601
1602 If 'full' is set, make sure all caches the function knows about have
1602 If 'full' is set, make sure all caches the function knows about have
1603 up-to-date data. Even the ones usually loaded more lazily.
1603 up-to-date data. Even the ones usually loaded more lazily.
1604 """
1604 """
1605 if tr is not None and tr.hookargs.get('source') == 'strip':
1605 if tr is not None and tr.hookargs.get('source') == 'strip':
1606 # During strip, many caches are invalid but
1606 # During strip, many caches are invalid but
1607 # later call to `destroyed` will refresh them.
1607 # later call to `destroyed` will refresh them.
1608 return
1608 return
1609
1609
1610 if tr is None or tr.changes['origrepolen'] < len(self):
1610 if tr is None or tr.changes['origrepolen'] < len(self):
1611 # updating the unfiltered branchmap should refresh all the others,
1611 # updating the unfiltered branchmap should refresh all the others,
1612 self.ui.debug('updating the branch cache\n')
1612 self.ui.debug('updating the branch cache\n')
1613 branchmap.updatecache(self.filtered('served'))
1613 branchmap.updatecache(self.filtered('served'))
1614
1614
1615 if full:
1615 if full:
1616 rbc = self.revbranchcache()
1616 rbc = self.revbranchcache()
1617 for r in self.changelog:
1617 for r in self.changelog:
1618 rbc.branchinfo(r)
1618 rbc.branchinfo(r)
1619 rbc.write()
1619 rbc.write()
1620
1620
1621 # ensure the working copy parents are in the manifestfulltextcache
1621 # ensure the working copy parents are in the manifestfulltextcache
1622 for ctx in self['.'].parents():
1622 for ctx in self['.'].parents():
1623 ctx.manifest() # accessing the manifest is enough
1623 ctx.manifest() # accessing the manifest is enough
1624
1624
1625 def invalidatecaches(self):
1625 def invalidatecaches(self):
1626
1626
1627 if '_tagscache' in vars(self):
1627 if '_tagscache' in vars(self):
1628 # can't use delattr on proxy
1628 # can't use delattr on proxy
1629 del self.__dict__['_tagscache']
1629 del self.__dict__['_tagscache']
1630
1630
1631 self.unfiltered()._branchcaches.clear()
1631 self.unfiltered()._branchcaches.clear()
1632 self.invalidatevolatilesets()
1632 self.invalidatevolatilesets()
1633 self._sparsesignaturecache.clear()
1633 self._sparsesignaturecache.clear()
1634
1634
1635 def invalidatevolatilesets(self):
1635 def invalidatevolatilesets(self):
1636 self.filteredrevcache.clear()
1636 self.filteredrevcache.clear()
1637 obsolete.clearobscaches(self)
1637 obsolete.clearobscaches(self)
1638
1638
1639 def invalidatedirstate(self):
1639 def invalidatedirstate(self):
1640 '''Invalidates the dirstate, causing the next call to dirstate
1640 '''Invalidates the dirstate, causing the next call to dirstate
1641 to check if it was modified since the last time it was read,
1641 to check if it was modified since the last time it was read,
1642 rereading it if it has.
1642 rereading it if it has.
1643
1643
1644 This is different to dirstate.invalidate() that it doesn't always
1644 This is different to dirstate.invalidate() that it doesn't always
1645 rereads the dirstate. Use dirstate.invalidate() if you want to
1645 rereads the dirstate. Use dirstate.invalidate() if you want to
1646 explicitly read the dirstate again (i.e. restoring it to a previous
1646 explicitly read the dirstate again (i.e. restoring it to a previous
1647 known good state).'''
1647 known good state).'''
1648 if hasunfilteredcache(self, 'dirstate'):
1648 if hasunfilteredcache(self, 'dirstate'):
1649 for k in self.dirstate._filecache:
1649 for k in self.dirstate._filecache:
1650 try:
1650 try:
1651 delattr(self.dirstate, k)
1651 delattr(self.dirstate, k)
1652 except AttributeError:
1652 except AttributeError:
1653 pass
1653 pass
1654 delattr(self.unfiltered(), 'dirstate')
1654 delattr(self.unfiltered(), 'dirstate')
1655
1655
1656 def invalidate(self, clearfilecache=False):
1656 def invalidate(self, clearfilecache=False):
1657 '''Invalidates both store and non-store parts other than dirstate
1657 '''Invalidates both store and non-store parts other than dirstate
1658
1658
1659 If a transaction is running, invalidation of store is omitted,
1659 If a transaction is running, invalidation of store is omitted,
1660 because discarding in-memory changes might cause inconsistency
1660 because discarding in-memory changes might cause inconsistency
1661 (e.g. incomplete fncache causes unintentional failure, but
1661 (e.g. incomplete fncache causes unintentional failure, but
1662 redundant one doesn't).
1662 redundant one doesn't).
1663 '''
1663 '''
1664 unfiltered = self.unfiltered() # all file caches are stored unfiltered
1664 unfiltered = self.unfiltered() # all file caches are stored unfiltered
1665 for k in list(self._filecache.keys()):
1665 for k in list(self._filecache.keys()):
1666 # dirstate is invalidated separately in invalidatedirstate()
1666 # dirstate is invalidated separately in invalidatedirstate()
1667 if k == 'dirstate':
1667 if k == 'dirstate':
1668 continue
1668 continue
1669 if (k == 'changelog' and
1669 if (k == 'changelog' and
1670 self.currenttransaction() and
1670 self.currenttransaction() and
1671 self.changelog._delayed):
1671 self.changelog._delayed):
1672 # The changelog object may store unwritten revisions. We don't
1672 # The changelog object may store unwritten revisions. We don't
1673 # want to lose them.
1673 # want to lose them.
1674 # TODO: Solve the problem instead of working around it.
1674 # TODO: Solve the problem instead of working around it.
1675 continue
1675 continue
1676
1676
1677 if clearfilecache:
1677 if clearfilecache:
1678 del self._filecache[k]
1678 del self._filecache[k]
1679 try:
1679 try:
1680 delattr(unfiltered, k)
1680 delattr(unfiltered, k)
1681 except AttributeError:
1681 except AttributeError:
1682 pass
1682 pass
1683 self.invalidatecaches()
1683 self.invalidatecaches()
1684 if not self.currenttransaction():
1684 if not self.currenttransaction():
1685 # TODO: Changing contents of store outside transaction
1685 # TODO: Changing contents of store outside transaction
1686 # causes inconsistency. We should make in-memory store
1686 # causes inconsistency. We should make in-memory store
1687 # changes detectable, and abort if changed.
1687 # changes detectable, and abort if changed.
1688 self.store.invalidatecaches()
1688 self.store.invalidatecaches()
1689
1689
1690 def invalidateall(self):
1690 def invalidateall(self):
1691 '''Fully invalidates both store and non-store parts, causing the
1691 '''Fully invalidates both store and non-store parts, causing the
1692 subsequent operation to reread any outside changes.'''
1692 subsequent operation to reread any outside changes.'''
1693 # extension should hook this to invalidate its caches
1693 # extension should hook this to invalidate its caches
1694 self.invalidate()
1694 self.invalidate()
1695 self.invalidatedirstate()
1695 self.invalidatedirstate()
1696
1696
1697 @unfilteredmethod
1697 @unfilteredmethod
1698 def _refreshfilecachestats(self, tr):
1698 def _refreshfilecachestats(self, tr):
1699 """Reload stats of cached files so that they are flagged as valid"""
1699 """Reload stats of cached files so that they are flagged as valid"""
1700 for k, ce in self._filecache.items():
1700 for k, ce in self._filecache.items():
1701 k = pycompat.sysstr(k)
1701 k = pycompat.sysstr(k)
1702 if k == r'dirstate' or k not in self.__dict__:
1702 if k == r'dirstate' or k not in self.__dict__:
1703 continue
1703 continue
1704 ce.refresh()
1704 ce.refresh()
1705
1705
1706 def _lock(self, vfs, lockname, wait, releasefn, acquirefn, desc,
1706 def _lock(self, vfs, lockname, wait, releasefn, acquirefn, desc,
1707 inheritchecker=None, parentenvvar=None):
1707 inheritchecker=None, parentenvvar=None):
1708 parentlock = None
1708 parentlock = None
1709 # the contents of parentenvvar are used by the underlying lock to
1709 # the contents of parentenvvar are used by the underlying lock to
1710 # determine whether it can be inherited
1710 # determine whether it can be inherited
1711 if parentenvvar is not None:
1711 if parentenvvar is not None:
1712 parentlock = encoding.environ.get(parentenvvar)
1712 parentlock = encoding.environ.get(parentenvvar)
1713
1713
1714 timeout = 0
1714 timeout = 0
1715 warntimeout = 0
1715 warntimeout = 0
1716 if wait:
1716 if wait:
1717 timeout = self.ui.configint("ui", "timeout")
1717 timeout = self.ui.configint("ui", "timeout")
1718 warntimeout = self.ui.configint("ui", "timeout.warn")
1718 warntimeout = self.ui.configint("ui", "timeout.warn")
1719 # internal config: ui.signal-safe-lock
1719 # internal config: ui.signal-safe-lock
1720 signalsafe = self.ui.configbool('ui', 'signal-safe-lock')
1720 signalsafe = self.ui.configbool('ui', 'signal-safe-lock')
1721
1721
1722 l = lockmod.trylock(self.ui, vfs, lockname, timeout, warntimeout,
1722 l = lockmod.trylock(self.ui, vfs, lockname, timeout, warntimeout,
1723 releasefn=releasefn,
1723 releasefn=releasefn,
1724 acquirefn=acquirefn, desc=desc,
1724 acquirefn=acquirefn, desc=desc,
1725 inheritchecker=inheritchecker,
1725 inheritchecker=inheritchecker,
1726 parentlock=parentlock,
1726 parentlock=parentlock,
1727 signalsafe=signalsafe)
1727 signalsafe=signalsafe)
1728 return l
1728 return l
1729
1729
1730 def _afterlock(self, callback):
1730 def _afterlock(self, callback):
1731 """add a callback to be run when the repository is fully unlocked
1731 """add a callback to be run when the repository is fully unlocked
1732
1732
1733 The callback will be executed when the outermost lock is released
1733 The callback will be executed when the outermost lock is released
1734 (with wlock being higher level than 'lock')."""
1734 (with wlock being higher level than 'lock')."""
1735 for ref in (self._wlockref, self._lockref):
1735 for ref in (self._wlockref, self._lockref):
1736 l = ref and ref()
1736 l = ref and ref()
1737 if l and l.held:
1737 if l and l.held:
1738 l.postrelease.append(callback)
1738 l.postrelease.append(callback)
1739 break
1739 break
1740 else: # no lock have been found.
1740 else: # no lock have been found.
1741 callback()
1741 callback()
1742
1742
1743 def lock(self, wait=True):
1743 def lock(self, wait=True):
1744 '''Lock the repository store (.hg/store) and return a weak reference
1744 '''Lock the repository store (.hg/store) and return a weak reference
1745 to the lock. Use this before modifying the store (e.g. committing or
1745 to the lock. Use this before modifying the store (e.g. committing or
1746 stripping). If you are opening a transaction, get a lock as well.)
1746 stripping). If you are opening a transaction, get a lock as well.)
1747
1747
1748 If both 'lock' and 'wlock' must be acquired, ensure you always acquires
1748 If both 'lock' and 'wlock' must be acquired, ensure you always acquires
1749 'wlock' first to avoid a dead-lock hazard.'''
1749 'wlock' first to avoid a dead-lock hazard.'''
1750 l = self._currentlock(self._lockref)
1750 l = self._currentlock(self._lockref)
1751 if l is not None:
1751 if l is not None:
1752 l.lock()
1752 l.lock()
1753 return l
1753 return l
1754
1754
1755 l = self._lock(self.svfs, "lock", wait, None,
1755 l = self._lock(self.svfs, "lock", wait, None,
1756 self.invalidate, _('repository %s') % self.origroot)
1756 self.invalidate, _('repository %s') % self.origroot)
1757 self._lockref = weakref.ref(l)
1757 self._lockref = weakref.ref(l)
1758 return l
1758 return l
1759
1759
1760 def _wlockchecktransaction(self):
1760 def _wlockchecktransaction(self):
1761 if self.currenttransaction() is not None:
1761 if self.currenttransaction() is not None:
1762 raise error.LockInheritanceContractViolation(
1762 raise error.LockInheritanceContractViolation(
1763 'wlock cannot be inherited in the middle of a transaction')
1763 'wlock cannot be inherited in the middle of a transaction')
1764
1764
1765 def wlock(self, wait=True):
1765 def wlock(self, wait=True):
1766 '''Lock the non-store parts of the repository (everything under
1766 '''Lock the non-store parts of the repository (everything under
1767 .hg except .hg/store) and return a weak reference to the lock.
1767 .hg except .hg/store) and return a weak reference to the lock.
1768
1768
1769 Use this before modifying files in .hg.
1769 Use this before modifying files in .hg.
1770
1770
1771 If both 'lock' and 'wlock' must be acquired, ensure you always acquires
1771 If both 'lock' and 'wlock' must be acquired, ensure you always acquires
1772 'wlock' first to avoid a dead-lock hazard.'''
1772 'wlock' first to avoid a dead-lock hazard.'''
1773 l = self._wlockref and self._wlockref()
1773 l = self._wlockref and self._wlockref()
1774 if l is not None and l.held:
1774 if l is not None and l.held:
1775 l.lock()
1775 l.lock()
1776 return l
1776 return l
1777
1777
1778 # We do not need to check for non-waiting lock acquisition. Such
1778 # We do not need to check for non-waiting lock acquisition. Such
1779 # acquisition would not cause dead-lock as they would just fail.
1779 # acquisition would not cause dead-lock as they would just fail.
1780 if wait and (self.ui.configbool('devel', 'all-warnings')
1780 if wait and (self.ui.configbool('devel', 'all-warnings')
1781 or self.ui.configbool('devel', 'check-locks')):
1781 or self.ui.configbool('devel', 'check-locks')):
1782 if self._currentlock(self._lockref) is not None:
1782 if self._currentlock(self._lockref) is not None:
1783 self.ui.develwarn('"wlock" acquired after "lock"')
1783 self.ui.develwarn('"wlock" acquired after "lock"')
1784
1784
1785 def unlock():
1785 def unlock():
1786 if self.dirstate.pendingparentchange():
1786 if self.dirstate.pendingparentchange():
1787 self.dirstate.invalidate()
1787 self.dirstate.invalidate()
1788 else:
1788 else:
1789 self.dirstate.write(None)
1789 self.dirstate.write(None)
1790
1790
1791 self._filecache['dirstate'].refresh()
1791 self._filecache['dirstate'].refresh()
1792
1792
1793 l = self._lock(self.vfs, "wlock", wait, unlock,
1793 l = self._lock(self.vfs, "wlock", wait, unlock,
1794 self.invalidatedirstate, _('working directory of %s') %
1794 self.invalidatedirstate, _('working directory of %s') %
1795 self.origroot,
1795 self.origroot,
1796 inheritchecker=self._wlockchecktransaction,
1796 inheritchecker=self._wlockchecktransaction,
1797 parentenvvar='HG_WLOCK_LOCKER')
1797 parentenvvar='HG_WLOCK_LOCKER')
1798 self._wlockref = weakref.ref(l)
1798 self._wlockref = weakref.ref(l)
1799 return l
1799 return l
1800
1800
1801 def _currentlock(self, lockref):
1801 def _currentlock(self, lockref):
1802 """Returns the lock if it's held, or None if it's not."""
1802 """Returns the lock if it's held, or None if it's not."""
1803 if lockref is None:
1803 if lockref is None:
1804 return None
1804 return None
1805 l = lockref()
1805 l = lockref()
1806 if l is None or not l.held:
1806 if l is None or not l.held:
1807 return None
1807 return None
1808 return l
1808 return l
1809
1809
1810 def currentwlock(self):
1810 def currentwlock(self):
1811 """Returns the wlock if it's held, or None if it's not."""
1811 """Returns the wlock if it's held, or None if it's not."""
1812 return self._currentlock(self._wlockref)
1812 return self._currentlock(self._wlockref)
1813
1813
1814 def _filecommit(self, fctx, manifest1, manifest2, linkrev, tr, changelist):
1814 def _filecommit(self, fctx, manifest1, manifest2, linkrev, tr, changelist):
1815 """
1815 """
1816 commit an individual file as part of a larger transaction
1816 commit an individual file as part of a larger transaction
1817 """
1817 """
1818
1818
1819 fname = fctx.path()
1819 fname = fctx.path()
1820 fparent1 = manifest1.get(fname, nullid)
1820 fparent1 = manifest1.get(fname, nullid)
1821 fparent2 = manifest2.get(fname, nullid)
1821 fparent2 = manifest2.get(fname, nullid)
1822 if isinstance(fctx, context.filectx):
1822 if isinstance(fctx, context.filectx):
1823 node = fctx.filenode()
1823 node = fctx.filenode()
1824 if node in [fparent1, fparent2]:
1824 if node in [fparent1, fparent2]:
1825 self.ui.debug('reusing %s filelog entry\n' % fname)
1825 self.ui.debug('reusing %s filelog entry\n' % fname)
1826 if manifest1.flags(fname) != fctx.flags():
1826 if manifest1.flags(fname) != fctx.flags():
1827 changelist.append(fname)
1827 changelist.append(fname)
1828 return node
1828 return node
1829
1829
1830 flog = self.file(fname)
1830 flog = self.file(fname)
1831 meta = {}
1831 meta = {}
1832 copy = fctx.renamed()
1832 copy = fctx.renamed()
1833 if copy and copy[0] != fname:
1833 if copy and copy[0] != fname:
1834 # Mark the new revision of this file as a copy of another
1834 # Mark the new revision of this file as a copy of another
1835 # file. This copy data will effectively act as a parent
1835 # file. This copy data will effectively act as a parent
1836 # of this new revision. If this is a merge, the first
1836 # of this new revision. If this is a merge, the first
1837 # parent will be the nullid (meaning "look up the copy data")
1837 # parent will be the nullid (meaning "look up the copy data")
1838 # and the second one will be the other parent. For example:
1838 # and the second one will be the other parent. For example:
1839 #
1839 #
1840 # 0 --- 1 --- 3 rev1 changes file foo
1840 # 0 --- 1 --- 3 rev1 changes file foo
1841 # \ / rev2 renames foo to bar and changes it
1841 # \ / rev2 renames foo to bar and changes it
1842 # \- 2 -/ rev3 should have bar with all changes and
1842 # \- 2 -/ rev3 should have bar with all changes and
1843 # should record that bar descends from
1843 # should record that bar descends from
1844 # bar in rev2 and foo in rev1
1844 # bar in rev2 and foo in rev1
1845 #
1845 #
1846 # this allows this merge to succeed:
1846 # this allows this merge to succeed:
1847 #
1847 #
1848 # 0 --- 1 --- 3 rev4 reverts the content change from rev2
1848 # 0 --- 1 --- 3 rev4 reverts the content change from rev2
1849 # \ / merging rev3 and rev4 should use bar@rev2
1849 # \ / merging rev3 and rev4 should use bar@rev2
1850 # \- 2 --- 4 as the merge base
1850 # \- 2 --- 4 as the merge base
1851 #
1851 #
1852
1852
1853 cfname = copy[0]
1853 cfname = copy[0]
1854 crev = manifest1.get(cfname)
1854 crev = manifest1.get(cfname)
1855 newfparent = fparent2
1855 newfparent = fparent2
1856
1856
1857 if manifest2: # branch merge
1857 if manifest2: # branch merge
1858 if fparent2 == nullid or crev is None: # copied on remote side
1858 if fparent2 == nullid or crev is None: # copied on remote side
1859 if cfname in manifest2:
1859 if cfname in manifest2:
1860 crev = manifest2[cfname]
1860 crev = manifest2[cfname]
1861 newfparent = fparent1
1861 newfparent = fparent1
1862
1862
1863 # Here, we used to search backwards through history to try to find
1863 # Here, we used to search backwards through history to try to find
1864 # where the file copy came from if the source of a copy was not in
1864 # where the file copy came from if the source of a copy was not in
1865 # the parent directory. However, this doesn't actually make sense to
1865 # the parent directory. However, this doesn't actually make sense to
1866 # do (what does a copy from something not in your working copy even
1866 # do (what does a copy from something not in your working copy even
1867 # mean?) and it causes bugs (eg, issue4476). Instead, we will warn
1867 # mean?) and it causes bugs (eg, issue4476). Instead, we will warn
1868 # the user that copy information was dropped, so if they didn't
1868 # the user that copy information was dropped, so if they didn't
1869 # expect this outcome it can be fixed, but this is the correct
1869 # expect this outcome it can be fixed, but this is the correct
1870 # behavior in this circumstance.
1870 # behavior in this circumstance.
1871
1871
1872 if crev:
1872 if crev:
1873 self.ui.debug(" %s: copy %s:%s\n" % (fname, cfname, hex(crev)))
1873 self.ui.debug(" %s: copy %s:%s\n" % (fname, cfname, hex(crev)))
1874 meta["copy"] = cfname
1874 meta["copy"] = cfname
1875 meta["copyrev"] = hex(crev)
1875 meta["copyrev"] = hex(crev)
1876 fparent1, fparent2 = nullid, newfparent
1876 fparent1, fparent2 = nullid, newfparent
1877 else:
1877 else:
1878 self.ui.warn(_("warning: can't find ancestor for '%s' "
1878 self.ui.warn(_("warning: can't find ancestor for '%s' "
1879 "copied from '%s'!\n") % (fname, cfname))
1879 "copied from '%s'!\n") % (fname, cfname))
1880
1880
1881 elif fparent1 == nullid:
1881 elif fparent1 == nullid:
1882 fparent1, fparent2 = fparent2, nullid
1882 fparent1, fparent2 = fparent2, nullid
1883 elif fparent2 != nullid:
1883 elif fparent2 != nullid:
1884 # is one parent an ancestor of the other?
1884 # is one parent an ancestor of the other?
1885 fparentancestors = flog.commonancestorsheads(fparent1, fparent2)
1885 fparentancestors = flog.commonancestorsheads(fparent1, fparent2)
1886 if fparent1 in fparentancestors:
1886 if fparent1 in fparentancestors:
1887 fparent1, fparent2 = fparent2, nullid
1887 fparent1, fparent2 = fparent2, nullid
1888 elif fparent2 in fparentancestors:
1888 elif fparent2 in fparentancestors:
1889 fparent2 = nullid
1889 fparent2 = nullid
1890
1890
1891 # is the file changed?
1891 # is the file changed?
1892 text = fctx.data()
1892 text = fctx.data()
1893 if fparent2 != nullid or flog.cmp(fparent1, text) or meta:
1893 if fparent2 != nullid or flog.cmp(fparent1, text) or meta:
1894 changelist.append(fname)
1894 changelist.append(fname)
1895 return flog.add(text, meta, tr, linkrev, fparent1, fparent2)
1895 return flog.add(text, meta, tr, linkrev, fparent1, fparent2)
1896 # are just the flags changed during merge?
1896 # are just the flags changed during merge?
1897 elif fname in manifest1 and manifest1.flags(fname) != fctx.flags():
1897 elif fname in manifest1 and manifest1.flags(fname) != fctx.flags():
1898 changelist.append(fname)
1898 changelist.append(fname)
1899
1899
1900 return fparent1
1900 return fparent1
1901
1901
1902 def checkcommitpatterns(self, wctx, vdirs, match, status, fail):
1902 def checkcommitpatterns(self, wctx, vdirs, match, status, fail):
1903 """check for commit arguments that aren't committable"""
1903 """check for commit arguments that aren't committable"""
1904 if match.isexact() or match.prefix():
1904 if match.isexact() or match.prefix():
1905 matched = set(status.modified + status.added + status.removed)
1905 matched = set(status.modified + status.added + status.removed)
1906
1906
1907 for f in match.files():
1907 for f in match.files():
1908 f = self.dirstate.normalize(f)
1908 f = self.dirstate.normalize(f)
1909 if f == '.' or f in matched or f in wctx.substate:
1909 if f == '.' or f in matched or f in wctx.substate:
1910 continue
1910 continue
1911 if f in status.deleted:
1911 if f in status.deleted:
1912 fail(f, _('file not found!'))
1912 fail(f, _('file not found!'))
1913 if f in vdirs: # visited directory
1913 if f in vdirs: # visited directory
1914 d = f + '/'
1914 d = f + '/'
1915 for mf in matched:
1915 for mf in matched:
1916 if mf.startswith(d):
1916 if mf.startswith(d):
1917 break
1917 break
1918 else:
1918 else:
1919 fail(f, _("no match under directory!"))
1919 fail(f, _("no match under directory!"))
1920 elif f not in self.dirstate:
1920 elif f not in self.dirstate:
1921 fail(f, _("file not tracked!"))
1921 fail(f, _("file not tracked!"))
1922
1922
1923 @unfilteredmethod
1923 @unfilteredmethod
1924 def commit(self, text="", user=None, date=None, match=None, force=False,
1924 def commit(self, text="", user=None, date=None, match=None, force=False,
1925 editor=False, extra=None):
1925 editor=False, extra=None):
1926 """Add a new revision to current repository.
1926 """Add a new revision to current repository.
1927
1927
1928 Revision information is gathered from the working directory,
1928 Revision information is gathered from the working directory,
1929 match can be used to filter the committed files. If editor is
1929 match can be used to filter the committed files. If editor is
1930 supplied, it is called to get a commit message.
1930 supplied, it is called to get a commit message.
1931 """
1931 """
1932 if extra is None:
1932 if extra is None:
1933 extra = {}
1933 extra = {}
1934
1934
1935 def fail(f, msg):
1935 def fail(f, msg):
1936 raise error.Abort('%s: %s' % (f, msg))
1936 raise error.Abort('%s: %s' % (f, msg))
1937
1937
1938 if not match:
1938 if not match:
1939 match = matchmod.always(self.root, '')
1939 match = matchmod.always(self.root, '')
1940
1940
1941 if not force:
1941 if not force:
1942 vdirs = []
1942 vdirs = []
1943 match.explicitdir = vdirs.append
1943 match.explicitdir = vdirs.append
1944 match.bad = fail
1944 match.bad = fail
1945
1945
1946 wlock = lock = tr = None
1946 wlock = lock = tr = None
1947 try:
1947 try:
1948 wlock = self.wlock()
1948 wlock = self.wlock()
1949 lock = self.lock() # for recent changelog (see issue4368)
1949 lock = self.lock() # for recent changelog (see issue4368)
1950
1950
1951 wctx = self[None]
1951 wctx = self[None]
1952 merge = len(wctx.parents()) > 1
1952 merge = len(wctx.parents()) > 1
1953
1953
1954 if not force and merge and not match.always():
1954 if not force and merge and not match.always():
1955 raise error.Abort(_('cannot partially commit a merge '
1955 raise error.Abort(_('cannot partially commit a merge '
1956 '(do not specify files or patterns)'))
1956 '(do not specify files or patterns)'))
1957
1957
1958 status = self.status(match=match, clean=force)
1958 status = self.status(match=match, clean=force)
1959 if force:
1959 if force:
1960 status.modified.extend(status.clean) # mq may commit clean files
1960 status.modified.extend(status.clean) # mq may commit clean files
1961
1961
1962 # check subrepos
1962 # check subrepos
1963 subs, commitsubs, newstate = subrepoutil.precommit(
1963 subs, commitsubs, newstate = subrepoutil.precommit(
1964 self.ui, wctx, status, match, force=force)
1964 self.ui, wctx, status, match, force=force)
1965
1965
1966 # make sure all explicit patterns are matched
1966 # make sure all explicit patterns are matched
1967 if not force:
1967 if not force:
1968 self.checkcommitpatterns(wctx, vdirs, match, status, fail)
1968 self.checkcommitpatterns(wctx, vdirs, match, status, fail)
1969
1969
1970 cctx = context.workingcommitctx(self, status,
1970 cctx = context.workingcommitctx(self, status,
1971 text, user, date, extra)
1971 text, user, date, extra)
1972
1972
1973 # internal config: ui.allowemptycommit
1973 # internal config: ui.allowemptycommit
1974 allowemptycommit = (wctx.branch() != wctx.p1().branch()
1974 allowemptycommit = (wctx.branch() != wctx.p1().branch()
1975 or extra.get('close') or merge or cctx.files()
1975 or extra.get('close') or merge or cctx.files()
1976 or self.ui.configbool('ui', 'allowemptycommit'))
1976 or self.ui.configbool('ui', 'allowemptycommit'))
1977 if not allowemptycommit:
1977 if not allowemptycommit:
1978 return None
1978 return None
1979
1979
1980 if merge and cctx.deleted():
1980 if merge and cctx.deleted():
1981 raise error.Abort(_("cannot commit merge with missing files"))
1981 raise error.Abort(_("cannot commit merge with missing files"))
1982
1982
1983 ms = mergemod.mergestate.read(self)
1983 ms = mergemod.mergestate.read(self)
1984 mergeutil.checkunresolved(ms)
1984 mergeutil.checkunresolved(ms)
1985
1985
1986 if editor:
1986 if editor:
1987 cctx._text = editor(self, cctx, subs)
1987 cctx._text = editor(self, cctx, subs)
1988 edited = (text != cctx._text)
1988 edited = (text != cctx._text)
1989
1989
1990 # Save commit message in case this transaction gets rolled back
1990 # Save commit message in case this transaction gets rolled back
1991 # (e.g. by a pretxncommit hook). Leave the content alone on
1991 # (e.g. by a pretxncommit hook). Leave the content alone on
1992 # the assumption that the user will use the same editor again.
1992 # the assumption that the user will use the same editor again.
1993 msgfn = self.savecommitmessage(cctx._text)
1993 msgfn = self.savecommitmessage(cctx._text)
1994
1994
1995 # commit subs and write new state
1995 # commit subs and write new state
1996 if subs:
1996 if subs:
1997 for s in sorted(commitsubs):
1997 for s in sorted(commitsubs):
1998 sub = wctx.sub(s)
1998 sub = wctx.sub(s)
1999 self.ui.status(_('committing subrepository %s\n') %
1999 self.ui.status(_('committing subrepository %s\n') %
2000 subrepoutil.subrelpath(sub))
2000 subrepoutil.subrelpath(sub))
2001 sr = sub.commit(cctx._text, user, date)
2001 sr = sub.commit(cctx._text, user, date)
2002 newstate[s] = (newstate[s][0], sr)
2002 newstate[s] = (newstate[s][0], sr)
2003 subrepoutil.writestate(self, newstate)
2003 subrepoutil.writestate(self, newstate)
2004
2004
2005 p1, p2 = self.dirstate.parents()
2005 p1, p2 = self.dirstate.parents()
2006 hookp1, hookp2 = hex(p1), (p2 != nullid and hex(p2) or '')
2006 hookp1, hookp2 = hex(p1), (p2 != nullid and hex(p2) or '')
2007 try:
2007 try:
2008 self.hook("precommit", throw=True, parent1=hookp1,
2008 self.hook("precommit", throw=True, parent1=hookp1,
2009 parent2=hookp2)
2009 parent2=hookp2)
2010 tr = self.transaction('commit')
2010 tr = self.transaction('commit')
2011 ret = self.commitctx(cctx, True)
2011 ret = self.commitctx(cctx, True)
2012 except: # re-raises
2012 except: # re-raises
2013 if edited:
2013 if edited:
2014 self.ui.write(
2014 self.ui.write(
2015 _('note: commit message saved in %s\n') % msgfn)
2015 _('note: commit message saved in %s\n') % msgfn)
2016 raise
2016 raise
2017 # update bookmarks, dirstate and mergestate
2017 # update bookmarks, dirstate and mergestate
2018 bookmarks.update(self, [p1, p2], ret)
2018 bookmarks.update(self, [p1, p2], ret)
2019 cctx.markcommitted(ret)
2019 cctx.markcommitted(ret)
2020 ms.reset()
2020 ms.reset()
2021 tr.close()
2021 tr.close()
2022
2022
2023 finally:
2023 finally:
2024 lockmod.release(tr, lock, wlock)
2024 lockmod.release(tr, lock, wlock)
2025
2025
2026 def commithook(node=hex(ret), parent1=hookp1, parent2=hookp2):
2026 def commithook(node=hex(ret), parent1=hookp1, parent2=hookp2):
2027 # hack for command that use a temporary commit (eg: histedit)
2027 # hack for command that use a temporary commit (eg: histedit)
2028 # temporary commit got stripped before hook release
2028 # temporary commit got stripped before hook release
2029 if self.changelog.hasnode(ret):
2029 if self.changelog.hasnode(ret):
2030 self.hook("commit", node=node, parent1=parent1,
2030 self.hook("commit", node=node, parent1=parent1,
2031 parent2=parent2)
2031 parent2=parent2)
2032 self._afterlock(commithook)
2032 self._afterlock(commithook)
2033 return ret
2033 return ret
2034
2034
2035 @unfilteredmethod
2035 @unfilteredmethod
2036 def commitctx(self, ctx, error=False):
2036 def commitctx(self, ctx, error=False):
2037 """Add a new revision to current repository.
2037 """Add a new revision to current repository.
2038 Revision information is passed via the context argument.
2038 Revision information is passed via the context argument.
2039
2039
2040 ctx.files() should list all files involved in this commit, i.e.
2040 ctx.files() should list all files involved in this commit, i.e.
2041 modified/added/removed files. On merge, it may be wider than the
2041 modified/added/removed files. On merge, it may be wider than the
2042 ctx.files() to be committed, since any file nodes derived directly
2042 ctx.files() to be committed, since any file nodes derived directly
2043 from p1 or p2 are excluded from the committed ctx.files().
2043 from p1 or p2 are excluded from the committed ctx.files().
2044 """
2044 """
2045
2045
2046 tr = None
2046 tr = None
2047 p1, p2 = ctx.p1(), ctx.p2()
2047 p1, p2 = ctx.p1(), ctx.p2()
2048 user = ctx.user()
2048 user = ctx.user()
2049
2049
2050 lock = self.lock()
2050 lock = self.lock()
2051 try:
2051 try:
2052 tr = self.transaction("commit")
2052 tr = self.transaction("commit")
2053 trp = weakref.proxy(tr)
2053 trp = weakref.proxy(tr)
2054
2054
2055 if ctx.manifestnode():
2055 if ctx.manifestnode():
2056 # reuse an existing manifest revision
2056 # reuse an existing manifest revision
2057 self.ui.debug('reusing known manifest\n')
2057 self.ui.debug('reusing known manifest\n')
2058 mn = ctx.manifestnode()
2058 mn = ctx.manifestnode()
2059 files = ctx.files()
2059 files = ctx.files()
2060 elif ctx.files():
2060 elif ctx.files():
2061 m1ctx = p1.manifestctx()
2061 m1ctx = p1.manifestctx()
2062 m2ctx = p2.manifestctx()
2062 m2ctx = p2.manifestctx()
2063 mctx = m1ctx.copy()
2063 mctx = m1ctx.copy()
2064
2064
2065 m = mctx.read()
2065 m = mctx.read()
2066 m1 = m1ctx.read()
2066 m1 = m1ctx.read()
2067 m2 = m2ctx.read()
2067 m2 = m2ctx.read()
2068
2068
2069 # check in files
2069 # check in files
2070 added = []
2070 added = []
2071 changed = []
2071 changed = []
2072 removed = list(ctx.removed())
2072 removed = list(ctx.removed())
2073 linkrev = len(self)
2073 linkrev = len(self)
2074 self.ui.note(_("committing files:\n"))
2074 self.ui.note(_("committing files:\n"))
2075 for f in sorted(ctx.modified() + ctx.added()):
2075 for f in sorted(ctx.modified() + ctx.added()):
2076 self.ui.note(f + "\n")
2076 self.ui.note(f + "\n")
2077 try:
2077 try:
2078 fctx = ctx[f]
2078 fctx = ctx[f]
2079 if fctx is None:
2079 if fctx is None:
2080 removed.append(f)
2080 removed.append(f)
2081 else:
2081 else:
2082 added.append(f)
2082 added.append(f)
2083 m[f] = self._filecommit(fctx, m1, m2, linkrev,
2083 m[f] = self._filecommit(fctx, m1, m2, linkrev,
2084 trp, changed)
2084 trp, changed)
2085 m.setflag(f, fctx.flags())
2085 m.setflag(f, fctx.flags())
2086 except OSError as inst:
2086 except OSError as inst:
2087 self.ui.warn(_("trouble committing %s!\n") % f)
2087 self.ui.warn(_("trouble committing %s!\n") % f)
2088 raise
2088 raise
2089 except IOError as inst:
2089 except IOError as inst:
2090 errcode = getattr(inst, 'errno', errno.ENOENT)
2090 errcode = getattr(inst, 'errno', errno.ENOENT)
2091 if error or errcode and errcode != errno.ENOENT:
2091 if error or errcode and errcode != errno.ENOENT:
2092 self.ui.warn(_("trouble committing %s!\n") % f)
2092 self.ui.warn(_("trouble committing %s!\n") % f)
2093 raise
2093 raise
2094
2094
2095 # update manifest
2095 # update manifest
2096 removed = [f for f in sorted(removed) if f in m1 or f in m2]
2096 removed = [f for f in sorted(removed) if f in m1 or f in m2]
2097 drop = [f for f in removed if f in m]
2097 drop = [f for f in removed if f in m]
2098 for f in drop:
2098 for f in drop:
2099 del m[f]
2099 del m[f]
2100 files = changed + removed
2100 files = changed + removed
2101 md = None
2101 md = None
2102 if not files:
2102 if not files:
2103 # if no "files" actually changed in terms of the changelog,
2103 # if no "files" actually changed in terms of the changelog,
2104 # try hard to detect unmodified manifest entry so that the
2104 # try hard to detect unmodified manifest entry so that the
2105 # exact same commit can be reproduced later on convert.
2105 # exact same commit can be reproduced later on convert.
2106 md = m1.diff(m, scmutil.matchfiles(self, ctx.files()))
2106 md = m1.diff(m, scmutil.matchfiles(self, ctx.files()))
2107 if not files and md:
2107 if not files and md:
2108 self.ui.debug('not reusing manifest (no file change in '
2108 self.ui.debug('not reusing manifest (no file change in '
2109 'changelog, but manifest differs)\n')
2109 'changelog, but manifest differs)\n')
2110 if files or md:
2110 if files or md:
2111 self.ui.note(_("committing manifest\n"))
2111 self.ui.note(_("committing manifest\n"))
2112 # we're using narrowmatch here since it's already applied at
2113 # other stages (such as dirstate.walk), so we're already
2114 # ignoring things outside of narrowspec in most cases. The
2115 # one case where we might have files outside the narrowspec
2116 # at this point is merges, and we already error out in the
2117 # case where the merge has files outside of the narrowspec,
2118 # so this is safe.
2112 mn = mctx.write(trp, linkrev,
2119 mn = mctx.write(trp, linkrev,
2113 p1.manifestnode(), p2.manifestnode(),
2120 p1.manifestnode(), p2.manifestnode(),
2114 added, drop)
2121 added, drop, match=self.narrowmatch())
2115 else:
2122 else:
2116 self.ui.debug('reusing manifest form p1 (listed files '
2123 self.ui.debug('reusing manifest form p1 (listed files '
2117 'actually unchanged)\n')
2124 'actually unchanged)\n')
2118 mn = p1.manifestnode()
2125 mn = p1.manifestnode()
2119 else:
2126 else:
2120 self.ui.debug('reusing manifest from p1 (no file change)\n')
2127 self.ui.debug('reusing manifest from p1 (no file change)\n')
2121 mn = p1.manifestnode()
2128 mn = p1.manifestnode()
2122 files = []
2129 files = []
2123
2130
2124 # update changelog
2131 # update changelog
2125 self.ui.note(_("committing changelog\n"))
2132 self.ui.note(_("committing changelog\n"))
2126 self.changelog.delayupdate(tr)
2133 self.changelog.delayupdate(tr)
2127 n = self.changelog.add(mn, files, ctx.description(),
2134 n = self.changelog.add(mn, files, ctx.description(),
2128 trp, p1.node(), p2.node(),
2135 trp, p1.node(), p2.node(),
2129 user, ctx.date(), ctx.extra().copy())
2136 user, ctx.date(), ctx.extra().copy())
2130 xp1, xp2 = p1.hex(), p2 and p2.hex() or ''
2137 xp1, xp2 = p1.hex(), p2 and p2.hex() or ''
2131 self.hook('pretxncommit', throw=True, node=hex(n), parent1=xp1,
2138 self.hook('pretxncommit', throw=True, node=hex(n), parent1=xp1,
2132 parent2=xp2)
2139 parent2=xp2)
2133 # set the new commit is proper phase
2140 # set the new commit is proper phase
2134 targetphase = subrepoutil.newcommitphase(self.ui, ctx)
2141 targetphase = subrepoutil.newcommitphase(self.ui, ctx)
2135 if targetphase:
2142 if targetphase:
2136 # retract boundary do not alter parent changeset.
2143 # retract boundary do not alter parent changeset.
2137 # if a parent have higher the resulting phase will
2144 # if a parent have higher the resulting phase will
2138 # be compliant anyway
2145 # be compliant anyway
2139 #
2146 #
2140 # if minimal phase was 0 we don't need to retract anything
2147 # if minimal phase was 0 we don't need to retract anything
2141 phases.registernew(self, tr, targetphase, [n])
2148 phases.registernew(self, tr, targetphase, [n])
2142 tr.close()
2149 tr.close()
2143 return n
2150 return n
2144 finally:
2151 finally:
2145 if tr:
2152 if tr:
2146 tr.release()
2153 tr.release()
2147 lock.release()
2154 lock.release()
2148
2155
2149 @unfilteredmethod
2156 @unfilteredmethod
2150 def destroying(self):
2157 def destroying(self):
2151 '''Inform the repository that nodes are about to be destroyed.
2158 '''Inform the repository that nodes are about to be destroyed.
2152 Intended for use by strip and rollback, so there's a common
2159 Intended for use by strip and rollback, so there's a common
2153 place for anything that has to be done before destroying history.
2160 place for anything that has to be done before destroying history.
2154
2161
2155 This is mostly useful for saving state that is in memory and waiting
2162 This is mostly useful for saving state that is in memory and waiting
2156 to be flushed when the current lock is released. Because a call to
2163 to be flushed when the current lock is released. Because a call to
2157 destroyed is imminent, the repo will be invalidated causing those
2164 destroyed is imminent, the repo will be invalidated causing those
2158 changes to stay in memory (waiting for the next unlock), or vanish
2165 changes to stay in memory (waiting for the next unlock), or vanish
2159 completely.
2166 completely.
2160 '''
2167 '''
2161 # When using the same lock to commit and strip, the phasecache is left
2168 # When using the same lock to commit and strip, the phasecache is left
2162 # dirty after committing. Then when we strip, the repo is invalidated,
2169 # dirty after committing. Then when we strip, the repo is invalidated,
2163 # causing those changes to disappear.
2170 # causing those changes to disappear.
2164 if '_phasecache' in vars(self):
2171 if '_phasecache' in vars(self):
2165 self._phasecache.write()
2172 self._phasecache.write()
2166
2173
2167 @unfilteredmethod
2174 @unfilteredmethod
2168 def destroyed(self):
2175 def destroyed(self):
2169 '''Inform the repository that nodes have been destroyed.
2176 '''Inform the repository that nodes have been destroyed.
2170 Intended for use by strip and rollback, so there's a common
2177 Intended for use by strip and rollback, so there's a common
2171 place for anything that has to be done after destroying history.
2178 place for anything that has to be done after destroying history.
2172 '''
2179 '''
2173 # When one tries to:
2180 # When one tries to:
2174 # 1) destroy nodes thus calling this method (e.g. strip)
2181 # 1) destroy nodes thus calling this method (e.g. strip)
2175 # 2) use phasecache somewhere (e.g. commit)
2182 # 2) use phasecache somewhere (e.g. commit)
2176 #
2183 #
2177 # then 2) will fail because the phasecache contains nodes that were
2184 # then 2) will fail because the phasecache contains nodes that were
2178 # removed. We can either remove phasecache from the filecache,
2185 # removed. We can either remove phasecache from the filecache,
2179 # causing it to reload next time it is accessed, or simply filter
2186 # causing it to reload next time it is accessed, or simply filter
2180 # the removed nodes now and write the updated cache.
2187 # the removed nodes now and write the updated cache.
2181 self._phasecache.filterunknown(self)
2188 self._phasecache.filterunknown(self)
2182 self._phasecache.write()
2189 self._phasecache.write()
2183
2190
2184 # refresh all repository caches
2191 # refresh all repository caches
2185 self.updatecaches()
2192 self.updatecaches()
2186
2193
2187 # Ensure the persistent tag cache is updated. Doing it now
2194 # Ensure the persistent tag cache is updated. Doing it now
2188 # means that the tag cache only has to worry about destroyed
2195 # means that the tag cache only has to worry about destroyed
2189 # heads immediately after a strip/rollback. That in turn
2196 # heads immediately after a strip/rollback. That in turn
2190 # guarantees that "cachetip == currenttip" (comparing both rev
2197 # guarantees that "cachetip == currenttip" (comparing both rev
2191 # and node) always means no nodes have been added or destroyed.
2198 # and node) always means no nodes have been added or destroyed.
2192
2199
2193 # XXX this is suboptimal when qrefresh'ing: we strip the current
2200 # XXX this is suboptimal when qrefresh'ing: we strip the current
2194 # head, refresh the tag cache, then immediately add a new head.
2201 # head, refresh the tag cache, then immediately add a new head.
2195 # But I think doing it this way is necessary for the "instant
2202 # But I think doing it this way is necessary for the "instant
2196 # tag cache retrieval" case to work.
2203 # tag cache retrieval" case to work.
2197 self.invalidate()
2204 self.invalidate()
2198
2205
2199 def status(self, node1='.', node2=None, match=None,
2206 def status(self, node1='.', node2=None, match=None,
2200 ignored=False, clean=False, unknown=False,
2207 ignored=False, clean=False, unknown=False,
2201 listsubrepos=False):
2208 listsubrepos=False):
2202 '''a convenience method that calls node1.status(node2)'''
2209 '''a convenience method that calls node1.status(node2)'''
2203 return self[node1].status(node2, match, ignored, clean, unknown,
2210 return self[node1].status(node2, match, ignored, clean, unknown,
2204 listsubrepos)
2211 listsubrepos)
2205
2212
2206 def addpostdsstatus(self, ps):
2213 def addpostdsstatus(self, ps):
2207 """Add a callback to run within the wlock, at the point at which status
2214 """Add a callback to run within the wlock, at the point at which status
2208 fixups happen.
2215 fixups happen.
2209
2216
2210 On status completion, callback(wctx, status) will be called with the
2217 On status completion, callback(wctx, status) will be called with the
2211 wlock held, unless the dirstate has changed from underneath or the wlock
2218 wlock held, unless the dirstate has changed from underneath or the wlock
2212 couldn't be grabbed.
2219 couldn't be grabbed.
2213
2220
2214 Callbacks should not capture and use a cached copy of the dirstate --
2221 Callbacks should not capture and use a cached copy of the dirstate --
2215 it might change in the meanwhile. Instead, they should access the
2222 it might change in the meanwhile. Instead, they should access the
2216 dirstate via wctx.repo().dirstate.
2223 dirstate via wctx.repo().dirstate.
2217
2224
2218 This list is emptied out after each status run -- extensions should
2225 This list is emptied out after each status run -- extensions should
2219 make sure it adds to this list each time dirstate.status is called.
2226 make sure it adds to this list each time dirstate.status is called.
2220 Extensions should also make sure they don't call this for statuses
2227 Extensions should also make sure they don't call this for statuses
2221 that don't involve the dirstate.
2228 that don't involve the dirstate.
2222 """
2229 """
2223
2230
2224 # The list is located here for uniqueness reasons -- it is actually
2231 # The list is located here for uniqueness reasons -- it is actually
2225 # managed by the workingctx, but that isn't unique per-repo.
2232 # managed by the workingctx, but that isn't unique per-repo.
2226 self._postdsstatus.append(ps)
2233 self._postdsstatus.append(ps)
2227
2234
2228 def postdsstatus(self):
2235 def postdsstatus(self):
2229 """Used by workingctx to get the list of post-dirstate-status hooks."""
2236 """Used by workingctx to get the list of post-dirstate-status hooks."""
2230 return self._postdsstatus
2237 return self._postdsstatus
2231
2238
2232 def clearpostdsstatus(self):
2239 def clearpostdsstatus(self):
2233 """Used by workingctx to clear post-dirstate-status hooks."""
2240 """Used by workingctx to clear post-dirstate-status hooks."""
2234 del self._postdsstatus[:]
2241 del self._postdsstatus[:]
2235
2242
2236 def heads(self, start=None):
2243 def heads(self, start=None):
2237 if start is None:
2244 if start is None:
2238 cl = self.changelog
2245 cl = self.changelog
2239 headrevs = reversed(cl.headrevs())
2246 headrevs = reversed(cl.headrevs())
2240 return [cl.node(rev) for rev in headrevs]
2247 return [cl.node(rev) for rev in headrevs]
2241
2248
2242 heads = self.changelog.heads(start)
2249 heads = self.changelog.heads(start)
2243 # sort the output in rev descending order
2250 # sort the output in rev descending order
2244 return sorted(heads, key=self.changelog.rev, reverse=True)
2251 return sorted(heads, key=self.changelog.rev, reverse=True)
2245
2252
2246 def branchheads(self, branch=None, start=None, closed=False):
2253 def branchheads(self, branch=None, start=None, closed=False):
2247 '''return a (possibly filtered) list of heads for the given branch
2254 '''return a (possibly filtered) list of heads for the given branch
2248
2255
2249 Heads are returned in topological order, from newest to oldest.
2256 Heads are returned in topological order, from newest to oldest.
2250 If branch is None, use the dirstate branch.
2257 If branch is None, use the dirstate branch.
2251 If start is not None, return only heads reachable from start.
2258 If start is not None, return only heads reachable from start.
2252 If closed is True, return heads that are marked as closed as well.
2259 If closed is True, return heads that are marked as closed as well.
2253 '''
2260 '''
2254 if branch is None:
2261 if branch is None:
2255 branch = self[None].branch()
2262 branch = self[None].branch()
2256 branches = self.branchmap()
2263 branches = self.branchmap()
2257 if branch not in branches:
2264 if branch not in branches:
2258 return []
2265 return []
2259 # the cache returns heads ordered lowest to highest
2266 # the cache returns heads ordered lowest to highest
2260 bheads = list(reversed(branches.branchheads(branch, closed=closed)))
2267 bheads = list(reversed(branches.branchheads(branch, closed=closed)))
2261 if start is not None:
2268 if start is not None:
2262 # filter out the heads that cannot be reached from startrev
2269 # filter out the heads that cannot be reached from startrev
2263 fbheads = set(self.changelog.nodesbetween([start], bheads)[2])
2270 fbheads = set(self.changelog.nodesbetween([start], bheads)[2])
2264 bheads = [h for h in bheads if h in fbheads]
2271 bheads = [h for h in bheads if h in fbheads]
2265 return bheads
2272 return bheads
2266
2273
2267 def branches(self, nodes):
2274 def branches(self, nodes):
2268 if not nodes:
2275 if not nodes:
2269 nodes = [self.changelog.tip()]
2276 nodes = [self.changelog.tip()]
2270 b = []
2277 b = []
2271 for n in nodes:
2278 for n in nodes:
2272 t = n
2279 t = n
2273 while True:
2280 while True:
2274 p = self.changelog.parents(n)
2281 p = self.changelog.parents(n)
2275 if p[1] != nullid or p[0] == nullid:
2282 if p[1] != nullid or p[0] == nullid:
2276 b.append((t, n, p[0], p[1]))
2283 b.append((t, n, p[0], p[1]))
2277 break
2284 break
2278 n = p[0]
2285 n = p[0]
2279 return b
2286 return b
2280
2287
2281 def between(self, pairs):
2288 def between(self, pairs):
2282 r = []
2289 r = []
2283
2290
2284 for top, bottom in pairs:
2291 for top, bottom in pairs:
2285 n, l, i = top, [], 0
2292 n, l, i = top, [], 0
2286 f = 1
2293 f = 1
2287
2294
2288 while n != bottom and n != nullid:
2295 while n != bottom and n != nullid:
2289 p = self.changelog.parents(n)[0]
2296 p = self.changelog.parents(n)[0]
2290 if i == f:
2297 if i == f:
2291 l.append(n)
2298 l.append(n)
2292 f = f * 2
2299 f = f * 2
2293 n = p
2300 n = p
2294 i += 1
2301 i += 1
2295
2302
2296 r.append(l)
2303 r.append(l)
2297
2304
2298 return r
2305 return r
2299
2306
2300 def checkpush(self, pushop):
2307 def checkpush(self, pushop):
2301 """Extensions can override this function if additional checks have
2308 """Extensions can override this function if additional checks have
2302 to be performed before pushing, or call it if they override push
2309 to be performed before pushing, or call it if they override push
2303 command.
2310 command.
2304 """
2311 """
2305
2312
2306 @unfilteredpropertycache
2313 @unfilteredpropertycache
2307 def prepushoutgoinghooks(self):
2314 def prepushoutgoinghooks(self):
2308 """Return util.hooks consists of a pushop with repo, remote, outgoing
2315 """Return util.hooks consists of a pushop with repo, remote, outgoing
2309 methods, which are called before pushing changesets.
2316 methods, which are called before pushing changesets.
2310 """
2317 """
2311 return util.hooks()
2318 return util.hooks()
2312
2319
2313 def pushkey(self, namespace, key, old, new):
2320 def pushkey(self, namespace, key, old, new):
2314 try:
2321 try:
2315 tr = self.currenttransaction()
2322 tr = self.currenttransaction()
2316 hookargs = {}
2323 hookargs = {}
2317 if tr is not None:
2324 if tr is not None:
2318 hookargs.update(tr.hookargs)
2325 hookargs.update(tr.hookargs)
2319 hookargs = pycompat.strkwargs(hookargs)
2326 hookargs = pycompat.strkwargs(hookargs)
2320 hookargs[r'namespace'] = namespace
2327 hookargs[r'namespace'] = namespace
2321 hookargs[r'key'] = key
2328 hookargs[r'key'] = key
2322 hookargs[r'old'] = old
2329 hookargs[r'old'] = old
2323 hookargs[r'new'] = new
2330 hookargs[r'new'] = new
2324 self.hook('prepushkey', throw=True, **hookargs)
2331 self.hook('prepushkey', throw=True, **hookargs)
2325 except error.HookAbort as exc:
2332 except error.HookAbort as exc:
2326 self.ui.write_err(_("pushkey-abort: %s\n") % exc)
2333 self.ui.write_err(_("pushkey-abort: %s\n") % exc)
2327 if exc.hint:
2334 if exc.hint:
2328 self.ui.write_err(_("(%s)\n") % exc.hint)
2335 self.ui.write_err(_("(%s)\n") % exc.hint)
2329 return False
2336 return False
2330 self.ui.debug('pushing key for "%s:%s"\n' % (namespace, key))
2337 self.ui.debug('pushing key for "%s:%s"\n' % (namespace, key))
2331 ret = pushkey.push(self, namespace, key, old, new)
2338 ret = pushkey.push(self, namespace, key, old, new)
2332 def runhook():
2339 def runhook():
2333 self.hook('pushkey', namespace=namespace, key=key, old=old, new=new,
2340 self.hook('pushkey', namespace=namespace, key=key, old=old, new=new,
2334 ret=ret)
2341 ret=ret)
2335 self._afterlock(runhook)
2342 self._afterlock(runhook)
2336 return ret
2343 return ret
2337
2344
2338 def listkeys(self, namespace):
2345 def listkeys(self, namespace):
2339 self.hook('prelistkeys', throw=True, namespace=namespace)
2346 self.hook('prelistkeys', throw=True, namespace=namespace)
2340 self.ui.debug('listing keys for "%s"\n' % namespace)
2347 self.ui.debug('listing keys for "%s"\n' % namespace)
2341 values = pushkey.list(self, namespace)
2348 values = pushkey.list(self, namespace)
2342 self.hook('listkeys', namespace=namespace, values=values)
2349 self.hook('listkeys', namespace=namespace, values=values)
2343 return values
2350 return values
2344
2351
2345 def debugwireargs(self, one, two, three=None, four=None, five=None):
2352 def debugwireargs(self, one, two, three=None, four=None, five=None):
2346 '''used to test argument passing over the wire'''
2353 '''used to test argument passing over the wire'''
2347 return "%s %s %s %s %s" % (one, two, pycompat.bytestr(three),
2354 return "%s %s %s %s %s" % (one, two, pycompat.bytestr(three),
2348 pycompat.bytestr(four),
2355 pycompat.bytestr(four),
2349 pycompat.bytestr(five))
2356 pycompat.bytestr(five))
2350
2357
2351 def savecommitmessage(self, text):
2358 def savecommitmessage(self, text):
2352 fp = self.vfs('last-message.txt', 'wb')
2359 fp = self.vfs('last-message.txt', 'wb')
2353 try:
2360 try:
2354 fp.write(text)
2361 fp.write(text)
2355 finally:
2362 finally:
2356 fp.close()
2363 fp.close()
2357 return self.pathto(fp.name[len(self.root) + 1:])
2364 return self.pathto(fp.name[len(self.root) + 1:])
2358
2365
2359 # used to avoid circular references so destructors work
2366 # used to avoid circular references so destructors work
2360 def aftertrans(files):
2367 def aftertrans(files):
2361 renamefiles = [tuple(t) for t in files]
2368 renamefiles = [tuple(t) for t in files]
2362 def a():
2369 def a():
2363 for vfs, src, dest in renamefiles:
2370 for vfs, src, dest in renamefiles:
2364 # if src and dest refer to a same file, vfs.rename is a no-op,
2371 # if src and dest refer to a same file, vfs.rename is a no-op,
2365 # leaving both src and dest on disk. delete dest to make sure
2372 # leaving both src and dest on disk. delete dest to make sure
2366 # the rename couldn't be such a no-op.
2373 # the rename couldn't be such a no-op.
2367 vfs.tryunlink(dest)
2374 vfs.tryunlink(dest)
2368 try:
2375 try:
2369 vfs.rename(src, dest)
2376 vfs.rename(src, dest)
2370 except OSError: # journal file does not yet exist
2377 except OSError: # journal file does not yet exist
2371 pass
2378 pass
2372 return a
2379 return a
2373
2380
2374 def undoname(fn):
2381 def undoname(fn):
2375 base, name = os.path.split(fn)
2382 base, name = os.path.split(fn)
2376 assert name.startswith('journal')
2383 assert name.startswith('journal')
2377 return os.path.join(base, name.replace('journal', 'undo', 1))
2384 return os.path.join(base, name.replace('journal', 'undo', 1))
2378
2385
2379 def instance(ui, path, create, intents=None, createopts=None):
2386 def instance(ui, path, create, intents=None, createopts=None):
2380 localpath = util.urllocalpath(path)
2387 localpath = util.urllocalpath(path)
2381 if create:
2388 if create:
2382 createrepository(ui, localpath, createopts=createopts)
2389 createrepository(ui, localpath, createopts=createopts)
2383
2390
2384 return localrepository(ui, localpath, intents=intents)
2391 return localrepository(ui, localpath, intents=intents)
2385
2392
2386 def islocal(path):
2393 def islocal(path):
2387 return True
2394 return True
2388
2395
2389 def newreporequirements(ui, createopts=None):
2396 def newreporequirements(ui, createopts=None):
2390 """Determine the set of requirements for a new local repository.
2397 """Determine the set of requirements for a new local repository.
2391
2398
2392 Extensions can wrap this function to specify custom requirements for
2399 Extensions can wrap this function to specify custom requirements for
2393 new repositories.
2400 new repositories.
2394 """
2401 """
2395 createopts = createopts or {}
2402 createopts = createopts or {}
2396
2403
2397 requirements = {'revlogv1'}
2404 requirements = {'revlogv1'}
2398 if ui.configbool('format', 'usestore'):
2405 if ui.configbool('format', 'usestore'):
2399 requirements.add('store')
2406 requirements.add('store')
2400 if ui.configbool('format', 'usefncache'):
2407 if ui.configbool('format', 'usefncache'):
2401 requirements.add('fncache')
2408 requirements.add('fncache')
2402 if ui.configbool('format', 'dotencode'):
2409 if ui.configbool('format', 'dotencode'):
2403 requirements.add('dotencode')
2410 requirements.add('dotencode')
2404
2411
2405 compengine = ui.config('experimental', 'format.compression')
2412 compengine = ui.config('experimental', 'format.compression')
2406 if compengine not in util.compengines:
2413 if compengine not in util.compengines:
2407 raise error.Abort(_('compression engine %s defined by '
2414 raise error.Abort(_('compression engine %s defined by '
2408 'experimental.format.compression not available') %
2415 'experimental.format.compression not available') %
2409 compengine,
2416 compengine,
2410 hint=_('run "hg debuginstall" to list available '
2417 hint=_('run "hg debuginstall" to list available '
2411 'compression engines'))
2418 'compression engines'))
2412
2419
2413 # zlib is the historical default and doesn't need an explicit requirement.
2420 # zlib is the historical default and doesn't need an explicit requirement.
2414 if compengine != 'zlib':
2421 if compengine != 'zlib':
2415 requirements.add('exp-compression-%s' % compengine)
2422 requirements.add('exp-compression-%s' % compengine)
2416
2423
2417 if scmutil.gdinitconfig(ui):
2424 if scmutil.gdinitconfig(ui):
2418 requirements.add('generaldelta')
2425 requirements.add('generaldelta')
2419 if ui.configbool('experimental', 'treemanifest'):
2426 if ui.configbool('experimental', 'treemanifest'):
2420 requirements.add('treemanifest')
2427 requirements.add('treemanifest')
2421 # experimental config: format.sparse-revlog
2428 # experimental config: format.sparse-revlog
2422 if ui.configbool('format', 'sparse-revlog'):
2429 if ui.configbool('format', 'sparse-revlog'):
2423 requirements.add(SPARSEREVLOG_REQUIREMENT)
2430 requirements.add(SPARSEREVLOG_REQUIREMENT)
2424
2431
2425 revlogv2 = ui.config('experimental', 'revlogv2')
2432 revlogv2 = ui.config('experimental', 'revlogv2')
2426 if revlogv2 == 'enable-unstable-format-and-corrupt-my-data':
2433 if revlogv2 == 'enable-unstable-format-and-corrupt-my-data':
2427 requirements.remove('revlogv1')
2434 requirements.remove('revlogv1')
2428 # generaldelta is implied by revlogv2.
2435 # generaldelta is implied by revlogv2.
2429 requirements.discard('generaldelta')
2436 requirements.discard('generaldelta')
2430 requirements.add(REVLOGV2_REQUIREMENT)
2437 requirements.add(REVLOGV2_REQUIREMENT)
2431 # experimental config: format.internal-phase
2438 # experimental config: format.internal-phase
2432 if ui.configbool('format', 'internal-phase'):
2439 if ui.configbool('format', 'internal-phase'):
2433 requirements.add('internal-phase')
2440 requirements.add('internal-phase')
2434
2441
2435 if createopts.get('narrowfiles'):
2442 if createopts.get('narrowfiles'):
2436 requirements.add(repository.NARROW_REQUIREMENT)
2443 requirements.add(repository.NARROW_REQUIREMENT)
2437
2444
2438 return requirements
2445 return requirements
2439
2446
2440 def filterknowncreateopts(ui, createopts):
2447 def filterknowncreateopts(ui, createopts):
2441 """Filters a dict of repo creation options against options that are known.
2448 """Filters a dict of repo creation options against options that are known.
2442
2449
2443 Receives a dict of repo creation options and returns a dict of those
2450 Receives a dict of repo creation options and returns a dict of those
2444 options that we don't know how to handle.
2451 options that we don't know how to handle.
2445
2452
2446 This function is called as part of repository creation. If the
2453 This function is called as part of repository creation. If the
2447 returned dict contains any items, repository creation will not
2454 returned dict contains any items, repository creation will not
2448 be allowed, as it means there was a request to create a repository
2455 be allowed, as it means there was a request to create a repository
2449 with options not recognized by loaded code.
2456 with options not recognized by loaded code.
2450
2457
2451 Extensions can wrap this function to filter out creation options
2458 Extensions can wrap this function to filter out creation options
2452 they know how to handle.
2459 they know how to handle.
2453 """
2460 """
2454 known = {'narrowfiles'}
2461 known = {'narrowfiles'}
2455
2462
2456 return {k: v for k, v in createopts.items() if k not in known}
2463 return {k: v for k, v in createopts.items() if k not in known}
2457
2464
2458 def createrepository(ui, path, createopts=None):
2465 def createrepository(ui, path, createopts=None):
2459 """Create a new repository in a vfs.
2466 """Create a new repository in a vfs.
2460
2467
2461 ``path`` path to the new repo's working directory.
2468 ``path`` path to the new repo's working directory.
2462 ``createopts`` options for the new repository.
2469 ``createopts`` options for the new repository.
2463 """
2470 """
2464 createopts = createopts or {}
2471 createopts = createopts or {}
2465
2472
2466 unknownopts = filterknowncreateopts(ui, createopts)
2473 unknownopts = filterknowncreateopts(ui, createopts)
2467
2474
2468 if not isinstance(unknownopts, dict):
2475 if not isinstance(unknownopts, dict):
2469 raise error.ProgrammingError('filterknowncreateopts() did not return '
2476 raise error.ProgrammingError('filterknowncreateopts() did not return '
2470 'a dict')
2477 'a dict')
2471
2478
2472 if unknownopts:
2479 if unknownopts:
2473 raise error.Abort(_('unable to create repository because of unknown '
2480 raise error.Abort(_('unable to create repository because of unknown '
2474 'creation option: %s') %
2481 'creation option: %s') %
2475 ', '.sorted(unknownopts),
2482 ', '.sorted(unknownopts),
2476 hint=_('is a required extension not loaded?'))
2483 hint=_('is a required extension not loaded?'))
2477
2484
2478 requirements = newreporequirements(ui, createopts=createopts)
2485 requirements = newreporequirements(ui, createopts=createopts)
2479
2486
2480 wdirvfs = vfsmod.vfs(path, expandpath=True, realpath=True)
2487 wdirvfs = vfsmod.vfs(path, expandpath=True, realpath=True)
2481 if not wdirvfs.exists():
2488 if not wdirvfs.exists():
2482 wdirvfs.makedirs()
2489 wdirvfs.makedirs()
2483
2490
2484 hgvfs = vfsmod.vfs(wdirvfs.join(b'.hg'))
2491 hgvfs = vfsmod.vfs(wdirvfs.join(b'.hg'))
2485 if hgvfs.exists():
2492 if hgvfs.exists():
2486 raise error.RepoError(_('repository %s already exists') % path)
2493 raise error.RepoError(_('repository %s already exists') % path)
2487
2494
2488 hgvfs.makedir(notindexed=True)
2495 hgvfs.makedir(notindexed=True)
2489
2496
2490 if b'store' in requirements:
2497 if b'store' in requirements:
2491 hgvfs.mkdir(b'store')
2498 hgvfs.mkdir(b'store')
2492
2499
2493 # We create an invalid changelog outside the store so very old
2500 # We create an invalid changelog outside the store so very old
2494 # Mercurial versions (which didn't know about the requirements
2501 # Mercurial versions (which didn't know about the requirements
2495 # file) encounter an error on reading the changelog. This
2502 # file) encounter an error on reading the changelog. This
2496 # effectively locks out old clients and prevents them from
2503 # effectively locks out old clients and prevents them from
2497 # mucking with a repo in an unknown format.
2504 # mucking with a repo in an unknown format.
2498 #
2505 #
2499 # The revlog header has version 2, which won't be recognized by
2506 # The revlog header has version 2, which won't be recognized by
2500 # such old clients.
2507 # such old clients.
2501 hgvfs.append(b'00changelog.i',
2508 hgvfs.append(b'00changelog.i',
2502 b'\0\0\0\2 dummy changelog to prevent using the old repo '
2509 b'\0\0\0\2 dummy changelog to prevent using the old repo '
2503 b'layout')
2510 b'layout')
2504
2511
2505 scmutil.writerequires(hgvfs, requirements)
2512 scmutil.writerequires(hgvfs, requirements)
2506
2513
2507 def poisonrepository(repo):
2514 def poisonrepository(repo):
2508 """Poison a repository instance so it can no longer be used."""
2515 """Poison a repository instance so it can no longer be used."""
2509 # Perform any cleanup on the instance.
2516 # Perform any cleanup on the instance.
2510 repo.close()
2517 repo.close()
2511
2518
2512 # Our strategy is to replace the type of the object with one that
2519 # Our strategy is to replace the type of the object with one that
2513 # has all attribute lookups result in error.
2520 # has all attribute lookups result in error.
2514 #
2521 #
2515 # But we have to allow the close() method because some constructors
2522 # But we have to allow the close() method because some constructors
2516 # of repos call close() on repo references.
2523 # of repos call close() on repo references.
2517 class poisonedrepository(object):
2524 class poisonedrepository(object):
2518 def __getattribute__(self, item):
2525 def __getattribute__(self, item):
2519 if item == r'close':
2526 if item == r'close':
2520 return object.__getattribute__(self, item)
2527 return object.__getattribute__(self, item)
2521
2528
2522 raise error.ProgrammingError('repo instances should not be used '
2529 raise error.ProgrammingError('repo instances should not be used '
2523 'after unshare')
2530 'after unshare')
2524
2531
2525 def close(self):
2532 def close(self):
2526 pass
2533 pass
2527
2534
2528 # We may have a repoview, which intercepts __setattr__. So be sure
2535 # We may have a repoview, which intercepts __setattr__. So be sure
2529 # we operate at the lowest level possible.
2536 # we operate at the lowest level possible.
2530 object.__setattr__(repo, r'__class__', poisonedrepository)
2537 object.__setattr__(repo, r'__class__', poisonedrepository)
@@ -1,2004 +1,2017 b''
1 # manifest.py - manifest revision class for mercurial
1 # manifest.py - manifest revision 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 heapq
10 import heapq
11 import itertools
11 import itertools
12 import struct
12 import struct
13 import weakref
13 import weakref
14
14
15 from .i18n import _
15 from .i18n import _
16 from .node import (
16 from .node import (
17 bin,
17 bin,
18 hex,
18 hex,
19 nullid,
19 nullid,
20 nullrev,
20 nullrev,
21 )
21 )
22 from . import (
22 from . import (
23 error,
23 error,
24 mdiff,
24 mdiff,
25 policy,
25 policy,
26 pycompat,
26 pycompat,
27 repository,
27 repository,
28 revlog,
28 revlog,
29 util,
29 util,
30 )
30 )
31 from .utils import (
31 from .utils import (
32 interfaceutil,
32 interfaceutil,
33 )
33 )
34
34
35 parsers = policy.importmod(r'parsers')
35 parsers = policy.importmod(r'parsers')
36 propertycache = util.propertycache
36 propertycache = util.propertycache
37
37
38 def _parse(data):
38 def _parse(data):
39 # This method does a little bit of excessive-looking
39 # This method does a little bit of excessive-looking
40 # precondition checking. This is so that the behavior of this
40 # precondition checking. This is so that the behavior of this
41 # class exactly matches its C counterpart to try and help
41 # class exactly matches its C counterpart to try and help
42 # prevent surprise breakage for anyone that develops against
42 # prevent surprise breakage for anyone that develops against
43 # the pure version.
43 # the pure version.
44 if data and data[-1:] != '\n':
44 if data and data[-1:] != '\n':
45 raise ValueError('Manifest did not end in a newline.')
45 raise ValueError('Manifest did not end in a newline.')
46 prev = None
46 prev = None
47 for l in data.splitlines():
47 for l in data.splitlines():
48 if prev is not None and prev > l:
48 if prev is not None and prev > l:
49 raise ValueError('Manifest lines not in sorted order.')
49 raise ValueError('Manifest lines not in sorted order.')
50 prev = l
50 prev = l
51 f, n = l.split('\0')
51 f, n = l.split('\0')
52 if len(n) > 40:
52 if len(n) > 40:
53 yield f, bin(n[:40]), n[40:]
53 yield f, bin(n[:40]), n[40:]
54 else:
54 else:
55 yield f, bin(n), ''
55 yield f, bin(n), ''
56
56
57 def _text(it):
57 def _text(it):
58 files = []
58 files = []
59 lines = []
59 lines = []
60 for f, n, fl in it:
60 for f, n, fl in it:
61 files.append(f)
61 files.append(f)
62 # if this is changed to support newlines in filenames,
62 # if this is changed to support newlines in filenames,
63 # be sure to check the templates/ dir again (especially *-raw.tmpl)
63 # be sure to check the templates/ dir again (especially *-raw.tmpl)
64 lines.append("%s\0%s%s\n" % (f, hex(n), fl))
64 lines.append("%s\0%s%s\n" % (f, hex(n), fl))
65
65
66 _checkforbidden(files)
66 _checkforbidden(files)
67 return ''.join(lines)
67 return ''.join(lines)
68
68
69 class lazymanifestiter(object):
69 class lazymanifestiter(object):
70 def __init__(self, lm):
70 def __init__(self, lm):
71 self.pos = 0
71 self.pos = 0
72 self.lm = lm
72 self.lm = lm
73
73
74 def __iter__(self):
74 def __iter__(self):
75 return self
75 return self
76
76
77 def next(self):
77 def next(self):
78 try:
78 try:
79 data, pos = self.lm._get(self.pos)
79 data, pos = self.lm._get(self.pos)
80 except IndexError:
80 except IndexError:
81 raise StopIteration
81 raise StopIteration
82 if pos == -1:
82 if pos == -1:
83 self.pos += 1
83 self.pos += 1
84 return data[0]
84 return data[0]
85 self.pos += 1
85 self.pos += 1
86 zeropos = data.find('\x00', pos)
86 zeropos = data.find('\x00', pos)
87 return data[pos:zeropos]
87 return data[pos:zeropos]
88
88
89 __next__ = next
89 __next__ = next
90
90
91 class lazymanifestiterentries(object):
91 class lazymanifestiterentries(object):
92 def __init__(self, lm):
92 def __init__(self, lm):
93 self.lm = lm
93 self.lm = lm
94 self.pos = 0
94 self.pos = 0
95
95
96 def __iter__(self):
96 def __iter__(self):
97 return self
97 return self
98
98
99 def next(self):
99 def next(self):
100 try:
100 try:
101 data, pos = self.lm._get(self.pos)
101 data, pos = self.lm._get(self.pos)
102 except IndexError:
102 except IndexError:
103 raise StopIteration
103 raise StopIteration
104 if pos == -1:
104 if pos == -1:
105 self.pos += 1
105 self.pos += 1
106 return data
106 return data
107 zeropos = data.find('\x00', pos)
107 zeropos = data.find('\x00', pos)
108 hashval = unhexlify(data, self.lm.extrainfo[self.pos],
108 hashval = unhexlify(data, self.lm.extrainfo[self.pos],
109 zeropos + 1, 40)
109 zeropos + 1, 40)
110 flags = self.lm._getflags(data, self.pos, zeropos)
110 flags = self.lm._getflags(data, self.pos, zeropos)
111 self.pos += 1
111 self.pos += 1
112 return (data[pos:zeropos], hashval, flags)
112 return (data[pos:zeropos], hashval, flags)
113
113
114 __next__ = next
114 __next__ = next
115
115
116 def unhexlify(data, extra, pos, length):
116 def unhexlify(data, extra, pos, length):
117 s = bin(data[pos:pos + length])
117 s = bin(data[pos:pos + length])
118 if extra:
118 if extra:
119 s += chr(extra & 0xff)
119 s += chr(extra & 0xff)
120 return s
120 return s
121
121
122 def _cmp(a, b):
122 def _cmp(a, b):
123 return (a > b) - (a < b)
123 return (a > b) - (a < b)
124
124
125 class _lazymanifest(object):
125 class _lazymanifest(object):
126 def __init__(self, data, positions=None, extrainfo=None, extradata=None):
126 def __init__(self, data, positions=None, extrainfo=None, extradata=None):
127 if positions is None:
127 if positions is None:
128 self.positions = self.findlines(data)
128 self.positions = self.findlines(data)
129 self.extrainfo = [0] * len(self.positions)
129 self.extrainfo = [0] * len(self.positions)
130 self.data = data
130 self.data = data
131 self.extradata = []
131 self.extradata = []
132 else:
132 else:
133 self.positions = positions[:]
133 self.positions = positions[:]
134 self.extrainfo = extrainfo[:]
134 self.extrainfo = extrainfo[:]
135 self.extradata = extradata[:]
135 self.extradata = extradata[:]
136 self.data = data
136 self.data = data
137
137
138 def findlines(self, data):
138 def findlines(self, data):
139 if not data:
139 if not data:
140 return []
140 return []
141 pos = data.find("\n")
141 pos = data.find("\n")
142 if pos == -1 or data[-1:] != '\n':
142 if pos == -1 or data[-1:] != '\n':
143 raise ValueError("Manifest did not end in a newline.")
143 raise ValueError("Manifest did not end in a newline.")
144 positions = [0]
144 positions = [0]
145 prev = data[:data.find('\x00')]
145 prev = data[:data.find('\x00')]
146 while pos < len(data) - 1 and pos != -1:
146 while pos < len(data) - 1 and pos != -1:
147 positions.append(pos + 1)
147 positions.append(pos + 1)
148 nexts = data[pos + 1:data.find('\x00', pos + 1)]
148 nexts = data[pos + 1:data.find('\x00', pos + 1)]
149 if nexts < prev:
149 if nexts < prev:
150 raise ValueError("Manifest lines not in sorted order.")
150 raise ValueError("Manifest lines not in sorted order.")
151 prev = nexts
151 prev = nexts
152 pos = data.find("\n", pos + 1)
152 pos = data.find("\n", pos + 1)
153 return positions
153 return positions
154
154
155 def _get(self, index):
155 def _get(self, index):
156 # get the position encoded in pos:
156 # get the position encoded in pos:
157 # positive number is an index in 'data'
157 # positive number is an index in 'data'
158 # negative number is in extrapieces
158 # negative number is in extrapieces
159 pos = self.positions[index]
159 pos = self.positions[index]
160 if pos >= 0:
160 if pos >= 0:
161 return self.data, pos
161 return self.data, pos
162 return self.extradata[-pos - 1], -1
162 return self.extradata[-pos - 1], -1
163
163
164 def _getkey(self, pos):
164 def _getkey(self, pos):
165 if pos >= 0:
165 if pos >= 0:
166 return self.data[pos:self.data.find('\x00', pos + 1)]
166 return self.data[pos:self.data.find('\x00', pos + 1)]
167 return self.extradata[-pos - 1][0]
167 return self.extradata[-pos - 1][0]
168
168
169 def bsearch(self, key):
169 def bsearch(self, key):
170 first = 0
170 first = 0
171 last = len(self.positions) - 1
171 last = len(self.positions) - 1
172
172
173 while first <= last:
173 while first <= last:
174 midpoint = (first + last)//2
174 midpoint = (first + last)//2
175 nextpos = self.positions[midpoint]
175 nextpos = self.positions[midpoint]
176 candidate = self._getkey(nextpos)
176 candidate = self._getkey(nextpos)
177 r = _cmp(key, candidate)
177 r = _cmp(key, candidate)
178 if r == 0:
178 if r == 0:
179 return midpoint
179 return midpoint
180 else:
180 else:
181 if r < 0:
181 if r < 0:
182 last = midpoint - 1
182 last = midpoint - 1
183 else:
183 else:
184 first = midpoint + 1
184 first = midpoint + 1
185 return -1
185 return -1
186
186
187 def bsearch2(self, key):
187 def bsearch2(self, key):
188 # same as the above, but will always return the position
188 # same as the above, but will always return the position
189 # done for performance reasons
189 # done for performance reasons
190 first = 0
190 first = 0
191 last = len(self.positions) - 1
191 last = len(self.positions) - 1
192
192
193 while first <= last:
193 while first <= last:
194 midpoint = (first + last)//2
194 midpoint = (first + last)//2
195 nextpos = self.positions[midpoint]
195 nextpos = self.positions[midpoint]
196 candidate = self._getkey(nextpos)
196 candidate = self._getkey(nextpos)
197 r = _cmp(key, candidate)
197 r = _cmp(key, candidate)
198 if r == 0:
198 if r == 0:
199 return (midpoint, True)
199 return (midpoint, True)
200 else:
200 else:
201 if r < 0:
201 if r < 0:
202 last = midpoint - 1
202 last = midpoint - 1
203 else:
203 else:
204 first = midpoint + 1
204 first = midpoint + 1
205 return (first, False)
205 return (first, False)
206
206
207 def __contains__(self, key):
207 def __contains__(self, key):
208 return self.bsearch(key) != -1
208 return self.bsearch(key) != -1
209
209
210 def _getflags(self, data, needle, pos):
210 def _getflags(self, data, needle, pos):
211 start = pos + 41
211 start = pos + 41
212 end = data.find("\n", start)
212 end = data.find("\n", start)
213 if end == -1:
213 if end == -1:
214 end = len(data) - 1
214 end = len(data) - 1
215 if start == end:
215 if start == end:
216 return ''
216 return ''
217 return self.data[start:end]
217 return self.data[start:end]
218
218
219 def __getitem__(self, key):
219 def __getitem__(self, key):
220 if not isinstance(key, bytes):
220 if not isinstance(key, bytes):
221 raise TypeError("getitem: manifest keys must be a bytes.")
221 raise TypeError("getitem: manifest keys must be a bytes.")
222 needle = self.bsearch(key)
222 needle = self.bsearch(key)
223 if needle == -1:
223 if needle == -1:
224 raise KeyError
224 raise KeyError
225 data, pos = self._get(needle)
225 data, pos = self._get(needle)
226 if pos == -1:
226 if pos == -1:
227 return (data[1], data[2])
227 return (data[1], data[2])
228 zeropos = data.find('\x00', pos)
228 zeropos = data.find('\x00', pos)
229 assert 0 <= needle <= len(self.positions)
229 assert 0 <= needle <= len(self.positions)
230 assert len(self.extrainfo) == len(self.positions)
230 assert len(self.extrainfo) == len(self.positions)
231 hashval = unhexlify(data, self.extrainfo[needle], zeropos + 1, 40)
231 hashval = unhexlify(data, self.extrainfo[needle], zeropos + 1, 40)
232 flags = self._getflags(data, needle, zeropos)
232 flags = self._getflags(data, needle, zeropos)
233 return (hashval, flags)
233 return (hashval, flags)
234
234
235 def __delitem__(self, key):
235 def __delitem__(self, key):
236 needle, found = self.bsearch2(key)
236 needle, found = self.bsearch2(key)
237 if not found:
237 if not found:
238 raise KeyError
238 raise KeyError
239 cur = self.positions[needle]
239 cur = self.positions[needle]
240 self.positions = self.positions[:needle] + self.positions[needle + 1:]
240 self.positions = self.positions[:needle] + self.positions[needle + 1:]
241 self.extrainfo = self.extrainfo[:needle] + self.extrainfo[needle + 1:]
241 self.extrainfo = self.extrainfo[:needle] + self.extrainfo[needle + 1:]
242 if cur >= 0:
242 if cur >= 0:
243 self.data = self.data[:cur] + '\x00' + self.data[cur + 1:]
243 self.data = self.data[:cur] + '\x00' + self.data[cur + 1:]
244
244
245 def __setitem__(self, key, value):
245 def __setitem__(self, key, value):
246 if not isinstance(key, bytes):
246 if not isinstance(key, bytes):
247 raise TypeError("setitem: manifest keys must be a byte string.")
247 raise TypeError("setitem: manifest keys must be a byte string.")
248 if not isinstance(value, tuple) or len(value) != 2:
248 if not isinstance(value, tuple) or len(value) != 2:
249 raise TypeError("Manifest values must be a tuple of (node, flags).")
249 raise TypeError("Manifest values must be a tuple of (node, flags).")
250 hashval = value[0]
250 hashval = value[0]
251 if not isinstance(hashval, bytes) or not 20 <= len(hashval) <= 22:
251 if not isinstance(hashval, bytes) or not 20 <= len(hashval) <= 22:
252 raise TypeError("node must be a 20-byte byte string")
252 raise TypeError("node must be a 20-byte byte string")
253 flags = value[1]
253 flags = value[1]
254 if len(hashval) == 22:
254 if len(hashval) == 22:
255 hashval = hashval[:-1]
255 hashval = hashval[:-1]
256 if not isinstance(flags, bytes) or len(flags) > 1:
256 if not isinstance(flags, bytes) or len(flags) > 1:
257 raise TypeError("flags must a 0 or 1 byte string, got %r", flags)
257 raise TypeError("flags must a 0 or 1 byte string, got %r", flags)
258 needle, found = self.bsearch2(key)
258 needle, found = self.bsearch2(key)
259 if found:
259 if found:
260 # put the item
260 # put the item
261 pos = self.positions[needle]
261 pos = self.positions[needle]
262 if pos < 0:
262 if pos < 0:
263 self.extradata[-pos - 1] = (key, hashval, value[1])
263 self.extradata[-pos - 1] = (key, hashval, value[1])
264 else:
264 else:
265 # just don't bother
265 # just don't bother
266 self.extradata.append((key, hashval, value[1]))
266 self.extradata.append((key, hashval, value[1]))
267 self.positions[needle] = -len(self.extradata)
267 self.positions[needle] = -len(self.extradata)
268 else:
268 else:
269 # not found, put it in with extra positions
269 # not found, put it in with extra positions
270 self.extradata.append((key, hashval, value[1]))
270 self.extradata.append((key, hashval, value[1]))
271 self.positions = (self.positions[:needle] + [-len(self.extradata)]
271 self.positions = (self.positions[:needle] + [-len(self.extradata)]
272 + self.positions[needle:])
272 + self.positions[needle:])
273 self.extrainfo = (self.extrainfo[:needle] + [0] +
273 self.extrainfo = (self.extrainfo[:needle] + [0] +
274 self.extrainfo[needle:])
274 self.extrainfo[needle:])
275
275
276 def copy(self):
276 def copy(self):
277 # XXX call _compact like in C?
277 # XXX call _compact like in C?
278 return _lazymanifest(self.data, self.positions, self.extrainfo,
278 return _lazymanifest(self.data, self.positions, self.extrainfo,
279 self.extradata)
279 self.extradata)
280
280
281 def _compact(self):
281 def _compact(self):
282 # hopefully not called TOO often
282 # hopefully not called TOO often
283 if len(self.extradata) == 0:
283 if len(self.extradata) == 0:
284 return
284 return
285 l = []
285 l = []
286 last_cut = 0
286 last_cut = 0
287 i = 0
287 i = 0
288 offset = 0
288 offset = 0
289 self.extrainfo = [0] * len(self.positions)
289 self.extrainfo = [0] * len(self.positions)
290 while i < len(self.positions):
290 while i < len(self.positions):
291 if self.positions[i] >= 0:
291 if self.positions[i] >= 0:
292 cur = self.positions[i]
292 cur = self.positions[i]
293 last_cut = cur
293 last_cut = cur
294 while True:
294 while True:
295 self.positions[i] = offset
295 self.positions[i] = offset
296 i += 1
296 i += 1
297 if i == len(self.positions) or self.positions[i] < 0:
297 if i == len(self.positions) or self.positions[i] < 0:
298 break
298 break
299 offset += self.positions[i] - cur
299 offset += self.positions[i] - cur
300 cur = self.positions[i]
300 cur = self.positions[i]
301 end_cut = self.data.find('\n', cur)
301 end_cut = self.data.find('\n', cur)
302 if end_cut != -1:
302 if end_cut != -1:
303 end_cut += 1
303 end_cut += 1
304 offset += end_cut - cur
304 offset += end_cut - cur
305 l.append(self.data[last_cut:end_cut])
305 l.append(self.data[last_cut:end_cut])
306 else:
306 else:
307 while i < len(self.positions) and self.positions[i] < 0:
307 while i < len(self.positions) and self.positions[i] < 0:
308 cur = self.positions[i]
308 cur = self.positions[i]
309 t = self.extradata[-cur - 1]
309 t = self.extradata[-cur - 1]
310 l.append(self._pack(t))
310 l.append(self._pack(t))
311 self.positions[i] = offset
311 self.positions[i] = offset
312 if len(t[1]) > 20:
312 if len(t[1]) > 20:
313 self.extrainfo[i] = ord(t[1][21])
313 self.extrainfo[i] = ord(t[1][21])
314 offset += len(l[-1])
314 offset += len(l[-1])
315 i += 1
315 i += 1
316 self.data = ''.join(l)
316 self.data = ''.join(l)
317 self.extradata = []
317 self.extradata = []
318
318
319 def _pack(self, d):
319 def _pack(self, d):
320 return d[0] + '\x00' + hex(d[1][:20]) + d[2] + '\n'
320 return d[0] + '\x00' + hex(d[1][:20]) + d[2] + '\n'
321
321
322 def text(self):
322 def text(self):
323 self._compact()
323 self._compact()
324 return self.data
324 return self.data
325
325
326 def diff(self, m2, clean=False):
326 def diff(self, m2, clean=False):
327 '''Finds changes between the current manifest and m2.'''
327 '''Finds changes between the current manifest and m2.'''
328 # XXX think whether efficiency matters here
328 # XXX think whether efficiency matters here
329 diff = {}
329 diff = {}
330
330
331 for fn, e1, flags in self.iterentries():
331 for fn, e1, flags in self.iterentries():
332 if fn not in m2:
332 if fn not in m2:
333 diff[fn] = (e1, flags), (None, '')
333 diff[fn] = (e1, flags), (None, '')
334 else:
334 else:
335 e2 = m2[fn]
335 e2 = m2[fn]
336 if (e1, flags) != e2:
336 if (e1, flags) != e2:
337 diff[fn] = (e1, flags), e2
337 diff[fn] = (e1, flags), e2
338 elif clean:
338 elif clean:
339 diff[fn] = None
339 diff[fn] = None
340
340
341 for fn, e2, flags in m2.iterentries():
341 for fn, e2, flags in m2.iterentries():
342 if fn not in self:
342 if fn not in self:
343 diff[fn] = (None, ''), (e2, flags)
343 diff[fn] = (None, ''), (e2, flags)
344
344
345 return diff
345 return diff
346
346
347 def iterentries(self):
347 def iterentries(self):
348 return lazymanifestiterentries(self)
348 return lazymanifestiterentries(self)
349
349
350 def iterkeys(self):
350 def iterkeys(self):
351 return lazymanifestiter(self)
351 return lazymanifestiter(self)
352
352
353 def __iter__(self):
353 def __iter__(self):
354 return lazymanifestiter(self)
354 return lazymanifestiter(self)
355
355
356 def __len__(self):
356 def __len__(self):
357 return len(self.positions)
357 return len(self.positions)
358
358
359 def filtercopy(self, filterfn):
359 def filtercopy(self, filterfn):
360 # XXX should be optimized
360 # XXX should be optimized
361 c = _lazymanifest('')
361 c = _lazymanifest('')
362 for f, n, fl in self.iterentries():
362 for f, n, fl in self.iterentries():
363 if filterfn(f):
363 if filterfn(f):
364 c[f] = n, fl
364 c[f] = n, fl
365 return c
365 return c
366
366
367 try:
367 try:
368 _lazymanifest = parsers.lazymanifest
368 _lazymanifest = parsers.lazymanifest
369 except AttributeError:
369 except AttributeError:
370 pass
370 pass
371
371
372 @interfaceutil.implementer(repository.imanifestdict)
372 @interfaceutil.implementer(repository.imanifestdict)
373 class manifestdict(object):
373 class manifestdict(object):
374 def __init__(self, data=''):
374 def __init__(self, data=''):
375 self._lm = _lazymanifest(data)
375 self._lm = _lazymanifest(data)
376
376
377 def __getitem__(self, key):
377 def __getitem__(self, key):
378 return self._lm[key][0]
378 return self._lm[key][0]
379
379
380 def find(self, key):
380 def find(self, key):
381 return self._lm[key]
381 return self._lm[key]
382
382
383 def __len__(self):
383 def __len__(self):
384 return len(self._lm)
384 return len(self._lm)
385
385
386 def __nonzero__(self):
386 def __nonzero__(self):
387 # nonzero is covered by the __len__ function, but implementing it here
387 # nonzero is covered by the __len__ function, but implementing it here
388 # makes it easier for extensions to override.
388 # makes it easier for extensions to override.
389 return len(self._lm) != 0
389 return len(self._lm) != 0
390
390
391 __bool__ = __nonzero__
391 __bool__ = __nonzero__
392
392
393 def __setitem__(self, key, node):
393 def __setitem__(self, key, node):
394 self._lm[key] = node, self.flags(key, '')
394 self._lm[key] = node, self.flags(key, '')
395
395
396 def __contains__(self, key):
396 def __contains__(self, key):
397 if key is None:
397 if key is None:
398 return False
398 return False
399 return key in self._lm
399 return key in self._lm
400
400
401 def __delitem__(self, key):
401 def __delitem__(self, key):
402 del self._lm[key]
402 del self._lm[key]
403
403
404 def __iter__(self):
404 def __iter__(self):
405 return self._lm.__iter__()
405 return self._lm.__iter__()
406
406
407 def iterkeys(self):
407 def iterkeys(self):
408 return self._lm.iterkeys()
408 return self._lm.iterkeys()
409
409
410 def keys(self):
410 def keys(self):
411 return list(self.iterkeys())
411 return list(self.iterkeys())
412
412
413 def filesnotin(self, m2, match=None):
413 def filesnotin(self, m2, match=None):
414 '''Set of files in this manifest that are not in the other'''
414 '''Set of files in this manifest that are not in the other'''
415 if match:
415 if match:
416 m1 = self.matches(match)
416 m1 = self.matches(match)
417 m2 = m2.matches(match)
417 m2 = m2.matches(match)
418 return m1.filesnotin(m2)
418 return m1.filesnotin(m2)
419 diff = self.diff(m2)
419 diff = self.diff(m2)
420 files = set(filepath
420 files = set(filepath
421 for filepath, hashflags in diff.iteritems()
421 for filepath, hashflags in diff.iteritems()
422 if hashflags[1][0] is None)
422 if hashflags[1][0] is None)
423 return files
423 return files
424
424
425 @propertycache
425 @propertycache
426 def _dirs(self):
426 def _dirs(self):
427 return util.dirs(self)
427 return util.dirs(self)
428
428
429 def dirs(self):
429 def dirs(self):
430 return self._dirs
430 return self._dirs
431
431
432 def hasdir(self, dir):
432 def hasdir(self, dir):
433 return dir in self._dirs
433 return dir in self._dirs
434
434
435 def _filesfastpath(self, match):
435 def _filesfastpath(self, match):
436 '''Checks whether we can correctly and quickly iterate over matcher
436 '''Checks whether we can correctly and quickly iterate over matcher
437 files instead of over manifest files.'''
437 files instead of over manifest files.'''
438 files = match.files()
438 files = match.files()
439 return (len(files) < 100 and (match.isexact() or
439 return (len(files) < 100 and (match.isexact() or
440 (match.prefix() and all(fn in self for fn in files))))
440 (match.prefix() and all(fn in self for fn in files))))
441
441
442 def walk(self, match):
442 def walk(self, match):
443 '''Generates matching file names.
443 '''Generates matching file names.
444
444
445 Equivalent to manifest.matches(match).iterkeys(), but without creating
445 Equivalent to manifest.matches(match).iterkeys(), but without creating
446 an entirely new manifest.
446 an entirely new manifest.
447
447
448 It also reports nonexistent files by marking them bad with match.bad().
448 It also reports nonexistent files by marking them bad with match.bad().
449 '''
449 '''
450 if match.always():
450 if match.always():
451 for f in iter(self):
451 for f in iter(self):
452 yield f
452 yield f
453 return
453 return
454
454
455 fset = set(match.files())
455 fset = set(match.files())
456
456
457 # avoid the entire walk if we're only looking for specific files
457 # avoid the entire walk if we're only looking for specific files
458 if self._filesfastpath(match):
458 if self._filesfastpath(match):
459 for fn in sorted(fset):
459 for fn in sorted(fset):
460 yield fn
460 yield fn
461 return
461 return
462
462
463 for fn in self:
463 for fn in self:
464 if fn in fset:
464 if fn in fset:
465 # specified pattern is the exact name
465 # specified pattern is the exact name
466 fset.remove(fn)
466 fset.remove(fn)
467 if match(fn):
467 if match(fn):
468 yield fn
468 yield fn
469
469
470 # for dirstate.walk, files=['.'] means "walk the whole tree".
470 # for dirstate.walk, files=['.'] means "walk the whole tree".
471 # follow that here, too
471 # follow that here, too
472 fset.discard('.')
472 fset.discard('.')
473
473
474 for fn in sorted(fset):
474 for fn in sorted(fset):
475 if not self.hasdir(fn):
475 if not self.hasdir(fn):
476 match.bad(fn, None)
476 match.bad(fn, None)
477
477
478 def matches(self, match):
478 def matches(self, match):
479 '''generate a new manifest filtered by the match argument'''
479 '''generate a new manifest filtered by the match argument'''
480 if match.always():
480 if match.always():
481 return self.copy()
481 return self.copy()
482
482
483 if self._filesfastpath(match):
483 if self._filesfastpath(match):
484 m = manifestdict()
484 m = manifestdict()
485 lm = self._lm
485 lm = self._lm
486 for fn in match.files():
486 for fn in match.files():
487 if fn in lm:
487 if fn in lm:
488 m._lm[fn] = lm[fn]
488 m._lm[fn] = lm[fn]
489 return m
489 return m
490
490
491 m = manifestdict()
491 m = manifestdict()
492 m._lm = self._lm.filtercopy(match)
492 m._lm = self._lm.filtercopy(match)
493 return m
493 return m
494
494
495 def diff(self, m2, match=None, clean=False):
495 def diff(self, m2, match=None, clean=False):
496 '''Finds changes between the current manifest and m2.
496 '''Finds changes between the current manifest and m2.
497
497
498 Args:
498 Args:
499 m2: the manifest to which this manifest should be compared.
499 m2: the manifest to which this manifest should be compared.
500 clean: if true, include files unchanged between these manifests
500 clean: if true, include files unchanged between these manifests
501 with a None value in the returned dictionary.
501 with a None value in the returned dictionary.
502
502
503 The result is returned as a dict with filename as key and
503 The result is returned as a dict with filename as key and
504 values of the form ((n1,fl1),(n2,fl2)), where n1/n2 is the
504 values of the form ((n1,fl1),(n2,fl2)), where n1/n2 is the
505 nodeid in the current/other manifest and fl1/fl2 is the flag
505 nodeid in the current/other manifest and fl1/fl2 is the flag
506 in the current/other manifest. Where the file does not exist,
506 in the current/other manifest. Where the file does not exist,
507 the nodeid will be None and the flags will be the empty
507 the nodeid will be None and the flags will be the empty
508 string.
508 string.
509 '''
509 '''
510 if match:
510 if match:
511 m1 = self.matches(match)
511 m1 = self.matches(match)
512 m2 = m2.matches(match)
512 m2 = m2.matches(match)
513 return m1.diff(m2, clean=clean)
513 return m1.diff(m2, clean=clean)
514 return self._lm.diff(m2._lm, clean)
514 return self._lm.diff(m2._lm, clean)
515
515
516 def setflag(self, key, flag):
516 def setflag(self, key, flag):
517 self._lm[key] = self[key], flag
517 self._lm[key] = self[key], flag
518
518
519 def get(self, key, default=None):
519 def get(self, key, default=None):
520 try:
520 try:
521 return self._lm[key][0]
521 return self._lm[key][0]
522 except KeyError:
522 except KeyError:
523 return default
523 return default
524
524
525 def flags(self, key, default=''):
525 def flags(self, key, default=''):
526 try:
526 try:
527 return self._lm[key][1]
527 return self._lm[key][1]
528 except KeyError:
528 except KeyError:
529 return default
529 return default
530
530
531 def copy(self):
531 def copy(self):
532 c = manifestdict()
532 c = manifestdict()
533 c._lm = self._lm.copy()
533 c._lm = self._lm.copy()
534 return c
534 return c
535
535
536 def items(self):
536 def items(self):
537 return (x[:2] for x in self._lm.iterentries())
537 return (x[:2] for x in self._lm.iterentries())
538
538
539 def iteritems(self):
539 def iteritems(self):
540 return (x[:2] for x in self._lm.iterentries())
540 return (x[:2] for x in self._lm.iterentries())
541
541
542 def iterentries(self):
542 def iterentries(self):
543 return self._lm.iterentries()
543 return self._lm.iterentries()
544
544
545 def text(self):
545 def text(self):
546 # most likely uses native version
546 # most likely uses native version
547 return self._lm.text()
547 return self._lm.text()
548
548
549 def fastdelta(self, base, changes):
549 def fastdelta(self, base, changes):
550 """Given a base manifest text as a bytearray and a list of changes
550 """Given a base manifest text as a bytearray and a list of changes
551 relative to that text, compute a delta that can be used by revlog.
551 relative to that text, compute a delta that can be used by revlog.
552 """
552 """
553 delta = []
553 delta = []
554 dstart = None
554 dstart = None
555 dend = None
555 dend = None
556 dline = [""]
556 dline = [""]
557 start = 0
557 start = 0
558 # zero copy representation of base as a buffer
558 # zero copy representation of base as a buffer
559 addbuf = util.buffer(base)
559 addbuf = util.buffer(base)
560
560
561 changes = list(changes)
561 changes = list(changes)
562 if len(changes) < 1000:
562 if len(changes) < 1000:
563 # start with a readonly loop that finds the offset of
563 # start with a readonly loop that finds the offset of
564 # each line and creates the deltas
564 # each line and creates the deltas
565 for f, todelete in changes:
565 for f, todelete in changes:
566 # bs will either be the index of the item or the insert point
566 # bs will either be the index of the item or the insert point
567 start, end = _msearch(addbuf, f, start)
567 start, end = _msearch(addbuf, f, start)
568 if not todelete:
568 if not todelete:
569 h, fl = self._lm[f]
569 h, fl = self._lm[f]
570 l = "%s\0%s%s\n" % (f, hex(h), fl)
570 l = "%s\0%s%s\n" % (f, hex(h), fl)
571 else:
571 else:
572 if start == end:
572 if start == end:
573 # item we want to delete was not found, error out
573 # item we want to delete was not found, error out
574 raise AssertionError(
574 raise AssertionError(
575 _("failed to remove %s from manifest") % f)
575 _("failed to remove %s from manifest") % f)
576 l = ""
576 l = ""
577 if dstart is not None and dstart <= start and dend >= start:
577 if dstart is not None and dstart <= start and dend >= start:
578 if dend < end:
578 if dend < end:
579 dend = end
579 dend = end
580 if l:
580 if l:
581 dline.append(l)
581 dline.append(l)
582 else:
582 else:
583 if dstart is not None:
583 if dstart is not None:
584 delta.append([dstart, dend, "".join(dline)])
584 delta.append([dstart, dend, "".join(dline)])
585 dstart = start
585 dstart = start
586 dend = end
586 dend = end
587 dline = [l]
587 dline = [l]
588
588
589 if dstart is not None:
589 if dstart is not None:
590 delta.append([dstart, dend, "".join(dline)])
590 delta.append([dstart, dend, "".join(dline)])
591 # apply the delta to the base, and get a delta for addrevision
591 # apply the delta to the base, and get a delta for addrevision
592 deltatext, arraytext = _addlistdelta(base, delta)
592 deltatext, arraytext = _addlistdelta(base, delta)
593 else:
593 else:
594 # For large changes, it's much cheaper to just build the text and
594 # For large changes, it's much cheaper to just build the text and
595 # diff it.
595 # diff it.
596 arraytext = bytearray(self.text())
596 arraytext = bytearray(self.text())
597 deltatext = mdiff.textdiff(
597 deltatext = mdiff.textdiff(
598 util.buffer(base), util.buffer(arraytext))
598 util.buffer(base), util.buffer(arraytext))
599
599
600 return arraytext, deltatext
600 return arraytext, deltatext
601
601
602 def _msearch(m, s, lo=0, hi=None):
602 def _msearch(m, s, lo=0, hi=None):
603 '''return a tuple (start, end) that says where to find s within m.
603 '''return a tuple (start, end) that says where to find s within m.
604
604
605 If the string is found m[start:end] are the line containing
605 If the string is found m[start:end] are the line containing
606 that string. If start == end the string was not found and
606 that string. If start == end the string was not found and
607 they indicate the proper sorted insertion point.
607 they indicate the proper sorted insertion point.
608
608
609 m should be a buffer, a memoryview or a byte string.
609 m should be a buffer, a memoryview or a byte string.
610 s is a byte string'''
610 s is a byte string'''
611 def advance(i, c):
611 def advance(i, c):
612 while i < lenm and m[i:i + 1] != c:
612 while i < lenm and m[i:i + 1] != c:
613 i += 1
613 i += 1
614 return i
614 return i
615 if not s:
615 if not s:
616 return (lo, lo)
616 return (lo, lo)
617 lenm = len(m)
617 lenm = len(m)
618 if not hi:
618 if not hi:
619 hi = lenm
619 hi = lenm
620 while lo < hi:
620 while lo < hi:
621 mid = (lo + hi) // 2
621 mid = (lo + hi) // 2
622 start = mid
622 start = mid
623 while start > 0 and m[start - 1:start] != '\n':
623 while start > 0 and m[start - 1:start] != '\n':
624 start -= 1
624 start -= 1
625 end = advance(start, '\0')
625 end = advance(start, '\0')
626 if bytes(m[start:end]) < s:
626 if bytes(m[start:end]) < s:
627 # we know that after the null there are 40 bytes of sha1
627 # we know that after the null there are 40 bytes of sha1
628 # this translates to the bisect lo = mid + 1
628 # this translates to the bisect lo = mid + 1
629 lo = advance(end + 40, '\n') + 1
629 lo = advance(end + 40, '\n') + 1
630 else:
630 else:
631 # this translates to the bisect hi = mid
631 # this translates to the bisect hi = mid
632 hi = start
632 hi = start
633 end = advance(lo, '\0')
633 end = advance(lo, '\0')
634 found = m[lo:end]
634 found = m[lo:end]
635 if s == found:
635 if s == found:
636 # we know that after the null there are 40 bytes of sha1
636 # we know that after the null there are 40 bytes of sha1
637 end = advance(end + 40, '\n')
637 end = advance(end + 40, '\n')
638 return (lo, end + 1)
638 return (lo, end + 1)
639 else:
639 else:
640 return (lo, lo)
640 return (lo, lo)
641
641
642 def _checkforbidden(l):
642 def _checkforbidden(l):
643 """Check filenames for illegal characters."""
643 """Check filenames for illegal characters."""
644 for f in l:
644 for f in l:
645 if '\n' in f or '\r' in f:
645 if '\n' in f or '\r' in f:
646 raise error.RevlogError(
646 raise error.RevlogError(
647 _("'\\n' and '\\r' disallowed in filenames: %r")
647 _("'\\n' and '\\r' disallowed in filenames: %r")
648 % pycompat.bytestr(f))
648 % pycompat.bytestr(f))
649
649
650
650
651 # apply the changes collected during the bisect loop to our addlist
651 # apply the changes collected during the bisect loop to our addlist
652 # return a delta suitable for addrevision
652 # return a delta suitable for addrevision
653 def _addlistdelta(addlist, x):
653 def _addlistdelta(addlist, x):
654 # for large addlist arrays, building a new array is cheaper
654 # for large addlist arrays, building a new array is cheaper
655 # than repeatedly modifying the existing one
655 # than repeatedly modifying the existing one
656 currentposition = 0
656 currentposition = 0
657 newaddlist = bytearray()
657 newaddlist = bytearray()
658
658
659 for start, end, content in x:
659 for start, end, content in x:
660 newaddlist += addlist[currentposition:start]
660 newaddlist += addlist[currentposition:start]
661 if content:
661 if content:
662 newaddlist += bytearray(content)
662 newaddlist += bytearray(content)
663
663
664 currentposition = end
664 currentposition = end
665
665
666 newaddlist += addlist[currentposition:]
666 newaddlist += addlist[currentposition:]
667
667
668 deltatext = "".join(struct.pack(">lll", start, end, len(content))
668 deltatext = "".join(struct.pack(">lll", start, end, len(content))
669 + content for start, end, content in x)
669 + content for start, end, content in x)
670 return deltatext, newaddlist
670 return deltatext, newaddlist
671
671
672 def _splittopdir(f):
672 def _splittopdir(f):
673 if '/' in f:
673 if '/' in f:
674 dir, subpath = f.split('/', 1)
674 dir, subpath = f.split('/', 1)
675 return dir + '/', subpath
675 return dir + '/', subpath
676 else:
676 else:
677 return '', f
677 return '', f
678
678
679 _noop = lambda s: None
679 _noop = lambda s: None
680
680
681 class treemanifest(object):
681 class treemanifest(object):
682 def __init__(self, dir='', text=''):
682 def __init__(self, dir='', text=''):
683 self._dir = dir
683 self._dir = dir
684 self._node = nullid
684 self._node = nullid
685 self._loadfunc = _noop
685 self._loadfunc = _noop
686 self._copyfunc = _noop
686 self._copyfunc = _noop
687 self._dirty = False
687 self._dirty = False
688 self._dirs = {}
688 self._dirs = {}
689 self._lazydirs = {}
689 self._lazydirs = {}
690 # Using _lazymanifest here is a little slower than plain old dicts
690 # Using _lazymanifest here is a little slower than plain old dicts
691 self._files = {}
691 self._files = {}
692 self._flags = {}
692 self._flags = {}
693 if text:
693 if text:
694 def readsubtree(subdir, subm):
694 def readsubtree(subdir, subm):
695 raise AssertionError('treemanifest constructor only accepts '
695 raise AssertionError('treemanifest constructor only accepts '
696 'flat manifests')
696 'flat manifests')
697 self.parse(text, readsubtree)
697 self.parse(text, readsubtree)
698 self._dirty = True # Mark flat manifest dirty after parsing
698 self._dirty = True # Mark flat manifest dirty after parsing
699
699
700 def _subpath(self, path):
700 def _subpath(self, path):
701 return self._dir + path
701 return self._dir + path
702
702
703 def _loadalllazy(self):
703 def _loadalllazy(self):
704 for k, (path, node, readsubtree) in self._lazydirs.iteritems():
704 for k, (path, node, readsubtree) in self._lazydirs.iteritems():
705 self._dirs[k] = readsubtree(path, node)
705 self._dirs[k] = readsubtree(path, node)
706 self._lazydirs = {}
706 self._lazydirs = {}
707
707
708 def _loadlazy(self, d):
708 def _loadlazy(self, d):
709 path, node, readsubtree = self._lazydirs[d]
709 path, node, readsubtree = self._lazydirs[d]
710 self._dirs[d] = readsubtree(path, node)
710 self._dirs[d] = readsubtree(path, node)
711 del self._lazydirs[d]
711 del self._lazydirs[d]
712
712
713 def _loadchildrensetlazy(self, visit):
713 def _loadchildrensetlazy(self, visit):
714 if not visit:
714 if not visit:
715 return None
715 return None
716 if visit == 'all' or visit == 'this':
716 if visit == 'all' or visit == 'this':
717 self._loadalllazy()
717 self._loadalllazy()
718 return None
718 return None
719
719
720 todel = []
720 todel = []
721 for k in visit:
721 for k in visit:
722 kslash = k + '/'
722 kslash = k + '/'
723 ld = self._lazydirs.get(kslash)
723 ld = self._lazydirs.get(kslash)
724 if ld:
724 if ld:
725 path, node, readsubtree = ld
725 path, node, readsubtree = ld
726 self._dirs[kslash] = readsubtree(path, node)
726 self._dirs[kslash] = readsubtree(path, node)
727 todel.append(kslash)
727 todel.append(kslash)
728 for kslash in todel:
728 for kslash in todel:
729 del self._lazydirs[kslash]
729 del self._lazydirs[kslash]
730 return visit
730 return visit
731
731
732 def __len__(self):
732 def __len__(self):
733 self._load()
733 self._load()
734 size = len(self._files)
734 size = len(self._files)
735 self._loadalllazy()
735 self._loadalllazy()
736 for m in self._dirs.values():
736 for m in self._dirs.values():
737 size += m.__len__()
737 size += m.__len__()
738 return size
738 return size
739
739
740 def __nonzero__(self):
740 def __nonzero__(self):
741 # Faster than "__len() != 0" since it avoids loading sub-manifests
741 # Faster than "__len() != 0" since it avoids loading sub-manifests
742 return not self._isempty()
742 return not self._isempty()
743
743
744 __bool__ = __nonzero__
744 __bool__ = __nonzero__
745
745
746 def _isempty(self):
746 def _isempty(self):
747 self._load() # for consistency; already loaded by all callers
747 self._load() # for consistency; already loaded by all callers
748 # See if we can skip loading everything.
748 # See if we can skip loading everything.
749 if self._files or (self._dirs and
749 if self._files or (self._dirs and
750 any(not m._isempty() for m in self._dirs.values())):
750 any(not m._isempty() for m in self._dirs.values())):
751 return False
751 return False
752 self._loadalllazy()
752 self._loadalllazy()
753 return (not self._dirs or
753 return (not self._dirs or
754 all(m._isempty() for m in self._dirs.values()))
754 all(m._isempty() for m in self._dirs.values()))
755
755
756 def __repr__(self):
756 def __repr__(self):
757 return ('<treemanifest dir=%s, node=%s, loaded=%s, dirty=%s at 0x%x>' %
757 return ('<treemanifest dir=%s, node=%s, loaded=%s, dirty=%s at 0x%x>' %
758 (self._dir, hex(self._node),
758 (self._dir, hex(self._node),
759 bool(self._loadfunc is _noop),
759 bool(self._loadfunc is _noop),
760 self._dirty, id(self)))
760 self._dirty, id(self)))
761
761
762 def dir(self):
762 def dir(self):
763 '''The directory that this tree manifest represents, including a
763 '''The directory that this tree manifest represents, including a
764 trailing '/'. Empty string for the repo root directory.'''
764 trailing '/'. Empty string for the repo root directory.'''
765 return self._dir
765 return self._dir
766
766
767 def node(self):
767 def node(self):
768 '''This node of this instance. nullid for unsaved instances. Should
768 '''This node of this instance. nullid for unsaved instances. Should
769 be updated when the instance is read or written from a revlog.
769 be updated when the instance is read or written from a revlog.
770 '''
770 '''
771 assert not self._dirty
771 assert not self._dirty
772 return self._node
772 return self._node
773
773
774 def setnode(self, node):
774 def setnode(self, node):
775 self._node = node
775 self._node = node
776 self._dirty = False
776 self._dirty = False
777
777
778 def iterentries(self):
778 def iterentries(self):
779 self._load()
779 self._load()
780 self._loadalllazy()
780 self._loadalllazy()
781 for p, n in sorted(itertools.chain(self._dirs.items(),
781 for p, n in sorted(itertools.chain(self._dirs.items(),
782 self._files.items())):
782 self._files.items())):
783 if p in self._files:
783 if p in self._files:
784 yield self._subpath(p), n, self._flags.get(p, '')
784 yield self._subpath(p), n, self._flags.get(p, '')
785 else:
785 else:
786 for x in n.iterentries():
786 for x in n.iterentries():
787 yield x
787 yield x
788
788
789 def items(self):
789 def items(self):
790 self._load()
790 self._load()
791 self._loadalllazy()
791 self._loadalllazy()
792 for p, n in sorted(itertools.chain(self._dirs.items(),
792 for p, n in sorted(itertools.chain(self._dirs.items(),
793 self._files.items())):
793 self._files.items())):
794 if p in self._files:
794 if p in self._files:
795 yield self._subpath(p), n
795 yield self._subpath(p), n
796 else:
796 else:
797 for f, sn in n.iteritems():
797 for f, sn in n.iteritems():
798 yield f, sn
798 yield f, sn
799
799
800 iteritems = items
800 iteritems = items
801
801
802 def iterkeys(self):
802 def iterkeys(self):
803 self._load()
803 self._load()
804 self._loadalllazy()
804 self._loadalllazy()
805 for p in sorted(itertools.chain(self._dirs, self._files)):
805 for p in sorted(itertools.chain(self._dirs, self._files)):
806 if p in self._files:
806 if p in self._files:
807 yield self._subpath(p)
807 yield self._subpath(p)
808 else:
808 else:
809 for f in self._dirs[p]:
809 for f in self._dirs[p]:
810 yield f
810 yield f
811
811
812 def keys(self):
812 def keys(self):
813 return list(self.iterkeys())
813 return list(self.iterkeys())
814
814
815 def __iter__(self):
815 def __iter__(self):
816 return self.iterkeys()
816 return self.iterkeys()
817
817
818 def __contains__(self, f):
818 def __contains__(self, f):
819 if f is None:
819 if f is None:
820 return False
820 return False
821 self._load()
821 self._load()
822 dir, subpath = _splittopdir(f)
822 dir, subpath = _splittopdir(f)
823 if dir:
823 if dir:
824 if dir in self._lazydirs:
824 if dir in self._lazydirs:
825 self._loadlazy(dir)
825 self._loadlazy(dir)
826
826
827 if dir not in self._dirs:
827 if dir not in self._dirs:
828 return False
828 return False
829
829
830 return self._dirs[dir].__contains__(subpath)
830 return self._dirs[dir].__contains__(subpath)
831 else:
831 else:
832 return f in self._files
832 return f in self._files
833
833
834 def get(self, f, default=None):
834 def get(self, f, default=None):
835 self._load()
835 self._load()
836 dir, subpath = _splittopdir(f)
836 dir, subpath = _splittopdir(f)
837 if dir:
837 if dir:
838 if dir in self._lazydirs:
838 if dir in self._lazydirs:
839 self._loadlazy(dir)
839 self._loadlazy(dir)
840
840
841 if dir not in self._dirs:
841 if dir not in self._dirs:
842 return default
842 return default
843 return self._dirs[dir].get(subpath, default)
843 return self._dirs[dir].get(subpath, default)
844 else:
844 else:
845 return self._files.get(f, default)
845 return self._files.get(f, default)
846
846
847 def __getitem__(self, f):
847 def __getitem__(self, f):
848 self._load()
848 self._load()
849 dir, subpath = _splittopdir(f)
849 dir, subpath = _splittopdir(f)
850 if dir:
850 if dir:
851 if dir in self._lazydirs:
851 if dir in self._lazydirs:
852 self._loadlazy(dir)
852 self._loadlazy(dir)
853
853
854 return self._dirs[dir].__getitem__(subpath)
854 return self._dirs[dir].__getitem__(subpath)
855 else:
855 else:
856 return self._files[f]
856 return self._files[f]
857
857
858 def flags(self, f):
858 def flags(self, f):
859 self._load()
859 self._load()
860 dir, subpath = _splittopdir(f)
860 dir, subpath = _splittopdir(f)
861 if dir:
861 if dir:
862 if dir in self._lazydirs:
862 if dir in self._lazydirs:
863 self._loadlazy(dir)
863 self._loadlazy(dir)
864
864
865 if dir not in self._dirs:
865 if dir not in self._dirs:
866 return ''
866 return ''
867 return self._dirs[dir].flags(subpath)
867 return self._dirs[dir].flags(subpath)
868 else:
868 else:
869 if f in self._lazydirs or f in self._dirs:
869 if f in self._lazydirs or f in self._dirs:
870 return ''
870 return ''
871 return self._flags.get(f, '')
871 return self._flags.get(f, '')
872
872
873 def find(self, f):
873 def find(self, f):
874 self._load()
874 self._load()
875 dir, subpath = _splittopdir(f)
875 dir, subpath = _splittopdir(f)
876 if dir:
876 if dir:
877 if dir in self._lazydirs:
877 if dir in self._lazydirs:
878 self._loadlazy(dir)
878 self._loadlazy(dir)
879
879
880 return self._dirs[dir].find(subpath)
880 return self._dirs[dir].find(subpath)
881 else:
881 else:
882 return self._files[f], self._flags.get(f, '')
882 return self._files[f], self._flags.get(f, '')
883
883
884 def __delitem__(self, f):
884 def __delitem__(self, f):
885 self._load()
885 self._load()
886 dir, subpath = _splittopdir(f)
886 dir, subpath = _splittopdir(f)
887 if dir:
887 if dir:
888 if dir in self._lazydirs:
888 if dir in self._lazydirs:
889 self._loadlazy(dir)
889 self._loadlazy(dir)
890
890
891 self._dirs[dir].__delitem__(subpath)
891 self._dirs[dir].__delitem__(subpath)
892 # If the directory is now empty, remove it
892 # If the directory is now empty, remove it
893 if self._dirs[dir]._isempty():
893 if self._dirs[dir]._isempty():
894 del self._dirs[dir]
894 del self._dirs[dir]
895 else:
895 else:
896 del self._files[f]
896 del self._files[f]
897 if f in self._flags:
897 if f in self._flags:
898 del self._flags[f]
898 del self._flags[f]
899 self._dirty = True
899 self._dirty = True
900
900
901 def __setitem__(self, f, n):
901 def __setitem__(self, f, n):
902 assert n is not None
902 assert n is not None
903 self._load()
903 self._load()
904 dir, subpath = _splittopdir(f)
904 dir, subpath = _splittopdir(f)
905 if dir:
905 if dir:
906 if dir in self._lazydirs:
906 if dir in self._lazydirs:
907 self._loadlazy(dir)
907 self._loadlazy(dir)
908 if dir not in self._dirs:
908 if dir not in self._dirs:
909 self._dirs[dir] = treemanifest(self._subpath(dir))
909 self._dirs[dir] = treemanifest(self._subpath(dir))
910 self._dirs[dir].__setitem__(subpath, n)
910 self._dirs[dir].__setitem__(subpath, n)
911 else:
911 else:
912 self._files[f] = n[:21] # to match manifestdict's behavior
912 self._files[f] = n[:21] # to match manifestdict's behavior
913 self._dirty = True
913 self._dirty = True
914
914
915 def _load(self):
915 def _load(self):
916 if self._loadfunc is not _noop:
916 if self._loadfunc is not _noop:
917 lf, self._loadfunc = self._loadfunc, _noop
917 lf, self._loadfunc = self._loadfunc, _noop
918 lf(self)
918 lf(self)
919 elif self._copyfunc is not _noop:
919 elif self._copyfunc is not _noop:
920 cf, self._copyfunc = self._copyfunc, _noop
920 cf, self._copyfunc = self._copyfunc, _noop
921 cf(self)
921 cf(self)
922
922
923 def setflag(self, f, flags):
923 def setflag(self, f, flags):
924 """Set the flags (symlink, executable) for path f."""
924 """Set the flags (symlink, executable) for path f."""
925 self._load()
925 self._load()
926 dir, subpath = _splittopdir(f)
926 dir, subpath = _splittopdir(f)
927 if dir:
927 if dir:
928 if dir in self._lazydirs:
928 if dir in self._lazydirs:
929 self._loadlazy(dir)
929 self._loadlazy(dir)
930 if dir not in self._dirs:
930 if dir not in self._dirs:
931 self._dirs[dir] = treemanifest(self._subpath(dir))
931 self._dirs[dir] = treemanifest(self._subpath(dir))
932 self._dirs[dir].setflag(subpath, flags)
932 self._dirs[dir].setflag(subpath, flags)
933 else:
933 else:
934 self._flags[f] = flags
934 self._flags[f] = flags
935 self._dirty = True
935 self._dirty = True
936
936
937 def copy(self):
937 def copy(self):
938 copy = treemanifest(self._dir)
938 copy = treemanifest(self._dir)
939 copy._node = self._node
939 copy._node = self._node
940 copy._dirty = self._dirty
940 copy._dirty = self._dirty
941 if self._copyfunc is _noop:
941 if self._copyfunc is _noop:
942 def _copyfunc(s):
942 def _copyfunc(s):
943 self._load()
943 self._load()
944 # OPT: it'd be nice to not load everything here. Unfortunately
944 # OPT: it'd be nice to not load everything here. Unfortunately
945 # this makes a mess of the "dirty" state tracking if we don't.
945 # this makes a mess of the "dirty" state tracking if we don't.
946 self._loadalllazy()
946 self._loadalllazy()
947 sdirs = s._dirs
947 sdirs = s._dirs
948 for d, v in self._dirs.iteritems():
948 for d, v in self._dirs.iteritems():
949 sdirs[d] = v.copy()
949 sdirs[d] = v.copy()
950 s._files = dict.copy(self._files)
950 s._files = dict.copy(self._files)
951 s._flags = dict.copy(self._flags)
951 s._flags = dict.copy(self._flags)
952 if self._loadfunc is _noop:
952 if self._loadfunc is _noop:
953 _copyfunc(copy)
953 _copyfunc(copy)
954 else:
954 else:
955 copy._copyfunc = _copyfunc
955 copy._copyfunc = _copyfunc
956 else:
956 else:
957 copy._copyfunc = self._copyfunc
957 copy._copyfunc = self._copyfunc
958 return copy
958 return copy
959
959
960 def filesnotin(self, m2, match=None):
960 def filesnotin(self, m2, match=None):
961 '''Set of files in this manifest that are not in the other'''
961 '''Set of files in this manifest that are not in the other'''
962 if match and not match.always():
962 if match and not match.always():
963 m1 = self.matches(match)
963 m1 = self.matches(match)
964 m2 = m2.matches(match)
964 m2 = m2.matches(match)
965 return m1.filesnotin(m2)
965 return m1.filesnotin(m2)
966
966
967 files = set()
967 files = set()
968 def _filesnotin(t1, t2):
968 def _filesnotin(t1, t2):
969 if t1._node == t2._node and not t1._dirty and not t2._dirty:
969 if t1._node == t2._node and not t1._dirty and not t2._dirty:
970 return
970 return
971 t1._load()
971 t1._load()
972 t2._load()
972 t2._load()
973 t1._loadalllazy()
973 t1._loadalllazy()
974 t2._loadalllazy()
974 t2._loadalllazy()
975 for d, m1 in t1._dirs.iteritems():
975 for d, m1 in t1._dirs.iteritems():
976 if d in t2._dirs:
976 if d in t2._dirs:
977 m2 = t2._dirs[d]
977 m2 = t2._dirs[d]
978 _filesnotin(m1, m2)
978 _filesnotin(m1, m2)
979 else:
979 else:
980 files.update(m1.iterkeys())
980 files.update(m1.iterkeys())
981
981
982 for fn in t1._files:
982 for fn in t1._files:
983 if fn not in t2._files:
983 if fn not in t2._files:
984 files.add(t1._subpath(fn))
984 files.add(t1._subpath(fn))
985
985
986 _filesnotin(self, m2)
986 _filesnotin(self, m2)
987 return files
987 return files
988
988
989 @propertycache
989 @propertycache
990 def _alldirs(self):
990 def _alldirs(self):
991 return util.dirs(self)
991 return util.dirs(self)
992
992
993 def dirs(self):
993 def dirs(self):
994 return self._alldirs
994 return self._alldirs
995
995
996 def hasdir(self, dir):
996 def hasdir(self, dir):
997 self._load()
997 self._load()
998 topdir, subdir = _splittopdir(dir)
998 topdir, subdir = _splittopdir(dir)
999 if topdir:
999 if topdir:
1000 if topdir in self._lazydirs:
1000 if topdir in self._lazydirs:
1001 self._loadlazy(topdir)
1001 self._loadlazy(topdir)
1002 if topdir in self._dirs:
1002 if topdir in self._dirs:
1003 return self._dirs[topdir].hasdir(subdir)
1003 return self._dirs[topdir].hasdir(subdir)
1004 return False
1004 return False
1005 dirslash = dir + '/'
1005 dirslash = dir + '/'
1006 return dirslash in self._dirs or dirslash in self._lazydirs
1006 return dirslash in self._dirs or dirslash in self._lazydirs
1007
1007
1008 def walk(self, match):
1008 def walk(self, match):
1009 '''Generates matching file names.
1009 '''Generates matching file names.
1010
1010
1011 Equivalent to manifest.matches(match).iterkeys(), but without creating
1011 Equivalent to manifest.matches(match).iterkeys(), but without creating
1012 an entirely new manifest.
1012 an entirely new manifest.
1013
1013
1014 It also reports nonexistent files by marking them bad with match.bad().
1014 It also reports nonexistent files by marking them bad with match.bad().
1015 '''
1015 '''
1016 if match.always():
1016 if match.always():
1017 for f in iter(self):
1017 for f in iter(self):
1018 yield f
1018 yield f
1019 return
1019 return
1020
1020
1021 fset = set(match.files())
1021 fset = set(match.files())
1022
1022
1023 for fn in self._walk(match):
1023 for fn in self._walk(match):
1024 if fn in fset:
1024 if fn in fset:
1025 # specified pattern is the exact name
1025 # specified pattern is the exact name
1026 fset.remove(fn)
1026 fset.remove(fn)
1027 yield fn
1027 yield fn
1028
1028
1029 # for dirstate.walk, files=['.'] means "walk the whole tree".
1029 # for dirstate.walk, files=['.'] means "walk the whole tree".
1030 # follow that here, too
1030 # follow that here, too
1031 fset.discard('.')
1031 fset.discard('.')
1032
1032
1033 for fn in sorted(fset):
1033 for fn in sorted(fset):
1034 if not self.hasdir(fn):
1034 if not self.hasdir(fn):
1035 match.bad(fn, None)
1035 match.bad(fn, None)
1036
1036
1037 def _walk(self, match):
1037 def _walk(self, match):
1038 '''Recursively generates matching file names for walk().'''
1038 '''Recursively generates matching file names for walk().'''
1039 visit = match.visitchildrenset(self._dir[:-1] or '.')
1039 visit = match.visitchildrenset(self._dir[:-1] or '.')
1040 if not visit:
1040 if not visit:
1041 return
1041 return
1042
1042
1043 # yield this dir's files and walk its submanifests
1043 # yield this dir's files and walk its submanifests
1044 self._load()
1044 self._load()
1045 visit = self._loadchildrensetlazy(visit)
1045 visit = self._loadchildrensetlazy(visit)
1046 for p in sorted(list(self._dirs) + list(self._files)):
1046 for p in sorted(list(self._dirs) + list(self._files)):
1047 if p in self._files:
1047 if p in self._files:
1048 fullp = self._subpath(p)
1048 fullp = self._subpath(p)
1049 if match(fullp):
1049 if match(fullp):
1050 yield fullp
1050 yield fullp
1051 else:
1051 else:
1052 if not visit or p[:-1] in visit:
1052 if not visit or p[:-1] in visit:
1053 for f in self._dirs[p]._walk(match):
1053 for f in self._dirs[p]._walk(match):
1054 yield f
1054 yield f
1055
1055
1056 def matches(self, match):
1056 def matches(self, match):
1057 '''generate a new manifest filtered by the match argument'''
1057 '''generate a new manifest filtered by the match argument'''
1058 if match.always():
1058 if match.always():
1059 return self.copy()
1059 return self.copy()
1060
1060
1061 return self._matches(match)
1061 return self._matches(match)
1062
1062
1063 def _matches(self, match):
1063 def _matches(self, match):
1064 '''recursively generate a new manifest filtered by the match argument.
1064 '''recursively generate a new manifest filtered by the match argument.
1065 '''
1065 '''
1066
1066
1067 visit = match.visitchildrenset(self._dir[:-1] or '.')
1067 visit = match.visitchildrenset(self._dir[:-1] or '.')
1068 if visit == 'all':
1068 if visit == 'all':
1069 return self.copy()
1069 return self.copy()
1070 ret = treemanifest(self._dir)
1070 ret = treemanifest(self._dir)
1071 if not visit:
1071 if not visit:
1072 return ret
1072 return ret
1073
1073
1074 self._load()
1074 self._load()
1075 for fn in self._files:
1075 for fn in self._files:
1076 # While visitchildrenset *usually* lists only subdirs, this is
1076 # While visitchildrenset *usually* lists only subdirs, this is
1077 # actually up to the matcher and may have some files in the set().
1077 # actually up to the matcher and may have some files in the set().
1078 # If visit == 'this', we should obviously look at the files in this
1078 # If visit == 'this', we should obviously look at the files in this
1079 # directory; if visit is a set, and fn is in it, we should inspect
1079 # directory; if visit is a set, and fn is in it, we should inspect
1080 # fn (but no need to inspect things not in the set).
1080 # fn (but no need to inspect things not in the set).
1081 if visit != 'this' and fn not in visit:
1081 if visit != 'this' and fn not in visit:
1082 continue
1082 continue
1083 fullp = self._subpath(fn)
1083 fullp = self._subpath(fn)
1084 # visitchildrenset isn't perfect, we still need to call the regular
1084 # visitchildrenset isn't perfect, we still need to call the regular
1085 # matcher code to further filter results.
1085 # matcher code to further filter results.
1086 if not match(fullp):
1086 if not match(fullp):
1087 continue
1087 continue
1088 ret._files[fn] = self._files[fn]
1088 ret._files[fn] = self._files[fn]
1089 if fn in self._flags:
1089 if fn in self._flags:
1090 ret._flags[fn] = self._flags[fn]
1090 ret._flags[fn] = self._flags[fn]
1091
1091
1092 visit = self._loadchildrensetlazy(visit)
1092 visit = self._loadchildrensetlazy(visit)
1093 for dir, subm in self._dirs.iteritems():
1093 for dir, subm in self._dirs.iteritems():
1094 if visit and dir[:-1] not in visit:
1094 if visit and dir[:-1] not in visit:
1095 continue
1095 continue
1096 m = subm._matches(match)
1096 m = subm._matches(match)
1097 if not m._isempty():
1097 if not m._isempty():
1098 ret._dirs[dir] = m
1098 ret._dirs[dir] = m
1099
1099
1100 if not ret._isempty():
1100 if not ret._isempty():
1101 ret._dirty = True
1101 ret._dirty = True
1102 return ret
1102 return ret
1103
1103
1104 def diff(self, m2, match=None, clean=False):
1104 def diff(self, m2, match=None, clean=False):
1105 '''Finds changes between the current manifest and m2.
1105 '''Finds changes between the current manifest and m2.
1106
1106
1107 Args:
1107 Args:
1108 m2: the manifest to which this manifest should be compared.
1108 m2: the manifest to which this manifest should be compared.
1109 clean: if true, include files unchanged between these manifests
1109 clean: if true, include files unchanged between these manifests
1110 with a None value in the returned dictionary.
1110 with a None value in the returned dictionary.
1111
1111
1112 The result is returned as a dict with filename as key and
1112 The result is returned as a dict with filename as key and
1113 values of the form ((n1,fl1),(n2,fl2)), where n1/n2 is the
1113 values of the form ((n1,fl1),(n2,fl2)), where n1/n2 is the
1114 nodeid in the current/other manifest and fl1/fl2 is the flag
1114 nodeid in the current/other manifest and fl1/fl2 is the flag
1115 in the current/other manifest. Where the file does not exist,
1115 in the current/other manifest. Where the file does not exist,
1116 the nodeid will be None and the flags will be the empty
1116 the nodeid will be None and the flags will be the empty
1117 string.
1117 string.
1118 '''
1118 '''
1119 if match and not match.always():
1119 if match and not match.always():
1120 m1 = self.matches(match)
1120 m1 = self.matches(match)
1121 m2 = m2.matches(match)
1121 m2 = m2.matches(match)
1122 return m1.diff(m2, clean=clean)
1122 return m1.diff(m2, clean=clean)
1123 result = {}
1123 result = {}
1124 emptytree = treemanifest()
1124 emptytree = treemanifest()
1125 def _diff(t1, t2):
1125 def _diff(t1, t2):
1126 if t1._node == t2._node and not t1._dirty and not t2._dirty:
1126 if t1._node == t2._node and not t1._dirty and not t2._dirty:
1127 return
1127 return
1128 t1._load()
1128 t1._load()
1129 t2._load()
1129 t2._load()
1130 # OPT: do we need to load everything?
1130 # OPT: do we need to load everything?
1131 t1._loadalllazy()
1131 t1._loadalllazy()
1132 t2._loadalllazy()
1132 t2._loadalllazy()
1133 for d, m1 in t1._dirs.iteritems():
1133 for d, m1 in t1._dirs.iteritems():
1134 m2 = t2._dirs.get(d, emptytree)
1134 m2 = t2._dirs.get(d, emptytree)
1135 _diff(m1, m2)
1135 _diff(m1, m2)
1136
1136
1137 for d, m2 in t2._dirs.iteritems():
1137 for d, m2 in t2._dirs.iteritems():
1138 if d not in t1._dirs:
1138 if d not in t1._dirs:
1139 _diff(emptytree, m2)
1139 _diff(emptytree, m2)
1140
1140
1141 for fn, n1 in t1._files.iteritems():
1141 for fn, n1 in t1._files.iteritems():
1142 fl1 = t1._flags.get(fn, '')
1142 fl1 = t1._flags.get(fn, '')
1143 n2 = t2._files.get(fn, None)
1143 n2 = t2._files.get(fn, None)
1144 fl2 = t2._flags.get(fn, '')
1144 fl2 = t2._flags.get(fn, '')
1145 if n1 != n2 or fl1 != fl2:
1145 if n1 != n2 or fl1 != fl2:
1146 result[t1._subpath(fn)] = ((n1, fl1), (n2, fl2))
1146 result[t1._subpath(fn)] = ((n1, fl1), (n2, fl2))
1147 elif clean:
1147 elif clean:
1148 result[t1._subpath(fn)] = None
1148 result[t1._subpath(fn)] = None
1149
1149
1150 for fn, n2 in t2._files.iteritems():
1150 for fn, n2 in t2._files.iteritems():
1151 if fn not in t1._files:
1151 if fn not in t1._files:
1152 fl2 = t2._flags.get(fn, '')
1152 fl2 = t2._flags.get(fn, '')
1153 result[t2._subpath(fn)] = ((None, ''), (n2, fl2))
1153 result[t2._subpath(fn)] = ((None, ''), (n2, fl2))
1154
1154
1155 _diff(self, m2)
1155 _diff(self, m2)
1156 return result
1156 return result
1157
1157
1158 def unmodifiedsince(self, m2):
1158 def unmodifiedsince(self, m2):
1159 return not self._dirty and not m2._dirty and self._node == m2._node
1159 return not self._dirty and not m2._dirty and self._node == m2._node
1160
1160
1161 def parse(self, text, readsubtree):
1161 def parse(self, text, readsubtree):
1162 selflazy = self._lazydirs
1162 selflazy = self._lazydirs
1163 subpath = self._subpath
1163 subpath = self._subpath
1164 for f, n, fl in _parse(text):
1164 for f, n, fl in _parse(text):
1165 if fl == 't':
1165 if fl == 't':
1166 f = f + '/'
1166 f = f + '/'
1167 selflazy[f] = (subpath(f), n, readsubtree)
1167 selflazy[f] = (subpath(f), n, readsubtree)
1168 elif '/' in f:
1168 elif '/' in f:
1169 # This is a flat manifest, so use __setitem__ and setflag rather
1169 # This is a flat manifest, so use __setitem__ and setflag rather
1170 # than assigning directly to _files and _flags, so we can
1170 # than assigning directly to _files and _flags, so we can
1171 # assign a path in a subdirectory, and to mark dirty (compared
1171 # assign a path in a subdirectory, and to mark dirty (compared
1172 # to nullid).
1172 # to nullid).
1173 self[f] = n
1173 self[f] = n
1174 if fl:
1174 if fl:
1175 self.setflag(f, fl)
1175 self.setflag(f, fl)
1176 else:
1176 else:
1177 # Assigning to _files and _flags avoids marking as dirty,
1177 # Assigning to _files and _flags avoids marking as dirty,
1178 # and should be a little faster.
1178 # and should be a little faster.
1179 self._files[f] = n
1179 self._files[f] = n
1180 if fl:
1180 if fl:
1181 self._flags[f] = fl
1181 self._flags[f] = fl
1182
1182
1183 def text(self):
1183 def text(self):
1184 """Get the full data of this manifest as a bytestring."""
1184 """Get the full data of this manifest as a bytestring."""
1185 self._load()
1185 self._load()
1186 return _text(self.iterentries())
1186 return _text(self.iterentries())
1187
1187
1188 def dirtext(self):
1188 def dirtext(self):
1189 """Get the full data of this directory as a bytestring. Make sure that
1189 """Get the full data of this directory as a bytestring. Make sure that
1190 any submanifests have been written first, so their nodeids are correct.
1190 any submanifests have been written first, so their nodeids are correct.
1191 """
1191 """
1192 self._load()
1192 self._load()
1193 flags = self.flags
1193 flags = self.flags
1194 lazydirs = [(d[:-1], node, 't') for
1194 lazydirs = [(d[:-1], node, 't') for
1195 d, (path, node, readsubtree) in self._lazydirs.iteritems()]
1195 d, (path, node, readsubtree) in self._lazydirs.iteritems()]
1196 dirs = [(d[:-1], self._dirs[d]._node, 't') for d in self._dirs]
1196 dirs = [(d[:-1], self._dirs[d]._node, 't') for d in self._dirs]
1197 files = [(f, self._files[f], flags(f)) for f in self._files]
1197 files = [(f, self._files[f], flags(f)) for f in self._files]
1198 return _text(sorted(dirs + files + lazydirs))
1198 return _text(sorted(dirs + files + lazydirs))
1199
1199
1200 def read(self, gettext, readsubtree):
1200 def read(self, gettext, readsubtree):
1201 def _load_for_read(s):
1201 def _load_for_read(s):
1202 s.parse(gettext(), readsubtree)
1202 s.parse(gettext(), readsubtree)
1203 s._dirty = False
1203 s._dirty = False
1204 self._loadfunc = _load_for_read
1204 self._loadfunc = _load_for_read
1205
1205
1206 def writesubtrees(self, m1, m2, writesubtree):
1206 def writesubtrees(self, m1, m2, writesubtree, match):
1207 self._load() # for consistency; should never have any effect here
1207 self._load() # for consistency; should never have any effect here
1208 m1._load()
1208 m1._load()
1209 m2._load()
1209 m2._load()
1210 emptytree = treemanifest()
1210 emptytree = treemanifest()
1211 def getnode(m, d):
1211 def getnode(m, d):
1212 ld = m._lazydirs.get(d)
1212 ld = m._lazydirs.get(d)
1213 if ld:
1213 if ld:
1214 return ld[1]
1214 return ld[1]
1215 return m._dirs.get(d, emptytree)._node
1215 return m._dirs.get(d, emptytree)._node
1216
1216
1217 # we should have always loaded everything by the time we get here for
1218 # `self`, but possibly not in `m1` or `m2`.
1219 assert not self._lazydirs
1220 # let's skip investigating things that `match` says we do not need.
1221 visit = match.visitchildrenset(self._dir[:-1] or '.')
1222 if visit == 'this' or visit == 'all':
1223 visit = None
1217 for d, subm in self._dirs.iteritems():
1224 for d, subm in self._dirs.iteritems():
1225 if visit and d[:-1] not in visit:
1226 continue
1218 subp1 = getnode(m1, d)
1227 subp1 = getnode(m1, d)
1219 subp2 = getnode(m2, d)
1228 subp2 = getnode(m2, d)
1220 if subp1 == nullid:
1229 if subp1 == nullid:
1221 subp1, subp2 = subp2, subp1
1230 subp1, subp2 = subp2, subp1
1222 writesubtree(subm, subp1, subp2)
1231 writesubtree(subm, subp1, subp2, match)
1223
1232
1224 def walksubtrees(self, matcher=None):
1233 def walksubtrees(self, matcher=None):
1225 """Returns an iterator of the subtrees of this manifest, including this
1234 """Returns an iterator of the subtrees of this manifest, including this
1226 manifest itself.
1235 manifest itself.
1227
1236
1228 If `matcher` is provided, it only returns subtrees that match.
1237 If `matcher` is provided, it only returns subtrees that match.
1229 """
1238 """
1230 if matcher and not matcher.visitdir(self._dir[:-1] or '.'):
1239 if matcher and not matcher.visitdir(self._dir[:-1] or '.'):
1231 return
1240 return
1232 if not matcher or matcher(self._dir[:-1]):
1241 if not matcher or matcher(self._dir[:-1]):
1233 yield self
1242 yield self
1234
1243
1235 self._load()
1244 self._load()
1236 # OPT: use visitchildrenset to avoid loading everything.
1245 # OPT: use visitchildrenset to avoid loading everything.
1237 self._loadalllazy()
1246 self._loadalllazy()
1238 for d, subm in self._dirs.iteritems():
1247 for d, subm in self._dirs.iteritems():
1239 for subtree in subm.walksubtrees(matcher=matcher):
1248 for subtree in subm.walksubtrees(matcher=matcher):
1240 yield subtree
1249 yield subtree
1241
1250
1242 class manifestfulltextcache(util.lrucachedict):
1251 class manifestfulltextcache(util.lrucachedict):
1243 """File-backed LRU cache for the manifest cache
1252 """File-backed LRU cache for the manifest cache
1244
1253
1245 File consists of entries, up to EOF:
1254 File consists of entries, up to EOF:
1246
1255
1247 - 20 bytes node, 4 bytes length, <length> manifest data
1256 - 20 bytes node, 4 bytes length, <length> manifest data
1248
1257
1249 These are written in reverse cache order (oldest to newest).
1258 These are written in reverse cache order (oldest to newest).
1250
1259
1251 """
1260 """
1252 def __init__(self, max):
1261 def __init__(self, max):
1253 super(manifestfulltextcache, self).__init__(max)
1262 super(manifestfulltextcache, self).__init__(max)
1254 self._dirty = False
1263 self._dirty = False
1255 self._read = False
1264 self._read = False
1256 self._opener = None
1265 self._opener = None
1257
1266
1258 def read(self):
1267 def read(self):
1259 if self._read or self._opener is None:
1268 if self._read or self._opener is None:
1260 return
1269 return
1261
1270
1262 try:
1271 try:
1263 with self._opener('manifestfulltextcache') as fp:
1272 with self._opener('manifestfulltextcache') as fp:
1264 set = super(manifestfulltextcache, self).__setitem__
1273 set = super(manifestfulltextcache, self).__setitem__
1265 # ignore trailing data, this is a cache, corruption is skipped
1274 # ignore trailing data, this is a cache, corruption is skipped
1266 while True:
1275 while True:
1267 node = fp.read(20)
1276 node = fp.read(20)
1268 if len(node) < 20:
1277 if len(node) < 20:
1269 break
1278 break
1270 try:
1279 try:
1271 size = struct.unpack('>L', fp.read(4))[0]
1280 size = struct.unpack('>L', fp.read(4))[0]
1272 except struct.error:
1281 except struct.error:
1273 break
1282 break
1274 value = bytearray(fp.read(size))
1283 value = bytearray(fp.read(size))
1275 if len(value) != size:
1284 if len(value) != size:
1276 break
1285 break
1277 set(node, value)
1286 set(node, value)
1278 except IOError:
1287 except IOError:
1279 # the file is allowed to be missing
1288 # the file is allowed to be missing
1280 pass
1289 pass
1281
1290
1282 self._read = True
1291 self._read = True
1283 self._dirty = False
1292 self._dirty = False
1284
1293
1285 def write(self):
1294 def write(self):
1286 if not self._dirty or self._opener is None:
1295 if not self._dirty or self._opener is None:
1287 return
1296 return
1288 # rotate backwards to the first used node
1297 # rotate backwards to the first used node
1289 with self._opener(
1298 with self._opener(
1290 'manifestfulltextcache', 'w', atomictemp=True, checkambig=True
1299 'manifestfulltextcache', 'w', atomictemp=True, checkambig=True
1291 ) as fp:
1300 ) as fp:
1292 node = self._head.prev
1301 node = self._head.prev
1293 while True:
1302 while True:
1294 if node.key in self._cache:
1303 if node.key in self._cache:
1295 fp.write(node.key)
1304 fp.write(node.key)
1296 fp.write(struct.pack('>L', len(node.value)))
1305 fp.write(struct.pack('>L', len(node.value)))
1297 fp.write(node.value)
1306 fp.write(node.value)
1298 if node is self._head:
1307 if node is self._head:
1299 break
1308 break
1300 node = node.prev
1309 node = node.prev
1301
1310
1302 def __len__(self):
1311 def __len__(self):
1303 if not self._read:
1312 if not self._read:
1304 self.read()
1313 self.read()
1305 return super(manifestfulltextcache, self).__len__()
1314 return super(manifestfulltextcache, self).__len__()
1306
1315
1307 def __contains__(self, k):
1316 def __contains__(self, k):
1308 if not self._read:
1317 if not self._read:
1309 self.read()
1318 self.read()
1310 return super(manifestfulltextcache, self).__contains__(k)
1319 return super(manifestfulltextcache, self).__contains__(k)
1311
1320
1312 def __iter__(self):
1321 def __iter__(self):
1313 if not self._read:
1322 if not self._read:
1314 self.read()
1323 self.read()
1315 return super(manifestfulltextcache, self).__iter__()
1324 return super(manifestfulltextcache, self).__iter__()
1316
1325
1317 def __getitem__(self, k):
1326 def __getitem__(self, k):
1318 if not self._read:
1327 if not self._read:
1319 self.read()
1328 self.read()
1320 # the cache lru order can change on read
1329 # the cache lru order can change on read
1321 setdirty = self._cache.get(k) is not self._head
1330 setdirty = self._cache.get(k) is not self._head
1322 value = super(manifestfulltextcache, self).__getitem__(k)
1331 value = super(manifestfulltextcache, self).__getitem__(k)
1323 if setdirty:
1332 if setdirty:
1324 self._dirty = True
1333 self._dirty = True
1325 return value
1334 return value
1326
1335
1327 def __setitem__(self, k, v):
1336 def __setitem__(self, k, v):
1328 if not self._read:
1337 if not self._read:
1329 self.read()
1338 self.read()
1330 super(manifestfulltextcache, self).__setitem__(k, v)
1339 super(manifestfulltextcache, self).__setitem__(k, v)
1331 self._dirty = True
1340 self._dirty = True
1332
1341
1333 def __delitem__(self, k):
1342 def __delitem__(self, k):
1334 if not self._read:
1343 if not self._read:
1335 self.read()
1344 self.read()
1336 super(manifestfulltextcache, self).__delitem__(k)
1345 super(manifestfulltextcache, self).__delitem__(k)
1337 self._dirty = True
1346 self._dirty = True
1338
1347
1339 def get(self, k, default=None):
1348 def get(self, k, default=None):
1340 if not self._read:
1349 if not self._read:
1341 self.read()
1350 self.read()
1342 return super(manifestfulltextcache, self).get(k, default=default)
1351 return super(manifestfulltextcache, self).get(k, default=default)
1343
1352
1344 def clear(self, clear_persisted_data=False):
1353 def clear(self, clear_persisted_data=False):
1345 super(manifestfulltextcache, self).clear()
1354 super(manifestfulltextcache, self).clear()
1346 if clear_persisted_data:
1355 if clear_persisted_data:
1347 self._dirty = True
1356 self._dirty = True
1348 self.write()
1357 self.write()
1349 self._read = False
1358 self._read = False
1350
1359
1351 @interfaceutil.implementer(repository.imanifeststorage)
1360 @interfaceutil.implementer(repository.imanifeststorage)
1352 class manifestrevlog(object):
1361 class manifestrevlog(object):
1353 '''A revlog that stores manifest texts. This is responsible for caching the
1362 '''A revlog that stores manifest texts. This is responsible for caching the
1354 full-text manifest contents.
1363 full-text manifest contents.
1355 '''
1364 '''
1356 def __init__(self, opener, tree='', dirlogcache=None, indexfile=None,
1365 def __init__(self, opener, tree='', dirlogcache=None, indexfile=None,
1357 treemanifest=False):
1366 treemanifest=False):
1358 """Constructs a new manifest revlog
1367 """Constructs a new manifest revlog
1359
1368
1360 `indexfile` - used by extensions to have two manifests at once, like
1369 `indexfile` - used by extensions to have two manifests at once, like
1361 when transitioning between flatmanifeset and treemanifests.
1370 when transitioning between flatmanifeset and treemanifests.
1362
1371
1363 `treemanifest` - used to indicate this is a tree manifest revlog. Opener
1372 `treemanifest` - used to indicate this is a tree manifest revlog. Opener
1364 options can also be used to make this a tree manifest revlog. The opener
1373 options can also be used to make this a tree manifest revlog. The opener
1365 option takes precedence, so if it is set to True, we ignore whatever
1374 option takes precedence, so if it is set to True, we ignore whatever
1366 value is passed in to the constructor.
1375 value is passed in to the constructor.
1367 """
1376 """
1368 # During normal operations, we expect to deal with not more than four
1377 # During normal operations, we expect to deal with not more than four
1369 # revs at a time (such as during commit --amend). When rebasing large
1378 # revs at a time (such as during commit --amend). When rebasing large
1370 # stacks of commits, the number can go up, hence the config knob below.
1379 # stacks of commits, the number can go up, hence the config knob below.
1371 cachesize = 4
1380 cachesize = 4
1372 optiontreemanifest = False
1381 optiontreemanifest = False
1373 opts = getattr(opener, 'options', None)
1382 opts = getattr(opener, 'options', None)
1374 if opts is not None:
1383 if opts is not None:
1375 cachesize = opts.get('manifestcachesize', cachesize)
1384 cachesize = opts.get('manifestcachesize', cachesize)
1376 optiontreemanifest = opts.get('treemanifest', False)
1385 optiontreemanifest = opts.get('treemanifest', False)
1377
1386
1378 self._treeondisk = optiontreemanifest or treemanifest
1387 self._treeondisk = optiontreemanifest or treemanifest
1379
1388
1380 self._fulltextcache = manifestfulltextcache(cachesize)
1389 self._fulltextcache = manifestfulltextcache(cachesize)
1381
1390
1382 if tree:
1391 if tree:
1383 assert self._treeondisk, 'opts is %r' % opts
1392 assert self._treeondisk, 'opts is %r' % opts
1384
1393
1385 if indexfile is None:
1394 if indexfile is None:
1386 indexfile = '00manifest.i'
1395 indexfile = '00manifest.i'
1387 if tree:
1396 if tree:
1388 indexfile = "meta/" + tree + indexfile
1397 indexfile = "meta/" + tree + indexfile
1389
1398
1390 self.tree = tree
1399 self.tree = tree
1391
1400
1392 # The dirlogcache is kept on the root manifest log
1401 # The dirlogcache is kept on the root manifest log
1393 if tree:
1402 if tree:
1394 self._dirlogcache = dirlogcache
1403 self._dirlogcache = dirlogcache
1395 else:
1404 else:
1396 self._dirlogcache = {'': self}
1405 self._dirlogcache = {'': self}
1397
1406
1398 self._revlog = revlog.revlog(opener, indexfile,
1407 self._revlog = revlog.revlog(opener, indexfile,
1399 # only root indexfile is cached
1408 # only root indexfile is cached
1400 checkambig=not bool(tree),
1409 checkambig=not bool(tree),
1401 mmaplargeindex=True)
1410 mmaplargeindex=True)
1402
1411
1403 self.index = self._revlog.index
1412 self.index = self._revlog.index
1404 self.version = self._revlog.version
1413 self.version = self._revlog.version
1405 self._generaldelta = self._revlog._generaldelta
1414 self._generaldelta = self._revlog._generaldelta
1406
1415
1407 def _setupmanifestcachehooks(self, repo):
1416 def _setupmanifestcachehooks(self, repo):
1408 """Persist the manifestfulltextcache on lock release"""
1417 """Persist the manifestfulltextcache on lock release"""
1409 if not util.safehasattr(repo, '_lockref'):
1418 if not util.safehasattr(repo, '_lockref'):
1410 return
1419 return
1411
1420
1412 self._fulltextcache._opener = repo.cachevfs
1421 self._fulltextcache._opener = repo.cachevfs
1413 reporef = weakref.ref(repo)
1422 reporef = weakref.ref(repo)
1414 manifestrevlogref = weakref.ref(self)
1423 manifestrevlogref = weakref.ref(self)
1415
1424
1416 def persistmanifestcache():
1425 def persistmanifestcache():
1417 repo = reporef()
1426 repo = reporef()
1418 self = manifestrevlogref()
1427 self = manifestrevlogref()
1419 if repo is None or self is None:
1428 if repo is None or self is None:
1420 return
1429 return
1421 if repo.manifestlog.getstorage(b'') is not self:
1430 if repo.manifestlog.getstorage(b'') is not self:
1422 # there's a different manifest in play now, abort
1431 # there's a different manifest in play now, abort
1423 return
1432 return
1424 self._fulltextcache.write()
1433 self._fulltextcache.write()
1425
1434
1426 if repo._currentlock(repo._lockref) is not None:
1435 if repo._currentlock(repo._lockref) is not None:
1427 repo._afterlock(persistmanifestcache)
1436 repo._afterlock(persistmanifestcache)
1428
1437
1429 @property
1438 @property
1430 def fulltextcache(self):
1439 def fulltextcache(self):
1431 return self._fulltextcache
1440 return self._fulltextcache
1432
1441
1433 def clearcaches(self, clear_persisted_data=False):
1442 def clearcaches(self, clear_persisted_data=False):
1434 self._revlog.clearcaches()
1443 self._revlog.clearcaches()
1435 self._fulltextcache.clear(clear_persisted_data=clear_persisted_data)
1444 self._fulltextcache.clear(clear_persisted_data=clear_persisted_data)
1436 self._dirlogcache = {self.tree: self}
1445 self._dirlogcache = {self.tree: self}
1437
1446
1438 def dirlog(self, d):
1447 def dirlog(self, d):
1439 if d:
1448 if d:
1440 assert self._treeondisk
1449 assert self._treeondisk
1441 if d not in self._dirlogcache:
1450 if d not in self._dirlogcache:
1442 mfrevlog = manifestrevlog(self.opener, d,
1451 mfrevlog = manifestrevlog(self.opener, d,
1443 self._dirlogcache,
1452 self._dirlogcache,
1444 treemanifest=self._treeondisk)
1453 treemanifest=self._treeondisk)
1445 self._dirlogcache[d] = mfrevlog
1454 self._dirlogcache[d] = mfrevlog
1446 return self._dirlogcache[d]
1455 return self._dirlogcache[d]
1447
1456
1448 def add(self, m, transaction, link, p1, p2, added, removed, readtree=None):
1457 def add(self, m, transaction, link, p1, p2, added, removed, readtree=None,
1458 match=None):
1449 if p1 in self.fulltextcache and util.safehasattr(m, 'fastdelta'):
1459 if p1 in self.fulltextcache and util.safehasattr(m, 'fastdelta'):
1450 # If our first parent is in the manifest cache, we can
1460 # If our first parent is in the manifest cache, we can
1451 # compute a delta here using properties we know about the
1461 # compute a delta here using properties we know about the
1452 # manifest up-front, which may save time later for the
1462 # manifest up-front, which may save time later for the
1453 # revlog layer.
1463 # revlog layer.
1454
1464
1455 _checkforbidden(added)
1465 _checkforbidden(added)
1456 # combine the changed lists into one sorted iterator
1466 # combine the changed lists into one sorted iterator
1457 work = heapq.merge([(x, False) for x in added],
1467 work = heapq.merge([(x, False) for x in added],
1458 [(x, True) for x in removed])
1468 [(x, True) for x in removed])
1459
1469
1460 arraytext, deltatext = m.fastdelta(self.fulltextcache[p1], work)
1470 arraytext, deltatext = m.fastdelta(self.fulltextcache[p1], work)
1461 cachedelta = self._revlog.rev(p1), deltatext
1471 cachedelta = self._revlog.rev(p1), deltatext
1462 text = util.buffer(arraytext)
1472 text = util.buffer(arraytext)
1463 n = self._revlog.addrevision(text, transaction, link, p1, p2,
1473 n = self._revlog.addrevision(text, transaction, link, p1, p2,
1464 cachedelta)
1474 cachedelta)
1465 else:
1475 else:
1466 # The first parent manifest isn't already loaded, so we'll
1476 # The first parent manifest isn't already loaded, so we'll
1467 # just encode a fulltext of the manifest and pass that
1477 # just encode a fulltext of the manifest and pass that
1468 # through to the revlog layer, and let it handle the delta
1478 # through to the revlog layer, and let it handle the delta
1469 # process.
1479 # process.
1470 if self._treeondisk:
1480 if self._treeondisk:
1471 assert readtree, "readtree must be set for treemanifest writes"
1481 assert readtree, "readtree must be set for treemanifest writes"
1482 assert match, "match must be specified for treemanifest writes"
1472 m1 = readtree(self.tree, p1)
1483 m1 = readtree(self.tree, p1)
1473 m2 = readtree(self.tree, p2)
1484 m2 = readtree(self.tree, p2)
1474 n = self._addtree(m, transaction, link, m1, m2, readtree)
1485 n = self._addtree(m, transaction, link, m1, m2, readtree,
1486 match=match)
1475 arraytext = None
1487 arraytext = None
1476 else:
1488 else:
1477 text = m.text()
1489 text = m.text()
1478 n = self._revlog.addrevision(text, transaction, link, p1, p2)
1490 n = self._revlog.addrevision(text, transaction, link, p1, p2)
1479 arraytext = bytearray(text)
1491 arraytext = bytearray(text)
1480
1492
1481 if arraytext is not None:
1493 if arraytext is not None:
1482 self.fulltextcache[n] = arraytext
1494 self.fulltextcache[n] = arraytext
1483
1495
1484 return n
1496 return n
1485
1497
1486 def _addtree(self, m, transaction, link, m1, m2, readtree):
1498 def _addtree(self, m, transaction, link, m1, m2, readtree, match):
1487 # If the manifest is unchanged compared to one parent,
1499 # If the manifest is unchanged compared to one parent,
1488 # don't write a new revision
1500 # don't write a new revision
1489 if self.tree != '' and (m.unmodifiedsince(m1) or m.unmodifiedsince(
1501 if self.tree != '' and (m.unmodifiedsince(m1) or m.unmodifiedsince(
1490 m2)):
1502 m2)):
1491 return m.node()
1503 return m.node()
1492 def writesubtree(subm, subp1, subp2):
1504 def writesubtree(subm, subp1, subp2, match):
1493 sublog = self.dirlog(subm.dir())
1505 sublog = self.dirlog(subm.dir())
1494 sublog.add(subm, transaction, link, subp1, subp2, None, None,
1506 sublog.add(subm, transaction, link, subp1, subp2, None, None,
1495 readtree=readtree)
1507 readtree=readtree, match=match)
1496 m.writesubtrees(m1, m2, writesubtree)
1508 m.writesubtrees(m1, m2, writesubtree, match)
1497 text = m.dirtext()
1509 text = m.dirtext()
1498 n = None
1510 n = None
1499 if self.tree != '':
1511 if self.tree != '':
1500 # Double-check whether contents are unchanged to one parent
1512 # Double-check whether contents are unchanged to one parent
1501 if text == m1.dirtext():
1513 if text == m1.dirtext():
1502 n = m1.node()
1514 n = m1.node()
1503 elif text == m2.dirtext():
1515 elif text == m2.dirtext():
1504 n = m2.node()
1516 n = m2.node()
1505
1517
1506 if not n:
1518 if not n:
1507 n = self._revlog.addrevision(text, transaction, link, m1.node(),
1519 n = self._revlog.addrevision(text, transaction, link, m1.node(),
1508 m2.node())
1520 m2.node())
1509
1521
1510 # Save nodeid so parent manifest can calculate its nodeid
1522 # Save nodeid so parent manifest can calculate its nodeid
1511 m.setnode(n)
1523 m.setnode(n)
1512 return n
1524 return n
1513
1525
1514 def __len__(self):
1526 def __len__(self):
1515 return len(self._revlog)
1527 return len(self._revlog)
1516
1528
1517 def __iter__(self):
1529 def __iter__(self):
1518 return self._revlog.__iter__()
1530 return self._revlog.__iter__()
1519
1531
1520 def rev(self, node):
1532 def rev(self, node):
1521 return self._revlog.rev(node)
1533 return self._revlog.rev(node)
1522
1534
1523 def node(self, rev):
1535 def node(self, rev):
1524 return self._revlog.node(rev)
1536 return self._revlog.node(rev)
1525
1537
1526 def lookup(self, value):
1538 def lookup(self, value):
1527 return self._revlog.lookup(value)
1539 return self._revlog.lookup(value)
1528
1540
1529 def parentrevs(self, rev):
1541 def parentrevs(self, rev):
1530 return self._revlog.parentrevs(rev)
1542 return self._revlog.parentrevs(rev)
1531
1543
1532 def parents(self, node):
1544 def parents(self, node):
1533 return self._revlog.parents(node)
1545 return self._revlog.parents(node)
1534
1546
1535 def linkrev(self, rev):
1547 def linkrev(self, rev):
1536 return self._revlog.linkrev(rev)
1548 return self._revlog.linkrev(rev)
1537
1549
1538 def checksize(self):
1550 def checksize(self):
1539 return self._revlog.checksize()
1551 return self._revlog.checksize()
1540
1552
1541 def revision(self, node, _df=None, raw=False):
1553 def revision(self, node, _df=None, raw=False):
1542 return self._revlog.revision(node, _df=_df, raw=raw)
1554 return self._revlog.revision(node, _df=_df, raw=raw)
1543
1555
1544 def revdiff(self, rev1, rev2):
1556 def revdiff(self, rev1, rev2):
1545 return self._revlog.revdiff(rev1, rev2)
1557 return self._revlog.revdiff(rev1, rev2)
1546
1558
1547 def cmp(self, node, text):
1559 def cmp(self, node, text):
1548 return self._revlog.cmp(node, text)
1560 return self._revlog.cmp(node, text)
1549
1561
1550 def deltaparent(self, rev):
1562 def deltaparent(self, rev):
1551 return self._revlog.deltaparent(rev)
1563 return self._revlog.deltaparent(rev)
1552
1564
1553 def emitrevisiondeltas(self, requests):
1565 def emitrevisiondeltas(self, requests):
1554 return self._revlog.emitrevisiondeltas(requests)
1566 return self._revlog.emitrevisiondeltas(requests)
1555
1567
1556 def addgroup(self, deltas, linkmapper, transaction, addrevisioncb=None):
1568 def addgroup(self, deltas, linkmapper, transaction, addrevisioncb=None):
1557 return self._revlog.addgroup(deltas, linkmapper, transaction,
1569 return self._revlog.addgroup(deltas, linkmapper, transaction,
1558 addrevisioncb=addrevisioncb)
1570 addrevisioncb=addrevisioncb)
1559
1571
1560 def getstrippoint(self, minlink):
1572 def getstrippoint(self, minlink):
1561 return self._revlog.getstrippoint(minlink)
1573 return self._revlog.getstrippoint(minlink)
1562
1574
1563 def strip(self, minlink, transaction):
1575 def strip(self, minlink, transaction):
1564 return self._revlog.strip(minlink, transaction)
1576 return self._revlog.strip(minlink, transaction)
1565
1577
1566 def files(self):
1578 def files(self):
1567 return self._revlog.files()
1579 return self._revlog.files()
1568
1580
1569 def clone(self, tr, destrevlog, **kwargs):
1581 def clone(self, tr, destrevlog, **kwargs):
1570 if not isinstance(destrevlog, manifestrevlog):
1582 if not isinstance(destrevlog, manifestrevlog):
1571 raise error.ProgrammingError('expected manifestrevlog to clone()')
1583 raise error.ProgrammingError('expected manifestrevlog to clone()')
1572
1584
1573 return self._revlog.clone(tr, destrevlog._revlog, **kwargs)
1585 return self._revlog.clone(tr, destrevlog._revlog, **kwargs)
1574
1586
1575 @property
1587 @property
1576 def indexfile(self):
1588 def indexfile(self):
1577 return self._revlog.indexfile
1589 return self._revlog.indexfile
1578
1590
1579 @indexfile.setter
1591 @indexfile.setter
1580 def indexfile(self, value):
1592 def indexfile(self, value):
1581 self._revlog.indexfile = value
1593 self._revlog.indexfile = value
1582
1594
1583 @property
1595 @property
1584 def opener(self):
1596 def opener(self):
1585 return self._revlog.opener
1597 return self._revlog.opener
1586
1598
1587 @opener.setter
1599 @opener.setter
1588 def opener(self, value):
1600 def opener(self, value):
1589 self._revlog.opener = value
1601 self._revlog.opener = value
1590
1602
1591 @interfaceutil.implementer(repository.imanifestlog)
1603 @interfaceutil.implementer(repository.imanifestlog)
1592 class manifestlog(object):
1604 class manifestlog(object):
1593 """A collection class representing the collection of manifest snapshots
1605 """A collection class representing the collection of manifest snapshots
1594 referenced by commits in the repository.
1606 referenced by commits in the repository.
1595
1607
1596 In this situation, 'manifest' refers to the abstract concept of a snapshot
1608 In this situation, 'manifest' refers to the abstract concept of a snapshot
1597 of the list of files in the given commit. Consumers of the output of this
1609 of the list of files in the given commit. Consumers of the output of this
1598 class do not care about the implementation details of the actual manifests
1610 class do not care about the implementation details of the actual manifests
1599 they receive (i.e. tree or flat or lazily loaded, etc)."""
1611 they receive (i.e. tree or flat or lazily loaded, etc)."""
1600 def __init__(self, opener, repo):
1612 def __init__(self, opener, repo):
1601 usetreemanifest = False
1613 usetreemanifest = False
1602 cachesize = 4
1614 cachesize = 4
1603
1615
1604 opts = getattr(opener, 'options', None)
1616 opts = getattr(opener, 'options', None)
1605 if opts is not None:
1617 if opts is not None:
1606 usetreemanifest = opts.get('treemanifest', usetreemanifest)
1618 usetreemanifest = opts.get('treemanifest', usetreemanifest)
1607 cachesize = opts.get('manifestcachesize', cachesize)
1619 cachesize = opts.get('manifestcachesize', cachesize)
1608
1620
1609 self._treemanifests = usetreemanifest
1621 self._treemanifests = usetreemanifest
1610
1622
1611 self._rootstore = repo._constructmanifest()
1623 self._rootstore = repo._constructmanifest()
1612 self._rootstore._setupmanifestcachehooks(repo)
1624 self._rootstore._setupmanifestcachehooks(repo)
1613 self._narrowmatch = repo.narrowmatch()
1625 self._narrowmatch = repo.narrowmatch()
1614
1626
1615 # A cache of the manifestctx or treemanifestctx for each directory
1627 # A cache of the manifestctx or treemanifestctx for each directory
1616 self._dirmancache = {}
1628 self._dirmancache = {}
1617 self._dirmancache[''] = util.lrucachedict(cachesize)
1629 self._dirmancache[''] = util.lrucachedict(cachesize)
1618
1630
1619 self._cachesize = cachesize
1631 self._cachesize = cachesize
1620
1632
1621 def __getitem__(self, node):
1633 def __getitem__(self, node):
1622 """Retrieves the manifest instance for the given node. Throws a
1634 """Retrieves the manifest instance for the given node. Throws a
1623 LookupError if not found.
1635 LookupError if not found.
1624 """
1636 """
1625 return self.get('', node)
1637 return self.get('', node)
1626
1638
1627 def get(self, tree, node, verify=True):
1639 def get(self, tree, node, verify=True):
1628 """Retrieves the manifest instance for the given node. Throws a
1640 """Retrieves the manifest instance for the given node. Throws a
1629 LookupError if not found.
1641 LookupError if not found.
1630
1642
1631 `verify` - if True an exception will be thrown if the node is not in
1643 `verify` - if True an exception will be thrown if the node is not in
1632 the revlog
1644 the revlog
1633 """
1645 """
1634 if node in self._dirmancache.get(tree, ()):
1646 if node in self._dirmancache.get(tree, ()):
1635 return self._dirmancache[tree][node]
1647 return self._dirmancache[tree][node]
1636
1648
1637 if not self._narrowmatch.always():
1649 if not self._narrowmatch.always():
1638 if not self._narrowmatch.visitdir(tree[:-1] or '.'):
1650 if not self._narrowmatch.visitdir(tree[:-1] or '.'):
1639 return excludeddirmanifestctx(tree, node)
1651 return excludeddirmanifestctx(tree, node)
1640 if tree:
1652 if tree:
1641 if self._rootstore._treeondisk:
1653 if self._rootstore._treeondisk:
1642 if verify:
1654 if verify:
1643 # Side-effect is LookupError is raised if node doesn't
1655 # Side-effect is LookupError is raised if node doesn't
1644 # exist.
1656 # exist.
1645 self.getstorage(tree).rev(node)
1657 self.getstorage(tree).rev(node)
1646
1658
1647 m = treemanifestctx(self, tree, node)
1659 m = treemanifestctx(self, tree, node)
1648 else:
1660 else:
1649 raise error.Abort(
1661 raise error.Abort(
1650 _("cannot ask for manifest directory '%s' in a flat "
1662 _("cannot ask for manifest directory '%s' in a flat "
1651 "manifest") % tree)
1663 "manifest") % tree)
1652 else:
1664 else:
1653 if verify:
1665 if verify:
1654 # Side-effect is LookupError is raised if node doesn't exist.
1666 # Side-effect is LookupError is raised if node doesn't exist.
1655 self._rootstore.rev(node)
1667 self._rootstore.rev(node)
1656
1668
1657 if self._treemanifests:
1669 if self._treemanifests:
1658 m = treemanifestctx(self, '', node)
1670 m = treemanifestctx(self, '', node)
1659 else:
1671 else:
1660 m = manifestctx(self, node)
1672 m = manifestctx(self, node)
1661
1673
1662 if node != nullid:
1674 if node != nullid:
1663 mancache = self._dirmancache.get(tree)
1675 mancache = self._dirmancache.get(tree)
1664 if not mancache:
1676 if not mancache:
1665 mancache = util.lrucachedict(self._cachesize)
1677 mancache = util.lrucachedict(self._cachesize)
1666 self._dirmancache[tree] = mancache
1678 self._dirmancache[tree] = mancache
1667 mancache[node] = m
1679 mancache[node] = m
1668 return m
1680 return m
1669
1681
1670 def getstorage(self, tree):
1682 def getstorage(self, tree):
1671 return self._rootstore.dirlog(tree)
1683 return self._rootstore.dirlog(tree)
1672
1684
1673 def clearcaches(self, clear_persisted_data=False):
1685 def clearcaches(self, clear_persisted_data=False):
1674 self._dirmancache.clear()
1686 self._dirmancache.clear()
1675 self._rootstore.clearcaches(clear_persisted_data=clear_persisted_data)
1687 self._rootstore.clearcaches(clear_persisted_data=clear_persisted_data)
1676
1688
1677 def rev(self, node):
1689 def rev(self, node):
1678 return self._rootstore.rev(node)
1690 return self._rootstore.rev(node)
1679
1691
1680 @interfaceutil.implementer(repository.imanifestrevisionwritable)
1692 @interfaceutil.implementer(repository.imanifestrevisionwritable)
1681 class memmanifestctx(object):
1693 class memmanifestctx(object):
1682 def __init__(self, manifestlog):
1694 def __init__(self, manifestlog):
1683 self._manifestlog = manifestlog
1695 self._manifestlog = manifestlog
1684 self._manifestdict = manifestdict()
1696 self._manifestdict = manifestdict()
1685
1697
1686 def _storage(self):
1698 def _storage(self):
1687 return self._manifestlog.getstorage(b'')
1699 return self._manifestlog.getstorage(b'')
1688
1700
1689 def new(self):
1701 def new(self):
1690 return memmanifestctx(self._manifestlog)
1702 return memmanifestctx(self._manifestlog)
1691
1703
1692 def copy(self):
1704 def copy(self):
1693 memmf = memmanifestctx(self._manifestlog)
1705 memmf = memmanifestctx(self._manifestlog)
1694 memmf._manifestdict = self.read().copy()
1706 memmf._manifestdict = self.read().copy()
1695 return memmf
1707 return memmf
1696
1708
1697 def read(self):
1709 def read(self):
1698 return self._manifestdict
1710 return self._manifestdict
1699
1711
1700 def write(self, transaction, link, p1, p2, added, removed):
1712 def write(self, transaction, link, p1, p2, added, removed, match=None):
1701 return self._storage().add(self._manifestdict, transaction, link,
1713 return self._storage().add(self._manifestdict, transaction, link,
1702 p1, p2, added, removed)
1714 p1, p2, added, removed, match=match)
1703
1715
1704 @interfaceutil.implementer(repository.imanifestrevisionstored)
1716 @interfaceutil.implementer(repository.imanifestrevisionstored)
1705 class manifestctx(object):
1717 class manifestctx(object):
1706 """A class representing a single revision of a manifest, including its
1718 """A class representing a single revision of a manifest, including its
1707 contents, its parent revs, and its linkrev.
1719 contents, its parent revs, and its linkrev.
1708 """
1720 """
1709 def __init__(self, manifestlog, node):
1721 def __init__(self, manifestlog, node):
1710 self._manifestlog = manifestlog
1722 self._manifestlog = manifestlog
1711 self._data = None
1723 self._data = None
1712
1724
1713 self._node = node
1725 self._node = node
1714
1726
1715 # TODO: We eventually want p1, p2, and linkrev exposed on this class,
1727 # TODO: We eventually want p1, p2, and linkrev exposed on this class,
1716 # but let's add it later when something needs it and we can load it
1728 # but let's add it later when something needs it and we can load it
1717 # lazily.
1729 # lazily.
1718 #self.p1, self.p2 = store.parents(node)
1730 #self.p1, self.p2 = store.parents(node)
1719 #rev = store.rev(node)
1731 #rev = store.rev(node)
1720 #self.linkrev = store.linkrev(rev)
1732 #self.linkrev = store.linkrev(rev)
1721
1733
1722 def _storage(self):
1734 def _storage(self):
1723 return self._manifestlog.getstorage(b'')
1735 return self._manifestlog.getstorage(b'')
1724
1736
1725 def node(self):
1737 def node(self):
1726 return self._node
1738 return self._node
1727
1739
1728 def new(self):
1740 def new(self):
1729 return memmanifestctx(self._manifestlog)
1741 return memmanifestctx(self._manifestlog)
1730
1742
1731 def copy(self):
1743 def copy(self):
1732 memmf = memmanifestctx(self._manifestlog)
1744 memmf = memmanifestctx(self._manifestlog)
1733 memmf._manifestdict = self.read().copy()
1745 memmf._manifestdict = self.read().copy()
1734 return memmf
1746 return memmf
1735
1747
1736 @propertycache
1748 @propertycache
1737 def parents(self):
1749 def parents(self):
1738 return self._storage().parents(self._node)
1750 return self._storage().parents(self._node)
1739
1751
1740 def read(self):
1752 def read(self):
1741 if self._data is None:
1753 if self._data is None:
1742 if self._node == nullid:
1754 if self._node == nullid:
1743 self._data = manifestdict()
1755 self._data = manifestdict()
1744 else:
1756 else:
1745 store = self._storage()
1757 store = self._storage()
1746 if self._node in store.fulltextcache:
1758 if self._node in store.fulltextcache:
1747 text = pycompat.bytestr(store.fulltextcache[self._node])
1759 text = pycompat.bytestr(store.fulltextcache[self._node])
1748 else:
1760 else:
1749 text = store.revision(self._node)
1761 text = store.revision(self._node)
1750 arraytext = bytearray(text)
1762 arraytext = bytearray(text)
1751 store.fulltextcache[self._node] = arraytext
1763 store.fulltextcache[self._node] = arraytext
1752 self._data = manifestdict(text)
1764 self._data = manifestdict(text)
1753 return self._data
1765 return self._data
1754
1766
1755 def readfast(self, shallow=False):
1767 def readfast(self, shallow=False):
1756 '''Calls either readdelta or read, based on which would be less work.
1768 '''Calls either readdelta or read, based on which would be less work.
1757 readdelta is called if the delta is against the p1, and therefore can be
1769 readdelta is called if the delta is against the p1, and therefore can be
1758 read quickly.
1770 read quickly.
1759
1771
1760 If `shallow` is True, nothing changes since this is a flat manifest.
1772 If `shallow` is True, nothing changes since this is a flat manifest.
1761 '''
1773 '''
1762 store = self._storage()
1774 store = self._storage()
1763 r = store.rev(self._node)
1775 r = store.rev(self._node)
1764 deltaparent = store.deltaparent(r)
1776 deltaparent = store.deltaparent(r)
1765 if deltaparent != nullrev and deltaparent in store.parentrevs(r):
1777 if deltaparent != nullrev and deltaparent in store.parentrevs(r):
1766 return self.readdelta()
1778 return self.readdelta()
1767 return self.read()
1779 return self.read()
1768
1780
1769 def readdelta(self, shallow=False):
1781 def readdelta(self, shallow=False):
1770 '''Returns a manifest containing just the entries that are present
1782 '''Returns a manifest containing just the entries that are present
1771 in this manifest, but not in its p1 manifest. This is efficient to read
1783 in this manifest, but not in its p1 manifest. This is efficient to read
1772 if the revlog delta is already p1.
1784 if the revlog delta is already p1.
1773
1785
1774 Changing the value of `shallow` has no effect on flat manifests.
1786 Changing the value of `shallow` has no effect on flat manifests.
1775 '''
1787 '''
1776 store = self._storage()
1788 store = self._storage()
1777 r = store.rev(self._node)
1789 r = store.rev(self._node)
1778 d = mdiff.patchtext(store.revdiff(store.deltaparent(r), r))
1790 d = mdiff.patchtext(store.revdiff(store.deltaparent(r), r))
1779 return manifestdict(d)
1791 return manifestdict(d)
1780
1792
1781 def find(self, key):
1793 def find(self, key):
1782 return self.read().find(key)
1794 return self.read().find(key)
1783
1795
1784 @interfaceutil.implementer(repository.imanifestrevisionwritable)
1796 @interfaceutil.implementer(repository.imanifestrevisionwritable)
1785 class memtreemanifestctx(object):
1797 class memtreemanifestctx(object):
1786 def __init__(self, manifestlog, dir=''):
1798 def __init__(self, manifestlog, dir=''):
1787 self._manifestlog = manifestlog
1799 self._manifestlog = manifestlog
1788 self._dir = dir
1800 self._dir = dir
1789 self._treemanifest = treemanifest()
1801 self._treemanifest = treemanifest()
1790
1802
1791 def _storage(self):
1803 def _storage(self):
1792 return self._manifestlog.getstorage(b'')
1804 return self._manifestlog.getstorage(b'')
1793
1805
1794 def new(self, dir=''):
1806 def new(self, dir=''):
1795 return memtreemanifestctx(self._manifestlog, dir=dir)
1807 return memtreemanifestctx(self._manifestlog, dir=dir)
1796
1808
1797 def copy(self):
1809 def copy(self):
1798 memmf = memtreemanifestctx(self._manifestlog, dir=self._dir)
1810 memmf = memtreemanifestctx(self._manifestlog, dir=self._dir)
1799 memmf._treemanifest = self._treemanifest.copy()
1811 memmf._treemanifest = self._treemanifest.copy()
1800 return memmf
1812 return memmf
1801
1813
1802 def read(self):
1814 def read(self):
1803 return self._treemanifest
1815 return self._treemanifest
1804
1816
1805 def write(self, transaction, link, p1, p2, added, removed):
1817 def write(self, transaction, link, p1, p2, added, removed, match=None):
1806 def readtree(dir, node):
1818 def readtree(dir, node):
1807 return self._manifestlog.get(dir, node).read()
1819 return self._manifestlog.get(dir, node).read()
1808 return self._storage().add(self._treemanifest, transaction, link,
1820 return self._storage().add(self._treemanifest, transaction, link,
1809 p1, p2, added, removed, readtree=readtree)
1821 p1, p2, added, removed, readtree=readtree,
1822 match=match)
1810
1823
1811 @interfaceutil.implementer(repository.imanifestrevisionstored)
1824 @interfaceutil.implementer(repository.imanifestrevisionstored)
1812 class treemanifestctx(object):
1825 class treemanifestctx(object):
1813 def __init__(self, manifestlog, dir, node):
1826 def __init__(self, manifestlog, dir, node):
1814 self._manifestlog = manifestlog
1827 self._manifestlog = manifestlog
1815 self._dir = dir
1828 self._dir = dir
1816 self._data = None
1829 self._data = None
1817
1830
1818 self._node = node
1831 self._node = node
1819
1832
1820 # TODO: Load p1/p2/linkrev lazily. They need to be lazily loaded so that
1833 # TODO: Load p1/p2/linkrev lazily. They need to be lazily loaded so that
1821 # we can instantiate treemanifestctx objects for directories we don't
1834 # we can instantiate treemanifestctx objects for directories we don't
1822 # have on disk.
1835 # have on disk.
1823 #self.p1, self.p2 = store.parents(node)
1836 #self.p1, self.p2 = store.parents(node)
1824 #rev = store.rev(node)
1837 #rev = store.rev(node)
1825 #self.linkrev = store.linkrev(rev)
1838 #self.linkrev = store.linkrev(rev)
1826
1839
1827 def _storage(self):
1840 def _storage(self):
1828 narrowmatch = self._manifestlog._narrowmatch
1841 narrowmatch = self._manifestlog._narrowmatch
1829 if not narrowmatch.always():
1842 if not narrowmatch.always():
1830 if not narrowmatch.visitdir(self._dir[:-1] or '.'):
1843 if not narrowmatch.visitdir(self._dir[:-1] or '.'):
1831 return excludedmanifestrevlog(self._dir)
1844 return excludedmanifestrevlog(self._dir)
1832 return self._manifestlog.getstorage(self._dir)
1845 return self._manifestlog.getstorage(self._dir)
1833
1846
1834 def read(self):
1847 def read(self):
1835 if self._data is None:
1848 if self._data is None:
1836 store = self._storage()
1849 store = self._storage()
1837 if self._node == nullid:
1850 if self._node == nullid:
1838 self._data = treemanifest()
1851 self._data = treemanifest()
1839 # TODO accessing non-public API
1852 # TODO accessing non-public API
1840 elif store._treeondisk:
1853 elif store._treeondisk:
1841 m = treemanifest(dir=self._dir)
1854 m = treemanifest(dir=self._dir)
1842 def gettext():
1855 def gettext():
1843 return store.revision(self._node)
1856 return store.revision(self._node)
1844 def readsubtree(dir, subm):
1857 def readsubtree(dir, subm):
1845 # Set verify to False since we need to be able to create
1858 # Set verify to False since we need to be able to create
1846 # subtrees for trees that don't exist on disk.
1859 # subtrees for trees that don't exist on disk.
1847 return self._manifestlog.get(dir, subm, verify=False).read()
1860 return self._manifestlog.get(dir, subm, verify=False).read()
1848 m.read(gettext, readsubtree)
1861 m.read(gettext, readsubtree)
1849 m.setnode(self._node)
1862 m.setnode(self._node)
1850 self._data = m
1863 self._data = m
1851 else:
1864 else:
1852 if self._node in store.fulltextcache:
1865 if self._node in store.fulltextcache:
1853 text = pycompat.bytestr(store.fulltextcache[self._node])
1866 text = pycompat.bytestr(store.fulltextcache[self._node])
1854 else:
1867 else:
1855 text = store.revision(self._node)
1868 text = store.revision(self._node)
1856 arraytext = bytearray(text)
1869 arraytext = bytearray(text)
1857 store.fulltextcache[self._node] = arraytext
1870 store.fulltextcache[self._node] = arraytext
1858 self._data = treemanifest(dir=self._dir, text=text)
1871 self._data = treemanifest(dir=self._dir, text=text)
1859
1872
1860 return self._data
1873 return self._data
1861
1874
1862 def node(self):
1875 def node(self):
1863 return self._node
1876 return self._node
1864
1877
1865 def new(self, dir=''):
1878 def new(self, dir=''):
1866 return memtreemanifestctx(self._manifestlog, dir=dir)
1879 return memtreemanifestctx(self._manifestlog, dir=dir)
1867
1880
1868 def copy(self):
1881 def copy(self):
1869 memmf = memtreemanifestctx(self._manifestlog, dir=self._dir)
1882 memmf = memtreemanifestctx(self._manifestlog, dir=self._dir)
1870 memmf._treemanifest = self.read().copy()
1883 memmf._treemanifest = self.read().copy()
1871 return memmf
1884 return memmf
1872
1885
1873 @propertycache
1886 @propertycache
1874 def parents(self):
1887 def parents(self):
1875 return self._storage().parents(self._node)
1888 return self._storage().parents(self._node)
1876
1889
1877 def readdelta(self, shallow=False):
1890 def readdelta(self, shallow=False):
1878 '''Returns a manifest containing just the entries that are present
1891 '''Returns a manifest containing just the entries that are present
1879 in this manifest, but not in its p1 manifest. This is efficient to read
1892 in this manifest, but not in its p1 manifest. This is efficient to read
1880 if the revlog delta is already p1.
1893 if the revlog delta is already p1.
1881
1894
1882 If `shallow` is True, this will read the delta for this directory,
1895 If `shallow` is True, this will read the delta for this directory,
1883 without recursively reading subdirectory manifests. Instead, any
1896 without recursively reading subdirectory manifests. Instead, any
1884 subdirectory entry will be reported as it appears in the manifest, i.e.
1897 subdirectory entry will be reported as it appears in the manifest, i.e.
1885 the subdirectory will be reported among files and distinguished only by
1898 the subdirectory will be reported among files and distinguished only by
1886 its 't' flag.
1899 its 't' flag.
1887 '''
1900 '''
1888 store = self._storage()
1901 store = self._storage()
1889 if shallow:
1902 if shallow:
1890 r = store.rev(self._node)
1903 r = store.rev(self._node)
1891 d = mdiff.patchtext(store.revdiff(store.deltaparent(r), r))
1904 d = mdiff.patchtext(store.revdiff(store.deltaparent(r), r))
1892 return manifestdict(d)
1905 return manifestdict(d)
1893 else:
1906 else:
1894 # Need to perform a slow delta
1907 # Need to perform a slow delta
1895 r0 = store.deltaparent(store.rev(self._node))
1908 r0 = store.deltaparent(store.rev(self._node))
1896 m0 = self._manifestlog.get(self._dir, store.node(r0)).read()
1909 m0 = self._manifestlog.get(self._dir, store.node(r0)).read()
1897 m1 = self.read()
1910 m1 = self.read()
1898 md = treemanifest(dir=self._dir)
1911 md = treemanifest(dir=self._dir)
1899 for f, ((n0, fl0), (n1, fl1)) in m0.diff(m1).iteritems():
1912 for f, ((n0, fl0), (n1, fl1)) in m0.diff(m1).iteritems():
1900 if n1:
1913 if n1:
1901 md[f] = n1
1914 md[f] = n1
1902 if fl1:
1915 if fl1:
1903 md.setflag(f, fl1)
1916 md.setflag(f, fl1)
1904 return md
1917 return md
1905
1918
1906 def readfast(self, shallow=False):
1919 def readfast(self, shallow=False):
1907 '''Calls either readdelta or read, based on which would be less work.
1920 '''Calls either readdelta or read, based on which would be less work.
1908 readdelta is called if the delta is against the p1, and therefore can be
1921 readdelta is called if the delta is against the p1, and therefore can be
1909 read quickly.
1922 read quickly.
1910
1923
1911 If `shallow` is True, it only returns the entries from this manifest,
1924 If `shallow` is True, it only returns the entries from this manifest,
1912 and not any submanifests.
1925 and not any submanifests.
1913 '''
1926 '''
1914 store = self._storage()
1927 store = self._storage()
1915 r = store.rev(self._node)
1928 r = store.rev(self._node)
1916 deltaparent = store.deltaparent(r)
1929 deltaparent = store.deltaparent(r)
1917 if (deltaparent != nullrev and
1930 if (deltaparent != nullrev and
1918 deltaparent in store.parentrevs(r)):
1931 deltaparent in store.parentrevs(r)):
1919 return self.readdelta(shallow=shallow)
1932 return self.readdelta(shallow=shallow)
1920
1933
1921 if shallow:
1934 if shallow:
1922 return manifestdict(store.revision(self._node))
1935 return manifestdict(store.revision(self._node))
1923 else:
1936 else:
1924 return self.read()
1937 return self.read()
1925
1938
1926 def find(self, key):
1939 def find(self, key):
1927 return self.read().find(key)
1940 return self.read().find(key)
1928
1941
1929 class excludeddir(treemanifest):
1942 class excludeddir(treemanifest):
1930 """Stand-in for a directory that is excluded from the repository.
1943 """Stand-in for a directory that is excluded from the repository.
1931
1944
1932 With narrowing active on a repository that uses treemanifests,
1945 With narrowing active on a repository that uses treemanifests,
1933 some of the directory revlogs will be excluded from the resulting
1946 some of the directory revlogs will be excluded from the resulting
1934 clone. This is a huge storage win for clients, but means we need
1947 clone. This is a huge storage win for clients, but means we need
1935 some sort of pseudo-manifest to surface to internals so we can
1948 some sort of pseudo-manifest to surface to internals so we can
1936 detect a merge conflict outside the narrowspec. That's what this
1949 detect a merge conflict outside the narrowspec. That's what this
1937 class is: it stands in for a directory whose node is known, but
1950 class is: it stands in for a directory whose node is known, but
1938 whose contents are unknown.
1951 whose contents are unknown.
1939 """
1952 """
1940 def __init__(self, dir, node):
1953 def __init__(self, dir, node):
1941 super(excludeddir, self).__init__(dir)
1954 super(excludeddir, self).__init__(dir)
1942 self._node = node
1955 self._node = node
1943 # Add an empty file, which will be included by iterators and such,
1956 # Add an empty file, which will be included by iterators and such,
1944 # appearing as the directory itself (i.e. something like "dir/")
1957 # appearing as the directory itself (i.e. something like "dir/")
1945 self._files[''] = node
1958 self._files[''] = node
1946 self._flags[''] = 't'
1959 self._flags[''] = 't'
1947
1960
1948 # Manifests outside the narrowspec should never be modified, so avoid
1961 # Manifests outside the narrowspec should never be modified, so avoid
1949 # copying. This makes a noticeable difference when there are very many
1962 # copying. This makes a noticeable difference when there are very many
1950 # directories outside the narrowspec. Also, it makes sense for the copy to
1963 # directories outside the narrowspec. Also, it makes sense for the copy to
1951 # be of the same type as the original, which would not happen with the
1964 # be of the same type as the original, which would not happen with the
1952 # super type's copy().
1965 # super type's copy().
1953 def copy(self):
1966 def copy(self):
1954 return self
1967 return self
1955
1968
1956 class excludeddirmanifestctx(treemanifestctx):
1969 class excludeddirmanifestctx(treemanifestctx):
1957 """context wrapper for excludeddir - see that docstring for rationale"""
1970 """context wrapper for excludeddir - see that docstring for rationale"""
1958 def __init__(self, dir, node):
1971 def __init__(self, dir, node):
1959 self._dir = dir
1972 self._dir = dir
1960 self._node = node
1973 self._node = node
1961
1974
1962 def read(self):
1975 def read(self):
1963 return excludeddir(self._dir, self._node)
1976 return excludeddir(self._dir, self._node)
1964
1977
1965 def write(self, *args):
1978 def write(self, *args):
1966 raise error.ProgrammingError(
1979 raise error.ProgrammingError(
1967 'attempt to write manifest from excluded dir %s' % self._dir)
1980 'attempt to write manifest from excluded dir %s' % self._dir)
1968
1981
1969 class excludedmanifestrevlog(manifestrevlog):
1982 class excludedmanifestrevlog(manifestrevlog):
1970 """Stand-in for excluded treemanifest revlogs.
1983 """Stand-in for excluded treemanifest revlogs.
1971
1984
1972 When narrowing is active on a treemanifest repository, we'll have
1985 When narrowing is active on a treemanifest repository, we'll have
1973 references to directories we can't see due to the revlog being
1986 references to directories we can't see due to the revlog being
1974 skipped. This class exists to conform to the manifestrevlog
1987 skipped. This class exists to conform to the manifestrevlog
1975 interface for those directories and proactively prevent writes to
1988 interface for those directories and proactively prevent writes to
1976 outside the narrowspec.
1989 outside the narrowspec.
1977 """
1990 """
1978
1991
1979 def __init__(self, dir):
1992 def __init__(self, dir):
1980 self._dir = dir
1993 self._dir = dir
1981
1994
1982 def __len__(self):
1995 def __len__(self):
1983 raise error.ProgrammingError(
1996 raise error.ProgrammingError(
1984 'attempt to get length of excluded dir %s' % self._dir)
1997 'attempt to get length of excluded dir %s' % self._dir)
1985
1998
1986 def rev(self, node):
1999 def rev(self, node):
1987 raise error.ProgrammingError(
2000 raise error.ProgrammingError(
1988 'attempt to get rev from excluded dir %s' % self._dir)
2001 'attempt to get rev from excluded dir %s' % self._dir)
1989
2002
1990 def linkrev(self, node):
2003 def linkrev(self, node):
1991 raise error.ProgrammingError(
2004 raise error.ProgrammingError(
1992 'attempt to get linkrev from excluded dir %s' % self._dir)
2005 'attempt to get linkrev from excluded dir %s' % self._dir)
1993
2006
1994 def node(self, rev):
2007 def node(self, rev):
1995 raise error.ProgrammingError(
2008 raise error.ProgrammingError(
1996 'attempt to get node from excluded dir %s' % self._dir)
2009 'attempt to get node from excluded dir %s' % self._dir)
1997
2010
1998 def add(self, *args, **kwargs):
2011 def add(self, *args, **kwargs):
1999 # We should never write entries in dirlogs outside the narrow clone.
2012 # We should never write entries in dirlogs outside the narrow clone.
2000 # However, the method still gets called from writesubtree() in
2013 # However, the method still gets called from writesubtree() in
2001 # _addtree(), so we need to handle it. We should possibly make that
2014 # _addtree(), so we need to handle it. We should possibly make that
2002 # avoid calling add() with a clean manifest (_dirty is always False
2015 # avoid calling add() with a clean manifest (_dirty is always False
2003 # in excludeddir instances).
2016 # in excludeddir instances).
2004 pass
2017 pass
@@ -1,1565 +1,1580 b''
1 # repository.py - Interfaces and base classes for repositories and peers.
1 # repository.py - Interfaces and base classes for repositories and peers.
2 #
2 #
3 # Copyright 2017 Gregory Szorc <gregory.szorc@gmail.com>
3 # Copyright 2017 Gregory Szorc <gregory.szorc@gmail.com>
4 #
4 #
5 # This software may be used and distributed according to the terms of the
5 # This software may be used and distributed according to the terms of the
6 # GNU General Public License version 2 or any later version.
6 # GNU General Public License version 2 or any later version.
7
7
8 from __future__ import absolute_import
8 from __future__ import absolute_import
9
9
10 from .i18n import _
10 from .i18n import _
11 from . import (
11 from . import (
12 error,
12 error,
13 )
13 )
14 from .utils import (
14 from .utils import (
15 interfaceutil,
15 interfaceutil,
16 )
16 )
17
17
18 # When narrowing is finalized and no longer subject to format changes,
18 # When narrowing is finalized and no longer subject to format changes,
19 # we should move this to just "narrow" or similar.
19 # we should move this to just "narrow" or similar.
20 NARROW_REQUIREMENT = 'narrowhg-experimental'
20 NARROW_REQUIREMENT = 'narrowhg-experimental'
21
21
22 class ipeerconnection(interfaceutil.Interface):
22 class ipeerconnection(interfaceutil.Interface):
23 """Represents a "connection" to a repository.
23 """Represents a "connection" to a repository.
24
24
25 This is the base interface for representing a connection to a repository.
25 This is the base interface for representing a connection to a repository.
26 It holds basic properties and methods applicable to all peer types.
26 It holds basic properties and methods applicable to all peer types.
27
27
28 This is not a complete interface definition and should not be used
28 This is not a complete interface definition and should not be used
29 outside of this module.
29 outside of this module.
30 """
30 """
31 ui = interfaceutil.Attribute("""ui.ui instance""")
31 ui = interfaceutil.Attribute("""ui.ui instance""")
32
32
33 def url():
33 def url():
34 """Returns a URL string representing this peer.
34 """Returns a URL string representing this peer.
35
35
36 Currently, implementations expose the raw URL used to construct the
36 Currently, implementations expose the raw URL used to construct the
37 instance. It may contain credentials as part of the URL. The
37 instance. It may contain credentials as part of the URL. The
38 expectations of the value aren't well-defined and this could lead to
38 expectations of the value aren't well-defined and this could lead to
39 data leakage.
39 data leakage.
40
40
41 TODO audit/clean consumers and more clearly define the contents of this
41 TODO audit/clean consumers and more clearly define the contents of this
42 value.
42 value.
43 """
43 """
44
44
45 def local():
45 def local():
46 """Returns a local repository instance.
46 """Returns a local repository instance.
47
47
48 If the peer represents a local repository, returns an object that
48 If the peer represents a local repository, returns an object that
49 can be used to interface with it. Otherwise returns ``None``.
49 can be used to interface with it. Otherwise returns ``None``.
50 """
50 """
51
51
52 def peer():
52 def peer():
53 """Returns an object conforming to this interface.
53 """Returns an object conforming to this interface.
54
54
55 Most implementations will ``return self``.
55 Most implementations will ``return self``.
56 """
56 """
57
57
58 def canpush():
58 def canpush():
59 """Returns a boolean indicating if this peer can be pushed to."""
59 """Returns a boolean indicating if this peer can be pushed to."""
60
60
61 def close():
61 def close():
62 """Close the connection to this peer.
62 """Close the connection to this peer.
63
63
64 This is called when the peer will no longer be used. Resources
64 This is called when the peer will no longer be used. Resources
65 associated with the peer should be cleaned up.
65 associated with the peer should be cleaned up.
66 """
66 """
67
67
68 class ipeercapabilities(interfaceutil.Interface):
68 class ipeercapabilities(interfaceutil.Interface):
69 """Peer sub-interface related to capabilities."""
69 """Peer sub-interface related to capabilities."""
70
70
71 def capable(name):
71 def capable(name):
72 """Determine support for a named capability.
72 """Determine support for a named capability.
73
73
74 Returns ``False`` if capability not supported.
74 Returns ``False`` if capability not supported.
75
75
76 Returns ``True`` if boolean capability is supported. Returns a string
76 Returns ``True`` if boolean capability is supported. Returns a string
77 if capability support is non-boolean.
77 if capability support is non-boolean.
78
78
79 Capability strings may or may not map to wire protocol capabilities.
79 Capability strings may or may not map to wire protocol capabilities.
80 """
80 """
81
81
82 def requirecap(name, purpose):
82 def requirecap(name, purpose):
83 """Require a capability to be present.
83 """Require a capability to be present.
84
84
85 Raises a ``CapabilityError`` if the capability isn't present.
85 Raises a ``CapabilityError`` if the capability isn't present.
86 """
86 """
87
87
88 class ipeercommands(interfaceutil.Interface):
88 class ipeercommands(interfaceutil.Interface):
89 """Client-side interface for communicating over the wire protocol.
89 """Client-side interface for communicating over the wire protocol.
90
90
91 This interface is used as a gateway to the Mercurial wire protocol.
91 This interface is used as a gateway to the Mercurial wire protocol.
92 methods commonly call wire protocol commands of the same name.
92 methods commonly call wire protocol commands of the same name.
93 """
93 """
94
94
95 def branchmap():
95 def branchmap():
96 """Obtain heads in named branches.
96 """Obtain heads in named branches.
97
97
98 Returns a dict mapping branch name to an iterable of nodes that are
98 Returns a dict mapping branch name to an iterable of nodes that are
99 heads on that branch.
99 heads on that branch.
100 """
100 """
101
101
102 def capabilities():
102 def capabilities():
103 """Obtain capabilities of the peer.
103 """Obtain capabilities of the peer.
104
104
105 Returns a set of string capabilities.
105 Returns a set of string capabilities.
106 """
106 """
107
107
108 def clonebundles():
108 def clonebundles():
109 """Obtains the clone bundles manifest for the repo.
109 """Obtains the clone bundles manifest for the repo.
110
110
111 Returns the manifest as unparsed bytes.
111 Returns the manifest as unparsed bytes.
112 """
112 """
113
113
114 def debugwireargs(one, two, three=None, four=None, five=None):
114 def debugwireargs(one, two, three=None, four=None, five=None):
115 """Used to facilitate debugging of arguments passed over the wire."""
115 """Used to facilitate debugging of arguments passed over the wire."""
116
116
117 def getbundle(source, **kwargs):
117 def getbundle(source, **kwargs):
118 """Obtain remote repository data as a bundle.
118 """Obtain remote repository data as a bundle.
119
119
120 This command is how the bulk of repository data is transferred from
120 This command is how the bulk of repository data is transferred from
121 the peer to the local repository
121 the peer to the local repository
122
122
123 Returns a generator of bundle data.
123 Returns a generator of bundle data.
124 """
124 """
125
125
126 def heads():
126 def heads():
127 """Determine all known head revisions in the peer.
127 """Determine all known head revisions in the peer.
128
128
129 Returns an iterable of binary nodes.
129 Returns an iterable of binary nodes.
130 """
130 """
131
131
132 def known(nodes):
132 def known(nodes):
133 """Determine whether multiple nodes are known.
133 """Determine whether multiple nodes are known.
134
134
135 Accepts an iterable of nodes whose presence to check for.
135 Accepts an iterable of nodes whose presence to check for.
136
136
137 Returns an iterable of booleans indicating of the corresponding node
137 Returns an iterable of booleans indicating of the corresponding node
138 at that index is known to the peer.
138 at that index is known to the peer.
139 """
139 """
140
140
141 def listkeys(namespace):
141 def listkeys(namespace):
142 """Obtain all keys in a pushkey namespace.
142 """Obtain all keys in a pushkey namespace.
143
143
144 Returns an iterable of key names.
144 Returns an iterable of key names.
145 """
145 """
146
146
147 def lookup(key):
147 def lookup(key):
148 """Resolve a value to a known revision.
148 """Resolve a value to a known revision.
149
149
150 Returns a binary node of the resolved revision on success.
150 Returns a binary node of the resolved revision on success.
151 """
151 """
152
152
153 def pushkey(namespace, key, old, new):
153 def pushkey(namespace, key, old, new):
154 """Set a value using the ``pushkey`` protocol.
154 """Set a value using the ``pushkey`` protocol.
155
155
156 Arguments correspond to the pushkey namespace and key to operate on and
156 Arguments correspond to the pushkey namespace and key to operate on and
157 the old and new values for that key.
157 the old and new values for that key.
158
158
159 Returns a string with the peer result. The value inside varies by the
159 Returns a string with the peer result. The value inside varies by the
160 namespace.
160 namespace.
161 """
161 """
162
162
163 def stream_out():
163 def stream_out():
164 """Obtain streaming clone data.
164 """Obtain streaming clone data.
165
165
166 Successful result should be a generator of data chunks.
166 Successful result should be a generator of data chunks.
167 """
167 """
168
168
169 def unbundle(bundle, heads, url):
169 def unbundle(bundle, heads, url):
170 """Transfer repository data to the peer.
170 """Transfer repository data to the peer.
171
171
172 This is how the bulk of data during a push is transferred.
172 This is how the bulk of data during a push is transferred.
173
173
174 Returns the integer number of heads added to the peer.
174 Returns the integer number of heads added to the peer.
175 """
175 """
176
176
177 class ipeerlegacycommands(interfaceutil.Interface):
177 class ipeerlegacycommands(interfaceutil.Interface):
178 """Interface for implementing support for legacy wire protocol commands.
178 """Interface for implementing support for legacy wire protocol commands.
179
179
180 Wire protocol commands transition to legacy status when they are no longer
180 Wire protocol commands transition to legacy status when they are no longer
181 used by modern clients. To facilitate identifying which commands are
181 used by modern clients. To facilitate identifying which commands are
182 legacy, the interfaces are split.
182 legacy, the interfaces are split.
183 """
183 """
184
184
185 def between(pairs):
185 def between(pairs):
186 """Obtain nodes between pairs of nodes.
186 """Obtain nodes between pairs of nodes.
187
187
188 ``pairs`` is an iterable of node pairs.
188 ``pairs`` is an iterable of node pairs.
189
189
190 Returns an iterable of iterables of nodes corresponding to each
190 Returns an iterable of iterables of nodes corresponding to each
191 requested pair.
191 requested pair.
192 """
192 """
193
193
194 def branches(nodes):
194 def branches(nodes):
195 """Obtain ancestor changesets of specific nodes back to a branch point.
195 """Obtain ancestor changesets of specific nodes back to a branch point.
196
196
197 For each requested node, the peer finds the first ancestor node that is
197 For each requested node, the peer finds the first ancestor node that is
198 a DAG root or is a merge.
198 a DAG root or is a merge.
199
199
200 Returns an iterable of iterables with the resolved values for each node.
200 Returns an iterable of iterables with the resolved values for each node.
201 """
201 """
202
202
203 def changegroup(nodes, source):
203 def changegroup(nodes, source):
204 """Obtain a changegroup with data for descendants of specified nodes."""
204 """Obtain a changegroup with data for descendants of specified nodes."""
205
205
206 def changegroupsubset(bases, heads, source):
206 def changegroupsubset(bases, heads, source):
207 pass
207 pass
208
208
209 class ipeercommandexecutor(interfaceutil.Interface):
209 class ipeercommandexecutor(interfaceutil.Interface):
210 """Represents a mechanism to execute remote commands.
210 """Represents a mechanism to execute remote commands.
211
211
212 This is the primary interface for requesting that wire protocol commands
212 This is the primary interface for requesting that wire protocol commands
213 be executed. Instances of this interface are active in a context manager
213 be executed. Instances of this interface are active in a context manager
214 and have a well-defined lifetime. When the context manager exits, all
214 and have a well-defined lifetime. When the context manager exits, all
215 outstanding requests are waited on.
215 outstanding requests are waited on.
216 """
216 """
217
217
218 def callcommand(name, args):
218 def callcommand(name, args):
219 """Request that a named command be executed.
219 """Request that a named command be executed.
220
220
221 Receives the command name and a dictionary of command arguments.
221 Receives the command name and a dictionary of command arguments.
222
222
223 Returns a ``concurrent.futures.Future`` that will resolve to the
223 Returns a ``concurrent.futures.Future`` that will resolve to the
224 result of that command request. That exact value is left up to
224 result of that command request. That exact value is left up to
225 the implementation and possibly varies by command.
225 the implementation and possibly varies by command.
226
226
227 Not all commands can coexist with other commands in an executor
227 Not all commands can coexist with other commands in an executor
228 instance: it depends on the underlying wire protocol transport being
228 instance: it depends on the underlying wire protocol transport being
229 used and the command itself.
229 used and the command itself.
230
230
231 Implementations MAY call ``sendcommands()`` automatically if the
231 Implementations MAY call ``sendcommands()`` automatically if the
232 requested command can not coexist with other commands in this executor.
232 requested command can not coexist with other commands in this executor.
233
233
234 Implementations MAY call ``sendcommands()`` automatically when the
234 Implementations MAY call ``sendcommands()`` automatically when the
235 future's ``result()`` is called. So, consumers using multiple
235 future's ``result()`` is called. So, consumers using multiple
236 commands with an executor MUST ensure that ``result()`` is not called
236 commands with an executor MUST ensure that ``result()`` is not called
237 until all command requests have been issued.
237 until all command requests have been issued.
238 """
238 """
239
239
240 def sendcommands():
240 def sendcommands():
241 """Trigger submission of queued command requests.
241 """Trigger submission of queued command requests.
242
242
243 Not all transports submit commands as soon as they are requested to
243 Not all transports submit commands as soon as they are requested to
244 run. When called, this method forces queued command requests to be
244 run. When called, this method forces queued command requests to be
245 issued. It will no-op if all commands have already been sent.
245 issued. It will no-op if all commands have already been sent.
246
246
247 When called, no more new commands may be issued with this executor.
247 When called, no more new commands may be issued with this executor.
248 """
248 """
249
249
250 def close():
250 def close():
251 """Signal that this command request is finished.
251 """Signal that this command request is finished.
252
252
253 When called, no more new commands may be issued. All outstanding
253 When called, no more new commands may be issued. All outstanding
254 commands that have previously been issued are waited on before
254 commands that have previously been issued are waited on before
255 returning. This not only includes waiting for the futures to resolve,
255 returning. This not only includes waiting for the futures to resolve,
256 but also waiting for all response data to arrive. In other words,
256 but also waiting for all response data to arrive. In other words,
257 calling this waits for all on-wire state for issued command requests
257 calling this waits for all on-wire state for issued command requests
258 to finish.
258 to finish.
259
259
260 When used as a context manager, this method is called when exiting the
260 When used as a context manager, this method is called when exiting the
261 context manager.
261 context manager.
262
262
263 This method may call ``sendcommands()`` if there are buffered commands.
263 This method may call ``sendcommands()`` if there are buffered commands.
264 """
264 """
265
265
266 class ipeerrequests(interfaceutil.Interface):
266 class ipeerrequests(interfaceutil.Interface):
267 """Interface for executing commands on a peer."""
267 """Interface for executing commands on a peer."""
268
268
269 def commandexecutor():
269 def commandexecutor():
270 """A context manager that resolves to an ipeercommandexecutor.
270 """A context manager that resolves to an ipeercommandexecutor.
271
271
272 The object this resolves to can be used to issue command requests
272 The object this resolves to can be used to issue command requests
273 to the peer.
273 to the peer.
274
274
275 Callers should call its ``callcommand`` method to issue command
275 Callers should call its ``callcommand`` method to issue command
276 requests.
276 requests.
277
277
278 A new executor should be obtained for each distinct set of commands
278 A new executor should be obtained for each distinct set of commands
279 (possibly just a single command) that the consumer wants to execute
279 (possibly just a single command) that the consumer wants to execute
280 as part of a single operation or round trip. This is because some
280 as part of a single operation or round trip. This is because some
281 peers are half-duplex and/or don't support persistent connections.
281 peers are half-duplex and/or don't support persistent connections.
282 e.g. in the case of HTTP peers, commands sent to an executor represent
282 e.g. in the case of HTTP peers, commands sent to an executor represent
283 a single HTTP request. While some peers may support multiple command
283 a single HTTP request. While some peers may support multiple command
284 sends over the wire per executor, consumers need to code to the least
284 sends over the wire per executor, consumers need to code to the least
285 capable peer. So it should be assumed that command executors buffer
285 capable peer. So it should be assumed that command executors buffer
286 called commands until they are told to send them and that each
286 called commands until they are told to send them and that each
287 command executor could result in a new connection or wire-level request
287 command executor could result in a new connection or wire-level request
288 being issued.
288 being issued.
289 """
289 """
290
290
291 class ipeerbase(ipeerconnection, ipeercapabilities, ipeerrequests):
291 class ipeerbase(ipeerconnection, ipeercapabilities, ipeerrequests):
292 """Unified interface for peer repositories.
292 """Unified interface for peer repositories.
293
293
294 All peer instances must conform to this interface.
294 All peer instances must conform to this interface.
295 """
295 """
296
296
297 @interfaceutil.implementer(ipeerbase)
297 @interfaceutil.implementer(ipeerbase)
298 class peer(object):
298 class peer(object):
299 """Base class for peer repositories."""
299 """Base class for peer repositories."""
300
300
301 def capable(self, name):
301 def capable(self, name):
302 caps = self.capabilities()
302 caps = self.capabilities()
303 if name in caps:
303 if name in caps:
304 return True
304 return True
305
305
306 name = '%s=' % name
306 name = '%s=' % name
307 for cap in caps:
307 for cap in caps:
308 if cap.startswith(name):
308 if cap.startswith(name):
309 return cap[len(name):]
309 return cap[len(name):]
310
310
311 return False
311 return False
312
312
313 def requirecap(self, name, purpose):
313 def requirecap(self, name, purpose):
314 if self.capable(name):
314 if self.capable(name):
315 return
315 return
316
316
317 raise error.CapabilityError(
317 raise error.CapabilityError(
318 _('cannot %s; remote repository does not support the %r '
318 _('cannot %s; remote repository does not support the %r '
319 'capability') % (purpose, name))
319 'capability') % (purpose, name))
320
320
321 class irevisiondelta(interfaceutil.Interface):
321 class irevisiondelta(interfaceutil.Interface):
322 """Represents a delta between one revision and another.
322 """Represents a delta between one revision and another.
323
323
324 Instances convey enough information to allow a revision to be exchanged
324 Instances convey enough information to allow a revision to be exchanged
325 with another repository.
325 with another repository.
326
326
327 Instances represent the fulltext revision data or a delta against
327 Instances represent the fulltext revision data or a delta against
328 another revision. Therefore the ``revision`` and ``delta`` attributes
328 another revision. Therefore the ``revision`` and ``delta`` attributes
329 are mutually exclusive.
329 are mutually exclusive.
330
330
331 Typically used for changegroup generation.
331 Typically used for changegroup generation.
332 """
332 """
333
333
334 node = interfaceutil.Attribute(
334 node = interfaceutil.Attribute(
335 """20 byte node of this revision.""")
335 """20 byte node of this revision.""")
336
336
337 p1node = interfaceutil.Attribute(
337 p1node = interfaceutil.Attribute(
338 """20 byte node of 1st parent of this revision.""")
338 """20 byte node of 1st parent of this revision.""")
339
339
340 p2node = interfaceutil.Attribute(
340 p2node = interfaceutil.Attribute(
341 """20 byte node of 2nd parent of this revision.""")
341 """20 byte node of 2nd parent of this revision.""")
342
342
343 linknode = interfaceutil.Attribute(
343 linknode = interfaceutil.Attribute(
344 """20 byte node of the changelog revision this node is linked to.""")
344 """20 byte node of the changelog revision this node is linked to.""")
345
345
346 flags = interfaceutil.Attribute(
346 flags = interfaceutil.Attribute(
347 """2 bytes of integer flags that apply to this revision.""")
347 """2 bytes of integer flags that apply to this revision.""")
348
348
349 basenode = interfaceutil.Attribute(
349 basenode = interfaceutil.Attribute(
350 """20 byte node of the revision this data is a delta against.
350 """20 byte node of the revision this data is a delta against.
351
351
352 ``nullid`` indicates that the revision is a full revision and not
352 ``nullid`` indicates that the revision is a full revision and not
353 a delta.
353 a delta.
354 """)
354 """)
355
355
356 baserevisionsize = interfaceutil.Attribute(
356 baserevisionsize = interfaceutil.Attribute(
357 """Size of base revision this delta is against.
357 """Size of base revision this delta is against.
358
358
359 May be ``None`` if ``basenode`` is ``nullid``.
359 May be ``None`` if ``basenode`` is ``nullid``.
360 """)
360 """)
361
361
362 revision = interfaceutil.Attribute(
362 revision = interfaceutil.Attribute(
363 """Raw fulltext of revision data for this node.""")
363 """Raw fulltext of revision data for this node.""")
364
364
365 delta = interfaceutil.Attribute(
365 delta = interfaceutil.Attribute(
366 """Delta between ``basenode`` and ``node``.
366 """Delta between ``basenode`` and ``node``.
367
367
368 Stored in the bdiff delta format.
368 Stored in the bdiff delta format.
369 """)
369 """)
370
370
371 class irevisiondeltarequest(interfaceutil.Interface):
371 class irevisiondeltarequest(interfaceutil.Interface):
372 """Represents a request to generate an ``irevisiondelta``."""
372 """Represents a request to generate an ``irevisiondelta``."""
373
373
374 node = interfaceutil.Attribute(
374 node = interfaceutil.Attribute(
375 """20 byte node of revision being requested.""")
375 """20 byte node of revision being requested.""")
376
376
377 p1node = interfaceutil.Attribute(
377 p1node = interfaceutil.Attribute(
378 """20 byte node of 1st parent of revision.""")
378 """20 byte node of 1st parent of revision.""")
379
379
380 p2node = interfaceutil.Attribute(
380 p2node = interfaceutil.Attribute(
381 """20 byte node of 2nd parent of revision.""")
381 """20 byte node of 2nd parent of revision.""")
382
382
383 linknode = interfaceutil.Attribute(
383 linknode = interfaceutil.Attribute(
384 """20 byte node to store in ``linknode`` attribute.""")
384 """20 byte node to store in ``linknode`` attribute.""")
385
385
386 basenode = interfaceutil.Attribute(
386 basenode = interfaceutil.Attribute(
387 """Base revision that delta should be generated against.
387 """Base revision that delta should be generated against.
388
388
389 If ``nullid``, the derived ``irevisiondelta`` should have its
389 If ``nullid``, the derived ``irevisiondelta`` should have its
390 ``revision`` field populated and no delta should be generated.
390 ``revision`` field populated and no delta should be generated.
391
391
392 If ``None``, the delta may be generated against any revision that
392 If ``None``, the delta may be generated against any revision that
393 is an ancestor of this revision. Or a full revision may be used.
393 is an ancestor of this revision. Or a full revision may be used.
394
394
395 If any other value, the delta should be produced against that
395 If any other value, the delta should be produced against that
396 revision.
396 revision.
397 """)
397 """)
398
398
399 ellipsis = interfaceutil.Attribute(
399 ellipsis = interfaceutil.Attribute(
400 """Boolean on whether the ellipsis flag should be set.""")
400 """Boolean on whether the ellipsis flag should be set.""")
401
401
402 class ifilerevisionssequence(interfaceutil.Interface):
402 class ifilerevisionssequence(interfaceutil.Interface):
403 """Contains index data for all revisions of a file.
403 """Contains index data for all revisions of a file.
404
404
405 Types implementing this behave like lists of tuples. The index
405 Types implementing this behave like lists of tuples. The index
406 in the list corresponds to the revision number. The values contain
406 in the list corresponds to the revision number. The values contain
407 index metadata.
407 index metadata.
408
408
409 The *null* revision (revision number -1) is always the last item
409 The *null* revision (revision number -1) is always the last item
410 in the index.
410 in the index.
411 """
411 """
412
412
413 def __len__():
413 def __len__():
414 """The total number of revisions."""
414 """The total number of revisions."""
415
415
416 def __getitem__(rev):
416 def __getitem__(rev):
417 """Returns the object having a specific revision number.
417 """Returns the object having a specific revision number.
418
418
419 Returns an 8-tuple with the following fields:
419 Returns an 8-tuple with the following fields:
420
420
421 offset+flags
421 offset+flags
422 Contains the offset and flags for the revision. 64-bit unsigned
422 Contains the offset and flags for the revision. 64-bit unsigned
423 integer where first 6 bytes are the offset and the next 2 bytes
423 integer where first 6 bytes are the offset and the next 2 bytes
424 are flags. The offset can be 0 if it is not used by the store.
424 are flags. The offset can be 0 if it is not used by the store.
425 compressed size
425 compressed size
426 Size of the revision data in the store. It can be 0 if it isn't
426 Size of the revision data in the store. It can be 0 if it isn't
427 needed by the store.
427 needed by the store.
428 uncompressed size
428 uncompressed size
429 Fulltext size. It can be 0 if it isn't needed by the store.
429 Fulltext size. It can be 0 if it isn't needed by the store.
430 base revision
430 base revision
431 Revision number of revision the delta for storage is encoded
431 Revision number of revision the delta for storage is encoded
432 against. -1 indicates not encoded against a base revision.
432 against. -1 indicates not encoded against a base revision.
433 link revision
433 link revision
434 Revision number of changelog revision this entry is related to.
434 Revision number of changelog revision this entry is related to.
435 p1 revision
435 p1 revision
436 Revision number of 1st parent. -1 if no 1st parent.
436 Revision number of 1st parent. -1 if no 1st parent.
437 p2 revision
437 p2 revision
438 Revision number of 2nd parent. -1 if no 1st parent.
438 Revision number of 2nd parent. -1 if no 1st parent.
439 node
439 node
440 Binary node value for this revision number.
440 Binary node value for this revision number.
441
441
442 Negative values should index off the end of the sequence. ``-1``
442 Negative values should index off the end of the sequence. ``-1``
443 should return the null revision. ``-2`` should return the most
443 should return the null revision. ``-2`` should return the most
444 recent revision.
444 recent revision.
445 """
445 """
446
446
447 def __contains__(rev):
447 def __contains__(rev):
448 """Whether a revision number exists."""
448 """Whether a revision number exists."""
449
449
450 def insert(self, i, entry):
450 def insert(self, i, entry):
451 """Add an item to the index at specific revision."""
451 """Add an item to the index at specific revision."""
452
452
453 class ifileindex(interfaceutil.Interface):
453 class ifileindex(interfaceutil.Interface):
454 """Storage interface for index data of a single file.
454 """Storage interface for index data of a single file.
455
455
456 File storage data is divided into index metadata and data storage.
456 File storage data is divided into index metadata and data storage.
457 This interface defines the index portion of the interface.
457 This interface defines the index portion of the interface.
458
458
459 The index logically consists of:
459 The index logically consists of:
460
460
461 * A mapping between revision numbers and nodes.
461 * A mapping between revision numbers and nodes.
462 * DAG data (storing and querying the relationship between nodes).
462 * DAG data (storing and querying the relationship between nodes).
463 * Metadata to facilitate storage.
463 * Metadata to facilitate storage.
464 """
464 """
465 index = interfaceutil.Attribute(
465 index = interfaceutil.Attribute(
466 """An ``ifilerevisionssequence`` instance.""")
466 """An ``ifilerevisionssequence`` instance.""")
467
467
468 def __len__():
468 def __len__():
469 """Obtain the number of revisions stored for this file."""
469 """Obtain the number of revisions stored for this file."""
470
470
471 def __iter__():
471 def __iter__():
472 """Iterate over revision numbers for this file."""
472 """Iterate over revision numbers for this file."""
473
473
474 def revs(start=0, stop=None):
474 def revs(start=0, stop=None):
475 """Iterate over revision numbers for this file, with control."""
475 """Iterate over revision numbers for this file, with control."""
476
476
477 def parents(node):
477 def parents(node):
478 """Returns a 2-tuple of parent nodes for a revision.
478 """Returns a 2-tuple of parent nodes for a revision.
479
479
480 Values will be ``nullid`` if the parent is empty.
480 Values will be ``nullid`` if the parent is empty.
481 """
481 """
482
482
483 def parentrevs(rev):
483 def parentrevs(rev):
484 """Like parents() but operates on revision numbers."""
484 """Like parents() but operates on revision numbers."""
485
485
486 def rev(node):
486 def rev(node):
487 """Obtain the revision number given a node.
487 """Obtain the revision number given a node.
488
488
489 Raises ``error.LookupError`` if the node is not known.
489 Raises ``error.LookupError`` if the node is not known.
490 """
490 """
491
491
492 def node(rev):
492 def node(rev):
493 """Obtain the node value given a revision number.
493 """Obtain the node value given a revision number.
494
494
495 Raises ``IndexError`` if the node is not known.
495 Raises ``IndexError`` if the node is not known.
496 """
496 """
497
497
498 def lookup(node):
498 def lookup(node):
499 """Attempt to resolve a value to a node.
499 """Attempt to resolve a value to a node.
500
500
501 Value can be a binary node, hex node, revision number, or a string
501 Value can be a binary node, hex node, revision number, or a string
502 that can be converted to an integer.
502 that can be converted to an integer.
503
503
504 Raises ``error.LookupError`` if a node could not be resolved.
504 Raises ``error.LookupError`` if a node could not be resolved.
505 """
505 """
506
506
507 def linkrev(rev):
507 def linkrev(rev):
508 """Obtain the changeset revision number a revision is linked to."""
508 """Obtain the changeset revision number a revision is linked to."""
509
509
510 def flags(rev):
510 def flags(rev):
511 """Obtain flags used to affect storage of a revision."""
511 """Obtain flags used to affect storage of a revision."""
512
512
513 def iscensored(rev):
513 def iscensored(rev):
514 """Return whether a revision's content has been censored."""
514 """Return whether a revision's content has been censored."""
515
515
516 def commonancestorsheads(node1, node2):
516 def commonancestorsheads(node1, node2):
517 """Obtain an iterable of nodes containing heads of common ancestors.
517 """Obtain an iterable of nodes containing heads of common ancestors.
518
518
519 See ``ancestor.commonancestorsheads()``.
519 See ``ancestor.commonancestorsheads()``.
520 """
520 """
521
521
522 def descendants(revs):
522 def descendants(revs):
523 """Obtain descendant revision numbers for a set of revision numbers.
523 """Obtain descendant revision numbers for a set of revision numbers.
524
524
525 If ``nullrev`` is in the set, this is equivalent to ``revs()``.
525 If ``nullrev`` is in the set, this is equivalent to ``revs()``.
526 """
526 """
527
527
528 def headrevs():
528 def headrevs():
529 """Obtain a list of revision numbers that are DAG heads.
529 """Obtain a list of revision numbers that are DAG heads.
530
530
531 The list is sorted oldest to newest.
531 The list is sorted oldest to newest.
532
532
533 TODO determine if sorting is required.
533 TODO determine if sorting is required.
534 """
534 """
535
535
536 def heads(start=None, stop=None):
536 def heads(start=None, stop=None):
537 """Obtain a list of nodes that are DAG heads, with control.
537 """Obtain a list of nodes that are DAG heads, with control.
538
538
539 The set of revisions examined can be limited by specifying
539 The set of revisions examined can be limited by specifying
540 ``start`` and ``stop``. ``start`` is a node. ``stop`` is an
540 ``start`` and ``stop``. ``start`` is a node. ``stop`` is an
541 iterable of nodes. DAG traversal starts at earlier revision
541 iterable of nodes. DAG traversal starts at earlier revision
542 ``start`` and iterates forward until any node in ``stop`` is
542 ``start`` and iterates forward until any node in ``stop`` is
543 encountered.
543 encountered.
544 """
544 """
545
545
546 def children(node):
546 def children(node):
547 """Obtain nodes that are children of a node.
547 """Obtain nodes that are children of a node.
548
548
549 Returns a list of nodes.
549 Returns a list of nodes.
550 """
550 """
551
551
552 def deltaparent(rev):
552 def deltaparent(rev):
553 """"Return the revision that is a suitable parent to delta against."""
553 """"Return the revision that is a suitable parent to delta against."""
554
554
555 class ifiledata(interfaceutil.Interface):
555 class ifiledata(interfaceutil.Interface):
556 """Storage interface for data storage of a specific file.
556 """Storage interface for data storage of a specific file.
557
557
558 This complements ``ifileindex`` and provides an interface for accessing
558 This complements ``ifileindex`` and provides an interface for accessing
559 data for a tracked file.
559 data for a tracked file.
560 """
560 """
561 def rawsize(rev):
561 def rawsize(rev):
562 """The size of the fulltext data for a revision as stored."""
562 """The size of the fulltext data for a revision as stored."""
563
563
564 def size(rev):
564 def size(rev):
565 """Obtain the fulltext size of file data.
565 """Obtain the fulltext size of file data.
566
566
567 Any metadata is excluded from size measurements. Use ``rawsize()`` if
567 Any metadata is excluded from size measurements. Use ``rawsize()`` if
568 metadata size is important.
568 metadata size is important.
569 """
569 """
570
570
571 def checkhash(fulltext, node, p1=None, p2=None, rev=None):
571 def checkhash(fulltext, node, p1=None, p2=None, rev=None):
572 """Validate the stored hash of a given fulltext and node.
572 """Validate the stored hash of a given fulltext and node.
573
573
574 Raises ``error.RevlogError`` is hash validation fails.
574 Raises ``error.RevlogError`` is hash validation fails.
575 """
575 """
576
576
577 def revision(node, raw=False):
577 def revision(node, raw=False):
578 """"Obtain fulltext data for a node.
578 """"Obtain fulltext data for a node.
579
579
580 By default, any storage transformations are applied before the data
580 By default, any storage transformations are applied before the data
581 is returned. If ``raw`` is True, non-raw storage transformations
581 is returned. If ``raw`` is True, non-raw storage transformations
582 are not applied.
582 are not applied.
583
583
584 The fulltext data may contain a header containing metadata. Most
584 The fulltext data may contain a header containing metadata. Most
585 consumers should use ``read()`` to obtain the actual file data.
585 consumers should use ``read()`` to obtain the actual file data.
586 """
586 """
587
587
588 def read(node):
588 def read(node):
589 """Resolve file fulltext data.
589 """Resolve file fulltext data.
590
590
591 This is similar to ``revision()`` except any metadata in the data
591 This is similar to ``revision()`` except any metadata in the data
592 headers is stripped.
592 headers is stripped.
593 """
593 """
594
594
595 def renamed(node):
595 def renamed(node):
596 """Obtain copy metadata for a node.
596 """Obtain copy metadata for a node.
597
597
598 Returns ``False`` if no copy metadata is stored or a 2-tuple of
598 Returns ``False`` if no copy metadata is stored or a 2-tuple of
599 (path, node) from which this revision was copied.
599 (path, node) from which this revision was copied.
600 """
600 """
601
601
602 def cmp(node, fulltext):
602 def cmp(node, fulltext):
603 """Compare fulltext to another revision.
603 """Compare fulltext to another revision.
604
604
605 Returns True if the fulltext is different from what is stored.
605 Returns True if the fulltext is different from what is stored.
606
606
607 This takes copy metadata into account.
607 This takes copy metadata into account.
608
608
609 TODO better document the copy metadata and censoring logic.
609 TODO better document the copy metadata and censoring logic.
610 """
610 """
611
611
612 def revdiff(rev1, rev2):
612 def revdiff(rev1, rev2):
613 """Obtain a delta between two revision numbers.
613 """Obtain a delta between two revision numbers.
614
614
615 Operates on raw data in the store (``revision(node, raw=True)``).
615 Operates on raw data in the store (``revision(node, raw=True)``).
616
616
617 The returned data is the result of ``bdiff.bdiff`` on the raw
617 The returned data is the result of ``bdiff.bdiff`` on the raw
618 revision data.
618 revision data.
619 """
619 """
620
620
621 def emitrevisiondeltas(requests):
621 def emitrevisiondeltas(requests):
622 """Produce ``irevisiondelta`` from ``irevisiondeltarequest``s.
622 """Produce ``irevisiondelta`` from ``irevisiondeltarequest``s.
623
623
624 Given an iterable of objects conforming to the ``irevisiondeltarequest``
624 Given an iterable of objects conforming to the ``irevisiondeltarequest``
625 interface, emits objects conforming to the ``irevisiondelta``
625 interface, emits objects conforming to the ``irevisiondelta``
626 interface.
626 interface.
627
627
628 This method is a generator.
628 This method is a generator.
629
629
630 ``irevisiondelta`` should be emitted in the same order of
630 ``irevisiondelta`` should be emitted in the same order of
631 ``irevisiondeltarequest`` that was passed in.
631 ``irevisiondeltarequest`` that was passed in.
632
632
633 The emitted objects MUST conform by the results of
633 The emitted objects MUST conform by the results of
634 ``irevisiondeltarequest``. Namely, they must respect any requests
634 ``irevisiondeltarequest``. Namely, they must respect any requests
635 for building a delta from a specific ``basenode`` if defined.
635 for building a delta from a specific ``basenode`` if defined.
636
636
637 When sending deltas, implementations must take into account whether
637 When sending deltas, implementations must take into account whether
638 the client has the base delta before encoding a delta against that
638 the client has the base delta before encoding a delta against that
639 revision. A revision encountered previously in ``requests`` is
639 revision. A revision encountered previously in ``requests`` is
640 always a suitable base revision. An example of a bad delta is a delta
640 always a suitable base revision. An example of a bad delta is a delta
641 against a non-ancestor revision. Another example of a bad delta is a
641 against a non-ancestor revision. Another example of a bad delta is a
642 delta against a censored revision.
642 delta against a censored revision.
643 """
643 """
644
644
645 class ifilemutation(interfaceutil.Interface):
645 class ifilemutation(interfaceutil.Interface):
646 """Storage interface for mutation events of a tracked file."""
646 """Storage interface for mutation events of a tracked file."""
647
647
648 def add(filedata, meta, transaction, linkrev, p1, p2):
648 def add(filedata, meta, transaction, linkrev, p1, p2):
649 """Add a new revision to the store.
649 """Add a new revision to the store.
650
650
651 Takes file data, dictionary of metadata, a transaction, linkrev,
651 Takes file data, dictionary of metadata, a transaction, linkrev,
652 and parent nodes.
652 and parent nodes.
653
653
654 Returns the node that was added.
654 Returns the node that was added.
655
655
656 May no-op if a revision matching the supplied data is already stored.
656 May no-op if a revision matching the supplied data is already stored.
657 """
657 """
658
658
659 def addrevision(revisiondata, transaction, linkrev, p1, p2, node=None,
659 def addrevision(revisiondata, transaction, linkrev, p1, p2, node=None,
660 flags=0, cachedelta=None):
660 flags=0, cachedelta=None):
661 """Add a new revision to the store.
661 """Add a new revision to the store.
662
662
663 This is similar to ``add()`` except it operates at a lower level.
663 This is similar to ``add()`` except it operates at a lower level.
664
664
665 The data passed in already contains a metadata header, if any.
665 The data passed in already contains a metadata header, if any.
666
666
667 ``node`` and ``flags`` can be used to define the expected node and
667 ``node`` and ``flags`` can be used to define the expected node and
668 the flags to use with storage.
668 the flags to use with storage.
669
669
670 ``add()`` is usually called when adding files from e.g. the working
670 ``add()`` is usually called when adding files from e.g. the working
671 directory. ``addrevision()`` is often called by ``add()`` and for
671 directory. ``addrevision()`` is often called by ``add()`` and for
672 scenarios where revision data has already been computed, such as when
672 scenarios where revision data has already been computed, such as when
673 applying raw data from a peer repo.
673 applying raw data from a peer repo.
674 """
674 """
675
675
676 def addgroup(deltas, linkmapper, transaction, addrevisioncb=None):
676 def addgroup(deltas, linkmapper, transaction, addrevisioncb=None):
677 """Process a series of deltas for storage.
677 """Process a series of deltas for storage.
678
678
679 ``deltas`` is an iterable of 7-tuples of
679 ``deltas`` is an iterable of 7-tuples of
680 (node, p1, p2, linknode, deltabase, delta, flags) defining revisions
680 (node, p1, p2, linknode, deltabase, delta, flags) defining revisions
681 to add.
681 to add.
682
682
683 The ``delta`` field contains ``mpatch`` data to apply to a base
683 The ``delta`` field contains ``mpatch`` data to apply to a base
684 revision, identified by ``deltabase``. The base node can be
684 revision, identified by ``deltabase``. The base node can be
685 ``nullid``, in which case the header from the delta can be ignored
685 ``nullid``, in which case the header from the delta can be ignored
686 and the delta used as the fulltext.
686 and the delta used as the fulltext.
687
687
688 ``addrevisioncb`` should be called for each node as it is committed.
688 ``addrevisioncb`` should be called for each node as it is committed.
689
689
690 Returns a list of nodes that were processed. A node will be in the list
690 Returns a list of nodes that were processed. A node will be in the list
691 even if it existed in the store previously.
691 even if it existed in the store previously.
692 """
692 """
693
693
694 def getstrippoint(minlink):
694 def getstrippoint(minlink):
695 """Find the minimum revision that must be stripped to strip a linkrev.
695 """Find the minimum revision that must be stripped to strip a linkrev.
696
696
697 Returns a 2-tuple containing the minimum revision number and a set
697 Returns a 2-tuple containing the minimum revision number and a set
698 of all revisions numbers that would be broken by this strip.
698 of all revisions numbers that would be broken by this strip.
699
699
700 TODO this is highly revlog centric and should be abstracted into
700 TODO this is highly revlog centric and should be abstracted into
701 a higher-level deletion API. ``repair.strip()`` relies on this.
701 a higher-level deletion API. ``repair.strip()`` relies on this.
702 """
702 """
703
703
704 def strip(minlink, transaction):
704 def strip(minlink, transaction):
705 """Remove storage of items starting at a linkrev.
705 """Remove storage of items starting at a linkrev.
706
706
707 This uses ``getstrippoint()`` to determine the first node to remove.
707 This uses ``getstrippoint()`` to determine the first node to remove.
708 Then it effectively truncates storage for all revisions after that.
708 Then it effectively truncates storage for all revisions after that.
709
709
710 TODO this is highly revlog centric and should be abstracted into a
710 TODO this is highly revlog centric and should be abstracted into a
711 higher-level deletion API.
711 higher-level deletion API.
712 """
712 """
713
713
714 class ifilestorage(ifileindex, ifiledata, ifilemutation):
714 class ifilestorage(ifileindex, ifiledata, ifilemutation):
715 """Complete storage interface for a single tracked file."""
715 """Complete storage interface for a single tracked file."""
716
716
717 version = interfaceutil.Attribute(
717 version = interfaceutil.Attribute(
718 """Version number of storage.
718 """Version number of storage.
719
719
720 TODO this feels revlog centric and could likely be removed.
720 TODO this feels revlog centric and could likely be removed.
721 """)
721 """)
722
722
723 _generaldelta = interfaceutil.Attribute(
723 _generaldelta = interfaceutil.Attribute(
724 """Whether deltas can be against any parent revision.
724 """Whether deltas can be against any parent revision.
725
725
726 TODO this is used by changegroup code and it could probably be
726 TODO this is used by changegroup code and it could probably be
727 folded into another API.
727 folded into another API.
728 """)
728 """)
729
729
730 def files():
730 def files():
731 """Obtain paths that are backing storage for this file.
731 """Obtain paths that are backing storage for this file.
732
732
733 TODO this is used heavily by verify code and there should probably
733 TODO this is used heavily by verify code and there should probably
734 be a better API for that.
734 be a better API for that.
735 """
735 """
736
736
737 def checksize():
737 def checksize():
738 """Obtain the expected sizes of backing files.
738 """Obtain the expected sizes of backing files.
739
739
740 TODO this is used by verify and it should not be part of the interface.
740 TODO this is used by verify and it should not be part of the interface.
741 """
741 """
742
742
743 class idirs(interfaceutil.Interface):
743 class idirs(interfaceutil.Interface):
744 """Interface representing a collection of directories from paths.
744 """Interface representing a collection of directories from paths.
745
745
746 This interface is essentially a derived data structure representing
746 This interface is essentially a derived data structure representing
747 directories from a collection of paths.
747 directories from a collection of paths.
748 """
748 """
749
749
750 def addpath(path):
750 def addpath(path):
751 """Add a path to the collection.
751 """Add a path to the collection.
752
752
753 All directories in the path will be added to the collection.
753 All directories in the path will be added to the collection.
754 """
754 """
755
755
756 def delpath(path):
756 def delpath(path):
757 """Remove a path from the collection.
757 """Remove a path from the collection.
758
758
759 If the removal was the last path in a particular directory, the
759 If the removal was the last path in a particular directory, the
760 directory is removed from the collection.
760 directory is removed from the collection.
761 """
761 """
762
762
763 def __iter__():
763 def __iter__():
764 """Iterate over the directories in this collection of paths."""
764 """Iterate over the directories in this collection of paths."""
765
765
766 def __contains__(path):
766 def __contains__(path):
767 """Whether a specific directory is in this collection."""
767 """Whether a specific directory is in this collection."""
768
768
769 class imanifestdict(interfaceutil.Interface):
769 class imanifestdict(interfaceutil.Interface):
770 """Interface representing a manifest data structure.
770 """Interface representing a manifest data structure.
771
771
772 A manifest is effectively a dict mapping paths to entries. Each entry
772 A manifest is effectively a dict mapping paths to entries. Each entry
773 consists of a binary node and extra flags affecting that entry.
773 consists of a binary node and extra flags affecting that entry.
774 """
774 """
775
775
776 def __getitem__(path):
776 def __getitem__(path):
777 """Returns the binary node value for a path in the manifest.
777 """Returns the binary node value for a path in the manifest.
778
778
779 Raises ``KeyError`` if the path does not exist in the manifest.
779 Raises ``KeyError`` if the path does not exist in the manifest.
780
780
781 Equivalent to ``self.find(path)[0]``.
781 Equivalent to ``self.find(path)[0]``.
782 """
782 """
783
783
784 def find(path):
784 def find(path):
785 """Returns the entry for a path in the manifest.
785 """Returns the entry for a path in the manifest.
786
786
787 Returns a 2-tuple of (node, flags).
787 Returns a 2-tuple of (node, flags).
788
788
789 Raises ``KeyError`` if the path does not exist in the manifest.
789 Raises ``KeyError`` if the path does not exist in the manifest.
790 """
790 """
791
791
792 def __len__():
792 def __len__():
793 """Return the number of entries in the manifest."""
793 """Return the number of entries in the manifest."""
794
794
795 def __nonzero__():
795 def __nonzero__():
796 """Returns True if the manifest has entries, False otherwise."""
796 """Returns True if the manifest has entries, False otherwise."""
797
797
798 __bool__ = __nonzero__
798 __bool__ = __nonzero__
799
799
800 def __setitem__(path, node):
800 def __setitem__(path, node):
801 """Define the node value for a path in the manifest.
801 """Define the node value for a path in the manifest.
802
802
803 If the path is already in the manifest, its flags will be copied to
803 If the path is already in the manifest, its flags will be copied to
804 the new entry.
804 the new entry.
805 """
805 """
806
806
807 def __contains__(path):
807 def __contains__(path):
808 """Whether a path exists in the manifest."""
808 """Whether a path exists in the manifest."""
809
809
810 def __delitem__(path):
810 def __delitem__(path):
811 """Remove a path from the manifest.
811 """Remove a path from the manifest.
812
812
813 Raises ``KeyError`` if the path is not in the manifest.
813 Raises ``KeyError`` if the path is not in the manifest.
814 """
814 """
815
815
816 def __iter__():
816 def __iter__():
817 """Iterate over paths in the manifest."""
817 """Iterate over paths in the manifest."""
818
818
819 def iterkeys():
819 def iterkeys():
820 """Iterate over paths in the manifest."""
820 """Iterate over paths in the manifest."""
821
821
822 def keys():
822 def keys():
823 """Obtain a list of paths in the manifest."""
823 """Obtain a list of paths in the manifest."""
824
824
825 def filesnotin(other, match=None):
825 def filesnotin(other, match=None):
826 """Obtain the set of paths in this manifest but not in another.
826 """Obtain the set of paths in this manifest but not in another.
827
827
828 ``match`` is an optional matcher function to be applied to both
828 ``match`` is an optional matcher function to be applied to both
829 manifests.
829 manifests.
830
830
831 Returns a set of paths.
831 Returns a set of paths.
832 """
832 """
833
833
834 def dirs():
834 def dirs():
835 """Returns an object implementing the ``idirs`` interface."""
835 """Returns an object implementing the ``idirs`` interface."""
836
836
837 def hasdir(dir):
837 def hasdir(dir):
838 """Returns a bool indicating if a directory is in this manifest."""
838 """Returns a bool indicating if a directory is in this manifest."""
839
839
840 def matches(match):
840 def matches(match):
841 """Generate a new manifest filtered through a matcher.
841 """Generate a new manifest filtered through a matcher.
842
842
843 Returns an object conforming to the ``imanifestdict`` interface.
843 Returns an object conforming to the ``imanifestdict`` interface.
844 """
844 """
845
845
846 def walk(match):
846 def walk(match):
847 """Generator of paths in manifest satisfying a matcher.
847 """Generator of paths in manifest satisfying a matcher.
848
848
849 This is equivalent to ``self.matches(match).iterkeys()`` except a new
849 This is equivalent to ``self.matches(match).iterkeys()`` except a new
850 manifest object is not created.
850 manifest object is not created.
851
851
852 If the matcher has explicit files listed and they don't exist in
852 If the matcher has explicit files listed and they don't exist in
853 the manifest, ``match.bad()`` is called for each missing file.
853 the manifest, ``match.bad()`` is called for each missing file.
854 """
854 """
855
855
856 def diff(other, match=None, clean=False):
856 def diff(other, match=None, clean=False):
857 """Find differences between this manifest and another.
857 """Find differences between this manifest and another.
858
858
859 This manifest is compared to ``other``.
859 This manifest is compared to ``other``.
860
860
861 If ``match`` is provided, the two manifests are filtered against this
861 If ``match`` is provided, the two manifests are filtered against this
862 matcher and only entries satisfying the matcher are compared.
862 matcher and only entries satisfying the matcher are compared.
863
863
864 If ``clean`` is True, unchanged files are included in the returned
864 If ``clean`` is True, unchanged files are included in the returned
865 object.
865 object.
866
866
867 Returns a dict with paths as keys and values of 2-tuples of 2-tuples of
867 Returns a dict with paths as keys and values of 2-tuples of 2-tuples of
868 the form ``((node1, flag1), (node2, flag2))`` where ``(node1, flag1)``
868 the form ``((node1, flag1), (node2, flag2))`` where ``(node1, flag1)``
869 represents the node and flags for this manifest and ``(node2, flag2)``
869 represents the node and flags for this manifest and ``(node2, flag2)``
870 are the same for the other manifest.
870 are the same for the other manifest.
871 """
871 """
872
872
873 def setflag(path, flag):
873 def setflag(path, flag):
874 """Set the flag value for a given path.
874 """Set the flag value for a given path.
875
875
876 Raises ``KeyError`` if the path is not already in the manifest.
876 Raises ``KeyError`` if the path is not already in the manifest.
877 """
877 """
878
878
879 def get(path, default=None):
879 def get(path, default=None):
880 """Obtain the node value for a path or a default value if missing."""
880 """Obtain the node value for a path or a default value if missing."""
881
881
882 def flags(path, default=''):
882 def flags(path, default=''):
883 """Return the flags value for a path or a default value if missing."""
883 """Return the flags value for a path or a default value if missing."""
884
884
885 def copy():
885 def copy():
886 """Return a copy of this manifest."""
886 """Return a copy of this manifest."""
887
887
888 def items():
888 def items():
889 """Returns an iterable of (path, node) for items in this manifest."""
889 """Returns an iterable of (path, node) for items in this manifest."""
890
890
891 def iteritems():
891 def iteritems():
892 """Identical to items()."""
892 """Identical to items()."""
893
893
894 def iterentries():
894 def iterentries():
895 """Returns an iterable of (path, node, flags) for this manifest.
895 """Returns an iterable of (path, node, flags) for this manifest.
896
896
897 Similar to ``iteritems()`` except items are a 3-tuple and include
897 Similar to ``iteritems()`` except items are a 3-tuple and include
898 flags.
898 flags.
899 """
899 """
900
900
901 def text():
901 def text():
902 """Obtain the raw data representation for this manifest.
902 """Obtain the raw data representation for this manifest.
903
903
904 Result is used to create a manifest revision.
904 Result is used to create a manifest revision.
905 """
905 """
906
906
907 def fastdelta(base, changes):
907 def fastdelta(base, changes):
908 """Obtain a delta between this manifest and another given changes.
908 """Obtain a delta between this manifest and another given changes.
909
909
910 ``base`` in the raw data representation for another manifest.
910 ``base`` in the raw data representation for another manifest.
911
911
912 ``changes`` is an iterable of ``(path, to_delete)``.
912 ``changes`` is an iterable of ``(path, to_delete)``.
913
913
914 Returns a 2-tuple containing ``bytearray(self.text())`` and the
914 Returns a 2-tuple containing ``bytearray(self.text())`` and the
915 delta between ``base`` and this manifest.
915 delta between ``base`` and this manifest.
916 """
916 """
917
917
918 class imanifestrevisionbase(interfaceutil.Interface):
918 class imanifestrevisionbase(interfaceutil.Interface):
919 """Base interface representing a single revision of a manifest.
919 """Base interface representing a single revision of a manifest.
920
920
921 Should not be used as a primary interface: should always be inherited
921 Should not be used as a primary interface: should always be inherited
922 as part of a larger interface.
922 as part of a larger interface.
923 """
923 """
924
924
925 def new():
925 def new():
926 """Obtain a new manifest instance.
926 """Obtain a new manifest instance.
927
927
928 Returns an object conforming to the ``imanifestrevisionwritable``
928 Returns an object conforming to the ``imanifestrevisionwritable``
929 interface. The instance will be associated with the same
929 interface. The instance will be associated with the same
930 ``imanifestlog`` collection as this instance.
930 ``imanifestlog`` collection as this instance.
931 """
931 """
932
932
933 def copy():
933 def copy():
934 """Obtain a copy of this manifest instance.
934 """Obtain a copy of this manifest instance.
935
935
936 Returns an object conforming to the ``imanifestrevisionwritable``
936 Returns an object conforming to the ``imanifestrevisionwritable``
937 interface. The instance will be associated with the same
937 interface. The instance will be associated with the same
938 ``imanifestlog`` collection as this instance.
938 ``imanifestlog`` collection as this instance.
939 """
939 """
940
940
941 def read():
941 def read():
942 """Obtain the parsed manifest data structure.
942 """Obtain the parsed manifest data structure.
943
943
944 The returned object conforms to the ``imanifestdict`` interface.
944 The returned object conforms to the ``imanifestdict`` interface.
945 """
945 """
946
946
947 class imanifestrevisionstored(imanifestrevisionbase):
947 class imanifestrevisionstored(imanifestrevisionbase):
948 """Interface representing a manifest revision committed to storage."""
948 """Interface representing a manifest revision committed to storage."""
949
949
950 def node():
950 def node():
951 """The binary node for this manifest."""
951 """The binary node for this manifest."""
952
952
953 parents = interfaceutil.Attribute(
953 parents = interfaceutil.Attribute(
954 """List of binary nodes that are parents for this manifest revision."""
954 """List of binary nodes that are parents for this manifest revision."""
955 )
955 )
956
956
957 def readdelta(shallow=False):
957 def readdelta(shallow=False):
958 """Obtain the manifest data structure representing changes from parent.
958 """Obtain the manifest data structure representing changes from parent.
959
959
960 This manifest is compared to its 1st parent. A new manifest representing
960 This manifest is compared to its 1st parent. A new manifest representing
961 those differences is constructed.
961 those differences is constructed.
962
962
963 The returned object conforms to the ``imanifestdict`` interface.
963 The returned object conforms to the ``imanifestdict`` interface.
964 """
964 """
965
965
966 def readfast(shallow=False):
966 def readfast(shallow=False):
967 """Calls either ``read()`` or ``readdelta()``.
967 """Calls either ``read()`` or ``readdelta()``.
968
968
969 The faster of the two options is called.
969 The faster of the two options is called.
970 """
970 """
971
971
972 def find(key):
972 def find(key):
973 """Calls self.read().find(key)``.
973 """Calls self.read().find(key)``.
974
974
975 Returns a 2-tuple of ``(node, flags)`` or raises ``KeyError``.
975 Returns a 2-tuple of ``(node, flags)`` or raises ``KeyError``.
976 """
976 """
977
977
978 class imanifestrevisionwritable(imanifestrevisionbase):
978 class imanifestrevisionwritable(imanifestrevisionbase):
979 """Interface representing a manifest revision that can be committed."""
979 """Interface representing a manifest revision that can be committed."""
980
980
981 def write(transaction, linkrev, p1node, p2node, added, removed):
981 def write(transaction, linkrev, p1node, p2node, added, removed, match=None):
982 """Add this revision to storage.
982 """Add this revision to storage.
983
983
984 Takes a transaction object, the changeset revision number it will
984 Takes a transaction object, the changeset revision number it will
985 be associated with, its parent nodes, and lists of added and
985 be associated with, its parent nodes, and lists of added and
986 removed paths.
986 removed paths.
987
987
988 If match is provided, storage can choose not to inspect or write out
989 items that do not match. Storage is still required to be able to provide
990 the full manifest in the future for any directories written (these
991 manifests should not be "narrowed on disk").
992
988 Returns the binary node of the created revision.
993 Returns the binary node of the created revision.
989 """
994 """
990
995
991 class imanifeststorage(interfaceutil.Interface):
996 class imanifeststorage(interfaceutil.Interface):
992 """Storage interface for manifest data."""
997 """Storage interface for manifest data."""
993
998
994 tree = interfaceutil.Attribute(
999 tree = interfaceutil.Attribute(
995 """The path to the directory this manifest tracks.
1000 """The path to the directory this manifest tracks.
996
1001
997 The empty bytestring represents the root manifest.
1002 The empty bytestring represents the root manifest.
998 """)
1003 """)
999
1004
1000 index = interfaceutil.Attribute(
1005 index = interfaceutil.Attribute(
1001 """An ``ifilerevisionssequence`` instance.""")
1006 """An ``ifilerevisionssequence`` instance.""")
1002
1007
1003 indexfile = interfaceutil.Attribute(
1008 indexfile = interfaceutil.Attribute(
1004 """Path of revlog index file.
1009 """Path of revlog index file.
1005
1010
1006 TODO this is revlog specific and should not be exposed.
1011 TODO this is revlog specific and should not be exposed.
1007 """)
1012 """)
1008
1013
1009 opener = interfaceutil.Attribute(
1014 opener = interfaceutil.Attribute(
1010 """VFS opener to use to access underlying files used for storage.
1015 """VFS opener to use to access underlying files used for storage.
1011
1016
1012 TODO this is revlog specific and should not be exposed.
1017 TODO this is revlog specific and should not be exposed.
1013 """)
1018 """)
1014
1019
1015 version = interfaceutil.Attribute(
1020 version = interfaceutil.Attribute(
1016 """Revlog version number.
1021 """Revlog version number.
1017
1022
1018 TODO this is revlog specific and should not be exposed.
1023 TODO this is revlog specific and should not be exposed.
1019 """)
1024 """)
1020
1025
1021 _generaldelta = interfaceutil.Attribute(
1026 _generaldelta = interfaceutil.Attribute(
1022 """Whether generaldelta storage is being used.
1027 """Whether generaldelta storage is being used.
1023
1028
1024 TODO this is revlog specific and should not be exposed.
1029 TODO this is revlog specific and should not be exposed.
1025 """)
1030 """)
1026
1031
1027 fulltextcache = interfaceutil.Attribute(
1032 fulltextcache = interfaceutil.Attribute(
1028 """Dict with cache of fulltexts.
1033 """Dict with cache of fulltexts.
1029
1034
1030 TODO this doesn't feel appropriate for the storage interface.
1035 TODO this doesn't feel appropriate for the storage interface.
1031 """)
1036 """)
1032
1037
1033 def __len__():
1038 def __len__():
1034 """Obtain the number of revisions stored for this manifest."""
1039 """Obtain the number of revisions stored for this manifest."""
1035
1040
1036 def __iter__():
1041 def __iter__():
1037 """Iterate over revision numbers for this manifest."""
1042 """Iterate over revision numbers for this manifest."""
1038
1043
1039 def rev(node):
1044 def rev(node):
1040 """Obtain the revision number given a binary node.
1045 """Obtain the revision number given a binary node.
1041
1046
1042 Raises ``error.LookupError`` if the node is not known.
1047 Raises ``error.LookupError`` if the node is not known.
1043 """
1048 """
1044
1049
1045 def node(rev):
1050 def node(rev):
1046 """Obtain the node value given a revision number.
1051 """Obtain the node value given a revision number.
1047
1052
1048 Raises ``error.LookupError`` if the revision is not known.
1053 Raises ``error.LookupError`` if the revision is not known.
1049 """
1054 """
1050
1055
1051 def lookup(value):
1056 def lookup(value):
1052 """Attempt to resolve a value to a node.
1057 """Attempt to resolve a value to a node.
1053
1058
1054 Value can be a binary node, hex node, revision number, or a bytes
1059 Value can be a binary node, hex node, revision number, or a bytes
1055 that can be converted to an integer.
1060 that can be converted to an integer.
1056
1061
1057 Raises ``error.LookupError`` if a ndoe could not be resolved.
1062 Raises ``error.LookupError`` if a ndoe could not be resolved.
1058
1063
1059 TODO this is only used by debug* commands and can probably be deleted
1064 TODO this is only used by debug* commands and can probably be deleted
1060 easily.
1065 easily.
1061 """
1066 """
1062
1067
1063 def parents(node):
1068 def parents(node):
1064 """Returns a 2-tuple of parent nodes for a node.
1069 """Returns a 2-tuple of parent nodes for a node.
1065
1070
1066 Values will be ``nullid`` if the parent is empty.
1071 Values will be ``nullid`` if the parent is empty.
1067 """
1072 """
1068
1073
1069 def parentrevs(rev):
1074 def parentrevs(rev):
1070 """Like parents() but operates on revision numbers."""
1075 """Like parents() but operates on revision numbers."""
1071
1076
1072 def linkrev(rev):
1077 def linkrev(rev):
1073 """Obtain the changeset revision number a revision is linked to."""
1078 """Obtain the changeset revision number a revision is linked to."""
1074
1079
1075 def revision(node, _df=None, raw=False):
1080 def revision(node, _df=None, raw=False):
1076 """Obtain fulltext data for a node."""
1081 """Obtain fulltext data for a node."""
1077
1082
1078 def revdiff(rev1, rev2):
1083 def revdiff(rev1, rev2):
1079 """Obtain a delta between two revision numbers.
1084 """Obtain a delta between two revision numbers.
1080
1085
1081 The returned data is the result of ``bdiff.bdiff()`` on the raw
1086 The returned data is the result of ``bdiff.bdiff()`` on the raw
1082 revision data.
1087 revision data.
1083 """
1088 """
1084
1089
1085 def cmp(node, fulltext):
1090 def cmp(node, fulltext):
1086 """Compare fulltext to another revision.
1091 """Compare fulltext to another revision.
1087
1092
1088 Returns True if the fulltext is different from what is stored.
1093 Returns True if the fulltext is different from what is stored.
1089 """
1094 """
1090
1095
1091 def emitrevisiondeltas(requests):
1096 def emitrevisiondeltas(requests):
1092 """Produce ``irevisiondelta`` from ``irevisiondeltarequest``s.
1097 """Produce ``irevisiondelta`` from ``irevisiondeltarequest``s.
1093
1098
1094 See the documentation for ``ifiledata`` for more.
1099 See the documentation for ``ifiledata`` for more.
1095 """
1100 """
1096
1101
1097 def addgroup(deltas, linkmapper, transaction, addrevisioncb=None):
1102 def addgroup(deltas, linkmapper, transaction, addrevisioncb=None):
1098 """Process a series of deltas for storage.
1103 """Process a series of deltas for storage.
1099
1104
1100 See the documentation in ``ifilemutation`` for more.
1105 See the documentation in ``ifilemutation`` for more.
1101 """
1106 """
1102
1107
1103 def getstrippoint(minlink):
1108 def getstrippoint(minlink):
1104 """Find minimum revision that must be stripped to strip a linkrev.
1109 """Find minimum revision that must be stripped to strip a linkrev.
1105
1110
1106 See the documentation in ``ifilemutation`` for more.
1111 See the documentation in ``ifilemutation`` for more.
1107 """
1112 """
1108
1113
1109 def strip(minlink, transaction):
1114 def strip(minlink, transaction):
1110 """Remove storage of items starting at a linkrev.
1115 """Remove storage of items starting at a linkrev.
1111
1116
1112 See the documentation in ``ifilemutation`` for more.
1117 See the documentation in ``ifilemutation`` for more.
1113 """
1118 """
1114
1119
1115 def checksize():
1120 def checksize():
1116 """Obtain the expected sizes of backing files.
1121 """Obtain the expected sizes of backing files.
1117
1122
1118 TODO this is used by verify and it should not be part of the interface.
1123 TODO this is used by verify and it should not be part of the interface.
1119 """
1124 """
1120
1125
1121 def files():
1126 def files():
1122 """Obtain paths that are backing storage for this manifest.
1127 """Obtain paths that are backing storage for this manifest.
1123
1128
1124 TODO this is used by verify and there should probably be a better API
1129 TODO this is used by verify and there should probably be a better API
1125 for this functionality.
1130 for this functionality.
1126 """
1131 """
1127
1132
1128 def deltaparent(rev):
1133 def deltaparent(rev):
1129 """Obtain the revision that a revision is delta'd against.
1134 """Obtain the revision that a revision is delta'd against.
1130
1135
1131 TODO delta encoding is an implementation detail of storage and should
1136 TODO delta encoding is an implementation detail of storage and should
1132 not be exposed to the storage interface.
1137 not be exposed to the storage interface.
1133 """
1138 """
1134
1139
1135 def clone(tr, dest, **kwargs):
1140 def clone(tr, dest, **kwargs):
1136 """Clone this instance to another."""
1141 """Clone this instance to another."""
1137
1142
1138 def clearcaches(clear_persisted_data=False):
1143 def clearcaches(clear_persisted_data=False):
1139 """Clear any caches associated with this instance."""
1144 """Clear any caches associated with this instance."""
1140
1145
1141 def dirlog(d):
1146 def dirlog(d):
1142 """Obtain a manifest storage instance for a tree."""
1147 """Obtain a manifest storage instance for a tree."""
1143
1148
1144 def add(m, transaction, link, p1, p2, added, removed, readtree=None):
1149 def add(m, transaction, link, p1, p2, added, removed, readtree=None,
1150 match=None):
1145 """Add a revision to storage.
1151 """Add a revision to storage.
1146
1152
1147 ``m`` is an object conforming to ``imanifestdict``.
1153 ``m`` is an object conforming to ``imanifestdict``.
1148
1154
1149 ``link`` is the linkrev revision number.
1155 ``link`` is the linkrev revision number.
1150
1156
1151 ``p1`` and ``p2`` are the parent revision numbers.
1157 ``p1`` and ``p2`` are the parent revision numbers.
1152
1158
1153 ``added`` and ``removed`` are iterables of added and removed paths,
1159 ``added`` and ``removed`` are iterables of added and removed paths,
1154 respectively.
1160 respectively.
1161
1162 ``readtree`` is a function that can be used to read the child tree(s)
1163 when recursively writing the full tree structure when using
1164 treemanifets.
1165
1166 ``match`` is a matcher that can be used to hint to storage that not all
1167 paths must be inspected; this is an optimization and can be safely
1168 ignored. Note that the storage must still be able to reproduce a full
1169 manifest including files that did not match.
1155 """
1170 """
1156
1171
1157 class imanifestlog(interfaceutil.Interface):
1172 class imanifestlog(interfaceutil.Interface):
1158 """Interface representing a collection of manifest snapshots.
1173 """Interface representing a collection of manifest snapshots.
1159
1174
1160 Represents the root manifest in a repository.
1175 Represents the root manifest in a repository.
1161
1176
1162 Also serves as a means to access nested tree manifests and to cache
1177 Also serves as a means to access nested tree manifests and to cache
1163 tree manifests.
1178 tree manifests.
1164 """
1179 """
1165
1180
1166 def __getitem__(node):
1181 def __getitem__(node):
1167 """Obtain a manifest instance for a given binary node.
1182 """Obtain a manifest instance for a given binary node.
1168
1183
1169 Equivalent to calling ``self.get('', node)``.
1184 Equivalent to calling ``self.get('', node)``.
1170
1185
1171 The returned object conforms to the ``imanifestrevisionstored``
1186 The returned object conforms to the ``imanifestrevisionstored``
1172 interface.
1187 interface.
1173 """
1188 """
1174
1189
1175 def get(tree, node, verify=True):
1190 def get(tree, node, verify=True):
1176 """Retrieve the manifest instance for a given directory and binary node.
1191 """Retrieve the manifest instance for a given directory and binary node.
1177
1192
1178 ``node`` always refers to the node of the root manifest (which will be
1193 ``node`` always refers to the node of the root manifest (which will be
1179 the only manifest if flat manifests are being used).
1194 the only manifest if flat manifests are being used).
1180
1195
1181 If ``tree`` is the empty string, the root manifest is returned.
1196 If ``tree`` is the empty string, the root manifest is returned.
1182 Otherwise the manifest for the specified directory will be returned
1197 Otherwise the manifest for the specified directory will be returned
1183 (requires tree manifests).
1198 (requires tree manifests).
1184
1199
1185 If ``verify`` is True, ``LookupError`` is raised if the node is not
1200 If ``verify`` is True, ``LookupError`` is raised if the node is not
1186 known.
1201 known.
1187
1202
1188 The returned object conforms to the ``imanifestrevisionstored``
1203 The returned object conforms to the ``imanifestrevisionstored``
1189 interface.
1204 interface.
1190 """
1205 """
1191
1206
1192 def getstorage(tree):
1207 def getstorage(tree):
1193 """Retrieve an interface to storage for a particular tree.
1208 """Retrieve an interface to storage for a particular tree.
1194
1209
1195 If ``tree`` is the empty bytestring, storage for the root manifest will
1210 If ``tree`` is the empty bytestring, storage for the root manifest will
1196 be returned. Otherwise storage for a tree manifest is returned.
1211 be returned. Otherwise storage for a tree manifest is returned.
1197
1212
1198 TODO formalize interface for returned object.
1213 TODO formalize interface for returned object.
1199 """
1214 """
1200
1215
1201 def clearcaches():
1216 def clearcaches():
1202 """Clear caches associated with this collection."""
1217 """Clear caches associated with this collection."""
1203
1218
1204 def rev(node):
1219 def rev(node):
1205 """Obtain the revision number for a binary node.
1220 """Obtain the revision number for a binary node.
1206
1221
1207 Raises ``error.LookupError`` if the node is not known.
1222 Raises ``error.LookupError`` if the node is not known.
1208 """
1223 """
1209
1224
1210 class completelocalrepository(interfaceutil.Interface):
1225 class completelocalrepository(interfaceutil.Interface):
1211 """Monolithic interface for local repositories.
1226 """Monolithic interface for local repositories.
1212
1227
1213 This currently captures the reality of things - not how things should be.
1228 This currently captures the reality of things - not how things should be.
1214 """
1229 """
1215
1230
1216 supportedformats = interfaceutil.Attribute(
1231 supportedformats = interfaceutil.Attribute(
1217 """Set of requirements that apply to stream clone.
1232 """Set of requirements that apply to stream clone.
1218
1233
1219 This is actually a class attribute and is shared among all instances.
1234 This is actually a class attribute and is shared among all instances.
1220 """)
1235 """)
1221
1236
1222 openerreqs = interfaceutil.Attribute(
1237 openerreqs = interfaceutil.Attribute(
1223 """Set of requirements that are passed to the opener.
1238 """Set of requirements that are passed to the opener.
1224
1239
1225 This is actually a class attribute and is shared among all instances.
1240 This is actually a class attribute and is shared among all instances.
1226 """)
1241 """)
1227
1242
1228 supported = interfaceutil.Attribute(
1243 supported = interfaceutil.Attribute(
1229 """Set of requirements that this repo is capable of opening.""")
1244 """Set of requirements that this repo is capable of opening.""")
1230
1245
1231 requirements = interfaceutil.Attribute(
1246 requirements = interfaceutil.Attribute(
1232 """Set of requirements this repo uses.""")
1247 """Set of requirements this repo uses.""")
1233
1248
1234 filtername = interfaceutil.Attribute(
1249 filtername = interfaceutil.Attribute(
1235 """Name of the repoview that is active on this repo.""")
1250 """Name of the repoview that is active on this repo.""")
1236
1251
1237 wvfs = interfaceutil.Attribute(
1252 wvfs = interfaceutil.Attribute(
1238 """VFS used to access the working directory.""")
1253 """VFS used to access the working directory.""")
1239
1254
1240 vfs = interfaceutil.Attribute(
1255 vfs = interfaceutil.Attribute(
1241 """VFS rooted at the .hg directory.
1256 """VFS rooted at the .hg directory.
1242
1257
1243 Used to access repository data not in the store.
1258 Used to access repository data not in the store.
1244 """)
1259 """)
1245
1260
1246 svfs = interfaceutil.Attribute(
1261 svfs = interfaceutil.Attribute(
1247 """VFS rooted at the store.
1262 """VFS rooted at the store.
1248
1263
1249 Used to access repository data in the store. Typically .hg/store.
1264 Used to access repository data in the store. Typically .hg/store.
1250 But can point elsewhere if the store is shared.
1265 But can point elsewhere if the store is shared.
1251 """)
1266 """)
1252
1267
1253 root = interfaceutil.Attribute(
1268 root = interfaceutil.Attribute(
1254 """Path to the root of the working directory.""")
1269 """Path to the root of the working directory.""")
1255
1270
1256 path = interfaceutil.Attribute(
1271 path = interfaceutil.Attribute(
1257 """Path to the .hg directory.""")
1272 """Path to the .hg directory.""")
1258
1273
1259 origroot = interfaceutil.Attribute(
1274 origroot = interfaceutil.Attribute(
1260 """The filesystem path that was used to construct the repo.""")
1275 """The filesystem path that was used to construct the repo.""")
1261
1276
1262 auditor = interfaceutil.Attribute(
1277 auditor = interfaceutil.Attribute(
1263 """A pathauditor for the working directory.
1278 """A pathauditor for the working directory.
1264
1279
1265 This checks if a path refers to a nested repository.
1280 This checks if a path refers to a nested repository.
1266
1281
1267 Operates on the filesystem.
1282 Operates on the filesystem.
1268 """)
1283 """)
1269
1284
1270 nofsauditor = interfaceutil.Attribute(
1285 nofsauditor = interfaceutil.Attribute(
1271 """A pathauditor for the working directory.
1286 """A pathauditor for the working directory.
1272
1287
1273 This is like ``auditor`` except it doesn't do filesystem checks.
1288 This is like ``auditor`` except it doesn't do filesystem checks.
1274 """)
1289 """)
1275
1290
1276 baseui = interfaceutil.Attribute(
1291 baseui = interfaceutil.Attribute(
1277 """Original ui instance passed into constructor.""")
1292 """Original ui instance passed into constructor.""")
1278
1293
1279 ui = interfaceutil.Attribute(
1294 ui = interfaceutil.Attribute(
1280 """Main ui instance for this instance.""")
1295 """Main ui instance for this instance.""")
1281
1296
1282 sharedpath = interfaceutil.Attribute(
1297 sharedpath = interfaceutil.Attribute(
1283 """Path to the .hg directory of the repo this repo was shared from.""")
1298 """Path to the .hg directory of the repo this repo was shared from.""")
1284
1299
1285 store = interfaceutil.Attribute(
1300 store = interfaceutil.Attribute(
1286 """A store instance.""")
1301 """A store instance.""")
1287
1302
1288 spath = interfaceutil.Attribute(
1303 spath = interfaceutil.Attribute(
1289 """Path to the store.""")
1304 """Path to the store.""")
1290
1305
1291 sjoin = interfaceutil.Attribute(
1306 sjoin = interfaceutil.Attribute(
1292 """Alias to self.store.join.""")
1307 """Alias to self.store.join.""")
1293
1308
1294 cachevfs = interfaceutil.Attribute(
1309 cachevfs = interfaceutil.Attribute(
1295 """A VFS used to access the cache directory.
1310 """A VFS used to access the cache directory.
1296
1311
1297 Typically .hg/cache.
1312 Typically .hg/cache.
1298 """)
1313 """)
1299
1314
1300 filteredrevcache = interfaceutil.Attribute(
1315 filteredrevcache = interfaceutil.Attribute(
1301 """Holds sets of revisions to be filtered.""")
1316 """Holds sets of revisions to be filtered.""")
1302
1317
1303 names = interfaceutil.Attribute(
1318 names = interfaceutil.Attribute(
1304 """A ``namespaces`` instance.""")
1319 """A ``namespaces`` instance.""")
1305
1320
1306 def close():
1321 def close():
1307 """Close the handle on this repository."""
1322 """Close the handle on this repository."""
1308
1323
1309 def peer():
1324 def peer():
1310 """Obtain an object conforming to the ``peer`` interface."""
1325 """Obtain an object conforming to the ``peer`` interface."""
1311
1326
1312 def unfiltered():
1327 def unfiltered():
1313 """Obtain an unfiltered/raw view of this repo."""
1328 """Obtain an unfiltered/raw view of this repo."""
1314
1329
1315 def filtered(name, visibilityexceptions=None):
1330 def filtered(name, visibilityexceptions=None):
1316 """Obtain a named view of this repository."""
1331 """Obtain a named view of this repository."""
1317
1332
1318 obsstore = interfaceutil.Attribute(
1333 obsstore = interfaceutil.Attribute(
1319 """A store of obsolescence data.""")
1334 """A store of obsolescence data.""")
1320
1335
1321 changelog = interfaceutil.Attribute(
1336 changelog = interfaceutil.Attribute(
1322 """A handle on the changelog revlog.""")
1337 """A handle on the changelog revlog.""")
1323
1338
1324 manifestlog = interfaceutil.Attribute(
1339 manifestlog = interfaceutil.Attribute(
1325 """An instance conforming to the ``imanifestlog`` interface.
1340 """An instance conforming to the ``imanifestlog`` interface.
1326
1341
1327 Provides access to manifests for the repository.
1342 Provides access to manifests for the repository.
1328 """)
1343 """)
1329
1344
1330 dirstate = interfaceutil.Attribute(
1345 dirstate = interfaceutil.Attribute(
1331 """Working directory state.""")
1346 """Working directory state.""")
1332
1347
1333 narrowpats = interfaceutil.Attribute(
1348 narrowpats = interfaceutil.Attribute(
1334 """Matcher patterns for this repository's narrowspec.""")
1349 """Matcher patterns for this repository's narrowspec.""")
1335
1350
1336 def narrowmatch():
1351 def narrowmatch():
1337 """Obtain a matcher for the narrowspec."""
1352 """Obtain a matcher for the narrowspec."""
1338
1353
1339 def setnarrowpats(newincludes, newexcludes):
1354 def setnarrowpats(newincludes, newexcludes):
1340 """Define the narrowspec for this repository."""
1355 """Define the narrowspec for this repository."""
1341
1356
1342 def __getitem__(changeid):
1357 def __getitem__(changeid):
1343 """Try to resolve a changectx."""
1358 """Try to resolve a changectx."""
1344
1359
1345 def __contains__(changeid):
1360 def __contains__(changeid):
1346 """Whether a changeset exists."""
1361 """Whether a changeset exists."""
1347
1362
1348 def __nonzero__():
1363 def __nonzero__():
1349 """Always returns True."""
1364 """Always returns True."""
1350 return True
1365 return True
1351
1366
1352 __bool__ = __nonzero__
1367 __bool__ = __nonzero__
1353
1368
1354 def __len__():
1369 def __len__():
1355 """Returns the number of changesets in the repo."""
1370 """Returns the number of changesets in the repo."""
1356
1371
1357 def __iter__():
1372 def __iter__():
1358 """Iterate over revisions in the changelog."""
1373 """Iterate over revisions in the changelog."""
1359
1374
1360 def revs(expr, *args):
1375 def revs(expr, *args):
1361 """Evaluate a revset.
1376 """Evaluate a revset.
1362
1377
1363 Emits revisions.
1378 Emits revisions.
1364 """
1379 """
1365
1380
1366 def set(expr, *args):
1381 def set(expr, *args):
1367 """Evaluate a revset.
1382 """Evaluate a revset.
1368
1383
1369 Emits changectx instances.
1384 Emits changectx instances.
1370 """
1385 """
1371
1386
1372 def anyrevs(specs, user=False, localalias=None):
1387 def anyrevs(specs, user=False, localalias=None):
1373 """Find revisions matching one of the given revsets."""
1388 """Find revisions matching one of the given revsets."""
1374
1389
1375 def url():
1390 def url():
1376 """Returns a string representing the location of this repo."""
1391 """Returns a string representing the location of this repo."""
1377
1392
1378 def hook(name, throw=False, **args):
1393 def hook(name, throw=False, **args):
1379 """Call a hook."""
1394 """Call a hook."""
1380
1395
1381 def tags():
1396 def tags():
1382 """Return a mapping of tag to node."""
1397 """Return a mapping of tag to node."""
1383
1398
1384 def tagtype(tagname):
1399 def tagtype(tagname):
1385 """Return the type of a given tag."""
1400 """Return the type of a given tag."""
1386
1401
1387 def tagslist():
1402 def tagslist():
1388 """Return a list of tags ordered by revision."""
1403 """Return a list of tags ordered by revision."""
1389
1404
1390 def nodetags(node):
1405 def nodetags(node):
1391 """Return the tags associated with a node."""
1406 """Return the tags associated with a node."""
1392
1407
1393 def nodebookmarks(node):
1408 def nodebookmarks(node):
1394 """Return the list of bookmarks pointing to the specified node."""
1409 """Return the list of bookmarks pointing to the specified node."""
1395
1410
1396 def branchmap():
1411 def branchmap():
1397 """Return a mapping of branch to heads in that branch."""
1412 """Return a mapping of branch to heads in that branch."""
1398
1413
1399 def revbranchcache():
1414 def revbranchcache():
1400 pass
1415 pass
1401
1416
1402 def branchtip(branchtip, ignoremissing=False):
1417 def branchtip(branchtip, ignoremissing=False):
1403 """Return the tip node for a given branch."""
1418 """Return the tip node for a given branch."""
1404
1419
1405 def lookup(key):
1420 def lookup(key):
1406 """Resolve the node for a revision."""
1421 """Resolve the node for a revision."""
1407
1422
1408 def lookupbranch(key):
1423 def lookupbranch(key):
1409 """Look up the branch name of the given revision or branch name."""
1424 """Look up the branch name of the given revision or branch name."""
1410
1425
1411 def known(nodes):
1426 def known(nodes):
1412 """Determine whether a series of nodes is known.
1427 """Determine whether a series of nodes is known.
1413
1428
1414 Returns a list of bools.
1429 Returns a list of bools.
1415 """
1430 """
1416
1431
1417 def local():
1432 def local():
1418 """Whether the repository is local."""
1433 """Whether the repository is local."""
1419 return True
1434 return True
1420
1435
1421 def publishing():
1436 def publishing():
1422 """Whether the repository is a publishing repository."""
1437 """Whether the repository is a publishing repository."""
1423
1438
1424 def cancopy():
1439 def cancopy():
1425 pass
1440 pass
1426
1441
1427 def shared():
1442 def shared():
1428 """The type of shared repository or None."""
1443 """The type of shared repository or None."""
1429
1444
1430 def wjoin(f, *insidef):
1445 def wjoin(f, *insidef):
1431 """Calls self.vfs.reljoin(self.root, f, *insidef)"""
1446 """Calls self.vfs.reljoin(self.root, f, *insidef)"""
1432
1447
1433 def file(f):
1448 def file(f):
1434 """Obtain a filelog for a tracked path.
1449 """Obtain a filelog for a tracked path.
1435
1450
1436 The returned type conforms to the ``ifilestorage`` interface.
1451 The returned type conforms to the ``ifilestorage`` interface.
1437 """
1452 """
1438
1453
1439 def setparents(p1, p2):
1454 def setparents(p1, p2):
1440 """Set the parent nodes of the working directory."""
1455 """Set the parent nodes of the working directory."""
1441
1456
1442 def filectx(path, changeid=None, fileid=None):
1457 def filectx(path, changeid=None, fileid=None):
1443 """Obtain a filectx for the given file revision."""
1458 """Obtain a filectx for the given file revision."""
1444
1459
1445 def getcwd():
1460 def getcwd():
1446 """Obtain the current working directory from the dirstate."""
1461 """Obtain the current working directory from the dirstate."""
1447
1462
1448 def pathto(f, cwd=None):
1463 def pathto(f, cwd=None):
1449 """Obtain the relative path to a file."""
1464 """Obtain the relative path to a file."""
1450
1465
1451 def adddatafilter(name, fltr):
1466 def adddatafilter(name, fltr):
1452 pass
1467 pass
1453
1468
1454 def wread(filename):
1469 def wread(filename):
1455 """Read a file from wvfs, using data filters."""
1470 """Read a file from wvfs, using data filters."""
1456
1471
1457 def wwrite(filename, data, flags, backgroundclose=False, **kwargs):
1472 def wwrite(filename, data, flags, backgroundclose=False, **kwargs):
1458 """Write data to a file in the wvfs, using data filters."""
1473 """Write data to a file in the wvfs, using data filters."""
1459
1474
1460 def wwritedata(filename, data):
1475 def wwritedata(filename, data):
1461 """Resolve data for writing to the wvfs, using data filters."""
1476 """Resolve data for writing to the wvfs, using data filters."""
1462
1477
1463 def currenttransaction():
1478 def currenttransaction():
1464 """Obtain the current transaction instance or None."""
1479 """Obtain the current transaction instance or None."""
1465
1480
1466 def transaction(desc, report=None):
1481 def transaction(desc, report=None):
1467 """Open a new transaction to write to the repository."""
1482 """Open a new transaction to write to the repository."""
1468
1483
1469 def undofiles():
1484 def undofiles():
1470 """Returns a list of (vfs, path) for files to undo transactions."""
1485 """Returns a list of (vfs, path) for files to undo transactions."""
1471
1486
1472 def recover():
1487 def recover():
1473 """Roll back an interrupted transaction."""
1488 """Roll back an interrupted transaction."""
1474
1489
1475 def rollback(dryrun=False, force=False):
1490 def rollback(dryrun=False, force=False):
1476 """Undo the last transaction.
1491 """Undo the last transaction.
1477
1492
1478 DANGEROUS.
1493 DANGEROUS.
1479 """
1494 """
1480
1495
1481 def updatecaches(tr=None, full=False):
1496 def updatecaches(tr=None, full=False):
1482 """Warm repo caches."""
1497 """Warm repo caches."""
1483
1498
1484 def invalidatecaches():
1499 def invalidatecaches():
1485 """Invalidate cached data due to the repository mutating."""
1500 """Invalidate cached data due to the repository mutating."""
1486
1501
1487 def invalidatevolatilesets():
1502 def invalidatevolatilesets():
1488 pass
1503 pass
1489
1504
1490 def invalidatedirstate():
1505 def invalidatedirstate():
1491 """Invalidate the dirstate."""
1506 """Invalidate the dirstate."""
1492
1507
1493 def invalidate(clearfilecache=False):
1508 def invalidate(clearfilecache=False):
1494 pass
1509 pass
1495
1510
1496 def invalidateall():
1511 def invalidateall():
1497 pass
1512 pass
1498
1513
1499 def lock(wait=True):
1514 def lock(wait=True):
1500 """Lock the repository store and return a lock instance."""
1515 """Lock the repository store and return a lock instance."""
1501
1516
1502 def wlock(wait=True):
1517 def wlock(wait=True):
1503 """Lock the non-store parts of the repository."""
1518 """Lock the non-store parts of the repository."""
1504
1519
1505 def currentwlock():
1520 def currentwlock():
1506 """Return the wlock if it's held or None."""
1521 """Return the wlock if it's held or None."""
1507
1522
1508 def checkcommitpatterns(wctx, vdirs, match, status, fail):
1523 def checkcommitpatterns(wctx, vdirs, match, status, fail):
1509 pass
1524 pass
1510
1525
1511 def commit(text='', user=None, date=None, match=None, force=False,
1526 def commit(text='', user=None, date=None, match=None, force=False,
1512 editor=False, extra=None):
1527 editor=False, extra=None):
1513 """Add a new revision to the repository."""
1528 """Add a new revision to the repository."""
1514
1529
1515 def commitctx(ctx, error=False):
1530 def commitctx(ctx, error=False):
1516 """Commit a commitctx instance to the repository."""
1531 """Commit a commitctx instance to the repository."""
1517
1532
1518 def destroying():
1533 def destroying():
1519 """Inform the repository that nodes are about to be destroyed."""
1534 """Inform the repository that nodes are about to be destroyed."""
1520
1535
1521 def destroyed():
1536 def destroyed():
1522 """Inform the repository that nodes have been destroyed."""
1537 """Inform the repository that nodes have been destroyed."""
1523
1538
1524 def status(node1='.', node2=None, match=None, ignored=False,
1539 def status(node1='.', node2=None, match=None, ignored=False,
1525 clean=False, unknown=False, listsubrepos=False):
1540 clean=False, unknown=False, listsubrepos=False):
1526 """Convenience method to call repo[x].status()."""
1541 """Convenience method to call repo[x].status()."""
1527
1542
1528 def addpostdsstatus(ps):
1543 def addpostdsstatus(ps):
1529 pass
1544 pass
1530
1545
1531 def postdsstatus():
1546 def postdsstatus():
1532 pass
1547 pass
1533
1548
1534 def clearpostdsstatus():
1549 def clearpostdsstatus():
1535 pass
1550 pass
1536
1551
1537 def heads(start=None):
1552 def heads(start=None):
1538 """Obtain list of nodes that are DAG heads."""
1553 """Obtain list of nodes that are DAG heads."""
1539
1554
1540 def branchheads(branch=None, start=None, closed=False):
1555 def branchheads(branch=None, start=None, closed=False):
1541 pass
1556 pass
1542
1557
1543 def branches(nodes):
1558 def branches(nodes):
1544 pass
1559 pass
1545
1560
1546 def between(pairs):
1561 def between(pairs):
1547 pass
1562 pass
1548
1563
1549 def checkpush(pushop):
1564 def checkpush(pushop):
1550 pass
1565 pass
1551
1566
1552 prepushoutgoinghooks = interfaceutil.Attribute(
1567 prepushoutgoinghooks = interfaceutil.Attribute(
1553 """util.hooks instance.""")
1568 """util.hooks instance.""")
1554
1569
1555 def pushkey(namespace, key, old, new):
1570 def pushkey(namespace, key, old, new):
1556 pass
1571 pass
1557
1572
1558 def listkeys(namespace):
1573 def listkeys(namespace):
1559 pass
1574 pass
1560
1575
1561 def debugwireargs(one, two, three=None, four=None, five=None):
1576 def debugwireargs(one, two, three=None, four=None, five=None):
1562 pass
1577 pass
1563
1578
1564 def savecommitmessage(text):
1579 def savecommitmessage(text):
1565 pass
1580 pass
General Comments 0
You need to be logged in to leave comments. Login now