Hi, this patch series is the final step to fully decouple the reftable library from the rest of the Git codebase. The goal of this is to make the library reusable by other projects like libgit2 by simply copying over the source files, making Git the canonical upstream for reftable functionality. This patch series stops using all kinds of helpers exposed by our "git-compat-util.h" header and open-codes them instead. In order to keep us from using these helpers by accident the final step is to pull out POSIX-related bits and pieces into a new "compat/posix.h" header, which the reftable library then uses instead of "git-compat-util.h". The series is built on top of master at 5f8f7081f7 (The third batch, 2025-01-23) with ps/reftable-sign-compare at 33319b0976 (reftable: address trivial -Wsign-compare warnings, 2025-01-20) merged into it. There is a trivial merge conflict with ps/zlib-ng that can be solved like this: diff --cc reftable/system.h index e4a8944a70,d02eacea8f..0000000000 --- a/reftable/system.h +++ b/reftable/system.h @@@ -11,15 -11,9 +11,15 @@@ https://developers.google.com/open-sour /* This header glues the reftable library to the rest of Git */ -#include "git-compat-util.h" +#include "compat/posix.h" - #include <zlib.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 Changes in v2: - The splitup of Windows headers has broken compilation because some of the headers couldn't be found anymore. I've fixed this more generally by converting includes in "compat/" to always be relative to the project source directory, dropping the platform-specific `-Icompat/` include. - Explain why we don't port over `EWOULDBLOCK` handling. - Fix commit message typos. - Link to v1: https://lore.kernel.org/r/20250127-pks-reftable-drop-git-compat-util-v1-0-6e280a564877@xxxxxx Changes in v3: - Fix type of `total_read` variable used to track how many bytes we have read in `fd_read_lines()`. - Drop the patch use root-relative includes again. Let's rather discuss this outside of the scope of this series. - Link to v2: https://lore.kernel.org/r/20250128-pks-reftable-drop-git-compat-util-v2-0-c85c20336317@xxxxxx Changes in v4: - Fix a couple of now-invalid relative includes that I missed. This fixes the build issue in "seen" with Meson. - Link to v3: https://lore.kernel.org/r/20250203-pks-reftable-drop-git-compat-util-v3-0-446c9ed4ee9e@xxxxxx Thanks! Patrick --- Patrick Steinhardt (18): reftable/stack: stop using `read_in_full()` reftable/stack: stop using `write_in_full()` reftable/blocksource: stop using `xmmap()` reftable/record: stop using `COPY_ARRAY()` reftable/record: stop using `BUG()` in `reftable_record_init()` reftable/record: don't `BUG()` in `reftable_record_cmp()` reftable: stop using `BUG()` in trivial cases reftable/basics: stop using `st_mult()` in array allocators reftable/basics: provide wrappers for big endian conversion reftable/reader: stop using `ARRAY_SIZE()` macro reftable/system: introduce `reftable_rand()` reftable/stack: stop using `sleep_millisec()` reftable/basics: stop using `SWAP()` macro reftable/basics: stop using `UNUSED` annotation compat/mingw: split out POSIX-related bits git-compat-util.h: split out POSIX-emulating bits reftable: decouple from Git codebase by pulling in "compat/posix.h" Makefile: skip reftable library for Coccinelle Makefile | 2 +- compat/{mingw.c => mingw/compat-util.c} | 28 +- compat/mingw/compat-util.h | 220 +++++++++++++ compat/{mingw.h => mingw/posix.h} | 216 +------------ compat/msvc.c | 6 - compat/msvc/compat-util.c | 6 + compat/msvc/compat-util.h | 7 + compat/{msvc.h => msvc/posix.h} | 8 +- compat/posix.h | 541 ++++++++++++++++++++++++++++++++ config.mak.uname | 6 +- contrib/buildsystems/CMakeLists.txt | 2 +- git-compat-util.h | 535 +------------------------------ meson.build | 8 +- reftable/basics.c | 19 -- reftable/basics.h | 123 +++++++- reftable/block.c | 16 +- reftable/blocksource.c | 21 +- reftable/iter.c | 20 +- reftable/merged.c | 27 +- reftable/pq.c | 40 ++- reftable/pq.h | 2 +- reftable/reader.c | 33 +- reftable/record.c | 109 ++++--- reftable/record.h | 6 +- reftable/stack.c | 52 ++- reftable/system.c | 7 + reftable/system.h | 9 +- reftable/writer.c | 29 +- t/unit-tests/t-reftable-basics.c | 28 +- t/unit-tests/t-reftable-pq.c | 22 +- t/unit-tests/t-reftable-record.c | 42 ++- 31 files changed, 1242 insertions(+), 948 deletions(-) Range-diff versus v3: 1: 801e7bb30c = 1: 07f44927f1 reftable/stack: stop using `read_in_full()` 2: 9b1b778a28 = 2: c62404d62e reftable/stack: stop using `write_in_full()` 3: 336b5ca3e1 = 3: f936b06d4b reftable/blocksource: stop using `xmmap()` 4: ec74201d8d = 4: ea203b9060 reftable/record: stop using `COPY_ARRAY()` 5: 853740bd10 = 5: c13aaeca16 reftable/record: stop using `BUG()` in `reftable_record_init()` 6: c6003aa731 = 6: 397b5321bf reftable/record: don't `BUG()` in `reftable_record_cmp()` 7: afbb02bdc7 = 7: 921d4ba9f0 reftable: stop using `BUG()` in trivial cases 8: fe34e5e425 = 8: 0c4396cc16 reftable/basics: stop using `st_mult()` in array allocators 9: 405b6bdac7 = 9: af50906b6d reftable/basics: provide wrappers for big endian conversion 10: f0ca7a5f13 = 10: 1e931c747b reftable/reader: stop using `ARRAY_SIZE()` macro 11: 2e8152c509 = 11: f66900df08 reftable/system: introduce `reftable_rand()` 12: bdb708349d = 12: 99af9a50da reftable/stack: stop using `sleep_millisec()` 13: 6e59462638 = 13: bdcd8744df reftable/basics: stop using `SWAP()` macro 14: 7c4e2eeb9b = 14: 41f637bd3f reftable/basics: stop using `UNUSED` annotation 15: 942eeca014 ! 15: 4dbbc71e11 compat/mingw: split out POSIX-related bits @@ Commit message Signed-off-by: Patrick Steinhardt <ps@xxxxxx> ## compat/mingw.c => compat/mingw/compat-util.c ## +@@ + #define USE_THE_REPOSITORY_VARIABLE + #define DISABLE_SIGN_COMPARE_WARNINGS + +-#include "../git-compat-util.h" +-#include "win32.h" ++#include "../../git-compat-util.h" ++#include "../win32.h" + #include <aclapi.h> + #include <sddl.h> + #include <conio.h> + #include <wchar.h> +-#include "../strbuf.h" +-#include "../run-command.h" +-#include "../abspath.h" +-#include "../alloc.h" +-#include "win32/lazyload.h" +-#include "../config.h" +-#include "../environment.h" +-#include "../trace2.h" +-#include "../symlinks.h" +-#include "../wrapper.h" +-#include "dir.h" +-#include "gettext.h" ++#include "../../strbuf.h" ++#include "../../run-command.h" ++#include "../../abspath.h" ++#include "../../alloc.h" ++#include "../win32/lazyload.h" ++#include "../../config.h" ++#include "../../environment.h" ++#include "../../trace2.h" ++#include "../../symlinks.h" ++#include "../../wrapper.h" ++#include "../../dir.h" ++#include "../../gettext.h" + #define SECURITY_WIN32 + #include <sspi.h> + ## compat/mingw/compat-util.h (new) ## @@ @@ compat/mingw/posix.h: char *mingw_query_user_email(void); -#endif +#endif /* COMPAT_MINGW_POSIX_H */ - ## compat/msvc.c => compat/msvc/compat-util.c ## + ## compat/msvc.c (deleted) ## @@ - #include <conio.h> - #include "../strbuf.h" - +-#include "../git-compat-util.h" +-#include "win32.h" +-#include <conio.h> +-#include "../strbuf.h" +- -#include "mingw.c" -+#include "mingw/compat-util.c" + + ## compat/msvc/compat-util.c (new) ## +@@ ++#include "../../git-compat-util.h" ++#include "../win32.h" ++#include <conio.h> ++#include "../../strbuf.h" ++ ++#include "../mingw/compat-util.c" ## compat/msvc/compat-util.h (new) ## @@ 16: 53151b2649 ! 16: f0e9c6d3ee git-compat-util.h: split out POSIX-emulating bits @@ compat/posix.h (new) +#define HOST_NAME_MAX 256 +#endif + -+#include "sane-ctype.h" ++#include "../sane-ctype.h" + +void git_stable_qsort(void *base, size_t nmemb, size_t size, + int(*compar)(const void *, const void *)); 17: b63a798513 = 17: 35a975dfe2 reftable: decouple from Git codebase by pulling in "compat/posix.h" 18: f9edb54708 = 18: 1dde84b32c Makefile: skip reftable library for Coccinelle --- base-commit: 8047765d092881ec4aef7dfc57772161eee7f0f5 change-id: 20241119-pks-reftable-drop-git-compat-util-470f2bfde562