narrow: move requirement constant from changegroup to repository
authorMartin von Zweigbergk <martinvonz@google.com>
Fri, 03 Aug 2018 11:02:34 -0700
changeset 38874 a232e6744ba3
parent 38873 c83ad57627ae
child 38875 fed6fe856333
narrow: move requirement constant from changegroup to repository As suggested by Gregory Szorc. Differential Revision: https://phab.mercurial-scm.org/D4094
hgext/narrow/__init__.py
hgext/narrow/narrowbundle2.py
hgext/narrow/narrowcommands.py
hgext/narrow/narrowrepo.py
mercurial/changegroup.py
mercurial/exchange.py
mercurial/localrepo.py
mercurial/repository.py
--- a/hgext/narrow/__init__.py	Fri Aug 03 12:35:23 2018 -0700
+++ b/hgext/narrow/__init__.py	Fri Aug 03 11:02:34 2018 -0700
@@ -15,11 +15,11 @@
 testedwith = 'ships-with-hg-core'
 
 from mercurial import (
-    changegroup,
     extensions,
     hg,
     localrepo,
     registrar,
+    repository,
     verify as verifymod,
 )
 
@@ -55,7 +55,7 @@
 cmdtable = narrowcommands.table
 
 def featuresetup(ui, features):
-    features.add(changegroup.NARROW_REQUIREMENT)
+    features.add(repository.NARROW_REQUIREMENT)
 
 def uisetup(ui):
     """Wraps user-facing mercurial commands with narrow-aware versions."""
@@ -71,7 +71,7 @@
     if not repo.local():
         return
 
-    if changegroup.NARROW_REQUIREMENT in repo.requirements:
+    if repository.NARROW_REQUIREMENT in repo.requirements:
         narrowrepo.wraprepo(repo)
         narrowcopies.setup(repo)
         narrowpatch.setup(repo)
--- a/hgext/narrow/narrowbundle2.py	Fri Aug 03 12:35:23 2018 -0700
+++ b/hgext/narrow/narrowbundle2.py	Fri Aug 03 11:02:34 2018 -0700
@@ -23,6 +23,7 @@
     extensions,
     narrowspec,
     repair,
+    repository,
     util,
     wireprototypes,
 )
@@ -174,8 +175,8 @@
 def _handlechangespec_2(op, inpart):
     includepats = set(inpart.params.get(_SPECPART_INCLUDE, '').splitlines())
     excludepats = set(inpart.params.get(_SPECPART_EXCLUDE, '').splitlines())
-    if not changegroup.NARROW_REQUIREMENT in op.repo.requirements:
-        op.repo.requirements.add(changegroup.NARROW_REQUIREMENT)
+    if not repository.NARROW_REQUIREMENT in op.repo.requirements:
+        op.repo.requirements.add(repository.NARROW_REQUIREMENT)
         op.repo._writerequirements()
     op.repo.setnarrowpats(includepats, excludepats)
 
--- a/hgext/narrow/narrowcommands.py	Fri Aug 03 12:35:23 2018 -0700
+++ b/hgext/narrow/narrowcommands.py	Fri Aug 03 11:02:34 2018 -0700
@@ -10,7 +10,6 @@
 
 from mercurial.i18n import _
 from mercurial import (
-    changegroup,
     cmdutil,
     commands,
     discovery,
@@ -24,6 +23,7 @@
     pycompat,
     registrar,
     repair,
+    repository,
     repoview,
     util,
 )
@@ -101,7 +101,7 @@
 
     def pullnarrow(orig, repo, *args, **kwargs):
         if opts_narrow:
-            repo.requirements.add(changegroup.NARROW_REQUIREMENT)
+            repo.requirements.add(repository.NARROW_REQUIREMENT)
             repo._writerequirements()
 
         return orig(repo, *args, **kwargs)
@@ -114,7 +114,7 @@
 def pullnarrowcmd(orig, ui, repo, *args, **opts):
     """Wraps pull command to allow modifying narrow spec."""
     wrappedextraprepare = util.nullcontextmanager()
-    if changegroup.NARROW_REQUIREMENT in repo.requirements:
+    if repository.NARROW_REQUIREMENT in repo.requirements:
 
         def pullbundle2extraprepare_widen(orig, pullop, kwargs):
             orig(pullop, kwargs)
@@ -128,7 +128,7 @@
 
 def archivenarrowcmd(orig, ui, repo, *args, **opts):
     """Wraps archive command to narrow the default includes."""
-    if changegroup.NARROW_REQUIREMENT in repo.requirements:
+    if repository.NARROW_REQUIREMENT in repo.requirements:
         repo_includes, repo_excludes = repo.narrowpats
         includes = set(opts.get(r'include', []))
         excludes = set(opts.get(r'exclude', []))
@@ -142,7 +142,7 @@
 
 def pullbundle2extraprepare(orig, pullop, kwargs):
     repo = pullop.repo
