| 518 | } |
| 519 | |
| 520 | static void t_table_refs_for(int indexed) |
| 521 | { |
| 522 | char **want_names; |
| 523 | int want_names_len = 0; |
| 524 | uint8_t want_hash[REFTABLE_HASH_SIZE_SHA1]; |
| 525 | |
| 526 | struct reftable_write_options opts = { |
| 527 | .block_size = 256, |
| 528 | }; |
| 529 | struct reftable_ref_record ref = { 0 }; |
| 530 | struct reftable_table *table; |
| 531 | struct reftable_block_source source = { 0 }; |
| 532 | struct reftable_buf buf = REFTABLE_BUF_INIT; |
| 533 | struct reftable_writer *w = cl_reftable_strbuf_writer(&buf, |
| 534 | &opts); |
| 535 | struct reftable_iterator it = { 0 }; |
| 536 | int N = 50, j, i; |
| 537 | int err; |
| 538 | |
| 539 | want_names = reftable_calloc(N + 1, sizeof(*want_names)); |
| 540 | cl_assert(want_names != NULL); |
| 541 | |
| 542 | cl_reftable_set_hash(want_hash, 4, REFTABLE_HASH_SHA1); |
| 543 | |
| 544 | for (i = 0; i < N; i++) { |
| 545 | uint8_t hash[REFTABLE_HASH_SIZE_SHA1]; |
| 546 | char fill[51] = { 0 }; |
| 547 | char name[100]; |
| 548 | struct reftable_ref_record ref = { 0 }; |
| 549 | |
| 550 | memset(hash, i, sizeof(hash)); |
| 551 | memset(fill, 'x', 50); |
| 552 | /* Put the variable part in the start */ |
| 553 | snprintf(name, sizeof(name), "br%02d%s", i, fill); |
| 554 | name[40] = 0; |
| 555 | ref.refname = name; |
| 556 | |
| 557 | ref.value_type = REFTABLE_REF_VAL2; |
| 558 | cl_reftable_set_hash(ref.value.val2.value, i / 4, |
| 559 | REFTABLE_HASH_SHA1); |
| 560 | cl_reftable_set_hash(ref.value.val2.target_value, |
| 561 | 3 + i / 4, REFTABLE_HASH_SHA1); |
| 562 | |
| 563 | /* 80 bytes / entry, so 3 entries per block. Yields 17 |
| 564 | */ |
| 565 | /* blocks. */ |
| 566 | cl_assert_equal_i(reftable_writer_add_ref(w, &ref), 0); |
| 567 | |
| 568 | if (!memcmp(ref.value.val2.value, want_hash, REFTABLE_HASH_SIZE_SHA1) || |
| 569 | !memcmp(ref.value.val2.target_value, want_hash, REFTABLE_HASH_SIZE_SHA1)) |
| 570 | want_names[want_names_len++] = xstrdup(name); |
| 571 | } |
| 572 | |
| 573 | cl_assert_equal_i(reftable_writer_close(w), 0); |
| 574 | |
| 575 | reftable_writer_free(w); |
| 576 | w = NULL; |
| 577 | |