aboutsummaryrefslogtreecommitdiff
path: root/format/commitgraph/iterators.go
diff options
context:
space:
mode:
authorGravatar Runxi Yu2026-03-06 08:05:51 +0800
committerGravatar Runxi Yu2026-03-06 10:00:35 +0800
commite15054a4f93fc54806e84aa7036e60168e78e823 (patch)
treeb576dcb1d3368324e7ca73ca0fe79dd8865c5524 /format/commitgraph/iterators.go
parentinternal/intconv: Add Uint32ToUint8 (diff)
signatureNo signature
format/commitgraph: Add initial commit-graph support
Diffstat (limited to 'format/commitgraph/iterators.go')
-rw-r--r--format/commitgraph/iterators.go45
1 files changed, 45 insertions, 0 deletions
diff --git a/format/commitgraph/iterators.go b/format/commitgraph/iterators.go
new file mode 100644
index 00000000..27385709
--- /dev/null
+++ b/format/commitgraph/iterators.go
@@ -0,0 +1,45 @@
+package commitgraph
+
+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
+ }
+ }
+ }
+}