Page MenuHomeSoftware Heritage

D3500.id12363.diff
No OneTemporary

D3500.id12363.diff

diff --git a/swh/storage/in_memory.py b/swh/storage/in_memory.py
--- a/swh/storage/in_memory.py
+++ b/swh/storage/in_memory.py
@@ -605,7 +605,7 @@
if target_types:
next_branch = None
branches = {}
- for (branch_name, branch) in snapshot.branches.items():
+ for (branch_name, branch) in sorted(snapshot.branches.items()):
if branch_name in sorted_branch_names[from_index:]:
if branch and branch.target_type.value in target_types:
if len(branches) < branches_count:
diff --git a/swh/storage/tests/test_storage.py b/swh/storage/tests/test_storage.py
--- a/swh/storage/tests/test_storage.py
+++ b/swh/storage/tests/test_storage.py
@@ -2749,6 +2749,36 @@
assert snapshot == expected_snapshot
+ def test_snapshot_add_get_branch_by_type(self, swh_storage):
+ snapshot = copy.deepcopy(data.complete_snapshot)
+
+ alias1 = b"alias1"
+ alias2 = b"alias2"
+ target1 = random.choice(list(snapshot["branches"].keys()))
+ target2 = random.choice(list(snapshot["branches"].keys()))
+
+ snapshot["branches"][alias2] = {
+ "target": target2,
+ "target_type": "alias",
+ }
+
+ snapshot["branches"][alias1] = {
+ "target": target1,
+ "target_type": "alias",
+ }
+
+ swh_storage.snapshot_add([snapshot])
+
+ branches = swh_storage.snapshot_get_branches(
+ snapshot["id"],
+ target_types=["alias"],
+ branches_from=alias1,
+ branches_count=1,
+ )["branches"]
+
+ assert len(branches) == 1
+ assert alias1 in branches
+
def test_snapshot_add_get(self, swh_storage):
origin_url = swh_storage.origin_add_one(data.origin)
visit = OriginVisit(

File Metadata

Mime Type
text/plain
Expires
Thu, Jul 3, 11:43 AM (3 w, 3 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3234131

Event Timeline