]> arthur.barton.de Git - bup.git/blob - cmd-split.py
Write git pack files instead of loose object files.
[bup.git] / cmd-split.py
1 #!/usr/bin/env python
2 import sys, time
3 import hashsplit, git, options
4 from helpers import *
5
6 optspec = """
7 bup split [-tcb] [-n name] [--bench] [filenames...]
8 --
9 b,blobs    output a series of blob ids
10 t,tree     output a tree id
11 c,commit   output a commit id
12 n,name=    name of backup set to update (if any)
13 v,verbose  increase log output (can be used more than once)
14 bench      print benchmark timings to stderr
15 """
16 o = options.Options('bup split', optspec)
17 (opt, flags, extra) = o.parse(sys.argv[1:])
18
19 if not (opt.blobs or opt.tree or opt.commit or opt.name):
20     log("bup split: use one or more of -b, -t, -c, -n\n")
21     o.usage()
22
23 hashsplit.split_verbosely = opt.verbose
24
25 start_time = time.time()
26
27 (shalist,tree) = hashsplit.split_to_tree(hashsplit.autofiles(extra))
28
29 if opt.blobs:
30     for (mode,name,sum) in shalist:
31         print sum
32 if opt.tree:
33     print tree
34 if opt.commit or opt.name:
35     msg = 'bup split\n\nGenerated by command:\n%r' % sys.argv
36     ref = opt.name and ('refs/heads/%s' % opt.name) or None
37     commit = git.gen_commit_easy(ref, tree, msg)
38     if opt.commit:
39         print commit
40
41 secs = time.time() - start_time
42 size = hashsplit.total_split
43 if opt.bench:
44     log('\nbup: %.2fkbytes in %.2f secs = %.2f kbytes/sec\n'
45         % (size/1024., secs, size/1024./secs))
46
47 git.flush_pack()