obsolete: support for any known obsstore format when reading or writing
authorPierre-Yves David <pierre-yves.david@fb.com>
Mon, 25 Aug 2014 16:16:01 +0200
changeset 22331 b130b241718e
parent 22330 e74f8a65252d
child 22332 13e22358e9d2
obsolete: support for any known obsstore format when reading or writing We can now read and write any known format. The list of known formats currently has one element (0). The obsstore itself is not aware of multiple formats yet and always uses format 0.
mercurial/obsolete.py
--- a/mercurial/obsolete.py	Mon Aug 25 16:09:18 2014 +0200
+++ b/mercurial/obsolete.py	Mon Aug 25 16:16:01 2014 +0200
@@ -142,10 +142,10 @@
     off = 0
     diskversion = _unpack('>B', data[off:off + 1])[0]
     off += 1
-    if diskversion != _fm0version:
+    if diskversion not in formats:
         raise util.Abort(_('parsing obsolete marker: unknown version %r')
                          % diskversion)
-    return _fm0readmarkers(data, off)
+    return formats[diskversion][0](data, off)
 
 def _fm0readmarkers(data, off=0):
     """Read and enumerate markers from raw data in format version 0"""
@@ -217,6 +217,10 @@
     data.extend(sucs)
     return _pack(format, *data) + metadata
 
+# mapping to read/write various marker formats
+# <version> -> (decoder, encoder)
+formats = {0: (_fm0readmarkers, _fm0encodeonemarker)}
+
 def encodemeta(meta):
     """Return encoded metadata string to string mapping.
 
@@ -438,13 +442,14 @@
             seennodes |= pendingnodes
         return seenmarkers
 
-def _encodemarkers(markers, addheader=False):
+def _encodemarkers(markers, addheader=False, version=_fm0version):
     # Kept separate from flushmarkers(), it will be reused for
     # markers exchange.
+    encodeone = formats[version][1]
     if addheader:
         yield _pack('>B', _fm0version)
     for marker in markers:
-        yield _fm0encodeonemarker(marker)
+        yield encodeone(marker)
 
 
 # arbitrary picked to fit into 8K limit from HTTP server