Add a ReInit function

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.
This commit is contained in:
Jesse Hathaway 2020-09-28 20:59:18 +00:00
parent 7e726fda6e
commit d693954cf5
1 changed files with 11 additions and 0 deletions

11
git.go
View File

@ -149,6 +149,17 @@ 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() {
pointerHandles.Clear()
C.git_libgit2_shutdown()
pointerHandles = NewHandleList()
C.git_libgit2_init()
}
// Oid represents the id for a Git object. // Oid represents the id for a Git object.
type Oid [20]byte type Oid [20]byte