[PATCH 2 of 5] obsolete: add readonly flag to obstore constructor

Durham Goode durham at fb.com
Tue Oct 14 16:51:49 CDT 2014


# HG changeset patch
# User Durham Goode <durham at fb.com>
# Date 1413318031 25200
#      Tue Oct 14 13:20:31 2014 -0700
# Node ID d399a51365763f19603de80323da3331ab381a6a
# 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.

diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -406,6 +406,7 @@ class localrepository(object):
         kwargs = {}
         if defaultformat is not None:
             defaultformat['defaultformat'] = defaultformat
+        kwargs['readonly'] = not obsolete._enabled
         store = obsolete.obsstore(self.sopener, **kwargs)
         if store and not obsolete._enabled:
             # message is rare enough to not be translated
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


More information about the Mercurial-devel mailing list