Mercurial > hg-stable
changeset 48790:5ba24e886cec
tracked-key: make it possible to upgrade to and downgrade from the feature
This seems rather important if we want people to start using it.
Differential Revision: https://phab.mercurial-scm.org/D12198
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Thu, 17 Feb 2022 06:32:03 +0100 |
parents | ef50a62eec40 |
children | 1af95465961a |
files | mercurial/dirstate.py mercurial/upgrade_utils/actions.py mercurial/upgrade_utils/engine.py tests/test-persistent-nodemap.t tests/test-status-tracked-key.t tests/test-upgrade-repo.t |
diffstat | 6 files changed, 118 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/dirstate.py Mon Jan 31 18:13:00 2022 +0300 +++ b/mercurial/dirstate.py Thu Feb 17 06:32:03 2022 +0100 @@ -763,6 +763,13 @@ with file(self._filename_tk) as f: self._write_tracked_key(tr, f) + def delete_tracked_key(self): + """remove the tracked_key file + + To be used by format downgrades operation""" + self._opener.unlink(self._filename_tk) + self._use_tracked_key = False + def addparentchangecallback(self, category, callback): """add a callback to be called when the wd parents are changed
--- a/mercurial/upgrade_utils/actions.py Mon Jan 31 18:13:00 2022 +0300 +++ b/mercurial/upgrade_utils/actions.py Thu Feb 17 06:32:03 2022 +0100 @@ -200,6 +200,29 @@ @registerformatvariant +class dirstatetrackedkey(requirementformatvariant): + name = b'tracked-key' + _requirement = requirements.DIRSTATE_TRACKED_KEY_V1 + + default = False + + description = _( + b'Add a small file to help external tooling that watch the tracked set' + ) + + upgrademessage = _( + b'external tools will be informated of potential change in the tracked set' + ) + + touches_filelogs = False + touches_manifests = False + touches_changelog = False + touches_requirements = True + touches_dirstate = True + compatible_with_share = True + + +@registerformatvariant class dotencode(requirementformatvariant): name = b'dotencode' @@ -967,6 +990,7 @@ requirements.REVLOGV2_REQUIREMENT, requirements.CHANGELOGV2_REQUIREMENT, requirements.REVLOGV1_REQUIREMENT, + requirements.DIRSTATE_TRACKED_KEY_V1, requirements.DIRSTATE_V2_REQUIREMENT, } for name in compression.compengines: @@ -989,6 +1013,7 @@ supported = { requirements.CHANGELOGV2_REQUIREMENT, requirements.COPIESSDC_REQUIREMENT, + requirements.DIRSTATE_TRACKED_KEY_V1, requirements.DIRSTATE_V2_REQUIREMENT, requirements.DOTENCODE_REQUIREMENT, requirements.FNCACHE_REQUIREMENT, @@ -1031,6 +1056,7 @@ requirements.REVLOGV1_REQUIREMENT, requirements.REVLOGV2_REQUIREMENT, requirements.CHANGELOGV2_REQUIREMENT, + requirements.DIRSTATE_TRACKED_KEY_V1, requirements.DIRSTATE_V2_REQUIREMENT, } for name in compression.compengines:
--- a/mercurial/upgrade_utils/engine.py Mon Jan 31 18:13:00 2022 +0300 +++ b/mercurial/upgrade_utils/engine.py Thu Feb 17 06:32:03 2022 +0100 @@ -486,6 +486,15 @@ upgrade_dirstate(ui, srcrepo, upgrade_op, b'v2', b'v1') upgrade_op.removed_actions.remove(upgrade_actions.dirstatev2) + if upgrade_actions.dirstatetrackedkey in upgrade_op.upgrade_actions: + ui.status(_(b'create dirstate-tracked-key file\n')) + upgrade_tracked_key(ui, srcrepo, upgrade_op, add=True) + upgrade_op.upgrade_actions.remove(upgrade_actions.dirstatetrackedkey) + elif upgrade_actions.dirstatetrackedkey in upgrade_op.removed_actions: + ui.status(_(b'remove dirstate-tracked-key file\n')) + upgrade_tracked_key(ui, srcrepo, upgrade_op, add=False) + upgrade_op.removed_actions.remove(upgrade_actions.dirstatetrackedkey) + if not (upgrade_op.upgrade_actions or upgrade_op.removed_actions): return @@ -660,3 +669,15 @@ srcrepo.dirstate.write(None) scmutil.writereporequirements(srcrepo, upgrade_op.new_requirements) + + +def upgrade_tracked_key(ui, srcrepo, upgrade_op, add): + if add: + srcrepo.dirstate._use_tracked_key = True + srcrepo.dirstate._dirty = True + srcrepo.dirstate._dirty_tracked_set = True + srcrepo.dirstate.write(None) + if not add: + srcrepo.dirstate.delete_tracked_key() + + scmutil.writereporequirements(srcrepo, upgrade_op.new_requirements)
--- a/tests/test-persistent-nodemap.t Mon Jan 31 18:13:00 2022 +0300 +++ b/tests/test-persistent-nodemap.t Thu Feb 17 06:32:03 2022 +0100 @@ -65,6 +65,7 @@ format-variant repo fncache: yes dirstate-v2: no + tracked-key: no dotencode: yes generaldelta: yes share-safe: yes @@ -782,6 +783,7 @@ format-variant repo config default fncache: yes yes yes dirstate-v2: no no no + tracked-key: no no no dotencode: yes yes yes generaldelta: yes yes yes share-safe: yes yes yes @@ -824,6 +826,7 @@ format-variant repo config default fncache: yes yes yes dirstate-v2: no no no + tracked-key: no no no dotencode: yes yes yes generaldelta: yes yes yes share-safe: yes yes yes
--- a/tests/test-status-tracked-key.t Mon Jan 31 18:13:00 2022 +0300 +++ b/tests/test-status-tracked-key.t Thu Feb 17 06:32:03 2022 +0100 @@ -161,3 +161,44 @@ $ hg up '.#generations[-1]' 1 files updated, 0 files merged, 0 files removed, 0 files unresolved $ diff --brief .hg/dirstate-tracked-key ../key-bck + +Test upgrade and downgrade +========================== + + $ ls .hg/dirstate-tracked-key + .hg/dirstate-tracked-key + $ hg debugrequires | grep 'tracked' + exp-dirstate-tracked-key-v1 + +downgrade + + $ hg debugupgraderepo --config format.dirstate-tracked-key=no --run --quiet + upgrade will perform the following actions: + + requirements + preserved: * (glob) + removed: exp-dirstate-tracked-key-v1 + + no revlogs to process + + $ ls -1 .hg/dirstate-tracked-key + ls: cannot access '.hg/dirstate-tracked-key': $ENOENT$ + [2] + $ hg debugrequires | grep 'tracked' + [1] + +upgrade + + $ hg debugupgraderepo --config format.dirstate-tracked-key=yes --run --quiet + upgrade will perform the following actions: + + requirements + preserved: * (glob) + added: exp-dirstate-tracked-key-v1 + + no revlogs to process + + $ ls -1 .hg/dirstate-tracked-key + .hg/dirstate-tracked-key + $ hg debugrequires | grep 'tracked' + exp-dirstate-tracked-key-v1
--- a/tests/test-upgrade-repo.t Mon Jan 31 18:13:00 2022 +0300 +++ b/tests/test-upgrade-repo.t Thu Feb 17 06:32:03 2022 +0100 @@ -214,6 +214,7 @@ format-variant repo fncache: yes dirstate-v2: no + tracked-key: no dotencode: yes generaldelta: yes share-safe: yes @@ -230,6 +231,7 @@ format-variant repo config default fncache: yes yes yes dirstate-v2: no no no + tracked-key: no no no dotencode: yes yes yes generaldelta: yes yes yes share-safe: yes yes yes @@ -247,6 +249,7 @@ format-variant repo config default fncache: yes no yes dirstate-v2: no no no + tracked-key: no no no dotencode: yes no yes generaldelta: yes yes yes share-safe: yes yes yes @@ -264,6 +267,7 @@ format-variant repo config default [formatvariant.name.mismatchconfig|fncache: ][formatvariant.repo.mismatchconfig| yes][formatvariant.config.special| no][formatvariant.default| yes] [formatvariant.name.uptodate|dirstate-v2: ][formatvariant.repo.uptodate| no][formatvariant.config.default| no][formatvariant.default| no] + [formatvariant.name.uptodate|tracked-key: ][formatvariant.repo.uptodate| no][formatvariant.config.default| no][formatvariant.default| no] [formatvariant.name.mismatchconfig|dotencode: ][formatvariant.repo.mismatchconfig| yes][formatvariant.config.special| no][formatvariant.default| yes] [formatvariant.name.uptodate|generaldelta: ][formatvariant.repo.uptodate| yes][formatvariant.config.default| yes][formatvariant.default| yes] [formatvariant.name.uptodate|share-safe: ][formatvariant.repo.uptodate| yes][formatvariant.config.default| yes][formatvariant.default| yes] @@ -292,6 +296,12 @@ "repo": false }, { + "config": false, + "default": false, + "name": "tracked-key", + "repo": false + }, + { "config": true, "default": true, "name": "dotencode", @@ -488,6 +498,7 @@ format-variant repo fncache: no dirstate-v2: no + tracked-key: no dotencode: no generaldelta: no share-safe: no @@ -503,6 +514,7 @@ format-variant repo config default fncache: no yes yes dirstate-v2: no no no + tracked-key: no no no dotencode: no yes yes generaldelta: no yes yes share-safe: no yes yes @@ -520,6 +532,7 @@ format-variant repo config default fncache: no yes yes dirstate-v2: no no no + tracked-key: no no no dotencode: no yes yes generaldelta: no no yes share-safe: no yes yes @@ -537,6 +550,7 @@ format-variant repo config default [formatvariant.name.mismatchconfig|fncache: ][formatvariant.repo.mismatchconfig| no][formatvariant.config.default| yes][formatvariant.default| yes] [formatvariant.name.uptodate|dirstate-v2: ][formatvariant.repo.uptodate| no][formatvariant.config.default| no][formatvariant.default| no] + [formatvariant.name.uptodate|tracked-key: ][formatvariant.repo.uptodate| no][formatvariant.config.default| no][formatvariant.default| no] [formatvariant.name.mismatchconfig|dotencode: ][formatvariant.repo.mismatchconfig| no][formatvariant.config.default| yes][formatvariant.default| yes] [formatvariant.name.mismatchdefault|generaldelta: ][formatvariant.repo.mismatchdefault| no][formatvariant.config.special| no][formatvariant.default| yes] [formatvariant.name.mismatchconfig|share-safe: ][formatvariant.repo.mismatchconfig| no][formatvariant.config.default| yes][formatvariant.default| yes] @@ -1588,6 +1602,7 @@ format-variant repo config default fncache: yes yes yes dirstate-v2: no no no + tracked-key: no no no dotencode: yes yes yes generaldelta: yes yes yes share-safe: yes yes yes @@ -1631,6 +1646,7 @@ format-variant repo config default fncache: yes yes yes dirstate-v2: no no no + tracked-key: no no no dotencode: yes yes yes generaldelta: yes yes yes share-safe: yes yes yes @@ -1677,6 +1693,7 @@ format-variant repo config default fncache: yes yes yes dirstate-v2: no no no + tracked-key: no no no dotencode: yes yes yes generaldelta: yes yes yes share-safe: yes yes yes @@ -1729,6 +1746,7 @@ format-variant repo config default fncache: yes yes yes dirstate-v2: no no no + tracked-key: no no no dotencode: yes yes yes generaldelta: yes yes yes share-safe: yes yes yes @@ -1778,6 +1796,7 @@ format-variant repo config default fncache: yes yes yes dirstate-v2: no no no + tracked-key: no no no dotencode: yes yes yes generaldelta: yes yes yes share-safe: yes yes yes @@ -1828,6 +1847,7 @@ format-variant repo config default fncache: yes yes yes dirstate-v2: no no no + tracked-key: no no no dotencode: yes yes yes generaldelta: yes yes yes share-safe: yes yes yes