diff options
author | Michael Muré <batolettre@gmail.com> | 2020-12-08 13:15:21 +0100 |
---|---|---|
committer | Michael Muré <batolettre@gmail.com> | 2020-12-08 13:15:21 +0100 |
commit | 71e1303234ef227851998f08c98c7c69670c9966 (patch) | |
tree | a2a72ec276992aa4628d418d68a99e49f40d1ef5 /repository/git.go | |
parent | be6e653f1566f5812e7c4442927eee02963dfb68 (diff) | |
download | git-bug-71e1303234ef227851998f08c98c7c69670c9966.tar.gz |
repo: simpler clock mutex locking
Diffstat (limited to 'repository/git.go')
-rw-r--r-- | repository/git.go | 9 |
1 files changed, 3 insertions, 6 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 } |