Changeset View
Changeset View
Standalone View
Standalone View
swh/web/common/identifiers.py
Show First 20 Lines • Show All 134 Lines • ▼ Show 20 Lines | if swhid_parsed.path and swhid_parsed.path != b"/": | ||||
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["target_type"] == REVISION: | if release["target_type"] == REVISION: | ||||
revision = archive.lookup_revision(release["target"]) | revision = archive.lookup_revision(release["target"]) | ||||
directory = revision["directory"] | directory = revision["directory"] | ||||
if object_type == ObjectType.CONTENT: | if object_type == ObjectType.CONTENT: | ||||
if not swhid_parsed.origin: | if ( | ||||
# when no origin context, content objects need to have their | not swhid_parsed.origin | ||||
# path prefixed by root directory id for proper breadcrumbs display | and swhid_parsed.anchor.object_type != ObjectType.REVISION | ||||
): | |||||
# when no origin or revision context, content objects need to have | |||||
# their path prefixed by root directory id for breadcrumbs display | |||||
query_dict["path"] = hash_to_hex(directory) + query_dict["path"] | query_dict["path"] = hash_to_hex(directory) + query_dict["path"] | ||||
else: | else: | ||||
# remove leading slash from SWHID content path | # remove leading slash from SWHID content path | ||||
query_dict["path"] = query_dict["path"][1:] | query_dict["path"] = query_dict["path"][1:] | ||||
elif object_type == ObjectType.DIRECTORY: | elif object_type == ObjectType.DIRECTORY: | ||||
object_id = directory | object_id = directory | ||||
# remove leading and trailing slashes from SWHID directory path | # remove leading and trailing slashes from SWHID directory path | ||||
if query_dict["path"].endswith("/"): | if query_dict["path"].endswith("/"): | ||||
▲ Show 20 Lines • Show All 228 Lines • Show Last 20 Lines |