changeset 45558:10284ce3d5ed

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
author Pulkit Goyal <7895pulkit@gmail.com>
date Tue, 01 Sep 2020 18:08:24 +0530
parents 4c8d9b53b1c7
children 952f9d37002c
files hgext/narrow/narrowbundle2.py hgext/remotefilelog/remotefilelogserver.py mercurial/bundle2.py mercurial/changegroup.py mercurial/cmdutil.py mercurial/exchange.py mercurial/repair.py mercurial/scmutil.py
diffstat 8 files changed, 20 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/narrow/narrowbundle2.py	Thu Sep 03 11:07:47 2020 -0400
+++ b/hgext/narrow/narrowbundle2.py	Tue Sep 01 18:08:24 2020 +0530
@@ -108,7 +108,7 @@
 
         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 @@
 
         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')
 
 
--- a/hgext/remotefilelog/remotefilelogserver.py	Thu Sep 03 11:07:47 2020 -0400
+++ b/hgext/remotefilelog/remotefilelogserver.py	Tue Sep 01 18:08:24 2020 +0530
@@ -23,7 +23,7 @@
     extensions,
     match,
     pycompat,
-    requirements,
+    scmutil,
     store,
     streamclone,
     util,
@@ -170,7 +170,7 @@
                         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')
--- a/mercurial/bundle2.py	Thu Sep 03 11:07:47 2020 -0400
+++ b/mercurial/bundle2.py	Tue Sep 01 18:08:24 2020 +0530
@@ -1964,10 +1964,7 @@
     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 @@
 
         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')
--- a/mercurial/changegroup.py	Thu Sep 03 11:07:47 2020 -0400
+++ b/mercurial/changegroup.py	Tue Sep 01 18:08:24 2020 +0530
@@ -27,6 +27,7 @@
     phases,
     pycompat,
     requirements,
+    scmutil,
     util,
 )
 
@@ -949,9 +950,7 @@
         # 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 @@
     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 @@
 # 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
--- a/mercurial/cmdutil.py	Thu Sep 03 11:07:47 2020 -0400
+++ b/mercurial/cmdutil.py	Tue Sep 01 18:08:24 2020 +0530
@@ -46,7 +46,6 @@
     phases,
     pycompat,
     repair,
-    requirements,
     revlog,
     rewriteutil,
     scmutil,
@@ -1359,7 +1358,7 @@
         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 "
--- a/mercurial/exchange.py	Thu Sep 03 11:07:47 2020 -0400
+++ b/mercurial/exchange.py	Tue Sep 01 18:08:24 2020 +0530
@@ -1068,7 +1068,7 @@
     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 @@
 
     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:
--- a/mercurial/repair.py	Thu Sep 03 11:07:47 2020 -0400
+++ b/mercurial/repair.py	Tue Sep 01 18:08:24 2020 +0530
@@ -27,6 +27,7 @@
     phases,
     pycompat,
     requirements,
+    scmutil,
     util,
 )
 from .utils import (
@@ -419,7 +420,7 @@
 
 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():
--- a/mercurial/scmutil.py	Thu Sep 03 11:07:47 2020 -0400
+++ b/mercurial/scmutil.py	Tue Sep 01 18:08:24 2020 +0530
@@ -1492,6 +1492,11 @@
     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: