comparison mercurial/exchange.py @ 22654:02e0a574bcd3

pull: move bookmark pulling into its own function This requires adding an attribute on the pulloperation object. The bookmark pulling is protected behind a "todostep" as other steps of pull.
author Pierre-Yves David <pierre-yves.david@fb.com>
date Sat, 27 Sep 2014 01:31:15 -0700
parents d94f5bec9c8e
children f48ac29c2a9e
comparison
equal deleted inserted replaced
22653:d94f5bec9c8e 22654:02e0a574bcd3
775 775
776 A new should be created at the beginning of each pull and discarded 776 A new should be created at the beginning of each pull and discarded
777 afterward. 777 afterward.
778 """ 778 """
779 779
780 def __init__(self, repo, remote, heads=None, force=False): 780 def __init__(self, repo, remote, heads=None, force=False, bookmarks=()):
781 # repo we pull into 781 # repo we pull into
782 self.repo = repo 782 self.repo = repo
783 # repo we pull from 783 # repo we pull from
784 self.remote = remote 784 self.remote = remote
785 # revision we try to pull (None is "all") 785 # revision we try to pull (None is "all")
786 self.heads = heads 786 self.heads = heads
787 # bookmark pulled explicitly
788 self.explicitbookmarks = bookmarks
787 # do we force pull? 789 # do we force pull?
788 self.force = force 790 self.force = force
789 # the name the pull transaction 791 # the name the pull transaction
790 self._trname = 'pull\n' + util.hidepassword(remote.url()) 792 self._trname = 'pull\n' + util.hidepassword(remote.url())
791 # hold the transaction once created 793 # hold the transaction once created
794 self.common = None 796 self.common = None
795 # set of pulled head 797 # set of pulled head
796 self.rheads = None 798 self.rheads = None
797 # list of missing changeset to fetch remotely 799 # list of missing changeset to fetch remotely
798 self.fetch = None 800 self.fetch = None
801 # remote bookmarks data
802 self.remotebookmarks = None
799 # result of changegroup pulling (used as return code by pull) 803 # result of changegroup pulling (used as return code by pull)
800 self.cgresult = None 804 self.cgresult = None
801 # list of step remaining todo (related to future bundle2 usage) 805 # list of step remaining todo (related to future bundle2 usage)
802 self.todosteps = set(['changegroup', 'phases', 'obsmarkers']) 806 self.todosteps = set(['changegroup', 'phases', 'obsmarkers',
807 'bookmarks'])
803 808
804 @util.propertycache 809 @util.propertycache
805 def pulledsubset(self): 810 def pulledsubset(self):
806 """heads of the set of changeset target by the pull""" 811 """heads of the set of changeset target by the pull"""
807 # compute target subset 812 # compute target subset
834 """release transaction if created""" 839 """release transaction if created"""
835 if self._tr is not None: 840 if self._tr is not None:
836 self._tr.release() 841 self._tr.release()
837 842
838 def pull(repo, remote, heads=None, force=False, bookmarks=()): 843 def pull(repo, remote, heads=None, force=False, bookmarks=()):
839 pullop = pulloperation(repo, remote, heads, force) 844 pullop = pulloperation(repo, remote, heads, force, bookmarks=bookmarks)
840 if pullop.remote.local(): 845 if pullop.remote.local():
841 missing = set(pullop.remote.requirements) - pullop.repo.supported 846 missing = set(pullop.remote.requirements) - pullop.repo.supported
842 if missing: 847 if missing:
843 msg = _("required features are not" 848 msg = _("required features are not"
844 " supported in the destination:" 849 " supported in the destination:"
845 " %s") % (', '.join(sorted(missing))) 850 " %s") % (', '.join(sorted(missing)))
846 raise util.Abort(msg) 851 raise util.Abort(msg)
847 852
848 remotebookmarks = remote.listkeys('bookmarks') 853 pullop.remotebookmarks = remote.listkeys('bookmarks')
849 lock = pullop.repo.lock() 854 lock = pullop.repo.lock()
850 try: 855 try:
851 _pulldiscovery(pullop) 856 _pulldiscovery(pullop)
852 if (pullop.repo.ui.configbool('experimental', 'bundle2-exp', False) 857 if (pullop.repo.ui.configbool('experimental', 'bundle2-exp', False)
853 and pullop.remote.capable('bundle2-exp')): 858 and pullop.remote.capable('bundle2-exp')):
854 _pullbundle2(pullop) 859 _pullbundle2(pullop)
855 _pullchangeset(pullop) 860 _pullchangeset(pullop)
856 _pullphase(pullop) 861 _pullphase(pullop)
857 _pullobsolete(pullop) 862 _pullobsolete(pullop)
863 _pullbookmarks(pullop)
858 pullop.closetransaction() 864 pullop.closetransaction()
859 finally: 865 finally:
860 pullop.releasetransaction() 866 pullop.releasetransaction()
861 lock.release() 867 lock.release()
862 bookmod.updatefromremote(repo.ui, repo, remotebookmarks, remote.url())
863 # update specified bookmarks
864 if bookmarks:
865 marks = repo._bookmarks
866 writer = repo.ui.status
867 if repo.ui.configbool('ui', 'quietbookmarkmove', False):
868 writer = repo.ui.debug
869 for b in bookmarks:
870 # explicit pull overrides local bookmark if any
871 writer(_("importing bookmark %s\n") % b)
872 marks[b] = repo[remotebookmarks[b]].node()
873 marks.write()
874 868
875 return pullop.cgresult 869 return pullop.cgresult
876 870
877 def _pulldiscovery(pullop): 871 def _pulldiscovery(pullop):
878 """discovery phase for the pull 872 """discovery phase for the pull
1003 # exclude changesets already draft locally and update the others 997 # exclude changesets already draft locally and update the others
1004 dheads = [pn for pn in dheads if phase(unfi, rev(pn)) > draft] 998 dheads = [pn for pn in dheads if phase(unfi, rev(pn)) > draft]
1005 if dheads: 999 if dheads:
1006 tr = pullop.gettransaction() 1000 tr = pullop.gettransaction()
1007 phases.advanceboundary(pullop.repo, tr, draft, dheads) 1001 phases.advanceboundary(pullop.repo, tr, draft, dheads)
1002
1003 def _pullbookmarks(pullop):
1004 """process the remote bookmark information to update the local one"""
1005 if 'bookmarks' not in pullop.todosteps:
1006 return
1007 pullop.todosteps.remove('bookmarks')
1008 repo = pullop.repo
1009 remotebookmarks = pullop.remotebookmarks
1010 bookmod.updatefromremote(repo.ui, repo, remotebookmarks,
1011 pullop.remote.url())
1012 # update specified bookmarks
1013 if pullop.explicitbookmarks:
1014 marks = repo._bookmarks
1015 writer = repo.ui.status
1016 if repo.ui.configbool('ui', 'quietbookmarkmove', False):
1017 writer = repo.ui.debug
1018 for b in pullop.explicitbookmarks:
1019 # explicit pull overrides local bookmark if any
1020 writer(_("importing bookmark %s\n") % b)
1021 marks[b] = repo[remotebookmarks[b]].node()
1022 marks.write()
1008 1023
1009 def _pullobsolete(pullop): 1024 def _pullobsolete(pullop):
1010 """utility function to pull obsolete markers from a remote 1025 """utility function to pull obsolete markers from a remote
1011 1026
1012 The `gettransaction` is function that return the pull transaction, creating 1027 The `gettransaction` is function that return the pull transaction, creating