Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: sharing not thread safe go-git tree and storer
- Loading branch information
1 parent
50b9a0c
commit 1e2755b
Showing
6 changed files
with
127 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package repo_handle | ||
|
||
import ( | ||
"fmt" | ||
"sync" | ||
|
||
"github.com/go-git/go-git/v5/plumbing" | ||
"github.com/go-git/go-git/v5/plumbing/object" | ||
) | ||
|
||
type treeHandle struct { | ||
tree *object.Tree | ||
mutex *sync.Mutex | ||
} | ||
|
||
func newTreeHandle(tree *object.Tree, mutex *sync.Mutex) *treeHandle { | ||
return &treeHandle{tree: tree, mutex: mutex} | ||
} | ||
|
||
func (h *treeHandle) Hash() plumbing.Hash { | ||
return h.tree.Hash | ||
} | ||
|
||
func (h *treeHandle) Tree(path string) (TreeHandle, error) { | ||
h.mutex.Lock() | ||
defer h.mutex.Unlock() | ||
|
||
tree, err := h.tree.Tree(path) | ||
if err != nil { | ||
return nil, fmt.Errorf("unable to get tree %q: %s", path, err) | ||
} | ||
|
||
treeHandle := newTreeHandle(tree, h.mutex) | ||
return treeHandle, nil | ||
} | ||
|
||
func (h *treeHandle) FindEntry(path string) (*object.TreeEntry, error) { | ||
h.mutex.Lock() | ||
defer h.mutex.Unlock() | ||
|
||
return h.tree.FindEntry(path) | ||
} | ||
|
||
func (h *treeHandle) Entries() []object.TreeEntry { | ||
h.mutex.Lock() | ||
defer h.mutex.Unlock() | ||
|
||
return h.tree.Entries | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters