mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-23 18:17:53 -06:00
fix: read a version basis at the profile_sync pin
This commit is contained in:
1 parent
198e2b2dc7
commit
bdfdb608e0
3 files changed
+44
-18
No files matched your search
@@ -44,6 +44,12 @@ def select_repo(profile: dict) -> upstream.Repo | None:
|
||||
return None
|
||||
|
||||
|
||||
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."""
|
||||
return "source" if field == "source_mirror" else field
|
||||
|
||||
|
||||
def resolve_pin(
|
||||
profile: dict, repo: upstream.Repo, cache_dir: str, offline: bool,
|
||||
field: str = "source", mode: str = "", branch: str | None = None,
|
||||
@@ -89,12 +95,11 @@ def select_views(
|
||||
repo = upstream.parse_repo(url)
|
||||
if repo is None or (repo.host, repo.slug) in seen:
|
||||
continue
|
||||
# A mirror carries the source's history, commits and branches alike:
|
||||
# its pin is source_commit. It read `source_mirror_commit`, a field
|
||||
# no profile carries, and fell back to profiled_date, which a bump
|
||||
# never moves (eden judged from f6e76860 while pinned on d16735f5).
|
||||
pin_field = "source" if field_name == "source_mirror" else field_name
|
||||
branch = declared if pin_field == "source" else None
|
||||
# A mirror read `source_mirror_commit`, a field no profile carries,
|
||||
# and fell back to profiled_date, which a bump never moves (eden
|
||||
# judged from f6e76860 while pinned on d16735f5).
|
||||
pinned_by = pin_field(field_name)
|
||||
branch = declared if pinned_by == "source" else None
|
||||
head = None
|
||||
try:
|
||||
unread: upstream.NotCachedError | None = None
|
||||
@@ -111,7 +116,7 @@ def select_views(
|
||||
if unread and not head:
|
||||
raise unread
|
||||
pin, origin = resolve_pin(
|
||||
profile, repo, cache_dir, offline, pin_field, mode, branch
|
||||
profile, repo, cache_dir, offline, pinned_by, mode, branch
|
||||
)
|
||||
if not pin or origin is None:
|
||||
continue
|
||||
|
||||
@@ -33,14 +33,11 @@ from collections.abc import Callable
|
||||
from dataclasses import dataclass
|
||||
|
||||
from core import upstream
|
||||
from profiling.repos import pin_field, resolve_pin
|
||||
|
||||
KINDS = ("file", "tag", "alias", "package", "none", "unverified")
|
||||
# Values copied from a .info or a branch name, which name no version.
|
||||
PLACEHOLDERS = frozenset({"git", "svn", "unknown", "master", "main", "latest", "dev", "head"})
|
||||
# Pin field of each repository field a basis may name. A mirror carries the
|
||||
# source's history, so source_commit pins it too.
|
||||
PIN_FIELDS = {"source": "source_commit", "source_mirror": "source_commit",
|
||||
"upstream": "upstream_commit"}
|
||||
|
||||
MATCH = "MATCH"
|
||||
DRIFT = "DRIFT"
|
||||
@@ -143,13 +140,17 @@ def _repo_and_pin(
|
||||
field = str(basis.get("repo") or "source")
|
||||
url = _by_mode(profile, field, mode) or ""
|
||||
repo = upstream.parse_repo(url)
|
||||
pin = _by_mode(profile, PIN_FIELDS.get(field, ""), mode) or ""
|
||||
where = url or field
|
||||
if repo is not None and not pin and field == "upstream" and profile.get("profiled_date"):
|
||||
# The pin of a second repository falls back on profiled_date,
|
||||
# as profile_sync resolves it.
|
||||
pin = upstream.resolve_commit_at(
|
||||
repo, str(profile["profiled_date"]), cache_dir, offline) or ""
|
||||
pin = ""
|
||||
if repo is not None:
|
||||
# The pin profile_sync compares at: the declared commit, else
|
||||
# the commit at profiled_date on the branch the source follows.
|
||||
pinned_by = pin_field(field)
|
||||
branch = str(profile.get("source_branch") or "") or None
|
||||
pin = resolve_pin(
|
||||
profile, repo, cache_dir, offline, pinned_by, mode,
|
||||
branch if pinned_by == "source" else None,
|
||||
)[0] or ""
|
||||
if repo is None:
|
||||
raise VersionUnreadable(f"{where}: not a forge repository")
|
||||
if not pin:
|
||||
|
||||
@@ -28,6 +28,7 @@ from profiling import resolver
|
||||
from profiling import yamledit
|
||||
from core import upstream
|
||||
from profiling import version_basis
|
||||
from profiling.repos import pin_field
|
||||
from model.profiles import load_emulator_profiles
|
||||
from profiling.reports import ProfileReport
|
||||
from profiling.bump import bump_commit
|
||||
@@ -186,7 +187,7 @@ class EveryProfileSaysWhereItsVersionIsRead(unittest.TestCase):
|
||||
for mode, basis in version_basis.bases(profile).items():
|
||||
if basis.get("kind") != "tag" or basis.get("url"):
|
||||
continue
|
||||
field = version_basis.PIN_FIELDS[str(basis.get("repo") or "source")]
|
||||
field = pin_field(str(basis.get("repo") or "source")) + "_commit"
|
||||
pin = version_basis._by_mode(profile, field, mode)
|
||||
if not pin:
|
||||
continue
|
||||
@@ -231,6 +232,25 @@ files: []
|
||||
"""
|
||||
|
||||
|
||||
class TheBasisPinIsTheComparisonPin(unittest.TestCase):
|
||||
def test_a_source_without_commit_reads_at_the_profiled_date(self):
|
||||
"""version_basis fell back on profiled_date for upstream only, while
|
||||
profile_sync compares every repository at that date's commit."""
|
||||
profile = {"source": "https://github.com/o/r", "source_branch": "port",
|
||||
"profiled_date": "2026-01-01"}
|
||||
basis = {"kind": "file", "repo": "source"}
|
||||
with mock.patch.object(upstream, "resolve_commit_at", return_value="a" * 40) as at:
|
||||
repo, pin = version_basis._repo_and_pin(profile, basis, "", "cache", True)
|
||||
self.assertEqual((repo.slug, pin), ("o/r", "a" * 40))
|
||||
self.assertEqual(at.call_args.args[1:], ("2026-01-01", "cache", True, "port"))
|
||||
|
||||
def test_a_mirror_is_pinned_by_the_source_commit(self):
|
||||
profile = {"source_mirror": "https://github.com/o/m", "source_commit": "b" * 40}
|
||||
repo, pin = version_basis._repo_and_pin(
|
||||
profile, {"kind": "file", "repo": "source_mirror"}, "", "cache", True)
|
||||
self.assertEqual((repo.slug, pin), ("o/m", "b" * 40))
|
||||
|
||||
|
||||
class AnAdvanceReadsTheVersionAgain(unittest.TestCase):
|
||||
"""A pin never moves without its version: read again, or refused."""
|
||||
|
||||
|
||||
Reference in new issue
Block a user