pull: move `heads` argument into pull object
authorPierre-Yves David <pierre-yves.david@logilab.fr>
Thu, 30 Jan 2014 17:35:55 -0800
changeset 20474 c9bceafc61be
parent 20473 1516daaca632
child 20475 b79b405583af
pull: move `heads` argument into pull object One more step toward a more modular pull function.
mercurial/exchange.py
--- a/mercurial/exchange.py	Thu Jan 30 17:32:04 2014 -0800
+++ b/mercurial/exchange.py	Thu Jan 30 17:35:55 2014 -0800
@@ -382,14 +382,16 @@
     afterward.
     """
 
-    def __init__(self, repo, remote):
+    def __init__(self, repo, remote, heads=None):
         # repo we pull from
         self.repo = repo
         # repo we pull to
         self.remote = remote
+        # revision we try to pull (None is "all")
+        self.heads = heads
 
 def pull(repo, remote, heads=None, force=False):
-    pullop = pulloperation(repo, remote)
+    pullop = pulloperation(repo, remote, heads)
     if pullop.remote.local():
         missing = set(pullop.remote.requirements) - pullop.repo.supported
         if missing:
@@ -406,43 +408,46 @@
     try:
         tmp = discovery.findcommonincoming(pullop.repo.unfiltered(),
                                            pullop.remote,
-                                           heads=heads, force=force)
+                                           heads=pullop.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]:
+            if pullop.heads is None and list(common) == [nullid]:
                 pullop.repo.ui.status(_("requesting all changes\n"))
-            elif heads is None and pullop.remote.capable('changegroupsubset'):
+            elif (pullop.heads is None
+                  and pullop.remote.capable('changegroupsubset')):
                 # issue1320, avoid a race if remote changed after discovery
-                heads = rheads
+                pullop.heads = rheads
 
             if pullop.remote.capable('getbundle'):
                 # TODO: get bundlecaps from remote
                 cg = pullop.remote.getbundle('pull', common=common,
-                                             heads=heads or rheads)
-            elif heads is None:
+                                             heads=pullop.heads or rheads)
+            elif pullop.heads is None:
                 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 = pullop.remote.changegroupsubset(fetch, heads, 'pull')
+                cg = pullop.remote.changegroupsubset(fetch, pullop.heads,
+                                                     'pull')
             result = pullop.repo.addchangegroup(cg, 'pull',
                                                 pullop.remote.url())
 
         # compute target subset
-        if heads is None:
+        if pullop.heads is None:
             # We pulled every thing possible
             # sync on everything common
             subset = common + rheads
         else:
             # We pulled a specific subset
             # sync on this subset
-            subset = heads
+            subset = pullop.heads
 
         # Get remote phases data from remote
         remotephases = pullop.remote.listkeys('phases')