diff options
| author | 2026-05-16 08:20:35 +0000 | |
|---|---|---|
| committer | 2026-05-16 08:20:35 +0000 | |
| commit | 890dff2213ae15e1a952471d3218577e93265bb6 (patch) | |
| tree | 6efe02b60189945bbd890388c03bf44a8fef33d2 | |
| parent | object/id: done from REFACTOR (diff) | |
| signature | No signature | |
object/typ: Simplify
| -rw-r--r-- | object/typ/errors.go | 5 | ||||
| -rw-r--r-- | object/typ/type.go | 15 | ||||
| -rw-r--r-- | object/typ/type_details.go | 1 | ||||
| -rw-r--r-- | object/typ/type_ops.go | 9 | ||||
| -rw-r--r-- | object/typ/type_parse.go | 8 |
5 files changed, 19 insertions, 19 deletions
diff --git a/object/typ/errors.go b/object/typ/errors.go new file mode 100644 index 00000000..8a442db0 --- /dev/null +++ b/object/typ/errors.go @@ -0,0 +1,5 @@ +package typ + +import "errors" + +var ErrInvalidType = errors.New("object/typ: Invalid type")
\ No newline at end of file diff --git a/object/typ/type.go b/object/typ/type.go index 5f7decc1..7a317479 100644 --- a/object/typ/type.go +++ b/object/typ/type.go @@ -4,18 +4,15 @@ package typ type Type uint8 const ( - // TypeInvalid represents an invalid Git object type. - TypeInvalid Type = 0 - - // TypeCommit represents a Git commit. - TypeCommit Type = 1 + // TypeBlob represents a Git blob. + TypeBlob Type = iota // TypeTree represents a Git tree. - TypeTree Type = 2 + TypeTree - // TypeBlob represents a Git blob. - TypeBlob Type = 3 + // TypeCommit represents a Git commit. + TypeCommit // TypeTag represents a Git tag. - TypeTag Type = 4 + TypeTag ) diff --git a/object/typ/type_details.go b/object/typ/type_details.go index ebe1bbbe..f8a18837 100644 --- a/object/typ/type_details.go +++ b/object/typ/type_details.go @@ -10,7 +10,6 @@ func (ty Type) details() typeDetails { //nolint:gochecknoglobals var typeTable = [...]typeDetails{ - TypeInvalid: {name: ""}, TypeCommit: {name: "commit"}, TypeTree: {name: "tree"}, TypeBlob: {name: "blob"}, diff --git a/object/typ/type_ops.go b/object/typ/type_ops.go index 535c7296..81570ab8 100644 --- a/object/typ/type_ops.go +++ b/object/typ/type_ops.go @@ -1,11 +1,6 @@ package typ // Name returns the canonical Git object type name. -func (ty Type) Name() (string, bool) { - details := ty.details() - if details.name == "" { - return "", false - } - - return details.name, true +func (ty Type) Name() (string) { + return ty.details().name } diff --git a/object/typ/type_parse.go b/object/typ/type_parse.go index a39a1949..3b69fc09 100644 --- a/object/typ/type_parse.go +++ b/object/typ/type_parse.go @@ -1,8 +1,12 @@ package typ // Parse parses a canonical Git object type name. -func Parse(name string) (Type, bool) { +func Parse(name string) (Type, error) { ty, ok := typeByName[name] - return ty, ok + if !ok { + return 0, ErrInvalidType + } + + return ty, nil } |
