##// END OF EJS Templates
localrepo: extract resolving of opener options to standalone functions...
Gregory Szorc -
r39736:b10d1458 default
parent child Browse files
Show More
@@ -1779,6 +1779,8 b' def handlechangegroup(op, inpart):'
1779 This is a very early implementation that will massive rework before being
1779 This is a very early implementation that will massive rework before being
1780 inflicted to any end-user.
1780 inflicted to any end-user.
1781 """
1781 """
1782 from . import localrepo
1783
1782 tr = op.gettransaction()
1784 tr = op.gettransaction()
1783 unpackerversion = inpart.params.get('version', '01')
1785 unpackerversion = inpart.params.get('version', '01')
1784 # We should raise an appropriate exception here
1786 # We should raise an appropriate exception here
@@ -1795,7 +1797,8 b' def handlechangegroup(op, inpart):'
1795 "bundle contains tree manifests, but local repo is "
1797 "bundle contains tree manifests, but local repo is "
1796 "non-empty and does not use tree manifests"))
1798 "non-empty and does not use tree manifests"))
1797 op.repo.requirements.add('treemanifest')
1799 op.repo.requirements.add('treemanifest')
1798 op.repo._applyopenerreqs()
1800 op.repo.svfs.options = localrepo.resolvestorevfsoptions(
1801 op.repo.ui, op.repo.requirements)
1799 op.repo._writerequirements()
1802 op.repo._writerequirements()
1800 extrakwargs = {}
1803 extrakwargs = {}
1801 targetphase = inpart.params.get('targetphase')
1804 targetphase = inpart.params.get('targetphase')
@@ -481,9 +481,11 b' def makelocalrepository(baseui, path, in'
481 # of them.
481 # of them.
482 store = makestore(requirements, storebasepath,
482 store = makestore(requirements, storebasepath,
483 lambda base: vfsmod.vfs(base, cacheaudited=True))
483 lambda base: vfsmod.vfs(base, cacheaudited=True))
484
485 hgvfs.createmode = store.createmode
484 hgvfs.createmode = store.createmode
486
485
486 storevfs = store.vfs
487 storevfs.options = resolvestorevfsoptions(ui, requirements)
488
487 # The cache vfs is used to manage cache files.
489 # The cache vfs is used to manage cache files.
488 cachevfs = vfsmod.vfs(cachepath, cacheaudited=True)
490 cachevfs = vfsmod.vfs(cachepath, cacheaudited=True)
489 cachevfs.createmode = store.createmode
491 cachevfs.createmode = store.createmode
@@ -578,6 +580,92 b' def makestore(requirements, path, vfstyp'
578
580
579 return storemod.basicstore(path, vfstype)
581 return storemod.basicstore(path, vfstype)
580
582
583 def resolvestorevfsoptions(ui, requirements):
584 """Resolve the options to pass to the store vfs opener.
585
586 The returned dict is used to influence behavior of the storage layer.
587 """
588 options = {}
589
590 if b'treemanifest' in requirements:
591 options[b'treemanifest'] = True
592
593 # experimental config: format.manifestcachesize
594 manifestcachesize = ui.configint(b'format', b'manifestcachesize')
595 if manifestcachesize is not None:
596 options[b'manifestcachesize'] = manifestcachesize
597
598 # In the absence of another requirement superseding a revlog-related
599 # requirement, we have to assume the repo is using revlog version 0.
600 # This revlog format is super old and we don't bother trying to parse
601 # opener options for it because those options wouldn't do anything
602 # meaningful on such old repos.
603 if b'revlogv1' in requirements or REVLOGV2_REQUIREMENT in requirements:
604 options.update(resolverevlogstorevfsoptions(ui, requirements))
605
606 return options
607
608 def resolverevlogstorevfsoptions(ui, requirements):
609 """Resolve opener options specific to revlogs."""
610
611 options = {}
612
613 if b'revlogv1' in requirements:
614 options[b'revlogv1'] = True
615 if REVLOGV2_REQUIREMENT in requirements:
616 options[b'revlogv2'] = True
617
618 if b'generaldelta' in requirements:
619 options[b'generaldelta'] = True
620
621 # experimental config: format.chunkcachesize
622 chunkcachesize = ui.configint(b'format', b'chunkcachesize')
623 if chunkcachesize is not None:
624 options[b'chunkcachesize'] = chunkcachesize
625
626 deltabothparents = ui.configbool(b'storage',
627 b'revlog.optimize-delta-parent-choice')
628 options[b'deltabothparents'] = deltabothparents
629
630 options[b'lazydeltabase'] = not scmutil.gddeltaconfig(ui)
631
632 chainspan = ui.configbytes(b'experimental', b'maxdeltachainspan')
633 if 0 <= chainspan:
634 options[b'maxdeltachainspan'] = chainspan
635
636 mmapindexthreshold = ui.configbytes(b'experimental',
637 b'mmapindexthreshold')
638 if mmapindexthreshold is not None:
639 options[b'mmapindexthreshold'] = mmapindexthreshold
640
641 withsparseread = ui.configbool(b'experimental', b'sparse-read')
642 srdensitythres = float(ui.config(b'experimental',
643 b'sparse-read.density-threshold'))
644 srmingapsize = ui.configbytes(b'experimental',
645 b'sparse-read.min-gap-size')
646 options[b'with-sparse-read'] = withsparseread
647 options[b'sparse-read-density-threshold'] = srdensitythres
648 options[b'sparse-read-min-gap-size'] = srmingapsize
649
650 sparserevlog = SPARSEREVLOG_REQUIREMENT in requirements
651 options[b'sparse-revlog'] = sparserevlog
652 if sparserevlog:
653 options[b'generaldelta'] = True
654
655 maxchainlen = None
656 if sparserevlog:
657 maxchainlen = revlogconst.SPARSE_REVLOG_MAX_CHAIN_LENGTH
658 # experimental config: format.maxchainlen
659 maxchainlen = ui.configint(b'format', b'maxchainlen', maxchainlen)
660 if maxchainlen is not None:
661 options[b'maxchainlen'] = maxchainlen
662
663 for r in requirements:
664 if r.startswith(b'exp-compression-'):
665 options[b'compengine'] = r[len(b'exp-compression-'):]
666
667 return options
668
581 @interfaceutil.implementer(repository.completelocalrepository)
669 @interfaceutil.implementer(repository.completelocalrepository)
582 class localrepository(object):
670 class localrepository(object):
583
671
@@ -602,11 +690,6 b' class localrepository(object):'
602 'exp-sparse',
690 'exp-sparse',
603 'internal-phase'
691 'internal-phase'
604 }
692 }
605 openerreqs = {
606 'revlogv1',
607 'generaldelta',
608 'treemanifest',
609 }
610
693
611 # list of prefix for file which can be written without 'wlock'
694 # list of prefix for file which can be written without 'wlock'
612 # Extensions should extend this list when needed
695 # Extensions should extend this list when needed
@@ -712,7 +795,6 b' class localrepository(object):'
712 self.svfs.vfs.audit = self._getsvfsward(self.svfs.vfs.audit)
795 self.svfs.vfs.audit = self._getsvfsward(self.svfs.vfs.audit)
713 else: # standard vfs
796 else: # standard vfs
714 self.svfs.audit = self._getsvfsward(self.svfs.audit)
797 self.svfs.audit = self._getsvfsward(self.svfs.audit)
715 self._applyopenerreqs()
716
798
717 self._dirstatevalidatewarned = False
799 self._dirstatevalidatewarned = False
718
800
@@ -817,56 +899,6 b' class localrepository(object):'
817 caps.add('bundle2=' + urlreq.quote(capsblob))
899 caps.add('bundle2=' + urlreq.quote(capsblob))
818 return caps
900 return caps
819
901
820 def _applyopenerreqs(self):
821 self.svfs.options = {r: True for r in self.requirements
822 if r in self.openerreqs}
823 # experimental config: format.chunkcachesize
824 chunkcachesize = self.ui.configint('format', 'chunkcachesize')
825 if chunkcachesize is not None:
826 self.svfs.options['chunkcachesize'] = chunkcachesize
827 # experimental config: format.manifestcachesize
828 manifestcachesize = self.ui.configint('format', 'manifestcachesize')
829 if manifestcachesize is not None:
830 self.svfs.options['manifestcachesize'] = manifestcachesize
831 deltabothparents = self.ui.configbool('storage',
832 'revlog.optimize-delta-parent-choice')
833 self.svfs.options['deltabothparents'] = deltabothparents
834 self.svfs.options['lazydeltabase'] = not scmutil.gddeltaconfig(self.ui)
835 chainspan = self.ui.configbytes('experimental', 'maxdeltachainspan')
836 if 0 <= chainspan:
837 self.svfs.options['maxdeltachainspan'] = chainspan
838 mmapindexthreshold = self.ui.configbytes('experimental',
839 'mmapindexthreshold')
840 if mmapindexthreshold is not None:
841 self.svfs.options['mmapindexthreshold'] = mmapindexthreshold
842 withsparseread = self.ui.configbool('experimental', 'sparse-read')
843 srdensitythres = float(self.ui.config('experimental',
844 'sparse-read.density-threshold'))
845 srmingapsize = self.ui.configbytes('experimental',
846 'sparse-read.min-gap-size')
847 self.svfs.options['with-sparse-read'] = withsparseread
848 self.svfs.options['sparse-read-density-threshold'] = srdensitythres
849 self.svfs.options['sparse-read-min-gap-size'] = srmingapsize
850 sparserevlog = SPARSEREVLOG_REQUIREMENT in self.requirements
851 self.svfs.options['sparse-revlog'] = sparserevlog
852 if sparserevlog:
853 self.svfs.options['generaldelta'] = True
854 maxchainlen = None
855 if sparserevlog:
856 maxchainlen = revlogconst.SPARSE_REVLOG_MAX_CHAIN_LENGTH
857 # experimental config: format.maxchainlen
858 maxchainlen = self.ui.configint('format', 'maxchainlen', maxchainlen)
859 if maxchainlen is not None:
860 self.svfs.options['maxchainlen'] = maxchainlen
861
862 for r in self.requirements:
863 if r.startswith('exp-compression-'):
864 self.svfs.options['compengine'] = r[len('exp-compression-'):]
865
866 # TODO move "revlogv2" to openerreqs once finalized.
867 if REVLOGV2_REQUIREMENT in self.requirements:
868 self.svfs.options['revlogv2'] = True
869
870 def _writerequirements(self):
902 def _writerequirements(self):
871 scmutil.writerequires(self.vfs, self.requirements)
903 scmutil.writerequires(self.vfs, self.requirements)
872
904
@@ -1234,12 +1234,6 b' class completelocalrepository(interfaceu'
1234 This is actually a class attribute and is shared among all instances.
1234 This is actually a class attribute and is shared among all instances.
1235 """)
1235 """)
1236
1236
1237 openerreqs = interfaceutil.Attribute(
1238 """Set of requirements that are passed to the opener.
1239
1240 This is actually a class attribute and is shared among all instances.
1241 """)
1242
1243 supported = interfaceutil.Attribute(
1237 supported = interfaceutil.Attribute(
1244 """Set of requirements that this repo is capable of opening.""")
1238 """Set of requirements that this repo is capable of opening.""")
1245
1239
@@ -114,6 +114,8 b' def maybeperformlegacystreamclone(pullop'
114 A legacy stream clone will not be performed if a bundle2 stream clone is
114 A legacy stream clone will not be performed if a bundle2 stream clone is
115 supported.
115 supported.
116 """
116 """
117 from . import localrepo
118
117 supported, requirements = canperformstreamclone(pullop)
119 supported, requirements = canperformstreamclone(pullop)
118
120
119 if not supported:
121 if not supported:
@@ -166,7 +168,8 b' def maybeperformlegacystreamclone(pullop'
166 # requirements from the streamed-in repository
168 # requirements from the streamed-in repository
167 repo.requirements = requirements | (
169 repo.requirements = requirements | (
168 repo.requirements - repo.supportedformats)
170 repo.requirements - repo.supportedformats)
169 repo._applyopenerreqs()
171 repo.svfs.options = localrepo.resolvestorevfsoptions(
172 repo.ui, repo.requirements)
170 repo._writerequirements()
173 repo._writerequirements()
171
174
172 if rbranchmap:
175 if rbranchmap:
@@ -624,6 +627,8 b' def consumev2(repo, fp, filecount, files'
624 progress.complete()
627 progress.complete()
625
628
626 def applybundlev2(repo, fp, filecount, filesize, requirements):
629 def applybundlev2(repo, fp, filecount, filesize, requirements):
630 from . import localrepo
631
627 missingreqs = [r for r in requirements if r not in repo.supported]
632 missingreqs = [r for r in requirements if r not in repo.supported]
628 if missingreqs:
633 if missingreqs:
629 raise error.Abort(_('unable to apply stream clone: '
634 raise error.Abort(_('unable to apply stream clone: '
@@ -637,5 +642,6 b' def applybundlev2(repo, fp, filecount, f'
637 # requirements from the streamed-in repository
642 # requirements from the streamed-in repository
638 repo.requirements = set(requirements) | (
643 repo.requirements = set(requirements) | (
639 repo.requirements - repo.supportedformats)
644 repo.requirements - repo.supportedformats)
640 repo._applyopenerreqs()
645 repo.svfs.options = localrepo.resolvestorevfsoptions(
646 repo.ui, repo.requirements)
641 repo._writerequirements()
647 repo._writerequirements()
General Comments 0
You need to be logged in to leave comments. Login now