diff options
author | Michael Muré <batolettre@gmail.com> | 2021-04-17 20:41:32 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-17 20:41:32 +0200 |
commit | 63b1d93db1dad1bee4390bad3bd6c2cb9d829a78 (patch) | |
tree | ee8e07be4dfd8afd942d1ebcfa4be55a79ac4543 /repository/gogit.go | |
parent | 6d1c9346cc5ff892f808a7e3dd3e01291e49a16d (diff) | |
parent | d000838cfb6a48298b6e3b6cd45e249096984936 (diff) | |
download | git-bug-63b1d93db1dad1bee4390bad3bd6c2cb9d829a78.tar.gz |
Merge pull request #635 from MichaelMure/gogit-thread
repository: workaround a non thread-safe path in go-git
Diffstat (limited to 'repository/gogit.go')
-rw-r--r-- | repository/gogit.go | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/repository/gogit.go b/repository/gogit.go index 20454bd7..d7c6823e 100644 --- a/repository/gogit.go +++ b/repository/gogit.go @@ -31,8 +31,13 @@ var _ ClockedRepo = &GoGitRepo{} var _ TestedRepo = &GoGitRepo{} type GoGitRepo struct { - r *gogit.Repository - path string + // Unfortunately, some parts of go-git are not thread-safe so we have to cover them with a big fat mutex here. + // See https://github.com/go-git/go-git/issues/48 + // See https://github.com/go-git/go-git/issues/208 + // See https://github.com/go-git/go-git/pull/186 + rMutex sync.Mutex + r *gogit.Repository + path string clocksMutex sync.Mutex clocks map[string]lamport.Clock @@ -448,6 +453,9 @@ func (repo *GoGitRepo) StoreData(data []byte) (Hash, error) { // ReadData will attempt to read arbitrary data from the given hash func (repo *GoGitRepo) ReadData(hash Hash) ([]byte, error) { + repo.rMutex.Lock() + defer repo.rMutex.Unlock() + obj, err := repo.r.BlobObject(plumbing.NewHash(hash.String())) if err != nil { return nil, err |