]> arthur.barton.de Git - bup.git/blob - cmd-split.py
Name temp files from 'make test' as *.tmp to make them easier to clean.
[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 if opt.verbose >= 2:
25     git.verbose = opt.verbose - 1
26     opt.bench = 1
27
28 start_time = time.time()
29
30 (shalist,tree) = hashsplit.split_to_tree(hashsplit.autofiles(extra))
31
32 if opt.verbose:
33     log('\n')
34 if opt.blobs:
35     for (mode,name,bin) in shalist:
36         print bin.encode('hex')
37 if opt.tree:
38     print tree.encode('hex')
39 if opt.commit or opt.name:
40     msg = 'bup split\n\nGenerated by command:\n%r' % sys.argv
41     ref = opt.name and ('refs/heads/%s' % opt.name) or None
42     commit = git.gen_commit_easy(ref, tree, msg)
43     if opt.commit:
44         print commit.encode('hex')
45
46 secs = time.time() - start_time
47 size = hashsplit.total_split
48 if opt.bench:
49     log('\nbup: %.2fkbytes in %.2f secs = %.2f kbytes/sec\n'
50         % (size/1024., secs, size/1024./secs))
51
52 git.flush_pack()