comparison mercurial/localrepo.py @ 51799:45c467d8422c

localrepo: remove _readrequires function in favor of scmutil.readrequires
author Arseniy Alekseyev <aalekseyev@janestreet.com>
date Thu, 15 Aug 2024 14:56:50 +0100
parents 5f37c36f36b9
children f4733654f144
comparison
equal deleted inserted replaced
51798:eb952b2d224c 51799:45c467d8422c
521 % sharedvfs.base 521 % sharedvfs.base
522 ) 522 )
523 return sharedvfs 523 return sharedvfs
524 524
525 525
526 def _readrequires(vfs, allowmissing):
527 """reads the require file present at root of this vfs
528 and return a set of requirements
529
530 If allowmissing is True, we suppress FileNotFoundError if raised"""
531 # requires file contains a newline-delimited list of
532 # features/capabilities the opener (us) must have in order to use
533 # the repository. This file was introduced in Mercurial 0.9.2,
534 # which means very old repositories may not have one. We assume
535 # a missing file translates to no requirements.
536 read = vfs.tryread if allowmissing else vfs.read
537 return set(read(b'requires').splitlines())
538
539
540 def makelocalrepository(baseui, path: bytes, intents=None): 526 def makelocalrepository(baseui, path: bytes, intents=None):
541 """Create a local repository object. 527 """Create a local repository object.
542 528
543 Given arguments needed to construct a local repository, this function 529 Given arguments needed to construct a local repository, this function
544 performs various early repository loading functionality (such as 530 performs various early repository loading functionality (such as
596 _(b'invalid path %s: %s') % (path, stringutil.forcebytestr(e)) 582 _(b'invalid path %s: %s') % (path, stringutil.forcebytestr(e))
597 ) 583 )
598 584
599 raise error.RepoError(_(b'repository %s not found') % path) 585 raise error.RepoError(_(b'repository %s not found') % path)
600 586
601 requirements = _readrequires(hgvfs, True) 587 requirements = scmutil.readrequires(hgvfs, True)
602 shared = ( 588 shared = (
603 requirementsmod.SHARED_REQUIREMENT in requirements 589 requirementsmod.SHARED_REQUIREMENT in requirements
604 or requirementsmod.RELATIVE_SHARED_REQUIREMENT in requirements 590 or requirementsmod.RELATIVE_SHARED_REQUIREMENT in requirements
605 ) 591 )
606 storevfs = None 592 storevfs = None
624 hint = _(b"see `hg help config.format.use-share-safe` for more information") 610 hint = _(b"see `hg help config.format.use-share-safe` for more information")
625 if requirementsmod.SHARESAFE_REQUIREMENT in requirements: 611 if requirementsmod.SHARESAFE_REQUIREMENT in requirements:
626 if ( 612 if (
627 shared 613 shared
628 and requirementsmod.SHARESAFE_REQUIREMENT 614 and requirementsmod.SHARESAFE_REQUIREMENT
629 not in _readrequires(sharedvfs, True) 615 not in scmutil.readrequires(sharedvfs, True)
630 ): 616 ):
631 mismatch_warn = ui.configbool( 617 mismatch_warn = ui.configbool(
632 b'share', b'safe-mismatch.source-not-safe.warn' 618 b'share', b'safe-mismatch.source-not-safe.warn'
633 ) 619 )
634 mismatch_config = ui.config( 620 mismatch_config = ui.config(
668 ) 654 )
669 % mismatch_config, 655 % mismatch_config,
670 hint=hint, 656 hint=hint,
671 ) 657 )
672 else: 658 else:
673 requirements |= _readrequires(storevfs, False) 659 requirements |= scmutil.readrequires(storevfs, False)
674 elif shared: 660 elif shared:
675 sourcerequires = _readrequires(sharedvfs, False) 661 sourcerequires = scmutil.readrequires(sharedvfs, False)
676 if requirementsmod.SHARESAFE_REQUIREMENT in sourcerequires: 662 if requirementsmod.SHARESAFE_REQUIREMENT in sourcerequires:
677 mismatch_config = ui.config(b'share', b'safe-mismatch.source-safe') 663 mismatch_config = ui.config(b'share', b'safe-mismatch.source-safe')
678 mismatch_warn = ui.configbool( 664 mismatch_warn = ui.configbool(
679 b'share', b'safe-mismatch.source-safe.warn' 665 b'share', b'safe-mismatch.source-safe.warn'
680 ) 666 )