mirror of
https://github.com/dolthub/dolt.git
synced 2026-01-29 03:08:47 -06:00
go: doltdb: CommitItr: Make the context parameter generic; able to be *sql.Context or context.Context.
This commit is contained in:
@@ -228,7 +228,7 @@ func historicalFuzzyMatching(ctx context.Context, heads hash.HashSet, groupings
|
||||
hs = append(hs, h)
|
||||
}
|
||||
|
||||
iterator, err := commitwalk.GetTopologicalOrderIterator(ctx, db, hs, func(cmt *doltdb.OptionalCommit) (bool, error) {
|
||||
iterator, err := commitwalk.GetTopologicalOrderIterator[context.Context](ctx, db, hs, func(cmt *doltdb.OptionalCommit) (bool, error) {
|
||||
return true, nil
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
@@ -27,16 +27,16 @@ import (
|
||||
)
|
||||
|
||||
// CommitItr is an interface for iterating over a set of unique commits
|
||||
type CommitItr interface {
|
||||
type CommitItr[C Context] interface {
|
||||
// Next returns the hash of the next commit, and a pointer to that commit. Implementations of Next must handle
|
||||
// making sure the list of commits returned are unique. When complete Next will return hash.Hash{}, nil, io.EOF
|
||||
Next(ctx context.Context) (hash.Hash, *OptionalCommit, error)
|
||||
Next(ctx C) (hash.Hash, *OptionalCommit, error)
|
||||
|
||||
// Reset the commit iterator back to the start
|
||||
Reset(ctx context.Context) error
|
||||
}
|
||||
|
||||
type commitItr struct {
|
||||
type commitItr[C Context] struct {
|
||||
ddb *DoltDB
|
||||
rootCommits []*Commit
|
||||
currentRoot int
|
||||
@@ -47,7 +47,7 @@ type commitItr struct {
|
||||
}
|
||||
|
||||
// CommitItrForAllBranches returns a CommitItr which will iterate over all commits in all branches in a DoltDB
|
||||
func CommitItrForAllBranches(ctx context.Context, ddb *DoltDB) (CommitItr, error) {
|
||||
func CommitItrForAllBranches[C Context](ctx context.Context, ddb *DoltDB) (CommitItr[C], error) {
|
||||
branchRefs, err := ddb.GetBranches(ctx)
|
||||
|
||||
if err != nil {
|
||||
@@ -65,13 +65,13 @@ func CommitItrForAllBranches(ctx context.Context, ddb *DoltDB) (CommitItr, error
|
||||
rootCommits = append(rootCommits, cm)
|
||||
}
|
||||
|
||||
cmItr := CommitItrForRoots(ddb, rootCommits...)
|
||||
cmItr := CommitItrForRoots[C](ddb, rootCommits...)
|
||||
return cmItr, nil
|
||||
}
|
||||
|
||||
// CommitItrForRoots will return a CommitItr which will iterate over all ancestor commits of the provided rootCommits.
|
||||
func CommitItrForRoots(ddb *DoltDB, rootCommits ...*Commit) CommitItr {
|
||||
return &commitItr{
|
||||
func CommitItrForRoots[C Context](ddb *DoltDB, rootCommits ...*Commit) CommitItr[C] {
|
||||
return &commitItr[C]{
|
||||
ddb: ddb,
|
||||
rootCommits: rootCommits,
|
||||
added: make(map[hash.Hash]bool, 4096),
|
||||
@@ -79,7 +79,7 @@ func CommitItrForRoots(ddb *DoltDB, rootCommits ...*Commit) CommitItr {
|
||||
}
|
||||
}
|
||||
|
||||
func (cmItr *commitItr) Reset(ctx context.Context) error {
|
||||
func (cmItr *commitItr[C]) Reset(ctx context.Context) error {
|
||||
cmItr.curr = nil
|
||||
cmItr.currentRoot = 0
|
||||
cmItr.added = make(map[hash.Hash]bool, 4096)
|
||||
@@ -90,7 +90,7 @@ func (cmItr *commitItr) Reset(ctx context.Context) error {
|
||||
|
||||
// Next returns the hash of the next commit, and a pointer to that commit. It handles making sure the list of commits
|
||||
// returned are unique. When complete Next will return hash.Hash{}, nil, io.EOF
|
||||
func (cmItr *commitItr) Next(ctx context.Context) (hash.Hash, *OptionalCommit, error) {
|
||||
func (cmItr *commitItr[C]) Next(ctx C) (hash.Hash, *OptionalCommit, error) {
|
||||
for cmItr.curr == nil {
|
||||
if cmItr.currentRoot >= len(cmItr.rootCommits) {
|
||||
return hash.Hash{}, nil, io.EOF
|
||||
@@ -159,13 +159,17 @@ func HashToCommit(ctx context.Context, vrw types.ValueReadWriter, ns tree.NodeSt
|
||||
return NewCommit(ctx, vrw, ns, dc)
|
||||
}
|
||||
|
||||
type Context interface {
|
||||
context.Context
|
||||
}
|
||||
|
||||
// CommitFilter is a function that returns true if a commit should be filtered out, and false if it should be kept
|
||||
type CommitFilter func(context.Context, hash.Hash, *OptionalCommit) (filterOut bool, err error)
|
||||
type CommitFilter[C Context] func(C, hash.Hash, *OptionalCommit) (filterOut bool, err error)
|
||||
|
||||
// FilteringCommitItr is a CommitItr implementation that applies a filtering function to limit the commits returned
|
||||
type FilteringCommitItr struct {
|
||||
itr CommitItr
|
||||
filter CommitFilter
|
||||
type FilteringCommitItr[C Context] struct {
|
||||
itr CommitItr[C]
|
||||
filter CommitFilter[C]
|
||||
}
|
||||
|
||||
// AllCommits is a CommitFilter that matches all commits
|
||||
@@ -173,13 +177,13 @@ func AllCommits(_ context.Context, _ hash.Hash, _ *Commit) (filterOut bool, err
|
||||
return false, nil
|
||||
}
|
||||
|
||||
func NewFilteringCommitItr(itr CommitItr, filter CommitFilter) FilteringCommitItr {
|
||||
return FilteringCommitItr{itr, filter}
|
||||
func NewFilteringCommitItr[C Context](itr CommitItr[C], filter CommitFilter[C]) FilteringCommitItr[C] {
|
||||
return FilteringCommitItr[C]{itr, filter}
|
||||
}
|
||||
|
||||
// Next returns the hash of the next commit, and a pointer to that commit. Implementations of Next must handle
|
||||
// making sure the list of commits returned are unique. When complete Next will return hash.Hash{}, nil, io.EOF
|
||||
func (itr FilteringCommitItr) Next(ctx context.Context) (hash.Hash, *OptionalCommit, error) {
|
||||
func (itr FilteringCommitItr[C]) Next(ctx C) (hash.Hash, *OptionalCommit, error) {
|
||||
// iteration will terminate on io.EOF or a commit that is !filteredOut
|
||||
for {
|
||||
h, cm, err := itr.itr.Next(ctx)
|
||||
@@ -197,23 +201,23 @@ func (itr FilteringCommitItr) Next(ctx context.Context) (hash.Hash, *OptionalCom
|
||||
}
|
||||
|
||||
// Reset the commit iterator back to the
|
||||
func (itr FilteringCommitItr) Reset(ctx context.Context) error {
|
||||
func (itr FilteringCommitItr[C]) Reset(ctx context.Context) error {
|
||||
return itr.itr.Reset(ctx)
|
||||
}
|
||||
|
||||
func NewCommitSliceIter(cm []*Commit, h []hash.Hash) *CommitSliceIter {
|
||||
return &CommitSliceIter{cm: cm, h: h}
|
||||
func NewCommitSliceIter[C Context](cm []*Commit, h []hash.Hash) *CommitSliceIter[C] {
|
||||
return &CommitSliceIter[C]{cm: cm, h: h}
|
||||
}
|
||||
|
||||
type CommitSliceIter struct {
|
||||
type CommitSliceIter[C Context] struct {
|
||||
h []hash.Hash
|
||||
cm []*Commit
|
||||
i int
|
||||
}
|
||||
|
||||
var _ CommitItr = (*CommitSliceIter)(nil)
|
||||
var _ CommitItr[context.Context] = (*CommitSliceIter[context.Context])(nil)
|
||||
|
||||
func (i *CommitSliceIter) Next(ctx context.Context) (hash.Hash, *OptionalCommit, error) {
|
||||
func (i *CommitSliceIter[C]) Next(ctx C) (hash.Hash, *OptionalCommit, error) {
|
||||
if i.i >= len(i.h) {
|
||||
return hash.Hash{}, nil, io.EOF
|
||||
}
|
||||
@@ -222,25 +226,25 @@ func (i *CommitSliceIter) Next(ctx context.Context) (hash.Hash, *OptionalCommit,
|
||||
|
||||
}
|
||||
|
||||
func (i *CommitSliceIter) Reset(ctx context.Context) error {
|
||||
func (i *CommitSliceIter[C]) Reset(ctx context.Context) error {
|
||||
i.i = 0
|
||||
return nil
|
||||
}
|
||||
|
||||
func NewOneCommitIter(cm *Commit, h hash.Hash, meta *datas.CommitMeta) *OneCommitIter {
|
||||
return &OneCommitIter{cm: &OptionalCommit{cm, h}, h: h}
|
||||
func NewOneCommitIter[C Context](cm *Commit, h hash.Hash, meta *datas.CommitMeta) *OneCommitIter[C] {
|
||||
return &OneCommitIter[C]{cm: &OptionalCommit{cm, h}, h: h}
|
||||
}
|
||||
|
||||
type OneCommitIter struct {
|
||||
type OneCommitIter[C Context] struct {
|
||||
h hash.Hash
|
||||
cm *OptionalCommit
|
||||
m *datas.CommitMeta
|
||||
done bool
|
||||
}
|
||||
|
||||
var _ CommitItr = (*OneCommitIter)(nil)
|
||||
var _ CommitItr[context.Context] = (*OneCommitIter[context.Context])(nil)
|
||||
|
||||
func (i *OneCommitIter) Next(_ context.Context) (hash.Hash, *OptionalCommit, error) {
|
||||
func (i *OneCommitIter[C]) Next(_ C) (hash.Hash, *OptionalCommit, error) {
|
||||
if i.done {
|
||||
return hash.Hash{}, nil, io.EOF
|
||||
}
|
||||
@@ -249,7 +253,7 @@ func (i *OneCommitIter) Next(_ context.Context) (hash.Hash, *OptionalCommit, err
|
||||
|
||||
}
|
||||
|
||||
func (i *OneCommitIter) Reset(_ context.Context) error {
|
||||
func (i *OneCommitIter[C]) Reset(_ context.Context) error {
|
||||
i.done = false
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -183,7 +183,7 @@ func newQueue() *q {
|
||||
// Roughly mimics `git log main..feature` or `git log main...feature` (if
|
||||
// more than one `includedHead` is provided).
|
||||
func GetDotDotRevisions(ctx context.Context, includedDB *doltdb.DoltDB, includedHeads []hash.Hash, excludedDB *doltdb.DoltDB, excludedHeads []hash.Hash, num int) ([]*doltdb.OptionalCommit, error) {
|
||||
itr, err := GetDotDotRevisionsIterator(ctx, includedDB, includedHeads, excludedDB, excludedHeads, nil)
|
||||
itr, err := GetDotDotRevisionsIterator[context.Context](ctx, includedDB, includedHeads, excludedDB, excludedHeads, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -205,21 +205,21 @@ func GetDotDotRevisions(ctx context.Context, includedDB *doltdb.DoltDB, included
|
||||
|
||||
// GetTopologicalOrderCommitIterator returns an iterator for commits generated with the same semantics as
|
||||
// GetTopologicalOrderCommits
|
||||
func GetTopologicalOrderIterator(ctx context.Context, ddb *doltdb.DoltDB, startCommitHashes []hash.Hash, matchFn func(*doltdb.OptionalCommit) (bool, error)) (doltdb.CommitItr, error) {
|
||||
return newCommiterator(ctx, ddb, startCommitHashes, matchFn)
|
||||
func GetTopologicalOrderIterator[C doltdb.Context](ctx context.Context, ddb *doltdb.DoltDB, startCommitHashes []hash.Hash, matchFn func(*doltdb.OptionalCommit) (bool, error)) (doltdb.CommitItr[C], error) {
|
||||
return newCommiterator[C](ctx, ddb, startCommitHashes, matchFn)
|
||||
}
|
||||
|
||||
type commiterator struct {
|
||||
type commiterator[C doltdb.Context] struct {
|
||||
ddb *doltdb.DoltDB
|
||||
startCommitHashes []hash.Hash
|
||||
matchFn func(*doltdb.OptionalCommit) (bool, error)
|
||||
q *q
|
||||
}
|
||||
|
||||
var _ doltdb.CommitItr = (*commiterator)(nil)
|
||||
var _ doltdb.CommitItr[context.Context] = (*commiterator[context.Context])(nil)
|
||||
|
||||
func newCommiterator(ctx context.Context, ddb *doltdb.DoltDB, startCommitHashes []hash.Hash, matchFn func(*doltdb.OptionalCommit) (bool, error)) (*commiterator, error) {
|
||||
itr := &commiterator{
|
||||
func newCommiterator[C doltdb.Context](ctx context.Context, ddb *doltdb.DoltDB, startCommitHashes []hash.Hash, matchFn func(*doltdb.OptionalCommit) (bool, error)) (*commiterator[C], error) {
|
||||
itr := &commiterator[C]{
|
||||
ddb: ddb,
|
||||
startCommitHashes: startCommitHashes,
|
||||
matchFn: matchFn,
|
||||
@@ -234,7 +234,7 @@ func newCommiterator(ctx context.Context, ddb *doltdb.DoltDB, startCommitHashes
|
||||
}
|
||||
|
||||
// Next implements doltdb.CommitItr
|
||||
func (iter *commiterator) Next(ctx context.Context) (hash.Hash, *doltdb.OptionalCommit, error) {
|
||||
func (iter *commiterator[C]) Next(ctx C) (hash.Hash, *doltdb.OptionalCommit, error) {
|
||||
if iter.q.NumVisiblePending() > 0 {
|
||||
nextC := iter.q.PopPending()
|
||||
|
||||
@@ -274,7 +274,7 @@ func (iter *commiterator) Next(ctx context.Context) (hash.Hash, *doltdb.Optional
|
||||
}
|
||||
|
||||
// Reset implements doltdb.CommitItr
|
||||
func (i *commiterator) Reset(ctx context.Context) error {
|
||||
func (i *commiterator[C]) Reset(ctx context.Context) error {
|
||||
i.q = newQueue()
|
||||
for _, startCommitHash := range i.startCommitHashes {
|
||||
if err := i.q.AddPendingIfUnseen(ctx, i.ddb, startCommitHash); err != nil {
|
||||
@@ -286,15 +286,15 @@ func (i *commiterator) Reset(ctx context.Context) error {
|
||||
|
||||
// GetDotDotRevisionsIterator returns an iterator for commits generated with the same semantics as
|
||||
// GetDotDotRevisions
|
||||
func GetDotDotRevisionsIterator(ctx context.Context, includedDdb *doltdb.DoltDB, startCommitHashes []hash.Hash, excludedDdb *doltdb.DoltDB, excludingCommitHashes []hash.Hash, matchFn func(*doltdb.OptionalCommit) (bool, error)) (doltdb.CommitItr, error) {
|
||||
return newDotDotCommiterator(ctx, includedDdb, startCommitHashes, excludedDdb, excludingCommitHashes, matchFn)
|
||||
func GetDotDotRevisionsIterator[C doltdb.Context](ctx context.Context, includedDdb *doltdb.DoltDB, startCommitHashes []hash.Hash, excludedDdb *doltdb.DoltDB, excludingCommitHashes []hash.Hash, matchFn func(*doltdb.OptionalCommit) (bool, error)) (doltdb.CommitItr[C], error) {
|
||||
return newDotDotCommiterator[C](ctx, includedDdb, startCommitHashes, excludedDdb, excludingCommitHashes, matchFn)
|
||||
}
|
||||
|
||||
// GetTopNTopoOrderedCommitsMatching returns the first N commits (If N <= 0 then all commits) reachable from the commits in
|
||||
// `startCommitHashes` in reverse topological order, with tiebreaking done by the height of the commit graph -- higher
|
||||
// commits appear first. Remaining ties are broken by timestamp; newer commits appear first. DO NOT DELETE, USED IN DOLTHUB
|
||||
func GetTopNTopoOrderedCommitsMatching(ctx context.Context, ddb *doltdb.DoltDB, startCommitHashes []hash.Hash, n int, matchFn func(commit *doltdb.OptionalCommit) (bool, error)) ([]*doltdb.Commit, error) {
|
||||
itr, err := GetTopologicalOrderIterator(ctx, ddb, startCommitHashes, matchFn)
|
||||
itr, err := GetTopologicalOrderIterator[context.Context](ctx, ddb, startCommitHashes, matchFn)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -316,7 +316,7 @@ func GetTopNTopoOrderedCommitsMatching(ctx context.Context, ddb *doltdb.DoltDB,
|
||||
return commitList, nil
|
||||
}
|
||||
|
||||
type dotDotCommiterator struct {
|
||||
type dotDotCommiterator[C doltdb.Context] struct {
|
||||
includedDdb *doltdb.DoltDB
|
||||
excludedDdb *doltdb.DoltDB
|
||||
startCommitHashes []hash.Hash
|
||||
@@ -325,10 +325,10 @@ type dotDotCommiterator struct {
|
||||
q *q
|
||||
}
|
||||
|
||||
var _ doltdb.CommitItr = (*dotDotCommiterator)(nil)
|
||||
var _ doltdb.CommitItr[context.Context] = (*dotDotCommiterator[context.Context])(nil)
|
||||
|
||||
func newDotDotCommiterator(ctx context.Context, includedDdb *doltdb.DoltDB, startCommitHashes []hash.Hash, excludedDdb *doltdb.DoltDB, excludingCommitHashes []hash.Hash, matchFn func(*doltdb.OptionalCommit) (bool, error)) (*dotDotCommiterator, error) {
|
||||
itr := &dotDotCommiterator{
|
||||
func newDotDotCommiterator[C doltdb.Context](ctx context.Context, includedDdb *doltdb.DoltDB, startCommitHashes []hash.Hash, excludedDdb *doltdb.DoltDB, excludingCommitHashes []hash.Hash, matchFn func(*doltdb.OptionalCommit) (bool, error)) (*dotDotCommiterator[C], error) {
|
||||
itr := &dotDotCommiterator[C]{
|
||||
includedDdb: includedDdb,
|
||||
excludedDdb: excludedDdb,
|
||||
startCommitHashes: startCommitHashes,
|
||||
@@ -345,7 +345,7 @@ func newDotDotCommiterator(ctx context.Context, includedDdb *doltdb.DoltDB, star
|
||||
}
|
||||
|
||||
// Next implements doltdb.CommitItr
|
||||
func (i *dotDotCommiterator) Next(ctx context.Context) (hash.Hash, *doltdb.OptionalCommit, error) {
|
||||
func (i *dotDotCommiterator[C]) Next(ctx C) (hash.Hash, *doltdb.OptionalCommit, error) {
|
||||
if i.q.NumVisiblePending() > 0 {
|
||||
nextC := i.q.PopPending()
|
||||
|
||||
@@ -389,7 +389,7 @@ func (i *dotDotCommiterator) Next(ctx context.Context) (hash.Hash, *doltdb.Optio
|
||||
}
|
||||
|
||||
// Reset implements doltdb.CommitItr
|
||||
func (i *dotDotCommiterator) Reset(ctx context.Context) error {
|
||||
func (i *dotDotCommiterator[C]) Reset(ctx context.Context) error {
|
||||
i.q = newQueue()
|
||||
for _, excludingCommitHash := range i.excludingCommitHashes {
|
||||
if err := i.q.SetInvisible(ctx, i.excludedDdb, excludingCommitHash); err != nil {
|
||||
|
||||
@@ -190,7 +190,7 @@ func findRebaseCommits(ctx *sql.Context, currentBranchCommit, upstreamBranchComm
|
||||
|
||||
// We use the dot-dot revision iterator because it gives us the behavior we want for rebase – it finds all
|
||||
// commits reachable from |currentBranchCommit| but NOT reachable by |upstreamBranchCommit|.
|
||||
commitItr, err := commitwalk.GetDotDotRevisionsIterator(ctx,
|
||||
commitItr, err := commitwalk.GetDotDotRevisionsIterator[*sql.Context](ctx,
|
||||
ddb, []hash.Hash{currentBranchCommitHash},
|
||||
ddb, []hash.Hash{upstreamBranchCommitHash}, nil)
|
||||
if err != nil {
|
||||
|
||||
@@ -807,7 +807,7 @@ func resolveAsOfTime(ctx *sql.Context, ddb *doltdb.DoltDB, head ref.DoltRef, asO
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
cmItr, err := commitwalk.GetTopologicalOrderIterator(ctx, ddb, []hash.Hash{h}, nil)
|
||||
cmItr, err := commitwalk.GetTopologicalOrderIterator[*sql.Context](ctx, ddb, []hash.Hash{h}, nil)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
@@ -140,7 +140,7 @@ func countCommits(ctx *sql.Context, args ...string) (ahead uint64, behind uint64
|
||||
// countCommitsInRange returns the number of commits between the given starting point to trace back to the given target point.
|
||||
// The starting commit must be a descendant of the target commit. Target commit must be a common ancestor commit.
|
||||
func countCommitsInRange(ctx context.Context, ddb *doltdb.DoltDB, startCommitHash, targetCommitHash hash.Hash) (uint64, error) {
|
||||
itr, iErr := commitwalk.GetTopologicalOrderIterator(ctx, ddb, []hash.Hash{startCommitHash}, nil)
|
||||
itr, iErr := commitwalk.GetTopologicalOrderIterator[context.Context](ctx, ddb, []hash.Hash{startCommitHash}, nil)
|
||||
if iErr != nil {
|
||||
return 0, iErr
|
||||
}
|
||||
|
||||
@@ -606,7 +606,7 @@ var _ sql.RowIter = (*logTableFunctionRowIter)(nil)
|
||||
|
||||
// logTableFunctionRowIter is a sql.RowIter implementation which iterates over each commit as if it's a row in the table.
|
||||
type logTableFunctionRowIter struct {
|
||||
child doltdb.CommitItr
|
||||
child doltdb.CommitItr[*sql.Context]
|
||||
showParents bool
|
||||
showSignature bool
|
||||
decoration string
|
||||
@@ -622,7 +622,7 @@ func (ltf *LogTableFunction) NewLogTableFunctionRowIter(ctx *sql.Context, ddb *d
|
||||
return nil, err
|
||||
}
|
||||
|
||||
child, err := commitwalk.GetTopologicalOrderIterator(ctx, ddb, []hash.Hash{h}, matchFn)
|
||||
child, err := commitwalk.GetTopologicalOrderIterator[*sql.Context](ctx, ddb, []hash.Hash{h}, matchFn)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -657,7 +657,7 @@ func (ltf *LogTableFunction) NewDotDotLogTableFunctionRowIter(ctx *sql.Context,
|
||||
exHashes[i] = h
|
||||
}
|
||||
|
||||
child, err := commitwalk.GetDotDotRevisionsIterator(ctx, ddb, hashes, ddb, exHashes, matchFn)
|
||||
child, err := commitwalk.GetDotDotRevisionsIterator[*sql.Context](ctx, ddb, hashes, ddb, exHashes, matchFn)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ type ColumnDiffTable struct {
|
||||
ddb *doltdb.DoltDB
|
||||
head *doltdb.Commit
|
||||
partitionFilters []sql.Expression
|
||||
commitCheck doltdb.CommitFilter
|
||||
commitCheck doltdb.CommitFilter[*sql.Context]
|
||||
}
|
||||
|
||||
var _ sql.Table = (*ColumnDiffTable)(nil)
|
||||
@@ -119,7 +119,7 @@ func (dt *ColumnDiffTable) PartitionRows(ctx *sql.Context, partition sql.Partiti
|
||||
if hasCommitHashEquality {
|
||||
return dt.newCommitHistoryRowItrFromCommits(ctx, cms)
|
||||
}
|
||||
iter := doltdb.CommitItrForRoots(dt.ddb, dt.head)
|
||||
iter := doltdb.CommitItrForRoots[*sql.Context](dt.ddb, dt.head)
|
||||
if dt.commitCheck != nil {
|
||||
iter = doltdb.NewFilteringCommitItr(iter, dt.commitCheck)
|
||||
}
|
||||
@@ -278,7 +278,7 @@ func (d *doltColDiffWorkingSetRowItr) Close(c *sql.Context) error {
|
||||
type doltColDiffCommitHistoryRowItr struct {
|
||||
ctx *sql.Context
|
||||
ddb *doltdb.DoltDB
|
||||
child doltdb.CommitItr
|
||||
child doltdb.CommitItr[*sql.Context]
|
||||
commits []*doltdb.Commit
|
||||
meta *datas.CommitMeta
|
||||
hash hash.Hash
|
||||
@@ -288,7 +288,7 @@ type doltColDiffCommitHistoryRowItr struct {
|
||||
}
|
||||
|
||||
// newCommitHistoryRowItr creates a doltDiffCommitHistoryRowItr from a CommitItr.
|
||||
func (dt *ColumnDiffTable) newCommitHistoryRowItrFromItr(ctx *sql.Context, iter doltdb.CommitItr) (*doltColDiffCommitHistoryRowItr, error) {
|
||||
func (dt *ColumnDiffTable) newCommitHistoryRowItrFromItr(ctx *sql.Context, iter doltdb.CommitItr[*sql.Context]) (*doltColDiffCommitHistoryRowItr, error) {
|
||||
dchItr := &doltColDiffCommitHistoryRowItr{
|
||||
ctx: ctx,
|
||||
ddb: dt.ddb,
|
||||
|
||||
@@ -92,7 +92,7 @@ func (ct *CommitAncestorsTable) PartitionRows(ctx *sql.Context, p sql.Partition)
|
||||
switch p := p.(type) {
|
||||
case *doltdb.CommitPart:
|
||||
return &CommitAncestorsRowItr{
|
||||
itr: doltdb.NewOneCommitIter(p.Commit(), p.Hash(), p.Meta()),
|
||||
itr: doltdb.NewOneCommitIter[*sql.Context](p.Commit(), p.Hash(), p.Meta()),
|
||||
ddb: ct.ddb,
|
||||
}, nil
|
||||
default:
|
||||
@@ -137,14 +137,14 @@ func (ct *CommitAncestorsTable) LookupPartitions(ctx *sql.Context, lookup sql.In
|
||||
// CommitAncestorsRowItr is a sql.RowItr which iterates over each
|
||||
// (commit, parent_commit) pair as if it's a row in the table.
|
||||
type CommitAncestorsRowItr struct {
|
||||
itr doltdb.CommitItr
|
||||
itr doltdb.CommitItr[*sql.Context]
|
||||
ddb *doltdb.DoltDB
|
||||
cache []sql.Row
|
||||
}
|
||||
|
||||
// NewCommitAncestorsRowItr creates a CommitAncestorsRowItr from the current environment.
|
||||
func NewCommitAncestorsRowItr(sqlCtx *sql.Context, ddb *doltdb.DoltDB) (*CommitAncestorsRowItr, error) {
|
||||
itr, err := doltdb.CommitItrForAllBranches(sqlCtx, ddb)
|
||||
itr, err := doltdb.CommitItrForAllBranches[*sql.Context](sqlCtx, ddb)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -136,12 +136,12 @@ func (ct *CommitsTable) LookupPartitions(ctx *sql.Context, lookup sql.IndexLooku
|
||||
|
||||
// CommitsRowItr is a sql.RowItr which iterates over each commit as if it's a row in the table.
|
||||
type CommitsRowItr struct {
|
||||
itr doltdb.CommitItr
|
||||
itr doltdb.CommitItr[*sql.Context]
|
||||
}
|
||||
|
||||
// NewCommitsRowItr creates a CommitsRowItr from the current environment.
|
||||
func NewCommitsRowItr(ctx *sql.Context, ddb *doltdb.DoltDB) (CommitsRowItr, error) {
|
||||
itr, err := doltdb.CommitItrForAllBranches(ctx, ddb)
|
||||
itr, err := doltdb.CommitItrForAllBranches[*sql.Context](ctx, ddb)
|
||||
if err != nil {
|
||||
return CommitsRowItr{}, err
|
||||
}
|
||||
|
||||
@@ -167,7 +167,7 @@ func (dt *DiffTable) Collation() sql.CollationID {
|
||||
}
|
||||
|
||||
func (dt *DiffTable) Partitions(ctx *sql.Context) (sql.PartitionIter, error) {
|
||||
cmItr := doltdb.CommitItrForRoots(dt.ddb, dt.head)
|
||||
cmItr := doltdb.CommitItrForRoots[*sql.Context](dt.ddb, dt.head)
|
||||
|
||||
sf, err := SelectFuncForFilters(ctx, dt.ddb.ValueReadWriter(), dt.partitionFilters)
|
||||
if err != nil {
|
||||
@@ -361,7 +361,7 @@ func (dt *DiffTable) fromCommitLookupPartitions(ctx *sql.Context, hashes []hash.
|
||||
return nil, err
|
||||
}
|
||||
|
||||
cmItr := doltdb.NewCommitSliceIter(pCommits, parentHashes)
|
||||
cmItr := doltdb.NewCommitSliceIter[*sql.Context](pCommits, parentHashes)
|
||||
|
||||
return &DiffPartitions{
|
||||
tblName: dt.tableName,
|
||||
@@ -421,7 +421,7 @@ func (dt *DiffTable) scanHeightForChild(ctx *sql.Context, parent hash.Hash, heig
|
||||
// reverseIterForChild finds the commit with the largest height that
|
||||
// is a child of the |parent| hash, or nil if no commit is found.
|
||||
func (dt *DiffTable) reverseIterForChild(ctx *sql.Context, parent hash.Hash) (*doltdb.Commit, hash.Hash, error) {
|
||||
iter := doltdb.CommitItrForRoots(dt.ddb, dt.head)
|
||||
iter := doltdb.CommitItrForRoots[*sql.Context](dt.ddb, dt.head)
|
||||
for {
|
||||
childHs, optCmt, err := iter.Next(ctx)
|
||||
if errors.Is(err, io.EOF) {
|
||||
@@ -564,7 +564,7 @@ func (dt *DiffTable) toCommitLookupPartitions(ctx *sql.Context, hashes []hash.Ha
|
||||
return nil, err
|
||||
}
|
||||
|
||||
cmItr := doltdb.NewCommitSliceIter(pCommits, parentHashes)
|
||||
cmItr := doltdb.NewCommitSliceIter[*sql.Context](pCommits, parentHashes)
|
||||
|
||||
return &DiffPartitions{
|
||||
tblName: dt.tableName,
|
||||
@@ -768,7 +768,7 @@ var _ sql.PartitionIter = &DiffPartitions{}
|
||||
// DiffPartitions a collection of partitions. Implements PartitionItr
|
||||
type DiffPartitions struct {
|
||||
tblName doltdb.TableName
|
||||
cmItr doltdb.CommitItr
|
||||
cmItr doltdb.CommitItr[*sql.Context]
|
||||
cmHashToTblInfo map[hash.Hash]TblInfoAtCommit
|
||||
selectFunc partitionSelectFunc
|
||||
toSch schema.Schema
|
||||
|
||||
@@ -209,7 +209,7 @@ func (dt *LogTable) HeadHash() (hash.Hash, error) {
|
||||
|
||||
// LogItr is a sql.RowItr implementation which iterates over each commit as if it's a row in the table.
|
||||
type LogItr struct {
|
||||
child doltdb.CommitItr
|
||||
child doltdb.CommitItr[*sql.Context]
|
||||
}
|
||||
|
||||
// NewLogItr creates a LogItr from the current environment.
|
||||
@@ -219,7 +219,7 @@ func NewLogItr(ctx *sql.Context, ddb *doltdb.DoltDB, head *doltdb.Commit) (*LogI
|
||||
return nil, err
|
||||
}
|
||||
|
||||
child, err := commitwalk.GetTopologicalOrderIterator(ctx, ddb, []hash.Hash{h}, nil)
|
||||
child, err := commitwalk.GetTopologicalOrderIterator[*sql.Context](ctx, ddb, []hash.Hash{h}, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ type UnscopedDiffTable struct {
|
||||
ddb *doltdb.DoltDB
|
||||
head *doltdb.Commit
|
||||
partitionFilters []sql.Expression
|
||||
commitCheck doltdb.CommitFilter
|
||||
commitCheck doltdb.CommitFilter[*sql.Context]
|
||||
}
|
||||
|
||||
var _ sql.Table = (*UnscopedDiffTable)(nil)
|
||||
@@ -135,7 +135,7 @@ func (dt *UnscopedDiffTable) PartitionRows(ctx *sql.Context, partition sql.Parti
|
||||
if hasCommitHashEquality {
|
||||
return dt.newCommitHistoryRowItrFromCommits(ctx, cms)
|
||||
}
|
||||
iter := doltdb.CommitItrForRoots(dt.ddb, dt.head)
|
||||
iter := doltdb.CommitItrForRoots[*sql.Context](dt.ddb, dt.head)
|
||||
if dt.commitCheck != nil {
|
||||
iter = doltdb.NewFilteringCommitItr(iter, dt.commitCheck)
|
||||
}
|
||||
@@ -283,7 +283,7 @@ func (d doltDiffPartition) Key() []byte {
|
||||
type doltDiffCommitHistoryRowItr struct {
|
||||
ctx *sql.Context
|
||||
ddb *doltdb.DoltDB
|
||||
child doltdb.CommitItr
|
||||
child doltdb.CommitItr[*sql.Context]
|
||||
commits []*doltdb.Commit
|
||||
meta *datas.CommitMeta
|
||||
hash hash.Hash
|
||||
@@ -292,7 +292,7 @@ type doltDiffCommitHistoryRowItr struct {
|
||||
}
|
||||
|
||||
// newCommitHistoryRowItr creates a doltDiffCommitHistoryRowItr from a CommitItr.
|
||||
func (dt *UnscopedDiffTable) newCommitHistoryRowItrFromItr(ctx *sql.Context, iter doltdb.CommitItr) (*doltDiffCommitHistoryRowItr, error) {
|
||||
func (dt *UnscopedDiffTable) newCommitHistoryRowItrFromItr(ctx *sql.Context, iter doltdb.CommitItr[*sql.Context]) (*doltDiffCommitHistoryRowItr, error) {
|
||||
dchItr := &doltDiffCommitHistoryRowItr{
|
||||
ctx: ctx,
|
||||
ddb: dt.ddb,
|
||||
@@ -472,12 +472,10 @@ func isTableDataEmpty(ctx *sql.Context, table *doltdb.Table) (bool, error) {
|
||||
}
|
||||
|
||||
// commitFilterForDiffTableFilterExprs returns CommitFilter used for CommitItr.
|
||||
func commitFilterForDiffTableFilterExprs(filters []sql.Expression) (doltdb.CommitFilter, error) {
|
||||
func commitFilterForDiffTableFilterExprs(filters []sql.Expression) (doltdb.CommitFilter[*sql.Context], error) {
|
||||
filters = transformFilters(filters...)
|
||||
|
||||
return func(ctx context.Context, h hash.Hash, optCmt *doltdb.OptionalCommit) (filterOut bool, err error) {
|
||||
sc := sql.NewContext(ctx)
|
||||
|
||||
return func(ctx *sql.Context, h hash.Hash, optCmt *doltdb.OptionalCommit) (filterOut bool, err error) {
|
||||
cm, ok := optCmt.ToCommit()
|
||||
if !ok {
|
||||
return false, doltdb.ErrGhostCommitEncountered
|
||||
@@ -488,7 +486,7 @@ func commitFilterForDiffTableFilterExprs(filters []sql.Expression) (doltdb.Commi
|
||||
return false, err
|
||||
}
|
||||
for _, filter := range filters {
|
||||
res, err := filter.Eval(sc, sql.Row{h.String(), meta.Name, meta.Time()})
|
||||
res, err := filter.Eval(ctx, sql.Row{h.String(), meta.Name, meta.Time()})
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
package sqle
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"strings"
|
||||
@@ -61,8 +60,8 @@ var _ sql.PrimaryKeyTable = (*HistoryTable)(nil)
|
||||
type HistoryTable struct {
|
||||
doltTable *DoltTable
|
||||
commitFilters []sql.Expression
|
||||
cmItr doltdb.CommitItr
|
||||
commitCheck doltdb.CommitFilter
|
||||
cmItr doltdb.CommitItr[*sql.Context]
|
||||
commitCheck doltdb.CommitFilter[*sql.Context]
|
||||
indexLookup sql.IndexLookup
|
||||
projectedCols []uint64
|
||||
conversionWarningsByColumn map[string]struct{}
|
||||
@@ -155,7 +154,7 @@ func (ht *HistoryTable) LookupPartitions(ctx *sql.Context, lookup sql.IndexLooku
|
||||
return sql.PartitionsToPartitionIter(), nil
|
||||
}
|
||||
|
||||
iter, err := ht.filterIter(ctx, doltdb.NewCommitSliceIter(commits, hashes))
|
||||
iter, err := ht.filterIter(ctx, doltdb.NewCommitSliceIter[*sql.Context](commits, hashes))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -168,7 +167,7 @@ func (ht *HistoryTable) LookupPartitions(ctx *sql.Context, lookup sql.IndexLooku
|
||||
|
||||
// NewHistoryTable creates a history table
|
||||
func NewHistoryTable(table *DoltTable, ddb *doltdb.DoltDB, head *doltdb.Commit) sql.Table {
|
||||
cmItr := doltdb.CommitItrForRoots(ddb, head)
|
||||
cmItr := doltdb.CommitItrForRoots[*sql.Context](ddb, head)
|
||||
|
||||
// System tables don't currently use overridden schemas, so if one is set on |table|,
|
||||
// clear it out to make sure we use the correct schema that matches the data being used.
|
||||
@@ -216,20 +215,20 @@ func historyTableSchema(tableName string, table *DoltTable) sql.Schema {
|
||||
return newSch
|
||||
}
|
||||
|
||||
func (ht *HistoryTable) filterIter(ctx *sql.Context, iter doltdb.CommitItr) (doltdb.CommitItr, error) {
|
||||
func (ht *HistoryTable) filterIter(ctx *sql.Context, iter doltdb.CommitItr[*sql.Context]) (doltdb.CommitItr[*sql.Context], error) {
|
||||
if len(ht.commitFilters) > 0 {
|
||||
r, err := ht.doltTable.db.GetRoot(ctx)
|
||||
if err != nil {
|
||||
return doltdb.FilteringCommitItr{}, err
|
||||
return doltdb.FilteringCommitItr[*sql.Context]{}, err
|
||||
}
|
||||
h, err := r.HashOf()
|
||||
if err != nil {
|
||||
return doltdb.FilteringCommitItr{}, err
|
||||
return doltdb.FilteringCommitItr[*sql.Context]{}, err
|
||||
}
|
||||
filters := substituteWorkingHash(h, ht.commitFilters)
|
||||
check, err := commitFilterForExprs(ctx, filters)
|
||||
if err != nil {
|
||||
return doltdb.FilteringCommitItr{}, err
|
||||
return doltdb.FilteringCommitItr[*sql.Context]{}, err
|
||||
}
|
||||
|
||||
return doltdb.NewFilteringCommitItr(iter, check), nil
|
||||
@@ -256,10 +255,10 @@ func substituteWorkingHash(h hash.Hash, f []sql.Expression) []sql.Expression {
|
||||
return ret
|
||||
}
|
||||
|
||||
func commitFilterForExprs(ctx *sql.Context, filters []sql.Expression) (doltdb.CommitFilter, error) {
|
||||
func commitFilterForExprs(ctx *sql.Context, filters []sql.Expression) (doltdb.CommitFilter[*sql.Context], error) {
|
||||
filters = transformFilters(ctx, filters...)
|
||||
|
||||
return func(ctx context.Context, h hash.Hash, optCmt *doltdb.OptionalCommit) (filterOut bool, err error) {
|
||||
return func(ctx *sql.Context, h hash.Hash, optCmt *doltdb.OptionalCommit) (filterOut bool, err error) {
|
||||
cm, ok := optCmt.ToCommit()
|
||||
if !ok {
|
||||
return false, nil // NM4 TEST.
|
||||
@@ -271,11 +270,10 @@ func commitFilterForExprs(ctx *sql.Context, filters []sql.Expression) (doltdb.Co
|
||||
return false, err
|
||||
}
|
||||
|
||||
sc := sql.NewContext(ctx)
|
||||
r := sql.Row{h.String(), meta.Name, meta.Time()}
|
||||
|
||||
for _, filter := range filters {
|
||||
res, err := filter.Eval(sc, r)
|
||||
res, err := filter.Eval(ctx, r)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
@@ -453,7 +451,7 @@ func (cp *commitPartition) Key() []byte {
|
||||
|
||||
// commitPartitioner creates partitions from a CommitItr
|
||||
type commitPartitioner struct {
|
||||
cmItr doltdb.CommitItr
|
||||
cmItr doltdb.CommitItr[*sql.Context]
|
||||
}
|
||||
|
||||
// Next returns the next partition and nil, io.EOF when complete
|
||||
|
||||
Reference in New Issue
Block a user