obscache: use _readmarkers() from core with correct signature
authorMartin von Zweigbergk <martinvonz@google.com>
Tue, 22 Aug 2017 10:59:19 -0700
changeset 2851 a13acecbc850
parent 2850 a0d6741d4bb8
child 2853 cec3d2ea2eeb
obscache: use _readmarkers() from core with correct signature The copied _readmarkers() went stale with Mercurial core commit 5d3ba4395288 (obsstore: let read marker API take a range of offsets, 2017-06-04). At the same time, the Mercurial core version of the function gained the desired offset argument, so we can now use that function.
hgext3rd/evolve/obscache.py
--- a/hgext3rd/evolve/obscache.py	Mon Aug 14 11:39:06 2017 +0530
+++ b/hgext3rd/evolve/obscache.py	Tue Aug 22 10:59:19 2017 -0700
@@ -111,21 +111,26 @@
 
     return obsstore
 
-# XXX copied as is from Mercurial 4.2 and added the "offset" parameters
-@util.nogc
-def _readmarkers(data, offset=None):
-    """Read and enumerate markers from raw data"""
-    off = 0
-    diskversion = struct.unpack('>B', data[off:off + 1])[0]
-    if offset is None:
-        off += 1
-    else:
-        assert 1 <= offset
-        off = offset
-    if diskversion not in obsolete.formats:
-        raise error.Abort(_('parsing obsolete marker: unknown version %r')
-                          % diskversion)
-    return diskversion, obsolete.formats[diskversion][0](data, off)
+if obsolete._readmarkers.__code__.co_argcount > 1:
+    # hg-4.3+ has the "offset" parameter, and _fm?readmarkers also have an
+    # extra "stop" parameter
+    _readmarkers = obsolete._readmarkers
+else:
+    # XXX copied as is from Mercurial 4.2 and added the "offset" parameters
+    @util.nogc
+    def _readmarkers(data, offset=None):
+        """Read and enumerate markers from raw data"""
+        off = 0
+        diskversion = struct.unpack('>B', data[off:off + 1])[0]
+        if offset is None:
+            off += 1
+        else:
+            assert 1 <= offset
+            off = offset
+        if diskversion not in obsolete.formats:
+            raise error.Abort(_('parsing obsolete marker: unknown version %r')
+                              % diskversion)
+        return diskversion, obsolete.formats[diskversion][0](data, off)
 
 def markersfrom(obsstore, byteoffset, firstmarker):
     if not firstmarker: