git2-rs icon indicating copy to clipboard operation
git2-rs copied to clipboard

Unnecessary lifetimes

Open edrevo opened this issue 1 year ago • 0 comments

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.

edrevo avatar Apr 03 '23 14:04 edrevo