Patchwork [evolve-ext,v2] obscache: use _readmarkers() from core with correct signature

login
register
mail settings
Submitter via Mercurial-devel
Date Aug. 23, 2017, 1:19 p.m.
Message ID <59ad0904a77f4fe8398b.1503494352@martinvonz.svl.corp.google.com>
Download mbox | patch
Permalink /patch/23225/
State Accepted
Headers show

Comments

via Mercurial-devel - Aug. 23, 2017, 1:19 p.m.
# HG changeset patch
# User Martin von Zweigbergk <martinvonz@google.com>
# Date 1503424759 25200
#      Tue Aug 22 10:59:19 2017 -0700
# Node ID 59ad0904a77f4fe8398b10a9c05a46bf79d900c5
# Parent  95470e817c00b03fcf99e486412cc7d7f0116681
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.
Boris Feld - Aug. 24, 2017, 3:53 p.m.
Queue thanks.

On Wed, 2017-08-23 at 06:19 -0700, Martin von Zweigbergk via Mercurial-
devel wrote:
> # HG changeset patch
> # User Martin von Zweigbergk <martinvonz@google.com>
> # Date 1503424759 25200
> #      Tue Aug 22 10:59:19 2017 -0700
> # Node ID 59ad0904a77f4fe8398b10a9c05a46bf79d900c5
> # Parent  95470e817c00b03fcf99e486412cc7d7f0116681
> 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.
> 
> diff --git a/hgext3rd/evolve/obscache.py
> b/hgext3rd/evolve/obscache.py
> --- a/hgext3rd/evolve/obscache.py
> +++ b/hgext3rd/evolve/obscache.py
> @@ -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:
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Patch

diff --git a/hgext3rd/evolve/obscache.py b/hgext3rd/evolve/obscache.py
--- a/hgext3rd/evolve/obscache.py
+++ b/hgext3rd/evolve/obscache.py
@@ -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: