aboutsummaryrefslogtreecommitdiff
path: root/obj.go
diff options
context:
space:
mode:
authorGravatar Runxi Yu2025-11-16 00:00:00 +0000
committerGravatar Runxi Yu2025-11-16 00:00:00 +0000
commit5cfbd8863dfb7c6af92497d9a5eb6eb63a6bd589 (patch)
tree42a871a72388bb6d40c479fbaa6eedde1cddc42e /obj.go
parenthash: Generic hash-algorithm API (diff)
signature
Revert "hash: Generic hash-algorithm API"
This reverts commit 94bfb1fa147f80e6ec39009d41fc2f853925e0a5. Generics actually kinda suck for these purposes... once you look at it from the user's perspective.
Diffstat (limited to 'obj.go')
-rw-r--r--obj.go29
1 files changed, 17 insertions, 12 deletions
diff --git a/obj.go b/obj.go
index 07b76c17..ce3d0258 100644
--- a/obj.go
+++ b/obj.go
@@ -29,10 +29,15 @@ const (
)
// Object describes any Git object variant.
-type Object[T HashType] interface {
+type Object interface {
ObjType() ObjType
}
+func computeRawHash(data []byte, hashSize int) Hash {
+ hashFunc := hashFuncs[hashSize]
+ return hashFunc(data)
+}
+
func headerForType(ty ObjType, body []byte) ([]byte, error) {
var tyStr string
switch ty {
@@ -59,11 +64,11 @@ func headerForType(ty ObjType, body []byte) ([]byte, error) {
return buf.Bytes(), nil
}
-func verifyRawObject[T HashType](buf []byte, want Hash[T]) bool {
- return computeRawHash[T](buf) == want
+func verifyRawObject(buf []byte, want Hash, hashSize int) bool {
+ return computeRawHash(buf, hashSize) == want
}
-func verifyTypedObject[T HashType](ty ObjType, body []byte, want Hash[T]) bool {
+func verifyTypedObject(ty ObjType, body []byte, want Hash, hashSize int) bool {
header, err := headerForType(ty, body)
if err != nil {
return false
@@ -71,19 +76,19 @@ func verifyTypedObject[T HashType](ty ObjType, body []byte, want Hash[T]) bool {
raw := make([]byte, len(header)+len(body))
copy(raw, header)
copy(raw[len(header):], body)
- return computeRawHash[T](raw) == want
+ return computeRawHash(raw, hashSize) == want
}
-func parseObjectBody[T HashType](ty ObjType, id Hash[T], body []byte) (Object[T], error) {
+func parseObjectBody(ty ObjType, id Hash, body []byte, hashSize int) (Object, error) {
switch ty {
case ObjBlob:
- return parseBlob[T](id, body)
+ return parseBlob(id, body)
case ObjTree:
- return parseTree[T](id, body)
+ return parseTree(id, body, hashSize)
case ObjCommit:
- return parseCommit[T](id, body)
+ return parseCommit(id, body, hashSize)
case ObjTag:
- return parseTag[T](id, body)
+ return parseTag(id, body, hashSize)
case ObjInvalid, ObjFuture, ObjOfsDelta, ObjRefDelta:
return nil, fmt.Errorf("furgit: object: unsupported type %d", ty)
default:
@@ -92,7 +97,7 @@ func parseObjectBody[T HashType](ty ObjType, id Hash[T], body []byte) (Object[T]
}
// ReadObject resolves an ID by consulting loose then packed storage.
-func (repo *Repository[T]) ReadObject(id Hash[T]) (Object[T], error) {
+func (repo *Repository) ReadObject(id Hash) (Object, error) {
obj, err := repo.looseRead(id)
if err == nil {
return obj, nil
@@ -108,7 +113,7 @@ func (repo *Repository[T]) ReadObject(id Hash[T]) (Object[T], error) {
}
// ReadObjectTypeSize reports the object type and size without inflating the body.
-func (repo *Repository[T]) ReadObjectTypeSize(id Hash[T]) (ObjType, int64, error) {
+func (repo *Repository) ReadObjectTypeSize(id Hash) (ObjType, int64, error) {
ty, size, err := repo.looseTypeSize(id)
if err == nil {
return ty, size, nil