From d693954cf53bf544359bc2eaf8634d7dc5540739 Mon Sep 17 00:00:00 2001 From: Jesse Hathaway Date: Mon, 28 Sep 2020 20:59:18 +0000 Subject: [PATCH 1/2] 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. --- git.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/git.go b/git.go index bd01b6d..ebece03 100644 --- a/git.go +++ b/git.go @@ -149,6 +149,17 @@ 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() { + pointerHandles.Clear() + C.git_libgit2_shutdown() + pointerHandles = NewHandleList() + C.git_libgit2_init() +} + // Oid represents the id for a Git object. type Oid [20]byte -- 2.45.2 From 26cf9e38ff3ac2faac778447df07b8c37d8cd4cc Mon Sep 17 00:00:00 2001 From: Jesse Hathaway Date: Tue, 29 Sep 2020 18:36:36 +0000 Subject: [PATCH 2/2] add initLibGit2() to avoid repetition Go does not allow you to call the package init() function, so instead add a new function to initialize libgit2 and use that function to reduce the repetition in ReInit() --- git.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/git.go b/git.go index ebece03..5acff0d 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() @@ -154,10 +158,8 @@ func Shutdown() { // 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() + Shutdown() + initLibGit2() } // Oid represents the id for a Git object. -- 2.45.2