changeset 40510:fc2766860796

remotefilelog: consolidate and rename on-disk store requirement The value of this constant appeared in too many places. While we're here, rename it to be more consistent with our naming conventions for experimental functionality. Differential Revision: https://phab.mercurial-scm.org/D5128
author Augie Fackler <augie@google.com>
date Tue, 16 Oct 2018 17:02:48 -0400
parents ed19958dbf5d
children 466dd4d70bff
files hgext/remotefilelog/__init__.py hgext/remotefilelog/constants.py hgext/remotefilelog/debugcommands.py hgext/remotefilelog/fileserverclient.py hgext/remotefilelog/remotefilelogserver.py hgext/remotefilelog/shallowbundle.py hgext/remotefilelog/shallowrepo.py tests/test-remotefilelog-clone-tree.t tests/test-remotefilelog-clone.t tests/test-remotefilelog-log.t
diffstat 10 files changed, 51 insertions(+), 54 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/remotefilelog/__init__.py	Tue Oct 16 17:30:47 2018 -0400
+++ b/hgext/remotefilelog/__init__.py	Tue Oct 16 17:02:48 2018 -0400
@@ -209,7 +209,7 @@
 testedwith = 'ships-with-hg-core'
 
 repoclass = localrepo.localrepository
-repoclass._basesupported.add(shallowrepo.requirement)
+repoclass._basesupported.add(constants.SHALLOWREPO_REQUIREMENT)
 
 def uisetup(ui):
     """Wraps user facing Mercurial commands to swap them out with shallow
@@ -231,7 +231,8 @@
 
     # Prevent 'hg manifest --all'
     def _manifest(orig, ui, repo, *args, **opts):
-        if shallowrepo.requirement in repo.requirements and opts.get('all'):
+        if (constants.SHALLOWREPO_REQUIREMENT in repo.requirements
+            and opts.get('all')):
             raise error.Abort(_("--all is not supported in a shallow repo"))
 
         return orig(ui, repo, *args, **opts)
@@ -256,7 +257,7 @@
     if opts.get('shallow'):
         repos = []
         def pull_shallow(orig, self, *args, **kwargs):
-            if shallowrepo.requirement not in self.requirements:
+            if constants.SHALLOWREPO_REQUIREMENT not in self.requirements:
                 repos.append(self.unfiltered())
                 # set up the client hooks so the post-clone update works
                 setupclient(self.ui, self.unfiltered())
@@ -266,7 +267,7 @@
                 if isinstance(self, repoview.repoview):
                     self.__class__.__bases__ = (self.__class__.__bases__[0],
                                                 self.unfiltered().__class__)
-                self.requirements.add(shallowrepo.requirement)
+                self.requirements.add(constants.SHALLOWREPO_REQUIREMENT)
                 self._writerequirements()
 
                 # Since setupclient hadn't been called, exchange.pull was not
@@ -312,14 +313,14 @@
                     return False, None
                 supported, requirements = orig(pullop, bundle2=bundle2)
                 if requirements is not None:
-                    requirements.add(shallowrepo.requirement)
+                    requirements.add(constants.SHALLOWREPO_REQUIREMENT)
                 return supported, requirements
             extensions.wrapfunction(
                 streamclone, 'canperformstreamclone', canperformstreamclone)
         else:
             def stream_in_shallow(orig, repo, remote, requirements):
                 setup_streamout(repo, remote)
-                requirements.add(shallowrepo.requirement)
+                requirements.add(constants.SHALLOWREPO_REQUIREMENT)
                 return orig(repo, remote, requirements)
             extensions.wrapfunction(
                 localrepo.localrepository, 'stream_in', stream_in_shallow)
@@ -349,7 +350,7 @@
     ui.setconfig('hooks', 'commit.prefetch', wcpprefetch)
 
     isserverenabled = ui.configbool('remotefilelog', 'server')
-    isshallowclient = shallowrepo.requirement in repo.requirements
+    isshallowclient = constants.SHALLOWREPO_REQUIREMENT in repo.requirements
 
     if isserverenabled and isshallowclient:
         raise RuntimeError("Cannot be both a server and shallow client.")
@@ -388,7 +389,7 @@
 
     def storewrapper(orig, requirements, path, vfstype):
         s = orig(requirements, path, vfstype)
-        if shallowrepo.requirement in requirements:
+        if constants.SHALLOWREPO_REQUIREMENT in requirements:
             s = shallowstore.wrapstore(s)
 
         return s
@@ -398,7 +399,7 @@
 
     # prefetch files before update
     def applyupdates(orig, repo, actions, wctx, mctx, overwrite, labels=None):
-        if shallowrepo.requirement in repo.requirements:
+        if constants.SHALLOWREPO_REQUIREMENT in repo.requirements:
             manifest = mctx.manifest()
             files = []
             for f, args, msg in actions['g']:
@@ -411,7 +412,7 @@
     # Prefetch merge checkunknownfiles
     def checkunknownfiles(orig, repo, wctx, mctx, force, actions,
                           *args, **kwargs):
-        if shallowrepo.requirement in repo.requirements:
+        if constants.SHALLOWREPO_REQUIREMENT in repo.requirements:
             files = []
             sparsematch = repo.maybesparsematch(mctx.rev())
             for f, (m, actionargs, msg) in actions.iteritems():
@@ -430,7 +431,7 @@
     # Prefetch files before status attempts to look at their size and contents
     def checklookup(orig, self, files):
         repo = self._repo
-        if shallowrepo.requirement in repo.requirements:
+        if constants.SHALLOWREPO_REQUIREMENT in repo.requirements:
             prefetchfiles = []
             for parent in self._parents:
                 for f in files:
@@ -443,7 +444,7 @@
 
     # Prefetch the logic that compares added and removed files for renames
     def findrenames(orig, repo, matcher, added, removed, *args, **kwargs):
-        if shallowrepo.requirement in repo.requirements:
+        if constants.SHALLOWREPO_REQUIREMENT in repo.requirements:
             files = []
             parentctx = repo['.']
             for f in removed:
@@ -456,7 +457,7 @@
     # prefetch files before mergecopies check
     def computenonoverlap(orig, repo, c1, c2, *args, **kwargs):
         u1, u2 = orig(repo, c1, c2, *args, **kwargs)
-        if shallowrepo.requirement in repo.requirements:
+        if constants.SHALLOWREPO_REQUIREMENT in repo.requirements:
             m1 = c1.manifest()
             m2 = c2.manifest()
             files = []
@@ -488,7 +489,7 @@
     def computeforwardmissing(orig, a, b, match=None):
         missing = list(orig(a, b, match=match))
         repo = a._repo
-        if shallowrepo.requirement in repo.requirements:
+        if constants.SHALLOWREPO_REQUIREMENT in repo.requirements:
             mb = b.manifest()
 
             files = []
@@ -515,7 +516,7 @@
             # repo can be None when running in chg:
             # - at startup, reposetup was called because serve is not norepo
             # - a norepo command like "help" is called
-            if repo and shallowrepo.requirement in repo.requirements:
+            if repo and constants.SHALLOWREPO_REQUIREMENT in repo.requirements:
                 repo.fileservice.close()
     extensions.wrapfunction(dispatch, 'runcommand', runcommand)
 
@@ -527,7 +528,7 @@
 
     # prevent strip from stripping remotefilelogs
     def _collectbrokencsets(orig, repo, files, striprev):
-        if shallowrepo.requirement in repo.requirements:
+        if constants.SHALLOWREPO_REQUIREMENT in repo.requirements:
             files = list([f for f in files if not repo.shallowmatch(f)])
         return orig(repo, files, striprev)
     extensions.wrapfunction(repair, '_collectbrokencsets', _collectbrokencsets)
@@ -578,7 +579,7 @@
     def filectx(orig, self, path, fileid=None, filelog=None):
         if fileid is None:
             fileid = self.filenode(path)
-        if (shallowrepo.requirement in self._repo.requirements and
+        if (constants.SHALLOWREPO_REQUIREMENT in self._repo.requirements and
             self._repo.shallowmatch(path)):
             return remotefilectx.remotefilectx(self._repo, path,
                 fileid=fileid, changectx=self, filelog=filelog)
@@ -586,7 +587,7 @@
     extensions.wrapfunction(context.changectx, 'filectx', filectx)
 
     def workingfilectx(orig, self, path, filelog=None):
-        if (shallowrepo.requirement in self._repo.requirements and
+        if (constants.SHALLOWREPO_REQUIREMENT in self._repo.requirements and
             self._repo.shallowmatch(path)):
             return remotefilectx.remoteworkingfilectx(self._repo,
                 path, workingctx=self, filelog=filelog)
@@ -596,7 +597,7 @@
     # prefetch required revisions before a diff
     def trydiff(orig, repo, revs, ctx1, ctx2, modified, added, removed,
                 copy, getfilectx, *args, **kwargs):
-        if shallowrepo.requirement in repo.requirements:
+        if constants.SHALLOWREPO_REQUIREMENT in repo.requirements:
             prefetch = []
             mf1 = ctx1.manifest()
             for fname in modified + added + removed:
@@ -654,7 +655,7 @@
     return getrenamed
 
 def walkfilerevs(orig, repo, match, follow, revs, fncache):
-    if not shallowrepo.requirement in repo.requirements:
+    if not constants.SHALLOWREPO_REQUIREMENT in repo.requirements:
         return orig(repo, match, follow, revs, fncache)
 
     # remotefilelog's can't be walked in rev order, so throw.
@@ -694,7 +695,7 @@
     a slower, more accurate result, use ``file()``.
     """
 
