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

Close iterators #772

Merged
merged 1 commit into from
Apr 3, 2019
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
6 changes: 4 additions & 2 deletions commit_trees.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,11 +330,13 @@ func (i *commitTreesRowIter) Close() error {
i.trees.Close()
}

if i.repo != nil {
i.repo.Close()
}

if i.index != nil {
return i.index.Close()
}

i.repo.Close()

return nil
}
5 changes: 4 additions & 1 deletion partition.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,5 +227,8 @@ func (i *partitionedIndexKeyValueIter) Next() (sql.Partition, sql.IndexKeyValueI
}

func (i *partitionedIndexKeyValueIter) Close() error {
return i.partitions.Close()
if i.partitions != nil {
return i.partitions.Close()
}
return nil
}
12 changes: 10 additions & 2 deletions ref_commits.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,12 +361,14 @@ func (i *refCommitsRowIter) Close() error {
i.refs.Close()
}

if i.repo != nil {
i.repo.Close()
}

if i.index != nil {
return i.index.Close()
}

i.repo.Close()

return nil
}

Expand Down Expand Up @@ -443,3 +445,9 @@ func (i *indexedCommitIter) Next() (*object.Commit, int, error) {
return c, frame.idx, nil
}
}

func (i *indexedCommitIter) Close() {
if i.repo != nil {
i.repo.Close()
}
}
6 changes: 4 additions & 2 deletions references.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,12 +320,14 @@ func (i *refRowIter) Close() error {
i.iter.Close()
}

if i.repo != nil {
i.repo.Close()
}

if i.index != nil {
return i.index.Close()
}

i.repo.Close()

return nil
}

