2 import sys, os, subprocess, errno, zlib, time
3 import hashsplit, git, options
17 #log('oldsize=%d+%d adding=%d\n' % (len(self.data), self.start, len(s)))
19 self.data = buffer(self.data, self.start) + s
22 def peek(self, count):
23 return buffer(self.data, self.start, count)
29 v = buffer(self.data, self.start, count)
34 return len(self.data) - self.start
38 b = buf.peek(buf.used())
39 ofs = hashsplit.splitbuf(b)
42 return buffer(b, 0, ofs)
53 yield '' # EOF indicator
56 def autofiles(filenames):
64 def hashsplit_iter(f):
72 while blob or not eof:
73 if not eof and (buf.used() < BLOB_LWM or not blob):
76 #log('got %d, total %d\n' % (len(bnew), buf.used()))
81 blob = buf.get(buf.used())
82 if not blob and buf.used() >= BLOB_MAX:
83 blob = buf.get(BLOB_MAX) # limit max blob size
84 if not blob and not eof:
88 yield (ofs, len(blob), git.hash_blob(blob))
91 nv = (ofs + buf.used())/1000000
98 bup split [-t] [filenames...]
100 b,blobs output a series of blob ids
101 t,tree output a tree id
102 c,commit output a commit id
103 n,name= name of backup set to update (if any)
104 bench print benchmark timings to stderr
106 o = options.Options('bup split', optspec)
107 (opt, flags, extra) = o.parse(sys.argv[1:])
109 if not (opt.blobs or opt.tree or opt.commit or opt.name):
110 log("bup split: use one or more of -b, -t, -c, -n\n")
113 start_time = time.time()
118 for (ofs, size, sha) in hashsplit_iter(autofiles(extra)):
119 #log('SPLIT @ %-8d size=%-8d\n' % (ofs, size))
123 # this silliness keeps chunk filenames "similar" when a file changes
128 #log('%x,%x,%x,%x\n' % (last_ofs,ofs,cn,bm))
129 if cn > last_ofs or ofs == last_ofs: break
132 shalist.append(('100644', 'bup.chunk.%016x' % cn, sha))
133 tree = git.gen_tree(shalist)
136 if opt.commit or opt.name:
137 msg = 'Generated by command:\n%r' % sys.argv
138 ref = opt.name and ('refs/heads/%s' % opt.name) or None
139 commit = git.gen_commit_easy(ref, tree, msg)
143 secs = time.time() - start_time
145 log('\nbup: %.2fkbytes in %.2f secs = %.2f kbytes/sec\n'
146 % (ofs/1024., secs, ofs/1024./secs))