aboutsummaryrefslogtreecommitdiffstats
path: root/cache/bug_cache.go
diff options
context:
space:
mode:
Diffstat (limited to 'cache/bug_cache.go')
-rw-r--r--cache/bug_cache.go105
1 files changed, 22 insertions, 83 deletions
diff --git a/cache/bug_cache.go b/cache/bug_cache.go
index 0e4611da..7503fc37 100644
--- a/cache/bug_cache.go
+++ b/cache/bug_cache.go
@@ -7,6 +7,7 @@ import (
"github.com/MichaelMure/git-bug/bug"
"github.com/MichaelMure/git-bug/entity"
+ "github.com/MichaelMure/git-bug/entity/dag"
"github.com/MichaelMure/git-bug/repository"
)
@@ -33,7 +34,7 @@ func NewBugCache(repoCache *RepoCache, b *bug.Bug) *BugCache {
func (c *BugCache) Snapshot() *bug.Snapshot {
c.mu.RLock()
defer c.mu.RUnlock()
- return c.bug.Snapshot()
+ return c.bug.Compile()
}
func (c *BugCache) Id() entity.Id {
@@ -84,18 +85,11 @@ func (c *BugCache) AddCommentWithFiles(message string, files []repository.Hash)
func (c *BugCache) AddCommentRaw(author *IdentityCache, unixTime int64, message string, files []repository.Hash, metadata map[string]string) (*bug.AddCommentOperation, error) {
c.mu.Lock()
- op, err := bug.AddCommentWithFiles(c.bug, author.Identity, unixTime, message, files)
+ op, err := bug.AddComment(c.bug, author, unixTime, message, files, metadata)
+ c.mu.Unlock()
if err != nil {
- c.mu.Unlock()
return nil, err
}
-
- for key, value := range metadata {
- op.SetMetadata(key, value)
- }
-
- c.mu.Unlock()
-
return op, c.notifyUpdated()
}
@@ -110,24 +104,12 @@ func (c *BugCache) ChangeLabels(added []string, removed []string) ([]bug.LabelCh
func (c *BugCache) ChangeLabelsRaw(author *IdentityCache, unixTime int64, added []string, removed []string, metadata map[string]string) ([]bug.LabelChangeResult, *bug.LabelChangeOperation, error) {
c.mu.Lock()
- changes, op, err := bug.ChangeLabels(c.bug, author.Identity, unixTime, added, removed)
- if err != nil {
- c.mu.Unlock()
- return changes, nil, err
- }
-
- for key, value := range metadata {
- op.SetMetadata(key, value)
- }
-
+ changes, op, err := bug.ChangeLabels(c.bug, author.Identity, unixTime, added, removed, metadata)
c.mu.Unlock()
-
- err = c.notifyUpdated()
if err != nil {
- return nil, nil, err
+ return changes, nil, err
}
-
- return changes, op, nil
+ return changes, op, c.notifyUpdated()
}
func (c *BugCache) ForceChangeLabels(added []string, removed []string) (*bug.LabelChangeOperation, error) {
@@ -141,23 +123,12 @@ func (c *BugCache) ForceChangeLabels(added []string, removed []string) (*bug.Lab
func (c *BugCache) ForceChangeLabelsRaw(author *IdentityCache, unixTime int64, added []string, removed []string, metadata map[string]string) (*bug.LabelChangeOperation, error) {
c.mu.Lock()
- op, err := bug.ForceChangeLabels(c.bug, author.Identity, unixTime, added, removed)
- if err != nil {
- c.mu.Unlock()
- return nil, err
- }
-
- for key, value := range metadata {
- op.SetMetadata(key, value)
- }
-
+ op, err := bug.ForceChangeLabels(c.bug, author.Identity, unixTime, added, removed, metadata)
c.mu.Unlock()
- err = c.notifyUpdated()
if err != nil {
return nil, err
}
-
- return op, nil
+ return op, c.notifyUpdated()
}
func (c *BugCache) Open() (*bug.SetStatusOperation, error) {
@@ -171,17 +142,11 @@ func (c *BugCache) Open() (*bug.SetStatusOperation, error) {
func (c *BugCache) OpenRaw(author *IdentityCache, unixTime int64, metadata map[string]string) (*bug.SetStatusOperation, error) {
c.mu.Lock()
- op, err := bug.Open(c.bug, author.Identity, unixTime)
+ op, err := bug.Open(c.bug, author.Identity, unixTime, metadata)
+ c.mu.Unlock()
if err != nil {
- c.mu.Unlock()
return nil, err
}
-
- for key, value := range metadata {
- op.SetMetadata(key, value)
- }
-
- c.mu.Unlock()
return op, c.notifyUpdated()
}
@@ -196,17 +161,11 @@ func (c *BugCache) Close() (*bug.SetStatusOperation, error) {
func (c *BugCache) CloseRaw(author *IdentityCache, unixTime int64, metadata map[string]string) (*bug.SetStatusOperation, error) {
c.mu.Lock()
- op, err := bug.Close(c.bug, author.Identity, unixTime)
+ op, err := bug.Close(c.bug, author.Identity, unixTime, metadata)
+ c.mu.Unlock()
if err != nil {
- c.mu.Unlock()
return nil, err
}
-
- for key, value := range metadata {
- op.SetMetadata(key, value)
- }
-
- c.mu.Unlock()
return op, c.notifyUpdated()
}
@@ -221,17 +180,11 @@ func (c *BugCache) SetTitle(title string) (*bug.SetTitleOperation, error) {
func (c *BugCache) SetTitleRaw(author *IdentityCache, unixTime int64, title string, metadata map[string]string) (*bug.SetTitleOperation, error) {
c.mu.Lock()
- op, err := bug.SetTitle(c.bug, author.Identity, unixTime, title)
+ op, err := bug.SetTitle(c.bug, author.Identity, unixTime, title, metadata)
+ c.mu.Unlock()
if err != nil {
- c.mu.Unlock()
return nil, err
}
-
- for key, value := range metadata {
- op.SetMetadata(key, value)
- }
-
- c.mu.Unlock()
return op, c.notifyUpdated()
}
@@ -248,17 +201,11 @@ func (c *BugCache) EditCreateComment(body string) (*bug.EditCommentOperation, er
// EditCreateCommentRaw is a convenience function to edit the body of a bug (the first comment)
func (c *BugCache) EditCreateCommentRaw(author *IdentityCache, unixTime int64, body string, metadata map[string]string) (*bug.EditCommentOperation, error) {
c.mu.Lock()
- op, err := bug.EditCreateComment(c.bug, author.Identity, unixTime, body)
+ op, err := bug.EditCreateComment(c.bug, author.Identity, unixTime, body, nil, metadata)
+ c.mu.Unlock()
if err != nil {
- c.mu.Unlock()
return nil, err
}
-
- for key, value := range metadata {
- op.SetMetadata(key, value)
- }
-
- c.mu.Unlock()
return op, c.notifyUpdated()
}
@@ -273,21 +220,15 @@ func (c *BugCache) EditComment(target entity.Id, message string) (*bug.EditComme
func (c *BugCache) EditCommentRaw(author *IdentityCache, unixTime int64, target entity.Id, message string, metadata map[string]string) (*bug.EditCommentOperation, error) {
c.mu.Lock()
- op, err := bug.EditComment(c.bug, author.Identity, unixTime, target, message)
+ op, err := bug.EditComment(c.bug, author.Identity, unixTime, target, message, nil, metadata)
+ c.mu.Unlock()
if err != nil {
- c.mu.Unlock()
return nil, err
}
-
- for key, value := range metadata {
- op.SetMetadata(key, value)
- }
-
- c.mu.Unlock()
return op, c.notifyUpdated()
}
-func (c *BugCache) SetMetadata(target entity.Id, newMetadata map[string]string) (*bug.SetMetadataOperation, error) {
+func (c *BugCache) SetMetadata(target entity.Id, newMetadata map[string]string) (*dag.SetMetadataOperation[*bug.Snapshot], error) {
author, err := c.repoCache.GetUserIdentity()
if err != nil {
return nil, err
@@ -296,15 +237,13 @@ func (c *BugCache) SetMetadata(target entity.Id, newMetadata map[string]string)
return c.SetMetadataRaw(author, time.Now().Unix(), target, newMetadata)
}
-func (c *BugCache) SetMetadataRaw(author *IdentityCache, unixTime int64, target entity.Id, newMetadata map[string]string) (*bug.SetMetadataOperation, error) {
+func (c *BugCache) SetMetadataRaw(author *IdentityCache, unixTime int64, target entity.Id, newMetadata map[string]string) (*dag.SetMetadataOperation[*bug.Snapshot], error) {
c.mu.Lock()
op, err := bug.SetMetadata(c.bug, author.Identity, unixTime, target, newMetadata)
+ c.mu.Unlock()
if err != nil {
- c.mu.Unlock()
return nil, err
}
-
- c.mu.Unlock()
return op, c.notifyUpdated()
}