@@ -28,9 +28,11 @@ import (
2828
2929// CommitItr is an interface for iterating over a set of unique commits
3030type CommitItr [C Context ] interface {
31- // Next returns the hash of the next commit, and a pointer to that commit. Implementations of Next must handle
32- // making sure the list of commits returned are unique. When complete Next will return hash.Hash{}, nil, io.EOF
33- Next (ctx C ) (hash.Hash , * OptionalCommit , error )
31+ // Next returns the next commit's hash, pointer, metadata, and height.
32+ // Implementations of Next must handle making sure the list of commits returned are unique.
33+ // When complete Next will return hash.Hash{}, nil, nil, 0, io.EOF
34+ // Note: Some implementations may always return nil for the metadata and height return values.
35+ Next (ctx C ) (hash.Hash , * OptionalCommit , * datas.CommitMeta , uint64 , error )
3436
3537 // Reset the commit iterator back to the start
3638 Reset (ctx context.Context ) error
@@ -88,25 +90,27 @@ func (cmItr *commitItr[C]) Reset(ctx context.Context) error {
8890 return nil
8991}
9092
91- // Next returns the hash of the next commit, and a pointer to that commit. It handles making sure the list of commits
92- // returned are unique. When complete Next will return hash.Hash{}, nil, io.EOF
93- func (cmItr * commitItr [C ]) Next (ctx C ) (hash.Hash , * OptionalCommit , error ) {
93+ // Next returns the hash of the next commit, and a pointer to that commit.
94+ // It handles making sure the list of commits returned are unique.
95+ // When complete Next will return hash.Hash{}, nil, nil, 0, io.EOF.
96+ // Note: This implementation always returns nil for the metadata and height return values.
97+ func (cmItr * commitItr [C ]) Next (ctx C ) (hash.Hash , * OptionalCommit , * datas.CommitMeta , uint64 , error ) {
9498 for cmItr .curr == nil {
9599 if cmItr .currentRoot >= len (cmItr .rootCommits ) {
96- return hash.Hash {}, nil , io .EOF
100+ return hash.Hash {}, nil , nil , 0 , io .EOF
97101 }
98102
99103 cm := cmItr .rootCommits [cmItr .currentRoot ]
100104 h , err := cm .HashOf ()
101105
102106 if err != nil {
103- return hash.Hash {}, nil , err
107+ return hash.Hash {}, nil , nil , 0 , err
104108 }
105109
106110 if ! cmItr .added [h ] {
107111 cmItr .added [h ] = true
108112 cmItr .curr = cm
109- return h , & OptionalCommit {cmItr .curr , h }, nil
113+ return h , & OptionalCommit {cmItr .curr , h }, nil , 0 , nil
110114 }
111115
112116 cmItr .currentRoot ++
@@ -115,7 +119,7 @@ func (cmItr *commitItr[C]) Next(ctx C) (hash.Hash, *OptionalCommit, error) {
115119 parents , err := cmItr .curr .ParentHashes (ctx )
116120
117121 if err != nil {
118- return hash.Hash {}, nil , err
122+ return hash.Hash {}, nil , nil , 0 , err
119123 }
120124
121125 for _ , h := range parents {
@@ -137,13 +141,13 @@ func (cmItr *commitItr[C]) Next(ctx C) (hash.Hash, *OptionalCommit, error) {
137141 cmItr .unprocessed = cmItr .unprocessed [:numUnprocessed - 1 ]
138142 cmItr .curr , err = HashToCommit (ctx , cmItr .ddb .ValueReadWriter (), cmItr .ddb .ns , next )
139143 if err != nil && err != ErrGhostCommitEncountered {
140- return hash.Hash {}, nil , err
144+ return hash.Hash {}, nil , nil , 0 , err
141145 }
142146 if err == ErrGhostCommitEncountered {
143147 cmItr .curr = nil
144148 }
145149
146- return next , & OptionalCommit {cmItr .curr , next }, nil
150+ return next , & OptionalCommit {cmItr .curr , next }, nil , 0 , nil
147151}
148152
149153func HashToCommit (ctx context.Context , vrw types.ValueReadWriter , ns tree.NodeStore , h hash.Hash ) (* Commit , error ) {
@@ -183,19 +187,18 @@ func NewFilteringCommitItr[C Context](itr CommitItr[C], filter CommitFilter[C])
183187
184188// Next returns the hash of the next commit, and a pointer to that commit. Implementations of Next must handle
185189// making sure the list of commits returned are unique. When complete Next will return hash.Hash{}, nil, io.EOF
186- func (itr FilteringCommitItr [C ]) Next (ctx C ) (hash.Hash , * OptionalCommit , error ) {
190+ func (itr FilteringCommitItr [C ]) Next (ctx C ) (hash.Hash , * OptionalCommit , * datas. CommitMeta , uint64 , error ) {
187191 // iteration will terminate on io.EOF or a commit that is !filteredOut
188192 for {
189- h , cm , err := itr .itr .Next (ctx )
190-
193+ h , cm , meta , height , err := itr .itr .Next (ctx )
191194 if err != nil {
192- return hash.Hash {}, nil , err
195+ return hash.Hash {}, nil , nil , 0 , err
193196 }
194197
195198 if filterOut , err := itr .filter (ctx , h , cm ); err != nil {
196- return hash.Hash {}, nil , err
199+ return hash.Hash {}, nil , nil , 0 , err
197200 } else if ! filterOut {
198- return h , cm , nil
201+ return h , cm , meta , height , nil
199202 }
200203 }
201204}
@@ -217,12 +220,14 @@ type CommitSliceIter[C Context] struct {
217220
218221var _ CommitItr [context.Context ] = (* CommitSliceIter [context.Context ])(nil )
219222
220- func (i * CommitSliceIter [C ]) Next (ctx C ) (hash.Hash , * OptionalCommit , error ) {
223+ // Next implements the CommitItr interface.
224+ // Note: This implementation always returns nil for the metadata and height return values.
225+ func (i * CommitSliceIter [C ]) Next (ctx C ) (hash.Hash , * OptionalCommit , * datas.CommitMeta , uint64 , error ) {
221226 if i .i >= len (i .h ) {
222- return hash.Hash {}, nil , io .EOF
227+ return hash.Hash {}, nil , nil , 0 , io .EOF
223228 }
224229 i .i ++
225- return i .h [i .i - 1 ], & OptionalCommit {i .cm [i .i - 1 ], i .h [i .i - 1 ]}, nil
230+ return i .h [i .i - 1 ], & OptionalCommit {i .cm [i .i - 1 ], i .h [i .i - 1 ]}, nil , 0 , nil
226231
227232}
228233
@@ -232,7 +237,7 @@ func (i *CommitSliceIter[C]) Reset(ctx context.Context) error {
232237}
233238
234239func NewOneCommitIter [C Context ](cm * Commit , h hash.Hash , meta * datas.CommitMeta ) * OneCommitIter [C ] {
235- return & OneCommitIter [C ]{cm : & OptionalCommit {cm , h }, h : h }
240+ return & OneCommitIter [C ]{cm : & OptionalCommit {cm , h }, h : h , m : meta }
236241}
237242
238243type OneCommitIter [C Context ] struct {
@@ -244,13 +249,14 @@ type OneCommitIter[C Context] struct {
244249
245250var _ CommitItr [context.Context ] = (* OneCommitIter [context.Context ])(nil )
246251
247- func (i * OneCommitIter [C ]) Next (_ C ) (hash.Hash , * OptionalCommit , error ) {
252+ // Next implements the CommitItr interface.
253+ // Note: This implementation always returns nil for the metadata and height return values.
254+ func (i * OneCommitIter [C ]) Next (_ C ) (hash.Hash , * OptionalCommit , * datas.CommitMeta , uint64 , error ) {
248255 if i .done {
249- return hash.Hash {}, nil , io .EOF
256+ return hash.Hash {}, nil , nil , 0 , io .EOF
250257 }
251258 i .done = true
252- return i .h , i .cm , nil
253-
259+ return i .h , i .cm , i .m , 0 , nil
254260}
255261
256262func (i * OneCommitIter [C ]) Reset (_ context.Context ) error {
0 commit comments