Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/upgrade_utils/engine.py @ 46447:2e8a844d0ae0
upgrade: don't create store backup if `--no-backup` is passed
If the user explicitly mentioned that they don't need backup, then let's not
create it.
Differential Revision: https://phab.mercurial-scm.org/D9770
author | Pulkit Goyal <7895pulkit@gmail.com> |
---|---|
date | Thu, 14 Jan 2021 16:25:40 +0530 |
parents | 8023991dc811 |
children | ee9002b99595 |
comparison
equal
deleted
inserted
replaced
46446:e92ca942ddca | 46447:2e8a844d0ae0 |
---|---|
410 upgrade_op: upgrade operation object | 410 upgrade_op: upgrade operation object |
411 to be used to decide what all is upgraded | 411 to be used to decide what all is upgraded |
412 """ | 412 """ |
413 # TODO: don't blindly rename everything in store | 413 # TODO: don't blindly rename everything in store |
414 # There can be upgrades where store is not touched at all | 414 # There can be upgrades where store is not touched at all |
415 util.rename(currentrepo.spath, backupvfs.join(b'store')) | 415 if upgrade_op.backup_store: |
416 util.rename(currentrepo.spath, backupvfs.join(b'store')) | |
417 else: | |
418 currentrepo.vfs.rmtree(b'store', forcibly=True) | |
416 util.rename(upgradedrepo.spath, currentrepo.spath) | 419 util.rename(upgradedrepo.spath, currentrepo.spath) |
417 | 420 |
418 | 421 |
419 def finishdatamigration(ui, srcrepo, dstrepo, requirements): | 422 def finishdatamigration(ui, srcrepo, dstrepo, requirements): |
420 """Hook point for extensions to perform additional actions during upgrade. | 423 """Hook point for extensions to perform additional actions during upgrade. |
434 upgrade can abort at any time without causing loss of service for | 437 upgrade can abort at any time without causing loss of service for |
435 readers and without corrupting the source repository. | 438 readers and without corrupting the source repository. |
436 """ | 439 """ |
437 assert srcrepo.currentwlock() | 440 assert srcrepo.currentwlock() |
438 assert dstrepo.currentwlock() | 441 assert dstrepo.currentwlock() |
442 backuppath = None | |
443 backupvfs = None | |
439 | 444 |
440 ui.status( | 445 ui.status( |
441 _( | 446 _( |
442 b'(it is safe to interrupt this process any time before ' | 447 b'(it is safe to interrupt this process any time before ' |
443 b'data migration completes)\n' | 448 b'data migration completes)\n' |
462 | 467 |
463 finishdatamigration(ui, srcrepo, dstrepo, requirements) | 468 finishdatamigration(ui, srcrepo, dstrepo, requirements) |
464 | 469 |
465 ui.status(_(b'data fully upgraded in a temporary repository\n')) | 470 ui.status(_(b'data fully upgraded in a temporary repository\n')) |
466 | 471 |
467 backuppath = pycompat.mkdtemp(prefix=b'upgradebackup.', dir=srcrepo.path) | 472 if upgrade_op.backup_store: |
468 backupvfs = vfsmod.vfs(backuppath) | 473 backuppath = pycompat.mkdtemp( |
469 | 474 prefix=b'upgradebackup.', dir=srcrepo.path |
470 # Make a backup of requires file first, as it is the first to be modified. | 475 ) |
471 util.copyfile(srcrepo.vfs.join(b'requires'), backupvfs.join(b'requires')) | 476 backupvfs = vfsmod.vfs(backuppath) |
477 | |
478 # Make a backup of requires file first, as it is the first to be modified. | |
479 util.copyfile( | |
480 srcrepo.vfs.join(b'requires'), backupvfs.join(b'requires') | |
481 ) | |
472 | 482 |
473 # We install an arbitrary requirement that clients must not support | 483 # We install an arbitrary requirement that clients must not support |
474 # as a mechanism to lock out new clients during the data swap. This is | 484 # as a mechanism to lock out new clients during the data swap. This is |
475 # better than allowing a client to continue while the repository is in | 485 # better than allowing a client to continue while the repository is in |
476 # an inconsistent state. | 486 # an inconsistent state. |
483 scmutil.writereporequirements( | 493 scmutil.writereporequirements( |
484 srcrepo, srcrepo.requirements | {b'upgradeinprogress'} | 494 srcrepo, srcrepo.requirements | {b'upgradeinprogress'} |
485 ) | 495 ) |
486 | 496 |
487 ui.status(_(b'starting in-place swap of repository data\n')) | 497 ui.status(_(b'starting in-place swap of repository data\n')) |
488 ui.status(_(b'replaced files will be backed up at %s\n') % backuppath) | 498 if upgrade_op.backup_store: |
499 ui.status(_(b'replaced files will be backed up at %s\n') % backuppath) | |
489 | 500 |
490 # Now swap in the new store directory. Doing it as a rename should make | 501 # Now swap in the new store directory. Doing it as a rename should make |
491 # the operation nearly instantaneous and atomic (at least in well-behaved | 502 # the operation nearly instantaneous and atomic (at least in well-behaved |
492 # environments). | 503 # environments). |
493 ui.status(_(b'replacing store...\n')) | 504 ui.status(_(b'replacing store...\n')) |
510 b'again\n' | 521 b'again\n' |
511 ) | 522 ) |
512 ) | 523 ) |
513 scmutil.writereporequirements(srcrepo, upgrade_op.new_requirements) | 524 scmutil.writereporequirements(srcrepo, upgrade_op.new_requirements) |
514 | 525 |
515 # The lock file from the old store won't be removed because nothing has a | 526 if upgrade_op.backup_store: |
516 # reference to its new location. So clean it up manually. Alternatively, we | 527 # The lock file from the old store won't be removed because nothing has a |
517 # could update srcrepo.svfs and other variables to point to the new | 528 # reference to its new location. So clean it up manually. Alternatively, we |
518 # location. This is simpler. | 529 # could update srcrepo.svfs and other variables to point to the new |
519 backupvfs.unlink(b'store/lock') | 530 # location. This is simpler. |
531 backupvfs.unlink(b'store/lock') | |
520 | 532 |
521 return backuppath | 533 return backuppath |