# HG changeset patch # User Pulkit Goyal <7895pulkit@gmail.com> # Date 2020-09-01 12:38:24 # Node ID dfe585655c3b9eda718baab582da5a443ff976e6 # Parent eb443f7cbc2c10ae9a775c0d2b97c073d0773bf4 scmutil: introduce function to check whether repo uses treemanifest or not In an upcoming patch, I wanted to check whether current repo uses treemanifest or not. I looked for a function and found that at all places we manually check for the requirement in repo requirements. I guess having a dedicated function for that is much better. Differential Revision: https://phab.mercurial-scm.org/D8981 diff --git a/hgext/narrow/narrowbundle2.py b/hgext/narrow/narrowbundle2.py --- a/hgext/narrow/narrowbundle2.py +++ b/hgext/narrow/narrowbundle2.py @@ -108,7 +108,7 @@ def generateellipsesbundle2( part = bundler.newpart(b'changegroup', data=cgdata) part.addparam(b'version', version) - if requirements.TREEMANIFEST_REQUIREMENT in repo.requirements: + if scmutil.istreemanifest(repo): part.addparam(b'treemanifest', b'1') @@ -163,7 +163,7 @@ def generate_ellipses_bundle2_for_wideni part = bundler.newpart(b'changegroup', data=cgdata) part.addparam(b'version', version) - if requirements.TREEMANIFEST_REQUIREMENT in repo.requirements: + if scmutil.istreemanifest(repo): part.addparam(b'treemanifest', b'1') diff --git a/hgext/remotefilelog/remotefilelogserver.py b/hgext/remotefilelog/remotefilelogserver.py --- a/hgext/remotefilelog/remotefilelogserver.py +++ b/hgext/remotefilelog/remotefilelogserver.py @@ -23,7 +23,7 @@ from mercurial import ( extensions, match, pycompat, - requirements, + scmutil, store, streamclone, util, @@ -170,7 +170,7 @@ def onetimesetup(ui): if kind == stat.S_IFDIR: visit.append(fp) - if requirements.TREEMANIFEST_REQUIREMENT in repo.requirements: + if scmutil.istreemanifest(repo): for (u, e, s) in repo.store.datafiles(): if u.startswith(b'meta/') and ( u.endswith(b'.i') or u.endswith(b'.d') diff --git a/mercurial/bundle2.py b/mercurial/bundle2.py --- a/mercurial/bundle2.py +++ b/mercurial/bundle2.py @@ -1964,10 +1964,7 @@ def handlechangegroup(op, inpart): nbchangesets = None if b'nbchanges' in inpart.params: nbchangesets = int(inpart.params.get(b'nbchanges')) - if ( - b'treemanifest' in inpart.params - and requirements.TREEMANIFEST_REQUIREMENT not in op.repo.requirements - ): + if b'treemanifest' in inpart.params and not scmutil.istreemanifest(op.repo): if len(op.repo.changelog) != 0: raise error.Abort( _( @@ -2577,7 +2574,7 @@ def widen_bundle( part = bundler.newpart(b'changegroup', data=cgdata) part.addparam(b'version', cgversion) - if requirements.TREEMANIFEST_REQUIREMENT in repo.requirements: + if scmutil.istreemanifest(repo): part.addparam(b'treemanifest', b'1') if b'exp-sidedata-flag' in repo.requirements: part.addparam(b'exp-sidedata', b'1') diff --git a/mercurial/changegroup.py b/mercurial/changegroup.py --- a/mercurial/changegroup.py +++ b/mercurial/changegroup.py @@ -27,6 +27,7 @@ from . import ( phases, pycompat, requirements, + scmutil, util, ) @@ -949,9 +950,7 @@ class cgpacker(object): # Treemanifests don't work correctly with fastpathlinkrev # either, because we don't discover which directory nodes to # send along with files. This could probably be fixed. - fastpathlinkrev = fastpathlinkrev and ( - requirements.TREEMANIFEST_REQUIREMENT not in repo.requirements - ) + fastpathlinkrev = fastpathlinkrev and not scmutil.istreemanifest(repo) fnodes = {} # needed file nodes @@ -1468,7 +1467,7 @@ def allsupportedversions(repo): if ( repo.ui.configbool(b'experimental', b'changegroup3') or repo.ui.configbool(b'experimental', b'treemanifest') - or requirements.TREEMANIFEST_REQUIREMENT in repo.requirements + or scmutil.istreemanifest(repo) ): # we keep version 03 because we need to to exchange treemanifest data # @@ -1496,7 +1495,7 @@ def supportedincomingversions(repo): # Changegroup versions that can be created from the repo def supportedoutgoingversions(repo): versions = allsupportedversions(repo) - if requirements.TREEMANIFEST_REQUIREMENT in repo.requirements: + if scmutil.istreemanifest(repo): # Versions 01 and 02 support only flat manifests and it's just too # expensive to convert between the flat manifest and tree manifest on # the fly. Since tree manifests are hashed differently, all of history diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py --- a/mercurial/cmdutil.py +++ b/mercurial/cmdutil.py @@ -46,7 +46,6 @@ from . import ( phases, pycompat, repair, - requirements, revlog, rewriteutil, scmutil, @@ -1359,7 +1358,7 @@ def openstorage(repo, cmd, file_, opts, if cl: r = repo.unfiltered().changelog elif dir: - if requirements.TREEMANIFEST_REQUIREMENT not in repo.requirements: + if not scmutil.istreemanifest(repo): raise error.Abort( _( b"--dir can only be used on repos with " diff --git a/mercurial/exchange.py b/mercurial/exchange.py --- a/mercurial/exchange.py +++ b/mercurial/exchange.py @@ -1068,7 +1068,7 @@ def _pushb2ctx(pushop, bundler): cgpart = bundler.newpart(b'changegroup', data=cgstream) if cgversions: cgpart.addparam(b'version', version) - if requirements.TREEMANIFEST_REQUIREMENT in pushop.repo.requirements: + if scmutil.istreemanifest(pushop.repo): cgpart.addparam(b'treemanifest', b'1') if b'exp-sidedata-flag' in pushop.repo.requirements: cgpart.addparam(b'exp-sidedata', b'1') @@ -2557,7 +2557,7 @@ def _getbundlechangegrouppart( part.addparam(b'nbchanges', b'%d' % len(outgoing.missing), mandatory=False) - if requirements.TREEMANIFEST_REQUIREMENT in repo.requirements: + if scmutil.istreemanifest(repo): part.addparam(b'treemanifest', b'1') if b'exp-sidedata-flag' in repo.requirements: diff --git a/mercurial/repair.py b/mercurial/repair.py --- a/mercurial/repair.py +++ b/mercurial/repair.py @@ -27,6 +27,7 @@ from . import ( phases, pycompat, requirements, + scmutil, util, ) from .utils import ( @@ -419,7 +420,7 @@ def stripmanifest(repo, striprev, tr, fi def manifestrevlogs(repo): yield repo.manifestlog.getstorage(b'') - if requirements.TREEMANIFEST_REQUIREMENT in repo.requirements: + if scmutil.istreemanifest(repo): # This logic is safe if treemanifest isn't enabled, but also # pointless, so we skip it if treemanifest isn't enabled. for unencoded, encoded, size in repo.store.datafiles(): diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py --- a/mercurial/scmutil.py +++ b/mercurial/scmutil.py @@ -1492,6 +1492,11 @@ def filterrequirements(requirements): return requirements, None +def istreemanifest(repo): + """ returns whether the repository is using treemanifest or not """ + return requirementsmod.TREEMANIFEST_REQUIREMENT in repo.requirements + + def writereporequirements(repo, requirements=None): """ writes requirements for the repo to .hg/requires """ if requirements: