comparison mercurial/upgrade_utils/auto_upgrade.py @ 49195:411d591e0a27

auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2 This is similar to what we introduced for `share-safe`, but apply to the tracked-hint feature. Differential Revision: https://phab.mercurial-scm.org/D12614
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Tue, 22 Mar 2022 14:14:52 +0100
parents e4b31016e194
children 71774d799de7
comparison
equal deleted inserted replaced
49194:e4b31016e194 49195:411d591e0a27
134 engine.upgrade_tracked_hint(ui, repo, op, add=False) 134 engine.upgrade_tracked_hint(ui, repo, op, add=False)
135 135
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 ]
143 200
144 201