97
display_throughput(progress, consumed_bytes);
98
}
99
100
+/*
101
+ * Decompress zstream from the standard input into a newly
102
+ * allocated buffer of specified size and return the buffer.
103
+ * The caller is responsible to free the returned buffer.
104
+ *
105
+ * But for dry_run mode, "get_data()" is only used to check the
106
+ * integrity of data, and the returned buffer is not used at all.
107
+ * Therefore, in dry_run mode, "get_data()" will release the small
108
+ * allocated buffer which is reused to hold temporary zstream output
109
+ * and return NULL instead of returning garbage data.
110
+ */
111
static void *get_data(unsigned long size)
112
{
113
git_zstream stream;
103
- void *buf = xmallocz(size);
114
+ unsigned long bufsize = dry_run && size > 8192 ? 8192 : size;
115
+ void *buf = xmallocz(bufsize);
116
117
memset(&stream, 0, sizeof(stream));
118
119
stream.next_out = buf;
108
- stream.avail_out = size;
120
+ stream.avail_out = bufsize;
121
stream.next_in = fill(1);
122
stream.avail_in = len;
123
git_inflate_init(&stream);
137
}
138
stream.next_in = fill(1);
139
stream.avail_in = len;
140
+ if (dry_run) {
141
+ /* reuse the buffer in dry_run mode */
142
+ stream.next_out = buf;
143
+ stream.avail_out = bufsize > size - stream.total_out ?
144
+ size - stream.total_out :
145
+ bufsize;
146
+ }
147
}
148
git_inflate_end(&stream);
149
+ if (dry_run)
150
+ FREE_AND_NULL(buf);
151
return buf;
152
}
153
347
{
348
void *buf = get_data(size);
349
329
- if (!dry_run && buf)
350
+ if (buf)
351
write_object(nr, type, buf, size);
331
- else
332
- free(buf);
352
}
353
354
static int resolve_against_held(unsigned nr, const struct object_id *base,
378
oidread(&base_oid, fill(the_hash_algo->rawsz));
379
use(the_hash_algo->rawsz);
380
delta_data = get_data(delta_size);
362
- if (dry_run || !delta_data) {
363
- free(delta_data);
381
+ if (!delta_data)
382
return;
365
- }
383
if (has_object_file(&base_oid))
384
; /* Ok we have this one */
385
else if (resolve_against_held(nr, &base_oid,
415
die("offset value out of bound for delta base object");
416
417
delta_data = get_data(delta_size);
401
- if (dry_run || !delta_data) {
402
- free(delta_data);
418
+ if (!delta_data)
419
return;
404
- }
420
lo = 0;
421
hi = nr;
422
while (lo < hi) {