mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-12-03 06:48:52 -06:00
refactor: one owner order for cited repositories
This commit is contained in:
1 parent
b0f7d6c661
commit
409cc843f9
5 files changed
+116
-19
No files matched your search
@@ -0,0 +1,35 @@
|
||||
"""Which declared repository a cited part belongs to, by its role word."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Callable, Iterable
|
||||
from typing import TypeVar
|
||||
|
||||
T = TypeVar("T")
|
||||
|
||||
|
||||
def field_role(field: str) -> str:
|
||||
"""source or upstream: the profile field a repository comes from."""
|
||||
return "upstream" if field == "upstream" else "source"
|
||||
|
||||
|
||||
def answers(field: str, mode: str, role: str) -> bool:
|
||||
"""Whether a part written under *role* means this repository: the field
|
||||
it comes from, or the build mode a keyed source declares it under."""
|
||||
return bool(role) and role in (field_role(field), mode)
|
||||
|
||||
|
||||
def owner_order(
|
||||
repositories: Iterable[T], role: str, declared: Callable[[T], tuple[str, str]]
|
||||
) -> list[T]:
|
||||
"""Repositories in the order a cited part claims them.
|
||||
|
||||
Those its role names come first, then the rest, each group in
|
||||
declaration order: between two trees that carry the cited path, the
|
||||
one declared first owns a part that names none. `declared` gives the
|
||||
(field, build mode) a repository was declared under.
|
||||
"""
|
||||
items = list(repositories)
|
||||
if not role:
|
||||
return items
|
||||
return sorted(items, key=lambda item: not answers(*declared(item), role))
|
||||
@@ -5,7 +5,7 @@ from __future__ import annotations
|
||||
import itertools
|
||||
import posixpath
|
||||
import subprocess
|
||||
from collections.abc import Iterable
|
||||
from collections.abc import Iterable, Mapping
|
||||
from dataclasses import dataclass, field
|
||||
from pathlib import Path
|
||||
|
||||
@@ -14,6 +14,7 @@ import yaml
|
||||
from core import upstream
|
||||
from model.sourceref import RefPart
|
||||
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
|
||||
@@ -173,6 +174,7 @@ def _realign_part(
|
||||
cache_dir: str,
|
||||
offline: bool,
|
||||
pinned: Iterable[tuple[upstream.Repo, str]] = (),
|
||||
declared: Mapping[upstream.Repo, tuple[str, str]] | None = None,
|
||||
) -> tuple[str, tuple[int, int] | str] | None:
|
||||
"""One range, anchored from its writing revision to the current pin.
|
||||
|
||||
@@ -180,16 +182,28 @@ def _realign_part(
|
||||
repository carries but an unmoved one does lives where nothing moved:
|
||||
it needs no move, and calling it absent made two readings of the same
|
||||
history disagree on every run (nethersx2's AetherSX2 citations).
|
||||
`declared` gives the (field, build mode) of each repository, which the
|
||||
part's role word is matched against.
|
||||
"""
|
||||
if is_external_citation(part.path):
|
||||
return None
|
||||
# The path as written decides first, as attribution does: a prefix is
|
||||
# The role word decides first, as attribution does: retrodream cites
|
||||
# `(upstream retro_host.c:196-198)` beside the fork's retro_host.c, and
|
||||
# both trees carry the file.
|
||||
fields = declared or {}
|
||||
|
||||
def claim(item: tuple) -> tuple[str, str]:
|
||||
return fields.get(item[0], ("source", ""))
|
||||
|
||||
pairs = owner_order(pairs, part.role, claim)
|
||||
pinned = owner_order(pinned, part.role, claim)
|
||||
# Then the path as written, as attribution reads it: a prefix is
|
||||
# stripped only when no declared repository carries the path itself.
|
||||
# hatarib's hatari/src/tos.c lives in hatariB, which did not move, and
|
||||
# stripping the prefix read it as hatari/hatari's src/tos.c instead.
|
||||
# Between two repositories that both carry the path, the one declared
|
||||
# first owns it, as in attribution: freej2me-plus and hex007/freej2me
|
||||
# both hold src/libretro/, and the citations describe the fork.
|
||||
# Between two repositories that both carry the path, owner_order puts
|
||||
# first the one declared first: freej2me-plus and hex007/freej2me both
|
||||
# hold src/libretro/, and the citations describe the fork.
|
||||
literal = [
|
||||
(repo, written, current) for repo, written, current in pairs
|
||||
if upstream.fetch_file(repo, written, part.path, cache_dir, offline) is not None
|
||||
@@ -289,6 +303,7 @@ def _realign_citation(
|
||||
cache_dir: str,
|
||||
offline: bool,
|
||||
pinned: Iterable[tuple[upstream.Repo, str]] = (),
|
||||
declared: Mapping[upstream.Repo, tuple[str, str]] | None = None,
|
||||
) -> tuple[dict[int, tuple[int, int, str | None]], list[str]]:
|
||||
"""The moves one prose run needs, and what blocks them.
|
||||
|
||||
@@ -304,7 +319,7 @@ def _realign_citation(
|
||||
outcomes = {
|
||||
repr(result): result
|
||||
for result in (
|
||||
_realign_part(part, pairs, cache_dir, offline, pinned) if pairs else None
|
||||
_realign_part(part, pairs, cache_dir, offline, pinned, declared) if pairs else None
|
||||
for pairs in readings
|
||||
)
|
||||
}
|
||||
@@ -335,6 +350,8 @@ class _ProseRepos:
|
||||
served: dict[upstream.Repo, upstream.Repo]
|
||||
# Every declared (repository, current pin).
|
||||
pinned: list[tuple[upstream.Repo, str]]
|
||||
# The (field, build mode) each repository read is declared under.
|
||||
roles: dict[upstream.Repo, tuple[str, str]]
|
||||
|
||||
|
||||
def _prose_repos(document: dict) -> _ProseRepos | None:
|
||||
@@ -366,7 +383,8 @@ def _prose_repos(document: dict) -> _ProseRepos | None:
|
||||
for field, mode, repo in repos
|
||||
if (pin := _pin_of(document, f"{field}_commit", mode))
|
||||
]
|
||||
return _ProseRepos(repos, served, pinned)
|
||||
roles = {served.get(repo, repo): (field, mode) for field, mode, repo in repos}
|
||||
return _ProseRepos(repos, served, pinned, roles)
|
||||
|
||||
|
||||
@dataclass
|
||||
@@ -463,7 +481,8 @@ def _prose_jobs(
|
||||
if not any(readings):
|
||||
continue
|
||||
moves, blocked = _realign_citation(
|
||||
citation, readings, ambiguous, cache_dir, offline, declared.pinned
|
||||
citation, readings, ambiguous, cache_dir, offline, declared.pinned,
|
||||
declared.roles,
|
||||
)
|
||||
if blocked:
|
||||
# Half a run must not move: the untouched ranges would read as
|
||||
|
||||
@@ -27,6 +27,7 @@ from profiling.anchoring import (
|
||||
verify_at_pin,
|
||||
worst_status,
|
||||
)
|
||||
from profiling.attribution import answers, field_role, owner_order
|
||||
from profiling.citations import (
|
||||
Citation,
|
||||
anchor_tokens,
|
||||
@@ -541,15 +542,12 @@ class _Resolver:
|
||||
candidates = self._candidate_paths(path)
|
||||
# A part that names its repository is looked up there first. In a
|
||||
# profile keyed by build mode, a part naming none belongs to the
|
||||
# first build declared, as _realign_part decides a shared path: the
|
||||
# libretro tree of xenia-edge carries emulator.cc offset, and its
|
||||
# better-scored line hid a standalone ref that had moved.
|
||||
# first build declared: the libretro tree of xenia-edge carries
|
||||
# emulator.cc offset, and its better-scored line hid a standalone
|
||||
# ref that had moved. owner_order is the rule realign follows too.
|
||||
if not wanted and self.primary.mode:
|
||||
wanted = self.primary.mode
|
||||
ordered = (
|
||||
sorted(self.views, key=lambda v: not _answers(v, wanted)) if wanted
|
||||
else self.views
|
||||
)
|
||||
ordered = owner_order(self.views, wanted, _declared)
|
||||
best: tuple[int, RepoView, str] | None = None
|
||||
for candidate in candidates:
|
||||
found, best = self._try_candidate(candidate, ordered, start, tokens, wanted, best)
|
||||
@@ -936,13 +934,15 @@ def build_report(
|
||||
|
||||
def _view_role(view: RepoView) -> str:
|
||||
"""source or upstream: the profile field a repository comes from."""
|
||||
return "upstream" if view.field == "upstream" else "source"
|
||||
return field_role(view.field)
|
||||
|
||||
|
||||
def _answers(view: RepoView, role: str) -> bool:
|
||||
"""Whether a part written under *role* means this repository: the field
|
||||
it comes from, or the build mode a keyed source declares it under."""
|
||||
return bool(role) and role in (_view_role(view), view.mode)
|
||||
return answers(view.field, view.mode, role)
|
||||
|
||||
|
||||
def _declared(view: RepoView) -> tuple[str, str]:
|
||||
return view.field, view.mode
|
||||
|
||||
|
||||
NO_SOURCE_REF = "no source_ref"
|
||||
Reference in new issue
Block a user