summaryrefslogtreecommitdiffstats
path: root/reftable
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2024-11-26 07:42:59 +0100
committerJunio C Hamano <gitster@pobox.com>2024-11-26 09:18:38 +0100
commiteb22c1b46b85f7fac8467f991890d50853e4ca4d (patch)
treeeae568370d99e59ad0e5b4ea87a811b0eaff985a /reftable
parentrefs/reftable: refactor reflog expiry to use reftable backend (diff)
downloadgit-eb22c1b46b85f7fac8467f991890d50853e4ca4d.tar.xz
git-eb22c1b46b85f7fac8467f991890d50853e4ca4d.zip
reftable/stack: add mechanism to notify callers on reload
Reftable stacks are reloaded in two cases: - When calling `reftable_stack_reload()`, if the stat-cache tells us that the stack has been modified. - When committing a reftable addition. While callers can figure out the second case, they do not have a mechanism to figure out whether `reftable_stack_reload()` led to an actual reload of the on-disk data. All they can do is thus to assume that data is always being reloaded in that case. Improve the situation by introducing a new `on_reload()` callback to the reftable options. If provided, the function will be invoked every time the stack has indeed been reloaded. This allows callers to invalidate data that depends on the current stack data. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'reftable')
-rw-r--r--reftable/reftable-writer.h9
-rw-r--r--reftable/stack.c4
2 files changed, 13 insertions, 0 deletions
diff --git a/reftable/reftable-writer.h b/reftable/reftable-writer.h
index c85ef5a5bd..5f9afa620b 100644
--- a/reftable/reftable-writer.h
+++ b/reftable/reftable-writer.h
@@ -68,6 +68,15 @@ struct reftable_write_options {
* fsync(3P) when unset.
*/
int (*fsync)(int fd);
+
+ /*
+ * Callback function to execute whenever the stack is being reloaded.
+ * This can be used e.g. to discard cached information that relies on
+ * the old stack's data. The payload data will be passed as argument to
+ * the callback.
+ */
+ void (*on_reload)(void *payload);
+ void *on_reload_payload;
};
/* reftable_block_stats holds statistics for a single block type */
diff --git a/reftable/stack.c b/reftable/stack.c
index 8beb5c0541..59fd695a12 100644
--- a/reftable/stack.c
+++ b/reftable/stack.c
@@ -548,6 +548,10 @@ out:
close(fd);
free_names(names);
free_names(names_after);
+
+ if (st->opts.on_reload)
+ st->opts.on_reload(st->opts.on_reload_payload);
+
return err;
}