aboutsummaryrefslogtreecommitdiffstats
path: root/cache/repo_cache_common.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2022-12-19 18:09:59 +0100
committerMichael Muré <batolettre@gmail.com>2022-12-19 18:09:59 +0100
commitf2def3a9331080a02e57710a859d2aac608ed44c (patch)
tree2697224efb96110b65489877b5ba7d67d508eb5e /cache/repo_cache_common.go
parent60d40d60e9f91247b61f541888f1469bff44f573 (diff)
downloadgit-bug-f2def3a9331080a02e57710a859d2aac608ed44c.tar.gz
WIP
Diffstat (limited to 'cache/repo_cache_common.go')
-rw-r--r--cache/repo_cache_common.go64
1 files changed, 31 insertions, 33 deletions
diff --git a/cache/repo_cache_common.go b/cache/repo_cache_common.go
index 18ba52f3..1aed04b2 100644
--- a/cache/repo_cache_common.go
+++ b/cache/repo_cache_common.go
@@ -1,8 +1,6 @@
package cache
import (
- "fmt"
-
"github.com/go-git/go-billy/v5"
"github.com/pkg/errors"
@@ -186,64 +184,64 @@ func (c *RepoCache) Pull(remote string) error {
}
func (c *RepoCache) SetUserIdentity(i *IdentityCache) error {
- err := identity.SetUserIdentity(c.repo, i.Identity)
- if err != nil {
- return err
- }
-
- c.muIdentity.RLock()
- defer c.muIdentity.RUnlock()
+ c.muUserIdentity.RLock()
+ defer c.muUserIdentity.RUnlock()
// Make sure that everything is fine
- if _, ok := c.identities[i.Id()]; !ok {
+ if _, err := c.identities.Resolve(i.Id()); err != nil {
panic("SetUserIdentity while the identity is not from the cache, something is wrong")
}
+ err := identity.SetUserIdentity(c.repo, i.Identity)
+ if err != nil {
+ return err
+ }
+
c.userIdentityId = i.Id()
return nil
}
func (c *RepoCache) GetUserIdentity() (*IdentityCache, error) {
+ c.muUserIdentity.RLock()
if c.userIdentityId != "" {
- i, ok := c.identities[c.userIdentityId]
- if ok {
- return i, nil
- }
+ defer c.muUserIdentity.RUnlock()
+ return c.identities.Resolve(c.userIdentityId)
}
+ c.muUserIdentity.RUnlock()
- c.muIdentity.Lock()
- defer c.muIdentity.Unlock()
+ c.muUserIdentity.Lock()
+ defer c.muUserIdentity.Unlock()
- i, err := identity.GetUserIdentity(c.repo)
+ i, err := identity.GetUserIdentityId(c.repo)
if err != nil {
return nil, err
}
- cached := NewIdentityCache(c, i)
- c.identities[i.Id()] = cached
- c.userIdentityId = i.Id()
+ c.userIdentityId = i
- return cached, nil
+ return c.identities.Resolve(i)
}
func (c *RepoCache) GetUserIdentityExcerpt() (*IdentityExcerpt, error) {
- if c.userIdentityId == "" {
- id, err := identity.GetUserIdentityId(c.repo)
- if err != nil {
- return nil, err
- }
- c.userIdentityId = id
+ c.muUserIdentity.RLock()
+ if c.userIdentityId != "" {
+ defer c.muUserIdentity.RUnlock()
+ return c.identities.ResolveExcerpt(c.userIdentityId)
}
+ c.muUserIdentity.RUnlock()
- c.muIdentity.RLock()
- defer c.muIdentity.RUnlock()
+ c.muUserIdentity.Lock()
+ defer c.muUserIdentity.Unlock()
- excerpt, ok := c.identitiesExcerpts[c.userIdentityId]
- if !ok {
- return nil, fmt.Errorf("cache: missing identity excerpt %v", c.userIdentityId)
+ i, err := identity.GetUserIdentityId(c.repo)
+ if err != nil {
+ return nil, err
}
- return excerpt, nil
+
+ c.userIdentityId = i
+
+ return c.identities.ResolveExcerpt(i)
}
func (c *RepoCache) IsUserIdentitySet() (bool, error) {