rust-lang / rust-lang/git2-rs

Unnecessary lifetimes

Open
#945 0 comments 4 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

Both ODB and Repository are ref-counted objects (see https://github.com/libgit2/libgit2/blob/2f20fe8869d7a1df7c9b7a9e2939c1a20533c6dc/src/libgit2/odb.c#L930 for example) so calling free doesn't necessarily mean that the underlying object is being freed.

There are several methods in git2-rs that return an object with a lifetime that is bound to either the original Repo or Odb, but there's nothing wrong with freeing the corresponding Repo or Odb. For example, this git2go code runs fine:

w, err := odb.NewWritePack(nil)
odb.Free() // Explicitly free the odb object
repo.Free() // Explicitly free the repo object
w.Write(response.PackfileData) // works fine
err = w.Commit() // works fine

Having these lifetimes makes git2-rs less ergonomic and they don't provide any extra safety. I guess removing them would be a breaking change to the git2-rs API, but maybe they could be replaced by 'static.

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 reviewing the git2-rs APIs that return objects whose lifetimes are tied to ODB or Repository, then read the cited libgit2 odb.c reference around line 930 and compare it with the git2go example. Determine the scope and compatibility impact of removing those lifetime bounds or replacing them with 'static, and define the affected API and test updates before making a change.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
api, developer-experience
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.