Skip to content

Commit 9d0e81e

Browse files
committed
Merge branch 'ps/zlib-ng'
The code paths to interact with zlib has been cleaned up in preparation for building with zlib-ng. * ps/zlib-ng: ci: make "linux-musl" job use zlib-ng ci: switch linux-musl to use Meson compat/zlib: allow use of zlib-ng as backend git-zlib: cast away potential constness of `next_in` pointer compat/zlib: provide stubs for `deflateSetHeader()` compat/zlib: provide `deflateBound()` shim centrally git-compat-util: move include of "compat/zlib.h" into "git-zlib.h" compat: introduce new "zlib.h" header git-compat-util: drop `z_const` define compat: drop `uncompress2()` compatibility shim
2 parents 9fad473 + 78cdeed commit 9d0e81e

20 files changed

+107
-140
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ jobs:
390390
- jobname: linux-meson
391391
image: ubuntu:rolling
392392
cc: gcc
393-
- jobname: linux-musl
393+
- jobname: linux-musl-meson
394394
image: alpine:latest
395395
# Supported until 2025-04-02.
396396
- jobname: linux32

.gitlab-ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ test:linux:
6060
CC: clang
6161
- jobname: pedantic
6262
image: fedora:latest
63-
- jobname: linux-musl
63+
- jobname: linux-musl-meson
6464
image: alpine:latest
6565
- jobname: linux32
6666
image: i386/ubuntu:20.04

Makefile

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,8 @@ include shared.mak
183183
# byte-order mark (BOM) when writing UTF-16 or UTF-32 and always writes in
184184
# big-endian format.
185185
#
186-
# Define NO_DEFLATE_BOUND if your zlib does not have deflateBound.
186+
# Define NO_DEFLATE_BOUND if your zlib does not have deflateBound. Define
187+
# ZLIB_NG if you want to use zlib-ng instead of zlib.
187188
#
188189
# Define NO_NORETURN if using buggy versions of gcc 4.6+ and profile feedback,
189190
# as the compiler can crash (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=49299)
@@ -985,7 +986,6 @@ LIB_OBJS += commit.o
985986
LIB_OBJS += compat/nonblock.o
986987
LIB_OBJS += compat/obstack.o
987988
LIB_OBJS += compat/terminal.o
988-
LIB_OBJS += compat/zlib-uncompress2.o
989989
LIB_OBJS += config.o
990990
LIB_OBJS += connect.o
991991
LIB_OBJS += connected.o
@@ -1692,11 +1692,20 @@ else
16921692
endif
16931693
IMAP_SEND_LDFLAGS += $(OPENSSL_LINK) $(OPENSSL_LIBSSL) $(LIB_4_CRYPTO)
16941694

1695-
ifdef ZLIB_PATH
1696-
BASIC_CFLAGS += -I$(ZLIB_PATH)/include
1697-
EXTLIBS += $(call libpath_template,$(ZLIB_PATH)/$(lib))
1695+
ifdef ZLIB_NG
1696+
BASIC_CFLAGS += -DHAVE_ZLIB_NG
1697+
ifdef ZLIB_NG_PATH
1698+
BASIC_CFLAGS += -I$(ZLIB_NG_PATH)/include
1699+
EXTLIBS += $(call libpath_template,$(ZLIB_NG_PATH)/$(lib))
1700+
endif
1701+
EXTLIBS += -lz-ng
1702+
else
1703+
ifdef ZLIB_PATH
1704+
BASIC_CFLAGS += -I$(ZLIB_PATH)/include
1705+
EXTLIBS += $(call libpath_template,$(ZLIB_PATH)/$(lib))
1706+
endif
1707+
EXTLIBS += -lz
16981708
endif
1699-
EXTLIBS += -lz
17001709

17011710
ifndef NO_OPENSSL
17021711
OPENSSL_LIBSSL = -lssl

