diff options
| author | 2026-03-06 11:54:21 +0800 | |
|---|---|---|
| committer | 2026-03-06 11:55:56 +0800 | |
| commit | c62c5544fa23378843a3383a9dcd4494e5ea33bc (patch) | |
| tree | 8b825a36767fe0ba3fb44f27cb634047c4c0318f /format/commitgraph/read/iterators.go | |
| parent | format/pack/ingest: Fix delta apply import (diff) | |
| signature | No signature | |
format/commitgraph: Split into ./read and ./ v0.1.60
Diffstat (limited to 'format/commitgraph/read/iterators.go')
| -rw-r--r-- | format/commitgraph/read/iterators.go | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/format/commitgraph/read/iterators.go b/format/commitgraph/read/iterators.go new file mode 100644 index 00000000..d4ad9105 --- /dev/null +++ b/format/commitgraph/read/iterators.go @@ -0,0 +1,45 @@ +package read + +import ( + "iter" + + "codeberg.org/lindenii/furgit/internal/intconv" + "codeberg.org/lindenii/furgit/objectid" +) + +// 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 + } + } + } +} |
