From 683e49d185efa9c1bb92807c67b582359f00ff73 Mon Sep 17 00:00:00 2001 From: "brian m. carlson" Date: Mon, 12 Jul 2021 12:14:06 +0000 Subject: [PATCH] tree: don't use system stat constants On most Unix systems, the stat constants (S_IFMT and friends) that Git uses are the same: that is, the system values are the same ones that Git uses. However, on zOS, this isn't the case, and the system constants are different. Let's add a set of our constants that are used by Git to determine the type of an object that will be right on all platforms instead of using the system constants. Note that the tests already cover this case; they'll just now pass on additional systems. --- tree.go | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/tree.go b/tree.go index a0e01b0..d4996ae 100644 --- a/tree.go +++ b/tree.go @@ -9,11 +9,21 @@ import ( "sort" "strconv" "strings" - "syscall" "github.com/git-lfs/gitobj/v2/pack" ) +// We define these here instead of using the system ones because not all +// operating systems use the traditional values. For example, zOS uses +// different values. +const ( + sIFMT = int32(0170000) + sIFREG = int32(0100000) + sIFDIR = int32(0040000) + sIFLNK = int32(0120000) + sIFGITLINK = int32(0160000) +) + // Tree encapsulates a Git tree object. type Tree struct { // Entries is the list of entries held by this tree. @@ -209,24 +219,18 @@ func (e *TreeEntry) Equal(other *TreeEntry) bool { // Type is the type of entry (either blob: BlobObjectType, or a sub-tree: // TreeObjectType). func (e *TreeEntry) Type() ObjectType { - switch e.Filemode & syscall.S_IFMT { - case syscall.S_IFREG: + switch e.Filemode & sIFMT { + case sIFREG: return BlobObjectType - case syscall.S_IFDIR: + case sIFDIR: return TreeObjectType - case syscall.S_IFLNK: + case sIFLNK: return BlobObjectType + case sIFGITLINK: + return CommitObjectType default: - if e.Filemode == 0xe000 { - // Mode 0xe000, or a gitlink, has no formal filesystem - // (`syscall.S_IF`) equivalent. - // - // Safeguard that catch here, or otherwise panic. - return CommitObjectType - } else { - panic(fmt.Sprintf("gitobj: unknown object type: %o", - e.Filemode)) - } + panic(fmt.Sprintf("gitobj: unknown object type: %o", + e.Filemode)) } }