aboutsummaryrefslogtreecommitdiff
path: root/objecttype/objecttype.go
blob: d9199509b19602994b44ad0c04c2f3874f5721d0 (about) (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Package objecttype provides object type constants and names.
package objecttype

// Type mirrors Git object type tags in packfiles.
type Type uint8

const (
	TypeInvalid  Type = 0
	TypeCommit   Type = 1
	TypeTree     Type = 2
	TypeBlob     Type = 3
	TypeTag      Type = 4
	TypeFuture   Type = 5
	TypeOfsDelta Type = 6
	TypeRefDelta Type = 7
)

const (
	typeNameBlob   = "blob"
	typeNameTree   = "tree"
	typeNameCommit = "commit"
	typeNameTag    = "tag"
)

// ParseName parses a canonical Git object type name.
func ParseName(name string) (Type, bool) {
	switch name {
	case typeNameBlob:
		return TypeBlob, true
	case typeNameTree:
		return TypeTree, true
	case typeNameCommit:
		return TypeCommit, true
	case typeNameTag:
		return TypeTag, true
	default:
		return TypeInvalid, false
	}
}

// Name returns the canonical Git object type name.
func Name(ty Type) (string, bool) {
	switch ty {
	case TypeBlob:
		return typeNameBlob, true
	case TypeTree:
		return typeNameTree, true
	case TypeCommit:
		return typeNameCommit, true
	case TypeTag:
		return typeNameTag, true
	default:
		return "", false
	}
}