##// END OF EJS Templates
subrepo: return both mapping directions from gitbranchmap
Eric Eisner -
r13086:8db85e39 default
parent child Browse files
Show More
@@ -670,12 +670,15 b' class gitsubrepo(object):'
670 670 return base == r1
671 671
672 672 def _gitbranchmap(self):
673 'returns the current branch and a map from git revision to branch[es]'
674 bm = {}
675 redirects = {}
673 '''returns 3 things:
674 the current branch,
675 a map from git branch to revision
676 a map from revision to branches'''
677 branch2rev = {}
678 rev2branch = {}
676 679 current = None
677 680 out = self._gitcommand(['branch', '-a', '--no-color',
678 '--verbose', '--abbrev=40'])
681 '--verbose', '--no-abbrev'])
679 682 for line in out.split('\n'):
680 683 if line[2:].startswith('(no branch)'):
681 684 continue
@@ -684,8 +687,9 b' class gitsubrepo(object):'
684 687 continue # ignore remote/HEAD redirects
685 688 if line[0] == '*':
686 689 current = branch
687 bm.setdefault(revision, []).append(branch)
688 return current, bm
690 branch2rev[branch] = revision
691 rev2branch.setdefault(revision, []).append(branch)
692 return current, branch2rev, rev2branch
689 693
690 694 def _fetch(self, source, revision):
691 695 if not os.path.exists('%s/.git' % self._path):
@@ -719,8 +723,8 b' class gitsubrepo(object):'
719 723 return
720 724 elif self._gitstate() == revision:
721 725 return
722 current, bm = self._gitbranchmap()
723 if revision not in bm:
726 current, branch2rev, rev2branch = self._gitbranchmap()
727 if revision not in rev2branch:
724 728 # no branch to checkout, check it out with no branch
725 729 self._ui.warn(_('checking out detached HEAD in subrepo %s\n') %
726 730 self._relpath)
@@ -728,7 +732,7 b' class gitsubrepo(object):'
728 732 'to make changes\n'))
729 733 self._gitcommand(['checkout', '-q', revision])
730 734 return
731 branches = bm[revision]
735 branches = rev2branch[revision]
732 736 firstlocalbranch = None
733 737 for b in branches:
734 738 if b == 'master':
@@ -768,12 +772,11 b' class gitsubrepo(object):'
768 772
769 773 def push(self, force):
770 774 # if a branch in origin contains the revision, nothing to do
771 current, bm = self._gitbranchmap()
772 for revision, branches in bm.iteritems():
773 for b in branches:
774 if b.startswith('remotes/origin'):
775 if self._gitisancestor(self._state[1], revision):
776 return True
775 current, branch2rev, rev2branch = self._gitbranchmap()
776 for b, revision in branch2rev.iteritems():
777 if b.startswith('remotes/origin'):
778 if self._gitisancestor(self._state[1], revision):
779 return True
777 780 # otherwise, try to push the currently checked out branch
778 781 cmd = ['push']
779 782 if force:
General Comments 0
You need to be logged in to leave comments. Login now