]> arthur.barton.de Git - bup.git/blobdiff - cmd/prune-older-cmd.py
LocalRepo.__init__: use correct dir everywhere
[bup.git] / cmd / prune-older-cmd.py
index f2ba1d18b661b90dc9525e5bd30705b586483168..6c67b69bfc72e1e717d6abfa6c5cd1aea3b12c66 100755 (executable)
@@ -5,7 +5,7 @@ exec "$bup_python" "$0" ${1+"$@"}
 """
 # end of bup preamble
 
-from __future__ import print_function
+from __future__ import absolute_import, print_function
 from collections import defaultdict
 from itertools import groupby
 from sys import stderr
@@ -15,12 +15,13 @@ import re, sys
 from bup import git, options
 from bup.gc import bup_gc
 from bup.helpers import die_if_errors, log, partition, period_as_secs
+from bup.repo import LocalRepo
 from bup.rm import bup_rm
 
 
 def branches(refnames=()):
-    return ((name[11:], sha) for (name,sha)
-            in git.list_refs(refnames=('refs/heads/' + n for n in refnames),
+    return ((name[11:], sha.encode('hex')) for (name,sha)
+            in git.list_refs(patterns=('refs/heads/' + n for n in refnames),
                              limit_to_heads=True))
 
 def save_name(branch, utc):
@@ -130,10 +131,15 @@ git.check_repo_or_die()
 # This could be more efficient, but for now just build the whole list
 # in memory and let bup_rm() do some redundant work.
 
+def parse_info(f):
+    author_secs = f.readline().strip()
+    return int(author_secs)
+
 removals = []
 for branch, branch_id in branches(roots):
     die_if_errors()
-    saves = git.rev_list(branch_id.encode('hex'))
+    saves = ((utc, oidx.decode('hex')) for (oidx, utc) in
+             git.rev_list(branch_id, format='%at', parse=parse_info))
     for keep_save, (utc, id) in classify_saves(saves, period_start):
         assert(keep_save in (False, True))
         # FIXME: base removals on hashes
@@ -144,7 +150,8 @@ for branch, branch_id in branches(roots):
 
 if not opt.pretend:
     die_if_errors()
-    bup_rm(removals, compression=opt.compress, verbosity=opt.verbose)
+    repo = LocalRepo()
+    bup_rm(repo, removals, compression=opt.compress, verbosity=opt.verbose)
     if opt.gc:
         die_if_errors()
         bup_gc(threshold=opt.gc_threshold,