refactor: split core.upstream by subject

HTTP to the forges moves to core.forgehttp, comparisons, trees and
clone history to core.upstreamtree. core.upstream keeps repositories,
the cache and revisions.
This commit is contained in:
Abdessamad Derraz committed 2026-11-24 06:20:52 +01:00
1 parent ce92eff0aa
commit 263a64c0e0
65 files changed
+1417 -1337

No files matched your search

+9 -8
View File
@@ -16,8 +16,9 @@ from collections.abc import Callable, Iterator
from pathlib import Path
from core import upstream
from core import forgehttp
from core.artifacts import file_lock as _file_lock, write_text_atomic
from core.upstream import remote_etag as _get_remote_etag
from core.forgehttp import remote_etag as _get_remote_etag
from model.registry import load_versions, versions_file_for
from packs.datadirextract import extract_tar_subtree, extract_zip_tree
@@ -30,7 +31,7 @@ DOWNLOAD_TIMEOUT = 300
# A mirror sometimes answers with a page that is not the archive: the
# buildbot's ScummVM.zip failed CI once as "File is not a zip file" and
# downloaded fine minutes later. Seconds to wait before each retry. The
# transfer itself is retried by core.upstream.download: these waits cover
# transfer itself is retried by core.forgehttp.download: these waits cover
# an archive that arrived whole and does not read.
DOWNLOAD_RETRY_WAITS = (5, 20)
_TRANSIENT = (
@@ -182,7 +183,7 @@ def get_remote_sha(source_url: str, version: str) -> str | None:
return None
try:
return upstream.resolve_head(repo, None, branch=version)
except (upstream.UpstreamError, ValueError) as exc:
except (forgehttp.UpstreamError, ValueError) as exc:
log.warning("failed to fetch remote SHA for %s@%s: %s", repo.slug, version, exc)
return None
@@ -266,7 +267,7 @@ def _download_and_extract_zip(
def _fetch(source_url: str, archive_path: Path, measured: Callable[[int], None] | None) -> None:
"""Download source_url to archive_path, its size handed to measured."""
log.info("downloading %s", source_url)
upstream.download(
forgehttp.download(
source_url, archive_path, timeout=DOWNLOAD_TIMEOUT, user_agent=USER_AGENT
)
if measured is not None:
@@ -277,7 +278,7 @@ def _measure_archive(source_url: str) -> int | None:
"""The size of the archive at source_url, read by streaming it: a
tarball GitHub builds on request is sent without a Content-Length."""
req = urllib.request.Request(
source_url, headers=upstream.forge_headers(source_url, user_agent=USER_AGENT)
source_url, headers=forgehttp.forge_headers(source_url, user_agent=USER_AGENT)
)
def count(resp: http.client.HTTPResponse) -> int:
@@ -287,8 +288,8 @@ def _measure_archive(source_url: str) -> int | None:
return size
try:
size = upstream.open_retrying(req, count, DOWNLOAD_TIMEOUT)
except (*_TRANSIENT, upstream.UpstreamError) as exc:
size = forgehttp.open_retrying(req, count, DOWNLOAD_TIMEOUT)
except (*_TRANSIENT, forgehttp.UpstreamError) as exc:
log.warning("could not measure %s: %s", source_url, exc)
return None
return size or None
@@ -446,7 +447,7 @@ def _refresh_entry(
try:
file_count = fetch()
break
except (NothingExtractedError, ValueError, upstream.UpstreamError) as exc:
except (NothingExtractedError, ValueError, forgehttp.UpstreamError) as exc:
# A host gone or still rate limited after core.upstream's own
# waits answers the same way on the next try.
log.warning("[%s] download failed: %s", key, exc)