Fast implementation of Git in pure Go
1package read
2
3import (
4 "encoding/binary"
5
6 "codeberg.org/lindenii/furgit/commitgraph"
7 "codeberg.org/lindenii/furgit/internal/intconv"
8)
9
10func (reader *Reader) readGenerationV2(layer *layer, index uint32, commitTime uint64) (uint64, error) {
11 if len(layer.chunkGeneration) == 0 {
12 return 0, nil
13 }
14
15 off64 := uint64(index) * 4
16
17 off, err := intconv.Uint64ToInt(off64)
18 if err != nil {
19 return 0, err
20 }
21
22 value := binary.BigEndian.Uint32(layer.chunkGeneration[off : off+4])
23
24 if value&commitgraph.GenerationOverflow == 0 {
25 return commitTime + uint64(value), nil
26 }
27
28 gdo2Index := value ^ commitgraph.GenerationOverflow
29 gdo2Off64 := uint64(gdo2Index) * 8
30
31 gdo2Off, err := intconv.Uint64ToInt(gdo2Off64)
32 if err != nil {
33 return 0, err
34 }
35
36 if gdo2Off+8 > len(layer.chunkGenerationOv) {
37 return 0, &MalformedError{Path: layer.path, Reason: "GDO2 index out of range"}
38 }
39
40 overflow := binary.BigEndian.Uint64(layer.chunkGenerationOv[gdo2Off : gdo2Off+8])
41
42 return commitTime + overflow, nil
43}