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

Function add_to_index

read-cache.c:712–808  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

710}
711
712int add_to_index(struct index_state *istate, const char *path, struct stat *st, int flags)
713{
714 int namelen, was_same;
715 mode_t st_mode = st->st_mode;
716 struct cache_entry *ce, *alias = NULL;
717 unsigned ce_option = CE_MATCH_IGNORE_VALID|CE_MATCH_IGNORE_SKIP_WORKTREE|CE_MATCH_RACY_IS_DIRTY;
718 int verbose = flags & (ADD_CACHE_VERBOSE | ADD_CACHE_PRETEND);
719 int pretend = flags & ADD_CACHE_PRETEND;
720 int intent_only = flags & ADD_CACHE_INTENT;
721 int add_option = (ADD_CACHE_OK_TO_ADD|ADD_CACHE_OK_TO_REPLACE|
722 (intent_only ? ADD_CACHE_NEW_ONLY : 0));
723 unsigned hash_flags = pretend ? 0 : INDEX_WRITE_OBJECT;
724
725 if (flags & ADD_CACHE_RENORMALIZE)
726 hash_flags |= INDEX_RENORMALIZE;
727
728 if (!S_ISREG(st_mode) && !S_ISLNK(st_mode) && !S_ISDIR(st_mode))
729 return error(_("%s: can only add regular files, symbolic links or git-directories"), path);
730
731 namelen = strlen(path);
732 if (S_ISDIR(st_mode)) {
733 while (namelen && path[namelen-1] == '/')
734 namelen--;
735 }
736 ce = make_empty_cache_entry(istate, namelen);
737 memcpy(ce->name, path, namelen);
738 ce->ce_namelen = namelen;
739 if (!intent_only)
740 fill_stat_cache_info(istate, ce, st);
741 else
742 ce->ce_flags |= CE_INTENT_TO_ADD;
743
744
745 if (trust_executable_bit && has_symlinks) {
746 ce->ce_mode = create_ce_mode(st_mode);
747 } else {
748 /* If there is an existing entry, pick the mode bits and type
749 * from it, otherwise assume unexecutable regular file.
750 */
751 struct cache_entry *ent;
752 int pos = index_name_pos_also_unmerged(istate, path, namelen);
753
754 ent = (0 <= pos) ? istate->cache[pos] : NULL;
755 ce->ce_mode = ce_mode_from_stat(ent, st_mode);
756 }
757
758 /* When core.ignorecase=true, determine if a directory of the same name but differing
759 * case already exists within the Git repository. If it does, ensure the directory
760 * case of the file being added to the repository matches (is folded into) the existing
761 * entry's directory case.
762 */
763 if (ignore_case) {
764 adjust_dirname_case(istate, ce->name);
765 }
766 if (!(flags & ADD_CACHE_RENORMALIZE)) {
767 alias = index_file_exists(istate, ce->name,
768 ce_namelen(ce), ignore_case);
769 if (alias &&

Callers 2

add_file_to_indexFunction · 0.85
add_remove_filesFunction · 0.85

Calls 15

errorFunction · 0.85
make_empty_cache_entryFunction · 0.85
fill_stat_cache_infoFunction · 0.85
create_ce_modeFunction · 0.85
ce_mode_from_statFunction · 0.85
adjust_dirname_caseFunction · 0.85
index_file_existsFunction · 0.85
ie_match_statFunction · 0.85
discard_cache_entryFunction · 0.85
index_pathFunction · 0.85

Tested by

no test coverage detected