diff options
author | Michael Muré <batolettre@gmail.com> | 2020-01-24 00:30:13 +0100 |
---|---|---|
committer | Michael Muré <batolettre@gmail.com> | 2020-02-08 17:19:57 +0100 |
commit | 74e91144105790cc997c1d79a7f638e1e3a1f3f8 (patch) | |
tree | 33ef7b3cf547afc10b613e5d4de087ca0439232b /cache | |
parent | 8da522d97af3dcaca8a8424e3541705c69779d6f (diff) | |
download | git-bug-74e91144105790cc997c1d79a7f638e1e3a1f3f8.tar.gz |
more more wip
Diffstat (limited to 'cache')
-rw-r--r-- | cache/bug_excerpt.go | 18 | ||||
-rw-r--r-- | cache/filter.go | 3 | ||||
-rw-r--r-- | cache/identity_cache.go | 2 | ||||
-rw-r--r-- | cache/identity_excerpt.go | 17 | ||||
-rw-r--r-- | cache/query.go | 4 | ||||
-rw-r--r-- | cache/repo_cache.go | 31 |
6 files changed, 29 insertions, 46 deletions
diff --git a/cache/bug_excerpt.go b/cache/bug_excerpt.go index 36c7dcfe..10e522f9 100644 --- a/cache/bug_excerpt.go +++ b/cache/bug_excerpt.go @@ -2,7 +2,6 @@ package cache import ( "encoding/gob" - "fmt" "github.com/MichaelMure/git-bug/bug" "github.com/MichaelMure/git-bug/entity" @@ -43,21 +42,11 @@ type BugExcerpt struct { // identity.Bare data are directly embedded in the bug excerpt type LegacyAuthorExcerpt struct { - Name string - Login string + Name string } func (l LegacyAuthorExcerpt) DisplayName() string { - switch { - case l.Name == "" && l.Login != "": - return l.Login - case l.Name != "" && l.Login == "": - return l.Name - case l.Name != "" && l.Login != "": - return fmt.Sprintf("%s (%s)", l.Name, l.Login) - } - - panic("invalid person data") + return l.Name } func NewBugExcerpt(b bug.Interface, snap *bug.Snapshot) *BugExcerpt { @@ -95,8 +84,7 @@ func NewBugExcerpt(b bug.Interface, snap *bug.Snapshot) *BugExcerpt { e.AuthorId = snap.Author.Id() case *identity.Bare: e.LegacyAuthor = LegacyAuthorExcerpt{ - Login: snap.Author.Login(), - Name: snap.Author.Name(), + Name: snap.Author.Name(), } default: panic("unhandled identity type") diff --git a/cache/filter.go b/cache/filter.go index 27e92cf3..9b1de1d5 100644 --- a/cache/filter.go +++ b/cache/filter.go @@ -37,8 +37,7 @@ func AuthorFilter(query string) Filter { } // Legacy identity support - return strings.Contains(strings.ToLower(excerpt.LegacyAuthor.Name), query) || - strings.Contains(strings.ToLower(excerpt.LegacyAuthor.Login), query) + return strings.Contains(strings.ToLower(excerpt.LegacyAuthor.Name), query) } } diff --git a/cache/identity_cache.go b/cache/identity_cache.go index e2129f84..eb5ee183 100644 --- a/cache/identity_cache.go +++ b/cache/identity_cache.go @@ -21,7 +21,7 @@ func (i *IdentityCache) notifyUpdated() error { return i.repoCache.identityUpdated(i.Identity.Id()) } -func (i *IdentityCache) Mutate(f func(identity.IdentityMutator) identity.IdentityMutator) error { +func (i *IdentityCache) Mutate(f func(identity.Mutator) identity.Mutator) error { i.Identity.Mutate(f) return i.notifyUpdated() } diff --git a/cache/identity_excerpt.go b/cache/identity_excerpt.go index 18514e9a..06788aa5 100644 --- a/cache/identity_excerpt.go +++ b/cache/identity_excerpt.go @@ -2,7 +2,6 @@ package cache import ( "encoding/gob" - "fmt" "strings" "github.com/MichaelMure/git-bug/entity" @@ -21,7 +20,6 @@ type IdentityExcerpt struct { Id entity.Id Name string - Login string ImmutableMetadata map[string]string } @@ -29,7 +27,6 @@ func NewIdentityExcerpt(i *identity.Identity) *IdentityExcerpt { return &IdentityExcerpt{ Id: i.Id(), Name: i.Name(), - Login: i.Login(), ImmutableMetadata: i.ImmutableMetadata(), } } @@ -37,23 +34,13 @@ func NewIdentityExcerpt(i *identity.Identity) *IdentityExcerpt { // 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") + return i.Name } // Match matches a query with the identity name, login and ID prefixes func (i *IdentityExcerpt) Match(query string) bool { return i.Id.HasPrefix(query) || - strings.Contains(strings.ToLower(i.Name), query) || - strings.Contains(strings.ToLower(i.Login), query) + strings.Contains(strings.ToLower(i.Name), query) } /* diff --git a/cache/query.go b/cache/query.go index 633ef1c2..967c18d6 100644 --- a/cache/query.go +++ b/cache/query.go @@ -91,7 +91,7 @@ func ParseQuery(query string) (*Query, error) { sortingDone = true default: - return nil, fmt.Errorf("unknow qualifier name %s", qualifierName) + return nil, fmt.Errorf("unknown qualifier name %s", qualifierName) } } @@ -165,7 +165,7 @@ func (q *Query) parseSorting(query string) error { q.OrderDirection = OrderAscending default: - return fmt.Errorf("unknow sorting %s", query) + return fmt.Errorf("unknown sorting %s", query) } return nil diff --git a/cache/repo_cache.go b/cache/repo_cache.go index 99afeb41..18be9b5a 100644 --- a/cache/repo_cache.go +++ b/cache/repo_cache.go @@ -789,12 +789,6 @@ func (c *RepoCache) ResolveIdentityImmutableMetadata(key string, value string) ( }) } -func (c *RepoCache) ResolveIdentityLogin(login string) (*IdentityCache, error) { - return c.ResolveIdentityMatcher(func(excerpt *IdentityExcerpt) bool { - return excerpt.Login == login - }) -} - func (c *RepoCache) ResolveIdentityMatcher(f func(*IdentityExcerpt) bool) (*IdentityCache, error) { // preallocate but empty matching := make([]entity.Id, 0, 5) @@ -869,21 +863,36 @@ func (c *RepoCache) IsUserIdentitySet() (bool, error) { return identity.IsUserIdentitySet(c.repo) } +func (c *RepoCache) NewIdentityFromGitUser() (*IdentityCache, error) { + return c.NewIdentityFromGitUserRaw(nil) +} + +func (c *RepoCache) NewIdentityFromGitUserRaw(metadata map[string]string) (*IdentityCache, error) { + i, err := identity.NewFromGitUser(c.repo) + if err != nil { + return nil, err + } + return c.finishIdentity(i, metadata) +} + // NewIdentity create a new identity // The new identity is written in the repository (commit) func (c *RepoCache) NewIdentity(name string, email string) (*IdentityCache, error) { - return c.NewIdentityRaw(name, email, "", "", nil) + return c.NewIdentityRaw(name, email, "", nil) } // NewIdentityFull create a new identity // The new identity is written in the repository (commit) -func (c *RepoCache) NewIdentityFull(name string, email string, login string, avatarUrl string) (*IdentityCache, error) { - return c.NewIdentityRaw(name, email, login, avatarUrl, nil) +func (c *RepoCache) NewIdentityFull(name string, email string, avatarUrl string) (*IdentityCache, error) { + return c.NewIdentityRaw(name, email, avatarUrl, nil) } -func (c *RepoCache) NewIdentityRaw(name string, email string, login string, avatarUrl string, metadata map[string]string) (*IdentityCache, error) { - i := identity.NewIdentityFull(name, email, login, avatarUrl) +func (c *RepoCache) NewIdentityRaw(name string, email string, avatarUrl string, metadata map[string]string) (*IdentityCache, error) { + i := identity.NewIdentityFull(name, email, avatarUrl) + return c.finishIdentity(i, metadata) +} +func (c *RepoCache) finishIdentity(i *identity.Identity, metadata map[string]string) (*IdentityCache, error) { for key, value := range metadata { i.SetMetadata(key, value) } |