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

Function rename_index_entry_at

read-cache.c:157–186  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

155}
156
157void rename_index_entry_at(struct index_state *istate, int nr, const char *new_name)
158{
159 struct cache_entry *old_entry = istate->cache[nr], *new_entry, *refreshed;
160 int namelen = strlen(new_name);
161
162 new_entry = make_empty_cache_entry(istate, namelen);
163 copy_cache_entry(new_entry, old_entry);
164 new_entry->ce_flags &= ~CE_HASHED;
165 new_entry->ce_namelen = namelen;
166 new_entry->index = 0;
167 memcpy(new_entry->name, new_name, namelen + 1);
168
169 cache_tree_invalidate_path(istate, old_entry->name);
170 untracked_cache_remove_from_index(istate, old_entry->name);
171 remove_index_entry_at(istate, nr);
172
173 /*
174 * Refresh the new index entry. Using 'refresh_cache_entry' ensures
175 * we only update stat info if the entry is otherwise up-to-date (i.e.,
176 * the contents/mode haven't changed). This ensures that we reflect the
177 * 'ctime' of the rename in the index without (incorrectly) updating
178 * the cached stat info to reflect unstaged changes on disk.
179 */
180 refreshed = refresh_cache_entry(istate, new_entry, CE_MATCH_REFRESH);
181 if (refreshed && refreshed != new_entry) {
182 add_index_entry(istate, refreshed, ADD_CACHE_OK_TO_ADD|ADD_CACHE_OK_TO_REPLACE);
183 discard_cache_entry(new_entry);
184 } else
185 add_index_entry(istate, new_entry, ADD_CACHE_OK_TO_ADD|ADD_CACHE_OK_TO_REPLACE);
186}
187
188/*
189 * This only updates the "non-critical" parts of the directory

Callers 1

cmd_mvFunction · 0.85

Calls 8

make_empty_cache_entryFunction · 0.85
copy_cache_entryFunction · 0.85
remove_index_entry_atFunction · 0.85
refresh_cache_entryFunction · 0.85
add_index_entryFunction · 0.85
discard_cache_entryFunction · 0.85

Tested by

no test coverage detected