changeset 49200:71774d799de7

auto-upgrade: skip the operation if the repository cannot be locked This seems like a fine default behavior for now. If some users wants something more aggressive we can make the behavior configurable in the future. Differential Revision: https://phab.mercurial-scm.org/D12619
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Tue, 05 Apr 2022 05:01:58 +0200
parents 575f3dedb69a
children f923bdd7477d
files mercurial/helptext/config.txt mercurial/upgrade_utils/auto_upgrade.py tests/test-upgrade-repo.t
diffstat 3 files changed, 31 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/helptext/config.txt	Tue Apr 05 04:45:48 2022 +0200
+++ b/mercurial/helptext/config.txt	Tue Apr 05 05:01:58 2022 +0200
@@ -957,6 +957,9 @@
    change is needed. This also applies to operations that would have been
    read-only (like hg status).
 
+   If the repository cannot be locked, the automatic-upgrade operation will be
+   skipped. The next operation will attempt it again.
+
    This configuration will apply for moves in any direction, either adding the
    `dirstate-v2` format if `format.use-dirstate-v2=yes` or removing the
    `dirstate-v2` requirement if `format.use-dirstate-v2=no`. So we recommend
@@ -1008,6 +1011,9 @@
    triggers if a change is needed. This also applies to operations that would
    have been read-only (like hg status).
 
+   If the repository cannot be locked, the automatic-upgrade operation will be
+   skipped. The next operation will attempt it again.
+
    This configuration will apply for moves in any direction, either adding the
    `dirstate-tracked-hint` format if `format.use-dirstate-tracked-hint=yes` or
    removing the `dirstate-tracked-hint` requirement if
@@ -1084,6 +1090,9 @@
    change is needed. This also applies to operation that would have been
    read-only (like hg status).
 
+   If the repository cannot be locked, the automatic-upgrade operation will be
+   skipped. The next operation will attempt it again.
+
    This configuration will apply for moves in any direction, either adding the
    `share-safe` format if `format.use-share-safe=yes` or removing the
    `share-safe` requirement if `format.use-share-safe=no`. So we recommend
--- a/mercurial/upgrade_utils/auto_upgrade.py	Tue Apr 05 04:45:48 2022 +0200
+++ b/mercurial/upgrade_utils/auto_upgrade.py	Tue Apr 05 05:01:58 2022 +0200
@@ -217,19 +217,26 @@
 
     loop = 0
 
-    while not clear:
-        loop += 1
-        if loop > 100:
-            # XXX basic protection against infinite loop, make it better.
-            raise error.ProgrammingError("Too many auto upgrade loops")
-        clear = True
-        for get_action in AUTO_UPGRADE_ACTIONS:
-            action = get_action(repo)
-            if action is not None:
-                clear = False
-                with repo.wlock(wait=False), repo.lock(wait=False):
-                    action = get_action(repo)
-                    if action is not None:
-                        action()
-                    repo = maker_func()
+    try:
+        while not clear:
+            loop += 1
+            if loop > 100:
+                # XXX basic protection against infinite loop, make it better.
+                raise error.ProgrammingError("Too many auto upgrade loops")
+            clear = True
+            for get_action in AUTO_UPGRADE_ACTIONS:
+                action = get_action(repo)
+                if action is not None:
+                    clear = False
+                    with repo.wlock(wait=False), repo.lock(wait=False):
+                        action = get_action(repo)
+                        if action is not None:
+                            action()
+                        repo = maker_func()
+    except error.LockError:
+        # if we cannot get the lock, ignore the auto-upgrade attemps and
+        # proceed. We might want to make this behavior configurable in the
+        # future.
+        pass
+
     return repo
--- a/tests/test-upgrade-repo.t	Tue Apr 05 04:45:48 2022 +0200
+++ b/tests/test-upgrade-repo.t	Tue Apr 05 05:01:58 2022 +0200
@@ -2069,8 +2069,6 @@
   $ hg status -R auto-upgrade \
   >     --config format.use-dirstate-v2.automatic-upgrade-of-mismatching-repositories=yes \
   >     --config format.use-dirstate-v2=no
-  abort: could not lock working directory of auto-upgrade: Permission denied
-  [20]
   $ hg debugformat -R auto-upgrade | grep dirstate-v2
   dirstate-v2:        yes
 
@@ -2085,8 +2083,6 @@
   $ hg status -R auto-upgrade \
   >     --config format.use-dirstate-v2.automatic-upgrade-of-mismatching-repositories=yes \
   >     --config format.use-dirstate-v2=no
-  abort: repository auto-upgrade: timed out waiting for lock held by 'brunhoff/effffffc:1215708'
-  [20]
   $ hg debugformat -R auto-upgrade | grep dirstate-v2
   dirstate-v2:        yes