Skip to content

Commit

Permalink
fix errors pointed out by staticcheck
Browse files Browse the repository at this point in the history
Signed-off-by: Miguel Molina <[email protected]>
  • Loading branch information
erizocosmico committed Jan 9, 2019
1 parent c6796b7 commit 56872d0
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 172 deletions.
3 changes: 2 additions & 1 deletion cmd/gitbase/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ var (
func main() {
parser := flags.NewNamedParser(name, flags.Default)
parser.UnknownOptionHandler = func(option string, arg flags.SplitArgument, args []string) ([]string, error) {
if "g" != option {
if option != "g" {
return nil, fmt.Errorf("unknown flag `%s'", option)
}

if len(args) == 0 {
return nil, fmt.Errorf("unknown flag `%s'", option)
}
Expand Down
2 changes: 0 additions & 2 deletions commit_files.go
Original file line number Diff line number Diff line change
Expand Up @@ -512,8 +512,6 @@ func (i *commitFilesKeyValueIter) Close() error {
type commitFilesIndexIter struct {
index sql.IndexValueIter
decoder *objectDecoder

file *object.File // holds the last obtained key
}

func newCommitFilesIndexIter(
Expand Down
56 changes: 27 additions & 29 deletions commits.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,40 +346,38 @@ func newCommitsKeyValueIter(
}

func (i *commitsKeyValueIter) Next() ([]interface{}, []byte, error) {
for {
commit, err := i.commits.Next()
if err != nil {
return nil, nil, err
}

offset, packfile, err := i.idx.find(commit.Hash)
if err != nil {
return nil, nil, err
}
commit, err := i.commits.Next()
if err != nil {
return nil, nil, err
}

var hash string
if offset < 0 {
hash = commit.Hash.String()
}
offset, packfile, err := i.idx.find(commit.Hash)
if err != nil {
return nil, nil, err
}

key, err := encodeIndexKey(&packOffsetIndexKey{
Repository: i.repo.ID,
Packfile: packfile.String(),
Offset: offset,
Hash: hash,
})
if err != nil {
return nil, nil, err
}
var hash string
if offset < 0 {
hash = commit.Hash.String()
}

row := commitToRow(i.repo.ID, commit)
values, err := rowIndexValues(row, i.columns, CommitsSchema)
if err != nil {
return nil, nil, err
}
key, err := encodeIndexKey(&packOffsetIndexKey{
Repository: i.repo.ID,
Packfile: packfile.String(),
Offset: offset,
Hash: hash,
})
if err != nil {
return nil, nil, err
}

return values, key, nil
row := commitToRow(i.repo.ID, commit)
values, err := rowIndexValues(row, i.columns, CommitsSchema)
if err != nil {
return nil, nil, err
}

return values, key, nil
}

func (i *commitsKeyValueIter) Close() error {
Expand Down
24 changes: 4 additions & 20 deletions filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,23 +66,6 @@ func (s selectors) textValues(key string) ([]string, error) {
return result, nil
}

// filtersToExpression concatenates all filters and turns them into an
// expression using the AND expression.
func filtersToExpression(filters []sql.Expression) sql.Expression {
switch len(filters) {
case 0:
return nil
case 1:
return filters[0]
default:
exp := expression.NewAnd(filters[0], filters[1])
for _, f := range filters[2:] {
exp = expression.NewAnd(exp, f)
}
return exp
}
}

// canHandleEquals returns whether the given equals expression can be handled
// as a selector. For that to happen one of the sides must be a GetField expr
// that exists in the given schema and the other must be a literal.
Expand Down Expand Up @@ -246,21 +229,22 @@ func classifyFilters(
// check all unfolded exprs can be handled, if not we have to
// resort to treating them as conditions
valid := true
Loop:
for _, e := range exprs {
switch e := e.(type) {
case *expression.Equals:
if !canHandleEquals(schema, table, e) {
valid = false
break
break Loop
}
case *expression.In:
if !canHandleIn(schema, table, e) {
valid = false
break
break Loop
}
default:
valid = false
break
break Loop
}
}

Expand Down
28 changes: 0 additions & 28 deletions index.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,34 +101,6 @@ type rowKeyMapper interface {
fromRow(sql.Row) ([]byte, error)
}

type rowKeyValueIter struct {
mapper rowKeyMapper
iter sql.RowIter
columns []string
schema sql.Schema
}

func (i *rowKeyValueIter) Next() ([]interface{}, []byte, error) {
row, err := i.iter.Next()
if err != nil {
return nil, nil, err
}

key, err := i.mapper.fromRow(row)
if err != nil {
return nil, nil, err
}

values, err := rowIndexValues(row, i.columns, i.schema)
if err != nil {
return nil, nil, err
}

return values, key, nil
}

func (i *rowKeyValueIter) Close() error { return i.iter.Close() }

var (
errRowKeyMapperRowLength = errors.NewKind("row should have %d columns, has: %d")
errRowKeyMapperColType = errors.NewKind("row column %d should have type %T, has: %T")
Expand Down
12 changes: 0 additions & 12 deletions integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"gopkg.in/src-d/go-mysql-server.v0/auth"
"gopkg.in/src-d/go-mysql-server.v0/sql"
"gopkg.in/src-d/go-mysql-server.v0/sql/analyzer"
"gopkg.in/src-d/go-mysql-server.v0/sql/expression"
sqlfunction "gopkg.in/src-d/go-mysql-server.v0/sql/expression/function"
"gopkg.in/src-d/go-mysql-server.v0/sql/index/pilosa"
)
Expand Down Expand Up @@ -751,17 +750,6 @@ func TestIndexes(t *testing.T) {
}
}

func col(t testing.TB, schema sql.Schema, name string) sql.Expression {
for i, col := range schema {
if col.Name == name {
return expression.NewGetFieldWithTable(i, col.Type, col.Source, col.Name, col.Nullable)
}
}

t.Fatalf("unknown column %s in schema", name)
return nil
}

type indexData struct {
id string
table string
Expand Down
56 changes: 4 additions & 52 deletions internal/rule/squashjoins.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func SquashJoins(
return n, nil
}

span, ctx := ctx.Span("gitbase.SquashJoins")
span, _ := ctx.Span("gitbase.SquashJoins")
defer span.Finish()

a.Log("squashing joins, node of type %T", n)
Expand Down Expand Up @@ -123,10 +123,6 @@ func squashProjects(parent, child *plan.Project) (sql.Node, bool) {
return plan.NewProject(projections, child.Child), true
}

func referenceSameColumn(parent, child *expression.GetField) bool {
return parent.Name() == child.Name() && parent.Table() == child.Table()
}

func squashJoin(join *plan.InnerJoin) (sql.Node, error) {
if !isJoinSquashable(join) {
return join, nil
Expand Down Expand Up @@ -675,6 +671,9 @@ func buildSquashedTable(
filters,
append(it.Schema(), gitbase.TreeEntriesSchema...),
)
if err != nil {
return nil, err
}

iter = gitbase.NewTreeTreeEntriesIter(it, f, false)
case nil:
Expand Down Expand Up @@ -1545,53 +1544,6 @@ func isCol(table, name string) validator {
}
}

func isGte(left, right validator) validator {
return func(e sql.Expression) bool {
switch e := e.(type) {
case *expression.GreaterThanOrEqual:
return left(e.Left()) && right(e.Right())
case *expression.LessThanOrEqual:
return left(e.Right()) && right(e.Left())
default:
return false
}
}
}

func isNum(n int64) validator {
return func(e sql.Expression) bool {
lit, ok := e.(*expression.Literal)
if !ok {
return false
}

result, err := lit.Eval(nil, nil)
if err != nil {
return false
}

num, ok := result.(int64)
if !ok {
return false
}

return num == n
}
}

func containsField(e sql.Expression, table, name string) bool {
var found bool
expression.Inspect(e, func(e sql.Expression) bool {
gf, ok := e.(*expression.GetField)
if ok && gf.Table() == table && gf.Name() == name {
found = true
return false
}
return true
})
return found
}

func fixFieldIndexes(e sql.Expression, schema sql.Schema) (sql.Expression, error) {
if e == nil {
return nil, nil
Expand Down
8 changes: 0 additions & 8 deletions internal/rule/squashjoins_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2754,14 +2754,6 @@ func lit(v interface{}) sql.Expression {
return expression.NewLiteral(v, sql.Int64)
}

func gte(left, right sql.Expression) sql.Expression {
return expression.NewGreaterThanOrEqual(left, right)
}

func lte(left, right sql.Expression) sql.Expression {
return expression.NewLessThanOrEqual(left, right)
}

func and(exprs ...sql.Expression) sql.Expression {
return expression.JoinAnd(exprs...)
}
Expand Down
4 changes: 0 additions & 4 deletions packfiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ import (
"gopkg.in/src-d/go-git.v4/plumbing/format/packfile"
)

type packRepository struct {
packs map[plumbing.Hash]idxfile.Index
}

func repositoryPackfiles(fs billy.Filesystem) (*dotgit.DotGit, []plumbing.Hash, error) {
fs, err := findDotGit(fs)
if err != nil {
Expand Down
2 changes: 0 additions & 2 deletions repository_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ import (
)

var (
errInvalidRepoKind = errors.NewKind("the repository is not: %s")
errRepoAlreadyRegistered = errors.NewKind("the repository is already registered: %s")
errRepoCannotOpen = errors.NewKind("the repository could not be opened: %s")

gitStorerOptions = filesystem.Options{
ExclusiveAccess: true,
Expand Down
12 changes: 0 additions & 12 deletions squash_iterator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -974,18 +974,6 @@ func TestRefsIterSiva(t *testing.T) {
})
}

type lookup struct {
values sql.IndexValueIter
}

func (l lookup) Values() (sql.IndexValueIter, error) {
return l.values, nil
}

func (l lookup) Indexes() []string {
return []string{"test_idx"}
}

func newSquashTable(iter ChainableIter) sql.Table {
return NewSquashedTable(iter, nil, nil, nil)
}
2 changes: 0 additions & 2 deletions tools/rev-upgrade/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ func main() {
if err != nil {
log.Println(err)
w.Reset(&git.ResetOptions{Mode: git.MixedReset})
} else {
// let commit manually
}
}()

Expand Down

0 comments on commit 56872d0

Please sign in to comment.