-    if not shallowrepo.requirement in repo.requirements:
+    if not constants.SHALLOWREPO_REQUIREMENT in repo.requirements:
         return orig(repo, subset, x)
 
     # i18n: "filelog" is a keyword
@@ -802,7 +803,7 @@
         # Protect against any repo or config changes that have happened since
         # this repo was added to the repos file. We'd rather this loop succeed
         # and too much be deleted, than the loop fail and nothing gets deleted.
-        if shallowrepo.requirement not in repo.requirements:
+        if constants.SHALLOWREPO_REQUIREMENT not in repo.requirements:
             continue
 
         if not util.safehasattr(repo, 'name'):
@@ -851,7 +852,7 @@
         ui.warn(_("warning: no valid repos in repofile\n"))
 
 def log(orig, ui, repo, *pats, **opts):
-    if shallowrepo.requirement not in repo.requirements:
+    if constants.SHALLOWREPO_REQUIREMENT not in repo.requirements:
         return orig(ui, repo, *pats, **opts)
 
     follow = opts.get('follow')
@@ -912,7 +913,7 @@
     """Prefetches in background revisions specified by bgprefetchrevs revset.
     Does background repack if backgroundrepack flag is set in config.
     """
-    shallow = shallowrepo.requirement in repo.requirements
+    shallow = constants.SHALLOWREPO_REQUIREMENT in repo.requirements
     bgprefetchrevs = ui.config('remotefilelog', 'bgprefetchrevs')
     isready = readytofetch(repo)
 
