aboutsummaryrefslogtreecommitdiffstats
path: root/cache
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2022-07-31 14:38:32 +0200
committerMichael Muré <batolettre@gmail.com>2022-07-31 14:38:32 +0200
commitd179b8b7ec7815ccac73e00f35f5cfbdc4ddbe2e (patch)
treed3faa7217cb287c7b20f2769f5c5808373aca63b /cache
parent3d454d9dc8ba2409046c0938618a70864e6eb8ef (diff)
downloadgit-bug-d179b8b7ec7815ccac73e00f35f5cfbdc4ddbe2e.tar.gz
bug: fix an issue where Id would be used, then changed due to metadata
Diffstat (limited to 'cache')
-rw-r--r--cache/bug_cache.go100
-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, 25 insertions, 91 deletions
diff --git a/cache/bug_cache.go b/cache/bug_cache.go
index 390db37c..7503fc37 100644
--- a/cache/bug_cache.go
+++ b/cache/bug_cache.go
@@ -34,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 {
@@ -85,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()
}
@@ -111,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) {
@@ -142,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) {
@@ -172,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()
}
@@ -197,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()
}
@@ -222,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()
}
@@ -249,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()
}
@@ -274,17 +220,11 @@ 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()
}
@@ -300,12 +240,10 @@ func (c *BugCache) SetMetadata(target entity.Id, newMetadata map[string]string)
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()
}
}