changeset 38911:576eef1ab43d

narrow: move .hg/narrowspec to .hg/store/narrowspec (BC) The narrowspec is more closely related to the store than to the working copy. For example, if the narrowspec changes, the set of revlogs also needs to change (the working copy may change, but that depends on which commit is checked out). Also, when using the share extension, the narrowspec needs to be shared along with the store. This patch therefore moves the narrowspec into the store/ directory. This is clearly a breaking change, but I haven't bothered trying to fall back to reading the narrowspec from the old location (.hg/), because there are very few users of narrow out there. (We'll add a temporary hack to our Google-internal extension to handle the migration.) Differential Revision: https://phab.mercurial-scm.org/D4099
author Martin von Zweigbergk <martinvonz@google.com>
date Thu, 02 Aug 2018 14:57:20 -0700
parents 204e074c188e
children 7e75777e4a51
files hgext/narrow/__init__.py hgext/narrow/narrowrepo.py mercurial/localrepo.py mercurial/narrowspec.py mercurial/store.py tests/test-narrow-debugcommands.t tests/test-narrow-pull.t
diffstat 7 files changed, 10 insertions(+), 37 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/narrow/__init__.py	Fri Aug 03 13:53:02 2018 -0700
+++ b/hgext/narrow/__init__.py	Thu Aug 02 14:57:20 2018 -0700
@@ -16,7 +16,6 @@
 
 from mercurial import (
     extensions,
-    hg,
     localrepo,
     registrar,
     repository,
@@ -86,8 +85,6 @@
 
 def extsetup(ui):
     extensions.wrapfunction(verifymod.verifier, '__init__', _verifierinit)
-    extensions.wrapfunction(hg, 'postshare', narrowrepo.wrappostshare)
-    extensions.wrapfunction(hg, 'copystore', narrowrepo.unsharenarrowspec)
 
 templatekeyword = narrowtemplates.templatekeyword
 revsetpredicate = narrowtemplates.revsetpredicate
--- a/hgext/narrow/narrowrepo.py	Fri Aug 03 13:53:02 2018 -0700
+++ b/hgext/narrow/narrowrepo.py	Thu Aug 02 14:57:20 2018 -0700
@@ -7,34 +7,11 @@
 
 from __future__ import absolute_import
 
-from mercurial import (
-    hg,
-    narrowspec,
-    repository,
-)
-
 from . import (
     narrowdirstate,
     narrowrevlog,
 )
 
-def wrappostshare(orig, sourcerepo, destrepo, **kwargs):
-    orig(sourcerepo, destrepo, **kwargs)
-    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 (repository.NARROW_REQUIREMENT in repo.requirements
-        and repo.path == repopath and repo.shared()):
-        srcrepo = hg.sharedreposource(repo)
-        with srcrepo.vfs(narrowspec.FILENAME) as f:
-            spec = f.read()
-        with repo.vfs(narrowspec.FILENAME, 'w') as f:
-            f.write(spec)
-    return orig(ui, repo, repopath)
-
 def wraprepo(repo):
     """Enables narrow clone functionality on a single local repository."""
 
--- a/mercurial/localrepo.py	Fri Aug 03 13:53:02 2018 -0700
+++ b/mercurial/localrepo.py	Thu Aug 02 14:57:20 2018 -0700
@@ -811,7 +811,7 @@
                                " working parent %s!\n") % short(node))
             return nullid
 
-    @repofilecache(narrowspec.FILENAME)
+    @storecache(narrowspec.FILENAME)
     def narrowpats(self):
         """matcher patterns for this repository's narrowspec
 
@@ -823,7 +823,7 @@
             source = hg.sharedreposource(self)
         return narrowspec.load(source)
 
-    @repofilecache(narrowspec.FILENAME)
+    @storecache(narrowspec.FILENAME)
     def _narrowmatch(self):
         if repository.NARROW_REQUIREMENT not in self.requirements:
             return matchmod.always(self.root, '')
--- a/mercurial/narrowspec.py	Fri Aug 03 13:53:02 2018 -0700
+++ b/mercurial/narrowspec.py	Thu Aug 02 14:57:20 2018 -0700
@@ -108,7 +108,7 @@
 
 def load(repo):
     try:
-        spec = repo.vfs.read(FILENAME)
+        spec = repo.svfs.read(FILENAME)
     except IOError as e:
         # Treat "narrowspec does not exist" the same as "narrowspec file exists
         # and is empty".
@@ -125,19 +125,19 @@
 
 def save(repo, includepats, excludepats):
     spec = format(includepats, excludepats)
-    repo.vfs.write(FILENAME, spec)
+    repo.svfs.write(FILENAME, spec)
 
 def savebackup(repo, backupname):
     if repository.NARROW_REQUIREMENT not in repo.requirements:
         return
     vfs = repo.vfs
     vfs.tryunlink(backupname)
-    util.copyfile(vfs.join(FILENAME), vfs.join(backupname), hardlink=True)
+    util.copyfile(repo.svfs.join(FILENAME), vfs.join(backupname), hardlink=True)
 
 def restorebackup(repo, backupname):
     if repository.NARROW_REQUIREMENT not in repo.requirements:
         return
-    repo.vfs.rename(backupname, FILENAME)
+    util.rename(repo.vfs.join(backupname), repo.svfs.join(FILENAME))
 
 def clearbackup(repo, backupname):
     if repository.NARROW_REQUIREMENT not in repo.requirements:
--- a/mercurial/store.py	Fri Aug 03 13:53:02 2018 -0700
+++ b/mercurial/store.py	Thu Aug 02 14:57:20 2018 -0700
@@ -317,8 +317,8 @@
         mode = None
     return mode
 
-_data = ('data meta 00manifest.d 00manifest.i 00changelog.d 00changelog.i'
-         ' phaseroots obsstore')
+_data = ('narrowspec data meta 00manifest.d 00manifest.i'
+         ' 00changelog.d 00changelog.i phaseroots obsstore')
 
 def isrevlog(f, kind, st):
     return kind == stat.S_IFREG and f[-2:] in ('.i', '.d')
@@ -546,7 +546,7 @@
                     raise
 
     def copylist(self):
-        d = ('data meta dh fncache phaseroots obsstore'
+        d = ('narrowspec data meta dh fncache phaseroots obsstore'
              ' 00manifest.d 00manifest.i 00changelog.d 00changelog.i')
         return (['requires', '00changelog.i'] +
                 ['store/' + f for f in d.split()])
--- a/tests/test-narrow-debugcommands.t	Fri Aug 03 13:53:02 2018 -0700
+++ b/tests/test-narrow-debugcommands.t	Thu Aug 02 14:57:20 2018 -0700
@@ -1,7 +1,7 @@
   $ . "$TESTDIR/narrow-library.sh"
   $ hg init repo
   $ cd repo
-  $ cat << EOF > .hg/narrowspec
+  $ cat << EOF > .hg/store/narrowspec
   > [include]
   > path:foo
   > [exclude]
--- a/tests/test-narrow-pull.t	Fri Aug 03 13:53:02 2018 -0700
+++ b/tests/test-narrow-pull.t	Thu Aug 02 14:57:20 2018 -0700
@@ -166,7 +166,6 @@
 
 We should also be able to unshare without breaking everything:
   $ hg unshare
-  devel-warn: write with no wlock: "narrowspec" at: */hgext/narrow/narrowrepo.py:* (unsharenarrowspec) (glob)
   $ hg verify
   checking changesets
   checking manifests