reftable: introduce "reftable-system.h" header

We're including a couple of standard headers like <stdint.h> in a bunch of locations, which makes it hard for a project to plug in their own logic for making required functionality available. For us this is for example via "compat/posix.h", which already includes all of the system headers relevant to us. Introduce a new "reftable-system.h" header that allows projects to provide their own headers. This new header is supposed to contain all the project-specific bits to provide the POSIX-like environment, and some additional supporting code. With this change, we thus have the following split in our system-specific code: - "reftable/reftable-system.h" is the project-specific header that provides a POSIX-like environment. Every project is expected to provide their own implementation. - "reftable/system.h" contains the project-independent definition of the interfaces that a project needs to implement. This file should not be touched by a project. - "reftable/system.c" contains the project-specific implementation of the interfaces defined in "system.h". Again, every project is expected to provide their own implementation. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Apr 2, 2026 at 09:31 UTC 34c17b840d5bdb8060ef6309aee04f919616c9de
13 files changed +34 -12
reftable/reftable-basics.h
+1 -1
@@ -9,7 +9,7 @@
9 #ifndef REFTABLE_BASICS_H
10 #define REFTABLE_BASICS_H
11
12 -#include <stddef.h>
12 +#include "reftable-system.h"
13
14 /* A buffer that contains arbitrary byte slices. */
15 struct reftable_buf {
reftable/reftable-block.h
+1 -2
@@ -9,8 +9,7 @@
9 #ifndef REFTABLE_BLOCK_H
10 #define REFTABLE_BLOCK_H
11
12 -#include <stdint.h>
13 -
12 +#include "reftable-system.h"
13 #include "reftable-basics.h"
14 #include "reftable-blocksource.h"
15 #include "reftable-iterator.h"
reftable/reftable-blocksource.h
+1 -1
@@ -9,7 +9,7 @@
9 #ifndef REFTABLE_BLOCKSOURCE_H
10 #define REFTABLE_BLOCKSOURCE_H
11
12 -#include <stdint.h>
12 +#include "reftable-system.h"
13
14 /*
15 * Generic wrapper for a seekable readable file.
reftable/reftable-error.h
+2
@@ -9,6 +9,8 @@
9 #ifndef REFTABLE_ERROR_H
10 #define REFTABLE_ERROR_H
11
12 +#include "reftable-system.h"
13 +
14 /*
15 * Errors in reftable calls are signaled with negative integer return values. 0
16 * means success.
reftable/reftable-fsck.h
+1
@@ -1,6 +1,7 @@
1 #ifndef REFTABLE_FSCK_H
2 #define REFTABLE_FSCK_H
3
4 +#include "reftable-system.h"
5 #include "reftable-stack.h"
6
7 enum reftable_fsck_error {
reftable/reftable-iterator.h
+1
@@ -9,6 +9,7 @@
9 #ifndef REFTABLE_ITERATOR_H
10 #define REFTABLE_ITERATOR_H
11
12 +#include "reftable-system.h"
13 #include "reftable-record.h"
14
15 struct reftable_iterator_vtable;
reftable/reftable-merged.h
+1
@@ -9,6 +9,7 @@
9 #ifndef REFTABLE_MERGED_H
10 #define REFTABLE_MERGED_H
11
12 +#include "reftable-system.h"
13 #include "reftable-iterator.h"
14
15 /*
reftable/reftable-record.h
+1 -1
@@ -9,8 +9,8 @@
9 #ifndef REFTABLE_RECORD_H
10 #define REFTABLE_RECORD_H
11
12 +#include "reftable-system.h"
13 #include "reftable-basics.h"
13 -#include <stdint.h>
14
15 /*
16 * Basic data types
reftable/reftable-stack.h
+1
@@ -9,6 +9,7 @@
9 #ifndef REFTABLE_STACK_H
10 #define REFTABLE_STACK_H
11
12 +#include "reftable-system.h"
13 #include "reftable-writer.h"
14
15 /*
reftable/reftable-system.h new
+15
@@ -0,0 +1,15 @@
1 +#ifndef REFTABLE_SYSTEM_H
2 +#define REFTABLE_SYSTEM_H
3 +
4 +/*
5 + * This header defines the platform-specific bits required to compile the
6 + * reftable library. It should provide an environment that bridges over the
7 + * gaps between POSIX and your system, as well as the zlib interfaces. This
8 + * header is expected to be changed by the individual project.
9 + */
10 +
11 +#define MINGW_DONT_HANDLE_IN_USE_ERROR
12 +#include "compat/posix.h"
13 +#include "compat/zlib-compat.h"
14 +
15 +#endif
reftable/reftable-table.h
+1
@@ -9,6 +9,7 @@
9 #ifndef REFTABLE_TABLE_H
10 #define REFTABLE_TABLE_H
11
12 +#include "reftable-system.h"
13 #include "reftable-iterator.h"
14 #include "reftable-block.h"
15 #include "reftable-blocksource.h"
reftable/reftable-writer.h
+1 -3
@@ -9,11 +9,9 @@
9 #ifndef REFTABLE_WRITER_H
10 #define REFTABLE_WRITER_H
11
12 +#include "reftable-system.h"
13 #include "reftable-record.h"
14
14 -#include <stdint.h>
15 -#include <unistd.h> /* ssize_t */
16 -
15 /* Writing single reftables */
16
17 /* reftable_write_options sets options for writing a single reftable. */
reftable/system.h
+7 -4
@@ -9,11 +9,14 @@
9 #ifndef SYSTEM_H
10 #define SYSTEM_H
11
12 -/* This header glues the reftable library to the rest of Git */
12 +/*
13 + * This header defines the platform-agnostic interface that is to be
14 + * implemented by the project to make it work on their respective supported
15 + * systems, and to integrate it into the project itself. This header is not
16 + * expected to be changed by the individual project.
17 + */
18
14 -#define MINGW_DONT_HANDLE_IN_USE_ERROR
15 -#include "compat/posix.h"
16 -#include "compat/zlib-compat.h"
19 +#include "reftable-system.h"
20
21 /*
22 * Return a random 32 bit integer. This function is expected to return