arche / internal/object/object.go

commit 154431fd
  1package object
  2
  3import "time"
  4
  5type Kind string
  6
  7const (
  8	KindBlob       Kind = "blob"
  9	KindTree       Kind = "tree"
 10	KindCommit     Kind = "commit"
 11	KindConflict   Kind = "conflict"
 12	KindObsolete   Kind = "obsolete"
 13	KindIssueEvent Kind = "issue-event"
 14)
 15
 16type EntryMode uint8
 17
 18const (
 19	ModeFile    EntryMode = 0
 20	ModeExec    EntryMode = 1
 21	ModeSymlink EntryMode = 2
 22	ModeDir     EntryMode = 3
 23)
 24
 25type Phase uint8
 26
 27const (
 28	PhaseDraft  Phase = 0
 29	PhasePublic Phase = 1
 30	PhaseSecret Phase = 2
 31)
 32
 33func (p Phase) String() string {
 34	switch p {
 35	case PhaseDraft:
 36		return "draft"
 37	case PhasePublic:
 38		return "public"
 39	case PhaseSecret:
 40		return "secret"
 41	default:
 42		return "unknown"
 43	}
 44}
 45
 46var ZeroID [32]byte
 47
 48type Blob struct {
 49	Content []byte
 50}
 51
 52type TreeEntry struct {
 53	Name     string
 54	Mode     EntryMode
 55	ObjectID [32]byte
 56	Props    map[string]string
 57}
 58
 59type Tree struct {
 60	Entries []TreeEntry
 61}
 62
 63type Signature struct {
 64	Name      string
 65	Email     string
 66	Timestamp time.Time
 67}
 68
 69type Commit struct {
 70	TreeID    [32]byte
 71	Parents   [][32]byte
 72	ChangeID  string
 73	Author    Signature
 74	Committer Signature
 75	Message   string
 76	Phase     Phase
 77	CommitSig []byte
 78}
 79
 80type ConflictSide struct {
 81	CommitID [32]byte
 82	BlobID   [32]byte
 83}
 84
 85type Conflict struct {
 86	Base   *ConflictSide
 87	Ours   ConflictSide
 88	Theirs ConflictSide
 89}
 90
 91type ObsoleteMarker struct {
 92	Predecessor [32]byte
 93	Successors  [][32]byte
 94	Reason      string
 95	Timestamp   int64
 96}
 97
 98func Short(id [32]byte) string {
 99	const hex = "0123456789abcdef"
100	out := make([]byte, 12)
101	for i := 0; i < 6; i++ {
102		out[2*i] = hex[id[i]>>4]
103		out[2*i+1] = hex[id[i]&0xf]
104	}
105	return string(out)
106}