MCPcopy Create free account
hub / github.com/git/git / unpack_loose_rest

Function unpack_loose_rest

object-file.c:202–248  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

200}
201
202void *unpack_loose_rest(git_zstream *stream,
203 void *buffer, unsigned long size,
204 const struct object_id *oid)
205{
206 size_t bytes = strlen(buffer) + 1, n;
207 unsigned char *buf = xmallocz(size);
208 int status = Z_OK;
209
210 n = stream->total_out - bytes;
211 if (n > size)
212 n = size;
213 memcpy(buf, (char *) buffer + bytes, n);
214 bytes = n;
215 if (bytes <= size) {
216 /*
217 * The above condition must be (bytes <= size), not
218 * (bytes < size). In other words, even though we
219 * expect no more output and set avail_out to zero,
220 * the input zlib stream may have bytes that express
221 * "this concludes the stream", and we *do* want to
222 * eat that input.
223 *
224 * Otherwise we would not be able to test that we
225 * consumed all the input to reach the expected size;
226 * we also want to check that zlib tells us that all
227 * went well with status == Z_STREAM_END at the end.
228 */
229 stream->next_out = buf + bytes;
230 stream->avail_out = size - bytes;
231 while (status == Z_OK) {
232 obj_read_unlock();
233 status = git_inflate(stream, Z_FINISH);
234 obj_read_lock();
235 }
236 }
237
238 if (status != Z_STREAM_END) {
239 error(_("corrupt loose object '%s'"), oid_to_hex(oid));
240 FREE_AND_NULL(buf);
241 } else if (stream->avail_in) {
242 error(_("garbage at end of loose object '%s'"),
243 oid_to_hex(oid));
244 FREE_AND_NULL(buf);
245 }
246
247 return buf;
248}
249
250/*
251 * parse_loose_header() parses the starting "<type> <len>\0" of an

Callers 2

read_loose_objectFunction · 0.85

Calls 6

xmalloczFunction · 0.85
obj_read_unlockFunction · 0.85
git_inflateFunction · 0.85
obj_read_lockFunction · 0.85
errorFunction · 0.85
oid_to_hexFunction · 0.85

Tested by

no test coverage detected