Changeset View
Changeset View
Standalone View
Standalone View
swh/web/common/identifiers.py
Show First 20 Lines • Show All 156 Lines • ▼ Show 20 Lines | ) -> ResolvedSWHID: | ||||
# snapshot context | # snapshot context | ||||
if swhid_parsed.visit: | if swhid_parsed.visit: | ||||
if swhid_parsed.visit.object_type != ObjectType.SNAPSHOT: | if swhid_parsed.visit.object_type != ObjectType.SNAPSHOT: | ||||
raise BadInputExc("Visit must be a snapshot SWHID.") | raise BadInputExc("Visit must be a snapshot SWHID.") | ||||
query_dict["snapshot"] = hash_to_hex(swhid_parsed.visit.object_id) | query_dict["snapshot"] = hash_to_hex(swhid_parsed.visit.object_id) | ||||
if swhid_parsed.anchor: | if swhid_parsed.anchor: | ||||
if swhid_parsed.anchor.object_type == ObjectType.REVISION: | if ( | ||||
# check if the anchor revision is the tip of a branch | swhid_parsed.anchor.object_type == ObjectType.REVISION | ||||
branch_name = archive.lookup_snapshot_branch_name_from_tip_revision( | and object_type != ObjectType.REVISION | ||||
hash_to_hex(swhid_parsed.visit.object_id), | ): | ||||
hash_to_hex(swhid_parsed.anchor.object_id), | |||||
) | |||||
if branch_name: | |||||
query_dict["branch"] = branch_name | |||||
elif object_type != ObjectType.REVISION: | |||||
query_dict["revision"] = hash_to_hex(swhid_parsed.anchor.object_id) | query_dict["revision"] = hash_to_hex(swhid_parsed.anchor.object_id) | ||||
elif swhid_parsed.anchor.object_type == ObjectType.RELEASE: | elif swhid_parsed.anchor.object_type == ObjectType.RELEASE: | ||||
release = archive.lookup_release( | release = archive.lookup_release( | ||||
hash_to_hex(swhid_parsed.anchor.object_id) | hash_to_hex(swhid_parsed.anchor.object_id) | ||||
) | ) | ||||
if release: | if release: | ||||
query_dict["release"] = release["name"] | query_dict["release"] = release["name"] | ||||
if object_type == ObjectType.REVISION and "release" not in query_dict: | |||||
branch_name = archive.lookup_snapshot_branch_name_from_tip_revision( | |||||
hash_to_hex(swhid_parsed.visit.object_id), hash_to_hex(object_id) | |||||
) | |||||
if branch_name: | |||||
query_dict["branch"] = branch_name | |||||
# browsing content or directory without snapshot context | # browsing content or directory without snapshot context | ||||
elif ( | elif ( | ||||
object_type in (ObjectType.CONTENT, ObjectType.DIRECTORY) | object_type in (ObjectType.CONTENT, ObjectType.DIRECTORY) | ||||
and swhid_parsed.anchor | and swhid_parsed.anchor | ||||
): | ): | ||||
if swhid_parsed.anchor.object_type == ObjectType.REVISION: | if swhid_parsed.anchor.object_type == ObjectType.REVISION: | ||||
# anchor revision, objects are browsed from its view | # anchor revision, objects are browsed from its view | ||||
object_type = ObjectType.REVISION | object_type = ObjectType.REVISION | ||||
▲ Show 20 Lines • Show All 196 Lines • Show Last 20 Lines |