From 712f6cfe5411fdbbf46688c22a40fac7e0a8839b Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Tue, 18 Feb 2025 10:20:47 +0100 Subject: reftable/system: introduce `reftable_rand()` Introduce a new system-level `reftable_rand()` function that generates a single unsigned integer for us. The implementation of this function is to be provided by the calling codebase, which allows us to more easily hook into pre-seeded random number generators. Adapt the two callsites where we generated random data. Signed-off-by: Patrick Steinhardt Signed-off-by: Junio C Hamano --- reftable/system.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'reftable/system.h') diff --git a/reftable/system.h b/reftable/system.h index d02eacea8f..bb6a7e6285 100644 --- a/reftable/system.h +++ b/reftable/system.h @@ -14,6 +14,12 @@ https://developers.google.com/open-source/licenses/bsd #include "git-compat-util.h" #include "compat/zlib-compat.h" +/* + * Return a random 32 bit integer. This function is expected to return + * pre-seeded data. + */ +uint32_t reftable_rand(void); + /* * An implementation-specific temporary file. By making this specific to the * implementation it becomes possible to tie temporary files into any kind of -- cgit v1.3 From 6af23ac66cc5050aa4aa2adb5037196536c824e3 Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Tue, 18 Feb 2025 10:20:53 +0100 Subject: reftable: decouple from Git codebase by pulling in "compat/posix.h" The reftable library includes "git-compat-util.h" in order to get a POSIX-like programming environment that papers over various differences between platforms. The header also brings with it a couple of helpers specific to the Git codebase though, and over time we have started to use these helpers in the reftable library, as well. This makes it very hard to use the reftable library as a standalone library without the rest of the Git codebase, so other libraries like e.g. libgit2 cannot easily use it. But now that we have removed all calls to Git-specific functionality and have split out "compat/posix.h" as a separate header we can address this. Stop including "git-compat-util.h" and instead include "compat/posix.h" to finalize the decoupling of the reftable library from the rest of the Git codebase. The only bits which remain specific to Git are "system.h" and "system.c", which projects will have to provide. Signed-off-by: Patrick Steinhardt Signed-off-by: Junio C Hamano --- reftable/system.c | 2 ++ reftable/system.h | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'reftable/system.h') diff --git a/reftable/system.c b/reftable/system.c index e25ccc0da3..1ee268b125 100644 --- a/reftable/system.c +++ b/reftable/system.c @@ -1,3 +1,5 @@ +#include "../git-compat-util.h" + #include "system.h" #include "basics.h" #include "reftable-error.h" diff --git a/reftable/system.h b/reftable/system.h index bb6a7e6285..10055fbff2 100644 --- a/reftable/system.h +++ b/reftable/system.h @@ -11,7 +11,7 @@ https://developers.google.com/open-source/licenses/bsd /* This header glues the reftable library to the rest of Git */ -#include "git-compat-util.h" +#include "compat/posix.h" #include "compat/zlib-compat.h" /* -- cgit v1.3