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

Function add_index_file

apply.c:4443–4492  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4441}
4442
4443static int add_index_file(struct apply_state *state,
4444 const char *path,
4445 unsigned mode,
4446 void *buf,
4447 unsigned long size)
4448{
4449 struct stat st;
4450 struct cache_entry *ce;
4451 int namelen = strlen(path);
4452
4453 ce = make_empty_cache_entry(state->repo->index, namelen);
4454 memcpy(ce->name, path, namelen);
4455 ce->ce_mode = create_ce_mode(mode);
4456 ce->ce_flags = create_ce_flags(0);
4457 ce->ce_namelen = namelen;
4458 if (state->ita_only) {
4459 ce->ce_flags |= CE_INTENT_TO_ADD;
4460 set_object_name_for_intent_to_add_entry(ce);
4461 } else if (S_ISGITLINK(mode)) {
4462 const char *s;
4463
4464 if (!skip_prefix(buf, "Subproject commit ", &s) ||
4465 get_oid_hex(s, &ce->oid)) {
4466 discard_cache_entry(ce);
4467 return error(_("corrupt patch for submodule %s"), path);
4468 }
4469 } else {
4470 if (!state->cached) {
4471 if (lstat(path, &st) < 0) {
4472 discard_cache_entry(ce);
4473 return error_errno(_("unable to stat newly "
4474 "created file '%s'"),
4475 path);
4476 }
4477 fill_stat_cache_info(state->repo->index, ce, &st);
4478 }
4479 if (odb_write_object(the_repository->objects, buf, size,
4480 OBJ_BLOB, &ce->oid) < 0) {
4481 discard_cache_entry(ce);
4482 return error(_("unable to create backing store "
4483 "for newly created file %s"), path);
4484 }
4485 }
4486 if (add_index_entry(state->repo->index, ce, ADD_CACHE_OK_TO_ADD) < 0) {
4487 discard_cache_entry(ce);
4488 return error(_("unable to add cache entry for %s"), path);
4489 }
4490
4491 return 0;
4492}
4493
4494/*
4495 * Returns:

Callers 1

create_fileFunction · 0.85

Calls 11

make_empty_cache_entryFunction · 0.85
create_ce_modeFunction · 0.85
create_ce_flagsFunction · 0.85
get_oid_hexFunction · 0.85
discard_cache_entryFunction · 0.85
errorFunction · 0.85
error_errnoFunction · 0.85
fill_stat_cache_infoFunction · 0.85
odb_write_objectFunction · 0.85
add_index_entryFunction · 0.85

Tested by

no test coverage detected