[Updated] D12619: auto-upgrade: skip the operation if the repository cannot be locked

marmoute (Pierre-Yves David) phabricator at mercurial-scm.org
Tue May 24 14:51:25 UTC 2022


Closed by commit rHG71774d799de7: auto-upgrade: skip the operation if the repository cannot be locked (authored by marmoute).
This revision was automatically updated to reflect the committed changes.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D12619?vs=33432&id=33442

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D12619/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D12619

AFFECTED FILES
  mercurial/helptext/config.txt
  mercurial/upgrade_utils/auto_upgrade.py
  tests/test-upgrade-repo.t

CHANGE DETAILS

diff --git a/tests/test-upgrade-repo.t b/tests/test-upgrade-repo.t
--- a/tests/test-upgrade-repo.t
+++ b/tests/test-upgrade-repo.t
@@ -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
 
diff --git a/mercurial/upgrade_utils/auto_upgrade.py b/mercurial/upgrade_utils/auto_upgrade.py
--- a/mercurial/upgrade_utils/auto_upgrade.py
+++ b/mercurial/upgrade_utils/auto_upgrade.py
@@ -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
diff --git a/mercurial/helptext/config.txt b/mercurial/helptext/config.txt
--- a/mercurial/helptext/config.txt
+++ b/mercurial/helptext/config.txt
@@ -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



To: marmoute, #hg-reviewers, Alphare
Cc: Alphare, Kwan, mercurial-patches
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurial-scm.org/pipermail/mercurial-patches/attachments/20220524/dae76d6d/attachment-0002.html>


More information about the Mercurial-patches mailing list