From 45b04351d8d02e53b3401b0ee23f7cbe750b63cd Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Mon, 3 May 2021 11:45:15 +0200 Subject: bug: have a type for combined ids, fix https://github.com/MichaelMure/git-bug/issues/653 --- cache/bug_cache.go | 11 ++++++++--- cache/repo_cache_bug.go | 14 +++++++------- 2 files changed, 15 insertions(+), 10 deletions(-) (limited to 'cache') 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..226c4c13 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.TargetId().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 -- cgit From 6ed4b8b7a1185ad278eb2e40b32e859f828233d9 Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Tue, 23 Aug 2022 14:48:49 +0200 Subject: webui: adapt to CombinedId --- cache/repo_cache_bug.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cache') diff --git a/cache/repo_cache_bug.go b/cache/repo_cache_bug.go index 226c4c13..4522f1bc 100644 --- a/cache/repo_cache_bug.go +++ b/cache/repo_cache_bug.go @@ -290,7 +290,7 @@ func (c *RepoCache) ResolveComment(prefix string) (*BugCache, entity.CombinedId, } for _, comment := range b.Snapshot().Comments { - if comment.TargetId().HasPrefix(prefix) { + if comment.CombinedId().HasPrefix(prefix) { matchingBugIds = append(matchingBugIds, bugId) matchingBug = b matchingCommentId = comment.CombinedId() -- cgit