mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-10-10 13:33:24 -05:00
fix: diff every declaration of a repeated destination
This commit is contained in:
1 parent
7822de38fb
commit
892cff38bc
2 files changed
+32
-6
No files matched your search
@@ -157,6 +157,22 @@ def _core_names(config: dict) -> set[str]:
|
|||||||
return names
|
return names
|
||||||
|
|
||||||
|
|
||||||
|
def _keyed_files(files: list[dict]) -> dict[str, dict]:
|
||||||
|
"""Each declaration under its own key.
|
||||||
|
|
||||||
|
A platform declares one destination several times (an archive once per
|
||||||
|
inner ROM, MD5 alternatives): keyed by destination alone, the dict kept
|
||||||
|
the last and a change to the others read as identical.
|
||||||
|
"""
|
||||||
|
keyed: dict[str, dict] = {}
|
||||||
|
seen: dict[str, int] = {}
|
||||||
|
for f in files:
|
||||||
|
key = _file_key(f)
|
||||||
|
seen[key] = seen.get(key, 0) + 1
|
||||||
|
keyed[key if seen[key] == 1 else f"{key}#{seen[key]}"] = f
|
||||||
|
return keyed
|
||||||
|
|
||||||
|
|
||||||
def diff_platform(old: dict, new: dict) -> PlatformDiff:
|
def diff_platform(old: dict, new: dict) -> PlatformDiff:
|
||||||
"""Compare two platform files the way a reviewer reads the diff.
|
"""Compare two platform files the way a reviewer reads the diff.
|
||||||
|
|
||||||
@@ -172,12 +188,8 @@ def diff_platform(old: dict, new: dict) -> PlatformDiff:
|
|||||||
diff.systems_added = sorted(set(new_systems) - set(old_systems))
|
diff.systems_added = sorted(set(new_systems) - set(old_systems))
|
||||||
diff.systems_removed = sorted(set(old_systems) - set(new_systems))
|
diff.systems_removed = sorted(set(old_systems) - set(new_systems))
|
||||||
for system in sorted(set(old_systems) & set(new_systems)):
|
for system in sorted(set(old_systems) & set(new_systems)):
|
||||||
old_files = {
|
old_files = _keyed_files((old_systems[system] or {}).get("files") or [])
|
||||||
_file_key(f): f for f in (old_systems[system] or {}).get("files") or []
|
new_files = _keyed_files((new_systems[system] or {}).get("files") or [])
|
||||||
}
|
|
||||||
new_files = {
|
|
||||||
_file_key(f): f for f in (new_systems[system] or {}).get("files") or []
|
|
||||||
}
|
|
||||||
diff.files_added.extend(
|
diff.files_added.extend(
|
||||||
f"{system}/{k}" for k in sorted(set(new_files) - set(old_files))
|
f"{system}/{k}" for k in sorted(set(new_files) - set(old_files))
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -304,5 +304,19 @@ class RepositoryWiringTests(unittest.TestCase):
|
|||||||
self.assertIn("[data]", text)
|
self.assertIn("[data]", text)
|
||||||
|
|
||||||
|
|
||||||
|
class RepeatedDestinations(unittest.TestCase):
|
||||||
|
def test_a_change_to_an_earlier_declaration_is_seen(self):
|
||||||
|
from check_freshness import diff_platform # noqa: PLC0415
|
||||||
|
|
||||||
|
def platform(first_md5: str) -> dict:
|
||||||
|
return {"systems": {"pce": {"files": [
|
||||||
|
{"name": "syscard3.pce", "destination": "syscard3.pce", "md5": first_md5},
|
||||||
|
{"name": "syscard3.pce", "destination": "syscard3.pce", "md5": "b" * 32},
|
||||||
|
]}}}
|
||||||
|
|
||||||
|
diff = diff_platform(platform("a" * 32), platform("c" * 32))
|
||||||
|
self.assertEqual(diff.files_changed, ["pce/syscard3.pce"])
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
Reference in new issue
Block a user