Patchwork [11,of,11,(19,more,to,go)] push: move phases synchronisation function in its own function

login
register
mail settings
Submitter Pierre-Yves David
Date Feb. 11, 2014, 12:01 a.m.
Message ID <1c5e14e0c86a9c9a223e.1392076899@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/3557/
State Accepted
Commit eca9d5375606a6a41ed5f74967825d7af402e4b0
Headers show

Comments

Pierre-Yves David - Feb. 11, 2014, 12:01 a.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@logilab.fr>
# Date 1391142163 28800
#      Thu Jan 30 20:22:43 2014 -0800
# Node ID 1c5e14e0c86a9c9a223e1d34a7d63640f9ac6580
# Parent  eb48629ace02d80f4104c5d72f6ae5d672982f4c
push: move phases synchronisation function in its own function

Now that every necessary information is held in the `pushoperation` object, we
can finally extract the phase synchronisation phase to it's own function. This
is the first concrete block of code we extract from the huge push function.
Hooray!

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
@@ -171,84 +171,11 @@  def push(repo, remote, force=False, revs
                     # we return an integer indicating remote head count
                     # change
                     pushop.ret = pushop.remote.addchangegroup(cg, 'push',
                                                               pushop.repo.url())
 
-            if pushop.ret:
-                # push succeed, synchronize target of the push
-                cheads = pushop.outgoing.missingheads
-            elif pushop.revs is None:
-                # All out push fails. synchronize all common
-                cheads = pushop.outgoing.commonheads
-            else:
-                # I want cheads = heads(::missingheads and ::commonheads)
-                # (missingheads is revs with secret changeset filtered out)
-                #
-                # This can be expressed as:
-                #     cheads = ( (missingheads and ::commonheads)
-                #              + (commonheads and ::missingheads))"
-                #              )
-                #
-                # while trying to push we already computed the following:
-                #     common = (::commonheads)
-                #     missing = ((commonheads::missingheads) - commonheads)
-                #
-                # We can pick:
-                # * missingheads part of common (::commonheads)
-                common = set(pushop.outgoing.common)
-                nm = pushop.repo.changelog.nodemap
-                cheads = [node for node in pushop.revs if nm[node] in common]
-                # and
-                # * commonheads parents on missing
-                revset = unfi.set('%ln and parents(roots(%ln))',
-                                 pushop.outgoing.commonheads,
-                                 pushop.outgoing.missing)
-                cheads.extend(c.node() for c in revset)
-            # even when we don't push, exchanging phase data is useful
-            remotephases = pushop.remote.listkeys('phases')
-            if (pushop.ui.configbool('ui', '_usedassubrepo', False)
-                and remotephases    # server supports phases
-                and pushop.ret is None # nothing was pushed
-                and remotephases.get('publishing', False)):
-                # When:
-                # - this is a subrepo push
-                # - and remote support phase
-                # - and no changeset was pushed
-                # - and remote is publishing
-                # We may be in issue 3871 case!
-                # We drop the possible phase synchronisation done by
-                # courtesy to publish changesets possibly locally draft
-                # on the remote.
-                remotephases = {'publishing': 'True'}
-            if not remotephases: # old server or public only rer
-                _localphasemove(pushop, cheads)
-                # don't push any phase data as there is nothing to push
-            else:
-                ana = phases.analyzeremotephases(pushop.repo, cheads,
-                                                 remotephases)
-                pheads, droots = ana
-                ### Apply remote phase on local
-                if remotephases.get('publishing', False):
-                    _localphasemove(pushop, cheads)
-                else: # publish = False
-                    _localphasemove(pushop, pheads)
-                    _localphasemove(pushop, cheads, phases.draft)
-                ### Apply local phase on remote
-
-                # Get the list of all revs draft on remote by public here.
-                # XXX Beware that revset break if droots is not strictly
-                # XXX root we may want to ensure it is but it is costly
-                outdated =  unfi.set('heads((%ln::%ln) and public())',
-                                     droots, cheads)
-                for newremotehead in outdated:
-                    r = pushop.remote.pushkey('phases',
-                                              newremotehead.hex(),
-                                              str(phases.draft),
-                                              str(phases.public))
-                    if not r:
-                        pushop.ui.warn(_('updating %s to public failed!\n')
-                                       % newremotehead)
+            _pushsyncphase(pushop)
             _pushobsolete(pushop)
         finally:
             if lock is not None:
                 lock.release()
     finally:
@@ -256,10 +183,88 @@  def push(repo, remote, force=False, revs
             locallock.release()
 
     _pushbookmark(pushop)
     return pushop.ret
 
+def _pushsyncphase(pushop):
+    """synchronise phase information locally and remotly"""
+    unfi = pushop.repo.unfiltered()
+    if pushop.ret:
+        # push succeed, synchronize target of the push
+        cheads = pushop.outgoing.missingheads
+    elif pushop.revs is None:
+        # All out push fails. synchronize all common
+        cheads = pushop.outgoing.commonheads
+    else:
+        # I want cheads = heads(::missingheads and ::commonheads)
+        # (missingheads is revs with secret changeset filtered out)
+        #
+        # This can be expressed as:
+        #     cheads = ( (missingheads and ::commonheads)
+        #              + (commonheads and ::missingheads))"
+        #              )
+        #
+        # while trying to push we already computed the following:
+        #     common = (::commonheads)
+        #     missing = ((commonheads::missingheads) - commonheads)
+        #
+        # We can pick:
+        # * missingheads part of common (::commonheads)
+        common = set(pushop.outgoing.common)
+        nm = pushop.repo.changelog.nodemap
+        cheads = [node for node in pushop.revs if nm[node] in common]
+        # and
+        # * commonheads parents on missing
+        revset = unfi.set('%ln and parents(roots(%ln))',
+                         pushop.outgoing.commonheads,
+                         pushop.outgoing.missing)
+        cheads.extend(c.node() for c in revset)
+    # even when we don't push, exchanging phase data is useful
+    remotephases = pushop.remote.listkeys('phases')
+    if (pushop.ui.configbool('ui', '_usedassubrepo', False)
+        and remotephases    # server supports phases
+        and pushop.ret is None # nothing was pushed
+        and remotephases.get('publishing', False)):
+        # When:
+        # - this is a subrepo push
+        # - and remote support phase
+        # - and no changeset was pushed
+        # - and remote is publishing
+        # We may be in issue 3871 case!
+        # We drop the possible phase synchronisation done by
+        # courtesy to publish changesets possibly locally draft
+        # on the remote.
+        remotephases = {'publishing': 'True'}
+    if not remotephases: # old server or public only rer
+        _localphasemove(pushop, cheads)
+        # don't push any phase data as there is nothing to push
+    else:
+        ana = phases.analyzeremotephases(pushop.repo, cheads,
+                                         remotephases)
+        pheads, droots = ana
+        ### Apply remote phase on local
+        if remotephases.get('publishing', False):
+            _localphasemove(pushop, cheads)
+        else: # publish = False
+            _localphasemove(pushop, pheads)
+            _localphasemove(pushop, cheads, phases.draft)
+        ### Apply local phase on remote
+
+        # Get the list of all revs draft on remote by public here.
+        # XXX Beware that revset break if droots is not strictly
+        # XXX root we may want to ensure it is but it is costly
+        outdated =  unfi.set('heads((%ln::%ln) and public())',
+                             droots, cheads)
+        for newremotehead in outdated:
+            r = pushop.remote.pushkey('phases',
+                                      newremotehead.hex(),
+                                      str(phases.draft),
+                                      str(phases.public))
+            if not r:
+                pushop.ui.warn(_('updating %s to public failed!\n')
+                                       % newremotehead)
+
 def _localphasemove(pushop, nodes, phase=phases.public):
     """move <nodes> to <phase> in the local source repo"""
     if pushop.locallocked:
         phases.advanceboundary(pushop.repo, phase, nodes)
     else: