diff options
Diffstat (limited to 'object/tree/mode/ops.go')
| -rw-r--r-- | object/tree/mode/ops.go | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/object/tree/mode/ops.go b/object/tree/mode/ops.go new file mode 100644 index 00000000..149d95db --- /dev/null +++ b/object/tree/mode/ops.go @@ -0,0 +1,38 @@ +package mode + +import "lindenii.org/go/furgit/object/typ" + +// IsValid reports whether mode is a canonical mode that Git writes. +func (mode Mode) IsValid() bool { + return mode.details().valid +} + +// IsBlobLike reports whether mode names one blob-like tree entry kind. +// +// Blob-like entries store blob object IDs as their targets. +func (mode Mode) IsBlobLike() bool { + return mode.details().isBlobLike +} + +// IsRegularFile reports whether mode names one regular-file variant. +func (mode Mode) IsRegularFile() bool { + return mode.details().isRegularFile +} + +// HasSameType reports whether mode and other describe the same tree entry kind. +// +// Regular files and executable files have the same type for diff-status purposes. +func (mode Mode) HasSameType(other Mode) bool { + if mode == other { + return true + } + + return mode.details().isRegularFile && other.details().isRegularFile +} + +// ObjectType returns the type of object that an entry with this mode targets. +// +// It returns [typ.TypeUnknown] for invalid modes. +func (mode Mode) ObjectType() typ.Type { + return mode.details().objectType +} |
