aboutsummaryrefslogtreecommitdiffstats
path: root/cache
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2019-02-24 14:17:52 +0100
committerMichael Muré <batolettre@gmail.com>2019-03-01 22:48:51 +0100
commit7a80d8f849861a6033cd0765e5d85a52b08a8854 (patch)
tree30a2b00bec3e871aa18ba75acac626f9e7e1f1b2 /cache
parent8bba6d1493fdf064ac9fede0a5098b1abe969052 (diff)
downloadgit-bug-7a80d8f849861a6033cd0765e5d85a52b08a8854.tar.gz
commands: add a super-fast "user ls" command
Diffstat (limited to 'cache')
-rw-r--r--cache/bug_excerpt.go4
-rw-r--r--cache/identity_excerpt.go26
-rw-r--r--cache/repo_cache.go12
3 files changed, 39 insertions, 3 deletions
diff --git a/cache/bug_excerpt.go b/cache/bug_excerpt.go
index 55518077..fd06e51b 100644
--- a/cache/bug_excerpt.go
+++ b/cache/bug_excerpt.go
@@ -68,6 +68,10 @@ func NewBugExcerpt(b bug.Interface, snap *bug.Snapshot) *BugExcerpt {
return e
}
+func (b *BugExcerpt) HumanId() string {
+ return bug.FormatHumanID(b.Id)
+}
+
/*
* Sorting
*/
diff --git a/cache/identity_excerpt.go b/cache/identity_excerpt.go
index 0539a76b..2a13bc60 100644
--- a/cache/identity_excerpt.go
+++ b/cache/identity_excerpt.go
@@ -2,10 +2,16 @@ package cache
import (
"encoding/gob"
+ "fmt"
"github.com/MichaelMure/git-bug/identity"
)
+// Package initialisation used to register the type for (de)serialization
+func init() {
+ gob.Register(IdentityExcerpt{})
+}
+
// IdentityExcerpt hold a subset of the identity values to be able to sort and
// filter identities efficiently without having to read and compile each raw
// identity.
@@ -26,9 +32,23 @@ func NewIdentityExcerpt(i *identity.Identity) *IdentityExcerpt {
}
}
-// Package initialisation used to register the type for (de)serialization
-func init() {
- gob.Register(IdentityExcerpt{})
+func (i *IdentityExcerpt) HumanId() string {
+ return identity.FormatHumanID(i.Id)
+}
+
+// DisplayName return a non-empty string to display, representing the
+// identity, based on the non-empty values.
+func (i *IdentityExcerpt) DisplayName() string {
+ switch {
+ case i.Name == "" && i.Login != "":
+ return i.Login
+ case i.Name != "" && i.Login == "":
+ return i.Name
+ case i.Name != "" && i.Login != "":
+ return fmt.Sprintf("%s (%s)", i.Name, i.Login)
+ }
+
+ panic("invalid person data")
}
/*
diff --git a/cache/repo_cache.go b/cache/repo_cache.go
index 78633a69..a50c745b 100644
--- a/cache/repo_cache.go
+++ b/cache/repo_cache.go
@@ -489,6 +489,12 @@ func (c *RepoCache) AllBugsIds() []string {
return result
}
+// AllBugExcerpt return all known bug excerpt.
+// This maps is read-only.
+func (c *RepoCache) AllBugExcerpt() map[string]*BugExcerpt {
+ return c.bugExcerpts
+}
+
// ValidLabels list valid labels
//
// Note: in the future, a proper label policy could be implemented where valid
@@ -765,6 +771,12 @@ func (c *RepoCache) AllIdentityIds() []string {
return result
}
+// AllIdentityExcerpt return all known identities excerpt.
+// This maps is read-only.
+func (c *RepoCache) AllIdentityExcerpt() map[string]*IdentityExcerpt {
+ return c.identitiesExcerpts
+}
+
func (c *RepoCache) SetUserIdentity(i *IdentityCache) error {
err := identity.SetUserIdentity(c.repo, i.Identity)
if err != nil {