aboutsummaryrefslogtreecommitdiff
path: root/format/commitgraph/oidat.go
blob: e277125bdf41c2cfe4d73dfdfc3405cf0a1db55a (about) (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package commitgraph

import (
	"codeberg.org/lindenii/furgit/internal/intconv"
	"codeberg.org/lindenii/furgit/objectid"
)

// OIDAt returns object ID at one position.
func (reader *Reader) OIDAt(pos Position) (objectid.ObjectID, error) {
	layer, err := reader.layerByPosition(pos)
	if err != nil {
		return objectid.ObjectID{}, err
	}

	hashSize := reader.algo.Size()

	hashSizeU64, err := intconv.IntToUint64(hashSize)
	if err != nil {
		return objectid.ObjectID{}, err
	}

	start64 := uint64(pos.Index) * hashSizeU64
	end64 := start64 + hashSizeU64

	start, err := intconv.Uint64ToInt(start64)
	if err != nil {
		return objectid.ObjectID{}, err
	}

	end, err := intconv.Uint64ToInt(end64)
	if err != nil {
		return objectid.ObjectID{}, err
	}

	return objectid.FromBytes(reader.algo, layer.chunkOIDLookup[start:end])
}