[PATCH 3 of 4] subrepo: defer determination of git's current branch
Eric Eisner
ede at MIT.EDU
Tue Dec 14 21:07:26 CST 2010
# HG changeset patch
# User Eric Eisner <ede at mit.edu>
# Date 1292381803 18000
# Node ID 2fe9343bf03801cdb3c3f272f133263f7f23da00
# Parent 41862342ad1501aaccd2e84707e204310279f411
subrepo: defer determination of git's current branch
diff --git a/mercurial/subrepo.py b/mercurial/subrepo.py
--- a/mercurial/subrepo.py
+++ b/mercurial/subrepo.py
@@ -652,6 +652,12 @@ class gitsubrepo(abstractsubrepo):
def _gitstate(self):
return self._gitcommand(['rev-parse', 'HEAD'])
+ def _gitcurrentbranch(self):
+ current, err = self._gitdir(['symbolic-ref', 'HEAD', '--quiet'])
+ if err:
+ current = None
+ return current
+
def _githavelocally(self, revision):
out, code = self._gitdir(['cat-file', '-e', revision])
return code == 0
@@ -662,16 +668,12 @@ class gitsubrepo(abstractsubrepo):
def _gitbranchmap(self):
'''returns 3 things:
- the current branch,
a map from git branch to revision
- a map from revision to branches'''
+ a map from revision to branches
+ a map from remote branch to local tracking branch'''
branch2rev = {}
rev2branch = {}
tracking = {}
- current, err = self._gitdir(['symbolic-ref', 'HEAD', '--quiet'])
- if err:
- current = None
-
out = self._gitcommand(['for-each-ref', '--format',
'%(objectname) %(refname) %(upstream) end'])
for line in out.split('\n'):
@@ -685,7 +687,7 @@ class gitsubrepo(abstractsubrepo):
if upstream:
# assumes no more than one local tracking branch for a remote
tracking[upstream] = ref
- return current, branch2rev, rev2branch, tracking
+ return branch2rev, rev2branch, tracking
def _fetch(self, source, revision):
if not os.path.exists('%s/.git' % self._path):
@@ -723,7 +725,7 @@ class gitsubrepo(abstractsubrepo):
return
elif self._gitstate() == revision:
return
- current, branch2rev, rev2branch, tracking = self._gitbranchmap()
+ branch2rev, rev2branch, tracking = self._gitbranchmap()
def rawcheckout():
# no branch to checkout, check it out with no branch
@@ -768,7 +770,7 @@ class gitsubrepo(abstractsubrepo):
# which is equivalent to updating the local branch to the remote.
# Since we are only looking at branching at update, we need to
# detect this situation and perform this action lazily.
- if tracking[remote] != current:
+ if tracking[remote] != self._gitcurrentbranch():
self._gitcommand(['checkout', tracking[remote]])
self._gitcommand(['merge', '--ff', remote])
else:
@@ -801,7 +803,7 @@ class gitsubrepo(abstractsubrepo):
def push(self, force):
# if a branch in origin contains the revision, nothing to do
- current, branch2rev, rev2branch, tracking = self._gitbranchmap()
+ branch2rev, rev2branch, tracking = self._gitbranchmap()
if self._state[1] in rev2branch:
for b in rev2branch[self._state[1]]:
if b.startswith('refs/remotes/origin/'):
@@ -814,6 +816,8 @@ class gitsubrepo(abstractsubrepo):
cmd = ['push']
if force:
cmd.append('--force')
+
+ current = self._gitcurrentbranch()
if current:
# determine if the current branch is even useful
if not self._gitisancestor(self._state[1], current):
More information about the Mercurial-devel
mailing list