[PATCH 1 of 2] obsolete: move obsstore creation logic from localrepo

Gregory Szorc gregory.szorc at gmail.com
Fri Jun 9 02:26:00 EDT 2017


# HG changeset patch
# User Gregory Szorc <gregory.szorc at gmail.com>
# Date 1496984070 25200
#      Thu Jun 08 21:54:30 2017 -0700
# Node ID 4867bfadaa177b5e43108f2683e64898204827b7
# Parent  326c0e2c1a1d59e07f4c9d86f81e4419c3d779d8
obsolete: move obsstore creation logic from localrepo

This code has more to do with obsolete.py than localrepo.py. Let's
move it there.

diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -524,21 +524,7 @@ class localrepository(object):
 
     @storecache('obsstore')
     def obsstore(self):
-        # read default format for new obsstore.
-        # developer config: format.obsstore-version
-        defaultformat = self.ui.configint('format', 'obsstore-version', None)
-        # rely on obsstore class default when possible.
-        kwargs = {}
-        if defaultformat is not None:
-            kwargs['defaultformat'] = defaultformat
-        readonly = not obsolete.isenabled(self, obsolete.createmarkersopt)
-        store = obsolete.obsstore(self.svfs, readonly=readonly,
-                                  **kwargs)
-        if store and readonly:
-            self.ui.warn(
-                _('obsolete feature not enabled but %i markers found!\n')
-                % len(list(store)))
-        return store
+        return obsolete.makestore(self.ui, self)
 
     @storecache('00changelog.i')
     def changelog(self):
diff --git a/mercurial/obsolete.py b/mercurial/obsolete.py
--- a/mercurial/obsolete.py
+++ b/mercurial/obsolete.py
@@ -753,6 +753,23 @@ class obsstore(object):
             seennodes |= pendingnodes
         return seenmarkers
 
+def makestore(ui, repo):
+    """Create an obsstore instance from a repo."""
+    # read default format for new obsstore.
+    # developer config: format.obsstore-version
+    defaultformat = repo.ui.configint('format', 'obsstore-version', None)
+    # rely on obsstore class default when possible.
+    kwargs = {}
+    if defaultformat is not None:
+        kwargs['defaultformat'] = defaultformat
+    readonly = not isenabled(repo, createmarkersopt)
+    store = obsstore(repo.svfs, readonly=readonly, **kwargs)
+    if store and readonly:
+        ui.warn(
+            _('obsolete feature not enabled but %i markers found!\n')
+            % len(list(store)))
+    return store
+
 def _filterprunes(markers):
     """return a set with no prune markers"""
     return set(m for m in markers if m[1])


More information about the Mercurial-devel mailing list