|
4 | 4 | */
|
5 | 5 | #include "cache.h"
|
6 | 6 |
|
7 |
| -void git_inflate_init(z_streamp strm) |
| 7 | +static const char *zerr_to_string(int status) |
8 | 8 | {
|
9 |
| - const char *err; |
10 |
| - |
11 |
| - switch (inflateInit(strm)) { |
12 |
| - case Z_OK: |
13 |
| - return; |
14 |
| - |
| 9 | + switch (status) { |
15 | 10 | case Z_MEM_ERROR:
|
16 |
| - err = "out of memory"; |
17 |
| - break; |
| 11 | + return "out of memory"; |
18 | 12 | case Z_VERSION_ERROR:
|
19 |
| - err = "wrong version"; |
20 |
| - break; |
| 13 | + return "wrong version"; |
| 14 | + case Z_NEED_DICT: |
| 15 | + return "needs dictionary"; |
| 16 | + case Z_DATA_ERROR: |
| 17 | + return "data stream error"; |
| 18 | + case Z_STREAM_ERROR: |
| 19 | + return "stream consistency error"; |
21 | 20 | default:
|
22 |
| - err = "error"; |
| 21 | + return "unknown error"; |
23 | 22 | }
|
24 |
| - die("inflateInit: %s (%s)", err, strm->msg ? strm->msg : "no message"); |
25 | 23 | }
|
26 | 24 |
|
27 |
| -void git_inflate_end(z_streamp strm) |
| 25 | +void git_inflate_init(z_streamp strm) |
28 | 26 | {
|
29 |
| - if (inflateEnd(strm) != Z_OK) |
30 |
| - error("inflateEnd: %s", strm->msg ? strm->msg : "failed"); |
| 27 | + int status = inflateInit(strm); |
| 28 | + |
| 29 | + if (status == Z_OK) |
| 30 | + return; |
| 31 | + die("inflateInit: %s (%s)", zerr_to_string(status), |
| 32 | + strm->msg ? strm->msg : "no message"); |
31 | 33 | }
|
32 | 34 |
|
33 |
| -int git_inflate(z_streamp strm, int flush) |
| 35 | +void git_inflate_end(z_streamp strm) |
34 | 36 | {
|
35 |
| - int ret = inflate(strm, flush); |
36 |
| - const char *err; |
| 37 | + int status = inflateEnd(strm); |
37 | 38 |
|
38 |
| - switch (ret) { |
39 |
| - /* Out of memory is fatal. */ |
40 |
| - case Z_MEM_ERROR: |
41 |
| - die("inflate: out of memory"); |
| 39 | + if (status == Z_OK) |
| 40 | + return; |
| 41 | + error("inflateEnd: %s (%s)", zerr_to_string(status), |
| 42 | + strm->msg ? strm->msg : "no message"); |
| 43 | +} |
42 | 44 |
|
43 |
| - /* Data corruption errors: we may want to recover from them (fsck) */ |
44 |
| - case Z_NEED_DICT: |
45 |
| - err = "needs dictionary"; break; |
46 |
| - case Z_DATA_ERROR: |
47 |
| - err = "data stream error"; break; |
48 |
| - case Z_STREAM_ERROR: |
49 |
| - err = "stream consistency error"; break; |
50 |
| - default: |
51 |
| - err = "unknown error"; break; |
| 45 | +int git_inflate(z_streamp strm, int flush) |
| 46 | +{ |
| 47 | + int status = inflate(strm, flush); |
52 | 48 |
|
| 49 | + switch (status) { |
53 | 50 | /* Z_BUF_ERROR: normal, needs more space in the output buffer */
|
54 | 51 | case Z_BUF_ERROR:
|
55 | 52 | case Z_OK:
|
56 | 53 | case Z_STREAM_END:
|
57 |
| - return ret; |
| 54 | + return status; |
| 55 | + |
| 56 | + case Z_MEM_ERROR: |
| 57 | + die("inflate: out of memory"); |
| 58 | + default: |
| 59 | + break; |
58 | 60 | }
|
59 |
| - error("inflate: %s (%s)", err, strm->msg ? strm->msg : "no message"); |
60 |
| - return ret; |
| 61 | + error("inflate: %s (%s)", zerr_to_string(status), |
| 62 | + strm->msg ? strm->msg : "no message"); |
| 63 | + return status; |
61 | 64 | }
|
0 commit comments