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

login
register
mail settings
Submitter Pierre-Yves David
Date Feb. 11, 2014, 9:32 p.m.
Message ID <b1f6e0ea25feccb4b2ce.1392154375@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/3586/
State Accepted
Commit 233623d58c9acf74132b04fedf881152b4e07343
Headers show

Comments

Pierre-Yves David - Feb. 11, 2014, 9:32 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@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.

Patch

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