From e15054a4f93fc54806e84aa7036e60168e78e823 Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Fri, 6 Mar 2026 08:05:51 +0800 Subject: format/commitgraph: Add initial commit-graph support --- format/commitgraph/iterators.go | 45 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 format/commitgraph/iterators.go (limited to 'format/commitgraph/iterators.go') 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 + } + } + } +} -- cgit v1.3.1-10-gc9f91