author | Pierre-Yves David <pierre-yves.david@octobus.net> |
Tue, 05 Apr 2022 05:20:05 +0200 | |
changeset 49194 | e4b31016e194 |
parent 49192 | 2ab79873786e |
child 49195 | 411d591e0a27 |
permissions | -rw-r--r-- |
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 |
) |
2ab79873786e
auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
47 |
|
2ab79873786e
auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
48 |
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
|
49 |
|
2ab79873786e
auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
50 |
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
|
51 |
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
|
52 |
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
|
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 |
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
|
55 |
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
|
56 |
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
|
57 |
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
|
58 |
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
|
59 |
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
|
60 |
) |
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 |
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
|
62 |
|
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 |
def 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
|
64 |
if not ui.quiet: |
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 |
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
|
66 |
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
|
67 |
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
|
68 |
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
|
69 |
|
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 |
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
|
71 |
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
|
72 |
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
|
73 |
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
|
74 |
) |
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 |
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
|
76 |
|
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 |
def 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
|
78 |
if not ui.quiet: |
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 |
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
|
80 |
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
|
81 |
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
|
82 |
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
|
83 |
|
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 |
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
|
85 |
|
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 |
|
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
|
87 |
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
|
88 |
"""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
|
89 |
|
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
|
90 |
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
|
91 |
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
|
92 |
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
|
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 |
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
|
95 |
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
|
96 |
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
|
97 |
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
|
98 |
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
|
99 |
) |
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 |
|
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 |
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
|
102 |
|
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 |
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
|
104 |
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
|
105 |
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
|
106 |
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
|
107 |
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
|
108 |
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
|
109 |
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
|
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 |
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
|
112 |
|
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 |
def 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
|
114 |
if not ui.quiet: |
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 |
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
|
116 |
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
|
117 |
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
|
118 |
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
|
119 |
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
|
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 |
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
|
122 |
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
|
123 |
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
|
124 |
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
|
125 |
) |
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 |
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
|
127 |
|
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 |
def 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
|
129 |
if not ui.quiet: |
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 |
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
|
131 |
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
|
132 |
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
|
133 |
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
|
134 |
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
|
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 |
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
|
137 |
|
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 |
|
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
|
139 |
AUTO_UPGRADE_ACTIONS = [ |
2ab79873786e
auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
140 |
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
|
141 |
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
|
142 |
] |
2ab79873786e
auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
143 |
|
2ab79873786e
auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
144 |
|
2ab79873786e
auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
145 |
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
|
146 |
"""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
|
147 |
|
2ab79873786e
auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
148 |
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
|
149 |
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
|
150 |
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
|
151 |
|
2ab79873786e
auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
152 |
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
|
153 |
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
|
154 |
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
|
155 |
|
2ab79873786e
auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
156 |
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
|
157 |
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
|
158 |
""" |
2ab79873786e
auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
159 |
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
|
160 |
|
2ab79873786e
auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
161 |
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
|
162 |
|
2ab79873786e
auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
163 |
while not clear: |
2ab79873786e
auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
164 |
loop += 1 |
2ab79873786e
auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
165 |
if loop > 100: |
2ab79873786e
auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
166 |
# XXX basic protection against infinite loop, make it better. |
2ab79873786e
auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
167 |
raise error.ProgrammingError("Too many auto upgrade loops") |
2ab79873786e
auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
168 |
clear = True |
2ab79873786e
auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
169 |
for get_action in AUTO_UPGRADE_ACTIONS: |
2ab79873786e
auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
170 |
action = get_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
|
171 |
if action is not 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
|
172 |
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
|
173 |
with repo.wlock(wait=False), repo.lock(wait=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
|
174 |
action = get_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
|
175 |
if action is not 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
|
176 |
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
|
177 |
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
|
178 |
return repo |