MCPcopy Index your code
hub / github.com/git/git / load_preimage

Function load_preimage

apply.c:3570–3610  ·  view source on GitHub ↗

* We are about to apply "patch"; populate the "image" with the * current version we have, from the working tree or from the index, * depending on the situation e.g. --cached/--index. If we are * applying a non-git patch that incrementally updates the tree, * we read from the result of a previous diff. */

Source from the content-addressed store, hash-verified

3568 * we read from the result of a previous diff.
3569 */
3570static int load_preimage(struct apply_state *state,
3571 struct image *image,
3572 struct patch *patch, struct stat *st,
3573 const struct cache_entry *ce)
3574{
3575 struct strbuf buf = STRBUF_INIT;
3576 size_t len;
3577 char *img;
3578 struct patch *previous;
3579 int status;
3580
3581 previous = previous_patch(state, patch, &status);
3582 if (status)
3583 return error(_("path %s has been renamed/deleted"),
3584 patch->old_name);
3585 if (previous) {
3586 /* We have a patched copy in memory; use that. */
3587 strbuf_add(&buf, previous->result, previous->resultsize);
3588 } else {
3589 status = load_patch_target(state, &buf, ce, st, patch,
3590 patch->old_name, patch->old_mode);
3591 if (status < 0)
3592 return status;
3593 else if (status == SUBMODULE_PATCH_WITHOUT_INDEX) {
3594 /*
3595 * There is no way to apply subproject
3596 * patch without looking at the index.
3597 * NEEDSWORK: shouldn't this be flagged
3598 * as an error???
3599 */
3600 free_fragment_list(patch->fragments);
3601 patch->fragments = NULL;
3602 } else if (status) {
3603 return error(_("failed to read %s"), patch->old_name);
3604 }
3605 }
3606
3607 img = strbuf_detach(&buf, &len);
3608 image_prepare(image, img, len, !patch->is_binary);
3609 return 0;
3610}
3611
3612static int resolve_to(struct image *image, const struct object_id *result_id)
3613{

Callers 2

try_threewayFunction · 0.85
apply_dataFunction · 0.85

Calls 7

previous_patchFunction · 0.85
errorFunction · 0.85
strbuf_addFunction · 0.85
load_patch_targetFunction · 0.85
free_fragment_listFunction · 0.85
strbuf_detachFunction · 0.85
image_prepareFunction · 0.85

Tested by

no test coverage detected