diff --git a/swh/web/browse/snapshot_context.py b/swh/web/browse/snapshot_context.py
--- a/swh/web/browse/snapshot_context.py
+++ b/swh/web/browse/snapshot_context.py
@@ -78,7 +78,7 @@
branches_count=1,
target_types=["revision", "alias"],
)
- snp_branch, _ = process_snapshot_branches(snp)
+ snp_branch, _, _ = process_snapshot_branches(snp)
if snp_branch and snp_branch[0]["name"] == branch_name:
branches.append(snp_branch[0])
return snp_branch[0]
@@ -109,7 +109,7 @@
branches_count=1,
target_types=["release"],
)
- _, snp_release = process_snapshot_branches(snp)
+ _, snp_release, _ = process_snapshot_branches(snp)
if snp_release and snp_release[0]["name"] == release_name:
releases.append(snp_release[0])
return snp_release[0]
@@ -171,7 +171,7 @@
def process_snapshot_branches(
snapshot: Dict[str, Any]
-) -> Tuple[List[SnapshotBranchInfo], List[SnapshotReleaseInfo]]:
+) -> Tuple[List[SnapshotBranchInfo], List[SnapshotReleaseInfo], Dict[str, Any]]:
"""
Process a dictionary describing snapshot branches: extract those
targeting revisions and releases, put them in two different lists,
@@ -183,8 +183,9 @@
Returns:
A tuple whose first member is the sorted list of branches
- targeting revisions and second member the sorted list of branches
- targeting releases
+ targeting revisions, second member the sorted list of branches
+ targeting releases and third member a dict mapping resolved branch
+ aliases to their real target.
"""
snapshot_branches = snapshot["branches"]
branches: Dict[str, SnapshotBranchInfo] = {}
@@ -263,8 +264,11 @@
for release_id in revision_to_release[revision["id"]]:
releases[release_id]["directory"] = revision["directory"]
+ resolved_aliases = {}
+
for branch_alias, branch_target in branch_aliases.items():
resolved_alias = archive.lookup_snapshot_alias(snapshot["id"], branch_alias)
+ resolved_aliases[branch_alias] = resolved_alias
if resolved_alias is None:
continue
@@ -272,7 +276,6 @@
target = resolved_alias["target"]
if target_type == "revision":
- branches[branch_alias] = target
revision = archive.lookup_revision(target)
_add_branch_info(branch_alias, revision, alias=True)
elif target_type == "release":
@@ -285,12 +288,12 @@
ret_branches = list(sorted(branches.values(), key=lambda b: b["name"]))
ret_releases = list(sorted(releases.values(), key=lambda b: b["name"]))
- return ret_branches, ret_releases
+ return ret_branches, ret_releases, resolved_aliases
def get_snapshot_content(
snapshot_id: str,
-) -> Tuple[List[SnapshotBranchInfo], List[SnapshotReleaseInfo]]:
+) -> Tuple[List[SnapshotBranchInfo], List[SnapshotReleaseInfo], Dict[str, Any]]:
"""Returns the lists of branches and releases
associated to a swh snapshot.
That list is put in cache in order to speedup the navigation
@@ -303,9 +306,10 @@
snapshot_id: hexadecimal representation of the snapshot identifier
Returns:
- A tuple with two members. The first one is a list of dict describing
+ A tuple with three members. The first one is a list of dict describing
the snapshot branches. The second one is a list of dict describing the
- snapshot releases.
+ snapshot releases. The third one is a dict mapping resolved branch
+ aliases to their real target.
Raises:
NotFoundExc if the snapshot does not exist
@@ -314,10 +318,15 @@
cache_entry = cache.get(cache_entry_id)
if cache_entry:
- return cache_entry["branches"], cache_entry["releases"]
+ return (
+ cache_entry["branches"],
+ cache_entry["releases"],
+ cache_entry.get("aliases", {}),
+ )
branches: List[SnapshotBranchInfo] = []
releases: List[SnapshotReleaseInfo] = []
+ aliases: Dict[str, Any] = {}
snapshot_content_max_size = get_config()["snapshot_content_max_size"]
@@ -325,11 +334,13 @@
snapshot = archive.lookup_snapshot(
snapshot_id, branches_count=snapshot_content_max_size
)
- branches, releases = process_snapshot_branches(snapshot)
+ branches, releases, aliases = process_snapshot_branches(snapshot)
- cache.set(cache_entry_id, {"branches": branches, "releases": releases,})
+ cache.set(
+ cache_entry_id, {"branches": branches, "releases": releases, "aliases": aliases}
+ )
- return branches, releases
+ return branches, releases, aliases
def get_origin_visit_snapshot(
@@ -337,7 +348,7 @@
visit_ts: Optional[str] = None,
visit_id: Optional[int] = None,
snapshot_id: Optional[str] = None,
-) -> Tuple[List[SnapshotBranchInfo], List[SnapshotReleaseInfo]]:
+) -> Tuple[List[SnapshotBranchInfo], List[SnapshotReleaseInfo], Dict[str, Any]]:
"""Returns the lists of branches and releases associated to an origin for
a given visit.
@@ -364,10 +375,11 @@
snapshot_id: if provided, visit associated to the snapshot will be processed
Returns:
- A tuple with two members. The first one is a list of dict describing
+ A tuple with three members. The first one is a list of dict describing
the origin branches for the given visit.
The second one is a list of dict describing the origin releases
- for the given visit.
+ for the given visit. The third one is a dict mapping resolved branch
+ aliases to their real target.
Raises:
NotFoundExc if the origin or its visit are not found
@@ -450,7 +462,7 @@
if timestamp:
timestamp = visit_info["date"]
- branches, releases = get_origin_visit_snapshot(
+ branches, releases, aliases = get_origin_visit_snapshot(
origin_info, timestamp, visit_id, snapshot_id
)
@@ -473,7 +485,7 @@
releases_url = reverse("browse-origin-releases", query_params=query_params)
else:
assert snapshot_id is not None
- branches, releases = get_snapshot_content(snapshot_id)
+ branches, releases, aliases = get_snapshot_content(snapshot_id)
url_args = {"snapshot_id": snapshot_id}
branches_url = reverse("browse-snapshot-branches", url_args=url_args)
@@ -597,12 +609,14 @@
snapshot_context = SnapshotContext(
branch=branch_name,
+ branch_alias=branch_name in aliases,
branches=branches,
branches_url=branches_url,
is_empty=is_empty,
origin_info=origin_info,
origin_visits_url=origin_visits_url,
release=release_name,
+ release_alias=release_name in aliases,
release_id=release_id,
query_params=query_params,
releases=releases,
@@ -1226,7 +1240,7 @@
target_types=["revision", "alias"],
)
- displayed_branches, _ = process_snapshot_branches(snapshot)
+ displayed_branches, _, _ = process_snapshot_branches(snapshot)
for branch in displayed_branches:
rev_query_params = {}
@@ -1330,7 +1344,7 @@
target_types=["release", "alias"],
)
- _, displayed_releases = process_snapshot_branches(snapshot)
+ _, displayed_releases, _ = process_snapshot_branches(snapshot)
for release in displayed_releases:
query_params_tgt = {"snapshot": snapshot_id}
diff --git a/swh/web/common/typing.py b/swh/web/common/typing.py
--- a/swh/web/common/typing.py
+++ b/swh/web/common/typing.py
@@ -90,6 +90,8 @@
class SnapshotContext(TypedDict):
branch: Optional[str]
"""optional branch name set when browsing snapshot in that scope"""
+ branch_alias: bool
+ """indicates if the focused branch is an alias"""
branches: List[SnapshotBranchInfo]
"""list of snapshot branches (possibly truncated)"""
branches_url: str
@@ -104,6 +106,8 @@
"""common query parameters when browsing snapshot content"""
release: Optional[str]
"""optional release name set when browsing snapshot in that scope"""
+ release_alias: bool
+ """indicates if the focused release is an alias"""
release_id: Optional[str]
"""optional release identifier set when browsing snapshot in that scope"""
releases: List[SnapshotReleaseInfo]
diff --git a/swh/web/common/utils.py b/swh/web/common/utils.py
--- a/swh/web/common/utils.py
+++ b/swh/web/common/utils.py
@@ -26,6 +26,7 @@
SWH_WEB_METRICS_REGISTRY = CollectorRegistry(auto_describe=True)
swh_object_icons = {
+ "alias": "mdi mdi-star",
"branch": "mdi mdi-source-branch",
"branches": "mdi mdi-source-branch",
"content": "mdi mdi-file-document",
diff --git a/swh/web/templates/browse/branches.html b/swh/web/templates/browse/branches.html
--- a/swh/web/templates/browse/branches.html
+++ b/swh/web/templates/browse/branches.html
@@ -27,7 +27,12 @@