-    if changegroup.NARROW_REQUIREMENT not in repo.requirements:
+    if repository.NARROW_REQUIREMENT not in repo.requirements:
         return orig(pullop, kwargs)
 
     if narrowbundle2.NARROWCAP not in pullop.remotebundle2caps:
@@ -331,7 +331,7 @@
     empty and will not match any files.
     """
     opts = pycompat.byteskwargs(opts)
-    if changegroup.NARROW_REQUIREMENT not in repo.requirements:
+    if repository.NARROW_REQUIREMENT not in repo.requirements:
         ui.warn(_('The narrow command is only supported on respositories cloned'
                   ' with --narrow.\n'))
         return 1
--- a/hgext/narrow/narrowrepo.py	Fri Aug 03 12:35:23 2018 -0700
+++ b/hgext/narrow/narrowrepo.py	Fri Aug 03 11:02:34 2018 -0700
@@ -8,9 +8,9 @@
 from __future__ import absolute_import
 
 from mercurial import (
-    changegroup,
     hg,
     narrowspec,
+    repository,
 )
 
 from . import (
@@ -20,13 +20,13 @@
 
 def wrappostshare(orig, sourcerepo, destrepo, **kwargs):
     orig(sourcerepo, destrepo, **kwargs)
-    if changegroup.NARROW_REQUIREMENT in sourcerepo.requirements:
+    if repository.NARROW_REQUIREMENT in sourcerepo.requirements:
         with destrepo.wlock():
             with destrepo.vfs('shared', 'a') as fp:
                 fp.write(narrowspec.FILENAME + '\n')
 
 def unsharenarrowspec(orig, ui, repo, repopath):
-    if (changegroup.NARROW_REQUIREMENT in repo.requirements
+    if (repository.NARROW_REQUIREMENT in repo.requirements
         and repo.path == repopath and repo.shared()):
         srcrepo = hg.sharedreposource(repo)
         with srcrepo.vfs(narrowspec.FILENAME) as f:
--- a/mercurial/changegroup.py	Fri Aug 03 12:35:23 2018 -0700
+++ b/mercurial/changegroup.py	Fri Aug 03 11:02:34 2018 -0700
@@ -26,6 +26,7 @@
     mdiff,
     phases,
     pycompat,
+    repository,
     util,
 )
 
@@ -39,10 +40,6 @@
 
 LFS_REQUIREMENT = 'lfs'
 
-# When narrowing is finalized and no longer subject to format changes,
-# we should move this to just "narrow" or similar.
-NARROW_REQUIREMENT = 'narrowhg-experimental'
-
 readexactly = util.readexactly
 
 def getchunk(stream):
@@ -914,7 +911,7 @@
         # support versions 01 and 02.
         versions.discard('01')
         versions.discard('02')
-    if NARROW_REQUIREMENT in repo.requirements:
+    if repository.NARROW_REQUIREMENT in repo.requirements:
         # Versions 01 and 02 don't support revlog flags, and we need to
         # support that for stripping and unbundling to work.
         versions.discard('01')
--- a/mercurial/exchange.py	Fri Aug 03 12:35:23 2018 -0700
+++ b/mercurial/exchange.py	Fri Aug 03 11:02:34 2018 -0700
@@ -34,6 +34,7 @@
     phases,
     pushkey,
     pycompat,
+    repository,
     scmutil,
     sslutil,
     streamclone,
@@ -1432,7 +1433,7 @@
         old_heads = unficl.heads()
         clstart = len(unficl)
         _pullbundle2(pullop)
-        if changegroup.NARROW_REQUIREMENT in repo.requirements:
+        if repository.NARROW_REQUIREMENT in repo.requirements:
             # XXX narrow clones filter the heads on the server side during
             # XXX getbundle and result in partial replies as well.
             # XXX Disable pull bundles in this case as band aid to avoid
--- a/mercurial/localrepo.py	Fri Aug 03 12:35:23 2018 -0700
+++ b/mercurial/localrepo.py	Fri Aug 03 11:02:34 2018 -0700
@@ -825,7 +825,7 @@
 
     @repofilecache(narrowspec.FILENAME)
     def _narrowmatch(self):
-        if changegroup.NARROW_REQUIREMENT not in self.requirements:
+        if repository.NARROW_REQUIREMENT not in self.requirements:
             return matchmod.always(self.root, '')
         include, exclude = self.narrowpats
         return narrowspec.match(self.root, include=include, exclude=exclude)
--- a/mercurial/repository.py	Fri Aug 03 12:35:23 2018 -0700
+++ b/mercurial/repository.py	Fri Aug 03 11:02:34 2018 -0700
@@ -15,6 +15,10 @@
     interfaceutil,
 )
 
+# When narrowing is finalized and no longer subject to format changes,
+# we should move this to just "narrow" or similar.
+NARROW_REQUIREMENT = 'narrowhg-experimental'
+
 class ipeerconnection(interfaceutil.Interface):
     """Represents a "connection" to a repository.