aboutsummaryrefslogtreecommitdiff
path: root/format/commitgraph/read/edges.go
diff options
context:
space:
mode:
authorGravatar Runxi Yu2026-03-06 11:54:21 +0800
committerGravatar Runxi Yu2026-03-06 11:55:56 +0800
commitc62c5544fa23378843a3383a9dcd4494e5ea33bc (patch)
tree8b825a36767fe0ba3fb44f27cb634047c4c0318f /format/commitgraph/read/edges.go
parentformat/pack/ingest: Fix delta apply import (diff)
signatureNo signature
format/commitgraph: Split into ./read and ./ v0.1.60
Diffstat (limited to 'format/commitgraph/read/edges.go')
-rw-r--r--format/commitgraph/read/edges.go48
1 files changed, 48 insertions, 0 deletions
diff --git a/format/commitgraph/read/edges.go b/format/commitgraph/read/edges.go
new file mode 100644
index 00000000..de8bab60
--- /dev/null
+++ b/format/commitgraph/read/edges.go
@@ -0,0 +1,48 @@
+package read
+
+import (
+ "encoding/binary"
+
+ "codeberg.org/lindenii/furgit/format/commitgraph"
+ "codeberg.org/lindenii/furgit/internal/intconv"
+)
+
+func (reader *Reader) decodeExtraEdgeList(layer *layer, edgeStart uint32) ([]Position, error) {
+ if len(layer.chunkExtraEdges) == 0 {
+ return nil, &ErrMalformed{Path: layer.path, Reason: "missing EDGE chunk"}
+ }
+
+ out := make([]Position, 0)
+
+ cur := edgeStart
+ for {
+ off64 := uint64(cur) * 4
+
+ off, err := intconv.Uint64ToInt(off64)
+ if err != nil {
+ return nil, err
+ }
+
+ if off+4 > len(layer.chunkExtraEdges) {
+ return nil, &ErrMalformed{Path: layer.path, Reason: "EDGE index out of range"}
+ }
+
+ word := binary.BigEndian.Uint32(layer.chunkExtraEdges[off : off+4])
+ parentGlobal := word & commitgraph.ParentLastMask
+
+ parentPos, err := reader.globalToPosition(parentGlobal)
+ if err != nil {
+ return nil, err
+ }
+
+ out = append(out, parentPos)
+
+ if word&commitgraph.ParentExtraMask != 0 {
+ break
+ }
+
+ cur++
+ }
+
+ return out, nil
+}