Skip to content

Commit 6899dec

Browse files
ferhatelmassmola
authored andcommitted
Small refactoring (#48)
1 parent 4e15e80 commit 6899dec

File tree

4 files changed

+25
-42
lines changed

4 files changed

+25
-42
lines changed

cmd/gitql/query.go

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,15 @@ func (c *CmdQuery) Execute(args []string) error {
3636
return err
3737
}
3838

39-
if err := c.executeQuery(); err != nil {
40-
return err
41-
}
42-
43-
return nil
39+
return c.executeQuery()
4440
}
4541

4642
func (c *CmdQuery) validate() error {
4743
var err error
4844
c.Path, err = findDotGitFolder(c.Path)
49-
if err != nil {
50-
return err
51-
}
52-
53-
return nil
45+
return err
5446
}
47+
5548
func (c *CmdQuery) buildDatabase() error {
5649
c.print("opening %q repository...\n", c.Path)
5750

git/commits.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package git
22

33
import (
4-
"io"
5-
64
"github.com/gitql/gitql/sql"
75

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

6563
func (i *commitIter) Next() (sql.Row, error) {
6664
commit, err := i.i.Next()
67-
if err == io.EOF {
68-
return nil, io.EOF
69-
}
7065
if err != nil {
7166
return nil, err
7267
}

sql/analyzer/analyzer.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,13 @@ func (a *Analyzer) Analyze(n sql.Node) (sql.Node, error) {
3535
for !reflect.DeepEqual(prev, cur) {
3636
prev = cur
3737
cur = a.analyzeOnce(n)
38-
i += 1
38+
i++
3939
if i >= maxAnalysisIterations {
4040
return cur, fmt.Errorf("exceeded max analysis iterations (%d)", maxAnalysisIterations)
4141
}
4242
}
4343

44-
err := a.validate(cur)
45-
if err != nil {
46-
return cur, err
47-
}
48-
49-
return cur, nil
44+
return cur, a.validate(cur)
5045
}
5146

5247
func (a *Analyzer) analyzeOnce(n sql.Node) sql.Node {

sql/expression/comparison_test.go

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,32 @@ const (
1515
)
1616

1717
var comparisonCases = map[sql.Type]map[int][][]interface{}{
18-
sql.String: map[int][][]interface{}{
19-
testEqual: [][]interface{}{
20-
[]interface{}{"foo", "foo"},
21-
[]interface{}{"", ""},
18+
sql.String: {
19+
testEqual: {
20+
{"foo", "foo"},
21+
{"", ""},
2222
},
23-
testLess: [][]interface{}{
24-
[]interface{}{"a", "b"},
25-
[]interface{}{"", "1"},
23+
testLess: {
24+
{"a", "b"},
25+
{"", "1"},
2626
},
27-
testGreater: [][]interface{}{
28-
[]interface{}{"b", "a"},
29-
[]interface{}{"1", ""},
27+
testGreater: {
28+
{"b", "a"},
29+
{"1", ""},
3030
},
3131
},
32-
sql.Integer: map[int][][]interface{}{
33-
testEqual: [][]interface{}{
34-
[]interface{}{int32(1), int32(1)},
35-
[]interface{}{int32(0), int32(0)},
32+
sql.Integer: {
33+
testEqual: {
34+
{int32(1), int32(1)},
35+
{int32(0), int32(0)},
3636
},
37-
testLess: [][]interface{}{
38-
[]interface{}{int32(-1), int32(0)},
39-
[]interface{}{int32(1), int32(2)},
37+
testLess: {
38+
{int32(-1), int32(0)},
39+
{int32(1), int32(2)},
4040
},
41-
testGreater: [][]interface{}{
42-
[]interface{}{int32(2), int32(1)},
43-
[]interface{}{int32(0), int32(-1)},
41+
testGreater: {
42+
{int32(2), int32(1)},
43+
{int32(0), int32(-1)},
4444
},
4545
},
4646
}

0 commit comments

Comments
 (0)