aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--repository/git.go9
-rw-r--r--repository/gogit.go9
-rw-r--r--repository/mock_repo.go5
3 files changed, 11 insertions, 12 deletions
diff --git a/repository/git.go b/repository/git.go
index e67e12f5..2348f5d5 100644
--- a/repository/git.go
+++ b/repository/git.go
@@ -367,6 +367,9 @@ func (repo *GitRepo) GetTreeHash(commit Hash) (Hash, error) {
// GetOrCreateClock return a Lamport clock stored in the Repo.
// If the clock doesn't exist, it's created.
func (repo *GitRepo) GetOrCreateClock(name string) (lamport.Clock, error) {
+ repo.clocksMutex.Lock()
+ defer repo.clocksMutex.Unlock()
+
c, err := repo.getClock(name)
if err == nil {
return c, nil
@@ -375,9 +378,6 @@ func (repo *GitRepo) GetOrCreateClock(name string) (lamport.Clock, error) {
return nil, err
}
- repo.clocksMutex.Lock()
- defer repo.clocksMutex.Unlock()
-
c, err = lamport.NewPersistedClock(repo.LocalStorage(), name+"-clock")
if err != nil {
return nil, err
@@ -388,9 +388,6 @@ func (repo *GitRepo) GetOrCreateClock(name string) (lamport.Clock, error) {
}
func (repo *GitRepo) getClock(name string) (lamport.Clock, error) {
- repo.clocksMutex.Lock()
- defer repo.clocksMutex.Unlock()
-
if c, ok := repo.clocks[name]; ok {
return c, nil
}
diff --git a/repository/gogit.go b/repository/gogit.go
index 0d34c00a..741982aa 100644
--- a/repository/gogit.go
+++ b/repository/gogit.go
@@ -604,6 +604,9 @@ func (repo *GoGitRepo) ListCommits(ref string) ([]Hash, error) {
// GetOrCreateClock return a Lamport clock stored in the Repo.
// If the clock doesn't exist, it's created.
func (repo *GoGitRepo) GetOrCreateClock(name string) (lamport.Clock, error) {
+ repo.clocksMutex.Lock()
+ defer repo.clocksMutex.Unlock()
+
c, err := repo.getClock(name)
if err == nil {
return c, nil
@@ -612,9 +615,6 @@ func (repo *GoGitRepo) GetOrCreateClock(name string) (lamport.Clock, error) {
return nil, err
}
- repo.clocksMutex.Lock()
- defer repo.clocksMutex.Unlock()
-
c, err = lamport.NewPersistedClock(repo.localStorage, name+"-clock")
if err != nil {
return nil, err
@@ -625,9 +625,6 @@ func (repo *GoGitRepo) GetOrCreateClock(name string) (lamport.Clock, error) {
}
func (repo *GoGitRepo) getClock(name string) (lamport.Clock, error) {
- repo.clocksMutex.Lock()
- defer repo.clocksMutex.Unlock()
-
if c, ok := repo.clocks[name]; ok {
return c, nil
}
diff --git a/repository/mock_repo.go b/repository/mock_repo.go
index 74d4cae7..02e5010f 100644
--- a/repository/mock_repo.go
+++ b/repository/mock_repo.go
@@ -4,6 +4,7 @@ import (
"crypto/sha1"
"fmt"
"strings"
+ "sync"
"github.com/99designs/keyring"
"github.com/go-git/go-billy/v5"
@@ -337,6 +338,7 @@ func (m mockRepoForTest) EraseFromDisk() error {
}
type mockRepoClock struct {
+ mu sync.Mutex
clocks map[string]lamport.Clock
}
@@ -347,6 +349,9 @@ func NewMockRepoClock() *mockRepoClock {
}
func (r *mockRepoClock) GetOrCreateClock(name string) (lamport.Clock, error) {
+ r.mu.Lock()
+ defer r.mu.Unlock()
+
if c, ok := r.clocks[name]; ok {
return c, nil
}