aboutsummaryrefslogtreecommitdiff
path: root/format/commitgraph/read/iterators.go
blob: 85c56ff1e39cba57d3477f2b37cd721f24fe33ec (about) (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package read

import (
	"iter"

	"codeberg.org/lindenii/furgit/internal/intconv"
	objectid "codeberg.org/lindenii/furgit/object/id"
)

// AllPositions iterates all commit positions in native layer order.
func (reader *Reader) AllPositions() iter.Seq[Position] {
	return func(yield func(Position) bool) {
		for layerIdx := range reader.layers {
			layer := &reader.layers[layerIdx]

			graph, err := intconv.IntToUint32(layerIdx)
			if err != nil {
				return
			}

			for idx := range layer.numCommits {
				if !yield(Position{Graph: graph, Index: idx}) {
					return
				}
			}
		}
	}
}

// AllOIDs iterates all commit object IDs in native layer order.
func (reader *Reader) AllOIDs() iter.Seq[objectid.ObjectID] {
	return func(yield func(objectid.ObjectID) bool) {
		positions := reader.AllPositions()
		for pos := range positions {
			oid, err := reader.OIDAt(pos)
			if err != nil {
				return
			}

			if !yield(oid) {
				return
			}
		}
	}
}