fix: read a source declared gone at its mirror

This commit is contained in:
Abdessamad Derraz committed 2026-11-24 02:18:53 +01:00
1 parent ac334729f5
commit 08fbeff62f
7 files changed
+123 -49

No files matched your search

+25
View File
@@ -2,6 +2,8 @@
from __future__ import annotations
from core import upstream
# Read in this order: a declared repository decides attribution before the
# mirror that only keeps a gone forge's history reachable.
REPOSITORY_FIELDS = ("source", "upstream", "source_mirror")
@@ -30,6 +32,29 @@ def declared_repositories(profile: dict) -> list[tuple[str, str, str]]:
return urls
def _identity(url: str) -> tuple[str, str] | str:
"""What two URLs naming one repository share: host and slug on a known
forge, the URL itself elsewhere."""
repo = upstream.parse_repo(url)
return (repo.host, repo.slug) if repo is not None else url.strip().rstrip("/")
def serving_url(profile: dict, url: str) -> str:
"""The URL that serves a declared repository: the `source_mirror` of a
`source` the profile declares gone, the URL itself otherwise.
The mirror carries the same commits: simple64/simple64 and
teknogods/TeknoParrotUI answer 404, and the site linked every citation
into them while profile_sync read the mirror. An `upstream` naming the
gone source is served by the mirror too.
"""
mirror = str(profile.get("source_mirror") or "")
if not mirror or not str(profile.get("upstream_gone") or "").strip():
return url
gone = {_identity(u) for field, _mode, u in declared_repositories(profile) if field == "source"}
return mirror if _identity(url) in gone else url
def pin_field(field: str) -> str:
"""The `<field>_commit` that pins a repository field. A mirror carries
the source's history, commits and branches alike: source_commit pins it."""
+8 -11
View File
@@ -17,7 +17,7 @@ from profiling.anchoring import anchor_block
from profiling.attribution import owner_order
from profiling.citations import Citation, citation_key, collect_citations, is_external_citation
from profiling.proseedit import apply_prose_edits, run_after_moves
from model.profilerepos import declared_repositories
from model.profilerepos import declared_repositories, serving_url
from profiling.yamledit import apply_edit
@@ -359,24 +359,21 @@ def _prose_repos(document: dict) -> _ProseRepos | None:
# Every repository the profile declares, by build mode where it keys
# them so: eka2l1, mesence, supermodel and xemu pin a dict, and reading
# str(dict) found no repository at all, so their prose was never judged.
repos = [
(field, mode, repo)
urls = {
(field, mode, repo): url
for field, mode, url in declared_repositories(document)
if field != "source_mirror" and (repo := upstream.parse_repo(url)) is not None
]
if not repos:
}
if not urls:
return None
repos = list(urls)
# A source declared gone is read through its mirror, which carries the
# same commits: teknoparrot's notes stayed blocked once
# teknogods/TeknoParrotUI answered 404, every reading of the old pin
# calling the files absent.
mirror = (
upstream.parse_repo(str(document.get("source_mirror") or ""))
if document.get("upstream_gone") else None
)
served = {
repo: mirror for field, _mode, repo in repos
if mirror is not None and field == "source"
repo: mirror for (_field, _mode, repo), url in urls.items()
if (mirror := upstream.parse_repo(serving_url(document, url))) not in (None, repo)
}
pinned = [
(served.get(repo, repo), pin)
+21 -2
View File
@@ -7,7 +7,7 @@ from collections.abc import Iterable
from dataclasses import dataclass, replace
from core import upstream
from model.profilerepos import declared_pin, declared_repositories, pin_field
from model.profilerepos import declared_pin, declared_repositories, pin_field, serving_url
PIN = "pin"
@@ -66,6 +66,25 @@ def resolve_pin(
return (sha, f"profiled_date {date}") if sha else (None, None)
def _read_order(profile: dict) -> list[tuple[str, str, str]]:
"""The declared repositories in the order they are asked, as
(field, build mode, url): a source declared gone is followed at once by
the mirror that serves it, before the upstream.
The gone source is still asked, so a forge that answers again
contradicts the declaration. Listed last, the mirror ranked after a live
upstream and took no part in attribution, while the prose pass and the
site read it in the source's place.
"""
order: list[tuple[str, str, str]] = []
for field_name, mode, url in declared_repositories(profile):
order.append((field_name, mode, url))
served = serving_url(profile, url)
if field_name != "source_mirror" and served != url:
order.append(("source_mirror", mode, served))
return order
def select_views(
profile: dict, cache_dir: str, offline: bool
) -> list[RepoView]:
@@ -81,7 +100,7 @@ def select_views(
# A port living on a branch of a fork is absent from the default tip, so
# the branch it was read from is followed when the profile names one.
declared = str(profile.get("source_branch") or "") or None
for field_name, mode, url in declared_repositories(profile):
for field_name, mode, url in _read_order(profile):
repo = upstream.parse_repo(url)
if repo is None or (repo.host, repo.slug) in seen:
continue
+5 -3
View File
@@ -29,6 +29,7 @@ from model.profilerepos import (
declared_pin,
declared_repositories,
pin_field,
serving_url,
)
from model.sourcerevision import parse_source
from sitegen.render import escape_tags
@@ -41,10 +42,11 @@ def _repo_pins(profile: dict, field: str, label: str) -> list[tuple[str, str, st
and the revision by build mode. Reading them apart would pin a libretro
fork to the standalone revision and produce a permalink into a tree that
never held the cited line. Each tuple is (url, pin, source_commit
fallback for that same mode). A mirror is pinned by source_commit.
fallback for that same mode). A mirror is pinned by source_commit, and
a source the profile declares gone is given as the mirror serving it.
"""
declared = [(mode, url) for name, mode, url in declared_repositories(profile)
if name == field]
declared = [(mode, serving_url(profile, url))
for name, mode, url in declared_repositories(profile) if name == field]
# The requested build mode first, so it wins when several repositories
# would otherwise be equally good candidates.
declared.sort(key=lambda pair: bool(pair[0]) and pair[0] != label)