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

Function do_read_blob

dir.c:323–358  ·  view source on GitHub ↗

* Read the contents of the blob with the given OID into a buffer. * Append a trailing LF to the end if the last line doesn't have one. * * Returns: * -1 when the OID is invalid or unknown or does not refer to a blob. * 0 when the blob is empty. * 1 along with { data, size } of the (possibly augmented) buffer * when successful. * * Optionally updates the given oid_stat wit

Source from the content-addressed store, hash-verified

321 * Optionally updates the given oid_stat with the given OID (when valid).
322 */
323static int do_read_blob(const struct object_id *oid, struct oid_stat *oid_stat,
324 size_t *size_out, char **data_out)
325{
326 enum object_type type;
327 size_t sz;
328 char *data;
329
330 *size_out = 0;
331 *data_out = NULL;
332
333 data = odb_read_object(the_repository->objects, oid, &type, &sz);
334 if (!data || type != OBJ_BLOB) {
335 free(data);
336 return -1;
337 }
338
339 if (oid_stat) {
340 memset(&oid_stat->stat, 0, sizeof(oid_stat->stat));
341 oidcpy(&oid_stat->oid, oid);
342 }
343
344 if (sz == 0) {
345 free(data);
346 return 0;
347 }
348
349 if (data[sz - 1] != '\n') {
350 data = xrealloc(data, st_add(sz, 1));
351 data[sz++] = '\n';
352 }
353
354 *size_out = xsize_t(sz);
355 *data_out = data;
356
357 return 1;
358}
359
360#define DO_MATCH_EXCLUDE (1<<0)
361#define DO_MATCH_DIRECTORY (1<<1)

Calls 5

odb_read_objectFunction · 0.85
oidcpyFunction · 0.85
xreallocFunction · 0.85
st_addFunction · 0.85
xsize_tFunction · 0.85

Tested by

no test coverage detected