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

Function checkout_entry_ca

entry.c:481–592  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

479}
480
481int checkout_entry_ca(struct cache_entry *ce, struct conv_attrs *ca,
482 const struct checkout *state, char *topath,
483 int *nr_checkouts)
484{
485 static struct strbuf path = STRBUF_INIT;
486 struct stat st;
487 struct conv_attrs ca_buf;
488
489 if (ce->ce_flags & CE_WT_REMOVE) {
490 if (topath)
491 /*
492 * No content and thus no path to create, so we have
493 * no pathname to return.
494 */
495 BUG("Can't remove entry to a path");
496 unlink_entry(ce, state->super_prefix);
497 return 0;
498 }
499
500 if (topath) {
501 if (S_ISREG(ce->ce_mode) && !ca) {
502 convert_attrs(state->istate, &ca_buf, ce->name);
503 ca = &ca_buf;
504 }
505 return write_entry(ce, topath, ca, state, 1, nr_checkouts);
506 }
507
508 strbuf_reset(&path);
509 strbuf_add(&path, state->base_dir, state->base_dir_len);
510 strbuf_add(&path, ce->name, ce_namelen(ce));
511
512 if (!check_path(path.buf, path.len, &st, state->base_dir_len)) {
513 const struct submodule *sub;
514 unsigned changed = ie_match_stat(state->istate, ce, &st,
515 CE_MATCH_IGNORE_VALID | CE_MATCH_IGNORE_SKIP_WORKTREE);
516 /*
517 * Needs to be checked before !changed returns early,
518 * as the possibly empty directory was not changed
519 */
520 sub = submodule_from_ce(ce);
521 if (sub) {
522 int err;
523 if (!is_submodule_populated_gently(ce->name, &err)) {
524 struct stat sb;
525 if (lstat(ce->name, &sb))
526 die(_("could not stat file '%s'"), ce->name);
527 if (!(st.st_mode & S_IFDIR))
528 unlink_or_warn(ce->name);
529
530 return submodule_move_head(ce->name, state->super_prefix,
531 NULL, oid_to_hex(&ce->oid), 0);
532 } else
533 return submodule_move_head(ce->name, state->super_prefix,
534 "HEAD", oid_to_hex(&ce->oid),
535 state->force ? SUBMODULE_MOVE_HEAD_FORCE : 0);
536 }
537
538 if (!changed)

Callers 2

handle_resultsFunction · 0.85
checkout_entryFunction · 0.85

Calls 15

unlink_entryFunction · 0.85
convert_attrsFunction · 0.85
write_entryFunction · 0.85
strbuf_addFunction · 0.85
check_pathFunction · 0.85
ie_match_statFunction · 0.85
submodule_from_ceFunction · 0.85
unlink_or_warnFunction · 0.85
submodule_move_headFunction · 0.85
oid_to_hexFunction · 0.85
mark_colliding_entriesFunction · 0.85

Tested by

no test coverage detected