hgext/remotefilelog/__init__.py
changeset 40514 6f0b6905ef6f
parent 40513 525dcf5c1d41
child 40548 040447dc3c62
--- a/hgext/remotefilelog/__init__.py	Wed Oct 24 16:59:05 2018 +0300
+++ b/hgext/remotefilelog/__init__.py	Mon Nov 05 11:52:10 2018 -0800
@@ -216,6 +216,8 @@
 repoclass = localrepo.localrepository
 repoclass._basesupported.add(constants.SHALLOWREPO_REQUIREMENT)
 
+isenabled = shallowutil.isenabled
+
 def uisetup(ui):
     """Wraps user facing Mercurial commands to swap them out with shallow
     versions.
@@ -236,8 +238,7 @@
 
     # Prevent 'hg manifest --all'
     def _manifest(orig, ui, repo, *args, **opts):
-        if (constants.SHALLOWREPO_REQUIREMENT in repo.requirements
-            and opts.get('all')):
+        if (isenabled(repo) and opts.get('all')):
             raise error.Abort(_("--all is not supported in a shallow repo"))
 
         return orig(ui, repo, *args, **opts)
@@ -262,7 +263,7 @@
     if opts.get('shallow'):
         repos = []
         def pull_shallow(orig, self, *args, **kwargs):
-            if constants.SHALLOWREPO_REQUIREMENT not in self.requirements:
+            if not isenabled(self):
                 repos.append(self.unfiltered())
                 # set up the client hooks so the post-clone update works
                 setupclient(self.ui, self.unfiltered())
@@ -347,7 +348,7 @@
     ui.setconfig('hooks', 'commit.prefetch', wcpprefetch)
 
     isserverenabled = ui.configbool('remotefilelog', 'server')
-    isshallowclient = constants.SHALLOWREPO_REQUIREMENT in repo.requirements
+    isshallowclient = isenabled(repo)
 
     if isserverenabled and isshallowclient:
         raise RuntimeError("Cannot be both a server and shallow client.")
@@ -396,7 +397,7 @@
 
     # prefetch files before update
     def applyupdates(orig, repo, actions, wctx, mctx, overwrite, labels=None):
-        if constants.SHALLOWREPO_REQUIREMENT in repo.requirements:
+        if isenabled(repo):
             manifest = mctx.manifest()
             files = []
             for f, args, msg in actions['g']:
@@ -409,7 +410,7 @@
     # Prefetch merge checkunknownfiles
     def checkunknownfiles(orig, repo, wctx, mctx, force, actions,
                           *args, **kwargs):
-        if constants.SHALLOWREPO_REQUIREMENT in repo.requirements:
+        if isenabled(repo):
             files = []
             sparsematch = repo.maybesparsematch(mctx.rev())
             for f, (m, actionargs, msg) in actions.iteritems():
@@ -428,7 +429,7 @@
     # Prefetch files before status attempts to look at their size and contents
     def checklookup(orig, self, files):
         repo = self._repo
-        if constants.SHALLOWREPO_REQUIREMENT in repo.requirements:
+        if isenabled(repo):
             prefetchfiles = []
             for parent in self._parents:
                 for f in files:
@@ -441,7 +442,7 @@
 
     # Prefetch the logic that compares added and removed files for renames
     def findrenames(orig, repo, matcher, added, removed, *args, **kwargs):
-        if constants.SHALLOWREPO_REQUIREMENT in repo.requirements:
+        if isenabled(repo):
             files = []
             parentctx = repo['.']
             for f in removed:
@@ -454,7 +455,7 @@
     # prefetch files before mergecopies check
     def computenonoverlap(orig, repo, c1, c2, *args, **kwargs):
         u1, u2 = orig(repo, c1, c2, *args, **kwargs)
-        if constants.SHALLOWREPO_REQUIREMENT in repo.requirements:
+        if isenabled(repo):
             m1 = c1.manifest()
             m2 = c2.manifest()
             files = []
@@ -486,7 +487,7 @@
     def computeforwardmissing(orig, a, b, match=None):
         missing = list(orig(a, b, match=match))
         repo = a._repo
-        if constants.SHALLOWREPO_REQUIREMENT in repo.requirements:
+        if isenabled(repo):
             mb = b.manifest()
 
             files = []
@@ -513,7 +514,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 constants.SHALLOWREPO_REQUIREMENT in repo.requirements:
+            if repo and isenabled(repo):
                 repo.fileservice.close()
     extensions.wrapfunction(dispatch, 'runcommand', runcommand)
 
@@ -525,7 +526,7 @@
 
     # prevent strip from stripping remotefilelogs
     def _collectbrokencsets(orig, repo, files, striprev):
-        if constants.SHALLOWREPO_REQUIREMENT in repo.requirements:
+        if isenabled(repo):
             files = list([f for f in files if not repo.shallowmatch(f)])
         return orig(repo, files, striprev)
     extensions.wrapfunction(repair, '_collectbrokencsets', _collectbrokencsets)
@@ -576,16 +577,14 @@
     def filectx(orig, self, path, fileid=None, filelog=None):
         if fileid is None:
             fileid = self.filenode(path)
-        if (constants.SHALLOWREPO_REQUIREMENT in self._repo.requirements and
-            self._repo.shallowmatch(path)):
+        if (isenabled(self._repo) and self._repo.shallowmatch(path)):
             return remotefilectx.remotefilectx(self._repo, path,
                 fileid=fileid, changectx=self, filelog=filelog)
         return orig(self, path, fileid=fileid, filelog=filelog)
     extensions.wrapfunction(context.changectx, 'filectx', filectx)
 
     def workingfilectx(orig, self, path, filelog=None):
-        if (constants.SHALLOWREPO_REQUIREMENT in self._repo.requirements and
-            self._repo.shallowmatch(path)):
+        if (isenabled(self._repo) and self._repo.shallowmatch(path)):
             return remotefilectx.remoteworkingfilectx(self._repo,
                 path, workingctx=self, filelog=filelog)
         return orig(self, path, filelog=filelog)
@@ -594,7 +593,7 @@
     # prefetch required revisions before a diff
     def trydiff(orig, repo, revs, ctx1, ctx2, modified, added, removed,
                 copy, getfilectx, *args, **kwargs):
-        if constants.SHALLOWREPO_REQUIREMENT in repo.requirements:
+        if isenabled(repo):
             prefetch = []
             mf1 = ctx1.manifest()
             for fname in modified + added + removed:
@@ -652,7 +651,7 @@
     return getrenamed
 
 def walkfilerevs(orig, repo, match, follow, revs, fncache):
-    if not constants.SHALLOWREPO_REQUIREMENT in repo.requirements:
+    if not isenabled(repo):
         return orig(repo, match, follow, revs, fncache)
 
     # remotefilelog's can't be walked in rev order, so throw.
@@ -692,7 +691,7 @@
     a slower, more accurate result, use ``file()``.
     """
 
