Skip to content
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

Don't skip repos for remotes table with more than 1 URL #789

Merged
merged 3 commits into from
Apr 10, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
37 changes: 36 additions & 1 deletion common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"testing"

"github.com/stretchr/testify/require"
"gopkg.in/src-d/go-billy-siva.v4"
sivafs "gopkg.in/src-d/go-billy-siva.v4"
billy "gopkg.in/src-d/go-billy.v4"
"gopkg.in/src-d/go-billy.v4/osfs"
fixtures "gopkg.in/src-d/go-git-fixtures.v3"
Expand Down Expand Up @@ -243,6 +243,41 @@ func testTableIndexIterClosed(t *testing.T, table sql.IndexableTable) {
require.True(closed.Check())
}

func testTableIterators(t *testing.T, table sql.IndexableTable, columns []string) {
t.Helper()

require := require.New(t)
ctx, closed := setupSivaCloseRepos(t, "_testdata")

rows, _ := tableToRows(ctx, table)
expected := len(rows)

iter, err := table.IndexKeyValues(ctx, columns)
require.NoError(err)
actual := 0
for {
_, i, err := iter.Next()
if err != nil {
require.Equal(io.EOF, err)
break
}
for {
_, _, err := i.Next()
if err != nil {
require.Equal(io.EOF, err)
break
}
actual++
}

i.Close()
}
iter.Close()
require.True(closed.Check())

require.EqualValues(expected, actual)
}

func testTableIterClosed(t *testing.T, table sql.IndexableTable) {
t.Helper()

Expand Down
50 changes: 29 additions & 21 deletions remotes.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,28 +144,25 @@ type remotesRowIter struct {
}

func (i *remotesRowIter) Next() (sql.Row, error) {
if i.remotePos >= len(i.remotes) {
return nil, io.EOF
}

remote := i.remotes[i.remotePos]
config := remote.Config()

if i.urlPos >= len(config.URLs) || i.urlPos >= len(config.Fetch) {
i.remotePos++
for {
if i.remotePos >= len(i.remotes) {
return nil, io.EOF
}

remote = i.remotes[i.remotePos]
config = remote.Config()
i.urlPos = 0
}
remote := i.remotes[i.remotePos]
config := remote.Config()

if i.urlPos >= len(config.URLs) && i.urlPos >= len(config.Fetch) {
i.remotePos++
i.urlPos = 0
continue
}

row := remoteToRow(i.repo.ID, config, i.urlPos)
i.urlPos++
row := remoteToRow(i.repo.ID, config, i.urlPos)
i.urlPos++

return row, nil
return row, nil
}
}

func (i *remotesRowIter) Close() error {
Expand All @@ -177,13 +174,23 @@ func (i *remotesRowIter) Close() error {
}

func remoteToRow(repoID string, config *config.RemoteConfig, pos int) sql.Row {
url := ""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If no URL, it should be nil, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, URLs are strings

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, I meant at SQL table level. If there is no value, we should return NULL instead of empty string.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, done.

if pos < len(config.URLs) {
url = config.URLs[pos]
}

fetch := ""
if pos < len(config.Fetch) {
fetch = config.Fetch[pos].String()
}

return sql.NewRow(
repoID,
config.Name,
config.URLs[pos],
config.URLs[pos],
config.Fetch[pos].String(),
config.Fetch[pos].String(),
url,
url,
fetch,
fetch,
)
}

Expand Down Expand Up @@ -256,7 +263,8 @@ func (i *remotesKeyValueIter) Next() ([]interface{}, []byte, error) {
}

cfg := i.remotes[i.pos].Config()
if i.urlPos >= len(cfg.URLs) {
if i.urlPos >= len(cfg.URLs) && i.urlPos >= len(cfg.Fetch) {
i.urlPos = 0
i.pos++
continue
}
Expand Down
5 changes: 3 additions & 2 deletions remotes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ func TestRemotesIndexIterClosed(t *testing.T) {
testTableIndexIterClosed(t, new(remotesTable))
}

func TestRemotesIterClosed(t *testing.T) {
testTableIterClosed(t, new(remotesTable))
func TestRemotesIterators(t *testing.T) {
// columns names just for debugging
testTableIterators(t, new(remotesTable), []string{"remote_name", "remote_push_url"})
}