Skip to content

Commit 57c3fe4

Browse files
authored
Merge pull request #25 from bk2204/zos-ifmt
tree: don't use system stat constants
2 parents f177805 + 683e49d commit 57c3fe4

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

tree.go

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,21 @@ import (
99
"sort"
1010
"strconv"
1111
"strings"
12-
"syscall"
1312

1413
"github.com/git-lfs/gitobj/v2/pack"
1514
)
1615

16+
// We define these here instead of using the system ones because not all
17+
// operating systems use the traditional values. For example, zOS uses
18+
// different values.
19+
const (
20+
sIFMT = int32(0170000)
21+
sIFREG = int32(0100000)
22+
sIFDIR = int32(0040000)
23+
sIFLNK = int32(0120000)
24+
sIFGITLINK = int32(0160000)
25+
)
26+
1727
// Tree encapsulates a Git tree object.
1828
type Tree struct {
1929
// Entries is the list of entries held by this tree.
@@ -209,24 +219,18 @@ func (e *TreeEntry) Equal(other *TreeEntry) bool {
209219
// Type is the type of entry (either blob: BlobObjectType, or a sub-tree:
210220
// TreeObjectType).
211221
func (e *TreeEntry) Type() ObjectType {
212-
switch e.Filemode & syscall.S_IFMT {
213-
case syscall.S_IFREG:
222+
switch e.Filemode & sIFMT {
223+
case sIFREG:
214224
return BlobObjectType
215-
case syscall.S_IFDIR:
225+
case sIFDIR:
216226
return TreeObjectType
217-
case syscall.S_IFLNK:
227+
case sIFLNK:
218228
return BlobObjectType
229+
case sIFGITLINK:
230+
return CommitObjectType
219231
default:
220-
if e.Filemode == 0xe000 {
221-
// Mode 0xe000, or a gitlink, has no formal filesystem
222-
// (`syscall.S_IF<t>`) equivalent.
223-
//
224-
// Safeguard that catch here, or otherwise panic.
225-
return CommitObjectType
226-
} else {
227-
panic(fmt.Sprintf("gitobj: unknown object type: %o",
228-
e.Filemode))
229-
}
232+
panic(fmt.Sprintf("gitobj: unknown object type: %o",
233+
e.Filemode))
230234
}
231235
}
232236

0 commit comments

Comments
 (0)