diff options
-rw-r--r-- | core/object.go | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/core/object.go b/core/object.go index e64f650..74ea555 100644 --- a/core/object.go +++ b/core/object.go @@ -64,6 +64,28 @@ func (t ObjectType) Bytes() []byte { return []byte(t.String()) } +// ParseObjectType parses a string representation of ObjectType. It returns an +// error on parse failure. +func ParseObjectType(value string) (typ ObjectType, err error) { + switch value { + case "commit": + typ = CommitObject + case "tree": + typ = TreeObject + case "blob": + typ = BlobObject + case "tag": + typ = TagObject + case "ofs-delta": + typ = OFSDeltaObject + case "ref-delta": + typ = REFDeltaObject + default: + err = errors.New("unable to parse object type") + } + return +} + // ObjectIter is a generic closable interface for iterating over objects. type ObjectIter interface { Next() (Object, error) |