changeset 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
files mercurial/exchange.py
diffstat 1 files changed, 31 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/exchange.py	Sat Sep 27 01:34:02 2014 -0700
+++ b/mercurial/exchange.py	Sat Sep 27 01:31:15 2014 -0700
@@ -777,13 +777,15 @@
     afterward.
     """
 
-    def __init__(self, repo, remote, heads=None, force=False):
+    def __init__(self, repo, remote, heads=None, force=False, bookmarks=()):
         # repo we pull into
         self.repo = repo
         # repo we pull from
         self.remote = remote
         # revision we try to pull (None is "all")
         self.heads = heads
+        # bookmark pulled explicitly
+        self.explicitbookmarks = bookmarks
         # do we force pull?
         self.force = force
         # the name the pull transaction
@@ -796,10 +798,13 @@
         self.rheads = None
         # list of missing changeset to fetch remotely
         self.fetch = None
+        # remote bookmarks data
+        self.remotebookmarks = None
         # result of changegroup pulling (used as return code by pull)
         self.cgresult = None
         # list of step remaining todo (related to future bundle2 usage)
-        self.todosteps = set(['changegroup', 'phases', 'obsmarkers'])
+        self.todosteps = set(['changegroup', 'phases', 'obsmarkers',
+                              'bookmarks'])
 
     @util.propertycache
     def pulledsubset(self):
@@ -836,7 +841,7 @@
             self._tr.release()
 
 def pull(repo, remote, heads=None, force=False, bookmarks=()):
-    pullop = pulloperation(repo, remote, heads, force)
+    pullop = pulloperation(repo, remote, heads, force, bookmarks=bookmarks)
     if pullop.remote.local():
         missing = set(pullop.remote.requirements) - pullop.repo.supported
         if missing:
@@ -845,7 +850,7 @@
                     " %s") % (', '.join(sorted(missing)))
             raise util.Abort(msg)
 
-    remotebookmarks = remote.listkeys('bookmarks')
+    pullop.remotebookmarks = remote.listkeys('bookmarks')
     lock = pullop.repo.lock()
     try:
         _pulldiscovery(pullop)
@@ -855,22 +860,11 @@
         _pullchangeset(pullop)
         _pullphase(pullop)
         _pullobsolete(pullop)
+        _pullbookmarks(pullop)
         pullop.closetransaction()
     finally:
         pullop.releasetransaction()
         lock.release()
-    bookmod.updatefromremote(repo.ui, repo, remotebookmarks, remote.url())
-    # update specified bookmarks
-    if bookmarks:
-        marks = repo._bookmarks
-        writer = repo.ui.status
-        if repo.ui.configbool('ui', 'quietbookmarkmove', False):
-            writer = repo.ui.debug
-        for b in bookmarks:
-            # explicit pull overrides local bookmark if any
-            writer(_("importing bookmark %s\n") % b)
-            marks[b] = repo[remotebookmarks[b]].node()
-        marks.write()
 
     return pullop.cgresult
 
@@ -1006,6 +1000,27 @@
         tr = pullop.gettransaction()
         phases.advanceboundary(pullop.repo, tr, draft, dheads)
 
+def _pullbookmarks(pullop):
+    """process the remote bookmark information to update the local one"""
+    if 'bookmarks' not in pullop.todosteps:
+        return
+    pullop.todosteps.remove('bookmarks')
+    repo = pullop.repo
+    remotebookmarks = pullop.remotebookmarks
+    bookmod.updatefromremote(repo.ui, repo, remotebookmarks,
+                             pullop.remote.url())
+    # update specified bookmarks
+    if pullop.explicitbookmarks:
+        marks = repo._bookmarks
+        writer = repo.ui.status
+        if repo.ui.configbool('ui', 'quietbookmarkmove', False):
+            writer = repo.ui.debug
+        for b in pullop.explicitbookmarks:
+            # explicit pull overrides local bookmark if any
+            writer(_("importing bookmark %s\n") % b)
+            marks[b] = repo[remotebookmarks[b]].node()
+        marks.write()
+
 def _pullobsolete(pullop):
     """utility function to pull obsolete markers from a remote