comparison mercurial/upgrade_utils/auto_upgrade.py @ 49194:e4b31016e194

auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint This is similar to what we introduced for `share-safe`, but apply to the tracked-hint feature. Differential Revision: https://phab.mercurial-scm.org/D12613
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Tue, 05 Apr 2022 05:20:05 +0200
parents 2ab79873786e
children 411d591e0a27
comparison
equal deleted inserted replaced
49193:566066826e7c 49194:e4b31016e194
9 from .. import ( 9 from .. import (
10 error, 10 error,
11 requirements as requirementsmod, 11 requirements as requirementsmod,
12 scmutil, 12 scmutil,
13 ) 13 )
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 )
14 32
15 33
16 def get_share_safe_action(repo): 34 def get_share_safe_action(repo):
17 """return an automatic-upgrade action for `share-safe` if applicable 35 """return an automatic-upgrade action for `share-safe` if applicable
18 36
64 scmutil.writereporequirements(repo, requirements) 82 scmutil.writereporequirements(repo, requirements)
65 83
66 return action 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 AUTO_UPGRADE_ACTIONS = [ 139 AUTO_UPGRADE_ACTIONS = [
70 get_share_safe_action, 140 get_share_safe_action,
141 get_tracked_hint_action,
71 ] 142 ]
72 143
73 144
74 def may_auto_upgrade(repo, maker_func): 145 def may_auto_upgrade(repo, maker_func):
75 """potentially perform auto-upgrade and return the final repository to use 146 """potentially perform auto-upgrade and return the final repository to use