rust-lang / rust-lang/git2-rs

Self-referential repo + tree

Open
#622 6 comments 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've found that I often need to store a Repository and a Tree<'repo> that borrows from it. Unfortunately, this creates unsafe self-referential structs.

It would be helpful if this crate provided a safe abstraction for repo + tree together, e.g.

let repo = git2::Repository::open()?;

/// makes RepositoryWithTree
let repo = repo.with_tree(|repo| {
	repo.find_commit(head)?.tree()
});

*repo // Derefs to Repository
repo.tree(); // returns borrowed Tree

Alternatively, there's owning-ref that has OwningHandle trait. It would require git2 types to implement its traits.

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 with the Repository and Tree APIs and the proposed with_tree entry point; compare the owning_ref OwningHandle requirements mentioned in the issue. Define the safe ownership and borrowing behavior, then validate it with focused tests; done means callers can keep a Repository and borrowed Tree together without unsafe self-referential structs.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.