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

Function update_index_from_diff

builtin/reset.c:151–195  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

149}
150
151static void update_index_from_diff(struct diff_queue_struct *q,
152 struct diff_options *opt UNUSED,
153 void *data)
154{
155 int i;
156 int intent_to_add = *(int *)data;
157
158 for (i = 0; i < q->nr; i++) {
159 int pos;
160 struct diff_filespec *one = q->queue[i]->one;
161 int is_in_reset_tree = one->mode && !is_null_oid(&one->oid);
162 struct cache_entry *ce;
163
164 if (!is_in_reset_tree && !intent_to_add) {
165 remove_file_from_index(the_repository->index, one->path);
166 continue;
167 }
168
169 ce = make_cache_entry(the_repository->index, one->mode, &one->oid, one->path,
170 0, 0);
171
172 /*
173 * If the file 1) corresponds to an existing index entry with
174 * skip-worktree set, or 2) does not exist in the index but is
175 * outside the sparse checkout definition, add a skip-worktree bit
176 * to the new index entry. Note that a sparse index will be expanded
177 * if this entry is outside the sparse cone - this is necessary
178 * to properly construct the reset sparse directory.
179 */
180 pos = index_name_pos(the_repository->index, one->path, strlen(one->path));
181 if ((pos >= 0 && ce_skip_worktree(the_repository->index->cache[pos])) ||
182 (pos < 0 && !path_in_sparse_checkout(one->path, the_repository->index)))
183 ce->ce_flags |= CE_SKIP_WORKTREE;
184
185 if (!ce)
186 die(_("make_cache_entry failed for path '%s'"),
187 one->path);
188 if (!is_in_reset_tree) {
189 ce->ce_flags |= CE_INTENT_TO_ADD;
190 set_object_name_for_intent_to_add_entry(ce);
191 }
192 add_index_entry(the_repository->index, ce,
193 ADD_CACHE_OK_TO_ADD | ADD_CACHE_OK_TO_REPLACE);
194 }
195}
196
197static int read_from_tree(const struct pathspec *pathspec,
198 struct object_id *tree_oid,

Callers

nothing calls this directly

Calls 8

is_null_oidFunction · 0.85
remove_file_from_indexFunction · 0.85
make_cache_entryFunction · 0.85
index_name_posFunction · 0.85
path_in_sparse_checkoutFunction · 0.85
add_index_entryFunction · 0.85
dieFunction · 0.50

Tested by

no test coverage detected