diff --git a/commit_trees.go b/commit_trees.go index e28edfc7c..cf2d90559 100644 --- a/commit_trees.go +++ b/commit_trees.go @@ -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 } diff --git a/partition.go b/partition.go index 3d82322ed..e6d524ee4 100644 --- a/partition.go +++ b/partition.go @@ -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 } diff --git a/ref_commits.go b/ref_commits.go index 244bed4f9..cdcfc83f2 100644 --- a/ref_commits.go +++ b/ref_commits.go @@ -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 } @@ -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() + } +} diff --git a/references.go b/references.go index f7b9e5e5e..ee0956d12 100644 --- a/references.go +++ b/references.go @@ -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 } diff --git a/repositories.go b/repositories.go index d1286c5da..b14089543 100644 --- a/repositories.go +++ b/repositories.go @@ -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 } diff --git a/squash_iterator.go b/squash_iterator.go index c954deb37..d6f1058fb 100644 --- a/squash_iterator.go +++ b/squash_iterator.go @@ -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 { @@ -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 { @@ -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) { @@ -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) { @@ -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() } @@ -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) { @@ -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() } @@ -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) { @@ -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) { @@ -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() } @@ -1499,8 +1524,6 @@ func (i *squashRepoCommitsIter) Close() error { i.commits.Close() } - i.Repository().Close() - if i.repos != nil { return i.repos.Close() } @@ -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() } @@ -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() } @@ -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() } @@ -1953,8 +1980,6 @@ func (i *squashRepoTreeEntriesIter) Close() error { i.trees.Close() } - i.Repository().Close() - if i.repos != nil { return i.repos.Close() } @@ -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() } @@ -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 @@ -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() @@ -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() } @@ -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() } @@ -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() } @@ -2689,8 +2722,6 @@ func (i *squashCommitBlobsIter) Close() error { i.files.Close() } - i.Repository().Close() - if i.commits != nil { return i.commits.Close() } @@ -2821,8 +2852,6 @@ func (i *squashRepoBlobsIter) Close() error { i.blobs.Close() } - i.Repository().Close() - if i.repos != nil { return i.repos.Close() } @@ -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 { @@ -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() } @@ -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() } diff --git a/tree_entries.go b/tree_entries.go index 17dcf0bbe..aead61356 100644 --- a/tree_entries.go +++ b/tree_entries.go @@ -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 }