##// END OF EJS Templates
auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2...
marmoute -
r50090:411d591e default
parent child Browse files
Show More
@@ -1278,6 +1278,12 b' coreconfigitem('
1278 )
1278 )
1279 coreconfigitem(
1279 coreconfigitem(
1280 b'format',
1280 b'format',
1281 b'use-dirstate-v2.automatic-upgrade-of-mismatching-repositories',
1282 default=False,
1283 experimental=True,
1284 )
1285 coreconfigitem(
1286 b'format',
1281 b'use-dirstate-tracked-hint',
1287 b'use-dirstate-tracked-hint',
1282 default=False,
1288 default=False,
1283 experimental=True,
1289 experimental=True,
@@ -944,6 +944,24 b' https://www.mercurial-scm.org/wiki/Missi'
944
944
945 For a more comprehensive guide, see :hg:`help internals.dirstate-v2`.
945 For a more comprehensive guide, see :hg:`help internals.dirstate-v2`.
946
946
947 ``use-dirstate-v2.automatic-upgrade-of-mismatching-repositories``
948 When enabled, an automatic upgrade will be triggered when a repository format
949 does not match its `use-dirstate-v2` config.
950
951 This is an advanced behavior that most users will not need. We recommend you
952 don't use this unless you are a seasoned administrator of a Mercurial install
953 base.
954
955 Automatic upgrade means that any process accessing the repository will
956 upgrade the repository format to use `dirstate-v2`. This only triggers if a
957 change is needed. This also applies to operations that would have been
958 read-only (like hg status).
959
960 This configuration will apply for moves in any direction, either adding the
961 `dirstate-v2` format if `format.use-dirstate-v2=yes` or removing the
962 `dirstate-v2` requirement if `format.use-dirstate-v2=no`. So we recommend
963 setting both this value and `format.use-dirstate-v2` at the same time.
964
947 ``use-dirstate-tracked-hint``
965 ``use-dirstate-tracked-hint``
948 Enable or disable the writing of "tracked key" file alongside the dirstate.
966 Enable or disable the writing of "tracked key" file alongside the dirstate.
949 (default to disabled)
967 (default to disabled)
@@ -136,7 +136,64 b' def get_tracked_hint_action(repo):'
136 return action
136 return action
137
137
138
138
139 def get_dirstate_v2_action(repo):
140 """return an automatic-upgrade action for `dirstate-v2` if applicable
141
142 If no action is needed, return None, otherwise return a callback to upgrade
143 or downgrade the repository according the configuration and repository
144 format.
145 """
146 ui = repo.ui
147 requirements = set(repo.requirements)
148 auto_upgrade_tracked_hint = ui.configbool(
149 b'format',
150 b'use-dirstate-v2.automatic-upgrade-of-mismatching-repositories',
151 )
152
153 action = None
154
155 if auto_upgrade_tracked_hint:
156 d2_config = ui.configbool(b'format', b'use-dirstate-v2')
157 d2_local = requirementsmod.DIRSTATE_V2_REQUIREMENT in requirements
158 if d2_config and not d2_local:
159 msg = _(
160 b"automatically upgrading repository to the `dirstate-v2`"
161 b" feature\n"
162 )
163 hint = (
164 b"(see `hg help config.format.use-dirstate-v2` for details)\n"
165 )
166
167 def action():
168 if not ui.quiet:
169 ui.write_err(msg)
170 ui.write_err(hint)
171 requirements.add(requirementsmod.DIRSTATE_V2_REQUIREMENT)
172 fake_op = AutoUpgradeOperation(requirements)
173 engine.upgrade_dirstate(repo.ui, repo, fake_op, b'v1', b'v2')
174
175 elif d2_local and not d2_config:
176 msg = _(
177 b"automatically downgrading repository from the `dirstate-v2`"
178 b" feature\n"
179 )
180 hint = (
181 b"(see `hg help config.format.use-dirstate-v2` for details)\n"
182 )
183
184 def action():
185 if not ui.quiet:
186 ui.write_err(msg)
187 ui.write_err(hint)
188 requirements.discard(requirementsmod.DIRSTATE_V2_REQUIREMENT)
189 fake_op = AutoUpgradeOperation(requirements)
190 engine.upgrade_dirstate(repo.ui, repo, fake_op, b'v2', b'v1')
191
192 return action
193
194
139 AUTO_UPGRADE_ACTIONS = [
195 AUTO_UPGRADE_ACTIONS = [
196 get_dirstate_v2_action,
140 get_share_safe_action,
197 get_share_safe_action,
141 get_tracked_hint_action,
198 get_tracked_hint_action,
142 ]
199 ]
@@ -736,6 +736,11 b' const AUTO_UPGRADES: &[((&str, &str), (&'
736 ("format", "use-dirstate-tracked-hint"),
736 ("format", "use-dirstate-tracked-hint"),
737 requirements::DIRSTATE_TRACKED_HINT_V1,
737 requirements::DIRSTATE_TRACKED_HINT_V1,
738 ),
738 ),
739 (
740 ("use-dirstate-v2", "automatic-upgrade-of-mismatching-repositories"),
741 ("format", "use-dirstate-v2"),
742 requirements::DIRSTATE_V2_REQUIREMENT,
743 ),
739 ];
744 ];
740
745
741 /// Mercurial allows users to automatically upgrade their repository.
746 /// Mercurial allows users to automatically upgrade their repository.
@@ -1600,6 +1600,8 b' Separate sections from subsections'
1600
1600
1601 "use-dirstate-v2"
1601 "use-dirstate-v2"
1602
1602
1603 "use-dirstate-v2.automatic-upgrade-of-mismatching-repositories"
1604
1603 "use-dirstate-tracked-hint"
1605 "use-dirstate-tracked-hint"
1604
1606
1605 "use-dirstate-tracked-hint.automatic-upgrade-of-mismatching-repositories"
1607 "use-dirstate-tracked-hint.automatic-upgrade-of-mismatching-repositories"
@@ -1994,3 +1994,70 b' downgrade'
1994 dirstate-v2: no
1994 dirstate-v2: no
1995
1995
1996 $ cd ..
1996 $ cd ..
1997
1998 Test automatic upgrade/downgrade
1999 ================================
2000
2001
2002 For dirstate v2
2003 ---------------
2004
2005 create an initial repository
2006
2007 $ hg init auto-upgrade \
2008 > --config format.use-dirstate-v2=no \
2009 > --config format.use-dirstate-tracked-hint=yes \
2010 > --config format.use-share-safe=no
2011 $ hg debugbuilddag -R auto-upgrade --new-file .+5
2012 $ hg -R auto-upgrade update
2013 6 files updated, 0 files merged, 0 files removed, 0 files unresolved
2014 $ hg debugformat -R auto-upgrade | grep dirstate-v2
2015 dirstate-v2: no
2016
2017 upgrade it to dirstate-v2 automatically
2018
2019 $ hg status -R auto-upgrade \
2020 > --config format.use-dirstate-v2.automatic-upgrade-of-mismatching-repositories=yes \
2021 > --config format.use-dirstate-v2=yes
2022 automatically upgrading repository to the `dirstate-v2` feature
2023 (see `hg help config.format.use-dirstate-v2` for details)
2024 $ hg debugformat -R auto-upgrade | grep dirstate-v2
2025 dirstate-v2: yes
2026
2027 downgrade it from dirstate-v2 automatically
2028
2029 $ hg status -R auto-upgrade \
2030 > --config format.use-dirstate-v2.automatic-upgrade-of-mismatching-repositories=yes \
2031 > --config format.use-dirstate-v2=no
2032 automatically downgrading repository from the `dirstate-v2` feature
2033 (see `hg help config.format.use-dirstate-v2` for details)
2034 $ hg debugformat -R auto-upgrade | grep dirstate-v2
2035 dirstate-v2: no
2036
2037
2038 For multiple change at the same time
2039 ------------------------------------
2040
2041 $ hg debugformat -R auto-upgrade | egrep '(dirstate-v2|tracked|share-safe)'
2042 dirstate-v2: no
2043 tracked-hint: yes
2044 share-safe: no
2045
2046 $ hg status -R auto-upgrade \
2047 > --config format.use-dirstate-v2.automatic-upgrade-of-mismatching-repositories=yes \
2048 > --config format.use-dirstate-v2=yes \
2049 > --config format.use-dirstate-tracked-hint.automatic-upgrade-of-mismatching-repositories=yes \
2050 > --config format.use-dirstate-tracked-hint=no\
2051 > --config format.use-share-safe.automatic-upgrade-of-mismatching-repositories=yes \
2052 > --config format.use-share-safe=yes
2053 automatically upgrading repository to the `dirstate-v2` feature
2054 (see `hg help config.format.use-dirstate-v2` for details)
2055 automatically upgrading repository to the `share-safe` feature
2056 (see `hg help config.format.use-share-safe` for details)
2057 automatically downgrading repository from the `tracked-hint` feature
2058 (see `hg help config.format.use-dirstate-tracked-hint` for details)
2059 $ hg debugformat -R auto-upgrade | egrep '(dirstate-v2|tracked|share-safe)'
2060 dirstate-v2: yes
2061 tracked-hint: no
2062 share-safe: yes
2063
General Comments 0
You need to be logged in to leave comments. Login now