Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 19 additions & 15 deletions tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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<t>`) 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))
}
}

Expand Down