Skip to content

Commit 2b3362c

Browse files
pks-tgitster
authored andcommitted
reftable/block: rename block to block_data
The `reftable_block` structure associates a byte slice with a block source. As such it only holds the data of a reftable block without actually encoding any of the details for how to access that data. Rename the structure to instead be called `reftable_block_data`. Besides clarifying that this really only holds data, it also allows us to rename the `reftable_block_reader` to `reftable_block` in the next commit, as this is the structure that actually encapsulates access to the reftable blocks. Rename the `struct reftable_block_reader::block` member accordingly. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent fd88831 commit 2b3362c

File tree

8 files changed

+73
-73
lines changed

8 files changed

+73
-73
lines changed

reftable/block.c

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -210,16 +210,16 @@ int block_writer_finish(struct block_writer *w)
210210
}
211211

212212
static int read_block(struct reftable_block_source *source,
213-
struct reftable_block *dest, uint64_t off,
213+
struct reftable_block_data *dest, uint64_t off,
214214
uint32_t sz)
215215
{
216216
size_t size = block_source_size(source);
217-
block_source_return_block(dest);
217+
block_source_release_data(dest);
218218
if (off >= size)
219219
return 0;
220220
if (off + sz > size)
221221
sz = size - off;
222-
return block_source_read_block(source, dest, off, sz);
222+
return block_source_read_data(source, dest, off, sz);
223223
}
224224

