##// END OF EJS Templates
auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint...
marmoute -
r50089:e4b31016 default
parent child Browse files
Show More
@@ -1290,6 +1290,12 coreconfigitem(
1290 1290 )
1291 1291 coreconfigitem(
1292 1292 b'format',
1293 b'use-dirstate-tracked-hint.automatic-upgrade-of-mismatching-repositories',
1294 default=False,
1295 experimental=True,
1296 )
1297 coreconfigitem(
1298 b'format',
1293 1299 b'dotencode',
1294 1300 default=True,
1295 1301 )
@@ -976,6 +976,27 https://www.mercurial-scm.org/wiki/Missi
976 976
977 977 2) storing the value and comparing it to a later value.
978 978
979
980 ``use-dirstate-tracked-hint.automatic-upgrade-of-mismatching-repositories``
981 When enabled, an automatic upgrade will be triggered when a repository format
982 does not match its `use-dirstate-tracked-hint` config.
983
984 This is an advanced behavior that most users will not need. We recommend you
985 don't use this unless you are a seasoned administrator of a Mercurial install
986 base.
987
988 Automatic upgrade means that any process accessing the repository will
989 upgrade the repository format to use `dirstate-tracked-hint`. This only
990 triggers if a change is needed. This also applies to operations that would
991 have been read-only (like hg status).
992
993 This configuration will apply for moves in any direction, either adding the
994 `dirstate-tracked-hint` format if `format.use-dirstate-tracked-hint=yes` or
995 removing the `dirstate-tracked-hint` requirement if
996 `format.use-dirstate-tracked-hint=no`. So we recommend setting both this
997 value and `format.use-dirstate-tracked-hint` at the same time.
998
999
979 1000 ``use-persistent-nodemap``
980 1001 Enable or disable the "persistent-nodemap" feature which improves
981 1002 performance if the Rust extensions are available.
@@ -12,6 +12,24 from .. import (
12 12 scmutil,
13 13 )
14 14
15 from . import (
16 actions,
17 engine,
18 )
19
20
21 class AutoUpgradeOperation(actions.BaseOperation):
22 """A limited Upgrade Operation used to run simple auto upgrade task
23
24 (Expand it as needed in the future)
25 """
26
27 def __init__(self, req):
28 super().__init__(
29 new_requirements=req,
30 backup_store=False,
31 )
32
15 33
16 34 def get_share_safe_action(repo):
17 35 """return an automatic-upgrade action for `share-safe` if applicable
@@ -66,8 +84,61 def get_share_safe_action(repo):
66 84 return action
67 85
68 86
87 def get_tracked_hint_action(repo):
88 """return an automatic-upgrade action for `tracked-hint` if applicable
89
90 If no action is needed, return None, otherwise return a callback to upgrade
91 or downgrade the repository according the configuration and repository
92 format.
93 """
94 ui = repo.ui
95 requirements = set(repo.requirements)
96 auto_upgrade_tracked_hint = ui.configbool(
97 b'format',
98 b'use-dirstate-tracked-hint.automatic-upgrade-of-mismatching-repositories',
99 )
100
101 action = None
102
103 if auto_upgrade_tracked_hint:
104 th_config = ui.configbool(b'format', b'use-dirstate-tracked-hint')
105 th_local = requirementsmod.DIRSTATE_TRACKED_HINT_V1 in requirements
106 if th_config and not th_local:
107 msg = _(
108 b"automatically upgrading repository to the `tracked-hint`"
109 b" feature\n"
110 )
111 hint = b"(see `hg help config.format.use-dirstate-tracked-hint` for details)\n"
112
113 def action():
114 if not ui.quiet:
115 ui.write_err(msg)
116 ui.write_err(hint)
117 requirements.add(requirementsmod.DIRSTATE_TRACKED_HINT_V1)
118 op = AutoUpgradeOperation(requirements)
119 engine.upgrade_tracked_hint(ui, repo, op, add=True)
120
121 elif th_local and not th_config:
122 msg = _(
123 b"automatically downgrading repository from the `tracked-hint`"
124 b" feature\n"
125 )
126 hint = b"(see `hg help config.format.use-dirstate-tracked-hint` for details)\n"
127
128 def action():
129 if not ui.quiet:
130 ui.write_err(msg)
131 ui.write_err(hint)
132 requirements.discard(requirementsmod.DIRSTATE_TRACKED_HINT_V1)
133 op = AutoUpgradeOperation(requirements)
134 engine.upgrade_tracked_hint(ui, repo, op, add=False)
135
136 return action
137
138
69 139 AUTO_UPGRADE_ACTIONS = [
70 140 get_share_safe_action,
141 get_tracked_hint_action,
71 142 ]
72 143
73 144
@@ -100,6 +100,10 const SUPPORTED: &[&str] = &[
100 100
101 101 pub const DIRSTATE_V2_REQUIREMENT: &str = "dirstate-v2";
102 102
103 /// A repository that uses the tracked hint dirstate file
104 #[allow(unused)]
105 pub const DIRSTATE_TRACKED_HINT_V1: &str = "dirstate-tracked-key-v1";
106
103 107 /// When narrowing is finalized and no longer subject to format changes,
104 108 /// we should move this to just "narrow" or similar.
105 109 #[allow(unused)]
@@ -731,6 +731,11 const AUTO_UPGRADES: &[((&str, &str), (&
731 731 ("format", "use-share-safe"),
732 732 requirements::SHARESAFE_REQUIREMENT,
733 733 ),
734 (
735 ("format", "use-dirstate-tracked-hint.automatic-upgrade-of-mismatching-repositories"),
736 ("format", "use-dirstate-tracked-hint"),
737 requirements::DIRSTATE_TRACKED_HINT_V1,
738 ),
734 739 ];
735 740
736 741 /// Mercurial allows users to automatically upgrade their repository.
@@ -1602,6 +1602,8 Separate sections from subsections
1602 1602
1603 1603 "use-dirstate-tracked-hint"
1604 1604
1605 "use-dirstate-tracked-hint.automatic-upgrade-of-mismatching-repositories"
1606
1605 1607 "use-persistent-nodemap"
1606 1608
1607 1609 "use-share-safe"
@@ -603,3 +603,36 Test that unshare works
603 603 |
604 604 o f3ba8b99bb6f897c87bbc1c07b75c6ddf43a4f77: added foo
605 605
606
607 Test automatique upgrade/downgrade of main-repository
608 ------------------------------------------------------
609
610 create an initial repository
611
612 $ hg init auto-upgrade \
613 > --config format.use-share-safe=no
614 $ hg debugbuilddag -R auto-upgrade --new-file .+5
615 $ hg -R auto-upgrade update
616 6 files updated, 0 files merged, 0 files removed, 0 files unresolved
617 $ hg debugformat -R auto-upgrade | grep share-safe
618 share-safe: no
619
620 upgrade it to share-safe automatically
621
622 $ hg status -R auto-upgrade \
623 > --config format.use-share-safe.automatic-upgrade-of-mismatching-repositories=yes \
624 > --config format.use-share-safe=yes
625 automatically upgrading repository to the `share-safe` feature
626 (see `hg help config.format.use-share-safe` for details)
627 $ hg debugformat -R auto-upgrade | grep share-safe
628 share-safe: yes
629
630 downgrade it from share-safe automatically
631
632 $ hg status -R auto-upgrade \
633 > --config format.use-share-safe.automatic-upgrade-of-mismatching-repositories=yes \
634 > --config format.use-share-safe=no
635 automatically downgrading repository from the `share-safe` feature
636 (see `hg help config.format.use-share-safe` for details)
637 $ hg debugformat -R auto-upgrade | grep share-safe
638 share-safe: no
@@ -202,3 +202,37 upgrade
202 202 .hg/dirstate-tracked-hint
203 203 $ hg debugrequires | grep 'tracked'
204 204 dirstate-tracked-key-v1
205 $ cd ..
206
207 Test automatic upgrade and downgrade
208 ------------------------------------
209
210 create an initial repository
211
212 $ hg init auto-upgrade \
213 > --config format.use-dirstate-tracked-hint=no
214 $ hg debugbuilddag -R auto-upgrade --new-file .+5
215 $ hg -R auto-upgrade update
216 6 files updated, 0 files merged, 0 files removed, 0 files unresolved
217 $ hg debugformat -R auto-upgrade | grep tracked
218 tracked-hint: no
219
220 upgrade it to dirstate-tracked-hint automatically
221
222 $ hg status -R auto-upgrade \
223 > --config format.use-dirstate-tracked-hint.automatic-upgrade-of-mismatching-repositories=yes \
224 > --config format.use-dirstate-tracked-hint=yes
225 automatically upgrading repository to the `tracked-hint` feature
226 (see `hg help config.format.use-dirstate-tracked-hint` for details)
227 $ hg debugformat -R auto-upgrade | grep tracked
228 tracked-hint: yes
229
230 downgrade it from dirstate-tracked-hint automatically
231
232 $ hg status -R auto-upgrade \
233 > --config format.use-dirstate-tracked-hint.automatic-upgrade-of-mismatching-repositories=yes \
234 > --config format.use-dirstate-tracked-hint=no
235 automatically downgrading repository from the `tracked-hint` feature
236 (see `hg help config.format.use-dirstate-tracked-hint` for details)
237 $ hg debugformat -R auto-upgrade | grep tracked
238 tracked-hint: no
General Comments 0
You need to be logged in to leave comments. Login now