D4574: localrepo: move store() from store module

indygreg (Gregory Szorc) phabricator at mercurial-scm.org
Thu Sep 13 16:31:04 UTC 2018


indygreg created this revision.
Herald added subscribers: mercurial-devel, mjpieters.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  I want logic related to requirements handling to be in the localrepo
  module so it is all in one place.
  
  I would have loved to inline this logic. Unfortunately, statichttprepo
  also calls it. I didn't want to inline it twice. We could potentially
  refactor statichttppeer. But meh.

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  mercurial/localrepo.py
  mercurial/statichttprepo.py
  mercurial/store.py
  tests/test-fncache.t

CHANGE DETAILS

diff --git a/tests/test-fncache.t b/tests/test-fncache.t
--- a/tests/test-fncache.t
+++ b/tests/test-fncache.t
@@ -448,15 +448,15 @@
 
   $ cat > fncacheloadwarn.py << EOF
   > from __future__ import absolute_import
-  > from mercurial import extensions, store
+  > from mercurial import extensions, localrepo
   > 
   > def extsetup(ui):
   >     def wrapstore(orig, requirements, *args):
   >         store = orig(requirements, *args)
   >         if 'store' in requirements and 'fncache' in requirements:
   >             instrumentfncachestore(store, ui)
   >         return store
-  >     extensions.wrapfunction(store, 'store', wrapstore)
+  >     extensions.wrapfunction(localrepo, 'makestore', wrapstore)
   > 
   > def instrumentfncachestore(fncachestore, ui):
   >     class instrumentedfncache(type(fncachestore.fncache)):
diff --git a/mercurial/store.py b/mercurial/store.py
--- a/mercurial/store.py
+++ b/mercurial/store.py
@@ -585,10 +585,3 @@
             if e.startswith(path) and self._exists(e):
                 return True
         return False
-
-def store(requirements, path, vfstype):
-    if 'store' in requirements:
-        if 'fncache' in requirements:
-            return fncachestore(path, vfstype, 'dotencode' in requirements)
-        return encodedstore(path, vfstype)
-    return basicstore(path, vfstype)
diff --git a/mercurial/statichttprepo.py b/mercurial/statichttprepo.py
--- a/mercurial/statichttprepo.py
+++ b/mercurial/statichttprepo.py
@@ -19,7 +19,6 @@
     manifest,
     namespaces,
     pathutil,
-    store,
     url,
     util,
     vfs as vfsmod,
@@ -179,7 +178,7 @@
         localrepo.ensurerequirementscompatible(ui, requirements)
 
         # setup store
-        self.store = store.store(requirements, self.path, vfsclass)
+        self.store = localrepo.makestore(requirements, self.path, vfsclass)
         self.spath = self.store.path
         self.svfs = self.store.opener
         self.sjoin = self.store.join
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -479,8 +479,8 @@
     # The store has changed over time and the exact layout is dictated by
     # requirements. The store interface abstracts differences across all
     # of them.
-    store = storemod.store(requirements, storebasepath,
-                           lambda base: vfsmod.vfs(base, cacheaudited=True))
+    store = makestore(requirements, storebasepath,
+                      lambda base: vfsmod.vfs(base, cacheaudited=True))
 
     hgvfs.createmode = store.createmode
 
@@ -567,6 +567,17 @@
                                 b'sparse is not enabled; enable the '
                                 b'"sparse" extensions to access'))
 
+def makestore(requirements, path, vfstype):
+    """Construct a storage object for a repository."""
+    if b'store' in requirements:
+        if b'fncache' in requirements:
+            return storemod.fncachestore(path, vfstype,
+                                         b'dotencode' in requirements)
+
+        return storemod.encodedstore(path, vfstype)
+
+    return storemod.basicstore(path, vfstype)
+
 @interfaceutil.implementer(repository.completelocalrepository)
 class localrepository(object):
 



To: indygreg, #hg-reviewers
Cc: mjpieters, mercurial-devel


More information about the Mercurial-devel mailing list