aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2021-04-22 13:30:23 +0200
committerGitHub <noreply@github.com>2021-04-22 13:30:23 +0200
commitd20bc3c254311e8968f8ad0381cbf774b2f7cfc1 (patch)
tree9cc5f728cb91f696780cb2f848a8f16774ba0faf
parentc2a30a35fb24f1c4760ae9d2e9b25d444c2db060 (diff)
parent721975313658af8183c85528bf3ecd29b2de983b (diff)
downloadgit-bug-d20bc3c254311e8968f8ad0381cbf774b2f7cfc1.tar.gz
Merge pull request #643 from MichaelMure/gogit-more-mutex
repo: workaround more go-git concurrency issue
-rw-r--r--repository/gogit.go12
1 files changed, 12 insertions, 0 deletions
diff --git a/repository/gogit.go b/repository/gogit.go
index d7c6823e..bec340df 100644
--- a/repository/gogit.go
+++ b/repository/gogit.go
@@ -518,6 +518,9 @@ func (repo *GoGitRepo) StoreTree(mapping []TreeEntry) (Hash, error) {
// ReadTree will return the list of entries in a Git tree
func (repo *GoGitRepo) ReadTree(hash Hash) ([]TreeEntry, error) {
+ repo.rMutex.Lock()
+ defer repo.rMutex.Unlock()
+
h := plumbing.NewHash(hash.String())
// the given hash could be a tree or a commit
@@ -630,6 +633,9 @@ func (repo *GoGitRepo) StoreSignedCommit(treeHash Hash, signKey *openpgp.Entity,
// GetTreeHash return the git tree hash referenced in a commit
func (repo *GoGitRepo) GetTreeHash(commit Hash) (Hash, error) {
+ repo.rMutex.Lock()
+ defer repo.rMutex.Unlock()
+
obj, err := repo.r.CommitObject(plumbing.NewHash(commit.String()))
if err != nil {
return "", err
@@ -640,6 +646,9 @@ func (repo *GoGitRepo) GetTreeHash(commit Hash) (Hash, error) {
// FindCommonAncestor will return the last common ancestor of two chain of commit
func (repo *GoGitRepo) FindCommonAncestor(commit1 Hash, commit2 Hash) (Hash, error) {
+ repo.rMutex.Lock()
+ defer repo.rMutex.Unlock()
+
obj1, err := repo.r.CommitObject(plumbing.NewHash(commit1.String()))
if err != nil {
return "", err
@@ -723,6 +732,9 @@ func (repo *GoGitRepo) ListCommits(ref string) ([]Hash, error) {
}
func (repo *GoGitRepo) ReadCommit(hash Hash) (Commit, error) {
+ repo.rMutex.Lock()
+ defer repo.rMutex.Unlock()
+
commit, err := repo.r.CommitObject(plumbing.NewHash(hash.String()))
if err != nil {
return Commit{}, err