]> arthur.barton.de Git - bup.git/blobdiff - cmd-split.py
executable files: don't assume python2.5.
[bup.git] / cmd-split.py
index 74911c1ced18e7cf9f1c6f185b5d1e0c61818228..f462655a5e128fb95d212f5370f5da96cb8be442 100755 (executable)
@@ -1,21 +1,28 @@
 #!/usr/bin/env python
-import sys, time
-import hashsplit, git, options
+import sys, time, struct
+import hashsplit, git, options, client
 from helpers import *
+from subprocess import PIPE
+
 
 optspec = """
 bup split [-tcb] [-n name] [--bench] [filenames...]
 --
+r,remote=  remote repository path
 b,blobs    output a series of blob ids
 t,tree     output a tree id
 c,commit   output a commit id
 n,name=    name of backup set to update (if any)
 v,verbose  increase log output (can be used more than once)
 bench      print benchmark timings to stderr
+max-pack-size=  maximum bytes in a single pack
+max-pack-objects=  maximum number of objects in a single pack
+fanout=  maximum number of blobs in a single tree
 """
 o = options.Options('bup split', optspec)
 (opt, flags, extra) = o.parse(sys.argv[1:])
 
+git.check_repo_or_die()
 if not (opt.blobs or opt.tree or opt.commit or opt.name):
     log("bup split: use one or more of -b, -t, -c, -n\n")
     o.usage()
@@ -23,10 +30,30 @@ if not (opt.blobs or opt.tree or opt.commit or opt.name):
 hashsplit.split_verbosely = opt.verbose
 if opt.verbose >= 2:
     git.verbose = opt.verbose - 1
+    opt.bench = 1
+if opt.max_pack_size:
+    hashsplit.max_pack_size = int(opt.max_pack_size)
+if opt.max_pack_objects:
+    hashsplit.max_pack_objects = int(opt.max_pack_objects)
+if opt.fanout:
+    hashsplit.fanout = int(opt.fanout)
+if opt.blobs:
+    hashsplit.fanout = 0
 
 start_time = time.time()
 
-(shalist,tree) = hashsplit.split_to_tree(hashsplit.autofiles(extra))
+refname = opt.name and 'refs/heads/%s' % opt.name or None
+if opt.remote:
+    cli = client.Client(opt.remote)
+    oldref = refname and cli.read_ref(refname) or None
+    w = cli.new_packwriter()
+else:
+    cli = None
+    oldref = refname and git.read_ref(refname) or None
+    w = git.PackWriter()
+    
+shalist = hashsplit.split_to_shalist(w, hashsplit.autofiles(extra))
+tree = w.new_tree(shalist)
 
 if opt.verbose:
     log('\n')
@@ -38,14 +65,23 @@ if opt.tree:
 if opt.commit or opt.name:
     msg = 'bup split\n\nGenerated by command:\n%r' % sys.argv
     ref = opt.name and ('refs/heads/%s' % opt.name) or None
-    commit = git.gen_commit_easy(ref, tree, msg)
+    commit = w.new_commit(oldref, tree, msg)
     if opt.commit:
         print commit.encode('hex')
 
+w.close()  # must close before we can update the ref
+        
+if opt.name:
+    if cli:
+        cli.update_ref(refname, commit, oldref)
+    else:
+        git.update_ref(refname, commit, oldref)
+
+if cli:
+    cli.close()
+
 secs = time.time() - start_time
 size = hashsplit.total_split
 if opt.bench:
     log('\nbup: %.2fkbytes in %.2f secs = %.2f kbytes/sec\n'
         % (size/1024., secs, size/1024./secs))
-
-git.flush_pack()