Skip to content

Commit 429c946

Browse files
committed
gitbase: close repositories in squash table
Signed-off-by: Javi Fontan <[email protected]>
1 parent 7fcde1e commit 429c946

File tree

3 files changed

+64
-2
lines changed

3 files changed

+64
-2
lines changed

ref_commits.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,8 @@ func (i *refCommitsRowIter) next() (sql.Row, error) {
263263
if i.refs == nil {
264264
i.refs, err = i.repo.References()
265265
if err != nil {
266+
i.repo.Close()
267+
266268
if i.skipGitErrors {
267269
return nil, io.EOF
268270
}
@@ -275,6 +277,8 @@ func (i *refCommitsRowIter) next() (sql.Row, error) {
275277
if i.skipGitErrors {
276278
continue
277279
}
280+
281+
i.repo.Close()
278282
return nil, err
279283
}
280284
}
@@ -286,13 +290,15 @@ func (i *refCommitsRowIter) next() (sql.Row, error) {
286290
ref, err = i.refs.Next()
287291
if err != nil {
288292
if err == io.EOF {
293+
i.repo.Close()
289294
return nil, io.EOF
290295
}
291296

292297
if i.skipGitErrors {
293298
continue
294299
}
295300

301+
i.repo.Close()
296302
return nil, err
297303
}
298304

@@ -315,6 +321,7 @@ func (i *refCommitsRowIter) next() (sql.Row, error) {
315321
continue
316322
}
317323

324+
i.repo.Close()
318325
return nil, err
319326
}
320327

@@ -332,6 +339,7 @@ func (i *refCommitsRowIter) next() (sql.Row, error) {
332339
continue
333340
}
334341

342+
i.repo.Close()
335343
return nil, err
336344
}
337345

@@ -389,6 +397,7 @@ type stackFrame struct {
389397
func (i *indexedCommitIter) Next() (*object.Commit, int, error) {
390398
for {
391399
if len(i.stack) == 0 {
400+
i.repo.Close()
392401
return nil, -1, io.EOF
393402
}
394403

@@ -410,6 +419,7 @@ func (i *indexedCommitIter) Next() (*object.Commit, int, error) {
410419
continue
411420
}
412421

422+
i.repo.Close()
413423
return nil, -1, err
414424
}
415425

squash.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,12 @@ func (i *squashRowIter) Next() (sql.Row, error) {
213213
row, err := i.iter.Next()
214214
if err != nil {
215215
if err == io.EOF {
216+
i.iter.Close()
216217
i.iter = nil
217218
continue
218219
}
219220

221+
i.iter.Close()
220222
return nil, err
221223
}
222224

squash_iterator.go

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,8 @@ func NewRemoteRefsIter(
782782
func (i *squashRemoteRefsIter) Repository() *Repository { return i.remotes.Repository() }
783783
func (i *squashRemoteRefsIter) Ref() *Ref { return i.ref }
784784
func (i *squashRemoteRefsIter) Close() error {
785+
i.Repository().Close()
786+
785787
if i.refs != nil {
786788
i.refs.Close()
787789
}
@@ -934,6 +936,8 @@ func (i *squashRefRefCommitsIter) Close() error {
934936
if i.refs != nil {
935937
i.refs.Close()
936938
}
939+
940+
i.Repository().Close()
937941
return nil
938942
}
939943
func (i *squashRefRefCommitsIter) New(ctx *sql.Context, repo *Repository) (ChainableIter, error) {
@@ -1165,6 +1169,8 @@ func (i *squashRefCommitsIndexIter) Advance() error {
11651169

11661170
repoID := i.row[0]
11671171
if i.repo == nil || repoID != i.repo.ID {
1172+
i.repo.Close()
1173+
11681174
i.repo, err = i.pool.GetRepo(i.row[0].(string))
11691175
if err != nil {
11701176
if i.skipGitErrors {
@@ -1204,6 +1210,7 @@ func (i *squashRefCommitsIndexIter) Schema() sql.Schema {
12041210
return RefCommitsSchema
12051211
}
12061212
func (i *squashRefCommitsIndexIter) Close() error {
1213+
i.repo.Close()
12071214
return i.iter.Close()
12081215
}
12091216

@@ -1226,6 +1233,8 @@ func (i *squashRefCommitCommitsIter) Close() error {
12261233
if i.refCommits != nil {
12271234
i.refCommits.Close()
12281235
}
1236+
1237+
i.Repository().Close()
12291238
return nil
12301239
}
12311240
func (i *squashRefCommitCommitsIter) New(ctx *sql.Context, repo *Repository) (ChainableIter, error) {
@@ -1296,6 +1305,8 @@ func (i *squashCommitsIter) Close() error {
12961305
if i.commits != nil {
12971306
i.commits.Close()
12981307
}
1308+
1309+
i.repo.Close()
12991310
return nil
13001311
}
13011312
func (i *squashCommitsIter) New(ctx *sql.Context, repo *Repository) (ChainableIter, error) {
@@ -1432,6 +1443,8 @@ func (i *squashCommitsIndexIter) Advance() error {
14321443
}
14331444

14341445
if i.repo == nil || i.repo.ID != i.iter.repoID {
1446+
i.repo.Close()
1447+
14351448
i.repo, err = i.pool.GetRepo(i.iter.repoID)
14361449
if err != nil {
14371450
if i.skipGitErrors {
@@ -1464,6 +1477,7 @@ func (i *squashCommitsIndexIter) Schema() sql.Schema {
14641477
return CommitsSchema
14651478
}
14661479
func (i *squashCommitsIndexIter) Close() error {
1480+
i.repo.Close()
14671481
return i.iter.Close()
14681482
}
14691483

@@ -1490,9 +1504,12 @@ func (i *squashRepoCommitsIter) Close() error {
14901504
i.commits.Close()
14911505
}
14921506

1507+
i.Repository().Close()
1508+
14931509
if i.repos != nil {
14941510
return i.repos.Close()
14951511
}
1512+
14961513
return nil
14971514
}
14981515
func (i *squashRepoCommitsIter) New(ctx *sql.Context, repo *Repository) (ChainableIter, error) {
@@ -1517,6 +1534,8 @@ func (i *squashRepoCommitsIter) Row() sql.Row { return i.row }
15171534
func (i *squashRepoCommitsIter) Advance() error {
15181535
for {
15191536
if i.commits == nil {
1537+
i.Repository().Close()
1538+
15201539
err := i.repos.Advance()
15211540
if err != nil {
15221541
return err
@@ -1594,6 +1613,8 @@ func NewRefHEADCommitsIter(
15941613
func (i *squashRefHeadCommitsIter) Repository() *Repository { return i.refs.Repository() }
15951614
func (i *squashRefHeadCommitsIter) Commit() *object.Commit { return i.commit }
15961615
func (i *squashRefHeadCommitsIter) Close() error {
1616+
i.Repository().Close()
1617+
15971618
if i.refs != nil {
15981619
return i.refs.Close()
15991620
}
@@ -1786,6 +1807,7 @@ func (i *squashCommitTreesIndexIter) Schema() sql.Schema {
17861807
return CommitTreesSchema
17871808
}
17881809
func (i *squashCommitTreesIndexIter) Close() error {
1810+
i.repo.Close()
17891811
return i.iter.Close()
17901812
}
17911813

@@ -1933,6 +1955,8 @@ func (i *squashRepoTreeEntriesIter) Close() error {
19331955
i.trees.Close()
19341956
}
19351957

1958+
i.Repository().Close()
1959+
19361960
if i.repos != nil {
19371961
return i.repos.Close()
19381962
}
@@ -1961,6 +1985,8 @@ func (i *squashRepoTreeEntriesIter) Row() sql.Row { return i.row }
19611985
func (i *squashRepoTreeEntriesIter) Advance() error {
19621986
for {
19631987
if i.trees == nil {
1988+
i.Repository().Close()
1989+
19641990
err := i.repos.Advance()
19651991
if err != nil {
19661992
return err
@@ -2059,6 +2085,8 @@ func NewCommitMainTreeIter(
20592085
func (i *squashCommitMainTreeIter) Repository() *Repository { return i.commits.Repository() }
20602086
func (i *squashCommitMainTreeIter) Tree() *object.Tree { return i.tree }
20612087
func (i *squashCommitMainTreeIter) Close() error {
2088+
i.Repository().Close()
2089+
20622090
if i.commits != nil {
20632091
return i.commits.Close()
20642092
}
@@ -2251,6 +2279,8 @@ func NewAllTreeEntriesIter(filters sql.Expression) TreeEntriesIter {
22512279
func (i *squashTreeEntriesIter) Repository() *Repository { return i.repo }
22522280
func (i *squashTreeEntriesIter) TreeEntry() *TreeEntry { return i.entry }
22532281
func (i *squashTreeEntriesIter) Close() error {
2282+
i.Repository().Close()
2283+
22542284
if i.trees != nil {
22552285
i.trees.Close()
22562286
}
@@ -2420,6 +2450,7 @@ func (i *squashTreeEntriesIndexIter) Schema() sql.Schema {
24202450
return TreeEntriesSchema
24212451
}
24222452
func (i *squashTreeEntriesIndexIter) Close() error {
2453+
i.Repository().Close()
24232454
return i.iter.Close()
24242455
}
24252456

@@ -2451,6 +2482,8 @@ func NewTreeTreeEntriesIter(
24512482
func (i *squashTreeTreeEntriesIter) Repository() *Repository { return i.trees.Repository() }
24522483
func (i *squashTreeTreeEntriesIter) TreeEntry() *TreeEntry { return i.entry }
24532484
func (i *squashTreeTreeEntriesIter) Close() error {
2485+
i.Repository().Close()
2486+
24542487
if i.trees != nil {
24552488
return i.trees.Close()
24562489
}
@@ -2620,6 +2653,7 @@ func (i *squashCommitBlobsIndexIter) Schema() sql.Schema {
26202653
return CommitBlobsSchema
26212654
}
26222655
func (i *squashCommitBlobsIndexIter) Close() error {
2656+
i.Repository().Close()
26232657
return i.iter.Close()
26242658
}
26252659

@@ -2657,6 +2691,8 @@ func (i *squashCommitBlobsIter) Close() error {
26572691
i.files.Close()
26582692
}
26592693

2694+
i.Repository().Close()
2695+
26602696
if i.commits != nil {
26612697
return i.commits.Close()
26622698
}
@@ -2787,6 +2823,8 @@ func (i *squashRepoBlobsIter) Close() error {
27872823
i.blobs.Close()
27882824
}
27892825

2826+
i.Repository().Close()
2827+
27902828
if i.repos != nil {
27912829
return i.repos.Close()
27922830
}
@@ -2810,6 +2848,8 @@ func (i *squashRepoBlobsIter) Row() sql.Row { return i.row }
28102848
func (i *squashRepoBlobsIter) Advance() error {
28112849
for {
28122850
if i.blobs == nil {
2851+
i.repos.Repository().Close()
2852+
28132853
err := i.repos.Advance()
28142854
if err != nil {
28152855
return err
@@ -3169,6 +3209,7 @@ func (i *squashCommitFilesIter) Close() error {
31693209
i.files.Close()
31703210
}
31713211

3212+
i.Repository().Close()
31723213
return i.commits.Close()
31733214
}
31743215
func (i *squashCommitFilesIter) Schema() sql.Schema {
@@ -3229,6 +3270,8 @@ func (i *squashIndexCommitFilesIter) Advance() error {
32293270
i.file = commitFile.File
32303271

32313272
if i.repo == nil || i.repo.ID != commitFile.Repository {
3273+
i.repo.Close()
3274+
32323275
i.repo, err = i.pool.GetRepo(commitFile.Repository)
32333276
if err != nil {
32343277
if i.skipGitErrors {
@@ -3272,7 +3315,11 @@ func (i *squashIndexCommitFilesIter) File() *object.File { return i.file }
32723315
func (i *squashIndexCommitFilesIter) TreeHash() plumbing.Hash { return i.treeHash }
32733316
func (i *squashIndexCommitFilesIter) Row() sql.Row { return i.row }
32743317
func (i *squashIndexCommitFilesIter) Schema() sql.Schema { return CommitFilesSchema }
3275-
func (i *squashIndexCommitFilesIter) Close() error { return i.iter.Close() }
3318+
3319+
func (i *squashIndexCommitFilesIter) Close() error {
3320+
i.repo.Close()
3321+
return i.iter.Close()
3322+
}
32763323

32773324
type squashCommitFileFilesIter struct {
32783325
files FilesIter
@@ -3345,7 +3392,10 @@ func (i *squashCommitFileFilesIter) Row() sql.Row { return i.row }
33453392
func (i *squashCommitFileFilesIter) Schema() sql.Schema {
33463393
return append(i.files.Schema(), FilesSchema...)
33473394
}
3348-
func (i *squashCommitFileFilesIter) Close() error { return i.files.Close() }
3395+
func (i *squashCommitFileFilesIter) Close() error {
3396+
i.Repository().Close()
3397+
return i.files.Close()
3398+
}
33493399

33503400
func evalFilters(ctx *sql.Context, row sql.Row, filters sql.Expression) (bool, error) {
33513401
v, err := filters.Eval(ctx, row)

0 commit comments

Comments
 (0)