diff options
| author | 2026-03-10 13:30:48 +0800 | |
|---|---|---|
| committer | 2026-03-10 13:30:48 +0800 | |
| commit | 73e602a5c2c766caba59948e91c11122653705ec (patch) | |
| tree | 57951a4275dd90c2b3953e5b4bf3c9a7bd09b84a /commitgraph/read/generation.go | |
| parent | *: Move sideband64k and pktline to protocol/ (diff) | |
| signature | No signature | |
commitgraph: Move out of format/
Diffstat (limited to 'commitgraph/read/generation.go')
| -rw-r--r-- | commitgraph/read/generation.go | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/commitgraph/read/generation.go b/commitgraph/read/generation.go new file mode 100644 index 00000000..53dabe2d --- /dev/null +++ b/commitgraph/read/generation.go @@ -0,0 +1,43 @@ +package read + +import ( + "encoding/binary" + + "codeberg.org/lindenii/furgit/commitgraph" + "codeberg.org/lindenii/furgit/internal/intconv" +) + +func (reader *Reader) readGenerationV2(layer *layer, index uint32, commitTime uint64) (uint64, error) { + if len(layer.chunkGeneration) == 0 { + return 0, nil + } + + off64 := uint64(index) * 4 + + off, err := intconv.Uint64ToInt(off64) + if err != nil { + return 0, err + } + + value := binary.BigEndian.Uint32(layer.chunkGeneration[off : off+4]) + + if value&commitgraph.GenerationOverflow == 0 { + return commitTime + uint64(value), nil + } + + gdo2Index := value ^ commitgraph.GenerationOverflow + gdo2Off64 := uint64(gdo2Index) * 8 + + gdo2Off, err := intconv.Uint64ToInt(gdo2Off64) + if err != nil { + return 0, err + } + + if gdo2Off+8 > len(layer.chunkGenerationOv) { + return 0, &MalformedError{Path: layer.path, Reason: "GDO2 index out of range"} + } + + overflow := binary.BigEndian.Uint64(layer.chunkGenerationOv[gdo2Off : gdo2Off+8]) + + return commitTime + overflow, nil +} |
