aboutsummaryrefslogtreecommitdiff
path: root/format/packfile/ingest/entry_header.go
diff options
context:
space:
mode:
authorGravatar Runxi Yu2026-03-26 09:17:14 +0000
committerGravatar Runxi Yu2026-03-26 09:18:30 +0000
commit3e884f5f3d42cbc4874a04da31dde10314b0cfad (patch)
treef5e1e325fd1a2a0801791c054010213214475d80 /format/packfile/ingest/entry_header.go
parentnetwork/receivepack: Rename from receivepack (diff)
signatureNo signature
format: Move commitgraph and packfile here
Diffstat (limited to 'format/packfile/ingest/entry_header.go')
-rw-r--r--format/packfile/ingest/entry_header.go33
1 files changed, 33 insertions, 0 deletions
diff --git a/format/packfile/ingest/entry_header.go b/format/packfile/ingest/entry_header.go
new file mode 100644
index 00000000..c74fdc16
--- /dev/null
+++ b/format/packfile/ingest/entry_header.go
@@ -0,0 +1,33 @@
+package ingest
+
+import (
+ "codeberg.org/lindenii/furgit/internal/intconv"
+ objecttype "codeberg.org/lindenii/furgit/object/type"
+)
+
+// encodePackEntryHeader encodes one non-delta packed entry header.
+func encodePackEntryHeader(ty objecttype.Type, size int64) []byte {
+ var out [16]byte
+
+ n := 0
+
+ s, err := intconv.Int64ToUint64(size)
+ if err != nil {
+ panic(err)
+ }
+
+ c := (uint8(ty) << 4) | byte(s&0x0f)
+
+ s >>= 4
+ for s != 0 {
+ out[n] = c | 0x80
+ n++
+ c = byte(s & 0x7f)
+ s >>= 7
+ }
+
+ out[n] = c
+ n++
+
+ return append([]byte(nil), out[:n]...)
+}