marmoute created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  This is similar to what we introduce for `share-safe`, but apply tot he 
tracked-hint feature.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/configitems.py
  mercurial/helptext/config.txt
  mercurial/upgrade_utils/auto_upgrade.py
  rust/hg-core/src/requirements.rs
  rust/rhg/src/main.rs
  tests/test-help.t
  tests/test-share-safe.t
  tests/test-status-tracked-key.t

CHANGE DETAILS

diff --git a/tests/test-status-tracked-key.t b/tests/test-status-tracked-key.t
--- a/tests/test-status-tracked-key.t
+++ b/tests/test-status-tracked-key.t
@@ -202,3 +202,37 @@
   .hg/dirstate-tracked-hint
   $ hg debugrequires | grep 'tracked'
   dirstate-tracked-key-v1
+  $ cd ..
+
+Test automatic upgrade and downgrade
+------------------------------------
+
+create an initial repository
+
+  $ hg init auto-upgrade \
+  > --config format.use-dirstate-tracked-hint=no
+  $ hg debugbuilddag -R auto-upgrade --new-file .+5
+  $ hg -R auto-upgrade update
+  6 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ hg debugformat -R auto-upgrade | grep tracked
+  tracked-hint:        no
+
+upgrade it to dirstate-tracked-hint automatically
+
+  $ hg status -R auto-upgrade \
+  > --config 
format.use-dirstate-tracked-hint.automatic-upgrade-of-mismatching-repositories=yes
 \
+  > --config format.use-dirstate-tracked-hint=yes
+  automatically upgrading repository to the `tracked-hint` feature
+  (see `hg help config.format.use-dirstate-tracked-hint` for details)
+  $ hg debugformat -R auto-upgrade | grep tracked
+  tracked-hint:       yes
+
+downgrade it from dirstate-tracked-hint automatically
+
+  $ hg status -R auto-upgrade \
+  > --config 
format.use-dirstate-tracked-hint.automatic-upgrade-of-mismatching-repositories=yes
 \
+  > --config format.use-dirstate-tracked-hint=no
+  automatically downgrading repository from the `tracked-hint` feature
+  (see `hg help config.format.use-dirstate-tracked-hint` for details)
+  $ hg debugformat -R auto-upgrade | grep tracked
+  tracked-hint:        no
diff --git a/tests/test-share-safe.t b/tests/test-share-safe.t
--- a/tests/test-share-safe.t
+++ b/tests/test-share-safe.t
@@ -603,3 +603,36 @@
   |
   o  f3ba8b99bb6f897c87bbc1c07b75c6ddf43a4f77: added foo
   
+
+Test automatique upgrade/downgrade of main-repository
+------------------------------------------------------
+
+create an initial repository
+
+  $ hg init auto-upgrade \
+  > --config format.use-share-safe=no
+  $ hg debugbuilddag -R auto-upgrade --new-file .+5
+  $ hg -R auto-upgrade update
+  6 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ hg debugformat -R auto-upgrade | grep share-safe
+  share-safe:          no
+
+upgrade it to share-safe automatically
+
+  $ hg status -R auto-upgrade \
+  >     --config 
format.use-share-safe.automatic-upgrade-of-mismatching-repositories=yes \
+  >     --config format.use-share-safe=yes
+  automatically upgrading repository to the `share-safe` feature
+  (see `hg help config.format.use-share-safe` for details)
+  $ hg debugformat -R auto-upgrade | grep share-safe
+  share-safe:         yes
+
+downgrade it from share-safe automatically
+
+  $ hg status -R auto-upgrade \
+  >     --config 
format.use-share-safe.automatic-upgrade-of-mismatching-repositories=yes \
+  >     --config format.use-share-safe=no
+  automatically downgrading repository from the `share-safe` feature
+  (see `hg help config.format.use-share-safe` for details)
+  $ hg debugformat -R auto-upgrade | grep share-safe
+  share-safe:          no
diff --git a/tests/test-help.t b/tests/test-help.t
--- a/tests/test-help.t
+++ b/tests/test-help.t
@@ -1599,6 +1599,8 @@
   
       "use-dirstate-tracked-hint"
   
+      "use-dirstate-tracked-hint.automatic-upgrade-of-mismatching-repositories"
+  
       "use-persistent-nodemap"
   
       "use-share-safe"
diff --git a/rust/rhg/src/main.rs b/rust/rhg/src/main.rs
--- a/rust/rhg/src/main.rs
+++ b/rust/rhg/src/main.rs
@@ -731,6 +731,11 @@
         ("format", "use-share-safe"),
         requirements::SHARESAFE_REQUIREMENT,
     ),
+    (
+        ("format", 
"use-dirstate-tracked-hint.automatic-upgrade-of-mismatching-repositories"),
+        ("format", "use-dirstate-tracked-hint"),
+        requirements::DIRSTATE_TRACKED_HINT_V1,
+    ),
 ];
 
 /// Mercurial allows users to automatically upgrade their repository.
