Git fork

git-zlib: use `struct z_stream_s` instead of typedef

Throughout the Git codebase we're using the typedeffed version of
`z_stream`, which maps to `struct z_stream_s`. By using a typedef
instead of the struct it becomes somewhat harder to predeclare the
symbol so that headers depending on the struct can do so without having
to pull in "zlib-compat.h".

We don't yet have users that would really care about this: the only
users that declare `z_stream` as a pointer are in "reftable/block.h",
which is a header that is internal to the reftable library. But in the
next step we're going to expose the `struct reftable_block` publicly,
and that struct does contain a pointer to `z_stream`. And as the public
header shouldn't depend on "reftable/system.h", which is an internal
implementation detail, we won't have the typedef for `z_stream` readily
available.

Prepare for this change by using `struct z_stream_s` throughout our code
base. In case zlib-ng is used we use a define to map from `z_stream_s`
to `zng_stream_s`.

Drop the pre-declaration of `struct z_stream` while at it. This struct
does not exist in the first place, and the declaration wasn't needed
because "reftable/block.h" already includes "reftable/basics.h" which
transitively includes "reftable/system.h" and thus "git-zlib.h".

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

authored by

Patrick Steinhardt and committed by
Junio C Hamano
ce76cec9 12a9aa8c

+7 -9
+2 -2
Documentation/howto/recover-corrupted-object-harder.adoc
··· 125 125 { 126 126 /* make this absurdly large so we don't have to loop */ 127 127 static unsigned char out[1024*1024]; 128 - z_stream z; 128 + struct z_stream_s z; 129 129 int ret; 130 130 131 131 memset(&z, 0, sizeof(z)); ··· 278 278 static unsigned char buf[25 * 1024 * 1024]; 279 279 static unsigned char out[25 * 1024 * 1024]; 280 280 int len; 281 - z_stream z; 281 + struct z_stream_s z; 282 282 int ret; 283 283 284 284 len = read(0, buf, sizeof(buf));
+2 -2
compat/zlib-compat.h
··· 4 4 #ifdef HAVE_ZLIB_NG 5 5 # include <zlib-ng.h> 6 6 7 - # define z_stream zng_stream 8 - #define gz_header_s zng_gz_header_s 7 + # define z_stream_s zng_stream_s 8 + # define gz_header_s zng_gz_header_s 9 9 10 10 # define crc32(crc, buf, len) zng_crc32(crc, buf, len) 11 11
+1 -1
git-zlib.h
··· 4 4 #include "compat/zlib-compat.h" 5 5 6 6 typedef struct git_zstream { 7 - z_stream z; 7 + struct z_stream_s z; 8 8 unsigned long avail_in; 9 9 unsigned long avail_out; 10 10 unsigned long total_in;
+2 -4
reftable/block.h
··· 18 18 * allocation overhead. 19 19 */ 20 20 struct block_writer { 21 - z_stream *zstream; 21 + struct z_stream_s *zstream; 22 22 unsigned char *compressed; 23 23 size_t compressed_cap; 24 24 ··· 62 62 /* clears out internally allocated block_writer members. */ 63 63 void block_writer_release(struct block_writer *bw); 64 64 65 - struct z_stream; 66 - 67 65 /* 68 66 * A block part of a reftable. Contains records as well as some metadata 69 67 * describing them. ··· 78 76 uint32_t hash_size; 79 77 80 78 /* Uncompressed data for log entries. */ 81 - z_stream *zstream; 79 + struct z_stream_s *zstream; 82 80 unsigned char *uncompressed_data; 83 81 size_t uncompressed_cap; 84 82