aboutsummaryrefslogtreecommitdiff
path: root/packed_read_idx.go
diff options
context:
space:
mode:
authorGravatar Runxi Yu2026-02-20 12:49:27 +0800
committerGravatar Runxi Yu2026-02-20 12:57:31 +0800
commit4e4b630fe88b0f5c1f6f934a760632b9efbeaaf0 (patch)
tree0663e407a65684d4da43fd578c4e27bdef127805 /packed_read_idx.go
parentRevert "README: Writing packfiles has deltas now, but not thin packs" (diff)
signatureNo signature
Revert "packed: Cleanup"
This reverts commit 45da63f4d0fd94e5a8b11fc6aa8b626338dcabf8.
Diffstat (limited to 'packed_read_idx.go')
-rw-r--r--packed_read_idx.go26
1 files changed, 19 insertions, 7 deletions
diff --git a/packed_read_idx.go b/packed_read_idx.go
index 515ccdc0..0dbb9bcf 100644
--- a/packed_read_idx.go
+++ b/packed_read_idx.go
@@ -2,7 +2,6 @@ package furgit
import (
"bytes"
- "encoding/binary"
"errors"
"fmt"
"os"
@@ -147,10 +146,10 @@ func (pi *packIndex) parse(buf []byte) error {
if len(buf) < 8+256*4 {
return ErrInvalidObject
}
- if binary.BigEndian.Uint32(buf[0:4]) != idxMagic {
+ if readBE32(buf[0:4]) != idxMagic {
return ErrInvalidObject
}
- if binary.BigEndian.Uint32(buf[4:8]) != idxVersion2 {
+ if readBE32(buf[4:8]) != idxVersion2 {
return ErrInvalidObject
}
@@ -161,7 +160,7 @@ func (pi *packIndex) parse(buf []byte) error {
return ErrInvalidObject
}
pi.fanout = buf[fanoutStart:fanoutEnd]
- nobj := int(binary.BigEndian.Uint32(pi.fanout[len(pi.fanout)-4:]))
+ nobj := int(readBE32(pi.fanout[len(pi.fanout)-4:]))
namesStart := fanoutEnd
namesEnd := namesStart + nobj*pi.repo.hashAlgo.Size()
@@ -200,6 +199,19 @@ func (pi *packIndex) parse(buf []byte) error {
return nil
}
+func readBE32(b []byte) uint32 {
+ _ = b[3]
+ return uint32(b[0])<<24 | uint32(b[1])<<16 | uint32(b[2])<<8 | uint32(b[3])
+}
+
+func readBE64(b []byte) uint64 {
+ _ = b[7]
+ return (uint64(b[0]) << 56) | (uint64(b[1]) << 48) |
+ (uint64(b[2]) << 40) | (uint64(b[3]) << 32) |
+ (uint64(b[4]) << 24) | (uint64(b[5]) << 16) |
+ (uint64(b[6]) << 8) | uint64(b[7])
+}
+
func (pi *packIndex) fanoutEntry(i int) uint32 {
if len(pi.fanout) == 0 {
return 0
@@ -209,12 +221,12 @@ func (pi *packIndex) fanoutEntry(i int) uint32 {
return 0
}
start := i * 4
- return binary.BigEndian.Uint32(pi.fanout[start : start+4])
+ return readBE32(pi.fanout[start : start+4])
}
func (pi *packIndex) offset(idx int) (uint64, error) {
start := idx * 4
- word := binary.BigEndian.Uint32(pi.offset32[start : start+4])
+ word := readBE32(pi.offset32[start : start+4])
if word&0x80000000 == 0 {
return uint64(word), nil
}
@@ -224,7 +236,7 @@ func (pi *packIndex) offset(idx int) (uint64, error) {
return 0, errors.New("furgit: pack: corrupt 64-bit offset table")
}
base := pos * 8
- return binary.BigEndian.Uint64(pi.offset64[base : base+8]), nil
+ return readBE64(pi.offset64[base : base+8]), nil
}
func (pi *packIndex) lookup(id Hash) (packlocation, error) {