From c2d883c7c58a3bd64d799dd000fe7254e450a4e5 Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Sun, 7 Jun 2026 11:01:26 +0000 Subject: object/tree/mode: Initialize --- object/tree/mode/ops.go | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 object/tree/mode/ops.go (limited to 'object/tree/mode/ops.go') 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 +} -- cgit v1.3.1-10-gc9f91