Patchwork D2493: narrow: remove dependency from narrowspec module to hg module

login
register
mail settings
Submitter phabricator
Date Feb. 28, 2018, 8:57 p.m.
Message ID <differential-rev-PHID-DREV-5qgvfvmreqkybzkw3tof-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/28490/
State Superseded
Headers show

Comments

phabricator - Feb. 28, 2018, 8:57 p.m.
martinvonz created this revision.
Herald added a reviewer: durin42.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D2493

AFFECTED FILES
  hgext/narrow/narrowrepo.py
  mercurial/narrowspec.py

CHANGE DETAILS




To: martinvonz, durin42, #hg-reviewers
Cc: mercurial-devel
phabricator - March 1, 2018, 2:09 a.m.
indygreg accepted this revision.
indygreg added inline comments.
This revision is now accepted and ready to land.

INLINE COMMENTS

> narrowrepo.py:76-78
> +            source = self
> +            if self.shared():
> +                source = hg.sharedreposource(self)

It feels like there could be a helper method that returns the repo object backing the store. But that's for another patch.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D2493

To: martinvonz, durin42, #hg-reviewers, indygreg
Cc: indygreg, mercurial-devel

Patch

diff --git a/mercurial/narrowspec.py b/mercurial/narrowspec.py
--- a/mercurial/narrowspec.py
+++ b/mercurial/narrowspec.py
@@ -12,7 +12,6 @@ 
 from .i18n import _
 from . import (
     error,
-    hg,
     match as matchmod,
     util,
 )
@@ -129,8 +128,6 @@ 
     return [i for i in includes if i.startswith('include:')]
 
 def load(repo):
-    if repo.shared():
-        repo = hg.sharedreposource(repo)
     try:
         spec = repo.vfs.read(FILENAME)
     except IOError as e:
@@ -146,8 +143,6 @@ 
 
 def save(repo, includepats, excludepats):
     spec = format(includepats, excludepats)
-    if repo.shared():
-        repo = hg.sharedreposource(repo)
     repo.vfs.write(FILENAME, spec)
 
 def restrictpatterns(req_includes, req_excludes, repo_includes, repo_excludes):
diff --git a/hgext/narrow/narrowrepo.py b/hgext/narrow/narrowrepo.py
--- a/hgext/narrow/narrowrepo.py
+++ b/hgext/narrow/narrowrepo.py
@@ -73,7 +73,10 @@ 
 
             A tuple of (includes, excludes).
             """
-            return narrowspec.load(self)
+            source = self
+            if self.shared():
+                source = hg.sharedreposource(self)
+            return narrowspec.load(source)
 
         @localrepo.repofilecache(narrowspec.FILENAME)
         def _narrowmatch(self):
@@ -87,7 +90,10 @@ 
             return self._narrowmatch
 
         def setnarrowpats(self, newincludes, newexcludes):
-            narrowspec.save(self, newincludes, newexcludes)
+            target = self
+            if self.shared():
+                target = hg.sharedreposource(self)
+            narrowspec.save(target, newincludes, newexcludes)
             self.invalidate(clearfilecache=True)
 
         # I'm not sure this is the right place to do this filter.