From 86d0d53f1b00ec7f5da3c91fad896ffd88cb8918 Mon Sep 17 00:00:00 2001 From: Jesse Hathaway Date: Tue, 29 Sep 2020 17:42:20 -0500 Subject: [PATCH] Add a ReInit function (#647) 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 3c5c580d78831d10e082743f3783424b72ac9e09) --- git.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/git.go b/git.go index ff9b643..d833505 100644 --- a/git.go +++ b/git.go @@ -118,6 +118,10 @@ var ( var pointerHandles *HandleList func init() { + initLibGit2() +} + +func initLibGit2() { pointerHandles = NewHandleList() C.git_libgit2_init() @@ -149,6 +153,15 @@ func 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. type Oid [20]byte -- 2.45.2