| 1 |
# ext-sidedata-2.py - small extension to test (differently) the sidedata logic |
| 2 |
# |
| 3 |
# Simulates a client for a complex sidedata exchange. |
| 4 |
# |
| 5 |
# Copyright 2021 Raphaël Gomès <[email protected]> |
| 6 |
# |
| 7 |
# This software may be used and distributed according to the terms of the |
| 8 |
# GNU General Public License version 2 or any later version. |
| 9 |
|
| 10 |
|
| 11 |
import hashlib |
| 12 |
import struct |
| 13 |
|
| 14 |
from mercurial.revlogutils import sidedata as sidedatamod |
| 15 |
from mercurial.revlogutils import constants |
| 16 |
|
| 17 |
NO_FLAGS = (0, 0) # hoot |
| 18 |
|
| 19 |
|
| 20 |
def compute_sidedata_1(repo, revlog, rev, sidedata, text=None): |
| 21 |
sidedata = sidedata.copy() |
| 22 |
if text is None: |
| 23 |
text = revlog.revision(rev) |
| 24 |
sidedata[sidedatamod.SD_TEST1] = struct.pack('>I', len(text)) |
| 25 |
return sidedata, NO_FLAGS |
| 26 |
|
| 27 |
|
| 28 |
def compute_sidedata_2(repo, revlog, rev, sidedata, text=None): |
| 29 |
sidedata = sidedata.copy() |
| 30 |
if text is None: |
| 31 |
text = revlog.revision(rev) |
| 32 |
sha256 = hashlib.sha256(text).digest() |
| 33 |
sidedata[sidedatamod.SD_TEST2] = struct.pack('>32s', sha256) |
| 34 |
return sidedata, NO_FLAGS |
| 35 |
|
| 36 |
|
| 37 |
def reposetup(ui, repo): |
| 38 |
# Sidedata keys happen to be the same as the categories, easier for testing. |
| 39 |
for kind in constants.ALL_KINDS: |
| 40 |
repo.register_sidedata_computer( |
| 41 |
kind, |
| 42 |
sidedatamod.SD_TEST1, |
| 43 |
(sidedatamod.SD_TEST1,), |
| 44 |
compute_sidedata_1, |
| 45 |
0, |
| 46 |
) |
| 47 |
repo.register_sidedata_computer( |
| 48 |
kind, |
| 49 |
sidedatamod.SD_TEST2, |
| 50 |
(sidedatamod.SD_TEST2,), |
| 51 |
compute_sidedata_2, |
| 52 |
0, |
| 53 |
) |