From d237b698652120f4d859b6f9e12e3aa15aa7b2d5 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Fri, 17 Apr 2009 18:49:50 -0700 Subject: Implement git ref reading purely in Python Its much faster to read the refs from 114 projects when the reader is pure Python and just doing file IO than forking 114 git commands and parsing their output. The reader caches refs based upon file mtimes. If any single ref file has been modified since the last read, we re-read the entire repository's ref namespace. This simplifies the code as we don't need to worry about shooting down symbolic-refs, but it may cause more IO than is necessary if only one ref gets updated. This change drops `repo branches` in Android from 1.658s to 0.206s. Likewise, `repo sync` improves dramatically as well. Signed-off-by: Shawn O. Pearce --- project.py | 30 ++++-------------------------- 1 file changed, 4 insertions(+), 26 deletions(-) (limited to 'project.py') diff --git a/project.py b/project.py index 311379ca..086f0d77 100644 --- a/project.py +++ b/project.py @@ -28,11 +28,7 @@ from error import GitError, ImportError, UploadError from error import ManifestInvalidRevisionError from remote import Remote -HEAD = 'HEAD' -R_HEADS = 'refs/heads/' -R_TAGS = 'refs/tags/' -R_PUB = 'refs/published/' -R_M = 'refs/remotes/m/' +from git_refs import GitRefs, HEAD, R_HEADS, R_TAGS, R_PUB, R_M def _error(fmt, *args): msg = fmt % args @@ -226,6 +222,7 @@ class Project(object): else: self.work_git = None self.bare_git = self._GitGetByExec(self, bare=True) + self.bare_ref = GitRefs(gitdir) @property def Exists(self): @@ -301,7 +298,7 @@ class Project(object): """Get all existing local branches. """ current = self.CurrentBranch - all = self.bare_git.ListRefs() + all = self._allrefs heads = {} pubd = {} @@ -1030,32 +1027,13 @@ class Project(object): @property def _allrefs(self): - return self.bare_git.ListRefs() + return self.bare_ref.all class _GitGetByExec(object): def __init__(self, project, bare): self._project = project self._bare = bare - def ListRefs(self, *args): - cmdv = ['for-each-ref', '--format=%(objectname) %(refname)'] - cmdv.extend(args) - p = GitCommand(self._project, - cmdv, - bare = self._bare, - capture_stdout = True, - capture_stderr = True) - r = {} - for line in p.process.stdout: - id, name = line[:-1].split(' ', 2) - r[name] = id - if p.Wait() != 0: - raise GitError('%s for-each-ref %s: %s' % ( - self._project.name, - str(args), - p.stderr)) - return r - def LsOthers(self): p = GitCommand(self._project, ['ls-files', -- cgit v1.2.3-54-g00ecf