]> arthur.barton.de Git - bup.git/blobdiff - lib/bup/hashsplit.py
pylint: check for trailing whitespace
[bup.git] / lib / bup / hashsplit.py
index af0ad172be93a9e46188e0e3806b1cc6bdfa571c..ff00e54b3cd46b4fda1b30827e03762c7ebce025 100644 (file)
@@ -2,18 +2,16 @@
 from __future__ import absolute_import
 import io, math, os
 
-from bup import _helpers, compat, helpers
-from bup.compat import buffer_concat
+from bup import _helpers, helpers
+from bup._helpers import cat_bytes
+from bup.compat import buffer
 from bup.helpers import sc_page_size
 
-if compat.py_maj > 2:
-    from bup.compat import buffer, buffer_concat
-
 
 _fmincore = getattr(helpers, 'fmincore', None)
 
 BLOB_MAX = 8192*4   # 8192 is the "typical" blob size for bupsplit
-BLOB_READ_SIZE = 1024*1024
+BLOB_READ_SIZE = 8 * 1024 * 1024
 MAX_PER_TREE = 256
 progress_callback = None
 fanout = 16
@@ -31,18 +29,28 @@ class Buf:
         self.start = 0
 
     def put(self, s):
-        if s:
-            self.data = buffer_concat(buffer(self.data, self.start), s)
+        if not self.data:
+            self.data = s
+            self.start = 0
+        elif 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
 
@@ -193,10 +201,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)
@@ -244,7 +252,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))