]> arthur.barton.de Git - bup.git/blobdiff - cmd/split-cmd.py
cleanup-mounts-under: Don't fail when /proc/mounts isn't readable
[bup.git] / cmd / split-cmd.py
index 3faac3375c236f8db7085c2b3a29e609418afa08..70daf7c688258b7da31c34a2bac83015c3316fac 100755 (executable)
@@ -1,5 +1,5 @@
 #!/usr/bin/env python
-import sys, time
+import os, sys, time
 from bup import hashsplit, git, options, client
 from bup.helpers import *
 
@@ -86,9 +86,9 @@ refname = opt.name and 'refs/heads/%s' % opt.name or None
 if opt.noop or opt.copy:
     cli = pack_writer = oldref = None
 elif opt.remote or is_reverse:
-    cli = client.Client(opt.remote, compression_level=opt.compress)
+    cli = client.Client(opt.remote)
     oldref = refname and cli.read_ref(refname) or None
-    pack_writer = cli.new_packwriter()
+    pack_writer = cli.new_packwriter(compression_level=opt.compress)
 else:
     cli = None
     oldref = refname and git.read_ref(refname) or None
@@ -108,7 +108,7 @@ if opt.git_ids:
         def __init__(self, it):
             self.it = iter(it)
         def read(self, size):
-            v = next(self.it)
+            v = next(self.it, None)
             return v or ''
     def read_ids():
         while 1:
@@ -119,7 +119,7 @@ if opt.git_ids:
                 line = line.strip()
             try:
                 it = cp.get(line.strip())
-                next(it)  # skip the file type
+                next(it, None)  # skip the file type
             except KeyError, e:
                 add_error('error: %s' % e)
                 continue
@@ -137,11 +137,19 @@ if pack_writer and opt.blobs:
         print sha.encode('hex')
         reprogress()
 elif pack_writer:  # tree or commit or name
-    shalist = hashsplit.split_to_shalist(pack_writer.new_blob,
-                                         pack_writer.new_tree,
-                                         files,
-                                         keep_boundaries=opt.keep_boundaries,
-                                         progress=prog)
+    if opt.name: # insert dummy_name which may be used as a restore target
+        mode, sha = \
+            hashsplit.split_to_blob_or_tree(pack_writer.new_blob,
+                                            pack_writer.new_tree,
+                                            files,
+                                            keep_boundaries=opt.keep_boundaries,
+                                            progress=prog)
+        splitfile_name = git.mangle_name('data', hashsplit.GIT_MODE_FILE, mode)
+        shalist = [(mode, splitfile_name, sha)]
+    else:
+        shalist = hashsplit.split_to_shalist(
+                      pack_writer.new_blob, pack_writer.new_tree, files,
+                      keep_boundaries=opt.keep_boundaries, progress=prog)
     tree = pack_writer.new_tree(shalist)
 else:
     last = 0
@@ -161,7 +169,7 @@ if opt.verbose:
 if opt.tree:
     print tree.encode('hex')
 if opt.commit or opt.name:
-    msg = 'bup split\n\nGenerated by command:\n%r' % sys.argv
+    msg = 'bup split\n\nGenerated by command:\n%r\n' % sys.argv
     ref = opt.name and ('refs/heads/%s' % opt.name) or None
     commit = pack_writer.new_commit(oldref, tree, date, msg)
     if opt.commit: