[PATCH 5 of 7 (push is done; 12 more to go for pull)] push: move discovery in its own function

pierre-yves.david at ens-lyon.org pierre-yves.david at ens-lyon.org
Tue Feb 11 15:32:55 CST 2014


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at logilab.fr>
# Date 1391144729 28800
#      Thu Jan 30 21:05:29 2014 -0800
# Node ID b1f6e0ea25feccb4b2ce5c3c72b58b91a5d85928
# Parent  2890c2e587627bd14728ccaf6eacc581ee7a4fa9
push: move discovery in its own function

Now that every necessary information is held in the `pushoperation` object, we
can extract the discovery logic 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
@@ -76,11 +76,10 @@ def push(repo, remote, force=False, revs
     # unbundle assumes local user cannot lock remote repo (new ssh
     # servers, http servers).
 
     if not pushop.remote.canpush():
         raise util.Abort(_("destination does not support push"))
-    unfi = pushop.repo.unfiltered()
     # get local lock as we might write phase data
     locallock = None
     try:
         locallock = pushop.repo.lock()
         pushop.locallocked = True
@@ -98,21 +97,11 @@ def push(repo, remote, force=False, revs
         lock = None
         unbundle = pushop.remote.capable('unbundle')
         if not unbundle:
             lock = pushop.remote.lock()
         try:
-            # discovery
-            fci = discovery.findcommonincoming
-            commoninc = fci(unfi, pushop.remote, force=pushop.force)
-            common, inc, remoteheads = commoninc
-            fco = discovery.findcommonoutgoing
-            outgoing = fco(unfi, pushop.remote, onlyheads=pushop.revs,
-                           commoninc=commoninc, force=pushop.force)
-            pushop.outgoing = outgoing
-            pushop.remoteheads = remoteheads
-            pushop.incoming = inc
-
+            _pushdiscovery(pushop)
             if _pushcheckoutgoing(pushop):
                 _pushchangeset(pushop)
             _pushsyncphase(pushop)
             _pushobsolete(pushop)
         finally:
@@ -123,10 +112,23 @@ def push(repo, remote, force=False, revs
             locallock.release()
 
     _pushbookmark(pushop)
     return pushop.ret
 
+def _pushdiscovery(pushop):
+    # discovery
+    unfi = pushop.repo.unfiltered()
+    fci = discovery.findcommonincoming
+    commoninc = fci(unfi, pushop.remote, force=pushop.force)
+    common, inc, remoteheads = commoninc
+    fco = discovery.findcommonoutgoing
+    outgoing = fco(unfi, pushop.remote, onlyheads=pushop.revs,
+                   commoninc=commoninc, force=pushop.force)
+    pushop.outgoing = outgoing
+    pushop.remoteheads = remoteheads
+    pushop.incoming = inc
+
 def _pushcheckoutgoing(pushop):
     outgoing = pushop.outgoing
     unfi = pushop.repo.unfiltered()
     if not outgoing.missing:
         # nothing to push


More information about the Mercurial-devel mailing list