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