Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/mercurial/tests/test_loader.py
Show All 13 Lines | |||||
from swh.loader.mercurial.utils import parse_visit_date | from swh.loader.mercurial.utils import parse_visit_date | ||||
from swh.loader.tests import ( | from swh.loader.tests import ( | ||||
assert_last_visit_matches, | assert_last_visit_matches, | ||||
check_snapshot, | check_snapshot, | ||||
get_stats, | get_stats, | ||||
prepare_repository_from_archive, | prepare_repository_from_archive, | ||||
) | ) | ||||
from swh.model.hashutil import hash_to_bytes | from swh.model.hashutil import hash_to_bytes, hash_to_hex | ||||
from swh.model.identifiers import ObjectType | |||||
from swh.model.model import RevisionType, Snapshot, SnapshotBranch, TargetType | from swh.model.model import RevisionType, Snapshot, SnapshotBranch, TargetType | ||||
from swh.storage.algos.snapshot import snapshot_get_latest | from swh.storage.algos.snapshot import snapshot_get_latest | ||||
from ..loader import CloneTimeoutError, HgArchiveBundle20Loader, HgBundle20Loader | from ..loader import CloneTimeoutError, HgArchiveBundle20Loader, HgBundle20Loader | ||||
VISIT_DATE = parse_visit_date("2016-05-03 15:16:32+00") | VISIT_DATE = parse_visit_date("2016-05-03 15:16:32+00") | ||||
assert VISIT_DATE is not None | assert VISIT_DATE is not None | ||||
▲ Show 20 Lines • Show All 271 Lines • ▼ Show 20 Lines | for branch in snapshot.branches.values(): | ||||
if branch.target_type.value != "revision": | if branch.target_type.value != "revision": | ||||
continue | continue | ||||
revisions.append(branch.target) | revisions.append(branch.target) | ||||
# extract original changesets info and the transplant sources | # extract original changesets info and the transplant sources | ||||
hg_changesets = set() | hg_changesets = set() | ||||
transplant_sources = set() | transplant_sources = set() | ||||
for rev in swh_storage.revision_log(revisions): | for rev in swh_storage.revision_log(revisions): | ||||
hg_changesets.add(rev["metadata"]["node"]) | extids = list( | ||||
loader.storage.extid_get_from_target(ObjectType.REVISION, [rev["id"]]) | |||||
) | |||||
assert len(extids) == 1 | |||||
hg_changesets.add(hash_to_hex(extids[0].extid)) | |||||
for k, v in rev["extra_headers"]: | for k, v in rev["extra_headers"]: | ||||
if k == b"transplant_source": | if k == b"transplant_source": | ||||
transplant_sources.add(v.decode("ascii")) | transplant_sources.add(v.decode("ascii")) | ||||
# check extracted data are valid | # check extracted data are valid | ||||
assert len(hg_changesets) > 0 | assert len(hg_changesets) > 0 | ||||
assert len(transplant_sources) > 0 | assert len(transplant_sources) > 0 | ||||
assert transplant_sources.issubset(hg_changesets) | assert transplant_sources.issubset(hg_changesets) | ||||
▲ Show 20 Lines • Show All 47 Lines • Show Last 20 Lines |