Skip to content

Commit 3c443a0

Browse files
hanwengitster
authored andcommitted
reftable: add test for length of disambiguating prefix
The ID => ref map is trimming object IDs to a disambiguating prefix. Check that we are computing their length correctly. Signed-off-by: Han-Wen Nienhuys <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b4007fc commit 3c443a0

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

reftable/readwrite_test.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,43 @@ static void test_write_object_id_min_length(void)
703703
strbuf_release(&buf);
704704
}
705705

706+
static void test_write_object_id_length(void)
707+
{
708+
struct reftable_write_options opts = {
709+
.block_size = 75,
710+
};
711+
struct strbuf buf = STRBUF_INIT;
712+
struct reftable_writer *w =
713+
reftable_new_writer(&strbuf_add_void, &buf, &opts);
714+
uint8_t hash[GIT_SHA1_RAWSZ] = {42};
715+
struct reftable_ref_record ref = {
716+
.update_index = 1,
717+
.value_type = REFTABLE_REF_VAL1,
718+
.value.val1 = hash,
719+
};
720+
int err;
721+
int i;
722+
723+
reftable_writer_set_limits(w, 1, 1);
724+
725+
/* Write the same hash in many refs. If there is only 1 hash, the
726+
* disambiguating prefix is length 0 */
727+
for (i = 0; i < 256; i++) {
728+
char name[256];
729+
snprintf(name, sizeof(name), "ref%05d", i);
730+
ref.refname = name;
731+
ref.value.val1[15] = i;
732+
err = reftable_writer_add_ref(w, &ref);
733+
EXPECT_ERR(err);
734+
}
735+
736+
err = reftable_writer_close(w);
737+
EXPECT_ERR(err);
738+
EXPECT(writer_stats(w)->object_id_len == 16);
739+
reftable_writer_free(w);
740+
strbuf_release(&buf);
741+
}
742+
706743
static void test_write_empty_key(void)
707744
{
708745
struct reftable_write_options opts = { 0 };
@@ -808,6 +845,7 @@ int readwrite_test_main(int argc, const char *argv[])
808845
RUN_TEST(test_write_empty_key);
809846
RUN_TEST(test_write_empty_table);
810847
RUN_TEST(test_log_overflow);
848+
RUN_TEST(test_write_object_id_length);
811849
RUN_TEST(test_write_object_id_min_length);
812850
return 0;
813851
}

0 commit comments

Comments
 (0)