Patchwork [2,of,5,V2] obsolete: add readonly flag to obstore constructor

login
register
mail settings
Submitter Durham Goode
Date Oct. 15, 2014, 8:03 p.m.
Message ID <c2a05a28061077532e41.1413403402@dev2000.prn2.facebook.com>
Download mbox | patch
Permalink /patch/6288/
State Accepted
Headers show

Comments

Durham Goode - Oct. 15, 2014, 8:03 p.m.
# HG changeset patch
# User Durham Goode <durham@fb.com>
# Date 1413318031 25200
#      Tue Oct 14 13:20:31 2014 -0700
# Node ID c2a05a28061077532e4153ff3724ed82ed2de139
# Parent  a22ff14b5ff64123d37e1fc42cad86cf76a4c3b1
obsolete: add readonly flag to obstore constructor

Previously, obstore read the obsolete._enabled flag to determine whether to
allow writes to the obstore. Since obsolete._enabled will be moving into a repo
specific config, we can't read it globally, and therefore must pass the
information into the constructor.

Patch

diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -406,7 +406,8 @@  class localrepository(object):
         kwargs = {}
         if defaultformat is not None:
             defaultformat['defaultformat'] = defaultformat
-        store = obsolete.obsstore(self.sopener, **kwargs)
+        store = obsolete.obsstore(self.sopener, readonly=not obsolete._enabled,
+                                  **kwargs)
         if store and not obsolete._enabled:
             # message is rare enough to not be translated
             msg = 'obsolete feature not enabled but %i markers found!\n'
diff --git a/mercurial/obsolete.py b/mercurial/obsolete.py
--- a/mercurial/obsolete.py
+++ b/mercurial/obsolete.py
@@ -450,7 +450,7 @@  class obsstore(object):
     # parents: (tuple of nodeid) or None, parents of precursors
     #          None is used when no data has been recorded
 
-    def __init__(self, sopener, defaultformat=_fm1version):
+    def __init__(self, sopener, defaultformat=_fm1version, readonly=False):
         # caches for various obsolescence related cache
         self.caches = {}
         self._all = []
@@ -460,6 +460,7 @@  class obsstore(object):
         self.sopener = sopener
         data = sopener.tryread('obsstore')
         self._version = defaultformat
+        self._readonly = readonly
         if data:
             self._version, markers = _readmarkers(data)
             self._load(markers)
@@ -513,8 +514,9 @@  class obsstore(object):
 
         Take care of filtering duplicate.
         Return the number of new marker."""
-        if not _enabled:
-            raise util.Abort('obsolete feature is not enabled on this repo')
+        if self._readonly:
+            raise util.Abort('creating obsolete markers is not enabled on this '
+                             'repo')
         known = set(self._all)
         new = []
         for m in markers:
diff --git a/tests/test-obsolete.t b/tests/test-obsolete.t
--- a/tests/test-obsolete.t
+++ b/tests/test-obsolete.t
@@ -32,7 +32,7 @@ 
 Checking that the feature is properly disabled
 
   $ hg debugobsolete -d '0 0' `getid kill_me` -u babar
-  abort: obsolete feature is not enabled on this repo
+  abort: creating obsolete markers is not enabled on this repo
   [255]
 
 Enabling it