comparison mercurial/localrepo.py @ 45353:665e911563da

localrepo: refactor logic to calculate sharedvfs in separate fn We will be reusing this in an upcoming patch, so better to refactor it into a separate function. Also the underlying handling deserves a function of it's own. Differential Revision: https://phab.mercurial-scm.org/D8909
author Pulkit Goyal <7895pulkit@gmail.com>
date Fri, 07 Aug 2020 15:52:52 +0530
parents dc283bc7e033
children c4fe2262435e
comparison
equal deleted inserted replaced
45351:909dafff6a78 45353:665e911563da
457 # is capable of opening. Functions will typically add elements to the 457 # is capable of opening. Functions will typically add elements to the
458 # set to reflect that the extension knows how to handle that requirements. 458 # set to reflect that the extension knows how to handle that requirements.
459 featuresetupfuncs = set() 459 featuresetupfuncs = set()
460 460
461 461
462 def _getsharedvfs(hgvfs, requirements):
463 """ returns the vfs object pointing to root of shared source
464 repo for a shared repository
465
466 hgvfs is vfs pointing at .hg/ of current repo (shared one)
467 requirements is a set of requirements of current repo (shared one)
468 """
469 # The ``shared`` or ``relshared`` requirements indicate the
470 # store lives in the path contained in the ``.hg/sharedpath`` file.
471 # This is an absolute path for ``shared`` and relative to
472 # ``.hg/`` for ``relshared``.
473 sharedpath = hgvfs.read(b'sharedpath').rstrip(b'\n')
474 if b'relshared' in requirements:
475 sharedpath = hgvfs.join(sharedpath)
476
477 sharedvfs = vfsmod.vfs(sharedpath, realpath=True)
478
479 if not sharedvfs.exists():
480 raise error.RepoError(
481 _(b'.hg/sharedpath points to nonexistent directory %s')
482 % sharedvfs.base
483 )
484 return sharedvfs
485
486
462 def makelocalrepository(baseui, path, intents=None): 487 def makelocalrepository(baseui, path, intents=None):
463 """Create a local repository object. 488 """Create a local repository object.
464 489
465 Given arguments needed to construct a local repository, this function 490 Given arguments needed to construct a local repository, this function
466 performs various early repository loading functionality (such as 491 performs various early repository loading functionality (such as
498 wdirvfs = vfsmod.vfs(path, expandpath=True, realpath=True) 523 wdirvfs = vfsmod.vfs(path, expandpath=True, realpath=True)
499 524
500 # Main VFS for .hg/ directory. 525 # Main VFS for .hg/ directory.
501 hgpath = wdirvfs.join(b'.hg') 526 hgpath = wdirvfs.join(b'.hg')
502 hgvfs = vfsmod.vfs(hgpath, cacheaudited=True) 527 hgvfs = vfsmod.vfs(hgpath, cacheaudited=True)
528 # Whether this repository is shared one or not
529 shared = False
530 # If this repository is shared, vfs pointing to shared repo
531 sharedvfs = None
503 532
504 # The .hg/ path should exist and should be a directory. All other 533 # The .hg/ path should exist and should be a directory. All other
505 # cases are errors. 534 # cases are errors.
506 if not hgvfs.isdir(): 535 if not hgvfs.isdir():
507 try: 536 try:
565 # Now get on with doing that. 594 # Now get on with doing that.
566 595
567 features = set() 596 features = set()
568 597
569 # The "store" part of the repository holds versioned data. How it is 598 # The "store" part of the repository holds versioned data. How it is
570 # accessed is determined by various requirements. The ``shared`` or 599 # accessed is determined by various requirements. If `shared` or
571 # ``relshared`` requirements indicate the store lives in the path contained 600 # `relshared` requirements are present, this indicates current repository
572 # in the ``.hg/sharedpath`` file. This is an absolute path for 601 # is a share and store exists in path mentioned in `.hg/sharedpath`
573 # ``shared`` and relative to ``.hg/`` for ``relshared``. 602 shared = b'shared' in requirements or b'relshared' in requirements
574 if b'shared' in requirements or b'relshared' in requirements: 603 if shared:
575 sharedpath = hgvfs.read(b'sharedpath').rstrip(b'\n') 604 sharedvfs = _getsharedvfs(hgvfs, requirements)
576 if b'relshared' in requirements:
577 sharedpath = hgvfs.join(sharedpath)
578
579 sharedvfs = vfsmod.vfs(sharedpath, realpath=True)
580
581 if not sharedvfs.exists():
582 raise error.RepoError(
583 _(b'.hg/sharedpath points to nonexistent directory %s')
584 % sharedvfs.base
585 )
586
587 features.add(repository.REPO_FEATURE_SHARED_STORAGE)
588
589 storebasepath = sharedvfs.base 605 storebasepath = sharedvfs.base
590 cachepath = sharedvfs.join(b'cache') 606 cachepath = sharedvfs.join(b'cache')
607 features.add(repository.REPO_FEATURE_SHARED_STORAGE)
591 else: 608 else:
592 storebasepath = hgvfs.base 609 storebasepath = hgvfs.base
593 cachepath = hgvfs.join(b'cache') 610 cachepath = hgvfs.join(b'cache')
594 wcachepath = hgvfs.join(b'wcache') 611 wcachepath = hgvfs.join(b'wcache')
595 612