| 251 | } |
| 252 | |
| 253 | int git_deflate(git_zstream *strm, int flush) |
| 254 | { |
| 255 | int status; |
| 256 | |
| 257 | for (;;) { |
| 258 | zlib_pre_call(strm); |
| 259 | |
| 260 | /* Never say Z_FINISH unless we are feeding everything */ |
| 261 | status = deflate(&strm->z, |
| 262 | (strm->z.avail_in != strm->avail_in) |
| 263 | ? 0 : flush); |
| 264 | if (status == Z_MEM_ERROR) |
| 265 | die("deflate: out of memory"); |
| 266 | zlib_post_call(strm, status); |
| 267 | |
| 268 | /* |
| 269 | * Let zlib work another round, while we can still |
| 270 | * make progress. |
| 271 | */ |
| 272 | if ((strm->avail_out && !strm->z.avail_out) && |
| 273 | (status == Z_OK || status == Z_BUF_ERROR)) |
| 274 | continue; |
| 275 | break; |
| 276 | } |
| 277 | |
| 278 | switch (status) { |
| 279 | /* Z_BUF_ERROR: normal, needs more space in the output buffer */ |
| 280 | case Z_BUF_ERROR: |
| 281 | case Z_OK: |
| 282 | case Z_STREAM_END: |
| 283 | return status; |
| 284 | default: |
| 285 | break; |
| 286 | } |
| 287 | error("deflate: %s (%s)", zerr_to_string(status), |
| 288 | strm->z.msg ? strm->z.msg : "no message"); |
| 289 | return status; |
| 290 | } |