Mercurial > hg-stable
diff tests/testlib/ext-sidedata.py @ 43134:75ad8af9c95e
upgrade: allow upgrade to repository using sidedata
Repository can now be migrated to support sidedata. More requirements and
migration will be needed to actual side-data usage. This is a step in that
direction.
To test the feature, we leverage the test extension. It make sure the `update`
part of the side-data migration actually works.
Differential Revision: https://phab.mercurial-scm.org/D6942
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Sun, 06 Oct 2019 23:36:51 -0400 |
parents | 2372284d9457 |
children | d7dcc75a3eae |
line wrap: on
line diff
--- a/tests/testlib/ext-sidedata.py Sun Oct 06 23:36:51 2019 -0400 +++ b/tests/testlib/ext-sidedata.py Sun Oct 06 23:36:51 2019 -0400 @@ -12,8 +12,10 @@ from mercurial import ( extensions, + localrepo, node, revlog, + upgrade, ) from mercurial.revlogutils import sidedata @@ -36,6 +38,8 @@ def wraprevision(orig, self, nodeorrev, *args, **kwargs): text = orig(self, nodeorrev, *args, **kwargs) + if getattr(self, 'sidedatanocheck', False): + return text if nodeorrev != node.nullrev and nodeorrev != node.nullid: sd = self.sidedata(nodeorrev) if len(text) != struct.unpack('>I', sd[sidedata.SD_TEST1])[0]: @@ -47,6 +51,33 @@ return text +def wrapgetsidedatacompanion(orig, srcrepo, dstrepo): + sidedatacompanion = orig(srcrepo, dstrepo) + addedreqs = dstrepo.requirements - srcrepo.requirements + if localrepo.SIDEDATA_REQUIREMENT in addedreqs: + assert sidedatacompanion is None # deal with composition later + + def sidedatacompanion(revlog, rev): + update = {} + revlog.sidedatanocheck = True + try: + text = revlog.revision(rev) + finally: + del revlog.sidedatanocheck + ## let's store some arbitrary data just for testing + # text length + update[sidedata.SD_TEST1] = struct.pack('>I', len(text)) + # and sha2 hashes + sha256 = hashlib.sha256(text).digest() + update[sidedata.SD_TEST2] = struct.pack('>32s', sha256) + return False, (), update + + return sidedatacompanion + + def extsetup(ui): extensions.wrapfunction(revlog.revlog, 'addrevision', wrapaddrevision) extensions.wrapfunction(revlog.revlog, 'revision', wraprevision) + extensions.wrapfunction( + upgrade, 'getsidedatacompanion', wrapgetsidedatacompanion + )