Skip to content

Tie Indexer to the Odb borrow - #1353

Merged
weihanglo merged 4 commits into
rust-lang:mainfrom
fairfairfair-210:fix-indexer-odb-lifetime
Nov 29, 2026
Merged

weihanglo merged 4 commits into
rust-lang:mainfrom
fairfairfair-210:fix-indexer-odb-lifetime

Conversation

@fairfairfair-210

@fairfairfair-210 fairfairfair-210 commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

git_indexer_new keeps the supplied ODB pointer without taking a reference. An Indexer could previously outlive the Odb value and later dereference freed memory when verifying connectivity or fixing a thin pack.

Store Option<&'odb Odb<'odb>> in Indexer<'odb> and borrow the ODB in Indexer::new / new_ext. Add compile-fail regressions for borrowing a temporary ODB (E0716) and dropping a borrowed ODB before the indexer (E0505).

Clarify that None is accepted by libgit2. Thin packs requiring an external delta base fail during Indexer::commit, rather than write. With verification enabled, connectivity checks still run and missing referenced objects cannot be satisfied from an external ODB.

Fixes #1352.

Validation

Validated after merging main at 2ea0217 (libgit2 2.0.0-rc.1):

  • cargo +stable test --locked
  • cargo +stable test --locked --features https,ssh
  • cargo +stable test --locked -p git2-curl
  • cargo +stable run --locked -p systest
  • cargo +stable fmt --check
  • cargo +stable clippy --locked --all-targets --all-features -- -Dwarnings

The stable compile-fail suite retains all upstream cases and both new Indexer regressions. Existing SHA-1 and SHA-256 Indexer tests cover valid ODB borrows.

@rustbot rustbot added the S-waiting-on-review Status: Waiting on review label Nov 24, 2026

@DanielEScherzer DanielEScherzer 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.

community review: have a question inline
might want to consider adding compile-fail regression tests

View changes since this review

Comment thread src/indexer.rs
progress: raw::git_indexer_progress,
progress_payload_ptr: *mut OdbPackwriterCb<'odb>,
// libgit2's git_indexer stores a bare git_odb pointer (it does not addref
// it), so keep the Rust borrow alive for as long as the indexer exists.

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.

this documentation suggests that the Odb should never be None - but it can be None, can you document why that isn't an issue?

@weihanglo

Copy link
Copy Markdown
Member

might want to consider adding compile-fail regression tests

Agreed with this

@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

@fairfairfair-210

Copy link
Copy Markdown
Contributor Author

Added docs explaining why None is supported: libgit2 accepts a null ODB, but a thin pack that needs an external delta base is rejected during Indexer::commit. Connectivity verification still runs and rejects missing referenced objects that can't be found without an ODB. Also added compile-fail regressions for borrowing a temporary ODB (E0716) and dropping a borrowed ODB (E0505). Valid-borrow tests pass for both SHA-1 and SHA-256. Merged current main and kept all upstream compile-fail cases.

Comment thread src/indexer.rs Outdated
/// rejected when [`Indexer::commit`] resolves the pending deltas, with
/// "cannot fix a thin pack without an ODB".
///
/// When `verify` is enabled, connectivity is still checked. An object

@weihanglo weihanglo Nov 28, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

on L126 it also talks about verify. Can you consolidate them?

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

@rustbot

rustbot commented Nov 29, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@weihanglo weihanglo left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@weihanglo
weihanglo added this pull request to the merge queue Nov 29, 2026
Merged via the queue into rust-lang:main with commit d2c8178 Nov 29, 2026
12 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Waiting on review label Nov 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Indexer::new does not keep the Odb alive; libgit2 stores a bare git_odb * and a normal index operation dereferences the freed object

4 participants