[PATCH 2 of 5 V2] obsolete: add readonly flag to obstore constructor
Durham Goode
durham at fb.com
Wed Oct 15 15:03:22 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 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.
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
More information about the Mercurial-devel
mailing list