From: Zoran Zaric Date: Wed, 8 Sep 2010 20:11:36 +0000 (+0200) Subject: Adds a date option to save, split and bup.git.PackWriter._new_commit() X-Git-Tag: bup-0.20~16 X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?p=bup.git;a=commitdiff_plain;h=91eb5521829376b4ee4e5cb872965583336d7416 Adds a date option to save, split and bup.git.PackWriter._new_commit() Signed-off-by: Zoran Zaric --- diff --git a/cmd/save-cmd.py b/cmd/save-cmd.py index cf8a613..5b48afd 100755 --- a/cmd/save-cmd.py +++ b/cmd/save-cmd.py @@ -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') diff --git a/cmd/split-cmd.py b/cmd/split-cmd.py index 4bbd58e..94fba53 100755 --- a/cmd/split-cmd.py +++ b/cmd/split-cmd.py @@ -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') diff --git a/lib/bup/git.py b/lib/bup/git.py index af54a60..66370ca 100644 --- a/lib/bup/git.py +++ b/lib/bup/git.py @@ -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 diff --git a/lib/bup/helpers.py b/lib/bup/helpers.py index f911b04..bf43145 100644 --- a/lib/bup/helpers.py +++ b/lib/bup/helpers.py @@ -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