changeset 51432:dd519ea71416

chainsaw-update: lock the repository for the duration of the operation This should prevent and catch some misusage where something else try to touch the repository.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Fri, 23 Feb 2024 03:32:35 +0100
parents d36a81d70f25
children ad1066534237
files hgext/chainsaw.py
diffstat 1 files changed, 32 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/chainsaw.py	Fri Feb 23 11:41:55 2024 +0100
+++ b/hgext/chainsaw.py	Fri Feb 23 03:32:35 2024 +0100
@@ -180,38 +180,40 @@
         ui.status(_(b'had to break store lock\n'))
     if repo.vfs.tryunlink(b'wlock'):
         ui.status(_(b'had to break working copy lock\n'))
-
-    ui.status(_(b'recovering after interrupted transaction, if any\n'))
-    repo.recover()
+    # If another process relock after the breacking above, the next locking
+    # will have to wait.
+    with repo.wlock(), repo.lock():
+        ui.status(_(b'recovering after interrupted transaction, if any\n'))
+        repo.recover()
 
-    ui.status(_(b'pulling from %s\n') % source)
-    if repo_created and not opts.get('initial_clone_minimal'):
-        pull_revs = []
-    else:
-        pull_revs = [rev]
-    overrides = {(b'ui', b'quiet'): True}
-    with repo.ui.configoverride(overrides, b'chainsaw-update'):
-        pull = cmdutil.findcmd(b'pull', commands.table)[1][0]
-        pull(repo.ui, repo, source, rev=pull_revs, remote_hidden=False)
+        ui.status(_(b'pulling from %s\n') % source)
+        if repo_created and not opts.get('initial_clone_minimal'):
+            pull_revs = []
+        else:
+            pull_revs = [rev]
+        overrides = {(b'ui', b'quiet'): True}
+        with repo.ui.configoverride(overrides, b'chainsaw-update'):
+            pull = cmdutil.findcmd(b'pull', commands.table)[1][0]
+            pull(repo.ui, repo, source, rev=pull_revs, remote_hidden=False)
 
-    purge = cmdutil.findcmd(b'purge', commands.table)[1][0]
-    purge(
-        ui,
-        repo,
-        dirs=True,
-        all=opts.get('purge_ignored'),
-        files=opts.get('purge_unknown'),
-        confirm=False,
-    )
+        purge = cmdutil.findcmd(b'purge', commands.table)[1][0]
+        purge(
+            ui,
+            repo,
+            dirs=True,
+            all=opts.get('purge_ignored'),
+            files=opts.get('purge_unknown'),
+            confirm=False,
+        )
 
-    ui.status(_(b'updating to revision \'%s\'\n') % rev)
-    update = cmdutil.findcmd(b'update', commands.table)[1][0]
-    update(ui, repo, rev=rev, clean=True)
+        ui.status(_(b'updating to revision \'%s\'\n') % rev)
+        update = cmdutil.findcmd(b'update', commands.table)[1][0]
+        update(ui, repo, rev=rev, clean=True)
 
-    ui.status(
-        _(
-            b'chainsaw-update to revision \'%s\' '
-            b'for repository at \'%s\' done\n'
+        ui.status(
+            _(
+                b'chainsaw-update to revision \'%s\' '
+                b'for repository at \'%s\' done\n'
+            )
+            % (rev, repo.root)
         )
-        % (rev, repo.root)
-    )