Skip to content

Add --latest to mirror only the newest version - #631

Merged
andrew merged 3 commits into
git-pkgs:mainfrom
simonchrz:feat/mirror-latest
Oct 30, 2026
Merged

andrew merged 3 commits into
git-pkgs:mainfrom
simonchrz:feat/mirror-latest

Conversation

@simonchrz

Copy link
Copy Markdown
Contributor

proxy mirror pkg:npm/lodash mirrors every version the upstream lists. To keep the newest release of some packages cached, from cron for example, you have to look the version up first.

--latest (or "latest": true in a mirror API job) mirrors only the newest version of unversioned PURLs: the highest by the ecosystem's ordering (git-pkgs/vers, now a direct dependency), skipping yanked and retracted versions, and pre-releases unless there is nothing else. Versioned PURLs, also in an SBOM, are mirrored as given. Cooldown isn't applied, as for the rest of mirror.

Tests cover the version ordering for npm, PyPI, gem, Go and Maven, the PURL and SBOM sources, the API request, and yanked versions with a fake crates.io.

An unversioned PURL mirrors every version the upstream lists. With
--latest, or "latest": true in a mirror API job, only the newest is
mirrored: the highest by the ecosystem's version ordering, without
yanked or retracted versions and, unless there is nothing else,
pre-releases.

@andrew andrew left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

newestVersion and RegistryVersions.LatestVersion define "latest" locally, but git-pkgs/registries v0.12.0 (already in go.mod) has a shared policy for this in registries.FetchLatestVersion(ctx, reg, name) / SelectLatestVersion. It prefers the version the registry advertises (npm dist-tags.latest, pub, deno, conda), then the newest active version by publish time, and excludes every non-empty status, including StatusDeprecated, which this PR keeps.

The two disagree in practice: an npm package with 4.0.0 published by mistake and deprecated, and dist-tags.latest at 3.4.0, gets 4.0.0 mirrored here while registries and npm itself say 3.4.0.

Please have RegistryVersions.LatestVersion call registries.FetchLatestVersion on the client from r.registry(...), pulling the helm/swift name rewriting out of fetchVersions so both paths share it. That removes newestVersion, the cmp import and the direct vers dependency. The tests should cover the advertised-version case. If the publish-time fallback turns out wrong for mirroring, that change belongs in registries rather than here.

--latest now uses the shared policy from git-pkgs/registries: the version
the registry advertises as latest where it has one, otherwise the newest
active version by publish time. Deprecated versions are left out too, and
newestVersion and the direct vers dependency go away.
@simonchrz

Copy link
Copy Markdown
Contributor Author

Done in ea2baef. LatestVersion now calls registries.FetchLatestVersion, and registryFor holds the helm/swift name rewriting that fetchVersions uses too. newestVersion, the cmp import and the direct vers dependency are gone. Listers without LatestFinder fall back to registries.SelectLatestVersion. A new test covers your case: dist-tags.latest at 3.4.0 with a deprecated 4.0.0 mirrors 3.4.0. I also merged main.

@andrew andrew left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The update addresses my earlier review by using registries.FetchLatestVersion and covering the advertised-version case.

@andrew
andrew merged commit ce9ab47 into git-pkgs:main Oct 30, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants