Skip to content

gitbase: add support for siva files #224

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

Merged
merged 2 commits into from
Apr 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
15 changes: 14 additions & 1 deletion Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Empty file added _testdata/not-siva.txt
Empty file.
13 changes: 7 additions & 6 deletions cmd/gitbase/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ var enableUnstableSquash = os.Getenv("UNSTABLE_SQUASH_ENABLE") != ""
type cmdServer struct {
Verbose bool `short:"v" description:"Activates the verbose mode"`

Git string `short:"g" long:"git" description:"Path where the git repositories are located, one per dir"`
Git string `short:"g" long:"git" description:"Path where the git repositories are located"`
Siva string `long:"siva" description:"Path where the siva repositories are located"`
Host string `short:"h" long:"host" default:"localhost" description:"Host where the server is going to listen"`
Port int `short:"p" long:"port" default:"3306" description:"Port where the server is going to listen"`
User string `short:"u" long:"user" default:"root" description:"User name used for connection"`
Expand All @@ -44,12 +45,12 @@ func (c *cmdServer) buildDatabase() error {
logrus.WithField("dir", c.Git).Debug("added folder containing git repositories")
}

var err error
c.pool = gitbase.NewRepositoryPool()
Copy link
Contributor

Choose a reason for hiding this comment

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

so, now you can have mixed repositories on the same execution, standard ones and siva ones?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup. I can restrict that if we want to only have one type

Copy link
Contributor

Choose a reason for hiding this comment

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

it's ok, LGTM!

if err := c.pool.AddDir(c.Git); err != nil {
return err
}

pool := gitbase.NewRepositoryPool()
c.pool = &pool
err = c.pool.AddDir(c.Git)
if err != nil {
if err := c.pool.AddSivaDir(c.Siva); err != nil {
return err
}

Expand Down
2 changes: 1 addition & 1 deletion common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func setup(t *testing.T) (ctx *sql.Context, path string, cleanup CleanupFunc) {
require.NoError(fixtures.Clean())
}

session := NewSession(&pool)
session := NewSession(pool)
ctx = sql.NewContext(context.TODO(), sql.WithSession(session))

return ctx, path, cleanup
Expand Down
10 changes: 5 additions & 5 deletions integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func TestIntegration(t *testing.T) {
t.Run(tt.query, func(t *testing.T) {
require := require.New(t)

session := gitbase.NewSession(&pool)
session := gitbase.NewSession(pool)
ctx := sql.NewContext(context.TODO(), sql.WithSession(session))

_, iter, err := engine.Query(ctx, tt.query)
Expand Down Expand Up @@ -173,7 +173,7 @@ func TestUastQueries(t *testing.T) {
engine.AddDatabase(gitbase.NewDatabase("foo"))
engine.Catalog.RegisterFunctions(function.Functions)

session := gitbase.NewSession(&pool)
session := gitbase.NewSession(pool)
ctx := sql.NewContext(context.TODO(), sql.WithSession(session))
_, iter, err := engine.Query(ctx, `
SELECT uast_xpath(uast(content, 'php'), '//*[@roleIdentifier]') as uast, name
Expand Down Expand Up @@ -249,8 +249,8 @@ func TestSquashCorrectness(t *testing.T) {

for _, q := range queries {
t.Run(q, func(t *testing.T) {
expected := queryResults(t, engine, &pool, q)
result := queryResults(t, squashEngine, &pool, q)
expected := queryResults(t, engine, pool, q)
result := queryResults(t, squashEngine, pool, q)
require.ElementsMatch(
t,
expected,
Expand Down Expand Up @@ -374,7 +374,7 @@ func benchmarkQuery(b *testing.B, query string) {
pool := gitbase.NewRepositoryPool()
_, err := pool.AddGit(path)
require.NoError(b, err)
session := gitbase.NewSession(&pool)
session := gitbase.NewSession(pool)
ctx := sql.NewContext(context.TODO(), sql.WithSession(session))

run := func(b *testing.B) {
Expand Down
4 changes: 2 additions & 2 deletions internal/function/commit_has_blob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestCommitHasBlob(t *testing.T) {
pool.AddGit(f.Worktree().Root())
}

session := gitbase.NewSession(&pool)
session := gitbase.NewSession(pool)
ctx := sql.NewContext(context.TODO(), sql.WithSession(session))

testCases := []struct {
Expand Down Expand Up @@ -72,7 +72,7 @@ func BenchmarkCommitHasBlob(b *testing.B) {
pool.AddGit(f.Worktree().Root())
}

session := gitbase.NewSession(&pool)
session := gitbase.NewSession(pool)
ctx := sql.NewContext(context.TODO(), sql.WithSession(session))

rows := []sql.Row{
Expand Down
4 changes: 2 additions & 2 deletions internal/function/commit_has_tree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestCommitHasTree(t *testing.T) {
pool.AddGit(f.Worktree().Root())
}

session := gitbase.NewSession(&pool)
session := gitbase.NewSession(pool)
ctx := sql.NewContext(context.TODO(), sql.WithSession(session))

testCases := []struct {
Expand Down Expand Up @@ -73,7 +73,7 @@ func BenchmarkCommitHasTree(b *testing.B) {
pool.AddGit(f.Worktree().Root())
}

session := gitbase.NewSession(&pool)
session := gitbase.NewSession(pool)
ctx := sql.NewContext(context.TODO(), sql.WithSession(session))

rows := []sql.Row{
Expand Down
4 changes: 2 additions & 2 deletions internal/function/history_idx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestHistoryIdx(t *testing.T) {
pool.AddGit(f.Worktree().Root())
}

session := gitbase.NewSession(&pool)
session := gitbase.NewSession(pool)
ctx := sql.NewContext(context.TODO(), sql.WithSession(session))

testCases := []struct {
Expand Down Expand Up @@ -80,7 +80,7 @@ func BenchmarkHistoryIdx(b *testing.B) {
pool.AddGit(f.Worktree().Root())
}

session := gitbase.NewSession(&pool)
session := gitbase.NewSession(pool)
ctx := sql.NewContext(context.TODO(), sql.WithSession(session))

cases := []struct {
Expand Down
2 changes: 1 addition & 1 deletion internal/function/uast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func setup(t *testing.T) (*sql.Context, func()) {
pool.AddGit(f.Worktree().Root())
}

session := gitbase.NewSession(&pool)
session := gitbase.NewSession(pool)
ctx := sql.NewContext(context.TODO(), sql.WithSession(session))

return ctx, func() {
Expand Down
2 changes: 1 addition & 1 deletion iterator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ func setupIter(t *testing.T) (*sql.Context, func()) {
pool.AddGit(f.Worktree().Root())
}

session := NewSession(&pool)
session := NewSession(pool)
ctx := sql.NewContext(context.TODO(), sql.WithSession(session))
cleanup := func() {
require.NoError(t, fixtures.Clean())
Expand Down
4 changes: 2 additions & 2 deletions repositories_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ func TestRepositoriesTable_RowIter(t *testing.T) {
pool := NewRepositoryPool()

for _, id := range repoIDs {
pool.Add(id, "")
pool.Add(id, "", gitRepo)
}

session := NewSession(&pool)
session := NewSession(pool)
ctx := sql.NewContext(context.TODO(), sql.WithSession(session))

db := NewDatabase(RepositoriesTableName)
Expand Down
Loading