annotate mercurial/upgrade_utils/auto_upgrade.py @ 49342:67b210bb5ce2

auto-upgrade: add an option to silence the tracked-hint message For well tested case, the message can get in the way, so we add a way to disable it.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Tue, 14 Jun 2022 15:22:05 +0200
parents b38f5063a0c6
children 1c5810ce737e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
49192
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
1 # upgrade.py - functions for automatic upgrade of Mercurial repository
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
2 #
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
3 # Copyright (c) 2022-present, Pierre-Yves David
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
4 #
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
5 # This software may be used and distributed according to the terms of the
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
6 # GNU General Public License version 2 or any later version.
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
7 from ..i18n import _
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
8
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
9 from .. import (
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
10 error,
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
11 requirements as requirementsmod,
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
12 scmutil,
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
13 )
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
14
49194
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
15 from . import (
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
16 actions,
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
17 engine,
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
18 )
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
19
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
20
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
21 class AutoUpgradeOperation(actions.BaseOperation):
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
22 """A limited Upgrade Operation used to run simple auto upgrade task
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
23
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
24 (Expand it as needed in the future)
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
25 """
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
26
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
27 def __init__(self, req):
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
28 super().__init__(
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
29 new_requirements=req,
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
30 backup_store=False,
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
31 )
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
32
49192
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
33
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
34 def get_share_safe_action(repo):
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
35 """return an automatic-upgrade action for `share-safe` if applicable
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
36
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
37 If no action is needed, return None, otherwise return a callback to upgrade
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
38 or downgrade the repository according the configuration and repository
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
39 format.
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
40 """
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
41 ui = repo.ui
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
42 requirements = repo.requirements
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
43 auto_upgrade_share_source = ui.configbool(
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
44 b'format',
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
45 b'use-share-safe.automatic-upgrade-of-mismatching-repositories',
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
46 )
49339
9e203cda3238 auto-upgrade: add an option to silence the share-safe message
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49200
diff changeset
47 auto_upgrade_quiet = ui.configbool(
9e203cda3238 auto-upgrade: add an option to silence the share-safe message
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49200
diff changeset
48 b'format',
9e203cda3238 auto-upgrade: add an option to silence the share-safe message
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49200
diff changeset
49 b'use-share-safe.automatic-upgrade-of-mismatching-repositories:quiet',
9e203cda3238 auto-upgrade: add an option to silence the share-safe message
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49200
diff changeset
50 )
49192
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
51
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
52 action = None
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
53
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
54 if (
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
55 auto_upgrade_share_source
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
56 and requirementsmod.SHARED_REQUIREMENT not in requirements
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
57 ):
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
58 sf_config = ui.configbool(b'format', b'use-share-safe')
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
59 sf_local = requirementsmod.SHARESAFE_REQUIREMENT in requirements
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
60 if sf_config and not sf_local:
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
61 msg = _(
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
62 b"automatically upgrading repository to the `share-safe`"
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
63 b" feature\n"
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
64 )
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
65 hint = b"(see `hg help config.format.use-share-safe` for details)\n"
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
66
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
67 def action():
49339
9e203cda3238 auto-upgrade: add an option to silence the share-safe message
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49200
diff changeset
68 if not (ui.quiet or auto_upgrade_quiet):
49192
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
69 ui.write_err(msg)
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
70 ui.write_err(hint)
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
71 requirements.add(requirementsmod.SHARESAFE_REQUIREMENT)
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
72 scmutil.writereporequirements(repo, requirements)
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
73
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
74 elif sf_local and not sf_config:
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
75 msg = _(
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
76 b"automatically downgrading repository from the `share-safe`"
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
77 b" feature\n"
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
78 )
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
79 hint = b"(see `hg help config.format.use-share-safe` for details)\n"
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
80
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
81 def action():
49339
9e203cda3238 auto-upgrade: add an option to silence the share-safe message
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49200
diff changeset
82 if not (ui.quiet or auto_upgrade_quiet):
49192
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
83 ui.write_err(msg)
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
84 ui.write_err(hint)
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
85 requirements.discard(requirementsmod.SHARESAFE_REQUIREMENT)
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
86 scmutil.writereporequirements(repo, requirements)
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
87
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
88 return action
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
89
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
90
49194
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
91 def get_tracked_hint_action(repo):
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
92 """return an automatic-upgrade action for `tracked-hint` if applicable
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
93
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
94 If no action is needed, return None, otherwise return a callback to upgrade
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
95 or downgrade the repository according the configuration and repository
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
96 format.
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
97 """
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
98 ui = repo.ui
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
99 requirements = set(repo.requirements)
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
100 auto_upgrade_tracked_hint = ui.configbool(
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
101 b'format',
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
102 b'use-dirstate-tracked-hint.automatic-upgrade-of-mismatching-repositories',
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
103 )
49342
67b210bb5ce2 auto-upgrade: add an option to silence the tracked-hint message
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49341
diff changeset
104 auto_upgrade_quiet = ui.configbool(
67b210bb5ce2 auto-upgrade: add an option to silence the tracked-hint message
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49341
diff changeset
105 b'format',
67b210bb5ce2 auto-upgrade: add an option to silence the tracked-hint message
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49341
diff changeset
106 b'use-dirstate-tracked-hint.automatic-upgrade-of-mismatching-repositories:quiet',
67b210bb5ce2 auto-upgrade: add an option to silence the tracked-hint message
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49341
diff changeset
107 )
49194
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
108
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
109 action = None
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
110
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
111 if auto_upgrade_tracked_hint:
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
112 th_config = ui.configbool(b'format', b'use-dirstate-tracked-hint')
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
113 th_local = requirementsmod.DIRSTATE_TRACKED_HINT_V1 in requirements
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
114 if th_config and not th_local:
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
115 msg = _(
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
116 b"automatically upgrading repository to the `tracked-hint`"
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
117 b" feature\n"
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
118 )
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
119 hint = b"(see `hg help config.format.use-dirstate-tracked-hint` for details)\n"
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
120
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
121 def action():
49342
67b210bb5ce2 auto-upgrade: add an option to silence the tracked-hint message
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49341
diff changeset
122 if not (ui.quiet or auto_upgrade_quiet):
49194
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
123 ui.write_err(msg)
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
124 ui.write_err(hint)
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
125 requirements.add(requirementsmod.DIRSTATE_TRACKED_HINT_V1)
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
126 op = AutoUpgradeOperation(requirements)
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
127 engine.upgrade_tracked_hint(ui, repo, op, add=True)
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
128
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
129 elif th_local and not th_config:
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
130 msg = _(
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
131 b"automatically downgrading repository from the `tracked-hint`"
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
132 b" feature\n"
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
133 )
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
134 hint = b"(see `hg help config.format.use-dirstate-tracked-hint` for details)\n"
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
135
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
136 def action():
49342
67b210bb5ce2 auto-upgrade: add an option to silence the tracked-hint message
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49341
diff changeset
137 if not (ui.quiet or auto_upgrade_quiet):
49194
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
138 ui.write_err(msg)
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
139 ui.write_err(hint)
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
140 requirements.discard(requirementsmod.DIRSTATE_TRACKED_HINT_V1)
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
141 op = AutoUpgradeOperation(requirements)
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
142 engine.upgrade_tracked_hint(ui, repo, op, add=False)
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
143
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
144 return action
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
145
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
146
49195
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
147 def get_dirstate_v2_action(repo):
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
148 """return an automatic-upgrade action for `dirstate-v2` if applicable
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
149
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
150 If no action is needed, return None, otherwise return a callback to upgrade
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
151 or downgrade the repository according the configuration and repository
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
152 format.
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
153 """
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
154 ui = repo.ui
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
155 requirements = set(repo.requirements)
49340
1b9114709428 auto-upgrade: rename a variable to match the actual content
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49339
diff changeset
156 auto_upgrade_dv2 = ui.configbool(
49195
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
157 b'format',
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
158 b'use-dirstate-v2.automatic-upgrade-of-mismatching-repositories',
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
159 )
49341
b38f5063a0c6 auto-upgrade: add an option to silence the dirstate-v2 message
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49340
diff changeset
160 auto_upgrade_dv2_quiet = ui.configbool(
b38f5063a0c6 auto-upgrade: add an option to silence the dirstate-v2 message
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49340
diff changeset
161 b'format',
b38f5063a0c6 auto-upgrade: add an option to silence the dirstate-v2 message
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49340
diff changeset
162 b'use-dirstate-v2.automatic-upgrade-of-mismatching-repositories:quiet',
b38f5063a0c6 auto-upgrade: add an option to silence the dirstate-v2 message
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49340
diff changeset
163 )
49195
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
164
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
165 action = None
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
166
49340
1b9114709428 auto-upgrade: rename a variable to match the actual content
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49339
diff changeset
167 if auto_upgrade_dv2:
49195
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
168 d2_config = ui.configbool(b'format', b'use-dirstate-v2')
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
169 d2_local = requirementsmod.DIRSTATE_V2_REQUIREMENT in requirements
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
170 if d2_config and not d2_local:
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
171 msg = _(
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
172 b"automatically upgrading repository to the `dirstate-v2`"
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
173 b" feature\n"
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
174 )
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
175 hint = (
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
176 b"(see `hg help config.format.use-dirstate-v2` for details)\n"
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
177 )
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
178
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
179 def action():
49341
b38f5063a0c6 auto-upgrade: add an option to silence the dirstate-v2 message
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49340
diff changeset
180 if not (ui.quiet or auto_upgrade_dv2_quiet):
49195
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
181 ui.write_err(msg)
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
182 ui.write_err(hint)
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
183 requirements.add(requirementsmod.DIRSTATE_V2_REQUIREMENT)
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
184 fake_op = AutoUpgradeOperation(requirements)
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
185 engine.upgrade_dirstate(repo.ui, repo, fake_op, b'v1', b'v2')
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
186
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
187 elif d2_local and not d2_config:
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
188 msg = _(
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
189 b"automatically downgrading repository from the `dirstate-v2`"
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
190 b" feature\n"
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
191 )
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
192 hint = (
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
193 b"(see `hg help config.format.use-dirstate-v2` for details)\n"
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
194 )
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
195
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
196 def action():
49341
b38f5063a0c6 auto-upgrade: add an option to silence the dirstate-v2 message
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49340
diff changeset
197 if not (ui.quiet or auto_upgrade_dv2_quiet):
49195
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
198 ui.write_err(msg)
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
199 ui.write_err(hint)
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
200 requirements.discard(requirementsmod.DIRSTATE_V2_REQUIREMENT)
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
201 fake_op = AutoUpgradeOperation(requirements)
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
202 engine.upgrade_dirstate(repo.ui, repo, fake_op, b'v2', b'v1')
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
203
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
204 return action
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
205
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
206
49192
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
207 AUTO_UPGRADE_ACTIONS = [
49195
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49194
diff changeset
208 get_dirstate_v2_action,
49192
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
209 get_share_safe_action,
49194
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49192
diff changeset
210 get_tracked_hint_action,
49192
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
211 ]
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
212
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
213
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
214 def may_auto_upgrade(repo, maker_func):
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
215 """potentially perform auto-upgrade and return the final repository to use
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
216
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
217 Auto-upgrade are "quick" repository upgrade that might automatically be run
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
218 by "any" repository access. See `hg help config.format` for automatic
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
219 upgrade documentation.
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
220
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
221 note: each relevant upgrades are done one after the other for simplicity.
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
222 This avoid having repository is partially inconsistent state while
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
223 upgrading.
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
224
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
225 repo: the current repository instance
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
226 maker_func: a factory function that can recreate a repository after an upgrade
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
227 """
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
228 clear = False
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
229
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
230 loop = 0
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
231
49200
71774d799de7 auto-upgrade: skip the operation if the repository cannot be locked
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49195
diff changeset
232 try:
71774d799de7 auto-upgrade: skip the operation if the repository cannot be locked
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49195
diff changeset
233 while not clear:
71774d799de7 auto-upgrade: skip the operation if the repository cannot be locked
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49195
diff changeset
234 loop += 1
71774d799de7 auto-upgrade: skip the operation if the repository cannot be locked
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49195
diff changeset
235 if loop > 100:
71774d799de7 auto-upgrade: skip the operation if the repository cannot be locked
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49195
diff changeset
236 # XXX basic protection against infinite loop, make it better.
71774d799de7 auto-upgrade: skip the operation if the repository cannot be locked
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49195
diff changeset
237 raise error.ProgrammingError("Too many auto upgrade loops")
71774d799de7 auto-upgrade: skip the operation if the repository cannot be locked
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49195
diff changeset
238 clear = True
71774d799de7 auto-upgrade: skip the operation if the repository cannot be locked
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49195
diff changeset
239 for get_action in AUTO_UPGRADE_ACTIONS:
71774d799de7 auto-upgrade: skip the operation if the repository cannot be locked
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49195
diff changeset
240 action = get_action(repo)
71774d799de7 auto-upgrade: skip the operation if the repository cannot be locked
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49195
diff changeset
241 if action is not None:
71774d799de7 auto-upgrade: skip the operation if the repository cannot be locked
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49195
diff changeset
242 clear = False
71774d799de7 auto-upgrade: skip the operation if the repository cannot be locked
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49195
diff changeset
243 with repo.wlock(wait=False), repo.lock(wait=False):
71774d799de7 auto-upgrade: skip the operation if the repository cannot be locked
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49195
diff changeset
244 action = get_action(repo)
71774d799de7 auto-upgrade: skip the operation if the repository cannot be locked
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49195
diff changeset
245 if action is not None:
71774d799de7 auto-upgrade: skip the operation if the repository cannot be locked
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49195
diff changeset
246 action()
71774d799de7 auto-upgrade: skip the operation if the repository cannot be locked
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49195
diff changeset
247 repo = maker_func()
71774d799de7 auto-upgrade: skip the operation if the repository cannot be locked
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49195
diff changeset
248 except error.LockError:
71774d799de7 auto-upgrade: skip the operation if the repository cannot be locked
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49195
diff changeset
249 # if we cannot get the lock, ignore the auto-upgrade attemps and
71774d799de7 auto-upgrade: skip the operation if the repository cannot be locked
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49195
diff changeset
250 # proceed. We might want to make this behavior configurable in the
71774d799de7 auto-upgrade: skip the operation if the repository cannot be locked
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49195
diff changeset
251 # future.
71774d799de7 auto-upgrade: skip the operation if the repository cannot be locked
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49195
diff changeset
252 pass
71774d799de7 auto-upgrade: skip the operation if the repository cannot be locked
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49195
diff changeset
253
49192
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
254 return repo