Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unnecessary lifetimes #945

Open
edrevo opened this issue Apr 3, 2023 · 0 comments
Open

Unnecessary lifetimes #945

edrevo opened this issue Apr 3, 2023 · 0 comments

Comments

@edrevo
Copy link
Contributor

edrevo commented Apr 3, 2023

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.

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

No branches or pull requests

1 participant