Expand Down
3 changes: 3 additions & 0 deletions repositories.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,5 +151,8 @@ func (i *repositoriesRowIter) Next() (sql.Row, error) {

func (i *repositoriesRowIter) Close() error {
i.visited = true
if i.repo != nil {
i.repo.Close()
}
return nil
}
89 changes: 59 additions & 30 deletions squash_iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,13 @@ func NewAllReposIter(filters sql.Expression) ReposIter {
}

func (i *squashReposIter) Repo() *Repository { return i.repo }
func (i *squashReposIter) Close() error { return nil }
func (i *squashReposIter) Close() error {
if i.repo != nil {
i.repo.Close()
}

return nil
}
func (i *squashReposIter) New(ctx *sql.Context, repo *Repository) (ChainableIter, error) {
session, err := getSession(ctx)
if err != nil {
Expand Down Expand Up @@ -140,7 +146,13 @@ func NewAllRemotesIter(filters sql.Expression) RemotesIter {
}

func (i *squashRemoteIter) Remote() *Remote { return i.remote }
func (i *squashRemoteIter) Close() error { return nil }
func (i *squashRemoteIter) Close() error {
if i.repo != nil {
i.repo.Close()
}

return nil
}
func (i *squashRemoteIter) New(ctx *sql.Context, repo *Repository) (ChainableIter, error) {
session, err := getSession(ctx)
if err != nil {
Expand Down Expand Up @@ -403,6 +415,9 @@ func (i *squashRefIter) Close() error {
if i.refs != nil {
i.refs.Close()
}
if i.repo != nil {
i.repo.Close()
}
return i.repos.Close()
}
func (i *squashRefIter) New(ctx *sql.Context, repo *Repository) (ChainableIter, error) {
Expand Down Expand Up @@ -523,6 +538,10 @@ func NewIndexRefsIter(filters sql.Expression, index sql.IndexLookup) RefsIter {
func (i *squashRefIndexIter) Repository() *Repository { return i.repo }
func (i *squashRefIndexIter) Ref() *Ref { return i.ref }
func (i *squashRefIndexIter) Close() error {
if i.repo != nil {
i.repo.Close()
}

return i.iter.Close()
}
func (i *squashRefIndexIter) New(ctx *sql.Context, repo *Repository) (ChainableIter, error) {
Expand Down Expand Up @@ -778,8 +797,6 @@ func NewRemoteRefsIter(
func (i *squashRemoteRefsIter) Repository() *Repository { return i.remotes.Repository() }
func (i *squashRemoteRefsIter) Ref() *Ref { return i.ref }
func (i *squashRemoteRefsIter) Close() error {
i.Repository().Close()

if i.refs != nil {
i.refs.Close()
}
Expand Down Expand Up @@ -929,7 +946,9 @@ func (i *squashRefRefCommitsIter) Close() error {
i.refs.Close()
}

i.Repository().Close()
if i.commits != nil {
i.commits.Close()
}
return nil
}
func (i *squashRefRefCommitsIter) New(ctx *sql.Context, repo *Repository) (ChainableIter, error) {
Expand Down Expand Up @@ -1202,7 +1221,9 @@ func (i *squashRefCommitsIndexIter) Schema() sql.Schema {
return RefCommitsSchema
}
func (i *squashRefCommitsIndexIter) Close() error {
i.repo.Close()
if i.repo != nil {
i.repo.Close()
}
return i.iter.Close()
}

Expand All @@ -1226,7 +1247,6 @@ func (i *squashRefCommitCommitsIter) Close() error {
i.refCommits.Close()
}

i.Repository().Close()
return nil
}
func (i *squashRefCommitCommitsIter) New(ctx *sql.Context, repo *Repository) (ChainableIter, error) {
Expand Down Expand Up @@ -1297,8 +1317,10 @@ func (i *squashCommitsIter) Close() error {
if i.commits != nil {
i.commits.Close()
}
if i.repo != nil {
i.repo.Close()
}

i.repo.Close()
return nil
}
func (i *squashCommitsIter) New(ctx *sql.Context, repo *Repository) (ChainableIter, error) {
Expand Down Expand Up @@ -1472,7 +1494,10 @@ func (i *squashCommitsIndexIter) Schema() sql.Schema {
return CommitsSchema
}
func (i *squashCommitsIndexIter) Close() error {
i.repo.Close()
if i.repo != nil {
i.repo.Close()
}

return i.iter.Close()
}

Expand All @@ -1499,8 +1524,6 @@ func (i *squashRepoCommitsIter) Close() error {
i.commits.Close()
}

i.Repository().Close()

if i.repos != nil {
return i.repos.Close()
}
Expand Down Expand Up @@ -1611,8 +1634,6 @@ func NewRefHEADCommitsIter(
func (i *squashRefHeadCommitsIter) Repository() *Repository { return i.refs.Repository() }
func (i *squashRefHeadCommitsIter) Commit() *object.Commit { return i.commit }
func (i *squashRefHeadCommitsIter) Close() error {
i.Repository().Close()

if i.refs != nil {
return i.refs.Close()
}
Expand Down Expand Up @@ -1805,7 +1826,10 @@ func (i *squashCommitTreesIndexIter) Schema() sql.Schema {
return CommitTreesSchema
}
func (i *squashCommitTreesIndexIter) Close() error {
i.repo.Close()
if i.repo != nil {
i.repo.Close()
}

return i.iter.Close()
}

Expand Down Expand Up @@ -1837,6 +1861,9 @@ func NewCommitTreesIter(
func (i *squashCommitTreesIter) Repository() *Repository { return i.commits.Repository() }
func (i *squashCommitTreesIter) Tree() *object.Tree { return i.tree }
func (i *squashCommitTreesIter) Close() error {
if i.trees != nil {
i.trees.Close()
}
if i.commits != nil {
return i.commits.Close()
}
Expand Down Expand Up @@ -1953,8 +1980,6 @@ func (i *squashRepoTreeEntriesIter) Close() error {
i.trees.Close()
}

i.Repository().Close()

if i.repos != nil {
return i.repos.Close()
}
Expand Down Expand Up @@ -2083,8 +2108,6 @@ func NewCommitMainTreeIter(
func (i *squashCommitMainTreeIter) Repository() *Repository { return i.commits.Repository() }
func (i *squashCommitMainTreeIter) Tree() *object.Tree { return i.tree }
func (i *squashCommitMainTreeIter) Close() error {
i.Repository().Close()

if i.commits != nil {
return i.commits.Close()
}
Expand Down Expand Up @@ -2247,6 +2270,12 @@ func (i *commitTreeIter) Next() (*object.Tree, error) {
}
}

func (i *commitTreeIter) Close() {
if i.repo != nil {
i.repo.Close()
}
}

// TreeEntriesIter is a chainable iterator that operates on Tree Entries.
type TreeEntriesIter interface {
ChainableIter
Expand Down Expand Up @@ -2277,7 +2306,9 @@ func NewAllTreeEntriesIter(filters sql.Expression) TreeEntriesIter {
func (i *squashTreeEntriesIter) Repository() *Repository { return i.repo }
func (i *squashTreeEntriesIter) TreeEntry() *TreeEntry { return i.entry }
func (i *squashTreeEntriesIter) Close() error {
i.Repository().Close()
if i.repo != nil {
i.repo.Close()
}

if i.trees != nil {
i.trees.Close()
Expand Down Expand Up @@ -2448,7 +2479,9 @@ func (i *squashTreeEntriesIndexIter) Schema() sql.Schema {
return TreeEntriesSchema
}
func (i *squashTreeEntriesIndexIter) Close() error {
i.Repository().Close()
if i.repo != nil {
i.repo.Close()
}
return i.iter.Close()
}

Expand Down Expand Up @@ -2480,8 +2513,6 @@ func NewTreeTreeEntriesIter(
func (i *squashTreeTreeEntriesIter) Repository() *Repository { return i.trees.Repository() }
func (i *squashTreeTreeEntriesIter) TreeEntry() *TreeEntry { return i.entry }
func (i *squashTreeTreeEntriesIter) Close() error {
i.Repository().Close()

if i.trees != nil {
return i.trees.Close()
}
Expand Down Expand Up @@ -2651,7 +2682,9 @@ func (i *squashCommitBlobsIndexIter) Schema() sql.Schema {
return CommitBlobsSchema
}
func (i *squashCommitBlobsIndexIter) Close() error {
i.Repository().Close()
if i.repo != nil {
i.repo.Close()
}
return i.iter.Close()
}

Expand Down Expand Up @@ -2689,8 +2722,6 @@ func (i *squashCommitBlobsIter) Close() error {
i.files.Close()
}

i.Repository().Close()

if i.commits != nil {
return i.commits.Close()
}
Expand Down Expand Up @@ -2821,8 +2852,6 @@ func (i *squashRepoBlobsIter) Close() error {
i.blobs.Close()
}

i.Repository().Close()

if i.repos != nil {
return i.repos.Close()
}
Expand Down Expand Up @@ -3207,7 +3236,6 @@ func (i *squashCommitFilesIter) Close() error {
i.files.Close()
}

i.Repository().Close()
return i.commits.Close()
}
func (i *squashCommitFilesIter) Schema() sql.Schema {
Expand Down Expand Up @@ -3315,7 +3343,9 @@ func (i *squashIndexCommitFilesIter) Row() sql.Row { return i.row }
func (i *squashIndexCommitFilesIter) Schema() sql.Schema { return CommitFilesSchema }

func (i *squashIndexCommitFilesIter) Close() error {
i.repo.Close()
if i.repo != nil {
i.repo.Close()
}
return i.iter.Close()
}

Expand Down Expand Up @@ -3391,7 +3421,6 @@ func (i *squashCommitFileFilesIter) Schema() sql.Schema {
return append(i.files.Schema(), FilesSchema...)
}
func (i *squashCommitFileFilesIter) Close() error {
i.Repository().Close()
return i.files.Close()
}

Expand Down
6 changes: 3 additions & 3 deletions tree_entries.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,9 @@ func (i *treeEntriesRowIter) Close() error {
if i.iter != nil {
i.iter.Close()
}

i.repo.Close()

if i.repo != nil {
i.repo.Close()
}
return nil
}

Expand Down