comparison tests/testlib/ext-sidedata-2.py @ 47078:223b47235d1c

sidedata: enable sidedata computers to optionally rewrite flags Sidedata computers may want to influence the flags of the revision they touch. For example, the computer for changelog-based copytracing can add a flag to signify that this revision might affect copytracing, inversely removing said flag if the information is no longer applicable. See inline documentation in `storageutil` for more details. Differential Revision: https://phab.mercurial-scm.org/D10344
author Raphaël Gomès <rgomes@octobus.net>
date Thu, 08 Apr 2021 16:55:17 +0200
parents 64cd1496bb70
children 6000f5b25c9b
comparison
equal deleted inserted replaced
47077:119790e1c67c 47078:223b47235d1c
14 import struct 14 import struct
15 15
16 from mercurial.revlogutils import sidedata as sidedatamod 16 from mercurial.revlogutils import sidedata as sidedatamod
17 from mercurial.revlogutils import constants 17 from mercurial.revlogutils import constants
18 18
19 NO_FLAGS = (0, 0) # hoot
20
19 21
20 def compute_sidedata_1(repo, revlog, rev, sidedata, text=None): 22 def compute_sidedata_1(repo, revlog, rev, sidedata, text=None):
21 sidedata = sidedata.copy() 23 sidedata = sidedata.copy()
22 if text is None: 24 if text is None:
23 text = revlog.revision(rev) 25 text = revlog.revision(rev)
24 sidedata[sidedatamod.SD_TEST1] = struct.pack('>I', len(text)) 26 sidedata[sidedatamod.SD_TEST1] = struct.pack('>I', len(text))
25 return sidedata 27 return sidedata, NO_FLAGS
26 28
27 29
28 def compute_sidedata_2(repo, revlog, rev, sidedata, text=None): 30 def compute_sidedata_2(repo, revlog, rev, sidedata, text=None):
29 sidedata = sidedata.copy() 31 sidedata = sidedata.copy()
30 if text is None: 32 if text is None:
31 text = revlog.revision(rev) 33 text = revlog.revision(rev)
32 sha256 = hashlib.sha256(text).digest() 34 sha256 = hashlib.sha256(text).digest()
33 sidedata[sidedatamod.SD_TEST2] = struct.pack('>32s', sha256) 35 sidedata[sidedatamod.SD_TEST2] = struct.pack('>32s', sha256)
34 return sidedata 36 return sidedata, NO_FLAGS
35 37
36 38
37 def reposetup(ui, repo): 39 def reposetup(ui, repo):
38 # Sidedata keys happen to be the same as the categories, easier for testing. 40 # Sidedata keys happen to be the same as the categories, easier for testing.
39 for kind in constants.ALL_KINDS: 41 for kind in constants.ALL_KINDS:
40 repo.register_sidedata_computer( 42 repo.register_sidedata_computer(
41 kind, 43 kind,
42 sidedatamod.SD_TEST1, 44 sidedatamod.SD_TEST1,
43 (sidedatamod.SD_TEST1,), 45 (sidedatamod.SD_TEST1,),
44 compute_sidedata_1, 46 compute_sidedata_1,
47 0,
45 ) 48 )
46 repo.register_sidedata_computer( 49 repo.register_sidedata_computer(
47 kind, 50 kind,
48 sidedatamod.SD_TEST2, 51 sidedatamod.SD_TEST2,
49 (sidedatamod.SD_TEST2,), 52 (sidedatamod.SD_TEST2,),
50 compute_sidedata_2, 53 compute_sidedata_2,
54 0,
51 ) 55 )