[PATCH 04 of 13] pull: move `heads` argument into pull object

pierre-yves.david at ens-lyon.org pierre-yves.david at ens-lyon.org
Tue Feb 11 19:34:18 CST 2014


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at logilab.fr>
# Date 1391132155 28800
#      Thu Jan 30 17:35:55 2014 -0800
# Node ID afdcc38e482f72f10c6b64c808a5a10000cc7bf1
# Parent  52c2362718f8bb930cef5184bf3b44bde5d9d3d3
pull: move `heads` argument into pull object

One more step toward a more modular pull function.

diff --git a/mercurial/exchange.py b/mercurial/exchange.py
--- a/mercurial/exchange.py
+++ b/mercurial/exchange.py
@@ -321,18 +321,20 @@ class pulloperation(object):
 
     A new should be created at the begining of each push and discarded
     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:
             msg = _("required features are not"
                     " supported in the destination:"
@@ -345,47 +347,48 @@ def pull(repo, remote, heads=None, force
     trname = 'pull\n' + util.hidepassword(pullop.remote.url())
     lock = pullop.repo.lock()
     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')
         publishing = bool(remotephases.get('publishing', False))
         if remotephases and not publishing:


More information about the Mercurial-devel mailing list