[PATCH 13 of 13] pull: move changeset pulling in its own function

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


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at logilab.fr>
# Date 1391161199 28800
#      Fri Jan 31 01:39:59 2014 -0800
# Node ID 528b997e75b7d481ed80e809f7ab2701d4715368
# Parent  bcf91cad6594c122f297dcc025b7cb51182babc8
pull: move changeset pulling in its own function

pull: move changeset pulling in its own function

Now that every necessary information is held in the `pulloperation` object, we
can finally extract the changeset pulling to it's own function.

This changeset is pure code movement only.

diff --git a/mercurial/exchange.py b/mercurial/exchange.py
--- a/mercurial/exchange.py
+++ b/mercurial/exchange.py
@@ -391,49 +391,47 @@ def pull(repo, remote, heads=None, force
         pullop.common, pullop.fetch, pullop.rheads = tmp
         if not pullop.fetch:
             pullop.repo.ui.status(_("no changes found\n"))
             result = 0
         else:
-            # We delay the open of the transaction as late as possible so we
-            # don't open transaction for nothing or you break future useful
-            # rollback call
-            pullop.gettransaction()
-            if pullop.heads is None and list(pullop.common) == [nullid]:
-                pullop.repo.ui.status(_("requesting all changes\n"))
-            elif (pullop.heads is None
-                  and pullop.remote.capable('changegroupsubset')):
-                # issue1320, avoid a race if remote changed after discovery
-                pullop.heads = pullop.rheads
-
-            if pullop.remote.capable('getbundle'):
-                # TODO: get bundlecaps from remote
-                cg = pullop.remote.getbundle('pull',
-                                             common=pullop.common,
-                                             heads=(pullop.heads
-                                                   or pullop.rheads))
-            elif pullop.heads is None:
-                cg = pullop.remote.changegroup(pullop.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(pullop.fetch,
-                                                     pullop.heads,
-                                                     'pull')
-            result = pullop.repo.addchangegroup(cg, 'pull',
-                                                pullop.remote.url())
+            result = _pullchangeset(pullop)
 
         _pullphase(pullop)
         _pullobsolete(pullop)
         pullop.closetransaction()
     finally:
         pullop.releasetransaction()
         lock.release()
 
     return result
 
+def _pullchangeset(pullop):
+    """pull changeset from unbundle into the local repo"""
+    # We delay the open of the transaction as late as possible so we
+    # don't open transaction for nothing or you break future useful
+    # rollback call
+    pullop.gettransaction()
+    if pullop.heads is None and list(pullop.common) == [nullid]:
+        pullop.repo.ui.status(_("requesting all changes\n"))
+    elif pullop.heads is None and pullop.remote.capable('changegroupsubset'):
+        # issue1320, avoid a race if remote changed after discovery
+        pullop.heads = pullop.rheads
+
+    if pullop.remote.capable('getbundle'):
+        # TODO: get bundlecaps from remote
+        cg = pullop.remote.getbundle('pull', common=pullop.common,
+                                     heads=pullop.heads or pullop.rheads)
+    elif pullop.heads is None:
+        cg = pullop.remote.changegroup(pullop.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(pullop.fetch, pullop.heads, 'pull')
+    return pullop.repo.addchangegroup(cg, 'pull', pullop.remote.url())
+
 def _pullphase(pullop):
     # 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