diff options
author | Michael Muré <batolettre@gmail.com> | 2020-03-14 16:47:38 +0100 |
---|---|---|
committer | Michael Muré <batolettre@gmail.com> | 2020-03-28 17:13:27 +0100 |
commit | 5e4dc87ffec7f87bbf3ebfcf256777ad773e8450 (patch) | |
tree | 04553cfb7ab8ea279c7415586ce1d0fe5c819996 /cache/repo_cache.go | |
parent | 58abc6b0a35b679ac0c34579ff1cb53c8fa71af4 (diff) | |
download | git-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.go | 20 |
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) |