Skip to content

feat(git): SHA256 repository support#16939

Draft
weihanglo wants to merge 7 commits intorust-lang:masterfrom
weihanglo:sha256-git2
Draft

feat(git): SHA256 repository support#16939
weihanglo wants to merge 7 commits intorust-lang:masterfrom
weihanglo:sha256-git2

Conversation

@weihanglo
Copy link
Copy Markdown
Member

@weihanglo weihanglo commented Apr 24, 2026

What does this PR try to resolve?

This wires the unstable libgit2 SHA256 support into Cargo.

SHA256 repositories usage are gated behind -Zgit=sha256.

Before looking at a repo,
Cargo now try to guess whether this git dep is SHA1 or SHA256
from these places (in this order):

  • locked rev in Cargo.lock
  • local db (with or without -sha256 suffix)
  • Create a detached remote and probe its object format

What works and doesn't:

  • Git CLI and libgit2 interop works
  • SHA1 and SHA256 git db coexist (via -sha256 dir suffix)
  • -Zgit=sha256 gates during early fetch paths,
    so even have local db cached you cannot use without Z flag
  • gitoxide hasn't yet supported, and will fall back to libgit2 when sha256 is used

Some known issues and regressions:

  • Probing adds a silent extra round-trip on every first fetch,
    even for SHA1 repos.
    An alternative is to assume SHA1 and retry on mismatch,
    though it has cost of a wasted fetch attempt for SHA256 repos.

How to test and review this PR?

Fixes #14942

This is currently blocked on libgit2 and git2-rs to cut a new release that contain all fixes we want listed in #14942.

I haven't tried it end-to-end though

The current model also means that Cargo will always vendor libgit2, which I guess will cause some headache on downstream packagers (Fedora, Debian, NixOS, etc.)

@rustbot rustbot added A-documenting-cargo-itself Area: Cargo's documentation A-git Area: anything dealing with git A-testing-cargo-itself Area: cargo's tests A-unstable Area: nightly unstable support labels Apr 24, 2026
@weihanglo
Copy link
Copy Markdown
Member Author

Created for showcasing it works btw.

@weihanglo weihanglo force-pushed the sha256-git2 branch 2 times, most recently from aa393ab to 541130b Compare April 24, 2026 22:44
@weihanglo weihanglo force-pushed the sha256-git2 branch 2 times, most recently from beb11a4 to 0cf0b48 Compare April 25, 2026 00:20
This wires the unstable libgit2 SHA256 support into Cargo.

SHA256 repositories usage are gated behind `-Zgit=sha256`.

Before looking at a repo,
Cargo now try to guess whether this git dep is SHA1 or SHA256
from these places (in this order):

* locked rev in Cargo.lock
* local db (with or without `-sha256` suffix)
* Create a detached remote and probe its object format

What works and doesn't:

* Git CLI and libgit2 interop works
* SHA1 and SHA256 git db coexist (via `-sha256` dir suffix)
* `-Zgit=sha256` gates during early fetch paths,
  so even have local db cached you cannot use without Z flag
* gitoxide hasn't yet supported

Some known issues and regressions:

* Probing adds a silent extra round-trip on every first fetch,
  even for SHA1 repos.
  An alternative is to assume SHA1 and retry on mismatch,
  though it has cost of a wasted fetch attempt for SHA256 repos.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-documenting-cargo-itself Area: Cargo's documentation A-git Area: anything dealing with git A-testing-cargo-itself Area: cargo's tests A-unstable Area: nightly unstable support

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support SHA256 Git repositories

2 participants