16 #log('oldsize=%d+%d adding=%d\n' % (len(self.data), self.start, len(s)))
18 self.data = buffer(self.data, self.start) + s
21 def peek(self, count):
22 return buffer(self.data, self.start, count)
28 v = buffer(self.data, self.start, count)
33 return len(self.data) - self.start
37 global split_verbosely
38 b = buf.peek(buf.used())
39 ofs = chashsplit.splitbuf(b)
41 if split_verbosely >= 2:
44 return buffer(b, 0, ofs)
55 yield '' # EOF indicator
58 def autofiles(filenames):
66 def hashsplit_iter(files):
67 global split_verbosely
75 while blob or not eof:
76 if not eof and (buf.used() < BLOB_LWM or not blob):
79 #log('got %d, total %d\n' % (len(bnew), buf.used()))
84 blob = buf.get(buf.used())
85 if not blob and buf.used() >= BLOB_MAX:
86 blob = buf.get(buf.used()) # limit max blob size
87 if not blob and not eof:
91 yield (ofs, len(blob), git.hash_blob(blob))
94 nv = (ofs + buf.used())/1000000
96 if split_verbosely >= 1:
102 def split_to_shalist(files):
106 for (ofs, size, sha) in hashsplit_iter(files):
107 #log('SPLIT @ %-8d size=%-8d\n' % (ofs, size))
108 # this silliness keeps chunk filenames "similar" when a file changes
113 #log('%x,%x,%x,%x\n' % (last_ofs,ofs,cn,bm))
114 if cn > last_ofs or ofs == last_ofs: break
118 yield ('100644', 'bup.chunk.%016x' % cn, sha)
121 def split_to_tree(files):
122 shalist = list(split_to_shalist(files))
123 tree = git.gen_tree(shalist)
124 return (shalist, tree)
127 def split_to_blob_or_tree(files):
128 (shalist, tree) = split_to_tree(files)
129 if len(shalist) == 1:
130 return (shalist[0][0], shalist[0][2])
131 elif len(shalist) == 0:
132 return ('100644', git.hash_blob(''))
134 return ('40000', tree)