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

login
register
mail settings
Submitter Gregory Szorc
Date June 9, 2017, 6:26 a.m.
Message ID <4867bfadaa177b5e4310.1496989560@ubuntu-vm-main>
Download mbox | patch
Permalink /patch/21270/
State Accepted
Headers show

Comments

Gregory Szorc - June 9, 2017, 6:26 a.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@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.
Yuya Nishihara - June 9, 2017, 1:33 p.m.
On Thu, 08 Jun 2017 23:26:00 -0700, Gregory Szorc wrote:
> # HG changeset patch
> # User Gregory Szorc <gregory.szorc@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

Queued, thanks.

> 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)

Changed repo.ui to ui since it is explicitly passed.

Patch

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])