summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShawn O. Pearce <sop@google.com>2009-04-17 18:43:33 -0700
committerShawn O. Pearce <sop@google.com>2009-04-17 20:59:44 -0700
commit5b23f24881505ae77bf7a43d66663a7f2968b3c1 (patch)
tree5e543f57d62b99b677eada896c03e63e5143083b
parent66bdd468717a6f52056924837b766cf60889f2ed (diff)
downloadgit-repo-5b23f24881505ae77bf7a43d66663a7f2968b3c1.tar.gz
Implement 'git symbolic-ref HEAD' in Python
This is invoked once per project in `repo sync`. Taking it out saves about 1/114 of a second, so on a large set of projects like Android it can save up to a full second of sync time. Signed-off-by: Shawn O. Pearce <sop@google.com>
-rw-r--r--project.py19
1 files changed, 11 insertions, 8 deletions
diff --git a/project.py b/project.py
index b19ab5fb..311379ca 100644
--- a/project.py
+++ b/project.py
@@ -237,10 +237,7 @@ class Project(object):
237 The branch name omits the 'refs/heads/' prefix. 237 The branch name omits the 'refs/heads/' prefix.
238 None is returned if the project is on a detached HEAD. 238 None is returned if the project is on a detached HEAD.
239 """ 239 """
240 try: 240 b = self.work_git.GetHead()
241 b = self.work_git.GetHead()
242 except GitError:
243 return None
244 if b.startswith(R_HEADS): 241 if b.startswith(R_HEADS):
245 return b[len(R_HEADS):] 242 return b[len(R_HEADS):]
246 return None 243 return None
@@ -817,9 +814,8 @@ class Project(object):
817 kill.append(cb) 814 kill.append(cb)
818 815
819 if kill: 816 if kill:
820 try: 817 old = self.bare_git.GetHead()
821 old = self.bare_git.GetHead() 818 if old is None:
822 except GitError:
823 old = 'refs/heads/please_never_use_this_as_a_branch_name' 819 old = 'refs/heads/please_never_use_this_as_a_branch_name'
824 820
825 try: 821 try:
@@ -1125,7 +1121,14 @@ class Project(object):
1125 p.Wait() 1121 p.Wait()
1126 1122
1127 def GetHead(self): 1123 def GetHead(self):
1128 return self.symbolic_ref(HEAD) 1124 if self._bare:
1125 path = os.path.join(self._project.gitdir, HEAD)
1126 else:
1127 path = os.path.join(self._project.worktree, '.git', HEAD)
1128 line = open(path, 'r').read()
1129 if line.startswith('ref: '):
1130 return line[5:-1]
1131 return line[:-1]
1129 1132
1130 def SetHead(self, ref, message=None): 1133 def SetHead(self, ref, message=None):
1131 cmdv = [] 1134 cmdv = []