Changeset View
Changeset View
Standalone View
Standalone View
swh/web/common/archive.py
Show First 20 Lines • Show All 1,116 Lines • ▼ Show 20 Lines | Returns: | ||||
A dict filled with the snapshot content. | A dict filled with the snapshot content. | ||||
""" | """ | ||||
snp = snapshot_get_latest( | snp = snapshot_get_latest( | ||||
storage, origin, allowed_statuses=allowed_statuses, branches_count=1000 | storage, origin, allowed_statuses=allowed_statuses, branches_count=1000 | ||||
) | ) | ||||
return converters.from_snapshot(snp.to_dict()) if snp is not None else None | return converters.from_snapshot(snp.to_dict()) if snp is not None else None | ||||
def lookup_snapshot_branch_name_from_tip_revision( | |||||
snapshot_id: str, revision_id: str | |||||
) -> Optional[str]: | |||||
"""Check if a revision corresponds to the tip of a snapshot branch | |||||
Args: | |||||
snapshot_id: hexadecimal representation of a snapshot id | |||||
revision_id: hexadecimal representation of a revision id | |||||
Returns: | |||||
The name of the first found branch or None otherwise | |||||
""" | |||||
per_page = 10000 | |||||
branches_from = "" | |||||
snapshot: Dict[str, Any] = {"branches": {}} | |||||
branches = [] | |||||
while not branches_from or len(snapshot["branches"]) == per_page + 1: | |||||
snapshot = lookup_snapshot( | |||||
snapshot_id, | |||||
target_types=[REVISION], | |||||
branches_from=branches_from, | |||||
branches_count=per_page + 1, | |||||
branch_name_exclude_prefix=None, | |||||
) | |||||
branches += [ | |||||
{"name": k, "target": v["target"]} for k, v in snapshot["branches"].items() | |||||
] | |||||
branches_from = branches[-1]["name"] | |||||
for branch in branches: | |||||
if branch["target"] == revision_id: | |||||
return branch["name"] | |||||
return None | |||||
def lookup_snapshot_alias( | def lookup_snapshot_alias( | ||||
snapshot_id: str, alias_name: str | snapshot_id: str, alias_name: str | ||||
) -> Optional[Dict[str, Any]]: | ) -> Optional[Dict[str, Any]]: | ||||
"""Try to resolve a branch alias in a snapshot. | """Try to resolve a branch alias in a snapshot. | ||||
Args: | Args: | ||||
snapshot_id: hexadecimal representation of a snapshot id | snapshot_id: hexadecimal representation of a snapshot id | ||||
alias_name: name of the branch alias to resolve | alias_name: name of the branch alias to resolve | ||||
▲ Show 20 Lines • Show All 253 Lines • Show Last 20 Lines |