Skip to content

Commit 0f8ee94

Browse files
pks-tgitster
authored andcommitted
reftable/constants: make block types part of the public interface
Now that reftable blocks can be read individually via the public interface it becomes necessary for callers to be able to distinguish the different types of blocks. Expose the relevant constants. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent da89659 commit 0f8ee94

File tree

14 files changed

+131
-117
lines changed

14 files changed

+131
-117
lines changed

reftable/block.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ int block_writer_finish(struct block_writer *w)
160160
* Log records are stored zlib-compressed. Note that the compression
161161
* also spans over the restart points we have just written.
162162
*/
163-
if (block_writer_type(w) == BLOCK_TYPE_LOG) {
163+
if (block_writer_type(w) == REFTABLE_BLOCK_TYPE_LOG) {
164164
int block_header_skip = 4 + w->header_off;
165165
uLongf src_len = w->next - block_header_skip, compressed_len;
166166
int ret;
@@ -254,7 +254,7 @@ int reftable_block_init(struct reftable_block *block,
254254
goto done;
255255
}
256256

257-
if (block_type == BLOCK_TYPE_LOG) {
257+
if (block_type == REFTABLE_BLOCK_TYPE_LOG) {
258258
uint32_t block_header_skip = 4 + header_size;
259259
uLong dst_len = block_size - block_header_skip;
260260
uLong src_len = block->block_data.len - block_header_skip;

reftable/constants.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@
99
#ifndef CONSTANTS_H
1010
#define CONSTANTS_H
1111

12-
#define BLOCK_TYPE_LOG 'g'
13-
#define BLOCK_TYPE_INDEX 'i'
14-
#define BLOCK_TYPE_REF 'r'
15-
#define BLOCK_TYPE_OBJ 'o'
16-
#define BLOCK_TYPE_ANY 0
12+
#include "reftable-constants.h"
1713

1814
#define MAX_RESTARTS ((1 << 16) - 1)
1915
#define DEFAULT_BLOCK_SIZE 4096

reftable/iter.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ static int indexed_table_ref_iter_next_block(struct indexed_table_ref_iter *it)
131131
block_source_release_data(&it->block.block_data);
132132

133133
off = it->offsets[it->offset_idx++];
134-
err = table_init_block(it->table, &it->block, off, BLOCK_TYPE_REF);
134+
err = table_init_block(it->table, &it->block, off, REFTABLE_BLOCK_TYPE_REF);
135135
if (err < 0) {
136136
return err;
137137
}
@@ -246,7 +246,7 @@ int reftable_iterator_seek_ref(struct reftable_iterator *it,
246246
const char *name)
247247
{
248248
struct reftable_record want = {
249-
.type = BLOCK_TYPE_REF,
249+
.type = REFTABLE_BLOCK_TYPE_REF,
250250
.u.ref = {
251251
.refname = (char *)name,
252252
},
@@ -258,7 +258,7 @@ int reftable_iterator_next_ref(struct reftable_iterator *it,
258258
struct reftable_ref_record *ref)
259259
{
260260
struct reftable_record rec = {
261-
.type = BLOCK_TYPE_REF,
261+
.type = REFTABLE_BLOCK_TYPE_REF,
262262
.u = {
263263
.ref = *ref
264264
},
@@ -272,7 +272,7 @@ int reftable_iterator_seek_log_at(struct reftable_iterator *it,
272272
const char *name, uint64_t update_index)
273273
{
274274
struct reftable_record want = {
275-
.type = BLOCK_TYPE_LOG,
275+
.type = REFTABLE_BLOCK_TYPE_LOG,
276276
.u.log = {
277277
.refname = (char *)name,
278278
.update_index = update_index,
@@ -291,7 +291,7 @@ int reftable_iterator_next_log(struct reftable_iterator *it,
291291
struct reftable_log_record *log)
292292
{
293293
struct reftable_record rec = {
294-
.type = BLOCK_TYPE_LOG,
294+
.type = REFTABLE_BLOCK_TYPE_LOG,
295295
.u = {
296296
.log = *log,
297297
},

reftable/merged.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,13 +301,13 @@ int merged_table_init_iter(struct reftable_merged_table *mt,
301301
int reftable_merged_table_init_ref_iterator(struct reftable_merged_table *mt,
302302
struct reftable_iterator *it)
303303
{
304-
return merged_table_init_iter(mt, it, BLOCK_TYPE_REF);
304+
return merged_table_init_iter(mt, it, REFTABLE_BLOCK_TYPE_REF);
305305
}
306306

307307
int reftable_merged_table_init_log_iterator(struct reftable_merged_table *mt,
308308
struct reftable_iterator *it)
309309
{
310-
return merged_table_init_iter(mt, it, BLOCK_TYPE_LOG);
310+
return merged_table_init_iter(mt, it, REFTABLE_BLOCK_TYPE_LOG);
311311
}
312312

313313
enum reftable_hash reftable_merged_table_hash_id(struct reftable_merged_table *mt)

reftable/record.c

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,10 @@ int put_var_int(struct string_view *dest, uint64_t value)
6969
int reftable_is_block_type(uint8_t typ)
7070
{
7171
switch (typ) {
72-
case BLOCK_TYPE_REF:
73-
case BLOCK_TYPE_LOG:
74-
case BLOCK_TYPE_OBJ:
75-
case BLOCK_TYPE_INDEX:
72+
case REFTABLE_BLOCK_TYPE_REF:
73+
case REFTABLE_BLOCK_TYPE_LOG:
74+
case REFTABLE_BLOCK_TYPE_OBJ:
75+
case REFTABLE_BLOCK_TYPE_INDEX:
7676
return 1;
7777
}
7878
return 0;
@@ -462,7 +462,7 @@ static int reftable_ref_record_cmp_void(const void *_a, const void *_b)
462462

463463
static struct reftable_record_vtable reftable_ref_record_vtable = {
464464
.key = &reftable_ref_record_key,
465-
.type = BLOCK_TYPE_REF,
465+
.type = REFTABLE_BLOCK_TYPE_REF,
466466
.copy_from = &reftable_ref_record_copy_from,
467467
.val_type = &reftable_ref_record_val_type,
468468
.encode = &reftable_ref_record_encode,
@@ -664,7 +664,7 @@ static int reftable_obj_record_cmp_void(const void *_a, const void *_b)
664664

665665
static struct reftable_record_vtable reftable_obj_record_vtable = {
666666
.key = &reftable_obj_record_key,
667-
.type = BLOCK_TYPE_OBJ,
667+
.type = REFTABLE_BLOCK_TYPE_OBJ,
668668
.copy_from = &reftable_obj_record_copy_from,
669669
.val_type = &reftable_obj_record_val_type,
670670
.encode = &reftable_obj_record_encode,
@@ -1035,7 +1035,7 @@ static int reftable_log_record_is_deletion_void(const void *p)
10351035

10361036
static struct reftable_record_vtable reftable_log_record_vtable = {
10371037
.key = &reftable_log_record_key,
1038-
.type = BLOCK_TYPE_LOG,
1038+
.type = REFTABLE_BLOCK_TYPE_LOG,
10391039
.copy_from = &reftable_log_record_copy_from,
10401040
.val_type = &reftable_log_record_val_type,
10411041
.encode = &reftable_log_record_encode,
@@ -1137,7 +1137,7 @@ static int reftable_index_record_cmp(const void *_a, const void *_b)
11371137

11381138
static struct reftable_record_vtable reftable_index_record_vtable = {
11391139
.key = &reftable_index_record_key,
1140-
.type = BLOCK_TYPE_INDEX,
1140+
.type = REFTABLE_BLOCK_TYPE_INDEX,
11411141
.copy_from = &reftable_index_record_copy_from,
11421142
.val_type = &reftable_index_record_val_type,
11431143
.encode = &reftable_index_record_encode,
@@ -1280,13 +1280,13 @@ int reftable_log_record_is_deletion(const struct reftable_log_record *log)
12801280
static void *reftable_record_data(struct reftable_record *rec)
12811281
{
12821282
switch (rec->type) {
1283-
case BLOCK_TYPE_REF:
1283+
case REFTABLE_BLOCK_TYPE_REF:
12841284
return &rec->u.ref;
1285-
case BLOCK_TYPE_LOG:
1285+
case REFTABLE_BLOCK_TYPE_LOG:
12861286
return &rec->u.log;
1287-
case BLOCK_TYPE_INDEX:
1287+
case REFTABLE_BLOCK_TYPE_INDEX:
12881288
return &rec->u.idx;
1289-
case BLOCK_TYPE_OBJ:
1289+
case REFTABLE_BLOCK_TYPE_OBJ:
12901290
return &rec->u.obj;
12911291
}
12921292
abort();
@@ -1296,13 +1296,13 @@ static struct reftable_record_vtable *
12961296
reftable_record_vtable(struct reftable_record *rec)
12971297
{
12981298
switch (rec->type) {
1299-
case BLOCK_TYPE_REF:
1299+
case REFTABLE_BLOCK_TYPE_REF:
13001300
return &reftable_ref_record_vtable;
1301-
case BLOCK_TYPE_LOG:
1301+
case REFTABLE_BLOCK_TYPE_LOG:
13021302
return &reftable_log_record_vtable;
1303-
case BLOCK_TYPE_INDEX:
1303+
case REFTABLE_BLOCK_TYPE_INDEX:
13041304
return &reftable_index_record_vtable;
1305-
case BLOCK_TYPE_OBJ:
1305+
case REFTABLE_BLOCK_TYPE_OBJ:
13061306
return &reftable_obj_record_vtable;
13071307
}
13081308
abort();
@@ -1314,11 +1314,11 @@ int reftable_record_init(struct reftable_record *rec, uint8_t typ)
13141314
rec->type = typ;
13151315

13161316
switch (typ) {
1317-
case BLOCK_TYPE_REF:
1318-
case BLOCK_TYPE_LOG:
1319-
case BLOCK_TYPE_OBJ:
1317+
case REFTABLE_BLOCK_TYPE_REF:
1318+
case REFTABLE_BLOCK_TYPE_LOG:
1319+
case REFTABLE_BLOCK_TYPE_OBJ:
13201320
return 0;
1321-
case BLOCK_TYPE_INDEX:
1321+
case REFTABLE_BLOCK_TYPE_INDEX:
13221322
reftable_buf_init(&rec->u.idx.last_key);
13231323
return 0;
13241324
default:

reftable/reftable-constants.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* Copyright 2020 Google LLC
3+
*
4+
* Use of this source code is governed by a BSD-style
5+
* license that can be found in the LICENSE file or at
6+
* https://developers.google.com/open-source/licenses/bsd
7+
*/
8+
9+
#ifndef REFTABLE_CONSTANTS_H
10+
#define REFTABLE_CONSTANTS_H
11+
12+
#define REFTABLE_BLOCK_TYPE_LOG 'g'
13+
#define REFTABLE_BLOCK_TYPE_INDEX 'i'
14+
#define REFTABLE_BLOCK_TYPE_REF 'r'
15+
#define REFTABLE_BLOCK_TYPE_OBJ 'o'
16+
#define REFTABLE_BLOCK_TYPE_ANY 0
17+
18+
#endif /* REFTABLE_CONSTANTS_H */

reftable/stack.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,14 +203,14 @@ int reftable_stack_init_ref_iterator(struct reftable_stack *st,
203203
struct reftable_iterator *it)
204204
{
205205
return merged_table_init_iter(reftable_stack_merged_table(st),
206-
it, BLOCK_TYPE_REF);
206+
it, REFTABLE_BLOCK_TYPE_REF);
207207
}
208208

209209
int reftable_stack_init_log_iterator(struct reftable_stack *st,
210210
struct reftable_iterator *it)
211211
{
212212
return merged_table_init_iter(reftable_stack_merged_table(st),
213-
it, BLOCK_TYPE_LOG);
213+
it, REFTABLE_BLOCK_TYPE_LOG);
214214
}
215215

216216
struct reftable_merged_table *
@@ -1098,7 +1098,7 @@ static int stack_write_compact(struct reftable_stack *st,
10981098
if (err < 0)
10991099
goto done;
11001100

1101-
err = merged_table_init_iter(mt, &it, BLOCK_TYPE_REF);
1101+
err = merged_table_init_iter(mt, &it, REFTABLE_BLOCK_TYPE_REF);
11021102
if (err < 0)
11031103
goto done;
11041104

@@ -1126,7 +1126,7 @@ static int stack_write_compact(struct reftable_stack *st,
11261126
}
11271127
reftable_iterator_destroy(&it);
11281128

1129-
err = merged_table_init_iter(mt, &it, BLOCK_TYPE_LOG);
1129+
err = merged_table_init_iter(mt, &it, REFTABLE_BLOCK_TYPE_LOG);
11301130
if (err < 0)
11311131
goto done;
11321132

reftable/table.c

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ static struct reftable_table_offsets *
2020
table_offsets_for(struct reftable_table *t, uint8_t typ)
2121
{
2222
switch (typ) {
23-
case BLOCK_TYPE_REF:
23+
case REFTABLE_BLOCK_TYPE_REF:
2424
return &t->ref_offsets;
25-
case BLOCK_TYPE_LOG:
25+
case REFTABLE_BLOCK_TYPE_LOG:
2626
return &t->log_offsets;
27-
case BLOCK_TYPE_OBJ:
27+
case REFTABLE_BLOCK_TYPE_OBJ:
2828
return &t->obj_offsets;
2929
}
3030
abort();
@@ -112,9 +112,9 @@ static int parse_footer(struct reftable_table *t, uint8_t *footer,
112112
}
113113

114114
first_block_typ = header[header_size(t->version)];
115-
t->ref_offsets.is_present = (first_block_typ == BLOCK_TYPE_REF);
115+
t->ref_offsets.is_present = (first_block_typ == REFTABLE_BLOCK_TYPE_REF);
116116
t->ref_offsets.offset = 0;
117-
t->log_offsets.is_present = (first_block_typ == BLOCK_TYPE_LOG ||
117+
t->log_offsets.is_present = (first_block_typ == REFTABLE_BLOCK_TYPE_LOG ||
118118
t->log_offsets.offset > 0);
119119
t->obj_offsets.is_present = t->obj_offsets.offset > 0;
120120
if (t->obj_offsets.is_present && !t->object_id_len) {
@@ -150,7 +150,7 @@ static int table_iter_next_in_block(struct table_iter *ti,
150150
struct reftable_record *rec)
151151
{
152152
int res = block_iter_next(&ti->bi, rec);
153-
if (res == 0 && reftable_record_type(rec) == BLOCK_TYPE_REF) {
153+
if (res == 0 && reftable_record_type(rec) == REFTABLE_BLOCK_TYPE_REF) {
154154
rec->u.ref.update_index += ti->table->min_update_index;
155155
}
156156

@@ -177,7 +177,7 @@ int table_init_block(struct reftable_table *t, struct reftable_block *block,
177177
if (err < 0)
178178
goto done;
179179

180-
if (want_typ != BLOCK_TYPE_ANY && block->block_type != want_typ) {
180+
if (want_typ != REFTABLE_BLOCK_TYPE_ANY && block->block_type != want_typ) {
181181
err = 1;
182182
goto done;
183183
}
@@ -270,7 +270,7 @@ static int table_iter_seek_start(struct table_iter *ti, uint8_t typ, int index)
270270
if (off == 0) {
271271
return 1;
272272
}
273-
typ = BLOCK_TYPE_INDEX;
273+
typ = REFTABLE_BLOCK_TYPE_INDEX;
274274
}
275275

276276
return table_iter_seek_to(ti, off, typ);
@@ -366,10 +366,10 @@ static int table_iter_seek_indexed(struct table_iter *ti,
366366
struct reftable_record *rec)
367367
{
368368
struct reftable_record want_index = {
369-
.type = BLOCK_TYPE_INDEX, .u.idx = { .last_key = REFTABLE_BUF_INIT }
369+
.type = REFTABLE_BLOCK_TYPE_INDEX, .u.idx = { .last_key = REFTABLE_BUF_INIT }
370370
};
371371
struct reftable_record index_result = {
372-
.type = BLOCK_TYPE_INDEX,
372+
.type = REFTABLE_BLOCK_TYPE_INDEX,
373373
.u.idx = { .last_key = REFTABLE_BUF_INIT },
374374
};
375375
int err;
@@ -429,7 +429,7 @@ static int table_iter_seek_indexed(struct table_iter *ti,
429429
break;
430430
}
431431

432-
if (ti->typ != BLOCK_TYPE_INDEX) {
432+
if (ti->typ != REFTABLE_BLOCK_TYPE_INDEX) {
433433
err = REFTABLE_FORMAT_ERROR;
434434
goto done;
435435
}
@@ -517,13 +517,13 @@ int table_init_iter(struct reftable_table *t,
517517
int reftable_table_init_ref_iterator(struct reftable_table *t,
518518
struct reftable_iterator *it)
519519
{
520-
return table_init_iter(t, it, BLOCK_TYPE_REF);
520+
return table_init_iter(t, it, REFTABLE_BLOCK_TYPE_REF);
521521
}
522522

523523
int reftable_table_init_log_iterator(struct reftable_table *t,
524524
struct reftable_iterator *it)
525525
{
526-
return table_init_iter(t, it, BLOCK_TYPE_LOG);
526+
return table_init_iter(t, it, REFTABLE_BLOCK_TYPE_LOG);
527527
}
528528

529529
int reftable_table_new(struct reftable_table **out,
@@ -625,22 +625,22 @@ static int reftable_table_refs_for_indexed(struct reftable_table *t,
625625
uint8_t *oid)
626626
{
627627
struct reftable_record want = {
628-
.type = BLOCK_TYPE_OBJ,
628+
.type = REFTABLE_BLOCK_TYPE_OBJ,
629629
.u.obj = {
630630
.hash_prefix = oid,
631631
.hash_prefix_len = t->object_id_len,
632632
},
633633
};
634634
struct reftable_iterator oit = { NULL };
635635
struct reftable_record got = {
636-
.type = BLOCK_TYPE_OBJ,
636+
.type = REFTABLE_BLOCK_TYPE_OBJ,
637637
.u.obj = { 0 },
638638
};
639639
int err = 0;
640640
struct indexed_table_ref_iter *itr = NULL;
641641

642642
/* Look through the reverse index. */
643-
err = table_init_iter(t, &oit, BLOCK_TYPE_OBJ);
643+
err = table_init_iter(t, &oit, REFTABLE_BLOCK_TYPE_OBJ);
644644
if (err < 0)
645645
goto done;
646646

@@ -692,7 +692,7 @@ static int reftable_table_refs_for_unindexed(struct reftable_table *t,
692692
}
693693

694694
table_iter_init(ti, t);
695-
err = table_iter_seek_start(ti, BLOCK_TYPE_REF, 0);
695+
err = table_iter_seek_start(ti, REFTABLE_BLOCK_TYPE_REF, 0);
696696
if (err < 0)
697697
goto out;
698698

@@ -748,15 +748,15 @@ int reftable_table_print_blocks(const char *tablename)
748748
} sections[] = {
749749
{
750750
.name = "ref",
751-
.type = BLOCK_TYPE_REF,
751+
.type = REFTABLE_BLOCK_TYPE_REF,
752752
},
753753
{
754754
.name = "obj",
755-
.type = BLOCK_TYPE_OBJ,
755+
.type = REFTABLE_BLOCK_TYPE_OBJ,
756756
},
757757
{
758758
.name = "log",
759-
.type = BLOCK_TYPE_LOG,
759+
.type = REFTABLE_BLOCK_TYPE_LOG,
760760
},
761761
};
762762
struct reftable_block_source src = { 0 };

0 commit comments

Comments
 (0)