Add a ReInit function (#647) (#649)

libgit2 stores the lookup paths for gitconfig files in its global state.
This means that after a program changes its effective uid libgit2 will
still look for gitconfig files in the home directory of the original
uid. Expose a way to call C.git_libgit2_init so a user can reinitialize
the libgit2 global state.

(cherry picked from commit 3c5c580d78)

Co-authored-by: Jesse Hathaway <jesse@mbuki-mvuki.org>
This commit is contained in:
github-actions[bot] 2020-09-29 15:51:32 -07:00 committed by GitHub
parent 627f58d403
commit a81a08606f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 0 deletions

13
git.go
View File

@ -118,6 +118,10 @@ var (
var pointerHandles *HandleList var pointerHandles *HandleList
func init() { func init() {
initLibGit2()
}
func initLibGit2() {
pointerHandles = NewHandleList() pointerHandles = NewHandleList()
C.git_libgit2_init() C.git_libgit2_init()
@ -149,6 +153,15 @@ func Shutdown() {
C.git_libgit2_shutdown() C.git_libgit2_shutdown()
} }
// ReInit reinitializes the global state, this is useful if the effective user
// id has changed and you want to update the stored search paths for gitconfig
// files. This function frees any references to objects, so it should be called
// before any other functions are called.
func ReInit() {
Shutdown()
initLibGit2()
}
// Oid represents the id for a Git object. // Oid represents the id for a Git object.
type Oid [20]byte type Oid [20]byte