diff mercurial/obsolete.py @ 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
line wrap: on
line diff
--- 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: