]> arthur.barton.de Git - bup.git/blobdiff - lib/bup/hashsplit.py
hashsplit: replace join_bytes with cat_bytes
[bup.git] / lib / bup / hashsplit.py
index 5c481321dca0e9e2e855bba37b8943c0d136fc9d..0ae6acdb669a624a58688e3bc760ba01d0a35ddd 100644 (file)
@@ -3,7 +3,8 @@ from __future__ import absolute_import
 import io, math, os
 
 from bup import _helpers, compat, helpers
-from bup.compat import buffer, join_bytes
+from bup._helpers import cat_bytes
+from bup.compat import buffer, py_maj
 from bup.helpers import sc_page_size
 
 
@@ -29,17 +30,24 @@ class Buf:
 
     def put(self, s):
         if s:
-            self.data = join_bytes(buffer(self.data, self.start), s)
+            remaining = len(self.data) - self.start
+            self.data = cat_bytes(self.data, self.start, remaining,
+                                  s, 0, len(s))
             self.start = 0
             
     def peek(self, count):
+        if count <= 256:
+            return self.data[self.start : self.start + count]
         return buffer(self.data, self.start, count)
     
     def eat(self, count):
         self.start += count
 
     def get(self, count):
-        v = buffer(self.data, self.start, count)
+        if count <= 256:
+            v = self.data[self.start : self.start + count]
+        else:
+            v = buffer(self.data, self.start, count)
         self.start += count
         return v
 
@@ -190,10 +198,10 @@ def _make_shalist(l):
     ofs = 0
     l = list(l)
     total = sum(size for mode,sha,size, in l)
-    vlen = len('%x' % total)
+    vlen = len(b'%x' % total)
     shalist = []
     for (mode, sha, size) in l:
-        shalist.append((mode, '%0*x' % (vlen,ofs), sha))
+        shalist.append((mode, b'%0*x' % (vlen,ofs), sha))
         ofs += size
     assert(ofs == total)
     return (shalist, total)
@@ -241,7 +249,7 @@ def split_to_blob_or_tree(makeblob, maketree, files,
     if len(shalist) == 1:
         return (shalist[0][0], shalist[0][2])
     elif len(shalist) == 0:
-        return (GIT_MODE_FILE, makeblob(''))
+        return (GIT_MODE_FILE, makeblob(b''))
     else:
         return (GIT_MODE_TREE, maketree(shalist))