]> arthur.barton.de Git - bup.git/blobdiff - cmd/save-cmd.py
Adds -f option to save to use a given indexfile.
[bup.git] / cmd / save-cmd.py
index 5eaa5d969a72c2cd24a862df33dd762deca9891a..d278e70727a1b07e7b18b8a755a8d5378854325f 100755 (executable)
@@ -16,6 +16,9 @@ v,verbose  increase log output (can be used more than once)
 q,quiet    don't show progress meter
 smaller=   only back up files smaller than n bytes
 bwlimit=   maximum bytes/sec to transmit to server
+f,indexfile=  the name of the index file (normally BUP_DIR/bupindex)
+strip      strips the path to every filename given
+strip-path= path-prefix to be stripped when saving
 """
 o = options.Options('bup save', optspec)
 (opt, flags, extra) = o.parse(sys.argv[1:])
@@ -36,18 +39,16 @@ if opt.date:
 else:
     date = time.time()
 
+if opt.strip and opt.strip_path:
+    o.fatal("--strip is incompatible with --strip-path")
+
 is_reverse = os.environ.get('BUP_SERVER_REVERSE')
 if is_reverse and opt.remote:
     o.fatal("don't use -r in reverse mode; it's automatic")
 
 refname = opt.name and 'refs/heads/%s' % opt.name or None
 if opt.remote or is_reverse:
-    if opt.remote and opt.remote.find(":") == -1:
-        o.fatal("--remote argument must contain a colon")
-    try:
-        cli = client.Client(opt.remote)
-    except client.ClientError:
-        o.fatal("server exited unexpectedly; see errors above")
+    cli = client.Client(opt.remote)
     oldref = refname and cli.read_ref(refname) or None
     w = cli.new_packwriter()
 else:
@@ -134,7 +135,9 @@ def vlog(s):
     log(s)
 
 
-r = index.Reader(git.repo('bupindex'))
+indexfile = opt.indexfile or git.repo('bupindex')
+print indexfile
+r = index.Reader(indexfile)
 
 def already_saved(ent):
     return ent.is_valid() and w.exists(ent.sha) and ent.sha
@@ -200,7 +203,13 @@ for (transname,ent) in r.filter(extra, wantrecurse=wantrecurse_during):
         continue
 
     assert(dir.startswith('/'))
-    dirp = dir.split('/')
+    if opt.strip:
+        stripped_base_path = strip_base_path(dir, extra)
+        dirp = stripped_base_path.split('/')
+    elif opt.strip_path:
+        dirp = strip_path(opt.strip_path, dir).split('/')
+    else:
+        dirp = dir.split('/')
     while parts > dirp:
         _pop(force_tree = None)
     if dir != '/':
@@ -241,7 +250,12 @@ for (transname,ent) in r.filter(extra, wantrecurse=wantrecurse_during):
                 add_error(e)
                 lastskip_name = ent.name
             else:
-                (mode, id) = hashsplit.split_to_blob_or_tree(w, [f])
+                try:
+                    (mode, id) = hashsplit.split_to_blob_or_tree(w, [f],
+                                            keep_boundaries=False)
+                except IOError, e:
+                    add_error('%s: %s' % (ent.name, e))
+                    lastskip_name = ent.name
         else:
             if stat.S_ISDIR(ent.mode):
                 assert(0)  # handled above