Git fork

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>

authored by

Patrick Steinhardt and committed by
Junio C Hamano
0f8ee94b da896593

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