Skip to content

Commit d7bcd70

Browse files
authored
Merge pull request #184 from erizocosmico/feature/print-tree
gitquery: add String methods to all nodes
2 parents ffb1156 + 81589b4 commit d7bcd70

14 files changed

+94
-21
lines changed

blobs.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ func newBlobsTable(pool *RepositoryPool) sql.Table {
4141
return &blobsTable{pool: pool}
4242
}
4343

44+
func (blobsTable) String() string {
45+
return printTable(blobsTableName, blobsSchema)
46+
}
47+
4448
func (blobsTable) Resolved() bool {
4549
return true
4650
}

commits.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ func newCommitsTable(pool *RepositoryPool) sql.Table {
3131
return &commitsTable{pool: pool}
3232
}
3333

34+
func (commitsTable) String() string {
35+
return printTable(commitsTableName, commitsSchema)
36+
}
37+
3438
func (commitsTable) Resolved() bool {
3539
return true
3640
}

filters.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,13 @@ func fixFieldIndexes(schema sql.Schema, exp sql.Expression) (sql.Expression, err
105105
// as a selector. For that to happen one of the sides must be a GetField expr
106106
// that exists in the given schema and the other must be a literal.
107107
func canHandleEquals(schema sql.Schema, tableName string, eq *expression.Equals) bool {
108-
switch left := eq.Left.(type) {
108+
switch left := eq.Left().(type) {
109109
case *expression.GetField:
110-
if _, ok := eq.Right.(*expression.Literal); ok && left.Table() == tableName {
110+
if _, ok := eq.Right().(*expression.Literal); ok && left.Table() == tableName {
111111
return schema.Contains(left.Name())
112112
}
113113
case *expression.Literal:
114-
if right, ok := eq.Right.(*expression.GetField); ok && right.Table() == tableName {
114+
if right, ok := eq.Right().(*expression.GetField); ok && right.Table() == tableName {
115115
return schema.Contains(right.Name())
116116
}
117117
}
@@ -121,9 +121,9 @@ func canHandleEquals(schema sql.Schema, tableName string, eq *expression.Equals)
121121
// getEqualityValues returns the field and value of the literal in the
122122
// given equality expression.
123123
func getEqualityValues(eq *expression.Equals) (string, interface{}, error) {
124-
switch left := eq.Left.(type) {
124+
switch left := eq.Left().(type) {
125125
case *expression.GetField:
126-
right, err := eq.Right.Eval(nil, nil)
126+
right, err := eq.Right().Eval(nil, nil)
127127
if err != nil {
128128
return "", nil, err
129129
}
@@ -133,7 +133,7 @@ func getEqualityValues(eq *expression.Equals) (string, interface{}, error) {
133133
if err != nil {
134134
return "", nil, err
135135
}
136-
return eq.Right.(*expression.GetField).Name(), l, nil
136+
return eq.Right().(*expression.GetField).Name(), l, nil
137137
}
138138
return "", "", nil
139139
}

internal/function/commit_has_blob.go

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

33
import (
4+
"fmt"
45
"io"
56

67
"github.com/src-d/gitquery"
@@ -134,11 +135,6 @@ func hashInTree(hash plumbing.Hash, tree *object.Tree) (bool, error) {
134135
return contained, nil
135136
}
136137

137-
// Name implements the Expression interface.
138-
func (CommitHasBlob) Name() string {
139-
return "commit_has_blob"
140-
}
141-
142138
// IsNullable implements the Expression interface.
143139
func (f CommitHasBlob) IsNullable() bool {
144140
return f.commitHash.IsNullable() || f.blob.IsNullable()
@@ -163,3 +159,7 @@ func (f CommitHasBlob) TransformUp(fn func(sql.Expression) (sql.Expression, erro
163159

164160
return fn(NewCommitHasBlob(commitHash, blob))
165161
}
162+
163+
func (f CommitHasBlob) String() string {
164+
return fmt.Sprintf("commit_has_blob(%s, %s)", f.commitHash, f.blob)
165+
}

internal/function/commit_has_tree.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package function
22

33
import (
4+
"fmt"
45
"io"
56

67
"gopkg.in/src-d/go-git.v4/plumbing/filemode"
@@ -27,8 +28,9 @@ func NewCommitHasTree(commit, tree sql.Expression) sql.Expression {
2728
}}
2829
}
2930

30-
// Name implements the Expression interface.
31-
func (CommitHasTree) Name() string { return "commit_has_tree" }
31+
func (f CommitHasTree) String() string {
32+
return fmt.Sprintf("commit_has_tree(%s, %s)", f.Left, f.Right)
33+
}
3234

3335
// Type implements the Expression interface.
3436
func (CommitHasTree) Type() sql.Type { return sql.Boolean }

internal/function/history_idx.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package function
22

33
import (
4+
"fmt"
45
"io"
56

67
"github.com/src-d/gitquery"
@@ -21,8 +22,9 @@ func NewHistoryIdx(start, target sql.Expression) sql.Expression {
2122
return &HistoryIdx{expression.BinaryExpression{Left: start, Right: target}}
2223
}
2324

24-
// Name implements the Expression interface.
25-
func (HistoryIdx) Name() string { return "history_idx" }
25+
func (f HistoryIdx) String() string {
26+
return fmt.Sprintf("history_idx(%s, %s)", f.Left, f.Right)
27+
}
2628

2729
// Eval implements the Expression interface.
2830
func (f *HistoryIdx) Eval(session sql.Session, row sql.Row) (interface{}, error) {

internal/function/is_remote.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package function
22

33
import (
4+
"fmt"
45
"reflect"
56

67
"gopkg.in/src-d/go-git.v4/plumbing"
@@ -37,9 +38,8 @@ func (f *IsRemote) Eval(session sql.Session, row sql.Row) (interface{}, error) {
3738
return plumbing.ReferenceName(name).IsRemote(), nil
3839
}
3940

40-
// Name implements the Expression interface.
41-
func (IsRemote) Name() string {
42-
return "is_remote"
41+
func (f IsRemote) String() string {
42+
return fmt.Sprintf("is_remote(%s)", f.Child)
4343
}
4444

4545
// TransformUp implements the Expression interface.

internal/function/is_tag.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package function
22

33
import (
4+
"fmt"
45
"reflect"
56

67
"gopkg.in/src-d/go-git.v4/plumbing"
@@ -37,9 +38,8 @@ func (f *IsTag) Eval(session sql.Session, row sql.Row) (interface{}, error) {
3738
return plumbing.ReferenceName(name).IsTag(), nil
3839
}
3940

40-
// Name implements the Expression interface.
41-
func (IsTag) Name() string {
42-
return "is_tag"
41+
func (f IsTag) String() string {
42+
return fmt.Sprintf("is_tag(%s)", f.Child)
4343
}
4444

4545
// TransformUp implements the Expression interface.

references.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ func newReferencesTable(pool *RepositoryPool) sql.Table {
2525
return &referencesTable{pool: pool}
2626
}
2727

28+
func (r referencesTable) String() string {
29+
return printTable(referencesTableName, refsSchema)
30+
}
31+
2832
func (referencesTable) Resolved() bool {
2933
return true
3034
}

remotes.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ func (remotesTable) Schema() sql.Schema {
3939
return remotesSchema
4040
}
4141

42+
func (r remotesTable) String() string {
43+
return printTable(remotesTableName, remotesSchema)
44+
}
45+
4246
func (r *remotesTable) TransformUp(f func(sql.Node) (sql.Node, error)) (sql.Node, error) {
4347
return f(r)
4448
}

0 commit comments

Comments
 (0)