bdiff: (pure) support array.array arrays (issue5130) stable
authortimeless <timeless@mozdev.org>
Tue, 08 Mar 2016 17:26:12 +0000
branchstable
changeset 30624 9ab45fbe045eb0373e701ef0aecfb284fccd05cd
parent 30623 b1d35e2e1af60907adc05a97ae0874e4004e5765
child 30625 48e1a641765d541a4bdc3f36b69cb3f5974040af
push id200
push usergszorc@mozilla.com
push dateSat, 12 Mar 2016 00:54:44 +0000
bdiff: (pure) support array.array arrays (issue5130)
mercurial/pure/bdiff.py
tests/test-clone-uncompressed.t
--- a/mercurial/pure/bdiff.py
+++ b/mercurial/pure/bdiff.py
@@ -2,16 +2,17 @@
 #
 # Copyright 2009 Matt Mackall <mpm@selenic.com> and others
 #
 # This software may be used and distributed according to the terms of the
 # GNU General Public License version 2 or any later version.
 
 from __future__ import absolute_import
 
+import array
 import difflib
 import re
 import struct
 
 def splitnewlines(text):
     '''like str.splitlines, but only split on newlines.'''
     lines = [l + '\n' for l in text.split('\n')]
     if lines:
@@ -45,19 +46,25 @@ def _normalizeblocks(a, b, blocks):
             while (b1end + shift < b2end and
                    a[a1end + shift] == b[b1end + shift]):
                 shift += 1
         r.append((a1, b1, l1 + shift))
         prev = a2 + shift, b2 + shift, l2 - shift
     r.append(prev)
     return r
 
+def _tostring(c):
+    if type(c) is array.array:
+        # this copy overhead isn't ideal
+        return c.tostring()
+    return str(c)
+
 def bdiff(a, b):
-    a = str(a).splitlines(True)
-    b = str(b).splitlines(True)
+    a = _tostring(a).splitlines(True)
+    b = _tostring(b).splitlines(True)
 
     if not a:
         s = "".join(b)
         return s and (struct.pack(">lll", 0, 0, len(s)) + s)
 
     bin = []
     p = [0]
     for i in a: p.append(p[-1] + len(i))
--- a/tests/test-clone-uncompressed.t
+++ b/tests/test-clone-uncompressed.t
@@ -1,18 +1,22 @@
 #require serve
 
+Initialize repository
+the status call is to check for issue5130
+
   $ hg init server
   $ cd server
   $ touch foo
   $ hg -q commit -A -m initial
   >>> for i in range(1024):
   ...     with open(str(i), 'wb') as fh:
   ...         fh.write(str(i))
   $ hg -q commit -A -m 'add a lot of files'
+  $ hg st
   $ hg serve -p $HGPORT -d --pid-file=hg.pid
   $ cat hg.pid >> $DAEMON_PIDS
   $ cd ..
 
 Basic clone
 
   $ hg clone --uncompressed -U http://localhost:$HGPORT clone1
   streaming all changes