feat: follow the branch a port was read from

This commit is contained in:
Abdessamad Derraz committed 2026-08-10 17:55:35 +02:00
1 parent 87087c74f0
commit 2b7c5f9a64
5 files changed
+503 -124

No files matched your search

+6 -1
View File
@@ -687,6 +687,9 @@ def select_views(
"""
views: list[RepoView] = []
seen: set[tuple[str, str]] = set()
# 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.
branch = str(profile.get("source_branch") or "") or None
for field in ("source", "upstream"):
repo = upstream.parse_repo(str(profile.get(field) or ""))
if repo is None or (repo.host, repo.slug) in seen:
@@ -694,7 +697,9 @@ def select_views(
pin, origin = resolve_pin(profile, repo, cache_dir, offline, field)
if not pin:
continue
head = upstream.resolve_head(repo, cache_dir, offline)
head = upstream.resolve_head(
repo, cache_dir, offline, branch if field == "source" else None
)
if not head:
continue
seen.add((repo.host, repo.slug))
+21 -7
View File
@@ -262,16 +262,22 @@ def _project(repo: Repo) -> str:
return urllib.parse.quote(f"{repo.owner}/{repo.name}", safe="")
def _commits_url(repo: Repo, date: str | None) -> str:
def _commits_url(repo: Repo, date: str | None, branch: str | None = None) -> str:
if repo.family == "github":
base = f"{repo.api_base}/repos/{repo.slug}/commits?per_page=1"
if branch:
base += f"&sha={urllib.parse.quote(branch, safe='')}"
elif repo.family == "gitlab":
base = (
f"{repo.api_base}/projects/{_project(repo)}"
f"/repository/commits?per_page=1"
)
if branch:
base += f"&ref_name={urllib.parse.quote(branch, safe='')}"
else:
base = f"{repo.api_base}/repos/{repo.slug}/commits?limit=1"
if branch:
base += f"&sha={urllib.parse.quote(branch, safe='')}"
return f"{base}&until={date}T23:59:59Z" if date else base
@@ -283,16 +289,24 @@ def _first_sha(payload: object) -> str | None:
return None
def resolve_head(repo: Repo, cache_dir: str, offline: bool = False) -> str | None:
"""Sha of the default branch tip."""
return _first_sha(_api(_commits_url(repo, None), cache_dir, offline))
def resolve_head(
repo: Repo, cache_dir: str, offline: bool = False, branch: str | None = None
) -> str | None:
"""Sha of a branch tip, the default branch unless one is named.
A libretro port often lives on a branch of a fork rather than on the
default branch, so the code a profile documents can be absent from the
tip the forge serves by default.
"""
return _first_sha(_api(_commits_url(repo, None, branch), cache_dir, offline))
def resolve_commit_at(
repo: Repo, date: str, cache_dir: str, offline: bool = False
repo: Repo, date: str, cache_dir: str, offline: bool = False,
branch: str | None = None,
) -> str | None:
"""Last default-branch commit on or before a date."""
return _first_sha(_api(_commits_url(repo, date), cache_dir, offline))
"""Last commit on or before a date, on the default branch or a named one."""
return _first_sha(_api(_commits_url(repo, date, branch), cache_dir, offline))
def _tags_url(repo: Repo) -> str: