← Back to Pull requests

gitproto: sync SHA-256 repositories #151

Closed
unknown closed this pull request without merging on Nov 25, 2026 13:08 UTC
View on GitHub
unknown unknown commented on Nov 25, 2026 10:57 UTC
Author

Summary

git-sync could not sync SHA-256 repositories. Protocol v2 treats a client that omits object-format as SHA-1, so a SHA-256 server rejects every ls-refs and fetch from git-sync. Real git rejects both outright; a server that only checks on fetch answers it with object-format mismatch: client did not declare object-format, server "sha256". Past that, git-sync assumed SHA-1 in several more places. Each fix below exposed the next:

 V2Capabilities.RequestCapabilities        # ls-refs + fetch
   agent=…
+  object-format=<advertised>              # echo what the server advertised

 buildUpdateRequest                        # receive-pack
+  capability object-format=<advertised>
-  null id = plumbing.ZeroHash             # 40 hex zeros
+  null id = wireHash(…)                   # 64 hex zeros on a sha256 target

 FetchCommitParents → ExtractCommitParents # batched bootstrap
-  parser + hasher: sha1
+  parser + hasher: source's object-format
   parseCommitParents
-    parent id = 40 hex
+    parent id = format.HexSize() hex       # 64 under sha256

 sync planning / fetch                     # in-memory store
-  memory.NewStorage()                     # sha1
+  newSourceStore(source.ObjectFormat())

 bootstrap packStreamObserver              # upload diagnostics
-  packfile.NewScanner(pr)                 # sha1
+  packfile.NewScanner(pr, WithSHA256())   # when the source is sha256

v1 upload-pack requests declare the advertised object-format too.

git-sync relays the source's ids and packs unchanged, so it cannot sync between formats. Sync, plan, replicate and bootstrap between a SHA-1 and a SHA-256 repository now stop once both formats are known, before fetching anything, with an error that names both and wraps ErrObjectFormatMismatch. Probe skips that check, so it still shows what each endpoint advertised. A remote advertising a format other than sha1 or sha256 is rejected with ErrUnsupportedObjectFormat as soon as its advertisement is read, before any of its ids are decoded. Both sentinels are exported from the root package.

newSession
  ListSourceRefs          → ValidateObjectFormat(source)   # v1: first ref line, before ids; v2: before ls-refs
  list target refs        → ValidateObjectFormat(target)   # first ref line, before ids
Run / Bootstrap
  checkObjectFormats      → CheckObjectFormats(source, target)   # before any fetch
Probe                     # no compatibility check: reports both advertisements

Requests to SHA-1 repositories are unchanged, except that a server advertising object-format=sha1 now gets it echoed back, as real git does.

Evidence

All end-to-end tests run against real git http-backend.

New TestReplicate_GitHTTPBackendSHA256: replicate mode with prune and tags, SHA-256 source and target. A bootstrap into an empty target, then a fast-forward, a new branch and a branch deletion.

  • Before: replicate failed: list source refs: read pktline header: EOF (git rejects the ls-refs)

  • After echoing the format on fetch: bootstrap execute: push target refs: decode report-status: unexpected EOF

  • After: PASS
  • TestReplicate_GitHTTPBackendResumeAfterTrunkLanded gains two SHA-256 cases (empty target, and trunk already on the target):

  • Before: fetch bootstrap commit parents …: parse packfile: malformed pack file: checksum mismatch

  • After: PASS
  • New TestReplicate_GitHTTPBackendSplitsTrunkAcrossPushes (sha1 + sha256): three ~150 KB commits against a 325 KB push limit, so the trunk must be split across pushes.

  • Before: sha1 PASS; sha256 bootstrap checkpoint exceeds target pack limit and cannot be subdivided further: … http 413, because the parent parser dropped every 64-hex parent and the planner saw a one-commit chain

  • After: both PASS
  • The same test captures BootstrapLogger and requires every checkpoint to log observer_failed=false. Before the fix, a SHA-256 checkpoint that landed logged observer_failed=true. Without the SourceObjectFormat wiring in syncer, the test fails.

    TestRun_GitHTTPBackendSync (default sync mode) now runs for sha1 and sha256:

  • Before: the sha256 bootstrap passes, then the fast-forward fails with fetch to store: update object storage: malformed pack file: checksum mismatch

  • After: both PASS
  • New TestRun_GitHTTPBackendSyncObjectFormatMismatch (sha1→sha256 and sha256→sha1) asserts the mismatch error from sync, plan, replicate and bootstrap, that no fetch reaches the source, and that Probe still returns the source refs and both endpoints' object-format:

  • Before: the whole source is fetched, then push target refs: decode report-status: unexpected EOF

  • After: object formats: source and target object formats differ: source is sha1, target is sha256; …, with no fetch
  • New mise run test:git-http-backend:sha256 runs every git-http-backend test with GIT_DEFAULT_HASH=sha256; all pass. Both backend tasks run with -count=1: only the git subprocess reads GIT_DEFAULT_HASH, so Go's test cache would otherwise replay one format's result for the other.

    TestV1AdvertisementRejectsUnsupportedObjectFormat uses a sha512 advertisement with 128-hex ids, on the source and the target, in eight layouts: plain, version 1 first, a first ref line over 4 KiB, one near the 65520-byte pkt-line limit, version 1 followed by a long line, and three without the smart-HTTP banner (as SSH and remote helpers send):

  • Before: cannot read hash, invalid size: 128, not ErrUnsupportedObjectFormat (plain layout first; the other four after the first fix)

  • After: ErrUnsupportedObjectFormat in every layout; sha1 and sha256 advertisements still decode in every layout
  • Without a banner, a valid advertisement of any format whose first ref line is over 4 KiB used to fail with peek pktline: bufio: buffer full, on main too: the banner check peeked the whole first packet. It now peeks only # service=.

    Unit tests: TestCheckObjectFormats, TestValidateObjectFormat, TestListSourceRefsV2RejectsUnsupportedObjectFormatBeforeLsRefs, TestBuildV1UploadPackBodyDeclaresObjectFormat, TestRequestCapabilitiesEchoesObjectFormat, TestBuildUpdateRequestSHA256Target, TestBuildUpdateRequestSHA1TargetUnchanged, TestParseCommitParents_ObjectFormat, TestPackStreamObserverScansSHA256Pack.

    go test ./..., mise run test:git-http-backend, mise run test:git-http-backend:sha256 and golangci-lint run all pass.

    Merge Danger

    Door: two-way

    Blast Radius: wire requests

    Every v2 request and every receive-pack now carries object-format whenever the server advertises it, SHA-1 servers included. Real git does the same, so servers already accept it.

    A sync between repositories of different formats now fails before fetching, with a new error, instead of failing the push after a full fetch. It could never succeed, so no working setup changes.

    ExtractCommitParents and ExtractCommitParentsWithCache take a new format argument. Both are in internal/, so no external callers break.

    CI does not run the git-http-backend tests, so the SHA-256 end-to-end coverage only runs locally.

    🤖 Generated with Claude Code

    https://claude.ai/code/session_01FU3noQ5Lu6XeV7atoVDTmW

    <!-- CURSOR_SUMMARY -->
    ---

    [!NOTE]

    Medium Risk

    Changes Git wire requests and push encoding for all remotes that advertise object-format, and alters when sync fails (early mismatch vs late push errors); behavior for SHA-1 is mostly unchanged but v1/v2 requests may now include explicit format capabilities.

    > Overview

    SHA-256 repositories can now sync end-to-end. Protocol v2 ls-refs/fetch, v1 upload-pack, and receive-pack pushes echo the remote’s advertised object-format, and SHA-256 pushes use 64-hex null ids via wireHash. Pack parsing, planning stores (newSourceStore), commit-parent extraction, and bootstrap pack observers all run in the source’s format instead of assuming SHA-1.

    > Fail-fast compatibility checks add ErrObjectFormatMismatch and ErrUnsupportedObjectFormat (exported from the root package). Sync, plan, replicate, and bootstrap call checkObjectFormats before fetching; v0/v1 ads are validated on the first ref line before id decode. Probe still lists both sides’ capabilities.

    > Coverage includes git-http-backend integration tests for SHA-256 replicate/bootstrap/split-trunk, format-mismatch behavior, and mise run test:git-http-backend:sha256.

    > <sup>Reviewed by Cursor Bugbot for commit df0fff3e38da50a14e439a348caa1a72eaf67148. Configure here.</sup>

    <!-- /CURSOR_SUMMARY -->

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: pjbgf Review duration: 131m
    All Vouch review confidence checks passed
    Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #151"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 20.5% · Safe to merge
    20.5%