comparison mercurial/upgrade.py @ 46335:25be21ec6c65

share: rework config options to be much clearer and easier Recently I implemented various boolean configs which control how to behave when there is a share-safe mismatch between source and share repository. Mismatch means that source supports share-safe where as share does not or vice versa. However, while discussion and documentation we realized that it's too complicated and there are some combinations of values which makes no sense. We decided to introduce a config option with 4 possible values which makes controlling and understanding things easier. The config option `share.safe-mismatch.source-{not-}safe` can have following 4 values: * abort (default): error out if there is mismatch * allow: allow to work with respecting share source configuration * {up|down}grade-abort: try to {up|down}grade, if it fails, abort * {up|down}grade-allow: try to {up|down}grade, if it fails, continue in allow mode I am not sure if I can explain 3 config options which I deleted right now in just 5 lines which is a sign of how complex they became. No test changes demonstrate that functionality is same, only names have changed. Differential Revision: https://phab.mercurial-scm.org/D9785
author Pulkit Goyal <7895pulkit@gmail.com>
date Mon, 18 Jan 2021 21:37:20 +0530
parents 02f3badf9011
children 2eb5fe13461b
comparison
equal deleted inserted replaced
46331:8788981c95f8 46335:25be21ec6c65
239 ) 239 )
240 240
241 upgrade_op.print_post_op_messages() 241 upgrade_op.print_post_op_messages()
242 242
243 243
244 def upgrade_share_to_safe(ui, hgvfs, storevfs, current_requirements): 244 def upgrade_share_to_safe(
245 ui, hgvfs, storevfs, current_requirements, mismatch_config
246 ):
245 """Upgrades a share to use share-safe mechanism""" 247 """Upgrades a share to use share-safe mechanism"""
246 wlock = None 248 wlock = None
247 store_requirements = localrepo._readrequires(storevfs, False) 249 store_requirements = localrepo._readrequires(storevfs, False)
248 original_crequirements = current_requirements.copy() 250 original_crequirements = current_requirements.copy()
249 # after upgrade, store requires will be shared, so lets find 251 # after upgrade, store requires will be shared, so lets find
251 # write them to share's .hg/requires 253 # write them to share's .hg/requires
252 diffrequires = current_requirements - store_requirements 254 diffrequires = current_requirements - store_requirements
253 # add share-safe requirement as it will mark the share as share-safe 255 # add share-safe requirement as it will mark the share as share-safe
254 diffrequires.add(requirementsmod.SHARESAFE_REQUIREMENT) 256 diffrequires.add(requirementsmod.SHARESAFE_REQUIREMENT)
255 current_requirements.add(requirementsmod.SHARESAFE_REQUIREMENT) 257 current_requirements.add(requirementsmod.SHARESAFE_REQUIREMENT)
258 # in `allow` case, we don't try to upgrade, we just respect the source
259 # state, update requirements and continue
260 if mismatch_config == b'allow':
261 return
256 try: 262 try:
257 wlock = lockmod.trylock(ui, hgvfs, b'wlock', 0, 0) 263 wlock = lockmod.trylock(ui, hgvfs, b'wlock', 0, 0)
258 # some process might change the requirement in between, re-read 264 # some process might change the requirement in between, re-read
259 # and update current_requirements 265 # and update current_requirements
260 locked_requirements = localrepo._readrequires(hgvfs, True) 266 locked_requirements = localrepo._readrequires(hgvfs, True)
269 diffrequires.add(requirementsmod.SHARESAFE_REQUIREMENT) 275 diffrequires.add(requirementsmod.SHARESAFE_REQUIREMENT)
270 current_requirements.add(requirementsmod.SHARESAFE_REQUIREMENT) 276 current_requirements.add(requirementsmod.SHARESAFE_REQUIREMENT)
271 scmutil.writerequires(hgvfs, diffrequires) 277 scmutil.writerequires(hgvfs, diffrequires)
272 ui.warn(_(b'repository upgraded to use share-safe mode\n')) 278 ui.warn(_(b'repository upgraded to use share-safe mode\n'))
273 except error.LockError as e: 279 except error.LockError as e:
274 if ui.configbool(b'experimental', b'sharesafe-auto-upgrade-fail-error'): 280 if mismatch_config == b'upgrade-abort':
275 raise error.Abort( 281 raise error.Abort(
276 _(b'failed to upgrade share, got error: %s') 282 _(b'failed to upgrade share, got error: %s')
277 % stringutil.forcebytestr(e.strerror) 283 % stringutil.forcebytestr(e.strerror)
278 ) 284 )
279 elif ui.configbool(b'experimental', b'sharesafe-warn-outdated-shares'): 285 elif ui.configbool(b'experimental', b'sharesafe-warn-outdated-shares'):
289 def downgrade_share_to_non_safe( 295 def downgrade_share_to_non_safe(
290 ui, 296 ui,
291 hgvfs, 297 hgvfs,
292 sharedvfs, 298 sharedvfs,
293 current_requirements, 299 current_requirements,
300 mismatch_config,
294 ): 301 ):
295 """Downgrades a share which use share-safe to not use it""" 302 """Downgrades a share which use share-safe to not use it"""
296 wlock = None 303 wlock = None
297 source_requirements = localrepo._readrequires(sharedvfs, True) 304 source_requirements = localrepo._readrequires(sharedvfs, True)
298 original_crequirements = current_requirements.copy() 305 original_crequirements = current_requirements.copy()
300 # the source supported share-safe. However, we do know that working 307 # the source supported share-safe. However, we do know that working
301 # directory requirements were not there. Hence we remove them 308 # directory requirements were not there. Hence we remove them
302 source_requirements -= requirementsmod.WORKING_DIR_REQUIREMENTS 309 source_requirements -= requirementsmod.WORKING_DIR_REQUIREMENTS
303 current_requirements |= source_requirements 310 current_requirements |= source_requirements
304 current_requirements.remove(requirementsmod.SHARESAFE_REQUIREMENT) 311 current_requirements.remove(requirementsmod.SHARESAFE_REQUIREMENT)
312 if mismatch_config == b'allow':
313 return
305 314
306 try: 315 try:
307 wlock = lockmod.trylock(ui, hgvfs, b'wlock', 0, 0) 316 wlock = lockmod.trylock(ui, hgvfs, b'wlock', 0, 0)
308 # some process might change the requirement in between, re-read 317 # some process might change the requirement in between, re-read
309 # and update current_requirements 318 # and update current_requirements
317 current_requirements |= source_requirements 326 current_requirements |= source_requirements
318 current_requirements -= set(requirementsmod.SHARESAFE_REQUIREMENT) 327 current_requirements -= set(requirementsmod.SHARESAFE_REQUIREMENT)
319 scmutil.writerequires(hgvfs, current_requirements) 328 scmutil.writerequires(hgvfs, current_requirements)
320 ui.warn(_(b'repository downgraded to not use share-safe mode\n')) 329 ui.warn(_(b'repository downgraded to not use share-safe mode\n'))
321 except error.LockError as e: 330 except error.LockError as e:
322 # raise error right away because if downgrade failed, we cannot load 331 # If upgrade-abort is set, abort when upgrade fails, else let the
323 # the repository because it does not have complete set of requirements 332 # process continue as `upgrade-allow` is set
324 raise error.Abort( 333 if mismatch_config == b'downgrade-abort':
325 _(b'failed to downgrade share, got error: %s') 334 raise error.Abort(
326 % stringutil.forcebytestr(e.strerror) 335 _(b'failed to downgrade share, got error: %s')
327 ) 336 % stringutil.forcebytestr(e.strerror)
337 )
328 finally: 338 finally:
329 if wlock: 339 if wlock:
330 wlock.release() 340 wlock.release()