2 import sys, time, struct
3 import hashsplit, git, options, client
5 from subprocess import PIPE
9 bup split [-tcb] [-n name] [--bench] [filenames...]
11 r,remote= remote repository path
12 b,blobs output a series of blob ids
13 t,tree output a tree id
14 c,commit output a commit id
15 n,name= name of backup set to update (if any)
16 N,noop don't actually save the data anywhere
17 q,quiet don't print progress messages
18 v,verbose increase log output (can be used more than once)
19 copy just copy input to output, hashsplitting along the way
20 bench print benchmark timings to stderr
21 max-pack-size= maximum bytes in a single pack
22 max-pack-objects= maximum number of objects in a single pack
23 fanout= maximum number of blobs in a single tree
25 o = options.Options('bup split', optspec)
26 (opt, flags, extra) = o.parse(sys.argv[1:])
28 git.check_repo_or_die()
29 if not (opt.blobs or opt.tree or opt.commit or opt.name or
30 opt.noop or opt.copy):
31 log("bup split: use one or more of -b, -t, -c, -n, -N, --copy\n")
33 if (opt.noop or opt.copy) and (opt.blobs or opt.tree or
34 opt.commit or opt.name):
35 log('bup split: -N is incompatible with -b, -t, -c, -n\n')
39 git.verbose = opt.verbose - 1
42 hashsplit.max_pack_size = parse_num(opt.max_pack_size)
43 if opt.max_pack_objects:
44 hashsplit.max_pack_objects = parse_num(opt.max_pack_objects)
46 hashsplit.fanout = parse_num(opt.fanout)
50 start_time = time.time()
52 refname = opt.name and 'refs/heads/%s' % opt.name or None
53 if opt.noop or opt.copy:
54 cli = w = oldref = None
56 cli = client.Client(opt.remote)
57 oldref = refname and cli.read_ref(refname) or None
58 w = cli.new_packwriter()
61 oldref = refname and git.read_ref(refname) or None
64 files = extra and (open(fn) for fn in extra) or [sys.stdin]
66 shalist = hashsplit.split_to_shalist(w, files)
67 tree = w.new_tree(shalist)
70 for (blob, bits) in hashsplit.hashsplit_iter(files):
71 hashsplit.total_split += len(blob)
73 sys.stdout.write(str(blob))
74 megs = hashsplit.total_split/1024/1024
75 if not opt.quiet and last != megs:
76 progress('%d Mbytes read\r' % megs)
78 progress('%d Mbytes read, done.\n' % megs)
83 for (mode,name,bin) in shalist:
84 print bin.encode('hex')
86 print tree.encode('hex')
87 if opt.commit or opt.name:
88 msg = 'bup split\n\nGenerated by command:\n%r' % sys.argv
89 ref = opt.name and ('refs/heads/%s' % opt.name) or None
90 commit = w.new_commit(oldref, tree, msg)
92 print commit.encode('hex')
95 w.close() # must close before we can update the ref
99 cli.update_ref(refname, commit, oldref)
101 git.update_ref(refname, commit, oldref)
106 secs = time.time() - start_time
107 size = hashsplit.total_split
109 log('\nbup: %.2fkbytes in %.2f secs = %.2f kbytes/sec\n'
110 % (size/1024., secs, size/1024./secs))