annotate mercurial/upgrade.py @ 46236:eec47efe219d

sharesafe: add functionality to automatically downgrade shares Reasoning is same as previous patch which adds automatic upgrade support. Downgrade is required as if automatic upgrade is enabled, all shares upgrade and then source repository downgrades, shares won't work. We need to downgrade them. Differential Revision: https://phab.mercurial-scm.org/D9680
author Pulkit Goyal <7895pulkit@gmail.com>
date Wed, 06 Jan 2021 18:31:16 +0530
parents 0babe12ef35d
children 9796cf108e4e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
31894
9379689b6c10 upgrade: update the header comment
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31893
diff changeset
1 # upgrade.py - functions for in place upgrade of Mercurial repository
4702
18e91c9def0c strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
2 #
31895
783b4c9bd5f5 upgrade: update the copyright statement
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31894
diff changeset
3 # Copyright (c) 2016-present, Gregory Szorc
4702
18e91c9def0c strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
4 #
8225
46293a0c7e9f updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents: 8073
diff changeset
5 # This software may be used and distributed according to the terms of the
10263
25e572394f5c Update license to GPLv2+
Matt Mackall <mpm@selenic.com>
parents: 9150
diff changeset
6 # GNU General Public License version 2 or any later version.
4702
18e91c9def0c strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
7
25970
d1419cfbd4f4 repair: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25874
diff changeset
8 from __future__ import absolute_import
d1419cfbd4f4 repair: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25874
diff changeset
9
d1419cfbd4f4 repair: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25874
diff changeset
10 from .i18n import _
d1419cfbd4f4 repair: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25874
diff changeset
11 from . import (
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26425
diff changeset
12 error,
35352
06987c6971be upgrade: more standard creation of the temporary repository
Boris Feld <boris.feld@octobus.net>
parents: 35351
diff changeset
13 hg,
31893
165428b05fca upgrade: import 'localrepo' globally
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31875
diff changeset
14 localrepo,
46235
0babe12ef35d sharesafe: introduce functionality to automatically upgrade shares
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46231
diff changeset
15 lock as lockmod,
38198
2ce60954b1b7 py3: wrap tempfile.mkdtemp() to use bytes path
Yuya Nishihara <yuya@tcha.org>
parents: 37444
diff changeset
16 pycompat,
46235
0babe12ef35d sharesafe: introduce functionality to automatically upgrade shares
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46231
diff changeset
17 requirements as requirementsmod,
0babe12ef35d sharesafe: introduce functionality to automatically upgrade shares
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46231
diff changeset
18 scmutil,
46050
f105c49e89cd upgrade: split actual upgrade code away from the main module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46039
diff changeset
19 )
f105c49e89cd upgrade: split actual upgrade code away from the main module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46039
diff changeset
20
f105c49e89cd upgrade: split actual upgrade code away from the main module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46039
diff changeset
21 from .upgrade_utils import (
46051
4b89cf08d8dc upgrade: split definition and management of the actions from the main code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46050
diff changeset
22 actions as upgrade_actions,
46050
f105c49e89cd upgrade: split actual upgrade code away from the main module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46039
diff changeset
23 engine as upgrade_engine,
25970
d1419cfbd4f4 repair: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25874
diff changeset
24 )
d1419cfbd4f4 repair: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25874
diff changeset
25
46235
0babe12ef35d sharesafe: introduce functionality to automatically upgrade shares
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46231
diff changeset
26 from .utils import (
0babe12ef35d sharesafe: introduce functionality to automatically upgrade shares
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46231
diff changeset
27 stringutil,
0babe12ef35d sharesafe: introduce functionality to automatically upgrade shares
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46231
diff changeset
28 )
0babe12ef35d sharesafe: introduce functionality to automatically upgrade shares
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46231
diff changeset
29
46051
4b89cf08d8dc upgrade: split definition and management of the actions from the main code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46050
diff changeset
30 allformatvariant = upgrade_actions.allformatvariant
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43031
diff changeset
31
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43031
diff changeset
32
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43031
diff changeset
33 def upgraderepo(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43031
diff changeset
34 ui,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43031
diff changeset
35 repo,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43031
diff changeset
36 run=False,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43031
diff changeset
37 optimize=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43031
diff changeset
38 backup=True,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43031
diff changeset
39 manifest=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43031
diff changeset
40 changelog=None,
46012
7c539f0febbe upgrade: add an explicite --filelogs arguments
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46010
diff changeset
41 filelogs=None,
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43031
diff changeset
42 ):
30775
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
43 """Upgrade a repository in place."""
41091
5608b5a6c323 upgrade: add '-' in optimization name
Boris Feld <boris.feld@octobus.net>
parents: 41007
diff changeset
44 if optimize is None:
46208
083438d6f403 upgrade: drop support for old style optimization names
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46207
diff changeset
45 optimize = {}
30775
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
46 repo = repo.unfiltered()
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
47
46050
f105c49e89cd upgrade: split actual upgrade code away from the main module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46039
diff changeset
48 revlogs = set(upgrade_engine.UPGRADE_ALL_REVLOGS)
45996
53bde3ad0270 upgrade: directly use the upgrade action constant
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45995
diff changeset
49 specentries = (
46050
f105c49e89cd upgrade: split actual upgrade code away from the main module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46039
diff changeset
50 (upgrade_engine.UPGRADE_CHANGELOG, changelog),
f105c49e89cd upgrade: split actual upgrade code away from the main module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46039
diff changeset
51 (upgrade_engine.UPGRADE_MANIFEST, manifest),
f105c49e89cd upgrade: split actual upgrade code away from the main module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46039
diff changeset
52 (upgrade_engine.UPGRADE_FILELOGS, filelogs),
45996
53bde3ad0270 upgrade: directly use the upgrade action constant
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45995
diff changeset
53 )
42840
cf2b765cecd7 upgrade: add an argument to control manifest upgrade
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42715
diff changeset
54 specified = [(y, x) for (y, x) in specentries if x is not None]
cf2b765cecd7 upgrade: add an argument to control manifest upgrade
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42715
diff changeset
55 if specified:
cf2b765cecd7 upgrade: add an argument to control manifest upgrade
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42715
diff changeset
56 # we have some limitation on revlogs to be recloned
cf2b765cecd7 upgrade: add an argument to control manifest upgrade
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42715
diff changeset
57 if any(x for y, x in specified):
cf2b765cecd7 upgrade: add an argument to control manifest upgrade
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42715
diff changeset
58 revlogs = set()
45996
53bde3ad0270 upgrade: directly use the upgrade action constant
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45995
diff changeset
59 for upgrade, enabled in specified:
42840
cf2b765cecd7 upgrade: add an argument to control manifest upgrade
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42715
diff changeset
60 if enabled:
45996
53bde3ad0270 upgrade: directly use the upgrade action constant
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45995
diff changeset
61 revlogs.add(upgrade)
42840
cf2b765cecd7 upgrade: add an argument to control manifest upgrade
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42715
diff changeset
62 else:
cf2b765cecd7 upgrade: add an argument to control manifest upgrade
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42715
diff changeset
63 # none are enabled
45996
53bde3ad0270 upgrade: directly use the upgrade action constant
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45995
diff changeset
64 for upgrade, __ in specified:
53bde3ad0270 upgrade: directly use the upgrade action constant
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45995
diff changeset
65 revlogs.discard(upgrade)
42840
cf2b765cecd7 upgrade: add an argument to control manifest upgrade
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42715
diff changeset
66
30775
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
67 # Ensure the repository can be upgraded.
46052
f4f956342cf1 upgrade: move requirements checking in a dedicated function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46051
diff changeset
68 upgrade_actions.check_source_requirements(repo)
30775
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
69
46055
72b7b4bf3e65 upgrade: extract the checking of target requirements change
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46054
diff changeset
70 default_options = localrepo.defaultcreateopts(repo.ui)
72b7b4bf3e65 upgrade: extract the checking of target requirements change
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46054
diff changeset
71 newreqs = localrepo.newreporequirements(repo.ui, default_options)
46051
4b89cf08d8dc upgrade: split definition and management of the actions from the main code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46050
diff changeset
72 newreqs.update(upgrade_actions.preservedrequirements(repo))
30775
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
73
46055
72b7b4bf3e65 upgrade: extract the checking of target requirements change
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46054
diff changeset
74 upgrade_actions.check_requirements_changes(repo, newreqs)
30775
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
75
30776
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
76 # Find and validate all improvements that can be made.
46051
4b89cf08d8dc upgrade: split definition and management of the actions from the main code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46050
diff changeset
77 alloptimizations = upgrade_actions.findoptimizations(repo)
30776
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
78
31899
cccd8e1538b0 upgrade: filter optimizations outside of 'determineactions'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31898
diff changeset
79 # Apply and Validate arguments.
cccd8e1538b0 upgrade: filter optimizations outside of 'determineactions'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31898
diff changeset
80 optimizations = []
cccd8e1538b0 upgrade: filter optimizations outside of 'determineactions'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31898
diff changeset
81 for o in alloptimizations:
cccd8e1538b0 upgrade: filter optimizations outside of 'determineactions'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31898
diff changeset
82 if o.name in optimize:
cccd8e1538b0 upgrade: filter optimizations outside of 'determineactions'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31898
diff changeset
83 optimizations.append(o)
cccd8e1538b0 upgrade: filter optimizations outside of 'determineactions'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31898
diff changeset
84 optimize.discard(o.name)
cccd8e1538b0 upgrade: filter optimizations outside of 'determineactions'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31898
diff changeset
85
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43031
diff changeset
86 if optimize: # anything left is unknown
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43031
diff changeset
87 raise error.Abort(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
88 _(b'unknown optimization action requested: %s')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
89 % b', '.join(sorted(optimize)),
43117
8ff1ecfadcd1 cleanup: join string literals that are already on one line
Martin von Zweigbergk <martinvonz@google.com>
parents: 43089
diff changeset
90 hint=_(b'run without arguments to see valid optimizations'),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43031
diff changeset
91 )
30776
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
92
46205
53d083fa1f83 upgrade: rename finddeficiences() to find_format_upgrades()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46192
diff changeset
93 format_upgrades = upgrade_actions.find_format_upgrades(repo)
46210
6b40aac4da8e upgrade: rename actions to upgrade_actions
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46209
diff changeset
94 up_actions = upgrade_actions.determine_upgrade_actions(
46209
a51d345f1404 upgrade: move optimization addition to determineactions()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46208
diff changeset
95 repo, format_upgrades, optimizations, repo.requirements, newreqs
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43031
diff changeset
96 )
46213
30310886d423 upgrade: introduce post upgrade and downgrade message for improvements
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46210
diff changeset
97 removed_actions = upgrade_actions.find_format_downgrades(repo)
30776
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
98
42842
a3c2ffcd266f upgrade: make sure we reclone all revlogs when updating to some format
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42841
diff changeset
99 removedreqs = repo.requirements - newreqs
a3c2ffcd266f upgrade: make sure we reclone all revlogs when updating to some format
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42841
diff changeset
100 addedreqs = newreqs - repo.requirements
a3c2ffcd266f upgrade: make sure we reclone all revlogs when updating to some format
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42841
diff changeset
101
46050
f105c49e89cd upgrade: split actual upgrade code away from the main module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46039
diff changeset
102 if revlogs != upgrade_engine.UPGRADE_ALL_REVLOGS:
46051
4b89cf08d8dc upgrade: split definition and management of the actions from the main code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46050
diff changeset
103 incompatible = upgrade_actions.RECLONES_REQUIREMENTS & (
4b89cf08d8dc upgrade: split definition and management of the actions from the main code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46050
diff changeset
104 removedreqs | addedreqs
4b89cf08d8dc upgrade: split definition and management of the actions from the main code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46050
diff changeset
105 )
42842
a3c2ffcd266f upgrade: make sure we reclone all revlogs when updating to some format
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42841
diff changeset
106 if incompatible:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43031
diff changeset
107 msg = _(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
108 b'ignoring revlogs selection flags, format requirements '
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
109 b'change: %s\n'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43031
diff changeset
110 )
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
111 ui.warn(msg % b', '.join(sorted(incompatible)))
46050
f105c49e89cd upgrade: split actual upgrade code away from the main module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46039
diff changeset
112 revlogs = upgrade_engine.UPGRADE_ALL_REVLOGS
42842
a3c2ffcd266f upgrade: make sure we reclone all revlogs when updating to some format
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42841
diff changeset
113
46060
c407513a44a3 upgrade: start moving the "to be happening" data in a dedicated object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46055
diff changeset
114 upgrade_op = upgrade_actions.UpgradeOperation(
46188
945b33a7edfd upgrade: move `print_affected_revlogs()` to UpgradeOperation class
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46060
diff changeset
115 ui,
46060
c407513a44a3 upgrade: start moving the "to be happening" data in a dedicated object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46055
diff changeset
116 newreqs,
46191
aba979b1b90b upgrade: move `printrequirements()` to UpgradeOperation class
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46190
diff changeset
117 repo.requirements,
46210
6b40aac4da8e upgrade: rename actions to upgrade_actions
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46209
diff changeset
118 up_actions,
46213
30310886d423 upgrade: introduce post upgrade and downgrade message for improvements
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46210
diff changeset
119 removed_actions,
46060
c407513a44a3 upgrade: start moving the "to be happening" data in a dedicated object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46055
diff changeset
120 revlogs,
c407513a44a3 upgrade: start moving the "to be happening" data in a dedicated object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46055
diff changeset
121 )
c407513a44a3 upgrade: start moving the "to be happening" data in a dedicated object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46055
diff changeset
122
30775
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
123 if not run:
30776
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
124 fromconfig = []
31904
3c77f03f16b3 upgrade: simplify the "origin" dispatch in dry run
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31903
diff changeset
125 onlydefault = []
30776
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
126
46205
53d083fa1f83 upgrade: rename finddeficiences() to find_format_upgrades()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46192
diff changeset
127 for d in format_upgrades:
32031
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
128 if d.fromconfig(repo):
31901
9bdedb050d8d upgrade: simplify some of the initial dispatch for dry run
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31900
diff changeset
129 fromconfig.append(d)
32031
11a2461fc9b1 upgrade: move descriptions and selection logic in individual classes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32030
diff changeset
130 elif d.default:
31904
3c77f03f16b3 upgrade: simplify the "origin" dispatch in dry run
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31903
diff changeset
131 onlydefault.append(d)
30776
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
132
31904
3c77f03f16b3 upgrade: simplify the "origin" dispatch in dry run
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31903
diff changeset
133 if fromconfig or onlydefault:
30776
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
134
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
135 if fromconfig:
44875
e295ba238bd8 upgrade: support the --quiet flag
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44874
diff changeset
136 ui.status(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43031
diff changeset
137 _(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
138 b'repository lacks features recommended by '
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
139 b'current config options:\n\n'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43031
diff changeset
140 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43031
diff changeset
141 )
30776
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
142 for i in fromconfig:
44875
e295ba238bd8 upgrade: support the --quiet flag
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44874
diff changeset
143 ui.status(b'%s\n %s\n\n' % (i.name, i.description))
30776
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
144
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
145 if onlydefault:
44875
e295ba238bd8 upgrade: support the --quiet flag
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44874
diff changeset
146 ui.status(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43031
diff changeset
147 _(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
148 b'repository lacks features used by the default '
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
149 b'config options:\n\n'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43031
diff changeset
150 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43031
diff changeset
151 )
30776
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
152 for i in onlydefault:
44875
e295ba238bd8 upgrade: support the --quiet flag
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44874
diff changeset
153 ui.status(b'%s\n %s\n\n' % (i.name, i.description))
30776
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
154
44875
e295ba238bd8 upgrade: support the --quiet flag
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44874
diff changeset
155 ui.status(b'\n')
30776
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
156 else:
46205
53d083fa1f83 upgrade: rename finddeficiences() to find_format_upgrades()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46192
diff changeset
157 ui.status(_(b'(no format upgrades found in existing repository)\n'))
30776
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
158
44875
e295ba238bd8 upgrade: support the --quiet flag
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44874
diff changeset
159 ui.status(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43031
diff changeset
160 _(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
161 b'performing an upgrade with "--run" will make the following '
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
162 b'changes:\n\n'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43031
diff changeset
163 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43031
diff changeset
164 )
30775
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30707
diff changeset
165
46191
aba979b1b90b upgrade: move `printrequirements()` to UpgradeOperation class
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46190
diff changeset
166 upgrade_op.print_requirements()
46190
9ab2ab5bf9af upgrade: move `printoptimisations() to UpgradeOperation class
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46189
diff changeset
167 upgrade_op.print_optimisations()
46189
dfddcbb0c244 upgrade: move `printupgradeactions()` to UpgradeOperation class
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46188
diff changeset
168 upgrade_op.print_upgrade_actions()
46188
945b33a7edfd upgrade: move `print_affected_revlogs()` to UpgradeOperation class
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46060
diff changeset
169 upgrade_op.print_affected_revlogs()
30776
3997edc4a86d repair: determine what upgrade will do
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30775
diff changeset
170
46192
25d11b24dedf upgrade: move printing of unused optimizations to UpgradeOperation class
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46191
diff changeset
171 if upgrade_op.unused_optimizations:
44875
e295ba238bd8 upgrade: support the --quiet flag
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44874
diff changeset
172 ui.status(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43031
diff changeset
173 _(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
174 b'additional optimizations are available by specifying '
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
175 b'"--optimize <name>":\n\n'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43031
diff changeset
176 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43031
diff changeset
177 )
46192
25d11b24dedf upgrade: move printing of unused optimizations to UpgradeOperation class
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46191
diff changeset
178 upgrade_op.print_unused_optimizations()
30777
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
179 return
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
180
46231
d3113c4cf52c upgrade: don't perform anything if nothing to do
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46222
diff changeset
181 if not (upgrade_op.upgrade_actions or upgrade_op.removed_actions):
d3113c4cf52c upgrade: don't perform anything if nothing to do
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46222
diff changeset
182 ui.status(_(b'nothing to do\n'))
d3113c4cf52c upgrade: don't perform anything if nothing to do
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46222
diff changeset
183 return
30777
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
184 # Else we're in the run=true case.
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
185 ui.write(_(b'upgrade will perform the following actions:\n\n'))
46191
aba979b1b90b upgrade: move `printrequirements()` to UpgradeOperation class
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46190
diff changeset
186 upgrade_op.print_requirements()
46190
9ab2ab5bf9af upgrade: move `printoptimisations() to UpgradeOperation class
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46189
diff changeset
187 upgrade_op.print_optimisations()
46189
dfddcbb0c244 upgrade: move `printupgradeactions()` to UpgradeOperation class
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46188
diff changeset
188 upgrade_op.print_upgrade_actions()
46188
945b33a7edfd upgrade: move `print_affected_revlogs()` to UpgradeOperation class
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46060
diff changeset
189 upgrade_op.print_affected_revlogs()
30777
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
190
44875
e295ba238bd8 upgrade: support the --quiet flag
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44874
diff changeset
191 ui.status(_(b'beginning upgrade...\n'))
33438
8056481caa81 codemod: simplify nested withs
Jun Wu <quark@fb.com>
parents: 32331
diff changeset
192 with repo.wlock(), repo.lock():
44875
e295ba238bd8 upgrade: support the --quiet flag
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44874
diff changeset
193 ui.status(_(b'repository locked and read-only\n'))
33438
8056481caa81 codemod: simplify nested withs
Jun Wu <quark@fb.com>
parents: 32331
diff changeset
194 # Our strategy for upgrading the repository is to create a new,
8056481caa81 codemod: simplify nested withs
Jun Wu <quark@fb.com>
parents: 32331
diff changeset
195 # temporary repository, write data to it, then do a swap of the
8056481caa81 codemod: simplify nested withs
Jun Wu <quark@fb.com>
parents: 32331
diff changeset
196 # data. There are less heavyweight ways to do this, but it is easier
8056481caa81 codemod: simplify nested withs
Jun Wu <quark@fb.com>
parents: 32331
diff changeset
197 # to create a new repo object than to instantiate all the components
8056481caa81 codemod: simplify nested withs
Jun Wu <quark@fb.com>
parents: 32331
diff changeset
198 # (like the store) separately.
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
199 tmppath = pycompat.mkdtemp(prefix=b'upgrade.', dir=repo.path)
33438
8056481caa81 codemod: simplify nested withs
Jun Wu <quark@fb.com>
parents: 32331
diff changeset
200 backuppath = None
8056481caa81 codemod: simplify nested withs
Jun Wu <quark@fb.com>
parents: 32331
diff changeset
201 try:
44875
e295ba238bd8 upgrade: support the --quiet flag
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44874
diff changeset
202 ui.status(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43031
diff changeset
203 _(
46222
e22aed089567 upgrade: migrated -> upgraded in ui messages
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46221
diff changeset
204 b'creating temporary repository to stage upgraded '
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
205 b'data: %s\n'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43031
diff changeset
206 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43031
diff changeset
207 % tmppath
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43031
diff changeset
208 )
35351
75520786ad2f upgrade: use the repository 'ui' as the base for the new repository
Boris Feld <boris.feld@octobus.net>
parents: 35349
diff changeset
209
35388
6c28956ba2d4 upgrade: simplify workaround for repo.ui.copy()
Yuya Nishihara <yuya@tcha.org>
parents: 35354
diff changeset
210 # clone ui without using ui.copy because repo.ui is protected
6c28956ba2d4 upgrade: simplify workaround for repo.ui.copy()
Yuya Nishihara <yuya@tcha.org>
parents: 35354
diff changeset
211 repoui = repo.ui.__class__(repo.ui)
6c28956ba2d4 upgrade: simplify workaround for repo.ui.copy()
Yuya Nishihara <yuya@tcha.org>
parents: 35354
diff changeset
212 dstrepo = hg.repository(repoui, path=tmppath, create=True)
30777
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
213
33438
8056481caa81 codemod: simplify nested withs
Jun Wu <quark@fb.com>
parents: 32331
diff changeset
214 with dstrepo.wlock(), dstrepo.lock():
46050
f105c49e89cd upgrade: split actual upgrade code away from the main module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46039
diff changeset
215 backuppath = upgrade_engine.upgrade(
46060
c407513a44a3 upgrade: start moving the "to be happening" data in a dedicated object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46055
diff changeset
216 ui, repo, dstrepo, upgrade_op
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43031
diff changeset
217 )
46221
0ca98ed828f9 upgrade: remove unnecessary `is None` check
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46213
diff changeset
218 if not backup:
44875
e295ba238bd8 upgrade: support the --quiet flag
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44874
diff changeset
219 ui.status(
46207
e2139e071b5c upgrade: add a missing space in status message
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46205
diff changeset
220 _(b'removing old repository content %s\n') % backuppath
44875
e295ba238bd8 upgrade: support the --quiet flag
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44874
diff changeset
221 )
41092
a59a74721c76 debugupgraderepo: add a --no-backup mode
Boris Feld <boris.feld@octobus.net>
parents: 41091
diff changeset
222 repo.vfs.rmtree(backuppath, forcibly=True)
a59a74721c76 debugupgraderepo: add a --no-backup mode
Boris Feld <boris.feld@octobus.net>
parents: 41091
diff changeset
223 backuppath = None
30777
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
224
33438
8056481caa81 codemod: simplify nested withs
Jun Wu <quark@fb.com>
parents: 32331
diff changeset
225 finally:
44875
e295ba238bd8 upgrade: support the --quiet flag
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44874
diff changeset
226 ui.status(_(b'removing temporary repository %s\n') % tmppath)
33438
8056481caa81 codemod: simplify nested withs
Jun Wu <quark@fb.com>
parents: 32331
diff changeset
227 repo.vfs.rmtree(tmppath, forcibly=True)
30777
7de7afd8bdd9 repair: begin implementation of in-place upgrading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30776
diff changeset
228
44875
e295ba238bd8 upgrade: support the --quiet flag
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44874
diff changeset
229 if backuppath and not ui.quiet:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43031
diff changeset
230 ui.warn(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
231 _(b'copy of old repository backed up at %s\n') % backuppath
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43031
diff changeset
232 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43031
diff changeset
233 ui.warn(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43031
diff changeset
234 _(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
235 b'the old repository will not be deleted; remove '
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
236 b'it to free up disk space once the upgraded '
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
237 b'repository is verified\n'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43031
diff changeset
238 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43031
diff changeset
239 )
46017
705c37f22859 upgrade: add support for experimental safe share mode
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46012
diff changeset
240
46213
30310886d423 upgrade: introduce post upgrade and downgrade message for improvements
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46210
diff changeset
241 upgrade_op.print_post_op_messages()
46235
0babe12ef35d sharesafe: introduce functionality to automatically upgrade shares
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46231
diff changeset
242
0babe12ef35d sharesafe: introduce functionality to automatically upgrade shares
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46231
diff changeset
243
0babe12ef35d sharesafe: introduce functionality to automatically upgrade shares
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46231
diff changeset
244 def upgrade_share_to_safe(ui, hgvfs, storevfs, current_requirements):
0babe12ef35d sharesafe: introduce functionality to automatically upgrade shares
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46231
diff changeset
245 """Upgrades a share to use share-safe mechanism"""
0babe12ef35d sharesafe: introduce functionality to automatically upgrade shares
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46231
diff changeset
246 wlock = None
0babe12ef35d sharesafe: introduce functionality to automatically upgrade shares
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46231
diff changeset
247 try:
0babe12ef35d sharesafe: introduce functionality to automatically upgrade shares
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46231
diff changeset
248 wlock = lockmod.trylock(ui, hgvfs, b'wlock', 0, 0)
0babe12ef35d sharesafe: introduce functionality to automatically upgrade shares
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46231
diff changeset
249 store_requirements = localrepo._readrequires(storevfs, False)
0babe12ef35d sharesafe: introduce functionality to automatically upgrade shares
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46231
diff changeset
250 # after upgrade, store requires will be shared, so lets find
0babe12ef35d sharesafe: introduce functionality to automatically upgrade shares
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46231
diff changeset
251 # the requirements which are not present in store and
0babe12ef35d sharesafe: introduce functionality to automatically upgrade shares
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46231
diff changeset
252 # write them to share's .hg/requires
0babe12ef35d sharesafe: introduce functionality to automatically upgrade shares
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46231
diff changeset
253 diffrequires = current_requirements - store_requirements
0babe12ef35d sharesafe: introduce functionality to automatically upgrade shares
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46231
diff changeset
254 # add share-safe requirement as it will mark the share as share-safe
0babe12ef35d sharesafe: introduce functionality to automatically upgrade shares
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46231
diff changeset
255 diffrequires.add(requirementsmod.SHARESAFE_REQUIREMENT)
0babe12ef35d sharesafe: introduce functionality to automatically upgrade shares
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46231
diff changeset
256 scmutil.writerequires(hgvfs, diffrequires)
0babe12ef35d sharesafe: introduce functionality to automatically upgrade shares
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46231
diff changeset
257 current_requirements.add(requirementsmod.SHARESAFE_REQUIREMENT)
0babe12ef35d sharesafe: introduce functionality to automatically upgrade shares
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46231
diff changeset
258 ui.warn(_(b'repository upgraded to use share-safe mode\n'))
0babe12ef35d sharesafe: introduce functionality to automatically upgrade shares
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46231
diff changeset
259 except error.LockError as e:
0babe12ef35d sharesafe: introduce functionality to automatically upgrade shares
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46231
diff changeset
260 ui.warn(
0babe12ef35d sharesafe: introduce functionality to automatically upgrade shares
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46231
diff changeset
261 _(b'failed to upgrade share, got error: %s\n')
0babe12ef35d sharesafe: introduce functionality to automatically upgrade shares
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46231
diff changeset
262 % stringutil.forcebytestr(e.strerror)
0babe12ef35d sharesafe: introduce functionality to automatically upgrade shares
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46231
diff changeset
263 )
0babe12ef35d sharesafe: introduce functionality to automatically upgrade shares
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46231
diff changeset
264 finally:
0babe12ef35d sharesafe: introduce functionality to automatically upgrade shares
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46231
diff changeset
265 if wlock:
0babe12ef35d sharesafe: introduce functionality to automatically upgrade shares
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46231
diff changeset
266 wlock.release()
46236
eec47efe219d sharesafe: add functionality to automatically downgrade shares
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46235
diff changeset
267
eec47efe219d sharesafe: add functionality to automatically downgrade shares
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46235
diff changeset
268
eec47efe219d sharesafe: add functionality to automatically downgrade shares
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46235
diff changeset
269 def downgrade_share_to_non_safe(
eec47efe219d sharesafe: add functionality to automatically downgrade shares
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46235
diff changeset
270 ui,
eec47efe219d sharesafe: add functionality to automatically downgrade shares
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46235
diff changeset
271 hgvfs,
eec47efe219d sharesafe: add functionality to automatically downgrade shares
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46235
diff changeset
272 sharedvfs,
eec47efe219d sharesafe: add functionality to automatically downgrade shares
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46235
diff changeset
273 current_requirements,
eec47efe219d sharesafe: add functionality to automatically downgrade shares
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46235
diff changeset
274 ):
eec47efe219d sharesafe: add functionality to automatically downgrade shares
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46235
diff changeset
275 """Downgrades a share which use share-safe to not use it"""
eec47efe219d sharesafe: add functionality to automatically downgrade shares
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46235
diff changeset
276 wlock = None
eec47efe219d sharesafe: add functionality to automatically downgrade shares
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46235
diff changeset
277 try:
eec47efe219d sharesafe: add functionality to automatically downgrade shares
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46235
diff changeset
278 wlock = lockmod.trylock(ui, hgvfs, b'wlock', 0, 0)
eec47efe219d sharesafe: add functionality to automatically downgrade shares
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46235
diff changeset
279 source_requirements = localrepo._readrequires(sharedvfs, True)
eec47efe219d sharesafe: add functionality to automatically downgrade shares
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46235
diff changeset
280 # we cannot be 100% sure on which requirements were present in store when
eec47efe219d sharesafe: add functionality to automatically downgrade shares
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46235
diff changeset
281 # the source supported share-safe. However, we do know that working
eec47efe219d sharesafe: add functionality to automatically downgrade shares
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46235
diff changeset
282 # directory requirements were not there. Hence we remove them
eec47efe219d sharesafe: add functionality to automatically downgrade shares
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46235
diff changeset
283 source_requirements -= requirementsmod.WORKING_DIR_REQUIREMENTS
eec47efe219d sharesafe: add functionality to automatically downgrade shares
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46235
diff changeset
284 current_requirements |= source_requirements
eec47efe219d sharesafe: add functionality to automatically downgrade shares
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46235
diff changeset
285 current_requirements.remove(requirementsmod.SHARESAFE_REQUIREMENT)
eec47efe219d sharesafe: add functionality to automatically downgrade shares
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46235
diff changeset
286 scmutil.writerequires(hgvfs, current_requirements)
eec47efe219d sharesafe: add functionality to automatically downgrade shares
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46235
diff changeset
287 ui.warn(_(b'repository downgraded to not use share-safe mode\n'))
eec47efe219d sharesafe: add functionality to automatically downgrade shares
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46235
diff changeset
288 except error.LockError as e:
eec47efe219d sharesafe: add functionality to automatically downgrade shares
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46235
diff changeset
289 # raise error right away because if downgrade failed, we cannot load
eec47efe219d sharesafe: add functionality to automatically downgrade shares
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46235
diff changeset
290 # the repository because it does not have complete set of requirements
eec47efe219d sharesafe: add functionality to automatically downgrade shares
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46235
diff changeset
291 raise error.Abort(
eec47efe219d sharesafe: add functionality to automatically downgrade shares
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46235
diff changeset
292 _(b'failed to downgrade share, got error: %s')
eec47efe219d sharesafe: add functionality to automatically downgrade shares
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46235
diff changeset
293 % stringutil.forcebytestr(e.strerror)
eec47efe219d sharesafe: add functionality to automatically downgrade shares
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46235
diff changeset
294 )
eec47efe219d sharesafe: add functionality to automatically downgrade shares
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46235
diff changeset
295 finally:
eec47efe219d sharesafe: add functionality to automatically downgrade shares
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46235
diff changeset
296 if wlock:
eec47efe219d sharesafe: add functionality to automatically downgrade shares
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46235
diff changeset
297 wlock.release()