Patchwork [06,of,11,(19,more,to,go)] push: move local lock logic in pushoperation

login
register
mail settings
Submitter Pierre-Yves David
Date Feb. 11, 2014, 12:01 a.m.
Message ID <41b273449477a7d28aee.1392076894@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/3551/
State Accepted
Commit 2f2e8d1c4856ea259373e8aeda9386a30a1d4af9
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 1391140834 28800
#      Thu Jan 30 20:00:34 2014 -0800
# Node ID 41b273449477a7d28aeeb5b2479fd3eeb64e8cda
# Parent  8b97b0a12ed0bdd5c33c56d99ed08342c0a0bc9d
push: move local lock logic in pushoperation

During push, we try to lock the local repo to move local phase according to what
we saw/pushed on the remote repo. Locking the repo may fail, in that case we let
the push proceed without local phase movement (printing warning).

This mean we have code in phase synchronisation that will check if the local repo is
locked or not. we need to move this information in the push object to be able to
extract the phase synchronisation in its own function. This is done as a boolean
because putting reference to the actual lock outside of the main function
sounded a bad idea.

Patch

diff --git a/mercurial/exchange.py b/mercurial/exchange.py
--- a/mercurial/exchange.py
+++ b/mercurial/exchange.py
@@ -31,10 +31,12 @@  class pushoperation(object):
         self.force = force
         # revs to be pushed (None is "all")
         self.revs = revs
         # allow push of new branch
         self.newbranch = newbranch
+        # did a local lock get acquired?
+        self.locallocked = None
 
 def push(repo, remote, force=False, revs=None, newbranch=False):
     '''Push outgoing changesets (limited by revs) from a local
     repository to remote. Return an integer:
       - None means nothing to push
@@ -64,11 +66,11 @@  def push(repo, remote, force=False, revs
     if not pushop.remote.canpush():
         raise util.Abort(_("destination does not support push"))
     unfi = pushop.repo.unfiltered()
     def localphasemove(nodes, phase=phases.public):
         """move <nodes> to <phase> in the local source repo"""
-        if locallock is not None:
+        if pushop.locallocked:
             phases.advanceboundary(pushop.repo, phase, nodes)
         else:
             # repo is not locked, do not change any phases!
             # Informs the user that phases should have been moved when
             # applicable.
@@ -79,11 +81,13 @@  def push(repo, remote, force=False, revs
                                    'local %s phase update\n') % phasestr)
     # get local lock as we might write phase data
     locallock = None
     try:
         locallock = pushop.repo.lock()
+        pushop.locallocked = True
     except IOError, err:
+        pushop.locallocked = False
         if err.errno != errno.EACCES:
             raise
         # source repo cannot be locked.
         # We do not abort the push, but just disable the local phase
         # synchronisation.