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 <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Patrick Steinhardt committed
Apr 7, 2025 at 15:16 UTC
0f8ee94b636b5ab183c62b8fdd26c1611c2b86f4
14 files changed
+131
-117
reftable/block.c
+2
-2
@@ -160,7 +160,7 @@ int block_writer_finish(struct block_writer *w)
160
* Log records are stored zlib-compressed. Note that the compression
161
* also spans over the restart points we have just written.
162
*/
163
- if (block_writer_type(w) == BLOCK_TYPE_LOG) {
163
+ if (block_writer_type(w) == REFTABLE_BLOCK_TYPE_LOG) {
164
int block_header_skip = 4 + w->header_off;
165
uLongf src_len = w->next - block_header_skip, compressed_len;
166
int ret;
@@ -254,7 +254,7 @@ int reftable_block_init(struct reftable_block *block,
254
goto done;
255
}
256
257
- if (block_type == BLOCK_TYPE_LOG) {
257
+ if (block_type == REFTABLE_BLOCK_TYPE_LOG) {
258
uint32_t block_header_skip = 4 + header_size;
259
uLong dst_len = block_size - block_header_skip;
260
uLong src_len = block->block_data.len - block_header_skip;
reftable/constants.h
+1
-5
@@ -9,11 +9,7 @@
9
#ifndef CONSTANTS_H
10
#define CONSTANTS_H
11
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"
13
14
#define MAX_RESTARTS ((1 << 16) - 1)
15
#define DEFAULT_BLOCK_SIZE 4096
reftable/iter.c
+5
-5
@@ -131,7 +131,7 @@ static int indexed_table_ref_iter_next_block(struct indexed_table_ref_iter *it)
131
block_source_release_data(&it->block.block_data);
132
133
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);
135
if (err < 0) {
136
return err;
137
}
@@ -246,7 +246,7 @@ int reftable_iterator_seek_ref(struct reftable_iterator *it,
246
const char *name)
247
{
248
struct reftable_record want = {
249
- .type = BLOCK_TYPE_REF,
249
+ .type = REFTABLE_BLOCK_TYPE_REF,
250
.u.ref = {
251
.refname = (char *)name,
252
},
@@ -258,7 +258,7 @@ int reftable_iterator_next_ref(struct reftable_iterator *it,
258
struct reftable_ref_record *ref)
259
{
260
struct reftable_record rec = {
261
- .type = BLOCK_TYPE_REF,
261
+ .type = REFTABLE_BLOCK_TYPE_REF,
262
.u = {
263
.ref = *ref
264
},
@@ -272,7 +272,7 @@ int reftable_iterator_seek_log_at(struct reftable_iterator *it,
272
const char *name, uint64_t update_index)
273
{
274
struct reftable_record want = {
275
- .type = BLOCK_TYPE_LOG,
275
+ .type = REFTABLE_BLOCK_TYPE_LOG,
276
.u.log = {
277
.refname = (char *)name,
278
.update_index = update_index,
@@ -291,7 +291,7 @@ int reftable_iterator_next_log(struct reftable_iterator *it,
291
struct reftable_log_record *log)
292
{
293
struct reftable_record rec = {
294
- .type = BLOCK_TYPE_LOG,
294
+ .type = REFTABLE_BLOCK_TYPE_LOG,
295
.u = {
296
.log = *log,
297
},
reftable/merged.c
+2
-2
@@ -301,13 +301,13 @@ out:
301
int reftable_merged_table_init_ref_iterator(struct reftable_merged_table *mt,
302
struct reftable_iterator *it)
303
{
304
- return merged_table_init_iter(mt, it, BLOCK_TYPE_REF);
304
+ return merged_table_init_iter(mt, it, REFTABLE_BLOCK_TYPE_REF);
305
}
306
307
int reftable_merged_table_init_log_iterator(struct reftable_merged_table *mt,
308
struct reftable_iterator *it)
309
{
310
- return merged_table_init_iter(mt, it, BLOCK_TYPE_LOG);
310
+ return merged_table_init_iter(mt, it, REFTABLE_BLOCK_TYPE_LOG);
311
}
312
313
enum reftable_hash reftable_merged_table_hash_id(struct reftable_merged_table *mt)
reftable/record.c
+20
-20
@@ -69,10 +69,10 @@ int put_var_int(struct string_view *dest, uint64_t value)
69
int reftable_is_block_type(uint8_t typ)
70
{
71
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:
76
return 1;
77
}
78
return 0;
@@ -462,7 +462,7 @@ static int reftable_ref_record_cmp_void(const void *_a, const void *_b)
462
463
static struct reftable_record_vtable reftable_ref_record_vtable = {
464
.key = &reftable_ref_record_key,
465
- .type = BLOCK_TYPE_REF,
465
+ .type = REFTABLE_BLOCK_TYPE_REF,
466
.copy_from = &reftable_ref_record_copy_from,
467
.val_type = &reftable_ref_record_val_type,
468
.encode = &reftable_ref_record_encode,
@@ -664,7 +664,7 @@ static int reftable_obj_record_cmp_void(const void *_a, const void *_b)
664
665
static struct reftable_record_vtable reftable_obj_record_vtable = {
666
.key = &reftable_obj_record_key,
667
- .type = BLOCK_TYPE_OBJ,
667
+ .type = REFTABLE_BLOCK_TYPE_OBJ,
668
.copy_from = &reftable_obj_record_copy_from,
669
.val_type = &reftable_obj_record_val_type,
670
.encode = &reftable_obj_record_encode,
@@ -1035,7 +1035,7 @@ static int reftable_log_record_is_deletion_void(const void *p)
1035
1036
static struct reftable_record_vtable reftable_log_record_vtable = {
1037
.key = &reftable_log_record_key,
1038
- .type = BLOCK_TYPE_LOG,
1038
+ .type = REFTABLE_BLOCK_TYPE_LOG,
1039
.copy_from = &reftable_log_record_copy_from,
1040
.val_type = &reftable_log_record_val_type,
1041
.encode = &reftable_log_record_encode,
@@ -1137,7 +1137,7 @@ static int reftable_index_record_cmp(const void *_a, const void *_b)
1137
1138
static struct reftable_record_vtable reftable_index_record_vtable = {
1139
.key = &reftable_index_record_key,
1140
- .type = BLOCK_TYPE_INDEX,
1140
+ .type = REFTABLE_BLOCK_TYPE_INDEX,
1141
.copy_from = &reftable_index_record_copy_from,
1142
.val_type = &reftable_index_record_val_type,
1143
.encode = &reftable_index_record_encode,
@@ -1280,13 +1280,13 @@ int reftable_log_record_is_deletion(const struct reftable_log_record *log)
1280
static void *reftable_record_data(struct reftable_record *rec)
1281
{
1282
switch (rec->type) {
1283
- case BLOCK_TYPE_REF:
1283
+ case REFTABLE_BLOCK_TYPE_REF:
1284
return &rec->u.ref;
1285
- case BLOCK_TYPE_LOG:
1285
+ case REFTABLE_BLOCK_TYPE_LOG:
1286
return &rec->u.log;
1287
- case BLOCK_TYPE_INDEX:
1287
+ case REFTABLE_BLOCK_TYPE_INDEX:
1288
return &rec->u.idx;
1289
- case BLOCK_TYPE_OBJ:
1289
+ case REFTABLE_BLOCK_TYPE_OBJ:
1290
return &rec->u.obj;
1291
}
1292
abort();
@@ -1296,13 +1296,13 @@ static struct reftable_record_vtable *
1296
reftable_record_vtable(struct reftable_record *rec)
1297
{
1298
switch (rec->type) {
1299
- case BLOCK_TYPE_REF:
1299
+ case REFTABLE_BLOCK_TYPE_REF:
1300
return &reftable_ref_record_vtable;
1301
- case BLOCK_TYPE_LOG:
1301
+ case REFTABLE_BLOCK_TYPE_LOG:
1302
return &reftable_log_record_vtable;
1303
- case BLOCK_TYPE_INDEX:
1303
+ case REFTABLE_BLOCK_TYPE_INDEX:
1304
return &reftable_index_record_vtable;
1305
- case BLOCK_TYPE_OBJ:
1305
+ case REFTABLE_BLOCK_TYPE_OBJ:
1306
return &reftable_obj_record_vtable;
1307
}
1308
abort();
@@ -1314,11 +1314,11 @@ int reftable_record_init(struct reftable_record *rec, uint8_t typ)
1314
rec->type = typ;
1315
1316
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:
1320
return 0;
1321
- case BLOCK_TYPE_INDEX:
1321
+ case REFTABLE_BLOCK_TYPE_INDEX:
1322
reftable_buf_init(&rec->u.idx.last_key);
1323
return 0;
1324
default:
reftable/reftable-constants.h
new
+18
@@ -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
+4
-4
@@ -203,14 +203,14 @@ int reftable_stack_init_ref_iterator(struct reftable_stack *st,
203
struct reftable_iterator *it)
204
{
205
return merged_table_init_iter(reftable_stack_merged_table(st),
206
- it, BLOCK_TYPE_REF);
206
+ it, REFTABLE_BLOCK_TYPE_REF);
207
}
208
209
int reftable_stack_init_log_iterator(struct reftable_stack *st,
210
struct reftable_iterator *it)
211
{
212
return merged_table_init_iter(reftable_stack_merged_table(st),
213
- it, BLOCK_TYPE_LOG);
213
+ it, REFTABLE_BLOCK_TYPE_LOG);
214
}
215
216
struct reftable_merged_table *
@@ -1098,7 +1098,7 @@ static int stack_write_compact(struct reftable_stack *st,
1098
if (err < 0)
1099
goto done;
1100
1101
- err = merged_table_init_iter(mt, &it, BLOCK_TYPE_REF);
1101
+ err = merged_table_init_iter(mt, &it, REFTABLE_BLOCK_TYPE_REF);
1102
if (err < 0)
1103
goto done;
1104
@@ -1126,7 +1126,7 @@ static int stack_write_compact(struct reftable_stack *st,
1126
}
1127
reftable_iterator_destroy(&it);
1128
1129
- err = merged_table_init_iter(mt, &it, BLOCK_TYPE_LOG);
1129
+ err = merged_table_init_iter(mt, &it, REFTABLE_BLOCK_TYPE_LOG);
1130
if (err < 0)
1131
goto done;
1132
reftable/table.c
+20
-20
@@ -20,11 +20,11 @@ static struct reftable_table_offsets *
20
table_offsets_for(struct reftable_table *t, uint8_t typ)
21
{
22
switch (typ) {
23
- case BLOCK_TYPE_REF:
23
+ case REFTABLE_BLOCK_TYPE_REF:
24
return &t->ref_offsets;
25
- case BLOCK_TYPE_LOG:
25
+ case REFTABLE_BLOCK_TYPE_LOG:
26
return &t->log_offsets;
27
- case BLOCK_TYPE_OBJ:
27
+ case REFTABLE_BLOCK_TYPE_OBJ:
28
return &t->obj_offsets;
29
}
30
abort();
@@ -112,9 +112,9 @@ static int parse_footer(struct reftable_table *t, uint8_t *footer,
112
}
113
114
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);
116
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 ||
118
t->log_offsets.offset > 0);
119
t->obj_offsets.is_present = t->obj_offsets.offset > 0;
120
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,
150
struct reftable_record *rec)
151
{
152
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) {
154
rec->u.ref.update_index += ti->table->min_update_index;
155
}
156
@@ -177,7 +177,7 @@ int table_init_block(struct reftable_table *t, struct reftable_block *block,
177
if (err < 0)
178
goto done;
179
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) {
181
err = 1;
182
goto done;
183
}
@@ -270,7 +270,7 @@ static int table_iter_seek_start(struct table_iter *ti, uint8_t typ, int index)
270
if (off == 0) {
271
return 1;
272
}
273
- typ = BLOCK_TYPE_INDEX;
273
+ typ = REFTABLE_BLOCK_TYPE_INDEX;
274
}
275
276
return table_iter_seek_to(ti, off, typ);
@@ -366,10 +366,10 @@ static int table_iter_seek_indexed(struct table_iter *ti,
366
struct reftable_record *rec)
367
{
368
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 }
370
};
371
struct reftable_record index_result = {
372
- .type = BLOCK_TYPE_INDEX,
372
+ .type = REFTABLE_BLOCK_TYPE_INDEX,
373
.u.idx = { .last_key = REFTABLE_BUF_INIT },
374
};
375
int err;
@@ -429,7 +429,7 @@ static int table_iter_seek_indexed(struct table_iter *ti,
429
break;
430
}
431
432
- if (ti->typ != BLOCK_TYPE_INDEX) {
432
+ if (ti->typ != REFTABLE_BLOCK_TYPE_INDEX) {
433
err = REFTABLE_FORMAT_ERROR;
434
goto done;
435
}
@@ -517,13 +517,13 @@ int table_init_iter(struct reftable_table *t,
517
int reftable_table_init_ref_iterator(struct reftable_table *t,
518
struct reftable_iterator *it)
519
{
520
- return table_init_iter(t, it, BLOCK_TYPE_REF);
520
+ return table_init_iter(t, it, REFTABLE_BLOCK_TYPE_REF);
521
}
522
523
int reftable_table_init_log_iterator(struct reftable_table *t,
524
struct reftable_iterator *it)
525
{
526
- return table_init_iter(t, it, BLOCK_TYPE_LOG);
526
+ return table_init_iter(t, it, REFTABLE_BLOCK_TYPE_LOG);
527
}
528
529
int reftable_table_new(struct reftable_table **out,
@@ -625,7 +625,7 @@ static int reftable_table_refs_for_indexed(struct reftable_table *t,
625
uint8_t *oid)
626
{
627
struct reftable_record want = {
628
- .type = BLOCK_TYPE_OBJ,
628
+ .type = REFTABLE_BLOCK_TYPE_OBJ,
629
.u.obj = {
630
.hash_prefix = oid,
631
.hash_prefix_len = t->object_id_len,
@@ -633,14 +633,14 @@ static int reftable_table_refs_for_indexed(struct reftable_table *t,
633
};
634
struct reftable_iterator oit = { NULL };
635
struct reftable_record got = {
636
- .type = BLOCK_TYPE_OBJ,
636
+ .type = REFTABLE_BLOCK_TYPE_OBJ,
637
.u.obj = { 0 },
638
};
639
int err = 0;
640
struct indexed_table_ref_iter *itr = NULL;
641
642
/* 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);
644
if (err < 0)
645
goto done;
646
@@ -692,7 +692,7 @@ static int reftable_table_refs_for_unindexed(struct reftable_table *t,
692
}
693
694
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);
696
if (err < 0)
697
goto out;
698
@@ -748,15 +748,15 @@ int reftable_table_print_blocks(const char *tablename)
748
} sections[] = {
749
{
750
.name = "ref",
751
- .type = BLOCK_TYPE_REF,
751
+ .type = REFTABLE_BLOCK_TYPE_REF,
752
},
753
{
754
.name = "obj",
755
- .type = BLOCK_TYPE_OBJ,
755
+ .type = REFTABLE_BLOCK_TYPE_OBJ,
756
},
757
{
758
.name = "log",
759
- .type = BLOCK_TYPE_LOG,
759
+ .type = REFTABLE_BLOCK_TYPE_LOG,
760
},
761
};
762
struct reftable_block_source src = { 0 };
reftable/writer.c
+11
-11
@@ -172,7 +172,7 @@ int reftable_writer_new(struct reftable_writer **out,
172
wp->write_arg = writer_arg;
173
wp->opts = opts;
174
wp->flush = flush_func;
175
- writer_reinit_block_writer(wp, BLOCK_TYPE_REF);
175
+ writer_reinit_block_writer(wp, REFTABLE_BLOCK_TYPE_REF);
176
177
*out = wp;
178
@@ -347,7 +347,7 @@ int reftable_writer_add_ref(struct reftable_writer *w,
347
struct reftable_ref_record *ref)
348
{
349
struct reftable_record rec = {
350
- .type = BLOCK_TYPE_REF,
350
+ .type = REFTABLE_BLOCK_TYPE_REF,
351
.u = {
352
.ref = *ref
353
},
@@ -411,13 +411,13 @@ static int reftable_writer_add_log_verbatim(struct reftable_writer *w,
411
struct reftable_log_record *log)
412
{
413
struct reftable_record rec = {
414
- .type = BLOCK_TYPE_LOG,
414
+ .type = REFTABLE_BLOCK_TYPE_LOG,
415
.u = {
416
.log = *log,
417
},
418
};
419
if (w->block_writer &&
420
- block_writer_type(w->block_writer) == BLOCK_TYPE_REF) {
420
+ block_writer_type(w->block_writer) == REFTABLE_BLOCK_TYPE_REF) {
421
int err = writer_finish_public_section(w);
422
if (err < 0)
423
return err;
@@ -537,7 +537,7 @@ static int writer_finish_section(struct reftable_writer *w)
537
538
max_level++;
539
index_start = w->next;
540
- err = writer_reinit_block_writer(w, BLOCK_TYPE_INDEX);
540
+ err = writer_reinit_block_writer(w, REFTABLE_BLOCK_TYPE_INDEX);
541
if (err < 0)
542
return err;
543
@@ -549,7 +549,7 @@ static int writer_finish_section(struct reftable_writer *w)
549
w->index_cap = 0;
550
for (i = 0; i < idx_len; i++) {
551
struct reftable_record rec = {
552
- .type = BLOCK_TYPE_INDEX,
552
+ .type = REFTABLE_BLOCK_TYPE_INDEX,
553
.u = {
554
.idx = idx[i],
555
},
@@ -614,7 +614,7 @@ static void write_object_record(void *void_arg, void *key)
614
struct write_record_arg *arg = void_arg;
615
struct obj_index_tree_node *entry = key;
616
struct reftable_record
617
- rec = { .type = BLOCK_TYPE_OBJ,
617
+ rec = { .type = REFTABLE_BLOCK_TYPE_OBJ,
618
.u.obj = {
619
.hash_prefix = (uint8_t *)entry->hash.buf,
620
.hash_prefix_len = arg->w->stats.object_id_len,
@@ -632,7 +632,7 @@ static void write_object_record(void *void_arg, void *key)
632
if (arg->err < 0)
633
goto done;
634
635
- arg->err = writer_reinit_block_writer(arg->w, BLOCK_TYPE_OBJ);
635
+ arg->err = writer_reinit_block_writer(arg->w, REFTABLE_BLOCK_TYPE_OBJ);
636
if (arg->err < 0)
637
goto done;
638
@@ -670,7 +670,7 @@ static int writer_dump_object_index(struct reftable_writer *w)
670
infix_walk(w->obj_index_tree, &update_common, &common);
671
w->stats.object_id_len = common.max + 1;
672
673
- err = writer_reinit_block_writer(w, BLOCK_TYPE_OBJ);
673
+ err = writer_reinit_block_writer(w, REFTABLE_BLOCK_TYPE_OBJ);
674
if (err < 0)
675
return err;
676
@@ -694,7 +694,7 @@ static int writer_finish_public_section(struct reftable_writer *w)
694
err = writer_finish_section(w);
695
if (err < 0)
696
return err;
697
- if (typ == BLOCK_TYPE_REF && !w->opts.skip_index_objects &&
697
+ if (typ == REFTABLE_BLOCK_TYPE_REF && !w->opts.skip_index_objects &&
698
w->stats.ref_stats.index_blocks > 0) {
699
err = writer_dump_object_index(w);
700
if (err < 0)
@@ -799,7 +799,7 @@ static int writer_flush_nonempty_block(struct reftable_writer *w)
799
* By default, all records except for log records are padded to the
800
* block size.
801
*/
802
- if (!w->opts.unpadded && typ != BLOCK_TYPE_LOG)
802
+ if (!w->opts.unpadded && typ != REFTABLE_BLOCK_TYPE_LOG)
803
padding = w->opts.block_size - raw_bytes;
804
805
bstats = writer_reftable_block_stats(w, typ);
t/unit-tests/t-reftable-block.c
+11
-11
@@ -24,7 +24,7 @@ static void t_ref_block_read_write(void)
24
.last_key = REFTABLE_BUF_INIT,
25
};
26
struct reftable_record rec = {
27
- .type = BLOCK_TYPE_REF,
27
+ .type = REFTABLE_BLOCK_TYPE_REF,
28
};
29
size_t i = 0;
30
int ret;
@@ -37,7 +37,7 @@ static void t_ref_block_read_write(void)
37
check(block_data.buf != NULL);
38
block_data.len = block_size;
39
40
- ret = block_writer_init(&bw, BLOCK_TYPE_REF, (uint8_t *) block_data.buf, block_size,
40
+ ret = block_writer_init(&bw, REFTABLE_BLOCK_TYPE_REF, (uint8_t *) block_data.buf, block_size,
41
header_off, hash_size(REFTABLE_HASH_SHA1));
42
check(!ret);
43
@@ -118,7 +118,7 @@ static void t_log_block_read_write(void)
118
.last_key = REFTABLE_BUF_INIT,
119
};
120
struct reftable_record rec = {
121
- .type = BLOCK_TYPE_LOG,
121
+ .type = REFTABLE_BLOCK_TYPE_LOG,
122
};
123
size_t i = 0;
124
int ret;
@@ -131,7 +131,7 @@ static void t_log_block_read_write(void)
131
check(block_data.buf != NULL);
132
block_data.len = block_size;
133
134
- ret = block_writer_init(&bw, BLOCK_TYPE_LOG, (uint8_t *) block_data.buf, block_size,
134
+ ret = block_writer_init(&bw, REFTABLE_BLOCK_TYPE_LOG, (uint8_t *) block_data.buf, block_size,
135
header_off, hash_size(REFTABLE_HASH_SHA1));
136
check(!ret);
137
@@ -208,7 +208,7 @@ static void t_obj_block_read_write(void)
208
.last_key = REFTABLE_BUF_INIT,
209
};
210
struct reftable_record rec = {
211
- .type = BLOCK_TYPE_OBJ,
211
+ .type = REFTABLE_BLOCK_TYPE_OBJ,
212
};
213
size_t i = 0;
214
int ret;
@@ -221,7 +221,7 @@ static void t_obj_block_read_write(void)
221
check(block_data.buf != NULL);
222
block_data.len = block_size;
223
224
- ret = block_writer_init(&bw, BLOCK_TYPE_OBJ, (uint8_t *) block_data.buf, block_size,
224
+ ret = block_writer_init(&bw, REFTABLE_BLOCK_TYPE_OBJ, (uint8_t *) block_data.buf, block_size,
225
header_off, hash_size(REFTABLE_HASH_SHA1));
226
check(!ret);
227
@@ -291,7 +291,7 @@ static void t_index_block_read_write(void)
291
.last_key = REFTABLE_BUF_INIT,
292
};
293
struct reftable_record rec = {
294
- .type = BLOCK_TYPE_INDEX,
294
+ .type = REFTABLE_BLOCK_TYPE_INDEX,
295
.u.idx.last_key = REFTABLE_BUF_INIT,
296
};
297
size_t i = 0;
@@ -305,7 +305,7 @@ static void t_index_block_read_write(void)
305
check(block_data.buf != NULL);
306
block_data.len = block_size;
307
308
- ret = block_writer_init(&bw, BLOCK_TYPE_INDEX, (uint8_t *) block_data.buf, block_size,
308
+ ret = block_writer_init(&bw, REFTABLE_BLOCK_TYPE_INDEX, (uint8_t *) block_data.buf, block_size,
309
header_off, hash_size(REFTABLE_HASH_SHA1));
310
check(!ret);
311
@@ -315,7 +315,7 @@ static void t_index_block_read_write(void)
315
snprintf(buf, sizeof(buf), "branch%02"PRIuMAX, (uintmax_t)i);
316
317
reftable_buf_init(&recs[i].u.idx.last_key);
318
- recs[i].type = BLOCK_TYPE_INDEX;
318
+ recs[i].type = REFTABLE_BLOCK_TYPE_INDEX;
319
check(!reftable_buf_addstr(&recs[i].u.idx.last_key, buf));
320
recs[i].u.idx.offset = i;
321
@@ -389,13 +389,13 @@ static void t_block_iterator(void)
389
REFTABLE_CALLOC_ARRAY(data.buf, data.len);
390
check(data.buf != NULL);
391
392
- err = block_writer_init(&writer, BLOCK_TYPE_REF, (uint8_t *) data.buf, data.len,
392
+ err = block_writer_init(&writer, REFTABLE_BLOCK_TYPE_REF, (uint8_t *) data.buf, data.len,
393
0, hash_size(REFTABLE_HASH_SHA1));
394
check(!err);
395
396
for (size_t i = 0; i < ARRAY_SIZE(expected_refs); i++) {
397
expected_refs[i] = (struct reftable_record) {
398
- .type = BLOCK_TYPE_REF,
398
+ .type = REFTABLE_BLOCK_TYPE_REF,
399
.u.ref = {
400
.value_type = REFTABLE_REF_VAL1,
401
.refname = xstrfmt("refs/heads/branch-%02"PRIuMAX, (uintmax_t)i),
t/unit-tests/t-reftable-merged.c
+6
-6
@@ -84,7 +84,7 @@ static void t_merged_single_record(void)
84
struct reftable_iterator it = { 0 };
85
int err;
86
87
- err = merged_table_init_iter(mt, &it, BLOCK_TYPE_REF);
87
+ err = merged_table_init_iter(mt, &it, REFTABLE_BLOCK_TYPE_REF);
88
check(!err);
89
err = reftable_iterator_seek_ref(&it, "a");
90
check(!err);
@@ -164,7 +164,7 @@ static void t_merged_refs(void)
164
size_t cap = 0;
165
size_t i;
166
167
- err = merged_table_init_iter(mt, &it, BLOCK_TYPE_REF);
167
+ err = merged_table_init_iter(mt, &it, REFTABLE_BLOCK_TYPE_REF);
168
check(!err);
169
err = reftable_iterator_seek_ref(&it, "a");
170
check(!err);
@@ -244,7 +244,7 @@ static void t_merged_seek_multiple_times(void)
244
struct reftable_merged_table *mt;
245
246
mt = merged_table_from_records(refs, &sources, &tables, sizes, bufs, 2);
247
- merged_table_init_iter(mt, &it, BLOCK_TYPE_REF);
247
+ merged_table_init_iter(mt, &it, REFTABLE_BLOCK_TYPE_REF);
248
249
for (size_t i = 0; i < 5; i++) {
250
int err = reftable_iterator_seek_ref(&it, "c");
@@ -320,7 +320,7 @@ static void t_merged_seek_multiple_times_without_draining(void)
320
int err;
321
322
mt = merged_table_from_records(refs, &sources, &tables, sizes, bufs, 2);
323
- merged_table_init_iter(mt, &it, BLOCK_TYPE_REF);
323
+ merged_table_init_iter(mt, &it, REFTABLE_BLOCK_TYPE_REF);
324
325
err = reftable_iterator_seek_ref(&it, "b");
326
check(!err);
@@ -445,7 +445,7 @@ static void t_merged_logs(void)
445
size_t cap = 0;
446
size_t i;
447
448
- err = merged_table_init_iter(mt, &it, BLOCK_TYPE_LOG);
448
+ err = merged_table_init_iter(mt, &it, REFTABLE_BLOCK_TYPE_LOG);
449
check(!err);
450
err = reftable_iterator_seek_log(&it, "a");
451
check(!err);
@@ -469,7 +469,7 @@ static void t_merged_logs(void)
469
check(reftable_log_record_equal(want[i], &out[i],
470
REFTABLE_HASH_SIZE_SHA1));
471
472
- err = merged_table_init_iter(mt, &it, BLOCK_TYPE_LOG);
472
+ err = merged_table_init_iter(mt, &it, REFTABLE_BLOCK_TYPE_LOG);
473
check(!err);
474
err = reftable_iterator_seek_log_at(&it, "a", 2);
475
check(!err);
t/unit-tests/t-reftable-pq.c
+5
-5
@@ -34,7 +34,7 @@ static void t_pq_record(void)
34
char *last = NULL;
35
36
for (i = 0; i < N; i++) {
37
- check(!reftable_record_init(&recs[i], BLOCK_TYPE_REF));
37
+ check(!reftable_record_init(&recs[i], REFTABLE_BLOCK_TYPE_REF));
38
recs[i].u.ref.refname = xstrfmt("%02"PRIuMAX, (uintmax_t)i);
39
}
40
@@ -57,7 +57,7 @@ static void t_pq_record(void)
57
merged_iter_pqueue_check(&pq);
58
59
check(pq_entry_equal(&top, &e));
60
- check(reftable_record_type(e.rec) == BLOCK_TYPE_REF);
60
+ check(reftable_record_type(e.rec) == REFTABLE_BLOCK_TYPE_REF);
61
if (last)
62
check_int(strcmp(last, e.rec->u.ref.refname), <, 0);
63
last = e.rec->u.ref.refname;
@@ -76,7 +76,7 @@ static void t_pq_index(void)
76
size_t N = ARRAY_SIZE(recs), i;
77
78
for (i = 0; i < N; i++) {
79
- check(!reftable_record_init(&recs[i], BLOCK_TYPE_REF));
79
+ check(!reftable_record_init(&recs[i], REFTABLE_BLOCK_TYPE_REF));
80
recs[i].u.ref.refname = (char *) "refs/heads/master";
81
}
82
@@ -100,7 +100,7 @@ static void t_pq_index(void)
100
merged_iter_pqueue_check(&pq);
101
102
check(pq_entry_equal(&top, &e));
103
- check(reftable_record_type(e.rec) == BLOCK_TYPE_REF);
103
+ check(reftable_record_type(e.rec) == REFTABLE_BLOCK_TYPE_REF);
104
check_int(e.index, ==, i);
105
if (last)
106
check_str(last, e.rec->u.ref.refname);
@@ -117,7 +117,7 @@ static void t_merged_iter_pqueue_top(void)
117
size_t N = ARRAY_SIZE(recs), i;
118
119
for (i = 0; i < N; i++) {
120
- check(!reftable_record_init(&recs[i], BLOCK_TYPE_REF));
120
+ check(!reftable_record_init(&recs[i], REFTABLE_BLOCK_TYPE_REF));
121
recs[i].u.ref.refname = (char *) "refs/heads/master";
122
}
123
t/unit-tests/t-reftable-record.c
+20
-20
@@ -84,17 +84,17 @@ static void t_reftable_ref_record_comparison(void)
84
{
85
struct reftable_record in[3] = {
86
{
87
- .type = BLOCK_TYPE_REF,
87
+ .type = REFTABLE_BLOCK_TYPE_REF,
88
.u.ref.refname = (char *) "refs/heads/master",
89
.u.ref.value_type = REFTABLE_REF_VAL1,
90
},
91
{
92
- .type = BLOCK_TYPE_REF,
92
+ .type = REFTABLE_BLOCK_TYPE_REF,
93
.u.ref.refname = (char *) "refs/heads/master",
94
.u.ref.value_type = REFTABLE_REF_DELETION,
95
},
96
{
97
- .type = BLOCK_TYPE_REF,
97
+ .type = REFTABLE_BLOCK_TYPE_REF,
98
.u.ref.refname = (char *) "HEAD",
99
.u.ref.value_type = REFTABLE_REF_SYMREF,
100
.u.ref.value.symref = (char *) "refs/heads/master",
@@ -141,10 +141,10 @@ static void t_reftable_ref_record_roundtrip(void)
141
142
for (int i = REFTABLE_REF_DELETION; i < REFTABLE_NR_REF_VALUETYPES; i++) {
143
struct reftable_record in = {
144
- .type = BLOCK_TYPE_REF,
144
+ .type = REFTABLE_BLOCK_TYPE_REF,
145
.u.ref.value_type = i,
146
};
147
- struct reftable_record out = { .type = BLOCK_TYPE_REF };
147
+ struct reftable_record out = { .type = REFTABLE_BLOCK_TYPE_REF };
148
struct reftable_buf key = REFTABLE_BUF_INIT;
149
uint8_t buffer[1024] = { 0 };
150
struct string_view dest = {
@@ -198,17 +198,17 @@ static void t_reftable_log_record_comparison(void)
198
{
199
struct reftable_record in[3] = {
200
{
201
- .type = BLOCK_TYPE_LOG,
201
+ .type = REFTABLE_BLOCK_TYPE_LOG,
202
.u.log.refname = (char *) "refs/heads/master",
203
.u.log.update_index = 42,
204
},
205
{
206
- .type = BLOCK_TYPE_LOG,
206
+ .type = REFTABLE_BLOCK_TYPE_LOG,
207
.u.log.refname = (char *) "refs/heads/master",
208
.u.log.update_index = 22,
209
},
210
{
211
- .type = BLOCK_TYPE_LOG,
211
+ .type = REFTABLE_BLOCK_TYPE_LOG,
212
.u.log.refname = (char *) "refs/heads/main",
213
.u.log.update_index = 22,
214
},
@@ -297,7 +297,7 @@ static void t_reftable_log_record_roundtrip(void)
297
check(!reftable_log_record_is_deletion(&in[2]));
298
299
for (size_t i = 0; i < ARRAY_SIZE(in); i++) {
300
- struct reftable_record rec = { .type = BLOCK_TYPE_LOG };
300
+ struct reftable_record rec = { .type = REFTABLE_BLOCK_TYPE_LOG };
301
struct reftable_buf key = REFTABLE_BUF_INIT;
302
uint8_t buffer[1024] = { 0 };
303
struct string_view dest = {
@@ -306,7 +306,7 @@ static void t_reftable_log_record_roundtrip(void)
306
};
307
/* populate out, to check for leaks. */
308
struct reftable_record out = {
309
- .type = BLOCK_TYPE_LOG,
309
+ .type = REFTABLE_BLOCK_TYPE_LOG,
310
.u.log = {
311
.refname = xstrdup("old name"),
312
.value_type = REFTABLE_LOG_UPDATE,
@@ -384,21 +384,21 @@ static void t_reftable_obj_record_comparison(void)
384
uint64_t offsets[] = { 0, 16, 32, 48, 64, 80, 96, 112};
385
struct reftable_record in[3] = {
386
{
387
- .type = BLOCK_TYPE_OBJ,
387
+ .type = REFTABLE_BLOCK_TYPE_OBJ,
388
.u.obj.hash_prefix = id_bytes,
389
.u.obj.hash_prefix_len = 7,
390
.u.obj.offsets = offsets,
391
.u.obj.offset_len = 8,
392
},
393
{
394
- .type = BLOCK_TYPE_OBJ,
394
+ .type = REFTABLE_BLOCK_TYPE_OBJ,
395
.u.obj.hash_prefix = id_bytes,
396
.u.obj.hash_prefix_len = 7,
397
.u.obj.offsets = offsets,
398
.u.obj.offset_len = 5,
399
},
400
{
401
- .type = BLOCK_TYPE_OBJ,
401
+ .type = REFTABLE_BLOCK_TYPE_OBJ,
402
.u.obj.hash_prefix = id_bytes,
403
.u.obj.hash_prefix_len = 5,
404
},
@@ -450,13 +450,13 @@ static void t_reftable_obj_record_roundtrip(void)
450
.len = sizeof(buffer),
451
};
452
struct reftable_record in = {
453
- .type = BLOCK_TYPE_OBJ,
453
+ .type = REFTABLE_BLOCK_TYPE_OBJ,
454
.u = {
455
.obj = recs[i],
456
},
457
};
458
struct reftable_buf key = REFTABLE_BUF_INIT;
459
- struct reftable_record out = { .type = BLOCK_TYPE_OBJ };
459
+ struct reftable_record out = { .type = REFTABLE_BLOCK_TYPE_OBJ };
460
int n, m;
461
uint8_t extra;
462
@@ -482,17 +482,17 @@ static void t_reftable_index_record_comparison(void)
482
{
483
struct reftable_record in[3] = {
484
{
485
- .type = BLOCK_TYPE_INDEX,
485
+ .type = REFTABLE_BLOCK_TYPE_INDEX,
486
.u.idx.offset = 22,
487
.u.idx.last_key = REFTABLE_BUF_INIT,
488
},
489
{
490
- .type = BLOCK_TYPE_INDEX,
490
+ .type = REFTABLE_BLOCK_TYPE_INDEX,
491
.u.idx.offset = 32,
492
.u.idx.last_key = REFTABLE_BUF_INIT,
493
},
494
{
495
- .type = BLOCK_TYPE_INDEX,
495
+ .type = REFTABLE_BLOCK_TYPE_INDEX,
496
.u.idx.offset = 32,
497
.u.idx.last_key = REFTABLE_BUF_INIT,
498
},
@@ -523,7 +523,7 @@ static void t_reftable_index_record_comparison(void)
523
static void t_reftable_index_record_roundtrip(void)
524
{
525
struct reftable_record in = {
526
- .type = BLOCK_TYPE_INDEX,
526
+ .type = REFTABLE_BLOCK_TYPE_INDEX,
527
.u.idx = {
528
.offset = 42,
529
.last_key = REFTABLE_BUF_INIT,
@@ -537,7 +537,7 @@ static void t_reftable_index_record_roundtrip(void)
537
struct reftable_buf scratch = REFTABLE_BUF_INIT;
538
struct reftable_buf key = REFTABLE_BUF_INIT;
539
struct reftable_record out = {
540
- .type = BLOCK_TYPE_INDEX,
540
+ .type = REFTABLE_BLOCK_TYPE_INDEX,
541
.u.idx = { .last_key = REFTABLE_BUF_INIT },
542
};
543
int n, m;
t/unit-tests/t-reftable-table.c
+6
-6
@@ -106,33 +106,33 @@ static int t_table_block_iterator(void)
106
uint16_t record_count;
107
} expected_blocks[] = {
108
{
109
- .block_type = BLOCK_TYPE_REF,
109
+ .block_type = REFTABLE_BLOCK_TYPE_REF,
110
.header_off = 24,
111
.restart_count = 10,
112
.record_count = 158,
113
},
114
{
115
- .block_type = BLOCK_TYPE_REF,
115
+ .block_type = REFTABLE_BLOCK_TYPE_REF,
116
.restart_count = 10,
117
.record_count = 159,
118
},
119
{
120
- .block_type = BLOCK_TYPE_REF,
120
+ .block_type = REFTABLE_BLOCK_TYPE_REF,
121
.restart_count = 10,
122
.record_count = 159,
123
},
124
{
125
- .block_type = BLOCK_TYPE_REF,
125
+ .block_type = REFTABLE_BLOCK_TYPE_REF,
126
.restart_count = 2,
127
.record_count = 24,
128
},
129
{
130
- .block_type = BLOCK_TYPE_INDEX,
130
+ .block_type = REFTABLE_BLOCK_TYPE_INDEX,
131
.restart_count = 1,
132
.record_count = 4,
133
},
134
{
135
- .block_type = BLOCK_TYPE_OBJ,
135
+ .block_type = REFTABLE_BLOCK_TYPE_OBJ,
136
.restart_count = 1,
137
.record_count = 1,
138
},