aboutsummaryrefslogtreecommitdiffstats
path: root/cache
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2022-08-23 15:01:36 +0200
committerGitHub <noreply@github.com>2022-08-23 15:01:36 +0200
commit5a70e8b3a2e0fe3d1a1dcd4c24bb6bf64633cb7f (patch)
treee5382a09a45098672b6d60397eac201617fdd6ec /cache
parent81fd7a5d8b6443e65c861f00a7387c0a3c926c66 (diff)
parent6ed4b8b7a1185ad278eb2e40b32e859f828233d9 (diff)
downloadgit-bug-5a70e8b3a2e0fe3d1a1dcd4c24bb6bf64633cb7f.tar.gz
Merge pull request #664 from MichaelMure/combined-id-rework
bug: have a type for combined ids, fix #653
Diffstat (limited to 'cache')
-rw-r--r--cache/bug_cache.go11
-rw-r--r--cache/repo_cache_bug.go14
2 files changed, 15 insertions, 10 deletions
diff --git a/cache/bug_cache.go b/cache/bug_cache.go
index e03b27ff..6caaeb11 100644
--- a/cache/bug_cache.go
+++ b/cache/bug_cache.go
@@ -209,7 +209,7 @@ func (c *BugCache) EditCreateCommentRaw(author *IdentityCache, unixTime int64, b
return op, c.notifyUpdated()
}
-func (c *BugCache) EditComment(target entity.Id, message string) (*bug.EditCommentOperation, error) {
+func (c *BugCache) EditComment(target entity.CombinedId, message string) (*bug.EditCommentOperation, error) {
author, err := c.repoCache.GetUserIdentity()
if err != nil {
return nil, err
@@ -218,9 +218,14 @@ func (c *BugCache) EditComment(target entity.Id, message string) (*bug.EditComme
return c.EditCommentRaw(author, time.Now().Unix(), target, message, nil)
}
-func (c *BugCache) EditCommentRaw(author *IdentityCache, unixTime int64, target entity.Id, message string, metadata map[string]string) (*bug.EditCommentOperation, error) {
+func (c *BugCache) EditCommentRaw(author *IdentityCache, unixTime int64, target entity.CombinedId, message string, metadata map[string]string) (*bug.EditCommentOperation, error) {
+ comment, err := c.Snapshot().SearchComment(target)
+ if err != nil {
+ return nil, err
+ }
+
c.mu.Lock()
- op, err := bug.EditComment(c.bug, author.Identity, unixTime, target, message, nil, metadata)
+ op, err := bug.EditComment(c.bug, author.Identity, unixTime, comment.TargetId(), message, nil, metadata)
c.mu.Unlock()
if err != nil {
return nil, err
diff --git a/cache/repo_cache_bug.go b/cache/repo_cache_bug.go
index 9843f9d9..4522f1bc 100644
--- a/cache/repo_cache_bug.go
+++ b/cache/repo_cache_bug.go
@@ -263,7 +263,7 @@ func (c *RepoCache) resolveBugMatcher(f func(*BugExcerpt) bool) (entity.Id, erro
// ResolveComment search for a Bug/Comment combination matching the merged
// bug/comment Id prefix. Returns the Bug containing the Comment and the Comment's
// Id.
-func (c *RepoCache) ResolveComment(prefix string) (*BugCache, entity.Id, error) {
+func (c *RepoCache) ResolveComment(prefix string) (*BugCache, entity.CombinedId, error) {
bugPrefix, _ := entity.SeparateIds(prefix)
bugCandidate := make([]entity.Id, 0, 5)
@@ -277,7 +277,7 @@ func (c *RepoCache) ResolveComment(prefix string) (*BugCache, entity.Id, error)
c.muBug.RUnlock()
matchingBugIds := make([]entity.Id, 0, 5)
- matchingCommentId := entity.UnsetId
+ matchingCommentId := entity.UnsetCombinedId
var matchingBug *BugCache
// search for matching comments
@@ -286,22 +286,22 @@ func (c *RepoCache) ResolveComment(prefix string) (*BugCache, entity.Id, error)
for _, bugId := range bugCandidate {
b, err := c.ResolveBug(bugId)
if err != nil {
- return nil, entity.UnsetId, err
+ return nil, entity.UnsetCombinedId, err
}
for _, comment := range b.Snapshot().Comments {
- if comment.Id().HasPrefix(prefix) {
+ if comment.CombinedId().HasPrefix(prefix) {
matchingBugIds = append(matchingBugIds, bugId)
matchingBug = b
- matchingCommentId = comment.Id()
+ matchingCommentId = comment.CombinedId()
}
}
}
if len(matchingBugIds) > 1 {
- return nil, entity.UnsetId, entity.NewErrMultipleMatch("bug/comment", matchingBugIds)
+ return nil, entity.UnsetCombinedId, entity.NewErrMultipleMatch("bug/comment", matchingBugIds)
} else if len(matchingBugIds) == 0 {
- return nil, entity.UnsetId, errors.New("comment doesn't exist")
+ return nil, entity.UnsetCombinedId, errors.New("comment doesn't exist")
}
return matchingBug, matchingCommentId, nil