rust-lang / rust-lang/git2-rs

Confusion around ODB/mempack lifetimes

Open
#867 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
2.1k
Forks
450
Avg merge
11m
Merged PRs (30d)
1

Description

I have some code like this in a function:

repo.odb()
            .context("Failed to get the repo's object database")
            .unwrap()
            .add_new_mempack_backend(999)
            .context("Failed to create new mempack ODB backend")
            .unwrap();

So I'm immediately dropping the returned Odb. I had trouble understanding the underlying C code in libgit2, so my first question is:

Assuming I never explicitly set an alternative ODB, should repeated calls to repo.odb() ultimately point to the same underlying resource in "C land"?

Secondly, I've observed that if I create a mempack backend like this and then write things to the repository (trees, blobs) then most of the time they never get written to disk (good) but occasionally they do (intermittent, bad!)

So my next question is:

Is there an obvious explanation for this — e.g. am I supposed to be keeping the Odb alive to stop the mempack backend from (eventually?) being removed/destroyed?

I'm hoping I've just misunderstood something simple about mempack usage. 🙏

Thanks!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the issue's repo.odb() and add_new_mempack_backend(999) calls through the Rust bindings and the underlying libgit2 behavior. Reproduce repeated ODB access and repository writes, then determine whether dropping the returned ODB affects the mempack backend and whether the observed disk writes are expected.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
backend, databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.