diff options
Diffstat (limited to 'object/fetch/object.go')
| -rw-r--r-- | object/fetch/object.go | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/object/fetch/object.go b/object/fetch/object.go new file mode 100644 index 00000000..fdb46634 --- /dev/null +++ b/object/fetch/object.go @@ -0,0 +1,36 @@ +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 (fetcher *Fetcher) ExactObject(id oid.ObjectID) (*stored.Stored[object.Object], error) { + parsed, err := fetcher.parseObject(id) + if err != nil { + return nil, err + } + + return stored.New(id, parsed), nil +} + +func (fetcher *Fetcher) parseObject(id oid.ObjectID) (object.Object, error) { //nolint:ireturn + ty, content, err := fetcher.store.ReadBytesContent(id) + if err != nil { + return nil, wrapObjectReadError(id, err) + } + + parsed, err := object.ParseWithoutHeader(ty, content, id.ObjectFormat()) + if err != nil { + return nil, fmt.Errorf("object/fetch: parse object %s (%s): %w", id, ty.Name(), err) + } + + return parsed, nil +} |
