Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F9749671
D5404.id19341.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
5 KB
Subscribers
None
D5404.id19341.diff
View Options
diff --git a/swh/web/common/archive.py b/swh/web/common/archive.py
--- a/swh/web/common/archive.py
+++ b/swh/web/common/archive.py
@@ -1122,42 +1122,6 @@
return converters.from_snapshot(snp.to_dict()) if snp is not None else None
-def lookup_snapshot_branch_name_from_tip_revision(
- snapshot_id: str, revision_id: str
-) -> Optional[str]:
- """Check if a revision corresponds to the tip of a snapshot branch
-
- Args:
- snapshot_id: hexadecimal representation of a snapshot id
- revision_id: hexadecimal representation of a revision id
-
- Returns:
- The name of the first found branch or None otherwise
- """
- per_page = 10000
- branches_from = ""
- snapshot: Dict[str, Any] = {"branches": {}}
- branches = []
- while not branches_from or len(snapshot["branches"]) == per_page + 1:
- snapshot = lookup_snapshot(
- snapshot_id,
- target_types=[REVISION],
- branches_from=branches_from,
- branches_count=per_page + 1,
- branch_name_exclude_prefix=None,
- )
-
- branches += [
- {"name": k, "target": v["target"]} for k, v in snapshot["branches"].items()
- ]
- branches_from = branches[-1]["name"]
-
- for branch in branches:
- if branch["target"] == revision_id:
- return branch["name"]
- return None
-
-
def lookup_snapshot_alias(
snapshot_id: str, alias_name: str
) -> Optional[Dict[str, Any]]:
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
@@ -162,16 +162,11 @@
query_dict["snapshot"] = hash_to_hex(swhid_parsed.visit.object_id)
if swhid_parsed.anchor:
- if swhid_parsed.anchor.object_type == ObjectType.REVISION:
- # check if the anchor revision is the tip of a branch
- branch_name = archive.lookup_snapshot_branch_name_from_tip_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)
+ if (
+ swhid_parsed.anchor.object_type == ObjectType.REVISION
+ and object_type != ObjectType.REVISION
+ ):
+ query_dict["revision"] = hash_to_hex(swhid_parsed.anchor.object_id)
elif swhid_parsed.anchor.object_type == ObjectType.RELEASE:
release = archive.lookup_release(
@@ -180,13 +175,6 @@
if release:
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
elif (
object_type in (ObjectType.CONTENT, ObjectType.DIRECTORY)
diff --git a/swh/web/tests/common/test_archive.py b/swh/web/tests/common/test_archive.py
--- a/swh/web/tests/common/test_archive.py
+++ b/swh/web/tests/common/test_archive.py
@@ -992,27 +992,6 @@
assert origin_info["url"] == origin_url
-@given(snapshot())
-def test_lookup_snapshot_branch_name_from_tip_revision(archive_data, snapshot_id):
- snapshot = archive_data.snapshot_get(snapshot_id)
- branches = [
- {"name": k, "revision": v["target"]}
- for k, v in snapshot["branches"].items()
- if v["target_type"] == "revision"
- ]
- branch_info = random.choice(branches)
- possible_results = [
- b["name"] for b in branches if b["revision"] == branch_info["revision"]
- ]
-
- assert (
- archive.lookup_snapshot_branch_name_from_tip_revision(
- snapshot_id, branch_info["revision"]
- )
- in possible_results
- )
-
-
@given(origin(), new_origin())
def test_lookup_origins_get_by_sha1s(origin, unknown_origin):
hasher = hashlib.sha1()
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
@@ -556,22 +556,7 @@
query_params["release"] = snapshot_context["release"]
else:
obj_context["anchor"] = gen_swhid(REVISION, snapshot_context["revision_id"])
- if (
- snapshot_context["branch"]
- and snapshot_context["branch"] != snapshot_context["revision_id"]
- ):
- branch = snapshot_context["branch"]
- if branch == "HEAD":
- for b in snapshot_context["branches"]:
- if (
- b["revision"] == snapshot_context["revision_id"]
- and b["name"] != "HEAD"
- ):
- branch = b["name"]
- break
-
- query_params["branch"] = branch
- elif object_type != REVISION:
+ if object_type != REVISION:
query_params["revision"] = snapshot_context["revision_id"]
if path:
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Aug 24, 6:05 PM (2 d, 20 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3227857
Attached To
D5404: common/identifiers: Remove branch name processing in SWHID resolver
Event Timeline
Log In to Comment