Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/mercurial/tests/test_from_disk.py
Show First 20 Lines • Show All 106 Lines • ▼ Show 20 Lines | def test_loader_hg_new_visit_no_release(swh_storage, datadir, tmp_path): | ||||
archive_name = "the-sandbox" | archive_name = "the-sandbox" | ||||
archive_path = os.path.join(datadir, f"{archive_name}.tgz") | archive_path = os.path.join(datadir, f"{archive_name}.tgz") | ||||
repo_url = prepare_repository_from_archive(archive_path, archive_name, tmp_path) | repo_url = prepare_repository_from_archive(archive_path, archive_name, tmp_path) | ||||
loader = HgLoaderFromDisk(swh_storage, url=repo_url) | loader = HgLoaderFromDisk(swh_storage, url=repo_url) | ||||
assert loader.load() == {"status": "eventful"} | assert loader.load() == {"status": "eventful"} | ||||
mapping = { | tips = { | ||||
b"default": "70e750bb046101fdced06f428e73fee471509c56", | b"refs/hg/branch-tip/default": "70e750bb046101fdced06f428e73fee471509c56", | ||||
b"develop": "a9c4534552df370f43f0ef97146f393ef2f2a08c", | b"refs/hg/branch-tip/develop": "a9c4534552df370f43f0ef97146f393ef2f2a08c", | ||||
} | |||||
closed = { | |||||
b"feature/fun_time": "4d640e8064fe69b4c851dfd43915c431e80c7497", | b"feature/fun_time": "4d640e8064fe69b4c851dfd43915c431e80c7497", | ||||
b"feature/green2_loader": "94be9abcf9558213ff301af0ecd8223451ce991d", | b"feature/green2_loader": "94be9abcf9558213ff301af0ecd8223451ce991d", | ||||
b"feature/greenloader": "9f82d95bd3edfb7f18b1a21d6171170395ea44ce", | b"feature/greenloader": "9f82d95bd3edfb7f18b1a21d6171170395ea44ce", | ||||
b"feature/my_test": "dafa445964230e808148db043c126063ea1dc9b6", | b"feature/my_test": "dafa445964230e808148db043c126063ea1dc9b6", | ||||
b"feature/read2_loader": "9e912851eb64e3a1e08fbb587de7a4c897ce5a0a", | b"feature/read2_loader": "9e912851eb64e3a1e08fbb587de7a4c897ce5a0a", | ||||
b"feature/readloader": "ddecbc16f4c916c39eacfcb2302e15a9e70a231e", | b"feature/readloader": "ddecbc16f4c916c39eacfcb2302e15a9e70a231e", | ||||
b"feature/red": "cb36b894129ca7910bb81c457c72d69d5ff111bc", | b"feature/red": "cb36b894129ca7910bb81c457c72d69d5ff111bc", | ||||
b"feature/split5_loader": "3ed4b85d30401fe32ae3b1d650f215a588293a9e", | b"feature/split5_loader": "3ed4b85d30401fe32ae3b1d650f215a588293a9e", | ||||
b"feature/split_causing": "c346f6ff7f42f2a8ff867f92ab83a6721057d86c", | b"feature/split_causing": "c346f6ff7f42f2a8ff867f92ab83a6721057d86c", | ||||
b"feature/split_loader": "5f4eba626c3f826820c4475d2d81410759ec911b", | b"feature/split_loader": "5f4eba626c3f826820c4475d2d81410759ec911b", | ||||
b"feature/split_loader5": "5017ce0b285351da09a2029ea2cf544f79b593c7", | b"feature/split_loader5": "5017ce0b285351da09a2029ea2cf544f79b593c7", | ||||
b"feature/split_loading": "4e2dc6d6073f0b6d348f84ded52f9143b10344b9", | b"feature/split_loading": "4e2dc6d6073f0b6d348f84ded52f9143b10344b9", | ||||
b"feature/split_redload": "2d4a801c9a9645fcd3a9f4c06418d8393206b1f3", | b"feature/split_redload": "2d4a801c9a9645fcd3a9f4c06418d8393206b1f3", | ||||
b"feature/splitloading": "88b80615ed8561be74a700b92883ec0374ddacb0", | b"feature/splitloading": "88b80615ed8561be74a700b92883ec0374ddacb0", | ||||
b"feature/test": "61d762d65afb3150e2653d6735068241779c1fcf", | b"feature/test": "61d762d65afb3150e2653d6735068241779c1fcf", | ||||
b"feature/test_branch": "be44d5e6cc66580f59c108f8bff5911ee91a22e4", | b"feature/test_branch": "be44d5e6cc66580f59c108f8bff5911ee91a22e4", | ||||
b"feature/test_branching": "d2164061453ecb03d4347a05a77db83f706b8e15", | b"feature/test_branching": "d2164061453ecb03d4347a05a77db83f706b8e15", | ||||
b"feature/test_dog": "2973e5dc9568ac491b198f6b7f10c44ddc04e0a3", | b"feature/test_dog": "2973e5dc9568ac491b198f6b7f10c44ddc04e0a3", | ||||
} | } | ||||
mapping = {b"refs/hg/branch-closed-heads/%s/0" % b: n for b, n in closed.items()} | |||||
mapping.update(tips) | |||||
expected_branches = { | expected_branches = { | ||||
k: SnapshotBranch(target=hash_to_bytes(v), target_type=TargetType.REVISION) | k: SnapshotBranch(target=hash_to_bytes(v), target_type=TargetType.REVISION) | ||||
for k, v in mapping.items() | for k, v in mapping.items() | ||||
} | } | ||||
expected_branches[b"HEAD"] = SnapshotBranch( | expected_branches[b"HEAD"] = SnapshotBranch( | ||||
target=b"develop", target_type=TargetType.ALIAS | target=b"refs/hg/branch-tip/develop", target_type=TargetType.ALIAS | ||||
) | ) | ||||
expected_snapshot = Snapshot( | expected_snapshot = Snapshot( | ||||
id=hash_to_bytes("f5347d142821cc00f18fb4e2d3253cdefe6ad645"), | id=hash_to_bytes("731119321cfef9f369b86617cf37dbc3435c709b"), | ||||
branches=expected_branches, | branches=expected_branches, | ||||
) | ) | ||||
assert_last_visit_matches( | assert_last_visit_matches( | ||||
loader.storage, | loader.storage, | ||||
repo_url, | repo_url, | ||||
status="full", | status="full", | ||||
type="hg", | type="hg", | ||||
▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | def test_loader_hg_new_visit_with_release(swh_storage, datadir, tmp_path): | ||||
release = loader.storage.release_get([tip_release])[0] | release = loader.storage.release_get([tip_release])[0] | ||||
assert release is not None | assert release is not None | ||||
tip_revision_default = hash_to_bytes("c3dbe4fbeaaa98dd961834e4007edb3efb0e2a27") | tip_revision_default = hash_to_bytes("c3dbe4fbeaaa98dd961834e4007edb3efb0e2a27") | ||||
revision = loader.storage.revision_get([tip_revision_default])[0] | revision = loader.storage.revision_get([tip_revision_default])[0] | ||||
assert revision is not None | assert revision is not None | ||||
expected_snapshot = Snapshot( | expected_snapshot = Snapshot( | ||||
id=hash_to_bytes("d35668e02e2ba4321dc951cd308cf883786f918a"), | id=hash_to_bytes("2fd54d6f8382db2aac08a5e69c4fae68713afb94"), | ||||
branches={ | branches={ | ||||
b"default": SnapshotBranch( | b"refs/hg/branch-tip/default": SnapshotBranch( | ||||
target=tip_revision_default, target_type=TargetType.REVISION, | target=tip_revision_default, target_type=TargetType.REVISION, | ||||
), | ), | ||||
b"0.1": SnapshotBranch(target=tip_release, target_type=TargetType.RELEASE,), | b"0.1": SnapshotBranch(target=tip_release, target_type=TargetType.RELEASE,), | ||||
b"HEAD": SnapshotBranch(target=b"default", target_type=TargetType.ALIAS,), | b"HEAD": SnapshotBranch( | ||||
target=b"refs/hg/branch-tip/default", target_type=TargetType.ALIAS, | |||||
), | |||||
}, | }, | ||||
) | ) | ||||
check_snapshot(expected_snapshot, loader.storage) | check_snapshot(expected_snapshot, loader.storage) | ||||
assert_last_visit_matches( | assert_last_visit_matches( | ||||
loader.storage, | loader.storage, | ||||
repo_url, | repo_url, | ||||
type=RevisionType.MERCURIAL.value, | type=RevisionType.MERCURIAL.value, | ||||
▲ Show 20 Lines • Show All 198 Lines • ▼ Show 20 Lines | expected_stats = { | ||||
"origin_visit": 1, | "origin_visit": 1, | ||||
"release": 0, | "release": 0, | ||||
"revision": 9, | "revision": 9, | ||||
"skipped_content": 0, | "skipped_content": 0, | ||||
"snapshot": 1, | "snapshot": 1, | ||||
} | } | ||||
assert get_stats(old_loader.storage) == expected_stats | assert get_stats(old_loader.storage) == expected_stats | ||||
# Shouldn't pick up anything | # Will pick up more branches, hence a different snapshot | ||||
loader = HgLoaderFromDisk(swh_storage, repo_path) | |||||
res = loader.load() | |||||
new_expected_stats = { | |||||
**expected_stats, | |||||
"origin_visit": 2, | |||||
"snapshot": 2, | |||||
} | |||||
assert get_stats(loader.storage) == new_expected_stats | |||||
assert res == {"status": "eventful"} | |||||
# Shouldn't pick up anything now | |||||
loader = HgLoaderFromDisk(swh_storage, repo_path) | loader = HgLoaderFromDisk(swh_storage, repo_path) | ||||
assert loader.load() == {"status": "uneventful"} | assert loader.load() == {"status": "uneventful"} | ||||
# Shouldn't pick up anything either | # Shouldn't pick up anything either after another load | ||||
loader = HgLoaderFromDisk(swh_storage, repo_path) | loader = HgLoaderFromDisk(swh_storage, repo_path) | ||||
assert loader.load() == {"status": "uneventful"} | assert loader.load() == {"status": "uneventful"} | ||||
def test_load_unchanged_repo__dangling_extid(swh_storage, datadir, tmp_path): | def test_load_unchanged_repo__dangling_extid(swh_storage, datadir, tmp_path): | ||||
"""Checks the loader will load revisions targeted by an ExtID if the | """Checks the loader will load revisions targeted by an ExtID if the | ||||
revisions are missing from the storage""" | revisions are missing from the storage""" | ||||
archive_name = "hello" | archive_name = "hello" | ||||
▲ Show 20 Lines • Show All 66 Lines • ▼ Show 20 Lines | def test_missing_filelog_should_not_crash(swh_storage, datadir, tmp_path): | ||||
) | ) | ||||
actual_load_status = loader.load() | actual_load_status = loader.load() | ||||
assert actual_load_status == {"status": "eventful"} | assert actual_load_status == {"status": "eventful"} | ||||
assert_last_visit_matches(swh_storage, repo_url, status="partial", type="hg") | assert_last_visit_matches(swh_storage, repo_url, status="partial", type="hg") | ||||
def test_multiple_open_heads(swh_storage, datadir, tmp_path): | |||||
archive_name = "multiple-heads" | |||||
archive_path = os.path.join(datadir, f"{archive_name}.tgz") | |||||
repo_url = prepare_repository_from_archive(archive_path, archive_name, tmp_path) | |||||
loader = HgLoaderFromDisk(storage=swh_storage, url=repo_url,) | |||||
actual_load_status = loader.load() | |||||
assert actual_load_status == {"status": "eventful"} | |||||
assert_last_visit_matches(swh_storage, repo_url, status="full", type="hg") | |||||
snapshot = snapshot_get_latest(swh_storage, repo_url) | |||||
expected_branches = [ | |||||
b"HEAD", | |||||
b"refs/hg/branch-heads/default/0", | |||||
b"refs/hg/branch-heads/default/1", | |||||
b"refs/hg/branch-tip/default", | |||||
] | |||||
assert sorted(snapshot.branches.keys()) == expected_branches | |||||
# Check that we don't load anything the second time | |||||
loader = HgLoaderFromDisk(storage=swh_storage, url=repo_url,) | |||||
actual_load_status = loader.load() | |||||
assert actual_load_status == {"status": "uneventful"} | |||||
def hg_strip(repo: str, revset: str) -> None: | def hg_strip(repo: str, revset: str) -> None: | ||||
"""Removes `revset` and all of their descendants from the local repository.""" | """Removes `revset` and all of their descendants from the local repository.""" | ||||
# Previously called `hg strip`, it was renamed to `hg debugstrip` in Mercurial 5.7 | # Previously called `hg strip`, it was renamed to `hg debugstrip` in Mercurial 5.7 | ||||
# because it's most likely not what most users want to do (they should use some kind | # because it's most likely not what most users want to do (they should use some kind | ||||
# of history-rewriting tool like `histedit` or `prune`). | # of history-rewriting tool like `histedit` or `prune`). | ||||
# But here, it's exactly what we want to do. | # But here, it's exactly what we want to do. | ||||
subprocess.check_call(["hg", "debugstrip", revset], cwd=repo) | subprocess.check_call(["hg", "debugstrip", revset], cwd=repo) | ||||
Show All 39 Lines |