]> arthur.barton.de Git - bup.git/commitdiff
Retrieve the dates for all branches with one bulk git call in the VFS.
authorRob Browning <rlb@defaultvalue.org>
Thu, 8 May 2014 19:01:57 +0000 (14:01 -0500)
committerRob Browning <rlb@defaultvalue.org>
Thu, 8 May 2014 19:01:57 +0000 (14:01 -0500)
Instead of calling "git rev-list" once per branch to get the branch
tip dates for the VFS branch list, make a single call to "git show"
using a suitable pretty format, and pass all the branch refs as
arguments.

Signed-off-by: Rob Browning <rlb@defaultvalue.org>
lib/bup/git.py
lib/bup/vfs.py

index 623a1eddc6b5e87f8d7f45bd95960f005ff018be..2552c45fdcac4321b0b9f9718192b3353e4b2eb7 100644 (file)
@@ -759,11 +759,13 @@ def rev_list(ref, count=None):
         raise GitError, 'git rev-list returned error %d' % rv
 
 
-def rev_get_date(ref):
-    """Get the date of the latest commit on the specified ref."""
-    for (date, commit) in rev_list(ref, count=1):
-        return date
-    raise GitError, 'no such commit %r' % ref
+def get_commit_dates(refs):
+    """Get the dates for the specified commit refs."""
+    result = []
+    cmd = ['git', 'show', '-s', '--pretty=format:%ct']
+    for chunk in batchpipe(cmd, refs, preexec_fn=_gitenv):
+        result += chunk.splitlines()
+    return result
 
 
 def rev_parse(committish):
index 07c5e372feb35f0ceb70d83ae12b2453ddb6db50..301d14572ef6ae5e3817f3ae4d0c791b35bf56ba 100644 (file)
@@ -523,7 +523,7 @@ class TagDir(Node):
         for (name, sha) in git.list_refs():
             if name.startswith('refs/tags/'):
                 name = name[10:]
-                date = git.rev_get_date(sha.encode('hex'))
+                date = git.get_commit_dates([sha.encode('hex')])[0]
                 commithex = sha.encode('hex')
                 target = '../.commit/%s/%s' % (commithex[:2], commithex[2:])
                 tag1 = FakeSymlink(self, name, target)
@@ -590,10 +590,13 @@ class RefList(Node):
         tag_dir = TagDir(self, '.tag')
         self._subs['.tag'] = tag_dir
 
-        for (name,sha) in git.list_refs():
-            if name.startswith('refs/heads/'):
-                name = name[11:]
-                date = git.rev_get_date(sha.encode('hex'))
-                n1 = BranchList(self, name, sha)
-                n1.ctime = n1.mtime = date
-                self._subs[name] = n1
+        refs_info = [(name[11:], sha) for (name,sha) in git.list_refs() \
+                     if name.startswith('refs/heads/')]
+
+        dates = git.get_commit_dates([sha.encode('hex')
+                                      for (name, sha) in refs_info])
+
+        for (name, sha), date in zip(refs_info, dates):
+            n1 = BranchList(self, name, sha)
+            n1.ctime = n1.mtime = date
+            self._subs[name] = n1