mirror of
https://gerrit.googlesource.com/git-repo
synced 2024-12-21 07:16:21 +00:00
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>
This commit is contained in:
parent
66bdd46871
commit
5b23f24881
15
project.py
15
project.py
@ -237,10 +237,7 @@ class Project(object):
|
|||||||
The branch name omits the 'refs/heads/' prefix.
|
The branch name omits the 'refs/heads/' prefix.
|
||||||
None is returned if the project is on a detached HEAD.
|
None is returned if the project is on a detached HEAD.
|
||||||
"""
|
"""
|
||||||
try:
|
|
||||||
b = self.work_git.GetHead()
|
b = self.work_git.GetHead()
|
||||||
except GitError:
|
|
||||||
return None
|
|
||||||
if b.startswith(R_HEADS):
|
if b.startswith(R_HEADS):
|
||||||
return b[len(R_HEADS):]
|
return b[len(R_HEADS):]
|
||||||
return None
|
return None
|
||||||
@ -817,9 +814,8 @@ class Project(object):
|
|||||||
kill.append(cb)
|
kill.append(cb)
|
||||||
|
|
||||||
if kill:
|
if kill:
|
||||||
try:
|
|
||||||
old = self.bare_git.GetHead()
|
old = self.bare_git.GetHead()
|
||||||
except GitError:
|
if old is None:
|
||||||
old = 'refs/heads/please_never_use_this_as_a_branch_name'
|
old = 'refs/heads/please_never_use_this_as_a_branch_name'
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -1125,7 +1121,14 @@ class Project(object):
|
|||||||
p.Wait()
|
p.Wait()
|
||||||
|
|
||||||
def GetHead(self):
|
def GetHead(self):
|
||||||
return self.symbolic_ref(HEAD)
|
if self._bare:
|
||||||
|
path = os.path.join(self._project.gitdir, HEAD)
|
||||||
|
else:
|
||||||
|
path = os.path.join(self._project.worktree, '.git', HEAD)
|
||||||
|
line = open(path, 'r').read()
|
||||||
|
if line.startswith('ref: '):
|
||||||
|
return line[5:-1]
|
||||||
|
return line[:-1]
|
||||||
|
|
||||||
def SetHead(self, ref, message=None):
|
def SetHead(self, ref, message=None):
|
||||||
cmdv = []
|
cmdv = []
|
||||||
|
Loading…
Reference in New Issue
Block a user