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)
46 def hashsplit_iter(f):
53 while blob or not eof:
54 if not eof and (buf.used() < BLOB_LWM or not blob):
55 bnew = f.read(BLOB_HWM)
56 if not len(bnew): eof = 1
57 #log('got %d, total %d\n' % (len(bnew), buf.used()))
62 blob = buf.get(buf.used())
63 if not blob and buf.used() >= BLOB_MAX:
64 blob = buf.get(BLOB_MAX) # limit max blob size
65 if not blob and not eof:
69 yield (ofs, len(blob), git.hash_blob(blob))
72 nv = (ofs + buf.used())/1000000
78 def autofiles(filenames):
87 bup split [-t] [filenames...]
89 b,blobs output a series of blob ids
90 t,tree output a tree id
91 c,commit output a commit id
92 n,name= name of backup set to update (if any)
93 bench print benchmark timings to stderr
95 o = options.Options('bup split', optspec)
96 (opt, flags, extra) = o.parse(sys.argv[1:])
98 if not (opt.blobs or opt.tree or opt.commit or opt.name):
99 log("bup split: use one or more of -b, -t, -c, -n\n")
102 start_time = time.time()
107 for f in autofiles(extra):
108 for (xofs, size, sha) in hashsplit_iter(f):
109 #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
122 shalist.append(('100644', 'bup.chunk.%016x' % cn, sha))
124 tree = git.gen_tree(shalist)
127 if opt.commit or opt.name:
128 msg = 'Generated by command:\n%r' % sys.argv
129 ref = opt.name and ('refs/heads/%s' % opt.name) or None
130 commit = git.gen_commit_easy(ref, tree, msg)
134 secs = time.time() - start_time
136 log('\nbup: %.2fkbytes in %.2f secs = %.2f kbytes/sec\n'
137 % (ofs/1024., secs, ofs/1024./secs))