Debian Codegraph @

pack/type.go

raw
1 package pack
2
3 import (
4 "errors"
5 "fmt"
6 )
7
8 // PackedObjectType is a constant type that is defined for all valid object
9 // types that a packed object can represent.
10 type PackedObjectType uint8
11
12 const (
13 // TypeNone is the zero-value for PackedObjectType, and represents the
14 // absence of a type.
15 TypeNone PackedObjectType = iota
16 // TypeCommit is the PackedObjectType for commit objects.
17 TypeCommit
18 // TypeTree is the PackedObjectType for tree objects.
19 TypeTree
20 // Typeblob is the PackedObjectType for blob objects.
21 TypeBlob
22 // TypeTag is the PackedObjectType for tag objects.
23 TypeTag
24
25 // TypeObjectOffsetDelta is the type for OBJ_OFS_DELTA-typed objects.
26 TypeObjectOffsetDelta PackedObjectType = 6
27 // TypeObjectReferenceDelta is the type for OBJ_REF_DELTA-typed objects.
28 TypeObjectReferenceDelta PackedObjectType = 7
29 )
30
31 // String implements fmt.Stringer and returns an encoding of the type valid for
32 // use in the loose object format protocol (see: package 'gitobj' for more).
33 //
34 // If the receiving instance is not defined, String() will panic().
35 func (t PackedObjectType) String() string {
36 switch t {
37 case TypeNone:
38 return "<none>"
39 case TypeCommit:
40 return "commit"
41 case TypeTree:
42 return "tree"
43 case TypeBlob:
44 return "blob"
45 case TypeTag:
46 return "tag"
47 case TypeObjectOffsetDelta:
48 return "obj_ofs_delta"
49 case TypeObjectReferenceDelta:
50 return "obj_ref_delta"
51 }
52
53 panic(fmt.Sprintf("gitobj/pack: unknown object type: %d", t))
54 }
55
56 var (
57 errUnrecognizedObjectType = errors.New("gitobj/pack: unrecognized object type")
58 )