]> arthur.barton.de Git - bup.git/commitdiff
Adds a date option to save, split and bup.git.PackWriter._new_commit()
authorZoran Zaric <zz@zoranzaric.de>
Wed, 8 Sep 2010 20:11:36 +0000 (22:11 +0200)
committerAvery Pennarun <apenwarr@gmail.com>
Wed, 8 Sep 2010 21:16:08 +0000 (14:16 -0700)
Signed-off-by: Zoran Zaric <zz@zoranzaric.de>
cmd/save-cmd.py
cmd/split-cmd.py
lib/bup/git.py
lib/bup/helpers.py

index cf8a613bfa270d6cad3924a794198a10164cb674..5b48afdc9079bfa0119f341cd0950c8a7cf506a0 100755 (executable)
@@ -11,6 +11,7 @@ r,remote=  hostname:/path/to/repo of remote repository
 t,tree     output a tree id
 c,commit   output a commit id
 n,name=    name of backup set to update (if any)
+d,date=    date for the commit (seconds since the epoch)
 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
@@ -30,6 +31,11 @@ opt.smaller = parse_num(opt.smaller or 0)
 if opt.bwlimit:
     client.bwlimit = parse_num(opt.bwlimit)
 
+if opt.date:
+    date = parse_date_or_fatal(opt.date, o.fatal)
+else:
+    date = time.time()
+
 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")
@@ -276,7 +282,7 @@ if opt.tree:
 if opt.commit or opt.name:
     msg = 'bup save\n\nGenerated by command:\n%r' % sys.argv
     ref = opt.name and ('refs/heads/%s' % opt.name) or None
-    commit = w.new_commit(oldref, tree, msg)
+    commit = w.new_commit(oldref, tree, date, msg)
     if opt.commit:
         print commit.encode('hex')
 
index 4bbd58e18f70be2a70c18317a733d3be7d47de40..94fba53bda7793f76ef1cdec467c5fb96059a762 100755 (executable)
@@ -12,6 +12,7 @@ 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)
+d,date=    date for the commit (seconds since the epoch)
 q,quiet    don't print progress messages
 v,verbose  increase log output (can be used more than once)
 noop       don't actually save the data anywhere
@@ -47,6 +48,11 @@ if opt.blobs:
     hashsplit.fanout = 0
 if opt.bwlimit:
     client.bwlimit = parse_num(opt.bwlimit)
+if opt.date:
+    date = parse_date_or_fatal(opt.date, o.fatal)
+else:
+    date = time.time()
+
 
 is_reverse = os.environ.get('BUP_SERVER_REVERSE')
 if is_reverse and opt.remote:
@@ -96,7 +102,7 @@ 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 = pack_writer.new_commit(oldref, tree, msg)
+    commit = pack_writer.new_commit(oldref, tree, date, msg)
     if opt.commit:
         print commit.encode('hex')
 
index af54a60d98c6a9340b69a58dcd502cf873bd1b97..66370cacc64d6e6a967fa8220752397175ac7e82 100644 (file)
@@ -554,12 +554,11 @@ class PackWriter:
         l.append(msg)
         return self.maybe_write('commit', '\n'.join(l))
 
-    def new_commit(self, parent, tree, msg):
+    def new_commit(self, parent, tree, date, msg):
         """Create a commit object in the pack."""
-        now = time.time()
         userline = '%s <%s@%s>' % (userfullname(), username(), hostname())
         commit = self._new_commit(tree, parent,
-                                  userline, now, userline, now,
+                                  userline, date, userline, date,
                                   msg)
         return commit
 
index f911b046151123c8c31d85c6b41d9dae7dd97e7e..bf431455921de2b0d558de67516e2f2201b77198 100644 (file)
@@ -16,6 +16,14 @@ def atoi(s):
         return 0
 
 
+def atof(s):
+    """Convert the string 's' to a float. Return 0 if s is not a number."""
+    try:
+        return float(s or '0')
+    except ValueError:
+        return 0
+
+
 buglvl = atoi(os.environ.get('BUP_DEBUG', 0))
 
 
@@ -388,6 +396,16 @@ def columnate(l, prefix):
         out += prefix + ''.join(('%-*s' % (clen+2, s)) for s in row) + '\n'
     return out
 
+def parse_date_or_fatal(str, fatal):
+    """Parses the given date or calls Option.fatal().
+    For now we expect a string that contains a float."""
+    try:
+        date = atof(str)
+    except ValueError, e:
+        raise fatal('invalid date format (should be a float): %r' % e)
+    else:
+        return date
+
 
 # hashlib is only available in python 2.5 or higher, but the 'sha' module
 # produces a DeprecationWarning in python 2.6 or higher.  We want to support