Skip to content

Commit 3c5c580

Browse files
authored
Add a ReInit function (libgit2#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.
1 parent 7e726fd commit 3c5c580

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

git.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ var (
118118
var pointerHandles *HandleList
119119

120120
func init() {
121+
initLibGit2()
122+
}
123+
124+
func initLibGit2() {
121125
pointerHandles = NewHandleList()
122126

123127
C.git_libgit2_init()
@@ -149,6 +153,15 @@ func Shutdown() {
149153
C.git_libgit2_shutdown()
150154
}
151155

156+
// ReInit reinitializes the global state, this is useful if the effective user
157+
// id has changed and you want to update the stored search paths for gitconfig
158+
// files. This function frees any references to objects, so it should be called
159+
// before any other functions are called.
160+
func ReInit() {
161+
Shutdown()
162+
initLibGit2()
163+
}
164+
152165
// Oid represents the id for a Git object.
153166
type Oid [20]byte
154167

0 commit comments

Comments
 (0)