Mercurial > hg
annotate mercurial/upgrade_utils/auto_upgrade.py @ 52095:3e7b9357bbb8
tests: add coverage to for `HGCB_BUNDLE_BASENAME` with special characters
Per request on IRC, to show the behavior of dropping the quoting of
`HGCB_BUNDLE_BASENAME` in the next commit. This current failure is basically
the same error and output that currently happens on Windows with any path (even
without the embedded quote). The only difference is Windows doesn't print the
`cp: cannot stat ...` line.
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Mon, 21 Oct 2024 15:24:55 -0400 |
parents | 1c5810ce737e |
children |
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. |
51864
1c5810ce737e
typing: add `from __future__ import annotations` to remaining source files
Matt Harbison <matt_harbison@yahoo.com>
parents:
49342
diff
changeset
|
7 |
1c5810ce737e
typing: add `from __future__ import annotations` to remaining source files
Matt Harbison <matt_harbison@yahoo.com>
parents:
49342
diff
changeset
|
8 from __future__ import annotations |
1c5810ce737e
typing: add `from __future__ import annotations` to remaining source files
Matt Harbison <matt_harbison@yahoo.com>
parents:
49342
diff
changeset
|
9 |
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
|
10 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
|
11 |
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 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
|
13 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
|
14 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
|
15 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
|
16 ) |
2ab79873786e
auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
17 |
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
|
18 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
|
19 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
|
20 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
|
21 ) |
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 |
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 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
|
25 """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
|
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 (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
|
28 """ |
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 |
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 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
|
31 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
|
32 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
|
33 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
|
34 ) |
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
|
35 |
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
|
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 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
|
38 """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
|
39 |
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 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
|
41 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
|
42 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
|
43 """ |
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 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
|
45 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
|
46 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
|
47 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
|
48 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
|
49 ) |
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
|
50 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
|
51 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
|
52 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
|
53 ) |
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
|
54 |
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 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
|
56 |
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 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
|
58 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
|
59 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
|
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 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
|
62 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
|
63 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
|
64 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
|
65 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
|
66 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
|
67 ) |
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 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
|
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 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
|
71 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
|
72 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
|
73 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
|
74 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
|
75 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
|
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 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
|
78 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
|
79 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
|
80 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
|
81 ) |
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 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
|
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 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
|
85 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
|
86 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
|
87 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
|
88 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
|
89 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
|
90 |
2ab79873786e
auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
91 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
|
92 |
2ab79873786e
auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
93 |
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
|
94 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
|
95 """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
|
96 |
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 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
|
98 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
|
99 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
|
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 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
|
102 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
|
103 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
|
104 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
|
105 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
|
106 ) |
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
|
107 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
|
108 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
|
109 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
|
110 ) |
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
|
111 |
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 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
|
113 |
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 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
|
115 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
|
116 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
|
117 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
|
118 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
|
119 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
|
120 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
|
121 ) |
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 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
|
123 |
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 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
|
125 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
|
126 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
|
127 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
|
128 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
|
129 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
|
130 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
|
131 |
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 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
|
133 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
|
134 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
|
135 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
|
136 ) |
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 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
|
138 |
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 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
|
140 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
|
141 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
|
142 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
|
143 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
|
144 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
|
145 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
|
146 |
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
|
147 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
|
148 |
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
|
149 |
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
|
150 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
|
151 """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
|
152 |
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 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
|
154 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
|
155 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
|
156 """ |
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 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
|
158 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
|
159 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
|
160 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
|
161 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
|
162 ) |
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
|
163 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
|
164 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
|
165 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
|
166 ) |
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
|
167 |
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 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
|
169 |
49340
1b9114709428
auto-upgrade: rename a variable to match the actual content
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49339
diff
changeset
|
170 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
|
171 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
|
172 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
|
173 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
|
174 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
|
175 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
|
176 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
|
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 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
|
179 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
|
180 ) |
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 |
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 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
|
183 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
|
184 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
|
185 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
|
186 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
|
187 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
|
188 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
|
189 |
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 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
|
191 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
|
192 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
|
193 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
|
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 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
|
196 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
|
197 ) |
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 |
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 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
|
200 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
|
201 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
|
202 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
|
203 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
|
204 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
|
205 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
|
206 |
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
|
207 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
|
208 |
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
|
209 |
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
|
210 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
|
211 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
|
212 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
|
213 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
|
214 ] |
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 |
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 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
|
218 """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
|
219 |
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 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
|
221 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
|
222 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
|
223 |
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 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
|
225 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
|
226 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
|
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 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
|
229 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
|
230 """ |
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 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
|
232 |
2ab79873786e
auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
233 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
|
234 |
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
|
235 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
|
236 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
|
237 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
|
238 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
|
239 # 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
|
240 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
|
241 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
|
242 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
|
243 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
|
244 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
|
245 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
|
246 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
|
247 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
|
248 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
|
249 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
|
250 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
|
251 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
|
252 # 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
|
253 # 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
|
254 # 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
|
255 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
|
256 |
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
|
257 return repo |