Skip to content

Commit b8a0de5

Browse files
committed
Merge branch 'ps/zlib-ng' into seen
* ps/zlib-ng: 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 88323b2 + 20d77dd commit b8a0de5

15 files changed

+75
-125
lines changed

Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -986,7 +986,6 @@ LIB_OBJS += commit.o
986986
LIB_OBJS += compat/nonblock.o
987987
LIB_OBJS += compat/obstack.o
988988
LIB_OBJS += compat/terminal.o
989-
LIB_OBJS += compat/zlib-uncompress2.o
990989
LIB_OBJS += config.o
991990
LIB_OBJS += connect.o
992991
LIB_OBJS += connected.o

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"

compat/zlib-compat.h

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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+
# if ZLIB_VERNUM < 0x1221
34+
struct gz_header_s {
35+
int os;
36+
};
37+
38+
static int deflateSetHeader(z_streamp strm, struct gz_header_s *head)
39+
{
40+
(void)(strm);
41+
(void)(head);
42+
return Z_OK;
43+
}
44+
# endif
45+
#endif /* HAVE_ZLIB_NG */
46+
47+
#endif /* COMPAT_ZLIB_H */

compat/zlib-uncompress2.c

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

config.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "convert.h"
2020
#include "environment.h"
2121
#include "gettext.h"
22+
#include "git-zlib.h"
2223
#include "ident.h"
2324
#include "repository.h"
2425
#include "lockfile.h"

csum-file.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
1111
#define USE_THE_REPOSITORY_VARIABLE
1212

1313
#include "git-compat-util.h"
14-
#include "progress.h"
1514
#include "csum-file.h"
15+
#include "git-zlib.h"
1616
#include "hash.h"
17+
#include "progress.h"
1718

1819
static void verify_buffer_or_die(struct hashfile *f,
1920
const void *buf,

environment.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "convert.h"
1717
#include "environment.h"
1818
#include "gettext.h"
19+
#include "git-zlib.h"
1920
#include "repository.h"
2021
#include "config.h"
2122
#include "refs.h"

git-compat-util.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1555,18 +1555,6 @@ int cmd_main(int, const char **);
15551555
int common_exit(const char *file, int line, int code);
15561556
#define exit(code) exit(common_exit(__FILE__, __LINE__, (code)))
15571557

1558-
#define z_const
1559-
#include <zlib.h>
1560-
1561-
#if ZLIB_VERNUM < 0x1290
1562-
/*
1563-
* This is uncompress2, which is only available in zlib >= 1.2.9
1564-
* (released as of early 2017). See compat/zlib-uncompress2.c.
1565-
*/
1566-
int uncompress2(Bytef *dest, uLongf *destLen, const Bytef *source,
1567-
uLong *sourceLen);
1568-
#endif
1569-
15701558
/*
15711559
* This include must come after system headers, since it introduces macros that
15721560
* replace system names.

git-zlib.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ static void zlib_post_call(git_zstream *s)
5959

6060
s->total_out = s->z.total_out;
6161
s->total_in = s->z.total_in;
62-
s->next_in = s->z.next_in;
62+
s->next_in = (unsigned char *) s->z.next_in;
6363
s->next_out = s->z.next_out;
6464
s->avail_in -= bytes_consumed;
6565
s->avail_out -= bytes_produced;
@@ -147,10 +147,6 @@ int git_inflate(git_zstream *strm, int flush)
147147
return status;
148148
}
149149

150-
#if defined(NO_DEFLATE_BOUND) || ZLIB_VERNUM < 0x1200
151-
#define deflateBound(c,s) ((s) + (((s) + 7) >> 3) + (((s) + 63) >> 6) + 11)
152-
#endif
153-
154150
unsigned long git_deflate_bound(git_zstream *strm, unsigned long size)
155151
{
156152
return deflateBound(&strm->z, size);

git-zlib.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#ifndef GIT_ZLIB_H
22
#define GIT_ZLIB_H
33

4+
#include "compat/zlib-compat.h"
5+
46
typedef struct git_zstream {
57
z_stream z;
68
unsigned long avail_in;

meson.build

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,6 @@ libgit_sources = [
256256
'compat/nonblock.c',
257257
'compat/obstack.c',
258258
'compat/terminal.c',
259-
'compat/zlib-uncompress2.c',
260259
'config.c',
261260
'connect.c',
262261
'connected.c',
@@ -795,11 +794,23 @@ else
795794
build_options_config.set('NO_PERL_CPAN_FALLBACKS', '')
796795
endif
797796

798-
zlib = dependency('zlib', default_options: ['default_library=static', 'tests=disabled'])
799-
if zlib.version().version_compare('<1.2.0')
800-
libgit_c_args += '-DNO_DEFLATE_BOUND'
797+
zlib_backend = get_option('zlib_backend')
798+
if zlib_backend in ['auto', 'zlib-ng']
799+
zlib_ng = dependency('zlib-ng', required: zlib_backend == 'zlib-ng')
800+
if zlib_ng.found()
801+
zlib_backend = 'zlib-ng'
802+
libgit_c_args += '-DHAVE_ZLIB_NG'
803+
libgit_dependencies += zlib_ng
804+
endif
805+
endif
806+
if zlib_backend in ['auto', 'zlib']
807+
zlib = dependency('zlib', default_options: ['default_library=static', 'tests=disabled'])
808+
if zlib.version().version_compare('<1.2.0')
809+
libgit_c_args += '-DNO_DEFLATE_BOUND'
810+
endif
811+
zlib_backend = 'zlib'
812+
libgit_dependencies += zlib
801813
endif
802-
libgit_dependencies += zlib
803814

804815
threads = dependency('threads', required: false)
805816
if threads.found()
@@ -2002,4 +2013,5 @@ summary({
20022013
'sha1': sha1_backend,
20032014
'sha1_unsafe': sha1_unsafe_backend,
20042015
'sha256': sha256_backend,
2016+
'zlib': zlib_backend,
20052017
}, section: 'Backends')

meson_options.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ option('sha1_unsafe_backend', type: 'combo', choices: ['openssl', 'block', 'Comm
5757
description: 'The backend used for hashing data with the SHA1 object format in case no cryptographic security is needed.')
5858
option('sha256_backend', type: 'combo', choices: ['openssl', 'nettle', 'gcrypt', 'block'], value: 'block',
5959
description: 'The backend used for hashing objects with the SHA256 object format.')
60+
option('zlib_backend', type: 'combo', choices: ['auto', 'zlib', 'zlib-ng'], value: 'auto',
61+
description: 'The backend used for compressing objects and other data.')
6062

6163
# Build tweaks.
6264
option('breaking_changes', type: 'boolean', value: false,

reftable/block.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ license that can be found in the LICENSE file or at
1313
#include "record.h"
1414
#include "reftable-error.h"
1515
#include "system.h"
16-
#include <zlib.h>
1716

1817
int header_size(int version)
1918
{

reftable/system.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ license that can be found in the LICENSE file or at
1414
#define DISABLE_SIGN_COMPARE_WARNINGS
1515

1616
#include "git-compat-util.h"
17+
#include "compat/zlib-compat.h"
1718

1819
/*
1920
* An implementation-specific temporary file. By making this specific to the

0 commit comments

Comments
 (0)