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