archive-tar.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -473,9 +473,7 @@ static const char internal_gzip_command[] = "git archive gzip";
473473
static int write_tar_filter_archive(const struct archiver *ar,
474474
struct archiver_args *args)
475475
{
476-
#if ZLIB_VERNUM >= 0x1221
477476
struct gz_header_s gzhead = { .os = 3 }; /* Unix, for reproducibility */
478-
#endif
479477
struct strbuf cmd = STRBUF_INIT;
480478
struct child_process filter = CHILD_PROCESS_INIT;
481479
int r;
@@ -486,10 +484,8 @@ static int write_tar_filter_archive(const struct archiver *ar,
486484
if (!strcmp(ar->filter_command, internal_gzip_command)) {
487485
write_block = tgz_write_block;
488486
git_deflate_init_gzip(&gzstream, args->compression_level);
489-
#if ZLIB_VERNUM >= 0x1221
490487
if (deflateSetHeader(&gzstream.z, &gzhead) != Z_OK)
491488
BUG("deflateSetHeader() called too late");
492-
#endif
493489
gzstream.next_out = outbuf;
494490
gzstream.avail_out = sizeof(outbuf);
495491

archive.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "convert.h"
88
#include "environment.h"
99
#include "gettext.h"
10+
#include "git-zlib.h"
1011
#include "hex.h"
1112
#include "object-name.h"
1213
#include "path.h"

ci/install-dependencies.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ fi
2424

2525
case "$distro" in
2626
alpine-*)
27-
apk add --update shadow sudo build-base curl-dev openssl-dev expat-dev gettext \
28-
pcre2-dev python3 musl-libintl perl-utils ncurses \
27+
apk add --update shadow sudo meson ninja-build gcc libc-dev curl-dev openssl-dev expat-dev gettext \
28+
zlib-ng-dev pcre2-dev python3 musl-libintl perl-utils ncurses \
2929
apache2 apache2-http2 apache2-proxy apache2-ssl apache2-webdav apr-util-dbd_sqlite3 \
3030
bash cvs gnupg perl-cgi perl-dbd-sqlite perl-io-tty >/dev/null
3131
;;

ci/lib.sh

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -349,10 +349,7 @@ linux32)
349349
CC=gcc
350350
;;
351351
linux-musl)
352-
CC=gcc
353-
MAKEFLAGS="$MAKEFLAGS PYTHON_PATH=/usr/bin/python3 USE_LIBPCRE2=Yes"
354-
MAKEFLAGS="$MAKEFLAGS NO_REGEX=Yes ICONV_OMITS_BOM=Yes"
355-
MAKEFLAGS="$MAKEFLAGS GIT_TEST_UTF8_LOCALE=C.UTF-8"
352+
MESONFLAGS="$MESONFLAGS -DGIT_TEST_UTF8_LOCALE=C.UTF-8"
356353
;;
357354
linux-leaks|linux-reftable-leaks)
358355
export SANITIZE=leak

ci/run-build-and-tests.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ case "$jobname" in
5656
--fatal-meson-warnings \
5757
--warnlevel 2 --werror \
5858
--wrap-mode nofallback \
59-
-Dfuzzers=true
59+
-Dfuzzers=true \
60+
$MESONFLAGS
6061
group "Build" meson compile -C build --
6162
if test -n "$run_tests"
6263
then

compat/zlib-compat.h

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#ifndef COMPAT_ZLIB_H
2+
#define COMPAT_ZLIB_H
3+
4+
#ifdef HAVE_ZLIB_NG
5+
# include <zlib-ng.h>
6+
7+
# define z_stream zng_stream
8+
#define gz_header_s zng_gz_header_s
9+
10+
# define crc32(crc, buf, len) zng_crc32(crc, buf, len)
11+
12+
# define inflate(strm, bits) zng_inflate(strm, bits)
13+
# define inflateEnd(strm) zng_inflateEnd(strm)
14+
# define inflateInit(strm) zng_inflateInit(strm)
15+
# define inflateInit2(strm, bits) zng_inflateInit2(strm, bits)
16+
# define inflateReset(strm) zng_inflateReset(strm)
17+
18+
# define deflate(strm, flush) zng_deflate(strm, flush)
19+
# define deflateBound(strm, source_len) zng_deflateBound(strm, source_len)
20+
# define deflateEnd(strm) zng_deflateEnd(strm)
21+
# define deflateInit(strm, level) zng_deflateInit(strm, level)
22+
# define deflateInit2(stream, level, method, window_bits, mem_level, strategy) zng_deflateInit2(stream, level, method, window_bits, mem_level, strategy)
23+
# define deflateReset(strm) zng_deflateReset(strm)
24+
# define deflateSetHeader(strm, head) zng_deflateSetHeader(strm, head)
25+
26+
#else
27+
# include <zlib.h>
28+
29+
# if defined(NO_DEFLATE_BOUND) || ZLIB_VERNUM < 0x1200
30+
# define deflateBound(c,s) ((s) + (((s) + 7) >> 3) + (((s) + 63) >> 6) + 11)
31+
# endif
32+
33+
/*
34+
* zlib only gained support for setting up the gzip header in v1.2.2.1. In
35+
* Git we only set the header to make archives reproducible across different
36+
* operating systems, so it's fine to simply make this a no-op when using a
37+
* zlib version that doesn't support this yet.
38+
*/
39+
# if ZLIB_VERNUM < 0x1221
40+
struct gz_header_s {
41+
int os;
42+
};
43+
44+
static int deflateSetHeader(z_streamp strm, struct gz_header_s *head)
45+
{
46+
(void)(strm);
47+
(void)(head);
48+
return Z_OK;
49+
}
50+
# endif
51+
#endif /* HAVE_ZLIB_NG */
52+
53+
#endif /* COMPAT_ZLIB_H */

compat/zlib-uncompress2.c

Lines changed: 0 additions & 96 deletions
This file was deleted.

0 commit comments

Comments
 (0)