Skip to content

Commit 7489914

Browse files
committed
gitbase: fix squash_iterator tests and skip partition errors
Signed-off-by: Javi Fontan <[email protected]>
1 parent d5ee0e5 commit 7489914

File tree

2 files changed

+19
-31
lines changed

2 files changed

+19
-31
lines changed

partition.go

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import (
44
"io"
55

66
"github.com/src-d/go-borges"
7-
errors "gopkg.in/src-d/go-errors.v1"
87
"github.com/src-d/go-mysql-server/sql"
8+
errors "gopkg.in/src-d/go-errors.v1"
99
)
1010

1111
// partitioned is an embeddable helper that contains the methods for a table
@@ -49,10 +49,9 @@ func (p RepositoryPartition) Key() []byte {
4949
}
5050

5151
type repositoryPartitionIter struct {
52-
// repos []string
53-
// pos int
54-
repoIter borges.RepositoryIterator
55-
lib borges.Library
52+
repoIter borges.RepositoryIterator
53+
lib borges.Library
54+
skipErrors bool
5655
}
5756

5857
func newRepositoryPartitionIter(ctx *sql.Context) (sql.PartitionIter, error) {
@@ -67,32 +66,29 @@ func newRepositoryPartitionIter(ctx *sql.Context) (sql.PartitionIter, error) {
6766
}
6867

6968
return &repositoryPartitionIter{
70-
repoIter: it,
71-
lib: s.Pool.library,
69+
repoIter: it,
70+
lib: s.Pool.library,
71+
skipErrors: s.SkipGitErrors,
7272
}, nil
73-
74-
// return &repositoryPartitionIter{repos: s.Pool.idOrder}, nil
7573
}
7674

7775
func (i *repositoryPartitionIter) Next() (sql.Partition, error) {
78-
// if i.pos >= len(i.repos) {
79-
// return nil, io.EOF
80-
// }
81-
82-
// i.pos++
83-
// return RepositoryPartition(i.repos[i.pos-1]), nil
84-
85-
r, err := i.repoIter.Next()
86-
if err != nil {
87-
return nil, err
76+
var r borges.Repository
77+
var err error
78+
for {
79+
r, err = i.repoIter.Next()
80+
if err == nil {
81+
break
82+
}
83+
if err == io.EOF || !i.skipErrors {
84+
return nil, err
85+
}
8886
}
8987

90-
// br := borgesRepo(i.lib, r, cache.NewObjectLRU(64*cache.MiByte))
9188
return RepositoryPartition(r.ID().String()), nil
9289
}
9390

9491
func (i *repositoryPartitionIter) Close() error {
95-
// i.pos = len(i.repos)
9692
if i.repoIter != nil {
9793
i.repoIter.Close()
9894
}

squash_iterator_test.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,6 @@ func TestSquashContextCancelled(t *testing.T) {
5151
require.NoError(err)
5252

5353
for _, it := range iters {
54-
// repo, err := session.Pool.GetPos(0)
55-
// require.NoError(err)
56-
5754
iter, err := it.New(ctx, repo)
5855
require.NoError(err)
5956

@@ -789,7 +786,6 @@ func setupIterWithErrors(t *testing.T, badRepo bool, skipErrors bool) (*sql.Cont
789786
require.NoError(err)
790787
if ok {
791788
lib.AddPlain(pathToName(path), path, nil)
792-
// pool.AddGit(f.Worktree().Root())
793789
}
794790
}
795791

@@ -974,8 +970,6 @@ func TestRefsIterSiva(t *testing.T) {
974970
require.NoError(t, err)
975971

976972
path := filepath.Join(cwd, "_testdata", "05893125684f2d3943cd84a7ab2b75e53668fba1.siva")
977-
// pool := NewRepositoryPool(cache.DefaultMaxSize)
978-
// require.NoError(t, pool.AddSivaFile(path))
979973

980974
lib, pool, err := newMultiPool()
981975
require.NoError(t, err)
@@ -996,14 +990,12 @@ func TestRefsIterSiva(t *testing.T) {
996990

997991
expected := []sql.Row{
998992
{
999-
path,
1000-
// "refs/heads/HEAD/015da2f4-6d89-7ec8-5ac9-a38329ea875b",
993+
"015da2f4-6d89-7ec8-5ac9-a38329ea875b",
1001994
"HEAD",
1002995
"dbfab055c70379219cbcf422f05316fdf4e1aed3",
1003996
},
1004997
{
1005-
path,
1006-
// "refs/heads/master/015da2f4-6d89-7ec8-5ac9-a38329ea875b",
998+
"015da2f4-6d89-7ec8-5ac9-a38329ea875b",
1007999
"refs/heads/master",
10081000
"dbfab055c70379219cbcf422f05316fdf4e1aed3",
10091001
},

0 commit comments

Comments
 (0)