-    if not constants.SHALLOWREPO_REQUIREMENT in repo.requirements:
+    if not isenabled(repo):
         return orig(repo, subset, x)
 
     # i18n: "filelog" is a keyword
@@ -800,7 +799,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 constants.SHALLOWREPO_REQUIREMENT not in repo.requirements:
+        if not isenabled(repo):
             continue
 
         if not util.safehasattr(repo, 'name'):
@@ -849,7 +848,7 @@
         ui.warn(_("warning: no valid repos in repofile\n"))
 
 def log(orig, ui, repo, *pats, **opts):
-    if constants.SHALLOWREPO_REQUIREMENT not in repo.requirements:
+    if not isenabled(repo):
         return orig(ui, repo, *pats, **opts)
 
     follow = opts.get('follow')
@@ -910,7 +909,7 @@
     """Prefetches in background revisions specified by bgprefetchrevs revset.
     Does background repack if backgroundrepack flag is set in config.
     """
-    shallow = constants.SHALLOWREPO_REQUIREMENT in repo.requirements
+    shallow = isenabled(repo)
     bgprefetchrevs = ui.config('remotefilelog', 'bgprefetchrevs')
     isready = readytofetch(repo)
 
@@ -932,7 +931,7 @@
 def pull(orig, ui, repo, *pats, **opts):
     result = orig(ui, repo, *pats, **opts)
 
-    if constants.SHALLOWREPO_REQUIREMENT in repo.requirements:
+    if isenabled(repo):
         # prefetch if it's configured
         prefetchrevset = ui.config('remotefilelog', 'pullprefetch')
         bgrepack = repo.ui.configbool('remotefilelog', 'backgroundrepack')
@@ -972,7 +971,7 @@
     return orig(repo, remote, *args, **kwargs)
 
 def _fileprefetchhook(repo, revs, match):
-    if constants.SHALLOWREPO_REQUIREMENT in repo.requirements:
+    if isenabled(repo):
         allfiles = []
         for rev in revs:
             if rev == nodemod.wdirrev or rev is None:
@@ -1068,7 +1067,7 @@
 
     Return 0 on success.
     """
-    if not constants.SHALLOWREPO_REQUIREMENT in repo.requirements:
+    if not isenabled(repo):
         raise error.Abort(_("repo is not shallow"))
 
     opts = resolveprefetchopts(ui, opts)