MCPcopy Index your code
hub / github.com/git-bug/git-bug / resolveMatcher

Method resolveMatcher

cache/subcache.go:424–446  ·  view source on GitHub ↗
(f func(ExcerptT) bool)

Source from the content-addressed store, hash-verified

422}
423
424func (sc *SubCache[EntityT, ExcerptT, CacheT]) resolveMatcher(f func(ExcerptT) bool) (entity.Id, error) {
425 sc.mu.RLock()
426 defer sc.mu.RUnlock()
427
428 // preallocate but empty
429 matching := make([]entity.Id, 0, 5)
430
431 for _, excerpt := range sc.excerpts {
432 if f(excerpt) {
433 matching = append(matching, excerpt.Id())
434 }
435 }
436
437 if len(matching) > 1 {
438 return entity.UnsetId, entity.NewErrMultipleMatch(sc.typename, matching)
439 }
440
441 if len(matching) == 0 {
442 return entity.UnsetId, entity.NewErrNotFound(sc.typename)
443 }
444
445 return matching[0], nil
446}
447
448func (sc *SubCache[EntityT, ExcerptT, CacheT]) add(e EntityT) (CacheT, error) {
449 sc.mu.Lock()

Callers 2

ResolveMatcherMethod · 0.95
ResolveExcerptMatcherMethod · 0.95

Calls 3

NewErrMultipleMatchFunction · 0.92
NewErrNotFoundFunction · 0.92
IdMethod · 0.65

Tested by

no test coverage detected