]> git.ipfire.org Git - thirdparty/git.git/commitdiff
reftable/block: introduce macro to initialize `struct block_iter`
authorPatrick Steinhardt <ps@pks.im>
Mon, 11 Dec 2023 09:08:07 +0000 (10:08 +0100)
committerJunio C Hamano <gitster@pobox.com>
Mon, 11 Dec 2023 15:23:17 +0000 (07:23 -0800)
There are a bunch of locations where we initialize members of `struct
block_iter`, which makes it harder than necessary to expand this struct
to have additional members. Unify the logic via a new `BLOCK_ITER_INIT`
macro that initializes all members.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
reftable/block.c
reftable/block.h
reftable/block_test.c
reftable/iter.h
reftable/reader.c

index 34d4d073692f9e913d84715d987c8e1c35a7fe8a..8c6a8c77fc0f444e4a9bd2456bbb809dacfebc14 100644 (file)
@@ -389,9 +389,7 @@ int block_reader_seek(struct block_reader *br, struct block_iter *it,
        struct reftable_record rec = reftable_new_record(block_reader_type(br));
        struct strbuf key = STRBUF_INIT;
        int err = 0;
-       struct block_iter next = {
-               .last_key = STRBUF_INIT,
-       };
+       struct block_iter next = BLOCK_ITER_INIT;
 
        int i = binsearch(br->restart_count, &restart_key_less, &args);
        if (args.error) {
index 87c77539b5bd6ab0b9909c51801719258507b424..51699af233d823fafe681f3d7cbb20cf61b88d8a 100644 (file)
@@ -86,6 +86,10 @@ struct block_iter {
        struct strbuf last_key;
 };
 
+#define BLOCK_ITER_INIT { \
+       .last_key = STRBUF_INIT, \
+}
+
 /* initializes a block reader. */
 int block_reader_init(struct block_reader *br, struct reftable_block *bl,
                      uint32_t header_off, uint32_t table_block_size,
index cb88af4a5639258945f569ede758e31809b62ead..c00bbc8aed50f02d21ed06c046bed3c5d4c2f17f 100644 (file)
@@ -32,7 +32,7 @@ static void test_block_read_write(void)
        int i = 0;
        int n;
        struct block_reader br = { 0 };
-       struct block_iter it = { .last_key = STRBUF_INIT };
+       struct block_iter it = BLOCK_ITER_INIT;
        int j = 0;
        struct strbuf want = STRBUF_INIT;
 
@@ -87,7 +87,7 @@ static void test_block_read_write(void)
        block_iter_close(&it);
 
        for (i = 0; i < N; i++) {
-               struct block_iter it = { .last_key = STRBUF_INIT };
+               struct block_iter it = BLOCK_ITER_INIT;
                strbuf_reset(&want);
                strbuf_addstr(&want, names[i]);
 
index 09eb0cbfa5997e0eca4f378a8d45025c4af8732d..47d67d84df679c522ce50d1d7aade2d1be683b5a 100644 (file)
@@ -53,10 +53,10 @@ struct indexed_table_ref_iter {
        int is_finished;
 };
 
-#define INDEXED_TABLE_REF_ITER_INIT                                     \
-       {                                                               \
-               .cur = { .last_key = STRBUF_INIT }, .oid = STRBUF_INIT, \
-       }
+#define INDEXED_TABLE_REF_ITER_INIT { \
+       .cur = BLOCK_ITER_INIT, \
+       .oid = STRBUF_INIT, \
+}
 
 void iterator_from_indexed_table_ref_iter(struct reftable_iterator *it,
                                          struct indexed_table_ref_iter *itr);
index b4db23ce1880794a937b841e28ffa27e8869d2c7..9de64f50b444dc792763fd40cf85a6cf39f67399 100644 (file)
@@ -224,10 +224,9 @@ struct table_iter {
        struct block_iter bi;
        int is_finished;
 };
-#define TABLE_ITER_INIT                          \
-       {                                        \
-               .bi = {.last_key = STRBUF_INIT } \
-       }
+#define TABLE_ITER_INIT { \
+       .bi = BLOCK_ITER_INIT \
+}
 
 static void table_iter_copy_from(struct table_iter *dest,
                                 struct table_iter *src)