Skip to content

Commit fb4f97c

Browse files
committed
gitbase: add support for siva files
Add support in RepositoryPool for handling siva files as repositories. Added a new `AddSivaDir` method to `RepositoryPool`, which adds all the siva files inside that directory (a siva file is considered to be any file whose extension is `.siva`) and the direct child directories to allow bucketing. Also some minor changes related to the RepositoryPool: - NewRepositoryFromPath returns now *Repository for convenience. - NewRepositoryPool returns now *RepositoryPool, as it always needs to be used with a pointer. - Fixed golint warning about returning an unexported type in an exported method, which may be annoying by replacing the type with `sql.RowIter`. Signed-off-by: Miguel Molina <[email protected]>
1 parent aa44b0a commit fb4f97c

15 files changed

+192
-50
lines changed
Binary file not shown.
Binary file not shown.
Binary file not shown.

_testdata/not-siva.txt

Whitespace-only changes.

cmd/gitbase/server.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ var enableUnstableSquash = os.Getenv("UNSTABLE_SQUASH_ENABLE") != ""
2424
type cmdServer struct {
2525
Verbose bool `short:"v" description:"Activates the verbose mode"`
2626

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

47-
var err error
48+
c.pool = gitbase.NewRepositoryPool()
49+
if err := c.pool.AddDir(c.Git); err != nil {
50+
return err
51+
}
4852

49-
pool := gitbase.NewRepositoryPool()
50-
c.pool = &pool
51-
err = c.pool.AddDir(c.Git)
52-
if err != nil {
53+
if err := c.pool.AddSivaDir(c.Siva); err != nil {
5354
return err
5455
}
5556

common_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func setup(t *testing.T) (ctx *sql.Context, path string, cleanup CleanupFunc) {
3030
require.NoError(fixtures.Clean())
3131
}
3232

33-
session := NewSession(&pool)
33+
session := NewSession(pool)
3434
ctx = sql.NewContext(context.TODO(), sql.WithSession(session))
3535

3636
return ctx, path, cleanup

integration_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ func TestIntegration(t *testing.T) {
139139
t.Run(tt.query, func(t *testing.T) {
140140
require := require.New(t)
141141

142-
session := gitbase.NewSession(&pool)
142+
session := gitbase.NewSession(pool)
143143
ctx := sql.NewContext(context.TODO(), sql.WithSession(session))
144144

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

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

250250
for _, q := range queries {
251251
t.Run(q, func(t *testing.T) {
252-
expected := queryResults(t, engine, &pool, q)
253-
result := queryResults(t, squashEngine, &pool, q)
252+
expected := queryResults(t, engine, pool, q)
253+
result := queryResults(t, squashEngine, pool, q)
254254
require.ElementsMatch(
255255
t,
256256
expected,
@@ -374,7 +374,7 @@ func benchmarkQuery(b *testing.B, query string) {
374374
pool := gitbase.NewRepositoryPool()
375375
_, err := pool.AddGit(path)
376376
require.NoError(b, err)
377-
session := gitbase.NewSession(&pool)
377+
session := gitbase.NewSession(pool)
378378
ctx := sql.NewContext(context.TODO(), sql.WithSession(session))
379379

380380
run := func(b *testing.B) {

internal/function/commit_has_blob_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func TestCommitHasBlob(t *testing.T) {
2727
pool.AddGit(f.Worktree().Root())
2828
}
2929

30-
session := gitbase.NewSession(&pool)
30+
session := gitbase.NewSession(pool)
3131
ctx := sql.NewContext(context.TODO(), sql.WithSession(session))
3232

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

75-
session := gitbase.NewSession(&pool)
75+
session := gitbase.NewSession(pool)
7676
ctx := sql.NewContext(context.TODO(), sql.WithSession(session))
7777

7878
rows := []sql.Row{

internal/function/commit_has_tree_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func TestCommitHasTree(t *testing.T) {
2727
pool.AddGit(f.Worktree().Root())
2828
}
2929

30-
session := gitbase.NewSession(&pool)
30+
session := gitbase.NewSession(pool)
3131
ctx := sql.NewContext(context.TODO(), sql.WithSession(session))
3232

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

76-
session := gitbase.NewSession(&pool)
76+
session := gitbase.NewSession(pool)
7777
ctx := sql.NewContext(context.TODO(), sql.WithSession(session))
7878

7979
rows := []sql.Row{

internal/function/history_idx_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func TestHistoryIdx(t *testing.T) {
2727
pool.AddGit(f.Worktree().Root())
2828
}
2929

30-
session := gitbase.NewSession(&pool)
30+
session := gitbase.NewSession(pool)
3131
ctx := sql.NewContext(context.TODO(), sql.WithSession(session))
3232

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

83-
session := gitbase.NewSession(&pool)
83+
session := gitbase.NewSession(pool)
8484
ctx := sql.NewContext(context.TODO(), sql.WithSession(session))
8585

8686
cases := []struct {

0 commit comments

Comments
 (0)