##// END OF EJS Templates
upgrade: drop some dead code...
marmoute -
r49278:dc2ef4b4 default
parent child Browse files
Show More
@@ -1,418 +1,401 b''
1 # upgrade.py - functions for in place upgrade of Mercurial repository
1 # upgrade.py - functions for in place upgrade of Mercurial repository
2 #
2 #
3 # Copyright (c) 2016-present, Gregory Szorc
3 # Copyright (c) 2016-present, Gregory Szorc
4 #
4 #
5 # This software may be used and distributed according to the terms of the
5 # This software may be used and distributed according to the terms of the
6 # GNU General Public License version 2 or any later version.
6 # GNU General Public License version 2 or any later version.
7
7
8 from __future__ import absolute_import
8 from __future__ import absolute_import
9
9
10 from .i18n import _
10 from .i18n import _
11 from . import (
11 from . import (
12 error,
12 error,
13 hg,
13 hg,
14 localrepo,
14 localrepo,
15 lock as lockmod,
15 lock as lockmod,
16 pycompat,
16 pycompat,
17 requirements as requirementsmod,
17 requirements as requirementsmod,
18 scmutil,
18 scmutil,
19 )
19 )
20
20
21 from .upgrade_utils import (
21 from .upgrade_utils import (
22 actions as upgrade_actions,
22 actions as upgrade_actions,
23 engine as upgrade_engine,
23 engine as upgrade_engine,
24 )
24 )
25
25
26 from .utils import (
26 from .utils import (
27 stringutil,
27 stringutil,
28 )
28 )
29
29
30 allformatvariant = upgrade_actions.allformatvariant
30 allformatvariant = upgrade_actions.allformatvariant
31
31
32
32
33 def upgraderepo(
33 def upgraderepo(
34 ui,
34 ui,
35 repo,
35 repo,
36 run=False,
36 run=False,
37 optimize=None,
37 optimize=None,
38 backup=True,
38 backup=True,
39 manifest=None,
39 manifest=None,
40 changelog=None,
40 changelog=None,
41 filelogs=None,
41 filelogs=None,
42 ):
42 ):
43 """Upgrade a repository in place."""
43 """Upgrade a repository in place."""
44 if optimize is None:
44 if optimize is None:
45 optimize = {}
45 optimize = {}
46 repo = repo.unfiltered()
46 repo = repo.unfiltered()
47
47
48 specified_revlogs = {}
48 specified_revlogs = {}
49 if changelog is not None:
49 if changelog is not None:
50 specified_revlogs[upgrade_engine.UPGRADE_CHANGELOG] = changelog
50 specified_revlogs[upgrade_engine.UPGRADE_CHANGELOG] = changelog
51 if manifest is not None:
51 if manifest is not None:
52 specified_revlogs[upgrade_engine.UPGRADE_MANIFEST] = manifest
52 specified_revlogs[upgrade_engine.UPGRADE_MANIFEST] = manifest
53 if filelogs is not None:
53 if filelogs is not None:
54 specified_revlogs[upgrade_engine.UPGRADE_FILELOGS] = filelogs
54 specified_revlogs[upgrade_engine.UPGRADE_FILELOGS] = filelogs
55
55
56 # Ensure the repository can be upgraded.
56 # Ensure the repository can be upgraded.
57 upgrade_actions.check_source_requirements(repo)
57 upgrade_actions.check_source_requirements(repo)
58
58
59 default_options = localrepo.defaultcreateopts(repo.ui)
59 default_options = localrepo.defaultcreateopts(repo.ui)
60 newreqs = localrepo.newreporequirements(repo.ui, default_options)
60 newreqs = localrepo.newreporequirements(repo.ui, default_options)
61 newreqs.update(upgrade_actions.preservedrequirements(repo))
61 newreqs.update(upgrade_actions.preservedrequirements(repo))
62
62
63 upgrade_actions.check_requirements_changes(repo, newreqs)
63 upgrade_actions.check_requirements_changes(repo, newreqs)
64
64
65 # Find and validate all improvements that can be made.
65 # Find and validate all improvements that can be made.
66 alloptimizations = upgrade_actions.findoptimizations(repo)
66 alloptimizations = upgrade_actions.findoptimizations(repo)
67
67
68 # Apply and Validate arguments.
68 # Apply and Validate arguments.
69 optimizations = []
69 optimizations = []
70 for o in alloptimizations:
70 for o in alloptimizations:
71 if o.name in optimize:
71 if o.name in optimize:
72 optimizations.append(o)
72 optimizations.append(o)
73 optimize.discard(o.name)
73 optimize.discard(o.name)
74
74
75 if optimize: # anything left is unknown
75 if optimize: # anything left is unknown
76 raise error.Abort(
76 raise error.Abort(
77 _(b'unknown optimization action requested: %s')
77 _(b'unknown optimization action requested: %s')
78 % b', '.join(sorted(optimize)),
78 % b', '.join(sorted(optimize)),
79 hint=_(b'run without arguments to see valid optimizations'),
79 hint=_(b'run without arguments to see valid optimizations'),
80 )
80 )
81
81
82 format_upgrades = upgrade_actions.find_format_upgrades(repo)
82 format_upgrades = upgrade_actions.find_format_upgrades(repo)
83 up_actions = upgrade_actions.determine_upgrade_actions(
83 up_actions = upgrade_actions.determine_upgrade_actions(
84 repo, format_upgrades, optimizations, repo.requirements, newreqs
84 repo, format_upgrades, optimizations, repo.requirements, newreqs
85 )
85 )
86 removed_actions = upgrade_actions.find_format_downgrades(repo)
86 removed_actions = upgrade_actions.find_format_downgrades(repo)
87
87
88 removedreqs = repo.requirements - newreqs
89 addedreqs = newreqs - repo.requirements
90
91 # check if we need to touch revlog and if so, which ones
88 # check if we need to touch revlog and if so, which ones
92
89
93 touched_revlogs = set()
90 touched_revlogs = set()
94 overwrite_msg = _(b'warning: ignoring %14s, as upgrade is changing: %s\n')
91 overwrite_msg = _(b'warning: ignoring %14s, as upgrade is changing: %s\n')
95 select_msg = _(b'note: selecting %s for processing to change: %s\n')
92 select_msg = _(b'note: selecting %s for processing to change: %s\n')
96 msg_issued = 0
93 msg_issued = 0
97
94
98 FL = upgrade_engine.UPGRADE_FILELOGS
95 FL = upgrade_engine.UPGRADE_FILELOGS
99 MN = upgrade_engine.UPGRADE_MANIFEST
96 MN = upgrade_engine.UPGRADE_MANIFEST
100 CL = upgrade_engine.UPGRADE_CHANGELOG
97 CL = upgrade_engine.UPGRADE_CHANGELOG
101
98
102 if optimizations:
99 if optimizations:
103 if any(specified_revlogs.values()):
100 if any(specified_revlogs.values()):
104 # we have some limitation on revlogs to be recloned
101 # we have some limitation on revlogs to be recloned
105 for rl, enabled in specified_revlogs.items():
102 for rl, enabled in specified_revlogs.items():
106 if enabled:
103 if enabled:
107 touched_revlogs.add(rl)
104 touched_revlogs.add(rl)
108 else:
105 else:
109 touched_revlogs = set(upgrade_engine.UPGRADE_ALL_REVLOGS)
106 touched_revlogs = set(upgrade_engine.UPGRADE_ALL_REVLOGS)
110 for rl, enabled in specified_revlogs.items():
107 for rl, enabled in specified_revlogs.items():
111 if not enabled:
108 if not enabled:
112 touched_revlogs.discard(rl)
109 touched_revlogs.discard(rl)
113
110
114 for action in sorted(up_actions + removed_actions, key=lambda a: a.name):
111 for action in sorted(up_actions + removed_actions, key=lambda a: a.name):
115 # optimisation does not "requires anything, they just needs it.
112 # optimisation does not "requires anything, they just needs it.
116 if action.type != upgrade_actions.FORMAT_VARIANT:
113 if action.type != upgrade_actions.FORMAT_VARIANT:
117 continue
114 continue
118
115
119 if action.touches_filelogs and FL not in touched_revlogs:
116 if action.touches_filelogs and FL not in touched_revlogs:
120 if FL in specified_revlogs:
117 if FL in specified_revlogs:
121 if not specified_revlogs[FL]:
118 if not specified_revlogs[FL]:
122 msg = overwrite_msg % (b'--no-filelogs', action.name)
119 msg = overwrite_msg % (b'--no-filelogs', action.name)
123 ui.warn(msg)
120 ui.warn(msg)
124 msg_issued = 2
121 msg_issued = 2
125 else:
122 else:
126 msg = select_msg % (b'all-filelogs', action.name)
123 msg = select_msg % (b'all-filelogs', action.name)
127 ui.status(msg)
124 ui.status(msg)
128 if not ui.quiet:
125 if not ui.quiet:
129 msg_issued = 1
126 msg_issued = 1
130 touched_revlogs.add(FL)
127 touched_revlogs.add(FL)
131
128
132 if action.touches_manifests and MN not in touched_revlogs:
129 if action.touches_manifests and MN not in touched_revlogs:
133 if MN in specified_revlogs:
130 if MN in specified_revlogs:
134 if not specified_revlogs[MN]:
131 if not specified_revlogs[MN]:
135 msg = overwrite_msg % (b'--no-manifest', action.name)
132 msg = overwrite_msg % (b'--no-manifest', action.name)
136 ui.warn(msg)
133 ui.warn(msg)
137 msg_issued = 2
134 msg_issued = 2
138 else:
135 else:
139 msg = select_msg % (b'all-manifestlogs', action.name)
136 msg = select_msg % (b'all-manifestlogs', action.name)
140 ui.status(msg)
137 ui.status(msg)
141 if not ui.quiet:
138 if not ui.quiet:
142 msg_issued = 1
139 msg_issued = 1
143 touched_revlogs.add(MN)
140 touched_revlogs.add(MN)
144
141
145 if action.touches_changelog and CL not in touched_revlogs:
142 if action.touches_changelog and CL not in touched_revlogs:
146 if CL in specified_revlogs:
143 if CL in specified_revlogs:
147 if not specified_revlogs[CL]:
144 if not specified_revlogs[CL]:
148 msg = overwrite_msg % (b'--no-changelog', action.name)
145 msg = overwrite_msg % (b'--no-changelog', action.name)
149 ui.warn(msg)
146 ui.warn(msg)
150 msg_issued = True
147 msg_issued = True
151 else:
148 else:
152 msg = select_msg % (b'changelog', action.name)
149 msg = select_msg % (b'changelog', action.name)
153 ui.status(msg)
150 ui.status(msg)
154 if not ui.quiet:
151 if not ui.quiet:
155 msg_issued = 1
152 msg_issued = 1
156 touched_revlogs.add(CL)
153 touched_revlogs.add(CL)
157 if msg_issued >= 2:
154 if msg_issued >= 2:
158 ui.warn((b"\n"))
155 ui.warn((b"\n"))
159 elif msg_issued >= 1:
156 elif msg_issued >= 1:
160 ui.status((b"\n"))
157 ui.status((b"\n"))
161
158
162 # check the consistency of the revlog selection with the planned action
163
164 if touched_revlogs != upgrade_engine.UPGRADE_ALL_REVLOGS:
165 incompatible = upgrade_actions.RECLONES_REQUIREMENTS & (
166 removedreqs | addedreqs
167 )
168 if incompatible:
169 msg = _(
170 b'ignoring revlogs selection flags, format requirements '
171 b'change: %s\n'
172 )
173 ui.warn(msg % b', '.join(sorted(incompatible)))
174 touched_revlogs = upgrade_engine.UPGRADE_ALL_REVLOGS
175
176 upgrade_op = upgrade_actions.UpgradeOperation(
159 upgrade_op = upgrade_actions.UpgradeOperation(
177 ui,
160 ui,
178 newreqs,
161 newreqs,
179 repo.requirements,
162 repo.requirements,
180 up_actions,
163 up_actions,
181 removed_actions,
164 removed_actions,
182 touched_revlogs,
165 touched_revlogs,
183 backup,
166 backup,
184 )
167 )
185
168
186 if not run:
169 if not run:
187 fromconfig = []
170 fromconfig = []
188 onlydefault = []
171 onlydefault = []
189
172
190 for d in format_upgrades:
173 for d in format_upgrades:
191 if d.fromconfig(repo):
174 if d.fromconfig(repo):
192 fromconfig.append(d)
175 fromconfig.append(d)
193 elif d.default:
176 elif d.default:
194 onlydefault.append(d)
177 onlydefault.append(d)
195
178
196 if fromconfig or onlydefault:
179 if fromconfig or onlydefault:
197
180
198 if fromconfig:
181 if fromconfig:
199 ui.status(
182 ui.status(
200 _(
183 _(
201 b'repository lacks features recommended by '
184 b'repository lacks features recommended by '
202 b'current config options:\n\n'
185 b'current config options:\n\n'
203 )
186 )
204 )
187 )
205 for i in fromconfig:
188 for i in fromconfig:
206 ui.status(b'%s\n %s\n\n' % (i.name, i.description))
189 ui.status(b'%s\n %s\n\n' % (i.name, i.description))
207
190
208 if onlydefault:
191 if onlydefault:
209 ui.status(
192 ui.status(
210 _(
193 _(
211 b'repository lacks features used by the default '
194 b'repository lacks features used by the default '
212 b'config options:\n\n'
195 b'config options:\n\n'
213 )
196 )
214 )
197 )
215 for i in onlydefault:
198 for i in onlydefault:
216 ui.status(b'%s\n %s\n\n' % (i.name, i.description))
199 ui.status(b'%s\n %s\n\n' % (i.name, i.description))
217
200
218 ui.status(b'\n')
201 ui.status(b'\n')
219 else:
202 else:
220 ui.status(_(b'(no format upgrades found in existing repository)\n'))
203 ui.status(_(b'(no format upgrades found in existing repository)\n'))
221
204
222 ui.status(
205 ui.status(
223 _(
206 _(
224 b'performing an upgrade with "--run" will make the following '
207 b'performing an upgrade with "--run" will make the following '
225 b'changes:\n\n'
208 b'changes:\n\n'
226 )
209 )
227 )
210 )
228
211
229 upgrade_op.print_requirements()
212 upgrade_op.print_requirements()
230 upgrade_op.print_optimisations()
213 upgrade_op.print_optimisations()
231 upgrade_op.print_upgrade_actions()
214 upgrade_op.print_upgrade_actions()
232 upgrade_op.print_affected_revlogs()
215 upgrade_op.print_affected_revlogs()
233
216
234 if upgrade_op.unused_optimizations:
217 if upgrade_op.unused_optimizations:
235 ui.status(
218 ui.status(
236 _(
219 _(
237 b'additional optimizations are available by specifying '
220 b'additional optimizations are available by specifying '
238 b'"--optimize <name>":\n\n'
221 b'"--optimize <name>":\n\n'
239 )
222 )
240 )
223 )
241 upgrade_op.print_unused_optimizations()
224 upgrade_op.print_unused_optimizations()
242 return
225 return
243
226
244 if not (upgrade_op.upgrade_actions or upgrade_op.removed_actions):
227 if not (upgrade_op.upgrade_actions or upgrade_op.removed_actions):
245 ui.status(_(b'nothing to do\n'))
228 ui.status(_(b'nothing to do\n'))
246 return
229 return
247 # Else we're in the run=true case.
230 # Else we're in the run=true case.
248 ui.write(_(b'upgrade will perform the following actions:\n\n'))
231 ui.write(_(b'upgrade will perform the following actions:\n\n'))
249 upgrade_op.print_requirements()
232 upgrade_op.print_requirements()
250 upgrade_op.print_optimisations()
233 upgrade_op.print_optimisations()
251 upgrade_op.print_upgrade_actions()
234 upgrade_op.print_upgrade_actions()
252 upgrade_op.print_affected_revlogs()
235 upgrade_op.print_affected_revlogs()
253
236
254 ui.status(_(b'beginning upgrade...\n'))
237 ui.status(_(b'beginning upgrade...\n'))
255 with repo.wlock(), repo.lock():
238 with repo.wlock(), repo.lock():
256 ui.status(_(b'repository locked and read-only\n'))
239 ui.status(_(b'repository locked and read-only\n'))
257 # Our strategy for upgrading the repository is to create a new,
240 # Our strategy for upgrading the repository is to create a new,
258 # temporary repository, write data to it, then do a swap of the
241 # temporary repository, write data to it, then do a swap of the
259 # data. There are less heavyweight ways to do this, but it is easier
242 # data. There are less heavyweight ways to do this, but it is easier
260 # to create a new repo object than to instantiate all the components
243 # to create a new repo object than to instantiate all the components
261 # (like the store) separately.
244 # (like the store) separately.
262 tmppath = pycompat.mkdtemp(prefix=b'upgrade.', dir=repo.path)
245 tmppath = pycompat.mkdtemp(prefix=b'upgrade.', dir=repo.path)
263 backuppath = None
246 backuppath = None
264 try:
247 try:
265 ui.status(
248 ui.status(
266 _(
249 _(
267 b'creating temporary repository to stage upgraded '
250 b'creating temporary repository to stage upgraded '
268 b'data: %s\n'
251 b'data: %s\n'
269 )
252 )
270 % tmppath
253 % tmppath
271 )
254 )
272
255
273 # clone ui without using ui.copy because repo.ui is protected
256 # clone ui without using ui.copy because repo.ui is protected
274 repoui = repo.ui.__class__(repo.ui)
257 repoui = repo.ui.__class__(repo.ui)
275 dstrepo = hg.repository(repoui, path=tmppath, create=True)
258 dstrepo = hg.repository(repoui, path=tmppath, create=True)
276
259
277 with dstrepo.wlock(), dstrepo.lock():
260 with dstrepo.wlock(), dstrepo.lock():
278 backuppath = upgrade_engine.upgrade(
261 backuppath = upgrade_engine.upgrade(
279 ui, repo, dstrepo, upgrade_op
262 ui, repo, dstrepo, upgrade_op
280 )
263 )
281
264
282 finally:
265 finally:
283 ui.status(_(b'removing temporary repository %s\n') % tmppath)
266 ui.status(_(b'removing temporary repository %s\n') % tmppath)
284 repo.vfs.rmtree(tmppath, forcibly=True)
267 repo.vfs.rmtree(tmppath, forcibly=True)
285
268
286 if backuppath and not ui.quiet:
269 if backuppath and not ui.quiet:
287 ui.warn(
270 ui.warn(
288 _(b'copy of old repository backed up at %s\n') % backuppath
271 _(b'copy of old repository backed up at %s\n') % backuppath
289 )
272 )
290 ui.warn(
273 ui.warn(
291 _(
274 _(
292 b'the old repository will not be deleted; remove '
275 b'the old repository will not be deleted; remove '
293 b'it to free up disk space once the upgraded '
276 b'it to free up disk space once the upgraded '
294 b'repository is verified\n'
277 b'repository is verified\n'
295 )
278 )
296 )
279 )
297
280
298 upgrade_op.print_post_op_messages()
281 upgrade_op.print_post_op_messages()
299
282
300
283
301 def upgrade_share_to_safe(
284 def upgrade_share_to_safe(
302 ui,
285 ui,
303 hgvfs,
286 hgvfs,
304 storevfs,
287 storevfs,
305 current_requirements,
288 current_requirements,
306 mismatch_config,
289 mismatch_config,
307 mismatch_warn,
290 mismatch_warn,
308 ):
291 ):
309 """Upgrades a share to use share-safe mechanism"""
292 """Upgrades a share to use share-safe mechanism"""
310 wlock = None
293 wlock = None
311 store_requirements = localrepo._readrequires(storevfs, False)
294 store_requirements = localrepo._readrequires(storevfs, False)
312 original_crequirements = current_requirements.copy()
295 original_crequirements = current_requirements.copy()
313 # after upgrade, store requires will be shared, so lets find
296 # after upgrade, store requires will be shared, so lets find
314 # the requirements which are not present in store and
297 # the requirements which are not present in store and
315 # write them to share's .hg/requires
298 # write them to share's .hg/requires
316 diffrequires = current_requirements - store_requirements
299 diffrequires = current_requirements - store_requirements
317 # add share-safe requirement as it will mark the share as share-safe
300 # add share-safe requirement as it will mark the share as share-safe
318 diffrequires.add(requirementsmod.SHARESAFE_REQUIREMENT)
301 diffrequires.add(requirementsmod.SHARESAFE_REQUIREMENT)
319 current_requirements.add(requirementsmod.SHARESAFE_REQUIREMENT)
302 current_requirements.add(requirementsmod.SHARESAFE_REQUIREMENT)
320 # in `allow` case, we don't try to upgrade, we just respect the source
303 # in `allow` case, we don't try to upgrade, we just respect the source
321 # state, update requirements and continue
304 # state, update requirements and continue
322 if mismatch_config == b'allow':
305 if mismatch_config == b'allow':
323 return
306 return
324 try:
307 try:
325 wlock = lockmod.trylock(ui, hgvfs, b'wlock', 0, 0)
308 wlock = lockmod.trylock(ui, hgvfs, b'wlock', 0, 0)
326 # some process might change the requirement in between, re-read
309 # some process might change the requirement in between, re-read
327 # and update current_requirements
310 # and update current_requirements
328 locked_requirements = localrepo._readrequires(hgvfs, True)
311 locked_requirements = localrepo._readrequires(hgvfs, True)
329 if locked_requirements != original_crequirements:
312 if locked_requirements != original_crequirements:
330 removed = current_requirements - locked_requirements
313 removed = current_requirements - locked_requirements
331 # update current_requirements in place because it's passed
314 # update current_requirements in place because it's passed
332 # as reference
315 # as reference
333 current_requirements -= removed
316 current_requirements -= removed
334 current_requirements |= locked_requirements
317 current_requirements |= locked_requirements
335 diffrequires = current_requirements - store_requirements
318 diffrequires = current_requirements - store_requirements
336 # add share-safe requirement as it will mark the share as share-safe
319 # add share-safe requirement as it will mark the share as share-safe
337 diffrequires.add(requirementsmod.SHARESAFE_REQUIREMENT)
320 diffrequires.add(requirementsmod.SHARESAFE_REQUIREMENT)
338 current_requirements.add(requirementsmod.SHARESAFE_REQUIREMENT)
321 current_requirements.add(requirementsmod.SHARESAFE_REQUIREMENT)
339 scmutil.writerequires(hgvfs, diffrequires)
322 scmutil.writerequires(hgvfs, diffrequires)
340 ui.warn(_(b'repository upgraded to use share-safe mode\n'))
323 ui.warn(_(b'repository upgraded to use share-safe mode\n'))
341 except error.LockError as e:
324 except error.LockError as e:
342 hint = _(
325 hint = _(
343 "see `hg help config.format.use-share-safe` for more information"
326 "see `hg help config.format.use-share-safe` for more information"
344 )
327 )
345 if mismatch_config == b'upgrade-abort':
328 if mismatch_config == b'upgrade-abort':
346 raise error.Abort(
329 raise error.Abort(
347 _(b'failed to upgrade share, got error: %s')
330 _(b'failed to upgrade share, got error: %s')
348 % stringutil.forcebytestr(e.strerror),
331 % stringutil.forcebytestr(e.strerror),
349 hint=hint,
332 hint=hint,
350 )
333 )
351 elif mismatch_warn:
334 elif mismatch_warn:
352 ui.warn(
335 ui.warn(
353 _(b'failed to upgrade share, got error: %s\n')
336 _(b'failed to upgrade share, got error: %s\n')
354 % stringutil.forcebytestr(e.strerror),
337 % stringutil.forcebytestr(e.strerror),
355 hint=hint,
338 hint=hint,
356 )
339 )
357 finally:
340 finally:
358 if wlock:
341 if wlock:
359 wlock.release()
342 wlock.release()
360
343
361
344
362 def downgrade_share_to_non_safe(
345 def downgrade_share_to_non_safe(
363 ui,
346 ui,
364 hgvfs,
347 hgvfs,
365 sharedvfs,
348 sharedvfs,
366 current_requirements,
349 current_requirements,
367 mismatch_config,
350 mismatch_config,
368 mismatch_warn,
351 mismatch_warn,
369 ):
352 ):
370 """Downgrades a share which use share-safe to not use it"""
353 """Downgrades a share which use share-safe to not use it"""
371 wlock = None
354 wlock = None
372 source_requirements = localrepo._readrequires(sharedvfs, True)
355 source_requirements = localrepo._readrequires(sharedvfs, True)
373 original_crequirements = current_requirements.copy()
356 original_crequirements = current_requirements.copy()
374 # we cannot be 100% sure on which requirements were present in store when
357 # we cannot be 100% sure on which requirements were present in store when
375 # the source supported share-safe. However, we do know that working
358 # the source supported share-safe. However, we do know that working
376 # directory requirements were not there. Hence we remove them
359 # directory requirements were not there. Hence we remove them
377 source_requirements -= requirementsmod.WORKING_DIR_REQUIREMENTS
360 source_requirements -= requirementsmod.WORKING_DIR_REQUIREMENTS
378 current_requirements |= source_requirements
361 current_requirements |= source_requirements
379 current_requirements.remove(requirementsmod.SHARESAFE_REQUIREMENT)
362 current_requirements.remove(requirementsmod.SHARESAFE_REQUIREMENT)
380 if mismatch_config == b'allow':
363 if mismatch_config == b'allow':
381 return
364 return
382
365
383 try:
366 try:
384 wlock = lockmod.trylock(ui, hgvfs, b'wlock', 0, 0)
367 wlock = lockmod.trylock(ui, hgvfs, b'wlock', 0, 0)
385 # some process might change the requirement in between, re-read
368 # some process might change the requirement in between, re-read
386 # and update current_requirements
369 # and update current_requirements
387 locked_requirements = localrepo._readrequires(hgvfs, True)
370 locked_requirements = localrepo._readrequires(hgvfs, True)
388 if locked_requirements != original_crequirements:
371 if locked_requirements != original_crequirements:
389 removed = current_requirements - locked_requirements
372 removed = current_requirements - locked_requirements
390 # update current_requirements in place because it's passed
373 # update current_requirements in place because it's passed
391 # as reference
374 # as reference
392 current_requirements -= removed
375 current_requirements -= removed
393 current_requirements |= locked_requirements
376 current_requirements |= locked_requirements
394 current_requirements |= source_requirements
377 current_requirements |= source_requirements
395 current_requirements -= set(requirementsmod.SHARESAFE_REQUIREMENT)
378 current_requirements -= set(requirementsmod.SHARESAFE_REQUIREMENT)
396 scmutil.writerequires(hgvfs, current_requirements)
379 scmutil.writerequires(hgvfs, current_requirements)
397 ui.warn(_(b'repository downgraded to not use share-safe mode\n'))
380 ui.warn(_(b'repository downgraded to not use share-safe mode\n'))
398 except error.LockError as e:
381 except error.LockError as e:
399 hint = _(
382 hint = _(
400 "see `hg help config.format.use-share-safe` for more information"
383 "see `hg help config.format.use-share-safe` for more information"
401 )
384 )
402 # If upgrade-abort is set, abort when upgrade fails, else let the
385 # If upgrade-abort is set, abort when upgrade fails, else let the
403 # process continue as `upgrade-allow` is set
386 # process continue as `upgrade-allow` is set
404 if mismatch_config == b'downgrade-abort':
387 if mismatch_config == b'downgrade-abort':
405 raise error.Abort(
388 raise error.Abort(
406 _(b'failed to downgrade share, got error: %s')
389 _(b'failed to downgrade share, got error: %s')
407 % stringutil.forcebytestr(e.strerror),
390 % stringutil.forcebytestr(e.strerror),
408 hint=hint,
391 hint=hint,
409 )
392 )
410 elif mismatch_warn:
393 elif mismatch_warn:
411 ui.warn(
394 ui.warn(
412 _(b'failed to downgrade share, got error: %s\n')
395 _(b'failed to downgrade share, got error: %s\n')
413 % stringutil.forcebytestr(e.strerror),
396 % stringutil.forcebytestr(e.strerror),
414 hint=hint,
397 hint=hint,
415 )
398 )
416 finally:
399 finally:
417 if wlock:
400 if wlock:
418 wlock.release()
401 wlock.release()
General Comments 0
You need to be logged in to leave comments. Login now