aboutsummaryrefslogtreecommitdiffstats
path: root/cache
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2019-01-17 03:09:08 +0100
committerMichael Muré <batolettre@gmail.com>2019-03-01 22:35:37 +0100
commitbdbe9e7e8256fff820efe1ce707e7154d517ecb3 (patch)
tree82b86c7f89c6c9796b1c7b26beea350afa634d6f /cache
parent3df4f46c71650c9d23b267c44afec16f1b759e92 (diff)
downloadgit-bug-bdbe9e7e8256fff820efe1ce707e7154d517ecb3.tar.gz
identity: more progress and fixes
Diffstat (limited to 'cache')
-rw-r--r--cache/bug_excerpt.go2
-rw-r--r--cache/repo_cache.go70
2 files changed, 71 insertions, 1 deletions
diff --git a/cache/bug_excerpt.go b/cache/bug_excerpt.go
index 77c18175..f5844b64 100644
--- a/cache/bug_excerpt.go
+++ b/cache/bug_excerpt.go
@@ -20,7 +20,7 @@ type BugExcerpt struct {
EditUnixTime int64
Status bug.Status
- Author *identity.Identity
+ Author identity.Interface
Labels []bug.Label
CreateMetadata map[string]string
diff --git a/cache/repo_cache.go b/cache/repo_cache.go
index a149fd73..7d3e7d1d 100644
--- a/cache/repo_cache.go
+++ b/cache/repo_cache.go
@@ -30,6 +30,8 @@ type RepoCache struct {
excerpts map[string]*BugExcerpt
// bug loaded in memory
bugs map[string]*BugCache
+ // identities loaded in memory
+ identities map[string]*identity.Identity
}
func NewRepoCache(r repository.ClockedRepo) (*RepoCache, error) {
@@ -279,6 +281,7 @@ func (c *RepoCache) ResolveBugCreateMetadata(key string, value string) (*BugCach
return c.ResolveBug(matching[0])
}
+// QueryBugs return the id of all Bug matching the given Query
func (c *RepoCache) QueryBugs(query *Query) []string {
if query == nil {
return c.AllBugsIds()
@@ -525,3 +528,70 @@ func repoIsAvailable(repo repository.Repo) error {
return nil
}
+
+// ResolveIdentity retrieve an identity matching the exact given id
+func (c *RepoCache) ResolveIdentity(id string) (*identity.Identity, error) {
+ cached, ok := c.identities[id]
+ if ok {
+ return cached, nil
+ }
+
+ i, err := identity.Read(c.repo, id)
+ if err != nil {
+ return nil, err
+ }
+
+ c.identities[id] = i
+
+ return i, nil
+}
+
+// ResolveIdentityPrefix retrieve an Identity matching an id prefix. It fails if multiple
+// bugs match.
+// func (c *RepoCache) ResolveIdentityPrefix(prefix string) (*BugCache, error) {
+// // preallocate but empty
+// matching := make([]string, 0, 5)
+//
+// for id := range c.excerpts {
+// if strings.HasPrefix(id, prefix) {
+// matching = append(matching, id)
+// }
+// }
+//
+// if len(matching) > 1 {
+// return nil, bug.ErrMultipleMatch{Matching: matching}
+// }
+//
+// if len(matching) == 0 {
+// return nil, bug.ErrBugNotExist
+// }
+//
+// return c.ResolveBug(matching[0])
+// }
+
+// ResolveIdentityImmutableMetadata retrieve an Identity that has the exact given metadata on
+// one of it's version. If multiple version have the same key, the first defined take precedence.
+func (c *RepoCache) ResolveIdentityImmutableMetadata(key string, value string) (*BugCache, error) {
+ // // preallocate but empty
+ // matching := make([]string, 0, 5)
+ //
+ // for id, excerpt := range c.excerpts {
+ // if excerpt.CreateMetadata[key] == value {
+ // matching = append(matching, id)
+ // }
+ // }
+ //
+ // if len(matching) > 1 {
+ // return nil, bug.ErrMultipleMatch{Matching: matching}
+ // }
+ //
+ // if len(matching) == 0 {
+ // return nil, bug.ErrBugNotExist
+ // }
+ //
+ // return c.ResolveBug(matching[0])
+
+ // TODO
+
+ return nil, nil
+}