]> arthur.barton.de Git - bup.git/blobdiff - cmd-split.py
'bup split' takes a list of filenames on the command line.
[bup.git] / cmd-split.py
index 5a2f9670ecde373b7a4326f269823a18e8babeea..e755efec45338d73b7f88fdcbe9321ab1f694a30 100755 (executable)
@@ -52,7 +52,7 @@ def hashsplit_iter(f):
     lv = 0
     while blob or not eof:
         if not eof and (buf.used() < BLOB_LWM or not blob):
-            bnew = sys.stdin.read(BLOB_HWM)
+            bnew = f.read(BLOB_HWM)
             if not len(bnew): eof = 1
             #log('got %d, total %d\n' % (len(bnew), buf.used()))
             buf.put(bnew)
@@ -74,34 +74,51 @@ def hashsplit_iter(f):
             log('%d\t' % nv)
             lv = nv
 
+
+def autofiles(filenames):
+    if not filenames:
+        yield sys.stdin
+    else:
+        for n in filenames:
+            yield open(n)
+
+
 optspec = """
-bup split [-t] <filename
+bup split [-t] [filenames...]
 --
-t,tree     output a tree instead of a series of blobs
-c,commit   output a commit instead of a tree or blobs
+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)
 bench      print benchmark timings to stderr
 """
-(opt, flags, extra) = options.Options('bup split', optspec).parse(sys.argv[1:])
+o = options.Options('bup split', optspec)
+(opt, flags, extra) = o.parse(sys.argv[1:])
+
+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()
 
 start_time = time.time()
 shalist = []
 
 ofs = 0
-for (ofs, size, sha) in hashsplit_iter(sys.stdin):
-    #log('SPLIT @ %-8d size=%-8d\n' % (ofs, size))
-    if not opt.tree and not opt.commit:
-        print sha
-    shalist.append(('100644', '%016x.bupchunk' % ofs, sha))
-if opt.tree or opt.commit:
-    tree = git.gen_tree(shalist)
-if opt.commit:
+
+for f in autofiles(extra):
+    for (ofs, size, sha) in hashsplit_iter(f):
+        #log('SPLIT @ %-8d size=%-8d\n' % (ofs, size))
+        if opt.blobs:
+            print sha
+        shalist.append(('100644', '%016x.bupchunk' % ofs, sha))
+tree = git.gen_tree(shalist)
+if opt.tree:
+    print tree
+if opt.commit or opt.name:
     msg = 'Generated 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)
-    print commit
-elif opt.tree:
-    print tree
+    if opt.commit:
+        print commit
 
 secs = time.time() - start_time
 if opt.bench: