summaryrefslogtreecommitdiffstats
path: root/project.py
diff options
context:
space:
mode:
authorShawn O. Pearce <sop@google.com>2009-04-17 18:49:50 -0700
committerShawn O. Pearce <sop@google.com>2009-04-17 21:03:41 -0700
commitd237b698652120f4d859b6f9e12e3aa15aa7b2d5 (patch)
tree007a9736befbfaadfe022fbd99c0ab3d1ced0f3f /project.py
parent5b23f24881505ae77bf7a43d66663a7f2968b3c1 (diff)
downloadgit-repo-d237b698652120f4d859b6f9e12e3aa15aa7b2d5.tar.gz
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 <sop@google.com>
Diffstat (limited to 'project.py')
-rw-r--r--project.py30
1 files changed, 4 insertions, 26 deletions
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
28from error import ManifestInvalidRevisionError 28from error import ManifestInvalidRevisionError
29from remote import Remote 29from remote import Remote
30 30
31HEAD = 'HEAD' 31from git_refs import GitRefs, HEAD, R_HEADS, R_TAGS, R_PUB, R_M
32R_HEADS = 'refs/heads/'
33R_TAGS = 'refs/tags/'
34R_PUB = 'refs/published/'
35R_M = 'refs/remotes/m/'
36 32
37def _error(fmt, *args): 33def _error(fmt, *args):
38 msg = fmt % args 34 msg = fmt % args
@@ -226,6 +222,7 @@ class Project(object):
226 else: 222 else:
227 self.work_git = None 223 self.work_git = None
228 self.bare_git = self._GitGetByExec(self, bare=True) 224 self.bare_git = self._GitGetByExec(self, bare=True)
225 self.bare_ref = GitRefs(gitdir)
229 226
230 @property 227 @property
231 def Exists(self): 228 def Exists(self):
@@ -301,7 +298,7 @@ class Project(object):
301 """Get all existing local branches. 298 """Get all existing local branches.
302 """ 299 """
303 current = self.CurrentBranch 300 current = self.CurrentBranch
304 all = self.bare_git.ListRefs() 301 all = self._allrefs
305 heads = {} 302 heads = {}
306 pubd = {} 303 pubd = {}
307 304
@@ -1030,32 +1027,13 @@ class Project(object):
1030 1027
1031 @property 1028 @property
1032 def _allrefs(self): 1029 def _allrefs(self):
1033 return self.bare_git.ListRefs() 1030 return self.bare_ref.all
1034 1031
1035 class _GitGetByExec(object): 1032 class _GitGetByExec(object):
1036 def __init__(self, project, bare): 1033 def __init__(self, project, bare):
1037 self._project = project 1034 self._project = project
1038 self._bare = bare 1035 self._bare = bare
1039 1036
1040 def ListRefs(self, *args):
1041 cmdv = ['for-each-ref', '--format=%(objectname) %(refname)']
1042 cmdv.extend(args)
1043 p = GitCommand(self._project,
1044 cmdv,
1045 bare = self._bare,
1046 capture_stdout = True,
1047 capture_stderr = True)
1048 r = {}
1049 for line in p.process.stdout:
1050 id, name = line[:-1].split(' ', 2)
1051 r[name] = id
1052 if p.Wait() != 0:
1053 raise GitError('%s for-each-ref %s: %s' % (
1054 self._project.name,
1055 str(args),
1056 p.stderr))
1057 return r
1058
1059 def LsOthers(self): 1037 def LsOthers(self):
1060 p = GitCommand(self._project, 1038 p = GitCommand(self._project,
1061 ['ls-files', 1039 ['ls-files',