git-bug/cache/identity_cache.go

46 lines
951 B
Go
Raw Normal View History

package cache
import (
"github.com/MichaelMure/git-bug/identity"
)
var _ identity.Interface = &IdentityCache{}
2019-02-18 16:11:37 +03:00
// IdentityCache is a wrapper around an Identity for caching.
type IdentityCache struct {
*identity.Identity
repoCache *RepoCache
}
func NewIdentityCache(repoCache *RepoCache, id *identity.Identity) *IdentityCache {
return &IdentityCache{
Identity: id,
repoCache: repoCache,
}
}
2019-02-18 16:11:37 +03:00
func (i *IdentityCache) notifyUpdated() error {
return i.repoCache.identityUpdated(i.Identity.Id())
}
2020-01-24 02:30:13 +03:00
func (i *IdentityCache) Mutate(f func(identity.Mutator) identity.Mutator) error {
2020-01-15 00:01:44 +03:00
i.Identity.Mutate(f)
2019-02-19 01:16:47 +03:00
return i.notifyUpdated()
}
func (i *IdentityCache) Commit() error {
2019-02-19 01:16:47 +03:00
err := i.Identity.Commit(i.repoCache.repo)
if err != nil {
return err
}
return i.notifyUpdated()
}
func (i *IdentityCache) CommitAsNeeded() error {
2019-02-19 01:16:47 +03:00
err := i.Identity.CommitAsNeeded(i.repoCache.repo)
if err != nil {
return err
}
return i.notifyUpdated()
}