From 73e602a5c2c766caba59948e91c11122653705ec Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Tue, 10 Mar 2026 13:30:48 +0800 Subject: commitgraph: Move out of format/ --- commitgraph/read/edges.go | 48 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 commitgraph/read/edges.go (limited to 'commitgraph/read/edges.go') diff --git a/commitgraph/read/edges.go b/commitgraph/read/edges.go new file mode 100644 index 00000000..33a6c9fc --- /dev/null +++ b/commitgraph/read/edges.go @@ -0,0 +1,48 @@ +package read + +import ( + "encoding/binary" + + "codeberg.org/lindenii/furgit/commitgraph" + "codeberg.org/lindenii/furgit/internal/intconv" +) + +func (reader *Reader) decodeExtraEdgeList(layer *layer, edgeStart uint32) ([]Position, error) { + if len(layer.chunkExtraEdges) == 0 { + return nil, &MalformedError{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, &MalformedError{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 +} -- cgit v1.3.1-10-gc9f91