This repository was archived by the owner on Jan 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathapi.go
More file actions
146 lines (120 loc) · 3.18 KB
/
api.go
File metadata and controls
146 lines (120 loc) · 3.18 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/*
Copyright 2020 Google LLC
Use of this source code is governed by a BSD-style
license that can be found in the LICENSE file or at
https://developers.google.com/open-source/licenses/bsd
*/
package reftable
import "errors"
// BlockSource is an interface for reading reftable bytes.
type BlockSource interface {
Size() uint64
ReadBlock(off uint64, size int) ([]byte, error)
Close() error
}
// record is a single piece of keyed data, stored in the reftable.
type record interface {
key() string
typ() byte
copyFrom(record)
String() string
valType() uint8
// XXX negative n == error.s
encode(buf []byte, hashSize int) (n int, fits bool)
decode(buf []byte, key string, valType uint8, hashSize int) (n int, ok bool)
IsDeletion() bool
}
type HashID [4]byte
var SHA1ID = HashID([4]byte{'s', 'h', 'a', '1'})
var SHA256ID = HashID([4]byte{'s', '2', '5', '6'})
var NullHashID = HashID([4]byte{0, 0, 0, 0})
func (i HashID) Size() int {
switch i {
case NullHashID, SHA1ID:
return 20
case SHA256ID:
return 32
}
panic("unknown hash")
}
// Table is a read interface for reftables, either file reftables or merged reftables.
type Table interface {
// seekRecord returns an iterator pointed to just before the
// key specified by the record
seekRecord(rec record) (iterator, error)
MaxUpdateIndex() uint64
MinUpdateIndex() uint64
HashID() HashID
SeekRef(refName string) (*Iterator, error)
SeekLog(refName string, updateIndex uint64) (*Iterator, error)
RefsFor(oid []byte) (*Iterator, error)
Name() string
}
// iterator is an iterator over reftable
type Iterator struct {
impl iterator
}
type LogExpirationConfig struct {
Time uint64
MaxUpdateIndex uint64
MinUpdateIndex uint64
}
// Options define write options for reftables.
type Config struct {
// If set, do not pad blocks to blocksize.
Unaligned bool
// The block size, if not set 4096.
BlockSize uint32
SkipIndexObjects bool
RestartInterval int
// Hash identifier. Unset means sha1.
HashID HashID
// Allow dir/file conflicts and illegal refnames
SkipNameCheck bool
// If set, store reflog messages exactly. If unset, only allow
// a single line, and a trailing '\n' is added if it is missing.
ExactLogMessage bool
}
// RefRecord is a Record from the ref database.
type RefRecord struct {
RefName string
UpdateIndex uint64
Value []byte
TargetValue []byte
// is a 0-length target allowed?
Target string
}
// LogRecord is a Record from the reflog database.
type LogRecord struct {
RefName string
UpdateIndex uint64
New []byte
Old []byte
Name string
Email string
Time uint64
TZOffset int16
Message string
}
// BlockStats provides write statistics data of a certain block type.
type BlockStats struct {
Entries int
Restarts int
Blocks int
IndexBlocks int
MaxIndexLevel int
Offset uint64
IndexOffset uint64
}
// Stats provides general write statistics
type Stats struct {
ObjStats BlockStats
RefStats BlockStats
LogStats BlockStats
idxStats BlockStats
Blocks int
ObjectIDLen int
}
// ErrEmptyTable indicates that a writer tried to create a table
// without blocks.
var ErrEmptyTable = errors.New("reftable: table is empty")