Patchwork [16,of,16] push: move phase synchronisation in its own method

login
register
mail settings
Submitter Pierre-Yves David
Date April 17, 2013, 3:58 p.m.
Message ID <34df4d7e4b0e966d22be.1366214331@crater1.logilab.fr>
Download mbox | patch
Permalink /patch/1402/
State Deferred, archived
Headers show

Comments

Pierre-Yves David - April 17, 2013, 3:58 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@logilab.fr>
# Date 1366212143 -7200
#      Wed Apr 17 17:22:23 2013 +0200
# Node ID 34df4d7e4b0e966d22be286fdeaa667279654c07
# Parent  86031a108f85c2922afac8d173ea3c27d2f62bd6
push: move phase synchronisation in its own method

This move the last big chunk of code out of the god function.

Patch

diff --git a/mercurial/exchangeutil.py b/mercurial/exchangeutil.py
--- a/mercurial/exchangeutil.py
+++ b/mercurial/exchangeutil.py
@@ -65,55 +65,12 @@  class pushoperation(object):
                     scmutil.nochangesfound(unfi.ui, unfi,
                                            self._outgoing.excluded)
                 else:
                     self._ret = self._pushbundle()
 
-                self._commonheads = cheads = self._findcommonheads()
-
-                # even when we don't push, exchanging phase data is useful
-                remotephases = remote.listkeys('phases')
-                if (repo.ui.configbool('ui', '_usedassubrepo', False)
-                    and remotephases    # server supports phases
-                    and self._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 repo
-                    phases.advanceboundary(repo, phases.public, cheads)
-                    # don't push any phase data as there is nothing to push
-                else:
-                    ana = phases.analyzeremotephases(repo, cheads, remotephases)
-                    pheads, droots = ana
-                    ### Apply remote phase on local
-                    if remotephases.get('publishing', False):
-                        phases.advanceboundary(repo, phases.public, cheads)
-                    else: # publish = False
-                        phases.advanceboundary(repo, phases.public, pheads)
-                        phases.advanceboundary(repo, phases.draft, cheads)
-                    ### 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 = remote.pushkey('phases',
-                                           newremotehead.hex(),
-                                           str(phases.draft),
-                                           str(phases.public))
-                        if not r:
-                            repo.ui.warn(_('updating %s to public failed!\n')
-                                            % newremotehead)
+                self._commonheads = self._findcommonheads()
+                self._syncphases()
                 self._pushobsolescence()
             finally:
                 if lock is not None:
                     lock.release()
         finally:
@@ -218,11 +175,59 @@  class pushoperation(object):
                              self._outgoing.commonheads,
                              self._outgoing.missing)
             cheads.extend(c.node() for c in revset)
         return cheads
 
+    def _syncphases(self):
+        """Push and pull phase information"""
+        # even when we don't push, exchanging phase data is useful
+        repo = self.repo
+        remote = self.remote
+        unfi = repo.unfiltered()
+        cheads = self._commonheads
+        remotephases = remote.listkeys('phases')
+        if (repo.ui.configbool('ui', '_usedassubrepo', False)
+            and remotephases    # server supports phases
+            and self._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 repo
+            phases.advanceboundary(repo, phases.public, cheads)
+            # don't push any phase data as there is nothing to push
+        else:
+            ana = phases.analyzeremotephases(repo, cheads, remotephases)
+            pheads, droots = ana
+            ### Apply remote phase on local
+            if remotephases.get('publishing', False):
+                phases.advanceboundary(repo, phases.public, cheads)
+            else: # publish = False
+                phases.advanceboundary(repo, phases.public, pheads)
+                phases.advanceboundary(repo, phases.draft, cheads)
+            ### 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 = remote.pushkey('phases',
+                                   newremotehead.hex(),
+                                   str(phases.draft),
+                                   str(phases.public))
+                if not r:
+                    repo.ui.warn(_('updating %s to public failed!\n')
+                                    % newremotehead)
 
     def _pushobsolescence(self):
         """Send local obsolescence marker to remote"""
         self.repo.ui.debug('try to push obsolete markers to remote\n')
         if (obsolete._enabled and self.repo.obsstore and