aboutsummaryrefslogtreecommitdiff
path: root/format/commitgraph/bloom/settings.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/commitgraph/bloom/settings.go
parentnetwork/receivepack: Rename from receivepack (diff)
signatureNo signature
format: Move commitgraph and packfile here
Diffstat (limited to 'format/commitgraph/bloom/settings.go')
-rw-r--r--format/commitgraph/bloom/settings.go50
1 files changed, 50 insertions, 0 deletions
diff --git a/format/commitgraph/bloom/settings.go b/format/commitgraph/bloom/settings.go
new file mode 100644
index 00000000..764653bd
--- /dev/null
+++ b/format/commitgraph/bloom/settings.go
@@ -0,0 +1,50 @@
+package bloom
+
+import (
+ "encoding/binary"
+
+ "codeberg.org/lindenii/furgit/internal/intconv"
+)
+
+// Settings describe the changed-paths Bloom filter parameters stored in
+// commit-graph BDAT chunks.
+//
+// Obviously, they must match the repository's commit-graph settings to
+// interpret filters correctly.
+type Settings struct {
+ HashVersion uint32
+ NumHashes uint32
+ BitsPerEntry uint32
+ MaxChangePaths uint32
+}
+
+// ParseSettings reads Bloom filter settings from a BDAT chunk header.
+func ParseSettings(bdat []byte) (*Settings, error) {
+ if len(bdat) < DataHeaderSize {
+ return nil, ErrInvalid
+ }
+
+ settings := &Settings{
+ HashVersion: binary.BigEndian.Uint32(bdat[0:4]),
+ NumHashes: binary.BigEndian.Uint32(bdat[4:8]),
+ BitsPerEntry: binary.BigEndian.Uint32(bdat[8:12]),
+ MaxChangePaths: DefaultMaxChange,
+ }
+
+ switch settings.HashVersion {
+ case 1, 2:
+ default:
+ return nil, ErrInvalid
+ }
+
+ if settings.NumHashes == 0 {
+ return nil, ErrInvalid
+ }
+
+ _, err := intconv.Uint32ToInt(settings.NumHashes)
+ if err != nil {
+ return nil, ErrInvalid
+ }
+
+ return settings, nil
+}