From 4fb1f7a3000ca89445711fdf1400842b118861bd Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Thu, 11 Jun 2026 07:51:01 +0000 Subject: internal/format/packfile: Clean EntryType --- internal/format/packfile/entry_type.go | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'internal/format') 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 +} -- cgit v1.3.1-10-gc9f91