##// END OF EJS Templates
subrepo: backout 519ac79d680b...
Eric Eisner -
r13178:c4d857f5 default
parent child Browse files
Show More
@@ -678,27 +678,37 b' class gitsubrepo(abstractsubrepo):'
678 return base == r1
678 return base == r1
679
679
680 def _gitbranchmap(self):
680 def _gitbranchmap(self):
681 '''returns 3 things:
681 '''returns 2 things:
682 a map from git branch to revision
682 a map from git branch to revision
683 a map from revision to branches
683 a map from revision to branches'''
684 a map from remote branch to local tracking branch'''
685 branch2rev = {}
684 branch2rev = {}
686 rev2branch = {}
685 rev2branch = {}
687 tracking = {}
686
688 out = self._gitcommand(['for-each-ref', '--format',
687 out = self._gitcommand(['for-each-ref', '--format',
689 '%(objectname) %(refname) %(upstream) end'])
688 '%(objectname) %(refname)'])
690 for line in out.split('\n'):
689 for line in out.split('\n'):
691 revision, ref, upstream = line.split(' ')[:3]
690 revision, ref = line.split(' ')
692 if ref.startswith('refs/tags/'):
691 if ref.startswith('refs/tags/'):
693 continue
692 continue
694 if ref.startswith('refs/remotes/') and ref.endswith('/HEAD'):
693 if ref.startswith('refs/remotes/') and ref.endswith('/HEAD'):
695 continue # ignore remote/HEAD redirects
694 continue # ignore remote/HEAD redirects
696 branch2rev[ref] = revision
695 branch2rev[ref] = revision
697 rev2branch.setdefault(revision, []).append(ref)
696 rev2branch.setdefault(revision, []).append(ref)
698 if upstream:
697 return branch2rev, rev2branch
699 # assumes no more than one local tracking branch for a remote
698
700 tracking[upstream] = ref
699 def _gittracking(self, branches):
701 return branch2rev, rev2branch, tracking
700 'return map of remote branch to local tracking branch'
701 # assumes no more than one local tracking branch for each remote
702 tracking = {}
703 for b in branches:
704 if b.startswith('refs/remotes/'):
705 continue
706 remote = self._gitcommand(['config', 'branch.%s.remote' % b])
707 if remote:
708 ref = self._gitcommand(['config', 'branch.%s.merge' % b])
709 tracking['refs/remotes/%s/%s' %
710 (remote, ref.split('/', 2)[2])] = b
711 return tracking
702
712
703 def _fetch(self, source, revision):
713 def _fetch(self, source, revision):
704 if not os.path.exists('%s/.git' % self._path):
714 if not os.path.exists('%s/.git' % self._path):
@@ -735,7 +745,7 b' class gitsubrepo(abstractsubrepo):'
735 return
745 return
736 elif self._gitstate() == revision:
746 elif self._gitstate() == revision:
737 return
747 return
738 branch2rev, rev2branch, tracking = self._gitbranchmap()
748 branch2rev, rev2branch = self._gitbranchmap()
739
749
740 def rawcheckout():
750 def rawcheckout():
741 # no branch to checkout, check it out with no branch
751 # no branch to checkout, check it out with no branch
@@ -761,6 +771,7 b' class gitsubrepo(abstractsubrepo):'
761 self._gitcommand(['checkout', firstlocalbranch])
771 self._gitcommand(['checkout', firstlocalbranch])
762 return
772 return
763
773
774 tracking = self._gittracking(branch2rev.keys())
764 # choose a remote branch already tracked if possible
775 # choose a remote branch already tracked if possible
765 remote = branches[0]
776 remote = branches[0]
766 if remote not in tracking:
777 if remote not in tracking:
@@ -813,7 +824,7 b' class gitsubrepo(abstractsubrepo):'
813
824
814 def push(self, force):
825 def push(self, force):
815 # if a branch in origin contains the revision, nothing to do
826 # if a branch in origin contains the revision, nothing to do
816 branch2rev, rev2branch, tracking = self._gitbranchmap()
827 branch2rev, rev2branch = self._gitbranchmap()
817 if self._state[1] in rev2branch:
828 if self._state[1] in rev2branch:
818 for b in rev2branch[self._state[1]]:
829 for b in rev2branch[self._state[1]]:
819 if b.startswith('refs/remotes/origin/'):
830 if b.startswith('refs/remotes/origin/'):
General Comments 0
You need to be logged in to leave comments. Login now