9 max_pack_size = 1000*1000*1000
10 max_pack_objects = 10*1000*1000
19 #log('oldsize=%d+%d adding=%d\n' % (len(self.data), self.start, len(s)))
21 self.data = buffer(self.data, self.start) + s
24 def peek(self, count):
25 return buffer(self.data, self.start, count)
31 v = buffer(self.data, self.start, count)
36 return len(self.data) - self.start
40 global split_verbosely
41 b = buf.peek(buf.used())
42 ofs = chashsplit.splitbuf(b)
44 if split_verbosely >= 2:
47 return buffer(b, 0, ofs)
58 yield '' # EOF indicator
61 def autofiles(filenames):
69 def hashsplit_iter(w, files):
70 global split_verbosely
78 while blob or not eof:
79 if not eof and (buf.used() < BLOB_LWM or not blob):
82 #log('got %d, total %d\n' % (len(bnew), buf.used()))
87 blob = buf.get(buf.used())
88 if not blob and buf.used() >= BLOB_MAX:
89 blob = buf.get(buf.used()) # limit max blob size
90 if not blob and not eof:
94 if w.outbytes >= max_pack_size or w.count >= max_pack_objects:
96 yield (ofs, len(blob), w.new_blob(blob))
99 nv = (ofs + buf.used())/1000000
101 if split_verbosely >= 1:
107 def split_to_shalist(w, files):
111 for (ofs, size, sha) in hashsplit_iter(w, files):
112 #log('SPLIT @ %-8d size=%-8d\n' % (ofs, size))
113 # this silliness keeps chunk filenames "similar" when a file changes
118 #log('%x,%x,%x,%x\n' % (last_ofs,ofs,cn,bm))
119 if cn > last_ofs or ofs == last_ofs: break
123 yield ('100644', 'bup.chunk.%016x' % cn, sha)
129 except StopIteration:
133 def split_to_tree(w, files):
134 sl = iter(split_to_shalist(w, files))
142 if len(tmplist) >= fanout and len(tmplist) >= 3:
143 shalist.append(('40000', tmplist[0][1], w.new_tree(tmplist)))
146 tree = w.new_tree(shalist)
147 return (shalist, tree)
150 def split_to_blob_or_tree(w, files):
151 shalist = list(split_to_shalist(w, files))
152 if len(shalist) == 1:
153 return (shalist[0][0], shalist[0][2])
154 elif len(shalist) == 0:
155 return ('100644', w.new_blob(''))
157 return ('40000', w.new_tree(shalist))