Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

Commit f23141a

Browse files
committed
Added ParseObjectType function to core
1 parent 8e4fb52 commit f23141a

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

core/object.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,28 @@ func (t ObjectType) Bytes() []byte {
6464
return []byte(t.String())
6565
}
6666

67+
// ParseObjectType parses a string representation of ObjectType. It returns an
68+
// error on parse failure.
69+
func ParseObjectType(value string) (typ ObjectType, err error) {
70+
switch value {
71+
case "commit":
72+
typ = CommitObject
73+
case "tree":
74+
typ = TreeObject
75+
case "blob":
76+
typ = BlobObject
77+
case "tag":
78+
typ = TagObject
79+
case "ofs-delta":
80+
typ = OFSDeltaObject
81+
case "ref-delta":
82+
typ = REFDeltaObject
83+
default:
84+
err = errors.New("unable to parse object type")
85+
}
86+
return
87+
}
88+
6789
// ObjectIter is a generic closable interface for iterating over objects.
6890
type ObjectIter interface {
6991
Next() (Object, error)

0 commit comments

Comments
 (0)