diff --git a/rust/hg-core/src/requirements.rs b/rust/hg-core/src/requirements.rs
--- a/rust/hg-core/src/requirements.rs
+++ b/rust/hg-core/src/requirements.rs
@@ -100,6 +100,10 @@
 
 pub const DIRSTATE_V2_REQUIREMENT: &str = "dirstate-v2";
 
+/// A repository that uses the tracked hint dirstate file
+#[allow(unused)]
+pub const DIRSTATE_TRACKED_HINT_V1: &str = "dirstate-tracked-key-v1";
+
 /// When narrowing is finalized and no longer subject to format changes,
 /// we should move this to just "narrow" or similar.
 #[allow(unused)]
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
@@ -12,6 +12,24 @@
     scmutil,
 )
 
+from . import (
+    actions,
+    engine,
+)
+
+
+class AutoUpgradeOperation(actions.BaseOperation):
+    """A limited Upgrade Operation used to run simple auto upgrade task
+
+    (Expand it as needed in the future)
+    """
+
+    def __init__(self, req):
+        super().__init__(
+            new_requirements=req,
+            backup_store=False,
+        )
+
 
 def get_share_safe_action(repo):
     """return an automatic-upgrade action for `share-safe` if applicable
@@ -66,8 +84,61 @@
     return action
 
 
+def get_tracked_hint_action(repo):
+    """return an automatic-upgrade action for `tracked-hint` if applicable
+
+    If no action is needed, return None, otherwise return a callback to upgrade
+    or downgrade the repository according the configuration and repository
+    format.
+    """
+    ui = repo.ui
+    requirements = set(repo.requirements)
+    auto_upgrade_tracked_hint = ui.configbool(
+        b'format',
+        
b'use-dirstate-tracked-hint.automatic-upgrade-of-mismatching-repositories',
+    )
+
+    action = None
+
+    if auto_upgrade_tracked_hint:
+        th_config = ui.configbool(b'format', b'use-dirstate-tracked-hint')
+        th_local = requirementsmod.DIRSTATE_TRACKED_HINT_V1 in requirements
+        if th_config and not th_local:
+            msg = _(
+                b"automatically upgrading repository to the `tracked-hint`"
+                b" feature\n"
+            )
+            hint = b"(see `hg help config.format.use-dirstate-tracked-hint` 
for details)\n"
+
+            def action():
+                if not ui.quiet:
+                    ui.write_err(msg)
+                    ui.write_err(hint)
+                requirements.add(requirementsmod.DIRSTATE_TRACKED_HINT_V1)
+                op = AutoUpgradeOperation(requirements)
+                engine.upgrade_tracked_hint(ui, repo, op, add=True)
+
+        elif th_local and not th_config:
+            msg = _(
+                b"automatically downgrading repository from the `tracked-hint`"
+                b" feature\n"
+            )
+            hint = b"(see `hg help config.format.use-dirstate-tracked-hint` 
for details)\n"
+
+            def action():
+                if not ui.quiet:
+                    ui.write_err(msg)
+                    ui.write_err(hint)
+                requirements.discard(requirementsmod.DIRSTATE_TRACKED_HINT_V1)
+                op = AutoUpgradeOperation(requirements)
+                engine.upgrade_tracked_hint(ui, repo, op, add=False)
+
+    return action
+
+
 AUTO_UPGRADE_ACTIONS = [
     get_share_safe_action,
+    get_tracked_hint_action,
 ]
 
 
diff --git a/mercurial/helptext/config.txt b/mercurial/helptext/config.txt
--- a/mercurial/helptext/config.txt
+++ b/mercurial/helptext/config.txt
@@ -976,6 +976,27 @@
 
     2) storing the value and comparing it to a later value.
 
+
+``use-dirstate-tracked-hint.automatic-upgrade-of-mismatching-repositories``
+   When enable, automatic upgrade will be triggered when a repository format
+   mismatch its `use-dirstate-tracked-hint` config.
+
+   This is an advanced behavior that most user will not needs. We recommand you
+   don't use this unless you are a seasoned administrator of a Mercurial 
install
+   base.
+
+   Automatic upgrade mean that any process accessing the repository will 
upgrade
+   the repository format to use `dirstate-tracked-hint`. This only triggers if 
a
+   change is needed. This also apply to operation that would have been 
read-only
+   (like hg status).
+
+   This configuration will apply for move 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
+   `format.use-dirstate-tracked-hint=no`. So we recommand setting both this
+   value and `format.use-dirstate-tracked-hint` at the same time.
+
+
 ``use-persistent-nodemap``
     Enable or disable the "persistent-nodemap" feature which improves
     performance if the Rust extensions are available.
diff --git a/mercurial/configitems.py b/mercurial/configitems.py
--- a/mercurial/configitems.py
+++ b/mercurial/configitems.py
@@ -1290,6 +1290,12 @@
 )
 coreconfigitem(
     b'format',
+    b'use-dirstate-tracked-hint.automatic-upgrade-of-mismatching-repositories',
+    default=False,
+    experimental=True,
+)
+coreconfigitem(
+    b'format',
     b'dotencode',
     default=True,
 )



To: marmoute, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
_______________________________________________
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Reply via email to