Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F7066562
D3352.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Subscribers
None
D3352.diff
View Options
diff --git a/swh/web/common/identifiers.py b/swh/web/common/identifiers.py
--- a/swh/web/common/identifiers.py
+++ b/swh/web/common/identifiers.py
@@ -107,6 +107,7 @@
query_dict = QueryDict("", mutable=True)
fragment = ""
anchor_swhid_parsed = None
+ process_lines = object_type is CONTENT
if query_params and len(query_params) > 0:
for k in sorted(query_params.keys()):
@@ -189,14 +190,7 @@
object_id = anchor_swhid_parsed.object_id
if object_type == CONTENT:
- query_string = "sha1_git:" + object_id
- if "lines" in swh_id_parsed.metadata:
- lines = swh_id_parsed.metadata["lines"].split("-")
- fragment += "#L" + lines[0]
- if len(lines) > 1:
- fragment += "-L" + lines[1]
- url_args["query_string"] = query_string
-
+ url_args["query_string"] = f"sha1_git:{object_id}"
elif object_type == DIRECTORY:
url_args["sha1_git"] = object_id
elif object_type == RELEASE:
@@ -214,6 +208,12 @@
)
)
+ if "lines" in swh_id_parsed.metadata and process_lines:
+ lines = swh_id_parsed.metadata["lines"].split("-")
+ fragment += "#L" + lines[0]
+ if len(lines) > 1:
+ fragment += "-L" + lines[1]
+
if url_args:
browse_url = (
reverse(
diff --git a/swh/web/tests/common/test_identifiers.py b/swh/web/tests/common/test_identifiers.py
--- a/swh/web/tests/common/test_identifiers.py
+++ b/swh/web/tests/common/test_identifiers.py
@@ -499,9 +499,25 @@
path=f"/{directory_file['name']}",
)
+ _check_resolved_swhid_browse_url(
+ CONTENT,
+ directory_file["target"],
+ snapshot_context,
+ path=f"/{directory_file['name']}",
+ lines="10",
+ )
+
+ _check_resolved_swhid_browse_url(
+ CONTENT,
+ directory_file["target"],
+ snapshot_context,
+ path=f"/{directory_file['name']}",
+ lines="10-20",
+ )
+
def _check_resolved_swhid_browse_url(
- object_type, object_id, snapshot_context, path=None
+ object_type, object_id, snapshot_context, path=None, lines=None
):
snapshot_id = snapshot_context["snapshot_id"]
origin_url = None
@@ -557,6 +573,9 @@
if object_type == DIRECTORY:
object_id = snapshot_context["root_directory"]
+ if lines:
+ obj_context["lines"] = lines
+
obj_swhid = get_swh_persistent_id(object_type, object_id, metadata=obj_context)
obj_swhid_resolved = resolve_swh_persistent_id(obj_swhid)
@@ -570,5 +589,10 @@
expected_url = reverse(
f"browse-{object_type}", url_args=url_args, query_params=query_params,
)
+ if lines:
+ lines_number = lines.split("-")
+ expected_url += f"#L{lines_number[0]}"
+ if len(lines_number) > 1:
+ expected_url += f"-L{lines_number[1]}"
assert obj_swhid_resolved["browse_url"] == expected_url
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Nov 5 2024, 3:11 PM (12 w, 4 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3223438
Attached To
D3352: common/identifiers: Fix missing lines qualifier processing in resolver
Event Timeline
Log In to Comment