Changeset View
Changeset View
Standalone View
Standalone View
swh/web/browse/snapshot_context.py
# Copyright (C) 2018-2020 The Software Heritage developers | # Copyright (C) 2018-2020 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU Affero General Public License version 3, or any later version | # License: GNU Affero General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
# Utility module for browsing the archive in a snapshot context. | # Utility module for browsing the archive in a snapshot context. | ||||
from collections import defaultdict | from collections import defaultdict | ||||
from copy import copy | from copy import copy | ||||
from typing import Any, Dict, List, Optional, Tuple | from typing import Any, Dict, List, Optional, Tuple | ||||
from django.core.cache import cache | from django.core.cache import cache | ||||
from django.shortcuts import render | from django.shortcuts import render | ||||
from django.template.defaultfilters import filesizeformat | from django.template.defaultfilters import filesizeformat | ||||
from django.utils.html import escape | from django.utils.html import escape | ||||
import sentry_sdk | |||||
from swh.model.identifiers import ( | from swh.model.identifiers import ( | ||||
swhid, | swhid, | ||||
snapshot_identifier, | snapshot_identifier, | ||||
CONTENT, | CONTENT, | ||||
DIRECTORY, | DIRECTORY, | ||||
REVISION, | REVISION, | ||||
RELEASE, | RELEASE, | ||||
▲ Show 20 Lines • Show All 505 Lines • ▼ Show 20 Lines | if snapshot_total_size and revision_id is not None: | ||||
message=revision["message"], | message=revision["message"], | ||||
url=None, | url=None, | ||||
) | ) | ||||
) | ) | ||||
branch_name = revision_id | branch_name = revision_id | ||||
query_params["revision"] = revision_id | query_params["revision"] = revision_id | ||||
elif snapshot_total_size and release_name: | elif snapshot_total_size and release_name: | ||||
release = _get_release(releases, release_name, snapshot_id) | release = _get_release(releases, release_name, snapshot_id) | ||||
try: | if release is None: | ||||
root_directory = release["directory"] | |||||
revision_id = release["target"] | |||||
release_id = release["id"] | |||||
query_params["release"] = release_name | |||||
except Exception as exc: | |||||
sentry_sdk.capture_exception(exc) | |||||
_branch_not_found( | _branch_not_found( | ||||
"release", | "release", | ||||
release_name, | release_name, | ||||
snapshot_id, | snapshot_id, | ||||
snapshot_sizes, | snapshot_sizes, | ||||
origin_info, | origin_info, | ||||
timestamp, | timestamp, | ||||
visit_id, | visit_id, | ||||
) | ) | ||||
else: | |||||
root_directory = release["directory"] | |||||
revision_id = release["target"] | |||||
release_id = release["id"] | |||||
query_params["release"] = release_name | |||||
elif snapshot_total_size: | elif snapshot_total_size: | ||||
if branch_name: | if branch_name: | ||||
query_params["branch"] = branch_name | query_params["branch"] = branch_name | ||||
branch = _get_branch(branches, branch_name or "HEAD", snapshot_id) | branch = _get_branch(branches, branch_name or "HEAD", snapshot_id) | ||||
try: | if branch is None: | ||||
branch_name = branch["name"] | |||||
revision_id = branch["revision"] | |||||
root_directory = branch["directory"] | |||||
except Exception as exc: | |||||
sentry_sdk.capture_exception(exc) | |||||
_branch_not_found( | _branch_not_found( | ||||
"branch", | "branch", | ||||
branch_name, | branch_name, | ||||
snapshot_id, | snapshot_id, | ||||
snapshot_sizes, | snapshot_sizes, | ||||
origin_info, | origin_info, | ||||
timestamp, | timestamp, | ||||
visit_id, | visit_id, | ||||
) | ) | ||||
else: | |||||
branch_name = branch["name"] | |||||
revision_id = branch["revision"] | |||||
root_directory = branch["directory"] | |||||
for b in branches: | for b in branches: | ||||
branch_query_params = dict(query_params) | branch_query_params = dict(query_params) | ||||
branch_query_params.pop("release", None) | branch_query_params.pop("release", None) | ||||
if b["name"] != b["revision"]: | if b["name"] != b["revision"]: | ||||
branch_query_params.pop("revision", None) | branch_query_params.pop("revision", None) | ||||
branch_query_params["branch"] = b["name"] | branch_query_params["branch"] = b["name"] | ||||
b["url"] = reverse( | b["url"] = reverse( | ||||
▲ Show 20 Lines • Show All 886 Lines • Show Last 20 Lines |