1 #!/usr/bin/env python2.5
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 v,verbose increase log output (can be used more than once)
17 bench print benchmark timings to stderr
19 o = options.Options('bup split', optspec)
20 (opt, flags, extra) = o.parse(sys.argv[1:])
22 git.check_repo_or_die()
23 if not (opt.blobs or opt.tree or opt.commit or opt.name):
24 log("bup split: use one or more of -b, -t, -c, -n\n")
27 hashsplit.split_verbosely = opt.verbose
29 git.verbose = opt.verbose - 1
32 start_time = time.time()
34 refname = opt.name and 'refs/heads/%s' % opt.name or None
36 cli = client.Client(opt.remote)
37 oldref = refname and cli.read_ref(refname) or None
39 w = cli.new_packwriter()
42 oldref = refname and git.read_ref(refname) or None
45 (shalist,tree) = hashsplit.split_to_tree(w, hashsplit.autofiles(extra))
50 for (mode,name,bin) in shalist:
51 print bin.encode('hex')
53 print tree.encode('hex')
54 if opt.commit or opt.name:
55 msg = 'bup split\n\nGenerated by command:\n%r' % sys.argv
56 ref = opt.name and ('refs/heads/%s' % opt.name) or None
57 commit = w.new_commit(oldref, tree, msg)
59 print commit.encode('hex')
61 w.close() # must close before we can update the ref
65 cli.update_ref(refname, commit, oldref)
67 git.update_ref(refname, commit, oldref)
72 secs = time.time() - start_time
73 size = hashsplit.total_split
75 log('\nbup: %.2fkbytes in %.2f secs = %.2f kbytes/sec\n'
76 % (size/1024., secs, size/1024./secs))