Skip to content

Small refactoring #48

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions cmd/gitql/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,15 @@ func (c *CmdQuery) Execute(args []string) error {
return err
}

if err := c.executeQuery(); err != nil {
return err
}

return nil
return c.executeQuery()
}

func (c *CmdQuery) validate() error {
var err error
c.Path, err = findDotGitFolder(c.Path)
if err != nil {
return err
}

return nil
return err
}

func (c *CmdQuery) buildDatabase() error {
c.print("opening %q repository...\n", c.Path)

Expand Down
5 changes: 0 additions & 5 deletions git/commits.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package git

import (
"io"

"github.com/gitql/gitql/sql"

"gopkg.in/src-d/go-git.v4"
Expand Down Expand Up @@ -64,9 +62,6 @@ type commitIter struct {

func (i *commitIter) Next() (sql.Row, error) {
commit, err := i.i.Next()
if err == io.EOF {
return nil, io.EOF
}
if err != nil {
return nil, err
}
Expand Down
9 changes: 2 additions & 7 deletions sql/analyzer/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,13 @@ func (a *Analyzer) Analyze(n sql.Node) (sql.Node, error) {
for !reflect.DeepEqual(prev, cur) {
prev = cur
cur = a.analyzeOnce(n)
i += 1
i++
if i >= maxAnalysisIterations {
return cur, fmt.Errorf("exceeded max analysis iterations (%d)", maxAnalysisIterations)
}
}

err := a.validate(cur)
if err != nil {
return cur, err
}

return cur, nil
return cur, a.validate(cur)
}

func (a *Analyzer) analyzeOnce(n sql.Node) sql.Node {
Expand Down
40 changes: 20 additions & 20 deletions sql/expression/comparison_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,32 @@ const (
)

var comparisonCases = map[sql.Type]map[int][][]interface{}{
sql.String: map[int][][]interface{}{
testEqual: [][]interface{}{
[]interface{}{"foo", "foo"},
[]interface{}{"", ""},
sql.String: {
testEqual: {
{"foo", "foo"},
{"", ""},
},
testLess: [][]interface{}{
[]interface{}{"a", "b"},
[]interface{}{"", "1"},
testLess: {
{"a", "b"},
{"", "1"},
},
testGreater: [][]interface{}{
[]interface{}{"b", "a"},
[]interface{}{"1", ""},
testGreater: {
{"b", "a"},
{"1", ""},
},
},
sql.Integer: map[int][][]interface{}{
testEqual: [][]interface{}{
[]interface{}{int32(1), int32(1)},
[]interface{}{int32(0), int32(0)},
sql.Integer: {
testEqual: {
{int32(1), int32(1)},
{int32(0), int32(0)},
},
testLess: [][]interface{}{
[]interface{}{int32(-1), int32(0)},
[]interface{}{int32(1), int32(2)},
testLess: {
{int32(-1), int32(0)},
{int32(1), int32(2)},
},
testGreater: [][]interface{}{
[]interface{}{int32(2), int32(1)},
[]interface{}{int32(0), int32(-1)},
testGreater: {
{int32(2), int32(1)},
{int32(0), int32(-1)},
},
},
}
Expand Down