diff options
| author | 2026-03-06 08:05:51 +0800 | |
|---|---|---|
| committer | 2026-03-06 10:00:35 +0800 | |
| commit | e15054a4f93fc54806e84aa7036e60168e78e823 (patch) | |
| tree | b576dcb1d3368324e7ca73ca0fe79dd8865c5524 /format/commitgraph/oidat.go | |
| parent | internal/intconv: Add Uint32ToUint8 (diff) | |
| signature | No signature | |
format/commitgraph: Add initial commit-graph support
Diffstat (limited to 'format/commitgraph/oidat.go')
| -rw-r--r-- | format/commitgraph/oidat.go | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/format/commitgraph/oidat.go b/format/commitgraph/oidat.go new file mode 100644 index 00000000..e277125b --- /dev/null +++ b/format/commitgraph/oidat.go @@ -0,0 +1,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]) +} |
