[PATCH 02 of 13] pull: introduce a pulloperation object

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


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at logilab.fr>
# Date 1391131489 28800
#      Thu Jan 30 17:24:49 2014 -0800
# Node ID 4b65df36f72a82e7221d1a2f91300810eb354ae5
# Parent  164d38007b414b136c75e20595dc2163ca7c8a53
pull: introduce a pulloperation object

This object will hold all data and state gathered through the pull. This will
allow us to split the long function into multiple small one. Smaller function
will be easier to maintains and wrap.  The idea is to blindly store all
information related to the pull in this object so that each step and extension
can use them if necessary.

We start by putting the `repo` variable in the object. More migration in other
function.

diff --git a/mercurial/exchange.py b/mercurial/exchange.py
--- a/mercurial/exchange.py
+++ b/mercurial/exchange.py
@@ -312,36 +312,49 @@ def _pushbookmark(pushop):
         if remote.pushkey('bookmarks', b, dcid, scid):
             ui.status(_("updating bookmark %s\n") % b)
         else:
             ui.warn(_('updating bookmark %s failed!\n') % b)
 
+class pulloperation(object):
+    """A object that represent a single pull operation
+
+    It purpose is to carry push related state and very common operation.
+
+    A new should be created at the begining of each push and discarded
+    afterward.
+    """
+
+    def __init__(self, repo):
+        # repo we pull from
+        self.repo = repo
 
 def pull(repo, remote, heads=None, force=False):
+    pullop = pulloperation(repo)
     if remote.local():
-        missing = set(remote.requirements) - repo.supported
+        missing = set(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())
-    lock = repo.lock()
+    lock = pullop.repo.lock()
     try:
-        tmp = discovery.findcommonincoming(repo.unfiltered(), remote,
+        tmp = discovery.findcommonincoming(pullop.repo.unfiltered(), remote,
                                            heads=heads, force=force)
         common, fetch, rheads = tmp
         if not fetch:
-            repo.ui.status(_("no changes found\n"))
+            pullop.repo.ui.status(_("no changes found\n"))
             result = 0
         else:
-            tr = repo.transaction(trname)
+            tr = pullop.repo.transaction(trname)
             if heads is None and list(common) == [nullid]:
-                repo.ui.status(_("requesting all changes\n"))
+                pullop.repo.ui.status(_("requesting all changes\n"))
             elif heads is None and remote.capable('changegroupsubset'):
                 # issue1320, avoid a race if remote changed after discovery
                 heads = rheads
 
             if remote.capable('getbundle'):
@@ -354,11 +367,11 @@ def pull(repo, remote, heads=None, force
                 raise util.Abort(_("partial pull cannot be done because "
                                        "other repository doesn't support "
                                        "changegroupsubset."))
             else:
                 cg = remote.changegroupsubset(fetch, heads, 'pull')
-            result = repo.addchangegroup(cg, 'pull', remote.url())
+            result = pullop.repo.addchangegroup(cg, 'pull', remote.url())
 
         # compute target subset
         if heads is None:
             # We pulled every thing possible
             # sync on everything common
@@ -371,25 +384,25 @@ def pull(repo, remote, heads=None, force
         # Get remote phases data from remote
         remotephases = remote.listkeys('phases')
         publishing = bool(remotephases.get('publishing', False))
         if remotephases and not publishing:
             # remote is new and unpublishing
-            pheads, _dr = phases.analyzeremotephases(repo, subset,
+            pheads, _dr = phases.analyzeremotephases(pullop.repo, subset,
                                                      remotephases)
-            phases.advanceboundary(repo, phases.public, pheads)
-            phases.advanceboundary(repo, phases.draft, subset)
+            phases.advanceboundary(pullop.repo, phases.public, pheads)
+            phases.advanceboundary(pullop.repo, phases.draft, subset)
         else:
             # Remote is old or publishing all common changesets
             # should be seen as public
-            phases.advanceboundary(repo, phases.public, subset)
+            phases.advanceboundary(pullop.repo, phases.public, subset)
 
         def gettransaction():
             if tr is None:
-                return repo.transaction(trname)
+                return pullop.repo.transaction(trname)
             return tr
 
-        obstr = obsolete.syncpull(repo, remote, gettransaction)
+        obstr = obsolete.syncpull(pullop.repo, remote, gettransaction)
         if obstr is not None:
             tr = obstr
 
         if tr is not None:
             tr.close()


More information about the Mercurial-devel mailing list