diff mercurial/exchange.py @ 20473:1516daaca632

pull: move `remote` argument into pull object One more step toward a more modular pull function.
author Pierre-Yves David <pierre-yves.david@logilab.fr>
date Thu, 30 Jan 2014 17:32:04 -0800
parents b97a453b8c27
children c9bceafc61be
line wrap: on
line diff
--- a/mercurial/exchange.py	Thu Jan 30 17:24:49 2014 -0800
+++ b/mercurial/exchange.py	Thu Jan 30 17:32:04 2014 -0800
@@ -382,14 +382,16 @@
     afterward.
     """
 
-    def __init__(self, repo):
+    def __init__(self, repo, remote):
         # repo we pull from
         self.repo = repo
+        # repo we pull to
+        self.remote = remote
 
 def pull(repo, remote, heads=None, force=False):
-    pullop = pulloperation(repo)
-    if remote.local():
-        missing = set(remote.requirements) - pullop.repo.supported
+    pullop = pulloperation(repo, remote)
+    if pullop.remote.local():
+        missing = set(pullop.remote.requirements) - pullop.repo.supported
         if missing:
             msg = _("required features are not"
                     " supported in the destination:"
@@ -399,10 +401,11 @@
     # don't open transaction for nothing or you break future useful
     # rollback call
     tr = None
-    trname = 'pull\n' + util.hidepassword(remote.url())
+    trname = 'pull\n' + util.hidepassword(pullop.remote.url())
     lock = pullop.repo.lock()
     try:
-        tmp = discovery.findcommonincoming(pullop.repo.unfiltered(), remote,
+        tmp = discovery.findcommonincoming(pullop.repo.unfiltered(),
+                                           pullop.remote,
                                            heads=heads, force=force)
         common, fetch, rheads = tmp
         if not fetch:
@@ -412,23 +415,24 @@
             tr = pullop.repo.transaction(trname)
             if heads is None and list(common) == [nullid]:
                 pullop.repo.ui.status(_("requesting all changes\n"))
-            elif heads is None and remote.capable('changegroupsubset'):
+            elif heads is None and pullop.remote.capable('changegroupsubset'):
                 # issue1320, avoid a race if remote changed after discovery
                 heads = rheads
 
-            if remote.capable('getbundle'):
+            if pullop.remote.capable('getbundle'):
                 # TODO: get bundlecaps from remote
-                cg = remote.getbundle('pull', common=common,
-                                      heads=heads or rheads)
+                cg = pullop.remote.getbundle('pull', common=common,
+                                             heads=heads or rheads)
             elif heads is None:
-                cg = remote.changegroup(fetch, 'pull')
-            elif not remote.capable('changegroupsubset'):
+                cg = pullop.remote.changegroup(fetch, 'pull')
+            elif not pullop.remote.capable('changegroupsubset'):
                 raise util.Abort(_("partial pull cannot be done because "
                                        "other repository doesn't support "
                                        "changegroupsubset."))
             else:
-                cg = remote.changegroupsubset(fetch, heads, 'pull')
-            result = pullop.repo.addchangegroup(cg, 'pull', remote.url())
+                cg = pullop.remote.changegroupsubset(fetch, heads, 'pull')
+            result = pullop.repo.addchangegroup(cg, 'pull',
+                                                pullop.remote.url())
 
         # compute target subset
         if heads is None:
@@ -441,7 +445,7 @@
             subset = heads
 
         # Get remote phases data from remote
-        remotephases = remote.listkeys('phases')
+        remotephases = pullop.remote.listkeys('phases')
         publishing = bool(remotephases.get('publishing', False))
         if remotephases and not publishing:
             # remote is new and unpublishing
@@ -459,7 +463,7 @@
                 return pullop.repo.transaction(trname)
             return tr
 
-        obstr = obsolete.syncpull(pullop.repo, remote, gettransaction)
+        obstr = obsolete.syncpull(pullop.repo, pullop.remote, gettransaction)
         if obstr is not None:
             tr = obstr