aboutsummaryrefslogtreecommitdiff
path: root/obj.go
diff options
context:
space:
mode:
authorGravatar Runxi Yu2025-11-14 00:00:00 +0000
committerGravatar Runxi Yu2025-11-14 00:00:00 +0000
commit9ef659a016d4ffeac931291984a4c71f9527a747 (patch)
tree957a76630fe248b638c0a9c84f7acef40a7ee9f5 /obj.go
parentInitial commit (diff)
signature
Read types and sizes without inflating entire object
Diffstat (limited to 'obj.go')
-rw-r--r--obj.go19
1 files changed, 19 insertions, 0 deletions
diff --git a/obj.go b/obj.go
index 5ce639f9..d3d69c25 100644
--- a/obj.go
+++ b/obj.go
@@ -117,3 +117,22 @@ func (repo *Repository) ReadObject(id Hash) (Object, error) {
}
return obj, err
}
+
+// ReadObjectTypeSize reports the object type and size without inflating the body.
+func (repo *Repository) ReadObjectTypeSize(id Hash) (ObjType, int64, error) {
+ ty, size, err := repo.looseTypeSize(id)
+ if err == nil {
+ return ty, size, nil
+ }
+ if !errors.Is(err, ErrNotFound) {
+ return ObjInvalid, 0, err
+ }
+ loc, err := repo.packIndexFind(id)
+ if err != nil {
+ if errors.Is(err, ErrNotFound) {
+ return ObjInvalid, 0, ErrInvalidObject
+ }
+ return ObjInvalid, 0, err
+ }
+ return repo.packTypeSizeAtLocation(loc, nil)
+}