changeset 22950:bb8278b289ee

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.
author Durham Goode <durham@fb.com>
date Tue, 14 Oct 2014 13:20:31 -0700
parents 714f6ef43f3a
children 6c86c673dde6
files mercurial/localrepo.py mercurial/obsolete.py tests/test-obsolete.t
diffstat 3 files changed, 8 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/localrepo.py	Tue Oct 14 13:17:35 2014 -0700
+++ b/mercurial/localrepo.py	Tue Oct 14 13:20:31 2014 -0700
@@ -406,7 +406,8 @@
         kwargs = {}
         if defaultformat is not None:
             kwargs['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'
--- a/mercurial/obsolete.py	Tue Oct 14 13:17:35 2014 -0700
+++ b/mercurial/obsolete.py	Tue Oct 14 13:20:31 2014 -0700
@@ -450,7 +450,7 @@
     # 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 @@
         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 @@
 
         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:
--- a/tests/test-obsolete.t	Tue Oct 14 13:17:35 2014 -0700
+++ b/tests/test-obsolete.t	Tue Oct 14 13:20:31 2014 -0700
@@ -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