@@ -934,7 +935,7 @@
 def pull(orig, ui, repo, *pats, **opts):
     result = orig(ui, repo, *pats, **opts)
 
-    if shallowrepo.requirement in repo.requirements:
+    if constants.SHALLOWREPO_REQUIREMENT in repo.requirements:
         # prefetch if it's configured
         prefetchrevset = ui.config('remotefilelog', 'pullprefetch')
         bgrepack = repo.ui.configbool('remotefilelog', 'backgroundrepack')
@@ -974,7 +975,7 @@
     return orig(repo, remote, *args, **kwargs)
 
 def _fileprefetchhook(repo, revs, match):
-    if shallowrepo.requirement in repo.requirements:
+    if constants.SHALLOWREPO_REQUIREMENT in repo.requirements:
         allfiles = []
         for rev in revs:
             if rev == nodemod.wdirrev or rev is None:
@@ -1070,7 +1071,7 @@
 
     Return 0 on success.
     """
-    if not shallowrepo.requirement in repo.requirements:
+    if not constants.SHALLOWREPO_REQUIREMENT in repo.requirements:
         raise error.Abort(_("repo is not shallow"))
 
     opts = resolveprefetchopts(ui, opts)
--- a/hgext/remotefilelog/constants.py	Tue Oct 16 17:30:47 2018 -0400
+++ b/hgext/remotefilelog/constants.py	Tue Oct 16 17:02:48 2018 -0400
@@ -4,9 +4,9 @@
 
 from mercurial.i18n import _
 
-REQUIREMENT = "remotefilelog"
+NETWORK_CAP_LEGACY_SSH_GETFILES = 'exp-remotefilelog-ssh-getfiles-1'
 
-NETWORK_CAP_LEGACY_SSH_GETFILES = 'exp-remotefilelog-ssh-getfiles-1'
+SHALLOWREPO_REQUIREMENT = "exp-remotefilelog-repo-req-1"
 
 BUNDLE2_CAPABLITY = "exp-remotefilelog-b2cap-1"
 
--- a/hgext/remotefilelog/debugcommands.py	Tue Oct 16 17:30:47 2018 -0400
+++ b/hgext/remotefilelog/debugcommands.py	Tue Oct 16 17:02:48 2018 -0400
@@ -24,7 +24,6 @@
     fileserverclient,
     historypack,
     repack,
-    shallowrepo,
     shallowutil,
 )
 
@@ -93,7 +92,7 @@
     if (opts.get('changelog') or
         opts.get('manifest') or
         opts.get('dir') or
-        not shallowrepo.requirement in repo.requirements or
+        not constants.SHALLOWREPO_REQUIREMENT in repo.requirements or
         not repo.shallowmatch(file_)):
         return orig(ui, repo, file_, **opts)
 
@@ -140,7 +139,7 @@
 
 def debugindexdot(orig, ui, repo, file_):
     """dump an index DAG as a graphviz dot file"""
-    if not shallowrepo.requirement in repo.requirements:
+    if not constants.SHALLOWREPO_REQUIREMENT in repo.requirements:
         return orig(ui, repo, file_)
 
     r = buildtemprevlog(repo, os.path.basename(file_)[:-2])
--- a/hgext/remotefilelog/fileserverclient.py	Tue Oct 16 17:30:47 2018 -0400
+++ b/hgext/remotefilelog/fileserverclient.py	Tue Oct 16 17:02:48 2018 -0400
@@ -83,7 +83,8 @@
                 return
             if not util.safehasattr(self, '_localrepo'):
                 return
-            if constants.REQUIREMENT not in self._localrepo.requirements:
+            if (constants.SHALLOWREPO_REQUIREMENT
+                not in self._localrepo.requirements):
                 return
 
             bundlecaps = opts.get('bundlecaps')
--- a/hgext/remotefilelog/remotefilelogserver.py	Tue Oct 16 17:30:47 2018 -0400
+++ b/hgext/remotefilelog/remotefilelogserver.py	Tue Oct 16 17:02:48 2018 -0400
@@ -30,7 +30,6 @@
 )
 from .  import (
     constants,
-    shallowrepo,
     shallowutil,
 )
 
@@ -133,7 +132,7 @@
     def _walkstreamfiles(orig, repo):
         if state.shallowremote:
             # if we are shallow ourselves, stream our local commits
-            if shallowrepo.requirement in repo.requirements:
+            if constants.SHALLOWREPO_REQUIREMENT in repo.requirements:
                 striplen = len(repo.store.path) + 1
                 readdir = repo.store.rawvfs.readdir
                 visit = [os.path.join(repo.store.path, 'data')]
@@ -167,7 +166,7 @@
                     continue
                 yield x
 
-        elif shallowrepo.requirement in repo.requirements:
+        elif constants.SHALLOWREPO_REQUIREMENT in repo.requirements:
             # don't allow cloning from a shallow repo to a full repo
             # since it would require fetching every version of every
             # file in order to create the revlogs.
@@ -194,7 +193,7 @@
     # expose remotefilelog capabilities
     def _capabilities(orig, repo, proto):
         caps = orig(repo, proto)
-        if ((shallowrepo.requirement in repo.requirements or
+        if ((constants.SHALLOWREPO_REQUIREMENT in repo.requirements or
             ui.configbool('remotefilelog', 'server'))):
             if isinstance(proto, _sshv1server):
                 # legacy getfiles method which only works over ssh
@@ -279,7 +278,7 @@
     data is a compressed blob with revlog flag and ancestors information. See
     createfileblob for its content.
     """
