diff options
| author | 2026-06-11 07:51:01 +0000 | |
|---|---|---|
| committer | 2026-06-11 07:51:01 +0000 | |
| commit | 4fb1f7a3000ca89445711fdf1400842b118861bd (patch) | |
| tree | 0b88fd56b67af5b869c24ab5cdc94c59957b3c50 /internal/format | |
| parent | object/id: Export MaxObjectIDSize (diff) | |
internal/format/packfile: Clean EntryType
Diffstat (limited to 'internal/format')
| -rw-r--r-- | internal/format/packfile/entry_type.go | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/internal/format/packfile/entry_type.go b/internal/format/packfile/entry_type.go index 784f9b69..1dbf0ba9 100644 --- a/internal/format/packfile/entry_type.go +++ b/internal/format/packfile/entry_type.go @@ -34,8 +34,8 @@ const ( EntryTypeRefDelta EntryType = 7 ) -// ObjectTypeToEntryType converts an ordinary [typ.Type] into a packfile [EntryType]. -func ObjectTypeToEntryType(ty typ.Type) (EntryType, error) { +// EntryTypeFromObjectType converts an ordinary [typ.Type] into a packfile [EntryType]. +func EntryTypeFromObjectType(ty typ.Type) (EntryType, error) { switch ty { case typ.Commit: return EntryTypeCommit, nil @@ -50,8 +50,8 @@ func ObjectTypeToEntryType(ty typ.Type) (EntryType, error) { return EntryTypeInvalid, ErrUnrepresentableObjectType } -// ObjectTypeToEntryType converts a a packfile [EntryType] into an ordinary [typ.Type]. -func (entryType EntryType) EntryTypeToObjectType() (typ.Type, error) { +// ObjectType converts a packfile [EntryType] into an ordinary [typ.Type]. +func (entryType EntryType) ObjectType() (typ.Type, error) { switch entryType { case EntryTypeCommit: return typ.Commit, nil @@ -65,3 +65,21 @@ func (entryType EntryType) EntryTypeToObjectType() (typ.Type, error) { return typ.Unknown, ErrInternalEntryType } + +// IsBase reports whether the entry type +// is a base (non-delta) object type. +func (entryType EntryType) IsBase() bool { + switch entryType { + case EntryTypeCommit, EntryTypeTree, EntryTypeBlob, EntryTypeTag: + return true + case EntryTypeInvalid, EntryTypeFuture, EntryTypeOfsDelta, EntryTypeRefDelta: + return false + default: + return false + } +} + +// IsDelta reports whether the entry type is a delta type. +func (entryType EntryType) IsDelta() bool { + return entryType == EntryTypeOfsDelta || entryType == EntryTypeRefDelta +} |
