Patchwork [2,of,3,STABLE] rebase: lock the repo during the full rebase operation

login
register
mail settings
Submitter Pierre-Yves David
Date Aug. 12, 2015, 12:06 a.m.
Message ID <3cfb0c92590589c9ccde.1439338004@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/10192/
State Accepted
Headers show

Comments

Pierre-Yves David - Aug. 12, 2015, 12:06 a.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 1439336711 25200
#      Tue Aug 11 16:45:11 2015 -0700
# Branch stable
# Node ID 3cfb0c92590589c9ccdef1884b6133d0d6303805
# Parent  6070fb278da8f8e618f826a29feb5cb78ca038a0
rebase: lock the repo during the full rebase operation

Running `hg pull --rebase` would move bookmarks without any repository locking.
So we now lock the repository. For good measure and avoiding sneaking race
conditions we lock the repository for the whole operation.

There is no code change beside the indentation.

Patch

diff --git a/hgext/rebase.py b/hgext/rebase.py
--- a/hgext/rebase.py
+++ b/hgext/rebase.py
@@ -1024,44 +1024,50 @@  def clearrebased(ui, repo, state, skippe
 
 
 def pullrebase(orig, ui, repo, *args, **opts):
     'Call rebase after pull if the latter has been invoked with --rebase'
     if opts.get('rebase'):
-        if opts.get('update'):
-            del opts['update']
-            ui.debug('--update and --rebase are not compatible, ignoring '
-                     'the update flag\n')
+        wlock = lock = None
+        try:
+            wlock = repo.wlock()
+            lock = repo.lock()
+            if opts.get('update'):
+                del opts['update']
+                ui.debug('--update and --rebase are not compatible, ignoring '
+                         'the update flag\n')
 
-        movemarkfrom = repo['.'].node()
-        revsprepull = len(repo)
-        origpostincoming = commands.postincoming
-        def _dummy(*args, **kwargs):
-            pass
-        commands.postincoming = _dummy
-        try:
-            orig(ui, repo, *args, **opts)
+            movemarkfrom = repo['.'].node()
+            revsprepull = len(repo)
+            origpostincoming = commands.postincoming
+            def _dummy(*args, **kwargs):
+                pass
+            commands.postincoming = _dummy
+            try:
+                orig(ui, repo, *args, **opts)
+            finally:
+                commands.postincoming = origpostincoming
+            revspostpull = len(repo)
+            if revspostpull > revsprepull:
+                # --rev option from pull conflict with rebase own --rev
+                # dropping it
+                if 'rev' in opts:
+                    del opts['rev']
+                # positional argument from pull conflicts with rebase's own
+                # --source.
+                if 'source' in opts:
+                    del opts['source']
+                rebase(ui, repo, **opts)
+                branch = repo[None].branch()
+                dest = repo[branch].rev()
+                if dest != repo['.'].rev():
+                    # there was nothing to rebase we force an update
+                    hg.update(repo, dest)
+                    if bookmarks.update(repo, [movemarkfrom], repo['.'].node()):
+                        ui.status(_("updating bookmark %s\n")
+                                  % repo._activebookmark)
         finally:
-            commands.postincoming = origpostincoming
-        revspostpull = len(repo)
-        if revspostpull > revsprepull:
-            # --rev option from pull conflict with rebase own --rev
-            # dropping it
-            if 'rev' in opts:
-                del opts['rev']
-            # positional argument from pull conflicts with rebase's own
-            # --source.
-            if 'source' in opts:
-                del opts['source']
-            rebase(ui, repo, **opts)
-            branch = repo[None].branch()
-            dest = repo[branch].rev()
-            if dest != repo['.'].rev():
-                # there was nothing to rebase we force an update
-                hg.update(repo, dest)
-                if bookmarks.update(repo, [movemarkfrom], repo['.'].node()):
-                    ui.status(_("updating bookmark %s\n")
-                              % repo._activebookmark)
+            release(lock, wlock)
     else:
         if opts.get('tool'):
             raise util.Abort(_('--tool can only be used with --rebase'))
         orig(ui, repo, *args, **opts)