changeset 49347:4f04bb0d8deb

auto-upgrade: add an option to silence the safe-mismatch message For well tested case, the message can get in the way, so we add a way to disable it.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Tue, 14 Jun 2022 19:40:35 +0200
parents 67b210bb5ce2
children 44319aa4a2a4
files mercurial/configitems.py mercurial/helptext/config.txt mercurial/localrepo.py mercurial/upgrade.py tests/test-share-safe.t
diffstat 5 files changed, 47 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/configitems.py	Tue Jun 14 15:22:05 2022 +0200
+++ b/mercurial/configitems.py	Tue Jun 14 19:40:35 2022 +0200
@@ -2170,6 +2170,16 @@
     default=True,
 )
 coreconfigitem(
+    b'share',
+    b'safe-mismatch.source-not-safe:verbose-upgrade',
+    default=True,
+)
+coreconfigitem(
+    b'share',
+    b'safe-mismatch.source-safe:verbose-upgrade',
+    default=True,
+)
+coreconfigitem(
     b'shelve',
     b'maxbackups',
     default=10,
--- a/mercurial/helptext/config.txt	Tue Jun 14 15:22:05 2022 +0200
+++ b/mercurial/helptext/config.txt	Tue Jun 14 19:40:35 2022 +0200
@@ -2179,6 +2179,9 @@
     Check :hg:`help config.format.use-share-safe` for details about the
     share-safe feature.
 
+``safe-mismatch.source-safe:verbose-upgrade``
+    Display a message when upgrading, (default: True)
+
 ``safe-mismatch.source-safe.warn``
     Shows a warning on operations if the shared repository does not use
     share-safe, but the source repository does.
@@ -2204,6 +2207,9 @@
     Check :hg:`help config.format.use-share-safe` for details about the
     share-safe feature.
 
+``safe-mismatch.source-not-safe:verbose-upgrade``
+    Display a message when upgrading, (default: True)
+
 ``safe-mismatch.source-not-safe.warn``
     Shows a warning on operations if the shared repository uses share-safe,
     but the source repository does not.
--- a/mercurial/localrepo.py	Tue Jun 14 15:22:05 2022 +0200
+++ b/mercurial/localrepo.py	Tue Jun 14 19:40:35 2022 +0200
@@ -628,6 +628,9 @@
             mismatch_config = ui.config(
                 b'share', b'safe-mismatch.source-not-safe'
             )
+            mismatch_verbose_upgrade = ui.configbool(
+                b'share', b'safe-mismatch.source-not-safe:verbose-upgrade'
+            )
             if mismatch_config in (
                 b'downgrade-allow',
                 b'allow',
@@ -643,6 +646,7 @@
                     requirements,
                     mismatch_config,
                     mismatch_warn,
+                    mismatch_verbose_upgrade,
                 )
             elif mismatch_config == b'abort':
                 raise error.Abort(
@@ -668,6 +672,9 @@
             mismatch_warn = ui.configbool(
                 b'share', b'safe-mismatch.source-safe.warn'
             )
+            mismatch_verbose_upgrade = ui.configbool(
+                b'share', b'safe-mismatch.source-safe:verbose-upgrade'
+            )
             if mismatch_config in (
                 b'upgrade-allow',
                 b'allow',
@@ -683,6 +690,7 @@
                     requirements,
                     mismatch_config,
                     mismatch_warn,
+                    mismatch_verbose_upgrade,
                 )
             elif mismatch_config == b'abort':
                 raise error.Abort(
--- a/mercurial/upgrade.py	Tue Jun 14 15:22:05 2022 +0200
+++ b/mercurial/upgrade.py	Tue Jun 14 19:40:35 2022 +0200
@@ -305,6 +305,7 @@
     current_requirements,
     mismatch_config,
     mismatch_warn,
+    mismatch_verbose_upgrade,
 ):
     """Upgrades a share to use share-safe mechanism"""
     wlock = None
@@ -337,7 +338,8 @@
             diffrequires.add(requirementsmod.SHARESAFE_REQUIREMENT)
             current_requirements.add(requirementsmod.SHARESAFE_REQUIREMENT)
         scmutil.writerequires(hgvfs, diffrequires)
-        ui.warn(_(b'repository upgraded to use share-safe mode\n'))
+        if mismatch_verbose_upgrade:
+            ui.warn(_(b'repository upgraded to use share-safe mode\n'))
     except error.LockError as e:
         hint = _(
             b"see `hg help config.format.use-share-safe` for more information"
@@ -366,6 +368,7 @@
     current_requirements,
     mismatch_config,
     mismatch_warn,
+    mismatch_verbose_upgrade,
 ):
     """Downgrades a share which use share-safe to not use it"""
     wlock = None
@@ -394,7 +397,8 @@
             current_requirements |= source_requirements
             current_requirements -= set(requirementsmod.SHARESAFE_REQUIREMENT)
         scmutil.writerequires(hgvfs, current_requirements)
-        ui.warn(_(b'repository downgraded to not use share-safe mode\n'))
+        if mismatch_verbose_upgrade:
+            ui.warn(_(b'repository downgraded to not use share-safe mode\n'))
     except error.LockError as e:
         hint = _(
             b"see `hg help config.format.use-share-safe` for more information"
--- a/tests/test-share-safe.t	Tue Jun 14 15:22:05 2022 +0200
+++ b/tests/test-share-safe.t	Tue Jun 14 19:40:35 2022 +0200
@@ -521,12 +521,21 @@
   [255]
   $ rm ../ss-share/.hg/wlock
 
+  $ cp -R ../ss-share ../ss-share-bck
   $ hg log -GT "{node}: {desc}\n" -R ../ss-share --config share.safe-mismatch.source-not-safe=downgrade-abort
   repository downgraded to not use share-safe mode
   @  f63db81e6dde1d9c78814167f77fb1fb49283f4f: added bar
   |
   o  f3ba8b99bb6f897c87bbc1c07b75c6ddf43a4f77: added foo
   
+  $ rm -rf ../ss-share
+  $ mv ../ss-share-bck ../ss-share
+
+  $ hg log -GT "{node}: {desc}\n" -R ../ss-share --config share.safe-mismatch.source-not-safe=downgrade-abort --config share.safe-mismatch.source-not-safe:verbose-upgrade=no
+  @  f63db81e6dde1d9c78814167f77fb1fb49283f4f: added bar
+  |
+  o  f3ba8b99bb6f897c87bbc1c07b75c6ddf43a4f77: added foo
+  
 
   $ hg log -GT "{node}: {desc}\n" -R ../ss-share
   @  f63db81e6dde1d9c78814167f77fb1fb49283f4f: added bar
@@ -588,12 +597,20 @@
   [255]
 
   $ rm ../nss-share/.hg/wlock
+  $ cp -R ../nss-share ../nss-share-bck
   $ hg log -GT "{node}: {desc}\n" -R ../nss-share --config share.safe-mismatch.source-safe=upgrade-abort
   repository upgraded to use share-safe mode
   @  f63db81e6dde1d9c78814167f77fb1fb49283f4f: added bar
   |
   o  f3ba8b99bb6f897c87bbc1c07b75c6ddf43a4f77: added foo
   
+  $ rm -rf ../nss-share
+  $ mv ../nss-share-bck ../nss-share
+  $ hg log -GT "{node}: {desc}\n" -R ../nss-share --config share.safe-mismatch.source-safe=upgrade-abort --config share.safe-mismatch.source-safe:verbose-upgrade=no
+  @  f63db81e6dde1d9c78814167f77fb1fb49283f4f: added bar
+  |
+  o  f3ba8b99bb6f897c87bbc1c07b75c6ddf43a4f77: added foo
+  
 
 Test that unshare works