From 00ba9fb811e71bb6182b9379461bc6b493e3b7a4 Mon Sep 17 00:00:00 2001 From: Rob Browning Date: Thu, 8 May 2014 14:01:57 -0500 Subject: [PATCH] Retrieve the dates for all branches with one bulk git call in the VFS. 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 --- lib/bup/git.py | 12 +++++++----- lib/bup/vfs.py | 19 +++++++++++-------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/lib/bup/git.py b/lib/bup/git.py index 623a1ed..2552c45 100644 --- a/lib/bup/git.py +++ b/lib/bup/git.py @@ -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): diff --git a/lib/bup/vfs.py b/lib/bup/vfs.py index 07c5e37..301d145 100644 --- a/lib/bup/vfs.py +++ b/lib/bup/vfs.py @@ -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 -- 2.39.2