Files
git/reftable/writer.h
Patrick Steinhardt 44f46f2be5 reftable: split up write options
When initializing the reftable stack the caller may optionally pass some
write options. These write options mix up two different concerns though:

  - Of course, they allow the caller to configure how new reftables are
    being written.

  - But they also allow the caller to configure the stack itself, like
    its hash ID and the `on_reload` callback.

This is somewhat awkward, as it doesn't easily give the caller the
flexibility to for example write multiple reftables with different
options. Furthermore, this requires us to eagerly parse relevant
configuration when initializing the reftable backend.

Refactor the code by splitting out those options that configure the
stack itself. Creating a new stack will thus only require this limited
set of options, whereas the caller is expected to pass write options to
all functions that end up writing tables.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2026-06-26 08:27:19 -07:00

55 lines
1.2 KiB
C

/*
* Copyright 2020 Google LLC
*
* Use of this source code is governed by a BSD-style
* license that can be found in the LICENSE file or at
* https://developers.google.com/open-source/licenses/bsd
*/
#ifndef WRITER_H
#define WRITER_H
#include "basics.h"
#include "block.h"
#include "tree.h"
#include "reftable-writer.h"
struct reftable_writer {
ssize_t (*write)(void *, const void *, size_t);
int (*flush)(void *);
void *write_arg;
int pending_padding;
struct reftable_buf last_key;
/* Scratch buffer used to avoid allocations. */
struct reftable_buf scratch;
/* offset of next block to write. */
uint64_t next;
uint64_t min_update_index, max_update_index;
struct reftable_write_options opts;
enum reftable_hash hash_id;
/* memory buffer for writing */
uint8_t *block;
/* writer for the current section. NULL or points to
* block_writer_data */
struct block_writer *block_writer;
struct block_writer block_writer_data;
/* pending index records for the current section */
struct reftable_index_record *index;
size_t index_len;
size_t index_cap;
/*
* tree for use with tsearch; used to populate the 'o' inverse OID
* map */
struct tree_node *obj_index_tree;
struct reftable_stats stats;
};
#endif