aboutsummaryrefslogtreecommitdiffstats
path: root/cache/repo_cache.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2020-03-14 16:47:38 +0100
committerMichael Muré <batolettre@gmail.com>2020-03-28 17:13:27 +0100
commit5e4dc87ffec7f87bbf3ebfcf256777ad773e8450 (patch)
tree04553cfb7ab8ea279c7415586ce1d0fe5c819996 /cache/repo_cache.go
parent58abc6b0a35b679ac0c34579ff1cb53c8fa71af4 (diff)
downloadgit-bug-5e4dc87ffec7f87bbf3ebfcf256777ad773e8450.tar.gz
cache: 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.go20
1 files changed, 14 insertions, 6 deletions
diff --git a/cache/repo_cache.go b/cache/repo_cache.go
index d859a966..6546b15e 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/ast"
"github.com/MichaelMure/git-bug/repository"
"github.com/MichaelMure/git-bug/util/git"
"github.com/MichaelMure/git-bug/util/process"
@@ -525,7 +526,7 @@ 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(query *ast.Query) []entity.Id {
c.muBug.RLock()
defer c.muBug.RUnlock()
@@ -533,10 +534,12 @@ func (c *RepoCache) QueryBugs(query *Query) []entity.Id {
return c.AllBugsIds()
}
+ matcher := compileMatcher(query.Filters)
+
var filtered []*BugExcerpt
for _, excerpt := range c.bugExcerpts {
- if query.Match(excerpt, c) {
+ if matcher.Match(excerpt, c) {
filtered = append(filtered, excerpt)
}
}
@@ -544,18 +547,23 @@ func (c *RepoCache) QueryBugs(query *Query) []entity.Id {
var sorter sort.Interface
switch query.OrderBy {
- case OrderById:
+ case ast.OrderById:
sorter = BugsById(filtered)
- case OrderByCreation:
+ case ast.OrderByCreation:
sorter = BugsByCreationTime(filtered)
- case OrderByEdit:
+ case ast.OrderByEdit:
sorter = BugsByEditTime(filtered)
default:
panic("missing sort type")
}
- if query.OrderDirection == OrderDescending {
+ switch query.OrderDirection {
+ case ast.OrderAscending:
+ // Nothing to do
+ case ast.OrderDescending:
sorter = sort.Reverse(sorter)
+ default:
+ panic("missing sort direction")
}
sort.Sort(sorter)