Git fork

Provide zlib's uncompress2 from compat/zlib-compat.c

This will be needed for reading reflog blocks in reftable.

Helped-by: Carlo Marcelo Arenas Belón <carenas@gmail.com>
Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

authored by

Han-Wen Nienhuys and committed by
Junio C Hamano
a322920d e303bf22

+122
+7
Makefile
··· 256 256 # 257 257 # Define NO_DEFLATE_BOUND if your zlib does not have deflateBound. 258 258 # 259 + # Define NO_UNCOMPRESS2 if your zlib does not have uncompress2. 260 + # 259 261 # Define NO_NORETURN if using buggy versions of gcc 4.6+ and profile feedback, 260 262 # as the compiler can crash (http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49299) 261 263 # ··· 1736 1738 1737 1739 ifdef NO_DEFLATE_BOUND 1738 1740 BASIC_CFLAGS += -DNO_DEFLATE_BOUND 1741 + endif 1742 + 1743 + ifdef NO_UNCOMPRESS2 1744 + BASIC_CFLAGS += -DNO_UNCOMPRESS2 1745 + REFTABLE_OBJS += compat/zlib-uncompress2.o 1739 1746 endif 1740 1747 1741 1748 ifdef NO_POSIX_GOODIES
+1
ci/lib.sh
··· 224 224 ;; 225 225 Linux32) 226 226 CC=gcc 227 + MAKEFLAGS="$MAKEFLAGS NO_UNCOMPRESS2=1" 227 228 ;; 228 229 linux-musl) 229 230 CC=gcc
+1
compat/.gitattributes
··· 1 + /zlib-uncompress2.c whitespace=-indent-with-non-tab,-trailing-space
+95
compat/zlib-uncompress2.c
··· 1 + /* taken from zlib's uncompr.c 2 + 3 + commit cacf7f1d4e3d44d871b605da3b647f07d718623f 4 + Author: Mark Adler <madler@alumni.caltech.edu> 5 + Date: Sun Jan 15 09:18:46 2017 -0800 6 + 7 + zlib 1.2.11 8 + 9 + */ 10 + 11 + #include "../reftable/system.h" 12 + #define z_const 13 + 14 + /* 15 + * Copyright (C) 1995-2003, 2010, 2014, 2016 Jean-loup Gailly, Mark Adler 16 + * For conditions of distribution and use, see copyright notice in zlib.h 17 + */ 18 + 19 + #include <zlib.h> 20 + 21 + /* clang-format off */ 22 + 23 + /* =========================================================================== 24 + Decompresses the source buffer into the destination buffer. *sourceLen is 25 + the byte length of the source buffer. Upon entry, *destLen is the total size 26 + of the destination buffer, which must be large enough to hold the entire 27 + uncompressed data. (The size of the uncompressed data must have been saved 28 + previously by the compressor and transmitted to the decompressor by some 29 + mechanism outside the scope of this compression library.) Upon exit, 30 + *destLen is the size of the decompressed data and *sourceLen is the number 31 + of source bytes consumed. Upon return, source + *sourceLen points to the 32 + first unused input byte. 33 + 34 + uncompress returns Z_OK if success, Z_MEM_ERROR if there was not enough 35 + memory, Z_BUF_ERROR if there was not enough room in the output buffer, or 36 + Z_DATA_ERROR if the input data was corrupted, including if the input data is 37 + an incomplete zlib stream. 38 + */ 39 + int ZEXPORT uncompress2 ( 40 + Bytef *dest, 41 + uLongf *destLen, 42 + const Bytef *source, 43 + uLong *sourceLen) { 44 + z_stream stream; 45 + int err; 46 + const uInt max = (uInt)-1; 47 + uLong len, left; 48 + Byte buf[1]; /* for detection of incomplete stream when *destLen == 0 */ 49 + 50 + len = *sourceLen; 51 + if (*destLen) { 52 + left = *destLen; 53 + *destLen = 0; 54 + } 55 + else { 56 + left = 1; 57 + dest = buf; 58 + } 59 + 60 + stream.next_in = (z_const Bytef *)source; 61 + stream.avail_in = 0; 62 + stream.zalloc = (alloc_func)0; 63 + stream.zfree = (free_func)0; 64 + stream.opaque = (voidpf)0; 65 + 66 + err = inflateInit(&stream); 67 + if (err != Z_OK) return err; 68 + 69 + stream.next_out = dest; 70 + stream.avail_out = 0; 71 + 72 + do { 73 + if (stream.avail_out == 0) { 74 + stream.avail_out = left > (uLong)max ? max : (uInt)left; 75 + left -= stream.avail_out; 76 + } 77 + if (stream.avail_in == 0) { 78 + stream.avail_in = len > (uLong)max ? max : (uInt)len; 79 + len -= stream.avail_in; 80 + } 81 + err = inflate(&stream, Z_NO_FLUSH); 82 + } while (err == Z_OK); 83 + 84 + *sourceLen -= len + stream.avail_in; 85 + if (dest != buf) 86 + *destLen = stream.total_out; 87 + else if (stream.total_out && err == Z_BUF_ERROR) 88 + left = 1; 89 + 90 + inflateEnd(&stream); 91 + return err == Z_STREAM_END ? Z_OK : 92 + err == Z_NEED_DICT ? Z_DATA_ERROR : 93 + err == Z_BUF_ERROR && left + stream.avail_out ? Z_DATA_ERROR : 94 + err; 95 + }
+5
config.mak.uname
··· 258 258 FILENO_IS_A_MACRO = UnfortunatelyYes 259 259 endif 260 260 ifeq ($(uname_S),OpenBSD) 261 + # Versions < 7.0 need compatibility layer 262 + ifeq ($(shell expr "$(uname_R)" : "[1-6]\."),2) 263 + NO_UNCOMPRESS2 = UnfortunatelyYes 264 + endif 261 265 NO_STRCASESTR = YesPlease 262 266 NO_MEMMEM = YesPlease 263 267 USE_ST_TIMESPEC = YesPlease ··· 513 517 endif 514 518 endif 515 519 ifeq ($(uname_S),Minix) 520 + NO_UNCOMPRESS2 = YesPlease 516 521 NO_IPV6 = YesPlease 517 522 NO_ST_BLOCKS_IN_STRUCT_STAT = YesPlease 518 523 NO_NSEC = YesPlease
+13
configure.ac
··· 672 672 NO_DEFLATE_BOUND=yes]) 673 673 LIBS="$old_LIBS" 674 674 675 + AC_DEFUN([ZLIBTEST_UNCOMPRESS2_SRC], [ 676 + AC_LANG_PROGRAM([#include <zlib.h>], 677 + [uncompress2(NULL,NULL,NULL,NULL);])]) 678 + AC_MSG_CHECKING([for uncompress2 in -lz]) 679 + old_LIBS="$LIBS" 680 + LIBS="$LIBS -lz" 681 + AC_LINK_IFELSE([ZLIBTEST_UNCOMPRESS2_SRC], 682 + [AC_MSG_RESULT([yes])], 683 + [AC_MSG_RESULT([no]) 684 + NO_UNCOMPRESS2=yes]) 685 + LIBS="$old_LIBS" 686 + 675 687 GIT_UNSTASH_FLAGS($ZLIB_PATH) 676 688 677 689 GIT_CONF_SUBST([NO_DEFLATE_BOUND]) 690 + GIT_CONF_SUBST([NO_UNCOMPRESS2]) 678 691 679 692 # 680 693 # Define NEEDS_SOCKET if linking with libc is not enough (SunOS,