225225
int block_reader_init(struct block_reader *br,
@@ -236,27 +236,27 @@ int block_reader_init(struct block_reader *br,
236236
uint8_t block_type;
237237
int err;
238238

239-
err = read_block(source, &br->block, offset, guess_block_size);
239+
err = read_block(source, &br->block_data, offset, guess_block_size);
240240
if (err < 0)
241241
goto done;
242242

243-
block_type = br->block.data[header_size];
243+
block_type = br->block_data.data[header_size];
244244
if (!reftable_is_block_type(block_type)) {
245245
err = REFTABLE_FORMAT_ERROR;
246246
goto done;
247247
}
248248

249-
block_size = reftable_get_be24(br->block.data + header_size + 1);
249+
block_size = reftable_get_be24(br->block_data.data + header_size + 1);
250250
if (block_size > guess_block_size) {
251-
err = read_block(source, &br->block, offset, block_size);
251+
err = read_block(source, &br->block_data, offset, block_size);
252252
if (err < 0)
253253
goto done;
254254
}
255255

256256
if (block_type == BLOCK_TYPE_LOG) {
257257
uint32_t block_header_skip = 4 + header_size;
258258
uLong dst_len = block_size - block_header_skip;
259-
uLong src_len = br->block.len - block_header_skip;
259+
uLong src_len = br->block_data.len - block_header_skip;
260260

261261
/* Log blocks specify the *uncompressed* size in their header. */
262262
REFTABLE_ALLOC_GROW_OR_NULL(br->uncompressed_data, block_size,
@@ -267,7 +267,7 @@ int block_reader_init(struct block_reader *br,
267267
}
268268

269269
/* Copy over the block header verbatim. It's not compressed. */
270-
memcpy(br->uncompressed_data, br->block.data, block_header_skip);
270+
memcpy(br->uncompressed_data, br->block_data.data, block_header_skip);
271271

272272
if (!br->zstream) {
273273
REFTABLE_CALLOC_ARRAY(br->zstream, 1);
@@ -285,7 +285,7 @@ int block_reader_init(struct block_reader *br,
285285
goto done;
286286
}
287287

288-
br->zstream->next_in = br->block.data + block_header_skip;
288+
br->zstream->next_in = br->block_data.data + block_header_skip;
289289
br->zstream->avail_in = src_len;
290290
br->zstream->next_out = br->uncompressed_data + block_header_skip;
291291
br->zstream->avail_out = dst_len;
@@ -310,21 +310,21 @@ int block_reader_init(struct block_reader *br,
310310
}
311311

312312
/* We're done with the input data. */
313-
block_source_return_block(&br->block);
314-
br->block.data = br->uncompressed_data;
315-
br->block.len = block_size;
313+
block_source_release_data(&br->block_data);
314+
br->block_data.data = br->uncompressed_data;
315+
br->block_data.len = block_size;
316316
full_block_size = src_len + block_header_skip - br->zstream->avail_in;
317317
} else if (full_block_size == 0) {
318318
full_block_size = block_size;
319-
} else if (block_size < full_block_size && block_size < br->block.len &&
320-
br->block.data[block_size] != 0) {
319+
} else if (block_size < full_block_size && block_size < br->block_data.len &&
320+
br->block_data.data[block_size] != 0) {
321321
/* If the block is smaller than the full block size, it is
322322
padded (data followed by '\0') or the next block is
323323
unaligned. */
324324
full_block_size = block_size;
325325
}
326326

327-
restart_count = reftable_get_be16(br->block.data + block_size - 2);
327+
restart_count = reftable_get_be16(br->block_data.data + block_size - 2);
328328
restart_off = block_size - 2 - 3 * restart_count;
329329

330330
br->block_type = block_type;
@@ -347,20 +347,20 @@ void block_reader_release(struct block_reader *br)
347347
inflateEnd(br->zstream);
348348
reftable_free(br->zstream);
349349
reftable_free(br->uncompressed_data);
350-
block_source_return_block(&br->block);
350+
block_source_release_data(&br->block_data);
351351
memset(br, 0, sizeof(*br));
352352
}
353353

354354
uint8_t block_reader_type(const struct block_reader *r)
355355
{
356-
return r->block.data[r->header_off];
356+
return r->block_data.data[r->header_off];
357357
}
358358

359359
int block_reader_first_key(const struct block_reader *br, struct reftable_buf *key)
360360
{
361361
int off = br->header_off + 4, n;
362362
struct string_view in = {
363-
.buf = br->block.data + off,
363+
.buf = br->block_data.data + off,
364364
.len = br->restart_off - off,
365365
};
366366
uint8_t extra = 0;
@@ -378,12 +378,12 @@ int block_reader_first_key(const struct block_reader *br, struct reftable_buf *k
378378

379379
static uint32_t block_reader_restart_offset(const struct block_reader *br, size_t idx)
380380
{
381-
return reftable_get_be24(br->block.data + br->restart_off + 3 * idx);
381+
return reftable_get_be24(br->block_data.data + br->restart_off + 3 * idx);
382382
}
383383

384384
void block_iter_seek_start(struct block_iter *it, const struct block_reader *br)
385385
{
386-
it->block = br->block.data;
386+
it->block = br->block_data.data;
387387
it->block_len = br->restart_off;
388388
it->hash_size = br->hash_size;
389389
reftable_buf_reset(&it->last_key);
@@ -401,7 +401,7 @@ static int restart_needle_less(size_t idx, void *_args)
401401
struct restart_needle_less_args *args = _args;
402402
uint32_t off = block_reader_restart_offset(args->reader, idx);
403403
struct string_view in = {
404-
.buf = args->reader->block.data + off,
404+
.buf = args->reader->block_data.data + off,
405405
.len = args->reader->restart_off - off,
406406
};
407407
uint64_t prefix_len, suffix_len;
@@ -528,7 +528,7 @@ int block_iter_seek_key(struct block_iter *it, const struct block_reader *br,
528528
it->next_off = block_reader_restart_offset(br, i - 1);
529529
else
530530
it->next_off = br->header_off + 4;
531-
it->block = br->block.data;
531+
it->block = br->block_data.data;
532532
it->block_len = br->restart_off;
533533
it->hash_size = br->hash_size;
534534

reftable/block.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ struct block_reader {
7171
uint32_t header_off;
7272

7373
/* the memory block */
74-
struct reftable_block block;
74+
struct reftable_block_data block_data;
7575
uint32_t hash_size;
7676

7777
/* Uncompressed data for log entries. */

reftable/blocksource.c

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@
1313
#include "reftable-blocksource.h"
1414
#include "reftable-error.h"
1515

16-
void block_source_return_block(struct reftable_block *block)
16+
void block_source_release_data(struct reftable_block_data *data)
1717
{
18-
struct reftable_block_source source = block->source;
19-
if (block && source.ops)
20-
source.ops->return_block(source.arg, block);
21-
block->data = NULL;
22-
block->len = 0;
23-
block->source.ops = NULL;
24-
block->source.arg = NULL;
18+
struct reftable_block_source source = data->source;
19+
if (data && source.ops)
20+
source.ops->release_data(source.arg, data);
21+
data->data = NULL;
22+
data->len = 0;
23+
data->source.ops = NULL;
24+
data->source.arg = NULL;
2525
}
2626

2727
void block_source_close(struct reftable_block_source *source)
@@ -34,11 +34,11 @@ void block_source_close(struct reftable_block_source *source)
3434
source->ops = NULL;
3535
}
3636

37-
ssize_t block_source_read_block(struct reftable_block_source *source,
38-
struct reftable_block *dest, uint64_t off,
39-
uint32_t size)
37+
ssize_t block_source_read_data(struct reftable_block_source *source,
38+
struct reftable_block_data *dest, uint64_t off,
39+
uint32_t size)
4040
{
41-
ssize_t result = source->ops->read_block(source->arg, dest, off, size);
41+
ssize_t result = source->ops->read_data(source->arg, dest, off, size);
4242
dest->source = *source;
4343
return result;
4444
}
@@ -48,7 +48,7 @@ uint64_t block_source_size(struct reftable_block_source *source)
4848
return source->ops->size(source->arg);
4949
}
5050

51-
static void reftable_buf_return_block(void *b REFTABLE_UNUSED, struct reftable_block *dest)
51+
static void reftable_buf_release_data(void *b REFTABLE_UNUSED, struct reftable_block_data *dest)
5252
{
5353
if (dest->len)
5454
memset(dest->data, 0xff, dest->len);
@@ -59,8 +59,8 @@ static void reftable_buf_close(void *b REFTABLE_UNUSED)
5959
{
6060
}
6161

62-
static ssize_t reftable_buf_read_block(void *v, struct reftable_block *dest,
63-
uint64_t off, uint32_t size)
62+
static ssize_t reftable_buf_read_data(void *v, struct reftable_block_data *dest,
63+
uint64_t off, uint32_t size)
6464
{
6565
struct reftable_buf *b = v;
6666
assert(off + size <= b->len);
@@ -79,8 +79,8 @@ static uint64_t reftable_buf_size(void *b)
7979

8080
static struct reftable_block_source_vtable reftable_buf_vtable = {
8181
.size = &reftable_buf_size,
82-
.read_block = &reftable_buf_read_block,
83-
.return_block = &reftable_buf_return_block,
82+
.read_data = &reftable_buf_read_data,
83+
.release_data = &reftable_buf_release_data,
8484
.close = &reftable_buf_close,
8585
};
8686

@@ -102,7 +102,7 @@ static uint64_t file_size(void *b)
102102
return ((struct file_block_source *)b)->size;
103103
}
104104

105-
static void file_return_block(void *b REFTABLE_UNUSED, struct reftable_block *dest REFTABLE_UNUSED)
105+
static void file_release_data(void *b REFTABLE_UNUSED, struct reftable_block_data *dest REFTABLE_UNUSED)
106106
{
107107
}
108108

@@ -113,8 +113,8 @@ static void file_close(void *v)
113113
reftable_free(b);
114114
}
115115

116-
static ssize_t file_read_block(void *v, struct reftable_block *dest, uint64_t off,
117-
uint32_t size)
116+
static ssize_t file_read_data(void *v, struct reftable_block_data *dest, uint64_t off,
117+
uint32_t size)
118118
{
119119
struct file_block_source *b = v;
120120
assert(off + size <= b->size);
@@ -125,8 +125,8 @@ static ssize_t file_read_block(void *v, struct reftable_block *dest, uint64_t of
125125

126126
static struct reftable_block_source_vtable file_vtable = {
127127
.size = &file_size,
128-
.read_block = &file_read_block,
129-
.return_block = &file_return_block,
128+
.read_data = &file_read_data,
129+
.release_data = &file_release_data,
130130
.close = &file_close,
131131
};
132132

reftable/blocksource.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include "system.h"
1313

1414
struct reftable_block_source;
15-
struct reftable_block;
15+
struct reftable_block_data;
1616
struct reftable_buf;
1717

1818
/*
@@ -24,9 +24,9 @@ void block_source_close(struct reftable_block_source *source);
2424
/*
2525
* Read a block of length `size` from the source at the given `off`.
2626
*/
27-
ssize_t block_source_read_block(struct reftable_block_source *source,
28-
struct reftable_block *dest, uint64_t off,
29-
uint32_t size);
27+
ssize_t block_source_read_data(struct reftable_block_source *source,
28+
struct reftable_block_data *dest, uint64_t off,
29+
uint32_t size);
3030

3131
/*
3232
* Return the total length of the underlying resource.
@@ -37,7 +37,7 @@ uint64_t block_source_size(struct reftable_block_source *source);
3737
* Return a block to its original source, releasing any resources associated
3838
* with it.
3939
*/
40-
void block_source_return_block(struct reftable_block *block);
40+
void block_source_release_data(struct reftable_block_data *data);
4141

4242
/* Create an in-memory block source for reading reftables. */
4343
void block_source_from_buf(struct reftable_block_source *bs,

reftable/iter.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ static void indexed_table_ref_iter_close(void *p)
114114
{
115115
struct indexed_table_ref_iter *it = p;
116116
block_iter_close(&it->cur);
117-
block_source_return_block(&it->block_reader.block);
117+
block_source_release_data(&it->block_reader.block_data);
118118
reftable_free(it->offsets);
119119
reftable_buf_release(&it->oid);
120120
}
@@ -128,7 +128,7 @@ static int indexed_table_ref_iter_next_block(struct indexed_table_ref_iter *it)
128128
return 1;
129129
}
130130

131-
block_source_return_block(&it->block_reader.block);
131+
block_source_release_data(&it->block_reader.block_data);
132132

133133
off = it->offsets[it->offset_idx++];
134134
err = table_init_block_reader(it->table, &it->block_reader, off,

reftable/reftable-blocksource.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,28 @@ struct reftable_block_source {
2121

2222
/* a contiguous segment of bytes. It keeps track of its generating block_source
2323
* so it can return itself into the pool. */
24-
struct reftable_block {
24+
struct reftable_block_data {
2525
uint8_t *data;
2626
size_t len;
2727
struct reftable_block_source source;
2828
};
2929

3030
/* block_source_vtable are the operations that make up block_source */
3131
struct reftable_block_source_vtable {
32-
/* returns the size of a block source */
32+
/* Returns the size of a block source. */
3333
uint64_t (*size)(void *source);
3434

3535
/*
3636
* Reads a segment from the block source. It is an error to read beyond
3737
* the end of the block.
3838
*/
39-
ssize_t (*read_block)(void *source, struct reftable_block *dest,
40-
uint64_t off, uint32_t size);
39+
ssize_t (*read_data)(void *source, struct reftable_block_data *dest,
40+
uint64_t off, uint32_t size);
4141

42-
/* mark the block as read; may return the data back to malloc */
43-
void (*return_block)(void *source, struct reftable_block *blockp);
42+
/* Mark the block as read; may release the data. */
43+
void (*release_data)(void *source, struct reftable_block_data *data);
4444

45-
/* release all resources associated with the block source */
45+
/* Release all resources associated with the block source. */
4646
void (*close)(void *source);
4747
};
4848

0 commit comments

Comments
 (0)