From 799237852bd265feb1e1a8d4a19780e20991b4fd Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Mon, 13 May 2024 10:17:59 +0200 Subject: reftable: pass opts as constant pointer We sometimes pass the refatble write options as value and sometimes as a pointer. This is quite confusing and makes the reader wonder whether the options get modified sometimes. In fact, `reftable_new_writer()` does cause the caller-provided options to get updated when some values aren't set up. This is quite unexpected, but didn't cause any harm until now. Adapt the code so that we do not modify the caller-provided values anymore. While at it, refactor the code to code to consistently pass the options as a constant pointer to clarify that the caller-provided opts will not ever get modified. Signed-off-by: Patrick Steinhardt Signed-off-by: Junio C Hamano --- reftable/stack.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'reftable/stack.c') diff --git a/reftable/stack.c b/reftable/stack.c index 54e7473f3a..d2e68be7e8 100644 --- a/reftable/stack.c +++ b/reftable/stack.c @@ -54,12 +54,15 @@ static int reftable_fd_flush(void *arg) } int reftable_new_stack(struct reftable_stack **dest, const char *dir, - struct reftable_write_options opts) + const struct reftable_write_options *_opts) { struct reftable_stack *p = reftable_calloc(1, sizeof(*p)); struct strbuf list_file_name = STRBUF_INIT; + struct reftable_write_options opts = {0}; int err = 0; + if (_opts) + opts = *_opts; if (opts.hash_id == 0) opts.hash_id = GIT_SHA1_FORMAT_ID; @@ -1438,7 +1441,7 @@ int reftable_stack_print_directory(const char *stackdir, uint32_t hash_id) struct reftable_merged_table *merged = NULL; struct reftable_table table = { NULL }; - int err = reftable_new_stack(&stack, stackdir, opts); + int err = reftable_new_stack(&stack, stackdir, &opts); if (err < 0) goto done; -- cgit v1.3