| 721 | } |
| 722 | |
| 723 | void test_reftable_stack__tombstone(void) |
| 724 | { |
| 725 | char *dir = get_tmp_dir(__LINE__); |
| 726 | struct reftable_write_options opts = { 0 }; |
| 727 | struct reftable_stack *st = NULL; |
| 728 | struct reftable_ref_record refs[2] = { 0 }; |
| 729 | struct reftable_log_record logs[2] = { 0 }; |
| 730 | size_t i, N = ARRAY_SIZE(refs); |
| 731 | struct reftable_ref_record dest = { 0 }; |
| 732 | struct reftable_log_record log_dest = { 0 }; |
| 733 | |
| 734 | cl_assert_equal_i(reftable_new_stack(&st, dir, &opts), 0); |
| 735 | |
| 736 | /* even entries add the refs, odd entries delete them. */ |
| 737 | for (i = 0; i < N; i++) { |
| 738 | const char *buf = "branch"; |
| 739 | refs[i].refname = xstrdup(buf); |
| 740 | refs[i].update_index = i + 1; |
| 741 | if (i % 2 == 0) { |
| 742 | refs[i].value_type = REFTABLE_REF_VAL1; |
| 743 | cl_reftable_set_hash(refs[i].value.val1, i, |
| 744 | REFTABLE_HASH_SHA1); |
| 745 | } |
| 746 | |
| 747 | logs[i].refname = xstrdup(buf); |
| 748 | /* |
| 749 | * update_index is part of the key so should be constant. |
| 750 | * The value itself should be less than the writer's upper |
| 751 | * limit. |
| 752 | */ |
| 753 | logs[i].update_index = 1; |
| 754 | if (i % 2 == 0) { |
| 755 | logs[i].value_type = REFTABLE_LOG_UPDATE; |
| 756 | cl_reftable_set_hash(logs[i].value.update.new_hash, i, REFTABLE_HASH_SHA1); |
| 757 | logs[i].value.update.email = |
| 758 | xstrdup("identity@invalid"); |
| 759 | } |
| 760 | } |
| 761 | for (i = 0; i < N; i++) |
| 762 | cl_assert_equal_i(reftable_stack_add(st, write_test_ref, |
| 763 | &refs[i], 0), 0); |
| 764 | |
| 765 | for (i = 0; i < N; i++) { |
| 766 | struct write_log_arg arg = { |
| 767 | .log = &logs[i], |
| 768 | .update_index = reftable_stack_next_update_index(st), |
| 769 | }; |
| 770 | cl_assert_equal_i(reftable_stack_add(st, write_test_log, |
| 771 | &arg, 0), 0); |
| 772 | } |
| 773 | |
| 774 | cl_assert_equal_i(reftable_stack_read_ref(st, "branch", |
| 775 | &dest), 1); |
| 776 | reftable_ref_record_release(&dest); |
| 777 | |
| 778 | cl_assert_equal_i(reftable_stack_read_log(st, "branch", |
| 779 | &log_dest), 1); |
| 780 | reftable_log_record_release(&log_dest); |
nothing calls this directly
no test coverage detected