9 progress_callback = None
10 max_pack_size = 1000*1000*1000 # larger packs will slow down pruning
11 max_pack_objects = 200*1000 # cache memory usage is about 83 bytes per object
20 #log('oldsize=%d+%d adding=%d\n' % (len(self.data), self.start, len(s)))
22 self.data = buffer(self.data, self.start) + s
25 def peek(self, count):
26 return buffer(self.data, self.start, count)
32 v = buffer(self.data, self.start, count)
37 return len(self.data) - self.start
41 b = buf.peek(buf.used())
42 ofs = _hashsplit.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):
77 while blob or not eof:
78 if not eof and (buf.used() < BLOB_LWM or not blob):
81 #log('got %d, total %d\n' % (len(bnew), buf.used()))
86 blob = buf.get(buf.used())
87 if not blob and buf.used() >= BLOB_MAX:
88 blob = buf.get(buf.used()) # limit max blob size
89 if not blob and not eof:
93 if w.outbytes >= max_pack_size or w.count >= max_pack_objects:
95 yield (ofs, len(blob), w.new_blob(blob))
98 nv = (ofs + buf.used())/1000000
100 if split_verbosely >= 1:
106 def _split_to_shalist(w, files):
110 for (ofs, size, sha) in hashsplit_iter(w, files):
111 #log('SPLIT @ %-8d size=%-8d\n' % (ofs, size))
112 # this silliness keeps chunk filenames "similar" when a file changes
117 #log('%x,%x,%x,%x\n' % (last_ofs,ofs,cn,bm))
118 if cn > last_ofs or ofs == last_ofs: break
122 if progress_callback:
123 progress_callback(size)
124 yield ('100644', 'bup.chunk.%016x' % cn, sha)
130 except StopIteration:
134 def split_to_shalist(w, files):
135 sl = iter(_split_to_shalist(w, files))
143 if len(tmplist) >= fanout and len(tmplist) >= 3:
144 shalist.append(('40000', tmplist[0][1], w.new_tree(tmplist)))
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))