Mercurial > hg
changeset 47085:3aab2330b7d3
sidedata: move sidedata-related utils to the dedicated module
Differential Revision: https://phab.mercurial-scm.org/D10360
author | Raphaël Gomès <rgomes@octobus.net> |
---|---|
date | Mon, 19 Apr 2021 11:22:24 +0200 |
parents | 27f1191b1305 |
children | 8bd769b5c941 |
files | mercurial/changegroup.py mercurial/localrepo.py mercurial/metadata.py mercurial/revlog.py mercurial/revlogutils/sidedata.py mercurial/upgrade_utils/engine.py mercurial/utils/storageutil.py tests/testlib/ext-sidedata.py |
diffstat | 8 files changed, 75 insertions(+), 73 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/changegroup.py Mon Apr 19 11:22:24 2021 +0200 +++ b/mercurial/changegroup.py Mon Apr 19 11:22:24 2021 +0200 @@ -7,7 +7,6 @@ from __future__ import absolute_import -import collections import os import struct import weakref @@ -301,7 +300,7 @@ and srctype == b'pull' ) if adding_sidedata: - sidedata_helpers = get_sidedata_helpers( + sidedata_helpers = sidedatamod.get_sidedata_helpers( repo, sidedata_categories or set(), pull=True, @@ -1073,7 +1072,9 @@ # TODO a better approach would be for the strip bundle to # correctly advertise its sidedata categories directly. remote_sidedata = repo._wanted_sidedata - sidedata_helpers = get_sidedata_helpers(repo, remote_sidedata) + sidedata_helpers = sidedatamod.get_sidedata_helpers( + repo, remote_sidedata + ) clstate, deltas = self._generatechangelog( cl, @@ -1940,24 +1941,3 @@ ) return revisions, files - - -def get_sidedata_helpers(repo, remote_sd_categories, pull=False): - # Computers for computing sidedata on-the-fly - sd_computers = collections.defaultdict(list) - # Computers for categories to remove from sidedata - sd_removers = collections.defaultdict(list) - to_generate = remote_sd_categories - repo._wanted_sidedata - to_remove = repo._wanted_sidedata - remote_sd_categories - if pull: - to_generate, to_remove = to_remove, to_generate - - for revlog_kind, computers in repo._sidedata_computers.items(): - for category, computer in computers.items(): - if category in to_generate: - sd_computers[revlog_kind].append(computer) - if category in to_remove: - sd_removers[revlog_kind].append(computer) - - sidedata_helpers = (repo, sd_computers, sd_removers) - return sidedata_helpers
--- a/mercurial/localrepo.py Mon Apr 19 11:22:24 2021 +0200 +++ b/mercurial/localrepo.py Mon Apr 19 11:22:24 2021 +0200 @@ -49,7 +49,6 @@ match as matchmod, mergestate as mergestatemod, mergeutil, - metadata as metadatamod, namespaces, narrowspec, obsolete, @@ -90,6 +89,7 @@ from .revlogutils import ( concurrency_checker as revlogchecker, constants as revlogconst, + sidedata as sidedatamod, ) release = lockmod.release @@ -1407,7 +1407,7 @@ self._wanted_sidedata = set() self._sidedata_computers = {} - metadatamod.set_sidedata_spec_for_repo(self) + sidedatamod.set_sidedata_spec_for_repo(self) def _getvfsward(self, origfunc): """build a ward for self.vfs"""
--- a/mercurial/metadata.py Mon Apr 19 11:22:24 2021 +0200 +++ b/mercurial/metadata.py Mon Apr 19 11:22:24 2021 +0200 @@ -14,12 +14,10 @@ from .node import nullrev from . import ( error, - requirements as requirementsmod, util, ) from .revlogutils import ( - constants as revlogconst, flagutil as sidedataflag, sidedata as sidedatamod, ) @@ -824,18 +822,6 @@ return sidedata, (flags_to_add, 0) -def set_sidedata_spec_for_repo(repo): - if requirementsmod.COPIESSDC_REQUIREMENT in repo.requirements: - repo.register_wanted_sidedata(sidedatamod.SD_FILES) - repo.register_sidedata_computer( - revlogconst.KIND_CHANGELOG, - sidedatamod.SD_FILES, - (sidedatamod.SD_FILES,), - copies_sidedata_computer, - sidedataflag.REVIDX_HASCOPIESINFO, - ) - - def _sidedata_worker(srcrepo, revs_queue, sidedata_queue, tokens): """The function used by worker precomputing sidedata
--- a/mercurial/revlog.py Mon Apr 19 11:22:24 2021 +0200 +++ b/mercurial/revlog.py Mon Apr 19 11:22:24 2021 +0200 @@ -2781,7 +2781,7 @@ text, sidedata = self._revisiondata(rev) if sidedata_helpers is not None: - (sidedata, new_flags) = storageutil.run_sidedata_helpers( + (sidedata, new_flags) = sidedatautil.run_sidedata_helpers( self, sidedata_helpers, sidedata, rev ) flags = flags | new_flags[0] & ~new_flags[1] @@ -2811,7 +2811,7 @@ sidedata = self.sidedata(rev) if sidedata_helpers is not None: - (sidedata, new_flags) = storageutil.run_sidedata_helpers( + (sidedata, new_flags) = sidedatautil.run_sidedata_helpers( self, sidedata_helpers, sidedata, rev ) flags = flags | new_flags[0] & ~new_flags[1] @@ -3089,7 +3089,7 @@ current_offset = fp.tell() for rev in range(startrev, endrev + 1): entry = self.index[rev] - new_sidedata, flags = storageutil.run_sidedata_helpers( + new_sidedata, flags = sidedatautil.run_sidedata_helpers( store=self, sidedata_helpers=helpers, sidedata={},
--- a/mercurial/revlogutils/sidedata.py Mon Apr 19 11:22:24 2021 +0200 +++ b/mercurial/revlogutils/sidedata.py Mon Apr 19 11:22:24 2021 +0200 @@ -32,9 +32,11 @@ from __future__ import absolute_import +import collections import struct -from .. import error +from .. import error, requirements as requirementsmod +from ..revlogutils import constants, flagutil from ..utils import hashutil ## sidedata type constant @@ -91,3 +93,63 @@ sidedata[key] = entrytext dataoffset = nextdataoffset return sidedata + + +def get_sidedata_helpers(repo, remote_sd_categories, pull=False): + # Computers for computing sidedata on-the-fly + sd_computers = collections.defaultdict(list) + # Computers for categories to remove from sidedata + sd_removers = collections.defaultdict(list) + to_generate = remote_sd_categories - repo._wanted_sidedata + to_remove = repo._wanted_sidedata - remote_sd_categories + if pull: + to_generate, to_remove = to_remove, to_generate + + for revlog_kind, computers in repo._sidedata_computers.items(): + for category, computer in computers.items(): + if category in to_generate: + sd_computers[revlog_kind].append(computer) + if category in to_remove: + sd_removers[revlog_kind].append(computer) + + sidedata_helpers = (repo, sd_computers, sd_removers) + return sidedata_helpers + + +def run_sidedata_helpers(store, sidedata_helpers, sidedata, rev): + """Returns the sidedata for the given revision after running through + the given helpers. + - `store`: the revlog this applies to (changelog, manifest, or filelog + instance) + - `sidedata_helpers`: see `storageutil.emitrevisions` + - `sidedata`: previous sidedata at the given rev, if any + - `rev`: affected rev of `store` + """ + repo, sd_computers, sd_removers = sidedata_helpers + kind = store.revlog_kind + flags_to_add = 0 + flags_to_remove = 0 + for _keys, sd_computer, _flags in sd_computers.get(kind, []): + sidedata, flags = sd_computer(repo, store, rev, sidedata) + flags_to_add |= flags[0] + flags_to_remove |= flags[1] + for keys, _computer, flags in sd_removers.get(kind, []): + for key in keys: + sidedata.pop(key, None) + flags_to_remove |= flags + return sidedata, (flags_to_add, flags_to_remove) + + +def set_sidedata_spec_for_repo(repo): + # prevent cycle metadata -> revlogutils.sidedata -> metadata + from .. import metadata + + if requirementsmod.COPIESSDC_REQUIREMENT in repo.requirements: + repo.register_wanted_sidedata(SD_FILES) + repo.register_sidedata_computer( + constants.KIND_CHANGELOG, + SD_FILES, + (SD_FILES,), + metadata.copies_sidedata_computer, + flagutil.REVIDX_HASCOPIESINFO, + )
--- a/mercurial/upgrade_utils/engine.py Mon Apr 19 11:22:24 2021 +0200 +++ b/mercurial/upgrade_utils/engine.py Mon Apr 19 11:22:24 2021 +0200 @@ -12,7 +12,6 @@ from ..i18n import _ from ..pycompat import getattr from .. import ( - changegroup, changelog, error, filelog, @@ -45,7 +44,7 @@ flagutil.REVIDX_HASCOPIESINFO, replace=True, ) - return changegroup.get_sidedata_helpers(srcrepo, dstrepo._wanted_sidedata) + return sidedatamod.get_sidedata_helpers(srcrepo, dstrepo._wanted_sidedata) def _revlogfrompath(repo, rl_type, path):
--- a/mercurial/utils/storageutil.py Mon Apr 19 11:22:24 2021 +0200 +++ b/mercurial/utils/storageutil.py Mon Apr 19 11:22:24 2021 +0200 @@ -499,7 +499,7 @@ sidedata_flags = (0, 0) if sidedata_helpers: old_sidedata = store.sidedata(rev) - sidedata, sidedata_flags = run_sidedata_helpers( + sidedata, sidedata_flags = sidedatamod.run_sidedata_helpers( store=store, sidedata_helpers=sidedata_helpers, sidedata=old_sidedata, @@ -532,30 +532,6 @@ prevrev = rev -def run_sidedata_helpers(store, sidedata_helpers, sidedata, rev): - """Returns the sidedata for the given revision after running through - the given helpers. - - `store`: the revlog this applies to (changelog, manifest, or filelog - instance) - - `sidedata_helpers`: see `storageutil.emitrevisions` - - `sidedata`: previous sidedata at the given rev, if any - - `rev`: affected rev of `store` - """ - repo, sd_computers, sd_removers = sidedata_helpers - kind = store.revlog_kind - flags_to_add = 0 - flags_to_remove = 0 - for _keys, sd_computer, _flags in sd_computers.get(kind, []): - sidedata, flags = sd_computer(repo, store, rev, sidedata) - flags_to_add |= flags[0] - flags_to_remove |= flags[1] - for keys, _computer, flags in sd_removers.get(kind, []): - for key in keys: - sidedata.pop(key, None) - flags_to_remove |= flags - return sidedata, (flags_to_add, flags_to_remove) - - def deltaiscensored(delta, baserev, baselenfn): """Determine if a delta represents censored revision data.
--- a/tests/testlib/ext-sidedata.py Mon Apr 19 11:22:24 2021 +0200 +++ b/tests/testlib/ext-sidedata.py Mon Apr 19 11:22:24 2021 +0200 @@ -12,7 +12,6 @@ from mercurial.node import nullrev from mercurial import ( - changegroup, extensions, requirements, revlog, @@ -88,7 +87,7 @@ ) dstrepo.register_wanted_sidedata(b"whatever") - return changegroup.get_sidedata_helpers(srcrepo, dstrepo._wanted_sidedata) + return sidedata.get_sidedata_helpers(srcrepo, dstrepo._wanted_sidedata) def extsetup(ui):