-    if shallowrepo.requirement in repo.requirements:
+    if constants.SHALLOWREPO_REQUIREMENT in repo.requirements:
         return '1\0' + _('cannot fetch remote files from shallow repo')
     cachepath = repo.ui.config("remotefilelog", "servercachepath")
     if not cachepath:
@@ -292,7 +291,7 @@
 def getfiles(repo, proto):
     """A server api for requesting particular versions of particular files.
     """
-    if shallowrepo.requirement in repo.requirements:
+    if constants.SHALLOWREPO_REQUIREMENT in repo.requirements:
         raise error.Abort(_('cannot fetch remote files from shallow repo'))
     if not isinstance(proto, _sshv1server):
         raise error.Abort(_('cannot fetch remote files over non-ssh protocol'))
--- a/hgext/remotefilelog/shallowbundle.py	Tue Oct 16 17:30:47 2018 -0400
+++ b/hgext/remotefilelog/shallowbundle.py	Tue Oct 16 17:02:48 2018 -0400
@@ -26,8 +26,6 @@
 LocalFiles = 1
 AllFiles = 2
 
-requirement = "remotefilelog"
-
 def shallowgroup(cls, self, nodelist, rlog, lookup, units=None, reorder=None):
     if not isinstance(rlog, remotefilelog.remotefilelog):
         for c in super(cls, self).group(nodelist, rlog, lookup,
@@ -56,7 +54,7 @@
 
 class shallowcg1packer(changegroup.cgpacker):
     def generate(self, commonrevs, clnodes, fastpathlinkrev, source):
-        if "remotefilelog" in self._repo.requirements:
+        if constants.SHALLOWREPO_REQUIREMENT in self._repo.requirements:
             fastpathlinkrev = False
 
         return super(shallowcg1packer, self).generate(commonrevs, clnodes,
@@ -71,7 +69,7 @@
             linknodes, commonrevs, source = args
         except ValueError:
             commonrevs, source, mfdicts, fastpathlinkrev, fnodes, clrevs = args
-        if requirement in self._repo.requirements:
+        if constants.SHALLOWREPO_REQUIREMENT in self._repo.requirements:
             repo = self._repo
             if isinstance(repo, bundlerepo.bundlerepository):
                 # If the bundle contains filelogs, we can't pull from it, since
@@ -93,7 +91,7 @@
 
     def shouldaddfilegroups(self, source):
         repo = self._repo
-        if not requirement in repo.requirements:
+        if not constants.SHALLOWREPO_REQUIREMENT in repo.requirements:
             return AllFiles
 
         if source == "push" or source == "bundle":
@@ -141,7 +139,7 @@
         yield delta
 
 def makechangegroup(orig, repo, outgoing, version, source, *args, **kwargs):
-    if not requirement in repo.requirements:
+    if not constants.SHALLOWREPO_REQUIREMENT in repo.requirements:
         return orig(repo, outgoing, version, source, *args, **kwargs)
 
     original = repo.shallowmatch
@@ -170,7 +168,7 @@
         repo.shallowmatch = original
 
 def addchangegroupfiles(orig, repo, source, revmap, trp, expectedfiles, *args):
-    if not requirement in repo.requirements:
+    if not constants.SHALLOWREPO_REQUIREMENT in repo.requirements:
         return orig(repo, source, revmap, trp, expectedfiles, *args)
 
     files = 0
--- a/hgext/remotefilelog/shallowrepo.py	Tue Oct 16 17:30:47 2018 -0400
+++ b/hgext/remotefilelog/shallowrepo.py	Tue Oct 16 17:02:48 2018 -0400
@@ -40,7 +40,6 @@
     from mercurial.utils import procutil
     _hgexecutable = procutil.hgexecutable
 
-requirement = "remotefilelog"
 _prefetching = _('prefetching')
 
 # These make*stores functions are global so that other extensions can replace
--- a/tests/test-remotefilelog-clone-tree.t	Tue Oct 16 17:30:47 2018 -0400
+++ b/tests/test-remotefilelog-clone-tree.t	Tue Oct 16 17:02:48 2018 -0400
@@ -28,9 +28,9 @@
   $ cd shallow
   $ cat .hg/requires
   dotencode
+  exp-remotefilelog-repo-req-1
   fncache
   generaldelta
-  remotefilelog
   revlogv1
   store
   treemanifest
@@ -68,9 +68,9 @@
   $ cd shallow2
   $ cat .hg/requires
   dotencode
+  exp-remotefilelog-repo-req-1
   fncache
   generaldelta
-  remotefilelog
   revlogv1
   store
   treemanifest
@@ -109,9 +109,9 @@
   $ ls shallow3/.hg/store/data
   $ cat shallow3/.hg/requires
   dotencode
+  exp-remotefilelog-repo-req-1
   fncache
   generaldelta
-  remotefilelog
   revlogv1
   store
   treemanifest
--- a/tests/test-remotefilelog-clone.t	Tue Oct 16 17:30:47 2018 -0400
+++ b/tests/test-remotefilelog-clone.t	Tue Oct 16 17:02:48 2018 -0400
@@ -25,9 +25,9 @@
   $ cd shallow
   $ cat .hg/requires
   dotencode
+  exp-remotefilelog-repo-req-1
   fncache
   generaldelta
-  remotefilelog
   revlogv1
   store
 
@@ -58,9 +58,9 @@
   $ cd shallow2
   $ cat .hg/requires
   dotencode
+  exp-remotefilelog-repo-req-1
   fncache
   generaldelta
-  remotefilelog
   revlogv1
   store
   $ ls .hg/store/data
@@ -106,8 +106,8 @@
   $ ls shallow3/.hg/store/data
   $ cat shallow3/.hg/requires
   dotencode
+  exp-remotefilelog-repo-req-1
   fncache
   generaldelta
-  remotefilelog
   revlogv1
   store
--- a/tests/test-remotefilelog-log.t	Tue Oct 16 17:30:47 2018 -0400
+++ b/tests/test-remotefilelog-log.t	Tue Oct 16 17:02:48 2018 -0400
@@ -28,9 +28,9 @@
   $ cd shallow
   $ cat .hg/requires
   dotencode
+  exp-remotefilelog-repo-req-1
   fncache
   generaldelta
-  remotefilelog
   revlogv1
   store