aboutsummaryrefslogtreecommitdiffstats
path: root/cache/repo_cache.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2020-03-28 17:17:13 +0100
committerGitHub <noreply@github.com>2020-03-28 17:17:13 +0100
commit390e66eb2b3a7088cdb8a44eeaf384fe691daf4a (patch)
tree05386ddf08d7e1c2947a6fc6cf2fbd44efa19eaf /cache/repo_cache.go
parent58abc6b0a35b679ac0c34579ff1cb53c8fa71af4 (diff)
parent314fcbb2293d869c33d6a76aedd148aedff6561d (diff)
downloadgit-bug-390e66eb2b3a7088cdb8a44eeaf384fe691daf4a.tar.gz
Merge pull request #355 from MichaelMure/query-parser-ast
replace the all-in-one query parser by a complete one with AST/lexer/parser
Diffstat (limited to 'cache/repo_cache.go')
-rw-r--r--cache/repo_cache.go24
1 files changed, 16 insertions, 8 deletions
diff --git a/cache/repo_cache.go b/cache/repo_cache.go
index d859a966..f2e1c7d0 100644
--- a/cache/repo_cache.go
+++ b/cache/repo_cache.go
@@ -18,6 +18,7 @@ import (
"github.com/MichaelMure/git-bug/bug"
"github.com/MichaelMure/git-bug/entity"
"github.com/MichaelMure/git-bug/identity"
+ "github.com/MichaelMure/git-bug/query"
"github.com/MichaelMure/git-bug/repository"
"github.com/MichaelMure/git-bug/util/git"
"github.com/MichaelMure/git-bug/util/process"
@@ -525,37 +526,44 @@ func (c *RepoCache) resolveBugMatcher(f func(*BugExcerpt) bool) (entity.Id, erro
}
// QueryBugs return the id of all Bug matching the given Query
-func (c *RepoCache) QueryBugs(query *Query) []entity.Id {
+func (c *RepoCache) QueryBugs(q *query.Query) []entity.Id {
c.muBug.RLock()
defer c.muBug.RUnlock()
- if query == nil {
+ if q == nil {
return c.AllBugsIds()
}
+ matcher := compileMatcher(q.Filters)
+
var filtered []*BugExcerpt
for _, excerpt := range c.bugExcerpts {
- if query.Match(excerpt, c) {
+ if matcher.Match(excerpt, c) {
filtered = append(filtered, excerpt)
}
}
var sorter sort.Interface
- switch query.OrderBy {
- case OrderById:
+ switch q.OrderBy {
+ case query.OrderById:
sorter = BugsById(filtered)
- case OrderByCreation:
+ case query.OrderByCreation:
sorter = BugsByCreationTime(filtered)
- case OrderByEdit:
+ case query.OrderByEdit:
sorter = BugsByEditTime(filtered)
default:
panic("missing sort type")
}
- if query.OrderDirection == OrderDescending {
+ switch q.OrderDirection {
+ case query.OrderAscending:
+ // Nothing to do
+ case query.OrderDescending:
sorter = sort.Reverse(sorter)
+ default:
+ panic("missing sort direction")
}
sort.Sort(sorter)