Patchwork [3,of,4,for-reference] obsolete: add a "format.obsstore-version" config option

login
register
mail settings
Submitter Pierre-Yves David
Date Oct. 10, 2014, 11:25 p.m.
Message ID <e994b034e91e459d9fc1.1412983507@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/6214/
State Accepted
Headers show

Comments

Pierre-Yves David - Oct. 10, 2014, 11:25 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 1410915160 25200
#      Tue Sep 16 17:52:40 2014 -0700
# Node ID e994b034e91e459d9fc1e024c9271b1363ccda6c
# Parent  974389427e5fbe9b1d06333aaef61f2f24649f17
obsolete: add a "format.obsstore-version" config option

This option controls what version of the binary format to use when creating a new
obsstore file.

Default is still the old format. No safeguards are currently placed around the
option value, but no clueless users are in danger of harm since it is
undocumented.

Patch

diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -398,11 +398,17 @@  class localrepository(object):
     def _phasecache(self):
         return phases.phasecache(self, self._phasedefaults)
 
     @storecache('obsstore')
     def obsstore(self):
-        store = obsolete.obsstore(self.sopener)
+        # read default format for new obsstore.
+        defaultformat = self.ui.configint('format', 'obsstore-version', None)
+        # rely on obsstore class default when possible.
+        kwargs = {}
+        if defaultformat is not None:
+            defaultformat['defaultformat'] = defaultformat
+        store = obsolete.obsstore(self.sopener, **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'
             self.ui.warn(msg % len(list(store)))
         return store
diff --git a/mercurial/obsolete.py b/mercurial/obsolete.py
--- a/mercurial/obsolete.py
+++ b/mercurial/obsolete.py
@@ -448,20 +448,20 @@  class obsstore(object):
     # meta:    binary blob, encoded metadata dictionary
     # date:    (float, int) tuple, date of marker creation
     # parents: (tuple of nodeid) or None, parents of precursors
     #          None is used when no data has been recorded
 
-    def __init__(self, sopener):
+    def __init__(self, sopener, defaultformat=_fm0version):
         # caches for various obsolescence related cache
         self.caches = {}
         self._all = []
         self.precursors = {}
         self.successors = {}
         self.children = {}
         self.sopener = sopener
         data = sopener.tryread('obsstore')
-        self._version = _fm0version
+        self._version = defaultformat
         if data:
             self._version, markers = _readmarkers(data)
             self._load(markers)
 
     def __iter__(self):