aboutsummaryrefslogtreecommitdiff
path: root/object/tree/mode/ops.go
diff options
context:
space:
mode:
authorGravatar Runxi Yu2026-06-07 11:01:26 +0000
committerGravatar Runxi Yu2026-06-07 11:04:43 +0000
commitc2d883c7c58a3bd64d799dd000fe7254e450a4e5 (patch)
treea4456d8fc3718f235c2e934d42c056b3bcd3e1f9 /object/tree/mode/ops.go
parentobject/tag: Add (diff)
signatureNo signature
object/tree/mode: Initialize
Diffstat (limited to 'object/tree/mode/ops.go')
-rw-r--r--object/tree/mode/ops.go38
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
+}