Patchwork [03,of,13] pull: move `remote` argument into pull object

login
register
mail settings
Submitter Pierre-Yves David
Date Feb. 12, 2014, 1:34 a.m.
Message ID <52c2362718f8bb930cef.1392168857@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/3603/
State Accepted
Commit 1516daaca632b9ba16511c011fd01f3c4768557a
Headers show

Comments

Pierre-Yves David - Feb. 12, 2014, 1:34 a.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@logilab.fr>
# Date 1391131924 28800
#      Thu Jan 30 17:32:04 2014 -0800
# Node ID 52c2362718f8bb930cef5184bf3b44bde5d9d3d3
# Parent  4b65df36f72a82e7221d1a2f91300810eb354ae5
pull: move `remote` argument into pull object

One more step toward a more modular pull function.

Patch

diff --git a/mercurial/exchange.py b/mercurial/exchange.py
--- a/mercurial/exchange.py
+++ b/mercurial/exchange.py
@@ -321,57 +321,61 @@  class pulloperation(object):
 
     A new should be created at the begining of each push and discarded
     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:"
                     " %s") % (', '.join(sorted(missing)))
             raise util.Abort(msg)
 
     # 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:
             pullop.repo.ui.status(_("no changes found\n"))
             result = 0
         else:
             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:
             # We pulled every thing possible
             # sync on everything common
@@ -380,11 +384,11 @@  def pull(repo, remote, heads=None, force
             # We pulled a specific subset
             # sync on this subset
             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
             pheads, _dr = phases.analyzeremotephases(pullop.repo, subset,
                                                      remotephases)
@@ -398,11 +402,11 @@  def pull(repo, remote, heads=None, force
         def gettransaction():
             if tr is None:
                 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
 
         if tr is not None:
             tr.close()