aboutsummaryrefslogtreecommitdiff
path: root/object/fetch/object.go
diff options
context:
space:
mode:
authorGravatar Runxi Yu2026-06-08 07:15:15 +0000
committerGravatar Runxi Yu2026-06-08 07:15:15 +0000
commit404d7c088e46fd1bf655a7cfe0b0217eadb719be (patch)
treecdcff3f2d822158b5f5c5a37787ec0cfc2757bcd /object/fetch/object.go
parentobject/fetch: Port reader (diff)
object/fetch: port object
Diffstat (limited to 'object/fetch/object.go')
-rw-r--r--object/fetch/object.go41
1 files changed, 41 insertions, 0 deletions
diff --git a/object/fetch/object.go b/object/fetch/object.go
new file mode 100644
index 00000000..0ca88bfc
--- /dev/null
+++ b/object/fetch/object.go
@@ -0,0 +1,41 @@
+package fetch
+
+import (
+ "fmt"
+
+ "lindenii.org/go/furgit/object"
+ oid "lindenii.org/go/furgit/object/id"
+ "lindenii.org/go/furgit/object/stored"
+)
+
+// ExactObject reads, parses, and wraps the object at id without constraining
+// its concrete object kind.
+//
+// Labels: Life-Parent.
+func (r *Fetcher) ExactObject(id oid.ObjectID) (*stored.Stored[object.Object], error) {
+ parsed, err := r.parseObject(id)
+ if err != nil {
+ return nil, err
+ }
+
+ return stored.New(id, parsed), nil
+}
+
+func (r *Fetcher) parseObject(id oid.ObjectID) (object.Object, error) {
+ ty, content, err := r.store.ReadBytesContent(id)
+ if err != nil {
+ return nil, wrapObjectReadError(id, err)
+ }
+
+ parsed, err := object.ParseWithoutHeader(ty, content, id.ObjectFormat())
+ if err != nil {
+ tyName, ok := ty.Name()
+ if !ok {
+ tyName = fmt.Sprintf("type %d", ty)
+ }
+
+ return nil, fmt.Errorf("object/fetch: parse object %s (%s): %w", id, tyName, err)
+ }
+
+ return parsed, nil
+}