git-compat-util: move include of "compat/zlib.h" into "git-zlib.h"

We include "compat/zlib.h" in "git-compat-util.h", which is unnecessarily broad given that we only have a small handful of files that use the zlib library. Move the header into "git-zlib.h" instead and adapt users of zlib to include that header. One exception is the reftable library, as we don't want to use the Git-specific wrapper of zlib there, so we include "compat/zlib.h" instead. Furthermore, we move the include into "reftable/system.h" so that users of the library other than Git can wire up zlib themselves. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Jan 28, 2025 at 09:41 UTC 41f1a8435a900b660b7a6bc9da8dce2665e4b70a
8 files changed +8 -4
archive.c
+1
@@ -7,6 +7,7 @@
7 #include "convert.h"
8 #include "environment.h"
9 #include "gettext.h"
10 +#include "git-zlib.h"
11 #include "hex.h"
12 #include "object-name.h"
13 #include "path.h"
config.c
+1
@@ -19,6 +19,7 @@
19 #include "convert.h"
20 #include "environment.h"
21 #include "gettext.h"
22 +#include "git-zlib.h"
23 #include "ident.h"
24 #include "repository.h"
25 #include "lockfile.h"
csum-file.c
+2 -1
@@ -11,9 +11,10 @@
11 #define USE_THE_REPOSITORY_VARIABLE
12
13 #include "git-compat-util.h"
14 -#include "progress.h"
14 #include "csum-file.h"
15 +#include "git-zlib.h"
16 #include "hash.h"
17 +#include "progress.h"
18
19 static void verify_buffer_or_die(struct hashfile *f,
20 const void *buf,
environment.c
+1
@@ -16,6 +16,7 @@
16 #include "convert.h"
17 #include "environment.h"
18 #include "gettext.h"
19 +#include "git-zlib.h"
20 #include "repository.h"
21 #include "config.h"
22 #include "refs.h"
git-compat-util.h
-2
@@ -1537,8 +1537,6 @@ int cmd_main(int, const char **);
1537 int common_exit(const char *file, int line, int code);
1538 #define exit(code) exit(common_exit(__FILE__, __LINE__, (code)))
1539
1540 -#include "compat/zlib-compat.h"
1541 -
1540 /*
1541 * This include must come after system headers, since it introduces macros that
1542 * replace system names.
git-zlib.h
+2
@@ -1,6 +1,8 @@
1 #ifndef GIT_ZLIB_H
2 #define GIT_ZLIB_H
3
4 +#include "compat/zlib-compat.h"
5 +
6 typedef struct git_zstream {
7 z_stream z;
8 unsigned long avail_in;
reftable/block.c
-1
@@ -13,7 +13,6 @@ https://developers.google.com/open-source/licenses/bsd
13 #include "record.h"
14 #include "reftable-error.h"
15 #include "system.h"
16 -#include "compat/zlib-compat.h"
16
17 int header_size(int version)
18 {
reftable/system.h
+1
@@ -14,6 +14,7 @@ https://developers.google.com/open-source/licenses/bsd
14 #define DISABLE_SIGN_COMPARE_WARNINGS
15
16 #include "git-compat-util.h"
17 +#include "compat/zlib-compat.h"
18
19 /*
20 * An implementation-specific temporary file. By making this specific to the