Changeset View
Changeset View
Standalone View
Standalone View
swh/web/browse/views/revision.py
Show First 20 Lines • Show All 302 Lines • ▼ Show 20 Lines | def revision_browse(request, sha1_git): | ||||
identified by its id. | identified by its id. | ||||
The url that points to it is :http:get:`/browse/revision/(sha1_git)/`. | The url that points to it is :http:get:`/browse/revision/(sha1_git)/`. | ||||
""" | """ | ||||
try: | try: | ||||
revision = service.lookup_revision(sha1_git) | revision = service.lookup_revision(sha1_git) | ||||
origin_info = None | origin_info = None | ||||
snapshot_context = None | snapshot_context = None | ||||
origin_url = request.GET.get("origin_url", None) | origin_url = request.GET.get("origin_url") | ||||
if not origin_url: | if not origin_url: | ||||
origin_url = request.GET.get("origin", None) | origin_url = request.GET.get("origin") | ||||
timestamp = request.GET.get("timestamp", None) | timestamp = request.GET.get("timestamp") | ||||
visit_id = request.GET.get("visit_id", None) | visit_id = request.GET.get("visit_id") | ||||
snapshot_id = request.GET.get("snapshot_id", None) | snapshot_id = request.GET.get("snapshot_id") | ||||
path = request.GET.get("path", None) | if not snapshot_id: | ||||
snapshot_id = request.GET.get("snapshot") | |||||
path = request.GET.get("path") | |||||
dir_id = None | dir_id = None | ||||
dirs, files = None, None | dirs, files = None, None | ||||
content_data = {} | content_data = {} | ||||
if origin_url: | if origin_url: | ||||
try: | try: | ||||
snapshot_context = get_snapshot_context( | snapshot_context = get_snapshot_context( | ||||
origin_url=origin_url, timestamp=timestamp, visit_id=visit_id | snapshot_id=snapshot_id, | ||||
origin_url=origin_url, | |||||
timestamp=timestamp, | |||||
visit_id=visit_id, | |||||
branch_name=request.GET.get("branch"), | |||||
release_name=request.GET.get("release"), | |||||
revision_id=request.GET.get("revision"), | |||||
) | ) | ||||
except NotFoundExc: | except NotFoundExc as e: | ||||
raw_rev_url = reverse( | raw_rev_url = reverse( | ||||
"browse-revision", url_args={"sha1_git": sha1_git} | "browse-revision", url_args={"sha1_git": sha1_git} | ||||
) | ) | ||||
error_message = ( | error_message = ( | ||||
vlorentz: same | |||||
"The Software Heritage archive has a revision " | "The Software Heritage archive has a revision " | ||||
"with the hash you provided but the origin " | "with the hash you provided but the origin " | ||||
"mentioned in your request appears broken: %s. " | "mentioned in your request appears broken: %s. " | ||||
"Please check the URL and try again.\n\n" | "Please check the URL and try again.\n\n" | ||||
"Nevertheless, you can still browse the revision " | "Nevertheless, you can still browse the revision " | ||||
"without origin information: %s" | "without origin information: %s" | ||||
% (gen_link(origin_url), gen_link(raw_rev_url)) | % (gen_link(origin_url), gen_link(raw_rev_url)) | ||||
) | ) | ||||
if str(e).startswith("Origin"): | |||||
raise NotFoundExc(error_message) | raise NotFoundExc(error_message) | ||||
else: | |||||
raise e | |||||
origin_info = snapshot_context["origin_info"] | origin_info = snapshot_context["origin_info"] | ||||
snapshot_id = snapshot_context["snapshot_id"] | snapshot_id = snapshot_context["snapshot_id"] | ||||
elif snapshot_id: | elif snapshot_id: | ||||
snapshot_context = get_snapshot_context(snapshot_id) | snapshot_context = get_snapshot_context(snapshot_id) | ||||
if path: | if path: | ||||
file_info = service.lookup_directory_with_path(revision["directory"], path) | file_info = service.lookup_directory_with_path(revision["directory"], path) | ||||
if file_info["type"] == "dir": | if file_info["type"] == "dir": | ||||
dir_id = file_info["target"] | dir_id = file_info["target"] | ||||
else: | else: | ||||
query_string = "sha1_git:" + file_info["target"] | query_string = "sha1_git:" + file_info["target"] | ||||
content_data = request_content(query_string, raise_if_unavailable=False) | content_data = request_content(query_string, raise_if_unavailable=False) | ||||
else: | else: | ||||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | def revision_browse(request, sha1_git): | ||||
parents = [] | parents = [] | ||||
for p in revision["parents"]: | for p in revision["parents"]: | ||||
parent_url = gen_revision_url(p, snapshot_context) | parent_url = gen_revision_url(p, snapshot_context) | ||||
parents.append({"id": p, "url": parent_url}) | parents.append({"id": p, "url": parent_url}) | ||||
path_info = gen_path_info(path) | path_info = gen_path_info(path) | ||||
query_params = { | query_params = snapshot_context["query_params"] if snapshot_context else {} | ||||
"snapshot_id": snapshot_id, | |||||
"origin_url": origin_url, | |||||
"timestamp": timestamp, | |||||
"visit_id": visit_id, | |||||
} | |||||
breadcrumbs = [] | breadcrumbs = [] | ||||
breadcrumbs.append( | breadcrumbs.append( | ||||
{ | { | ||||
"name": revision["directory"][:7], | "name": revision["directory"][:7], | ||||
"url": reverse( | "url": reverse( | ||||
"browse-revision", | "browse-revision", | ||||
url_args={"sha1_git": sha1_git}, | url_args={"sha1_git": sha1_git}, | ||||
▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | if content_data: | ||||
mimetype = content_data["mimetype"] | mimetype = content_data["mimetype"] | ||||
if content_data["raw_data"]: | if content_data["raw_data"]: | ||||
content_display_data = prepare_content_for_display( | content_display_data = prepare_content_for_display( | ||||
content_data["raw_data"], content_data["mimetype"], path | content_data["raw_data"], content_data["mimetype"], path | ||||
) | ) | ||||
content = content_display_data["content_data"] | content = content_display_data["content_data"] | ||||
language = content_display_data["language"] | language = content_display_data["language"] | ||||
mimetype = content_display_data["mimetype"] | mimetype = content_display_data["mimetype"] | ||||
query_params = {} | |||||
if path: | if path: | ||||
filename = path_info[-1]["name"] | filename = path_info[-1]["name"] | ||||
query_params["filename"] = filename | |||||
extra_context["filename"] = filename | extra_context["filename"] = filename | ||||
top_right_link = { | top_right_link = { | ||||
"url": reverse( | "url": reverse( | ||||
"browse-content-raw", | "browse-content-raw", | ||||
url_args={"query_string": query_string}, | url_args={"query_string": query_string}, | ||||
query_params=query_params, | query_params={"filename": filename}, | ||||
), | ), | ||||
"icon": swh_object_icons["content"], | "icon": swh_object_icons["content"], | ||||
"text": "Raw File", | "text": "Raw File", | ||||
} | } | ||||
swh_objects.append( | swh_objects.append( | ||||
SWHObjectInfo(object_type=CONTENT, object_id=file_info["target"]) | SWHObjectInfo(object_type=CONTENT, object_id=file_info["target"]) | ||||
) | ) | ||||
Show All 34 Lines | else: | ||||
"text": "History", | "text": "History", | ||||
} | } | ||||
vault_cooking["directory_context"] = True | vault_cooking["directory_context"] = True | ||||
vault_cooking["directory_id"] = dir_id | vault_cooking["directory_id"] = dir_id | ||||
swh_objects.append(SWHObjectInfo(object_type=DIRECTORY, object_id=dir_id)) | swh_objects.append(SWHObjectInfo(object_type=DIRECTORY, object_id=dir_id)) | ||||
query_params.pop("path", None) | |||||
diff_revision_url = reverse( | diff_revision_url = reverse( | ||||
"diff-revision", | "diff-revision", url_args={"sha1_git": sha1_git}, query_params=query_params, | ||||
url_args={"sha1_git": sha1_git}, | |||||
query_params={ | |||||
"origin_url": origin_url, | |||||
"timestamp": timestamp, | |||||
"visit_id": visit_id, | |||||
}, | |||||
) | ) | ||||
if snapshot_id: | if snapshot_id: | ||||
swh_objects.append(SWHObjectInfo(object_type=SNAPSHOT, object_id=snapshot_id)) | swh_objects.append(SWHObjectInfo(object_type=SNAPSHOT, object_id=snapshot_id)) | ||||
swhids_info = get_swhids_info(swh_objects, snapshot_context, extra_context) | swhids_info = get_swhids_info(swh_objects, snapshot_context, extra_context) | ||||
heading = "Revision - %s - %s" % ( | heading = "Revision - %s - %s" % ( | ||||
▲ Show 20 Lines • Show All 45 Lines • Show Last 20 Lines |
same