aboutsummaryrefslogtreecommitdiffstats
path: root/cache
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2022-08-01 17:16:45 +0200
committerGitHub <noreply@github.com>2022-08-01 17:16:45 +0200
commitcd52872475f1b39f3fb6546606c1e78afb6c08e3 (patch)
tree9f04b1e1ee362e210e74aaa324d950058ed14bf2 /cache
parent2ade8fb1d570ddcb4aedc9386af46d208b129daa (diff)
parent56966fec5562c3a0e23340d0fbe754626c3beb64 (diff)
downloadgit-bug-cd52872475f1b39f3fb6546606c1e78afb6c08e3.tar.gz
Merge pull request #835 from MichaelMure/op-base
entity/dag: proper base operation for simplified implementation
Diffstat (limited to 'cache')
-rw-r--r--cache/bug_cache.go105
-rw-r--r--cache/repo_cache.go6
-rw-r--r--cache/repo_cache_bug.go6
-rw-r--r--cache/repo_cache_common.go4
4 files changed, 28 insertions, 93 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()
}
diff --git a/cache/repo_cache.go b/cache/repo_cache.go
index 14d5f3db..53948331 100644
--- a/cache/repo_cache.go
+++ b/cache/repo_cache.go
@@ -209,9 +209,9 @@ func (c *RepoCache) buildCache() error {
}
snap := b.Bug.Compile()
- c.bugExcerpts[b.Bug.Id()] = NewBugExcerpt(b.Bug, &snap)
+ c.bugExcerpts[b.Bug.Id()] = NewBugExcerpt(b.Bug, snap)
- if err := c.addBugToSearchIndex(&snap); err != nil {
+ if err := c.addBugToSearchIndex(snap); err != nil {
return err
}
}
@@ -222,7 +222,7 @@ func (c *RepoCache) buildCache() error {
}
// repoIsAvailable check is the given repository is locked by a Cache.
-// Note: this is a smart function that will cleanup the lock file if the
+// Note: this is a smart function that will clean the lock file if the
// corresponding process is not there anymore.
// If no error is returned, the repo is free to edit.
func repoIsAvailable(repo repository.RepoStorage) error {
diff --git a/cache/repo_cache_bug.go b/cache/repo_cache_bug.go
index f8bf5a2f..6af9fc04 100644
--- a/cache/repo_cache_bug.go
+++ b/cache/repo_cache_bug.go
@@ -461,15 +461,11 @@ func (c *RepoCache) NewBugWithFiles(title string, message string, files []reposi
// well as metadata for the Create operation.
// The new bug is written in the repository (commit)
func (c *RepoCache) NewBugRaw(author *IdentityCache, unixTime int64, title string, message string, files []repository.Hash, metadata map[string]string) (*BugCache, *bug.CreateOperation, error) {
- b, op, err := bug.CreateWithFiles(author.Identity, unixTime, title, message, files)
+ b, op, err := bug.Create(author.Identity, unixTime, title, message, files, metadata)
if err != nil {
return nil, nil, err
}
- for key, value := range metadata {
- op.SetMetadata(key, value)
- }
-
err = b.Commit(c.repo)
if err != nil {
return nil, nil, err
diff --git a/cache/repo_cache_common.go b/cache/repo_cache_common.go
index e23315f9..66797e80 100644
--- a/cache/repo_cache_common.go
+++ b/cache/repo_cache_common.go
@@ -36,7 +36,7 @@ func (c *RepoCache) Keyring() repository.Keyring {
return c.repo.Keyring()
}
-// GetUserName returns the name the the user has used to configure git
+// GetUserName returns the name the user has used to configure git
func (c *RepoCache) GetUserName() (string, error) {
return c.repo.GetUserName()
}
@@ -131,7 +131,7 @@ func (c *RepoCache) MergeAll(remote string) <-chan entity.MergeResult {
b := result.Entity.(*bug.Bug)
snap := b.Compile()
c.muBug.Lock()
- c.bugExcerpts[result.Id] = NewBugExcerpt(b, &snap)
+ c.bugExcerpts[result.Id] = NewBugExcerpt(b, snap)
c.muBug.Unlock()
}
}