Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/in_memory.py
Show First 20 Lines • Show All 594 Lines • ▼ Show 20 Lines | def snapshot_count_branches(self, snapshot_id): | ||||
) | ) | ||||
def snapshot_get_branches( | def snapshot_get_branches( | ||||
self, snapshot_id, branches_from=b"", branches_count=1000, target_types=None | self, snapshot_id, branches_from=b"", branches_count=1000, target_types=None | ||||
): | ): | ||||
snapshot = self._snapshots.get(snapshot_id) | snapshot = self._snapshots.get(snapshot_id) | ||||
if snapshot is None: | if snapshot is None: | ||||
return None | return None | ||||
sorted_branch_names = sorted(snapshot.branches) | sorted_branches = sorted(snapshot.branches.items()) | ||||
sorted_branch_names = [k for (k, v) in sorted_branches] | |||||
from_index = bisect.bisect_left(sorted_branch_names, branches_from) | from_index = bisect.bisect_left(sorted_branch_names, branches_from) | ||||
if target_types: | if target_types: | ||||
next_branch = None | next_branch = None | ||||
branches = {} | branches = {} | ||||
for (branch_name, branch) in snapshot.branches.items(): | for (branch_name, branch) in sorted_branches: | ||||
if branch_name in sorted_branch_names[from_index:]: | if branch_name in sorted_branch_names[from_index:]: | ||||
if branch and branch.target_type.value in target_types: | if branch and branch.target_type.value in target_types: | ||||
if len(branches) < branches_count: | if len(branches) < branches_count: | ||||
branches[branch_name] = branch | branches[branch_name] = branch | ||||
else: | else: | ||||
next_branch = branch_name | next_branch = branch_name | ||||
break | break | ||||
else: | else: | ||||
▲ Show 20 Lines • Show All 677 Lines • Show Last 20 Lines |