@@ -27,16 +27,16 @@ import (
27
27
)
28
28
29
29
// CommitItr is an interface for iterating over a set of unique commits
30
- type CommitItr interface {
30
+ type CommitItr [ C Context ] interface {
31
31
// Next returns the hash of the next commit, and a pointer to that commit. Implementations of Next must handle
32
32
// making sure the list of commits returned are unique. When complete Next will return hash.Hash{}, nil, io.EOF
33
- Next (ctx context. Context ) (hash.Hash , * OptionalCommit , error )
33
+ Next (ctx C ) (hash.Hash , * OptionalCommit , error )
34
34
35
35
// Reset the commit iterator back to the start
36
36
Reset (ctx context.Context ) error
37
37
}
38
38
39
- type commitItr struct {
39
+ type commitItr [ C Context ] struct {
40
40
ddb * DoltDB
41
41
rootCommits []* Commit
42
42
currentRoot int
@@ -47,7 +47,7 @@ type commitItr struct {
47
47
}
48
48
49
49
// CommitItrForAllBranches returns a CommitItr which will iterate over all commits in all branches in a DoltDB
50
- func CommitItrForAllBranches (ctx context.Context , ddb * DoltDB ) (CommitItr , error ) {
50
+ func CommitItrForAllBranches [ C Context ] (ctx context.Context , ddb * DoltDB ) (CommitItr [ C ] , error ) {
51
51
branchRefs , err := ddb .GetBranches (ctx )
52
52
53
53
if err != nil {
@@ -65,21 +65,21 @@ func CommitItrForAllBranches(ctx context.Context, ddb *DoltDB) (CommitItr, error
65
65
rootCommits = append (rootCommits , cm )
66
66
}
67
67
68
- cmItr := CommitItrForRoots (ddb , rootCommits ... )
68
+ cmItr := CommitItrForRoots [ C ] (ddb , rootCommits ... )
69
69
return cmItr , nil
70
70
}
71
71
72
72
// CommitItrForRoots will return a CommitItr which will iterate over all ancestor commits of the provided rootCommits.
73
- func CommitItrForRoots (ddb * DoltDB , rootCommits ... * Commit ) CommitItr {
74
- return & commitItr {
73
+ func CommitItrForRoots [ C Context ] (ddb * DoltDB , rootCommits ... * Commit ) CommitItr [ C ] {
74
+ return & commitItr [ C ] {
75
75
ddb : ddb ,
76
76
rootCommits : rootCommits ,
77
77
added : make (map [hash.Hash ]bool , 4096 ),
78
78
unprocessed : make ([]hash.Hash , 0 , 4096 ),
79
79
}
80
80
}
81
81
82
- func (cmItr * commitItr ) Reset (ctx context.Context ) error {
82
+ func (cmItr * commitItr [ C ] ) Reset (ctx context.Context ) error {
83
83
cmItr .curr = nil
84
84
cmItr .currentRoot = 0
85
85
cmItr .added = make (map [hash.Hash ]bool , 4096 )
@@ -90,7 +90,7 @@ func (cmItr *commitItr) Reset(ctx context.Context) error {
90
90
91
91
// Next returns the hash of the next commit, and a pointer to that commit. It handles making sure the list of commits
92
92
// returned are unique. When complete Next will return hash.Hash{}, nil, io.EOF
93
- func (cmItr * commitItr ) Next (ctx context. Context ) (hash.Hash , * OptionalCommit , error ) {
93
+ func (cmItr * commitItr [ C ] ) Next (ctx C ) (hash.Hash , * OptionalCommit , error ) {
94
94
for cmItr .curr == nil {
95
95
if cmItr .currentRoot >= len (cmItr .rootCommits ) {
96
96
return hash.Hash {}, nil , io .EOF
@@ -159,27 +159,31 @@ func HashToCommit(ctx context.Context, vrw types.ValueReadWriter, ns tree.NodeSt
159
159
return NewCommit (ctx , vrw , ns , dc )
160
160
}
161
161
162
+ type Context interface {
163
+ context.Context
164
+ }
165
+
162
166
// CommitFilter is a function that returns true if a commit should be filtered out, and false if it should be kept
163
- type CommitFilter func (context. Context , hash.Hash , * OptionalCommit ) (filterOut bool , err error )
167
+ type CommitFilter [ C Context ] func (C , hash.Hash , * OptionalCommit ) (filterOut bool , err error )
164
168
165
169
// FilteringCommitItr is a CommitItr implementation that applies a filtering function to limit the commits returned
166
- type FilteringCommitItr struct {
167
- itr CommitItr
168
- filter CommitFilter
170
+ type FilteringCommitItr [ C Context ] struct {
171
+ itr CommitItr [ C ]
172
+ filter CommitFilter [ C ]
169
173
}
170
174
171
175
// AllCommits is a CommitFilter that matches all commits
172
176
func AllCommits (_ context.Context , _ hash.Hash , _ * Commit ) (filterOut bool , err error ) {
173
177
return false , nil
174
178
}
175
179
176
- func NewFilteringCommitItr (itr CommitItr , filter CommitFilter ) FilteringCommitItr {
177
- return FilteringCommitItr {itr , filter }
180
+ func NewFilteringCommitItr [ C Context ] (itr CommitItr [ C ] , filter CommitFilter [ C ] ) FilteringCommitItr [ C ] {
181
+ return FilteringCommitItr [ C ] {itr , filter }
178
182
}
179
183
180
184
// Next returns the hash of the next commit, and a pointer to that commit. Implementations of Next must handle
181
185
// making sure the list of commits returned are unique. When complete Next will return hash.Hash{}, nil, io.EOF
182
- func (itr FilteringCommitItr ) Next (ctx context. Context ) (hash.Hash , * OptionalCommit , error ) {
186
+ func (itr FilteringCommitItr [ C ] ) Next (ctx C ) (hash.Hash , * OptionalCommit , error ) {
183
187
// iteration will terminate on io.EOF or a commit that is !filteredOut
184
188
for {
185
189
h , cm , err := itr .itr .Next (ctx )
@@ -197,23 +201,23 @@ func (itr FilteringCommitItr) Next(ctx context.Context) (hash.Hash, *OptionalCom
197
201
}
198
202
199
203
// Reset the commit iterator back to the
200
- func (itr FilteringCommitItr ) Reset (ctx context.Context ) error {
204
+ func (itr FilteringCommitItr [ C ] ) Reset (ctx context.Context ) error {
201
205
return itr .itr .Reset (ctx )
202
206
}
203
207
204
- func NewCommitSliceIter (cm []* Commit , h []hash.Hash ) * CommitSliceIter {
205
- return & CommitSliceIter {cm : cm , h : h }
208
+ func NewCommitSliceIter [ C Context ] (cm []* Commit , h []hash.Hash ) * CommitSliceIter [ C ] {
209
+ return & CommitSliceIter [ C ] {cm : cm , h : h }
206
210
}
207
211
208
- type CommitSliceIter struct {
212
+ type CommitSliceIter [ C Context ] struct {
209
213
h []hash.Hash
210
214
cm []* Commit
211
215
i int
212
216
}
213
217
214
- var _ CommitItr = (* CommitSliceIter )(nil )
218
+ var _ CommitItr [context. Context ] = (* CommitSliceIter [context. Context ] )(nil )
215
219
216
- func (i * CommitSliceIter ) Next (ctx context. Context ) (hash.Hash , * OptionalCommit , error ) {
220
+ func (i * CommitSliceIter [ C ] ) Next (ctx C ) (hash.Hash , * OptionalCommit , error ) {
217
221
if i .i >= len (i .h ) {
218
222
return hash.Hash {}, nil , io .EOF
219
223
}
@@ -222,25 +226,25 @@ func (i *CommitSliceIter) Next(ctx context.Context) (hash.Hash, *OptionalCommit,
222
226
223
227
}
224
228
225
- func (i * CommitSliceIter ) Reset (ctx context.Context ) error {
229
+ func (i * CommitSliceIter [ C ] ) Reset (ctx context.Context ) error {
226
230
i .i = 0
227
231
return nil
228
232
}
229
233
230
- func NewOneCommitIter (cm * Commit , h hash.Hash , meta * datas.CommitMeta ) * OneCommitIter {
231
- return & OneCommitIter {cm : & OptionalCommit {cm , h }, h : h }
234
+ func NewOneCommitIter [ C Context ] (cm * Commit , h hash.Hash , meta * datas.CommitMeta ) * OneCommitIter [ C ] {
235
+ return & OneCommitIter [ C ] {cm : & OptionalCommit {cm , h }, h : h }
232
236
}
233
237
234
- type OneCommitIter struct {
238
+ type OneCommitIter [ C Context ] struct {
235
239
h hash.Hash
236
240
cm * OptionalCommit
237
241
m * datas.CommitMeta
238
242
done bool
239
243
}
240
244
241
- var _ CommitItr = (* OneCommitIter )(nil )
245
+ var _ CommitItr [context. Context ] = (* OneCommitIter [context. Context ] )(nil )
242
246
243
- func (i * OneCommitIter ) Next (_ context. Context ) (hash.Hash , * OptionalCommit , error ) {
247
+ func (i * OneCommitIter [ C ] ) Next (_ C ) (hash.Hash , * OptionalCommit , error ) {
244
248
if i .done {
245
249
return hash.Hash {}, nil , io .EOF
246
250
}
@@ -249,7 +253,7 @@ func (i *OneCommitIter) Next(_ context.Context) (hash.Hash, *OptionalCommit, err
249
253
250
254
}
251
255
252
- func (i * OneCommitIter ) Reset (_ context.Context ) error {
256
+ func (i * OneCommitIter [ C ] ) Reset (_ context.Context ) error {
253
257
i .done = false
254
258
return nil
255
259
}
0 commit comments