cocci & cache.h: apply variable section of "pending" index-compatibility

Mostly apply the part of "index-compatibility.pending.cocci" that renames the global variables like "active_nr", which are a shorthand to referencing (in that case) a struct member as "the_index.cache_nr". In doing so move more of "index-compatibility.pending.cocci" to "index-compatibility.cocci". In the case of "active_nr" we'd have a textual conflict with "ab/various-leak-fixes" in "next"[1]. Let's exclude that specific case while moving the rule over from "pending". 1. 407b94280f8 (commit: discard partial cache before (re-)reading it, 2022-11-08) Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Nov 19, 2022 at 14:07 UTC dc594180d9e62438cb664c678f5e5bd229154c75
19 files changed +132 -129
builtin/add.c
+4 -4
@@ -42,8 +42,8 @@ static int chmod_pathspec(struct pathspec *pathspec, char flip, int show_only)
42 {
43 int i, ret = 0;
44
45 - for (i = 0; i < active_nr; i++) {
46 - struct cache_entry *ce = active_cache[i];
45 + for (i = 0; i < the_index.cache_nr; i++) {
46 + struct cache_entry *ce = the_index.cache[i];
47 int err;
48
49 if (!include_sparse &&
@@ -159,8 +159,8 @@ static int renormalize_tracked_files(const struct pathspec *pathspec, int flags)
159 {
160 int i, retval = 0;
161
162 - for (i = 0; i < active_nr; i++) {
163 - struct cache_entry *ce = active_cache[i];
162 + for (i = 0; i < the_index.cache_nr; i++) {
163 + struct cache_entry *ce = the_index.cache[i];
164
165 if (!include_sparse &&
166 (ce_skip_worktree(ce) ||
builtin/checkout-index.c
+5 -5
@@ -75,8 +75,8 @@ static int checkout_file(const char *name, const char *prefix)
75 if (pos < 0)
76 pos = -pos - 1;
77
78 - while (pos < active_nr) {
79 - struct cache_entry *ce = active_cache[pos];
78 + while (pos < the_index.cache_nr) {
79 + struct cache_entry *ce = the_index.cache[pos];
80 if (ce_namelen(ce) != namelen ||
81 memcmp(ce->name, name, namelen))
82 break;
@@ -136,8 +136,8 @@ static int checkout_all(const char *prefix, int prefix_length)
136 int i, errs = 0;
137 struct cache_entry *last_ce = NULL;
138
139 - for (i = 0; i < active_nr ; i++) {
140 - struct cache_entry *ce = active_cache[i];
139 + for (i = 0; i < the_index.cache_nr ; i++) {
140 + struct cache_entry *ce = the_index.cache[i];
141
142 if (S_ISSPARSEDIR(ce->ce_mode)) {
143 if (!ce_skip_worktree(ce))
@@ -151,7 +151,7 @@ static int checkout_all(const char *prefix, int prefix_length)
151 */
152 if (ignore_skip_worktree) {
153 ensure_full_index(&the_index);
154 - ce = active_cache[i];
154 + ce = the_index.cache[i];
155 }
156 }
157
builtin/checkout.c
+23 -23
@@ -150,7 +150,7 @@ static int update_some(const struct object_id *oid, struct strbuf *base,
150 */
151 pos = cache_name_pos(ce->name, ce->ce_namelen);
152 if (pos >= 0) {
153 - struct cache_entry *old = active_cache[pos];
153 + struct cache_entry *old = the_index.cache[pos];
154 if (ce->ce_mode == old->ce_mode &&
155 !ce_intent_to_add(old) &&
156 oideq(&ce->oid, &old->oid)) {
@@ -179,8 +179,8 @@ static int read_tree_some(struct tree *tree, const struct pathspec *pathspec)
179
180 static int skip_same_name(const struct cache_entry *ce, int pos)
181 {
182 - while (++pos < active_nr &&
183 - !strcmp(active_cache[pos]->name, ce->name))
182 + while (++pos < the_index.cache_nr &&
183 + !strcmp(the_index.cache[pos]->name, ce->name))
184 ; /* skip */
185 return pos;
186 }
@@ -188,9 +188,9 @@ static int skip_same_name(const struct cache_entry *ce, int pos)
188 static int check_stage(int stage, const struct cache_entry *ce, int pos,
189 int overlay_mode)
190 {
191 - while (pos < active_nr &&
192 - !strcmp(active_cache[pos]->name, ce->name)) {
193 - if (ce_stage(active_cache[pos]) == stage)
191 + while (pos < the_index.cache_nr &&
192 + !strcmp(the_index.cache[pos]->name, ce->name)) {
193 + if (ce_stage(the_index.cache[pos]) == stage)
194 return 0;
195 pos++;
196 }
@@ -207,8 +207,8 @@ static int check_stages(unsigned stages, const struct cache_entry *ce, int pos)
207 unsigned seen = 0;
208 const char *name = ce->name;
209
210 - while (pos < active_nr) {
211 - ce = active_cache[pos];
210 + while (pos < the_index.cache_nr) {
211 + ce = the_index.cache[pos];
212 if (strcmp(name, ce->name))
213 break;
214 seen |= (1 << ce_stage(ce));
@@ -224,10 +224,10 @@ static int checkout_stage(int stage, const struct cache_entry *ce, int pos,
224 const struct checkout *state, int *nr_checkouts,
225 int overlay_mode)
226 {
227 - while (pos < active_nr &&
228 - !strcmp(active_cache[pos]->name, ce->name)) {
229 - if (ce_stage(active_cache[pos]) == stage)
230 - return checkout_entry(active_cache[pos], state,
227 + while (pos < the_index.cache_nr &&
228 + !strcmp(the_index.cache[pos]->name, ce->name)) {
229 + if (ce_stage(the_index.cache[pos]) == stage)
230 + return checkout_entry(the_index.cache[pos], state,
231 NULL, nr_checkouts);
232 pos++;
233 }
@@ -244,7 +244,7 @@ static int checkout_stage(int stage, const struct cache_entry *ce, int pos,
244 static int checkout_merged(int pos, const struct checkout *state,
245 int *nr_checkouts, struct mem_pool *ce_mem_pool)
246 {
247 - struct cache_entry *ce = active_cache[pos];
247 + struct cache_entry *ce = the_index.cache[pos];
248 const char *path = ce->name;
249 mmfile_t ancestor, ours, theirs;
250 enum ll_merge_result merge_status;
@@ -257,7 +257,7 @@ static int checkout_merged(int pos, const struct checkout *state,
257 int renormalize = 0;
258
259 memset(threeway, 0, sizeof(threeway));
260 - while (pos < active_nr) {
260 + while (pos < the_index.cache_nr) {
261 int stage;
262 stage = ce_stage(ce);
263 if (!stage || strcmp(path, ce->name))
@@ -266,7 +266,7 @@ static int checkout_merged(int pos, const struct checkout *state,
266 if (stage == 2)
267 mode = create_ce_mode(ce->ce_mode);
268 pos++;
269 - ce = active_cache[pos];
269 + ce = the_index.cache[pos];
270 }
271 if (is_null_oid(&threeway[1]) || is_null_oid(&threeway[2]))
272 return error(_("path '%s' does not have necessary versions"), path);
@@ -392,8 +392,8 @@ static int checkout_worktree(const struct checkout_opts *opts,
392 if (pc_workers > 1)
393 init_parallel_checkout();
394
395 - for (pos = 0; pos < active_nr; pos++) {
396 - struct cache_entry *ce = active_cache[pos];
395 + for (pos = 0; pos < the_index.cache_nr; pos++) {
396 + struct cache_entry *ce = the_index.cache[pos];
397 if (ce->ce_flags & CE_MATCHED) {
398 if (!ce_stage(ce)) {
399 errs |= checkout_entry(ce, &state,
@@ -541,13 +541,13 @@ static int checkout_paths(const struct checkout_opts *opts,
541 * Make sure all pathspecs participated in locating the paths
542 * to be checked out.
543 */
544 - for (pos = 0; pos < active_nr; pos++)
544 + for (pos = 0; pos < the_index.cache_nr; pos++)
545 if (opts->overlay_mode)
546 - mark_ce_for_checkout_overlay(active_cache[pos],
546 + mark_ce_for_checkout_overlay(the_index.cache[pos],
547 ps_matched,
548 opts);
549 else
550 - mark_ce_for_checkout_no_overlay(active_cache[pos],
550 + mark_ce_for_checkout_no_overlay(the_index.cache[pos],
551 ps_matched,
552 opts);
553
@@ -562,8 +562,8 @@ static int checkout_paths(const struct checkout_opts *opts,
562 unmerge_marked_index(&the_index);
563
564 /* Any unmerged paths? */
565 - for (pos = 0; pos < active_nr; pos++) {
566 - const struct cache_entry *ce = active_cache[pos];
565 + for (pos = 0; pos < the_index.cache_nr; pos++) {
566 + const struct cache_entry *ce = the_index.cache[pos];
567 if (ce->ce_flags & CE_MATCHED) {
568 if (!ce_stage(ce))
569 continue;
@@ -868,7 +868,7 @@ static int merge_working_tree(const struct checkout_opts *opts,
868 }
869 }
870
871 - if (!cache_tree_fully_valid(active_cache_tree))
871 + if (!cache_tree_fully_valid(the_index.cache_tree))
872 cache_tree_update(&the_index, WRITE_TREE_SILENT | WRITE_TREE_REPAIR);
873
874 if (write_locked_index(&the_index, &lock_file, COMMIT_LOCK))
builtin/commit.c
+8 -8
@@ -272,8 +272,8 @@ static int list_paths(struct string_list *list, const char *with_tree,
272
273 /* TODO: audit for interaction with sparse-index. */
274 ensure_full_index(&the_index);
275 - for (i = 0; i < active_nr; i++) {
276 - const struct cache_entry *ce = active_cache[i];
275 + for (i = 0; i < the_index.cache_nr; i++) {
276 + const struct cache_entry *ce = the_index.cache[i];
277 struct string_list_item *item;
278
279 if (ce->ce_flags & CE_UPDATE)
@@ -461,8 +461,8 @@ static const char *prepare_index(const char **argv, const char *prefix,
461 if (!only && !pathspec.nr) {
462 hold_locked_index(&index_lock, LOCK_DIE_ON_ERROR);
463 refresh_cache_or_die(refresh_flags);
464 - if (active_cache_changed
465 - || !cache_tree_fully_valid(active_cache_tree))
464 + if (the_index.cache_changed
465 + || !cache_tree_fully_valid(the_index.cache_tree))
466 update_main_cache_tree(WRITE_TREE_SILENT);
467 if (write_locked_index(&the_index, &index_lock,
468 COMMIT_LOCK | SKIP_IF_UNCHANGED))
@@ -998,10 +998,10 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
998
999 /* TODO: audit for interaction with sparse-index. */
1000 ensure_full_index(&the_index);
1001 - for (i = 0; i < active_nr; i++)
1002 - if (ce_intent_to_add(active_cache[i]))
1001 + for (i = 0; i < the_index.cache_nr; i++)
1002 + if (ce_intent_to_add(the_index.cache[i]))
1003 ita_nr++;
1004 - committable = active_nr - ita_nr > 0;
1004 + committable = the_index.cache_nr - ita_nr > 0;
1005 } else {
1006 /*
1007 * Unless the user did explicitly request a submodule
@@ -1823,7 +1823,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
1823 append_merge_tag_headers(parents, &tail);
1824 }
1825
1826 - if (commit_tree_extended(sb.buf, sb.len, &active_cache_tree->oid,
1826 + if (commit_tree_extended(sb.buf, sb.len, &the_index.cache_tree->oid,
1827 parents, &oid, author_ident.buf, NULL,
1828 sign_commit, extra)) {
1829 rollback_index_files();
builtin/fsck.c
+6 -6
@@ -961,26 +961,26 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
961 read_cache();
962 /* TODO: audit for interaction with sparse-index. */
963 ensure_full_index(&the_index);
964 - for (i = 0; i < active_nr; i++) {
964 + for (i = 0; i < the_index.cache_nr; i++) {
965 unsigned int mode;
966 struct blob *blob;
967 struct object *obj;
968
969 - mode = active_cache[i]->ce_mode;
969 + mode = the_index.cache[i]->ce_mode;
970 if (S_ISGITLINK(mode))
971 continue;
972 blob = lookup_blob(the_repository,
973 - &active_cache[i]->oid);
973 + &the_index.cache[i]->oid);
974 if (!blob)
975 continue;
976 obj = &blob->object;
977 obj->flags |= USED;
978 fsck_put_object_name(&fsck_walk_options, &obj->oid,
979 - ":%s", active_cache[i]->name);
979 + ":%s", the_index.cache[i]->name);
980 mark_object_reachable(obj);
981 }
982 - if (active_cache_tree)
983 - fsck_cache_tree(active_cache_tree);
982 + if (the_index.cache_tree)
983 + fsck_cache_tree(the_index.cache_tree);
984 fsck_resolve_undo(&the_index);
985 }
986
builtin/merge-index.c
+5 -5
@@ -14,11 +14,11 @@ static int merge_entry(int pos, const char *path)
14 char ownbuf[4][60];
15 struct child_process cmd = CHILD_PROCESS_INIT;
16
17 - if (pos >= active_nr)
17 + if (pos >= the_index.cache_nr)
18 die("git merge-index: %s not in the cache", path);
19 found = 0;
20 do {
21 - const struct cache_entry *ce = active_cache[pos];
21 + const struct cache_entry *ce = the_index.cache[pos];
22 int stage = ce_stage(ce);
23
24 if (strcmp(ce->name, path))
@@ -28,7 +28,7 @@ static int merge_entry(int pos, const char *path)
28 xsnprintf(ownbuf[stage], sizeof(ownbuf[stage]), "%o", ce->ce_mode);
29 arguments[stage] = hexbuf[stage];
30 arguments[stage + 4] = ownbuf[stage];
31 - } while (++pos < active_nr);
31 + } while (++pos < the_index.cache_nr);
32 if (!found)
33 die("git merge-index: %s not in the cache", path);
34
@@ -62,8 +62,8 @@ static void merge_all(void)
62 int i;
63 /* TODO: audit for interaction with sparse-index. */
64 ensure_full_index(&the_index);
65 - for (i = 0; i < active_nr; i++) {
66 - const struct cache_entry *ce = active_cache[i];
65 + for (i = 0; i < the_index.cache_nr; i++) {
66 + const struct cache_entry *ce = the_index.cache[i];
67 if (!ce_stage(ce))
68 continue;
69 i += merge_entry(i, ce->name)-1;
builtin/merge.c
+3 -3
@@ -694,7 +694,7 @@ static int read_tree_trivial(struct object_id *common, struct object_id *head,
694 if (!trees[nr_trees++])
695 return -1;
696 opts.fn = threeway_merge;
697 - cache_tree_free(&active_cache_tree);
697 + cache_tree_free(&the_index.cache_tree);
698 for (i = 0; i < nr_trees; i++) {
699 parse_tree(trees[i]);
700 init_tree_desc(t+i, trees[i]->buffer, trees[i]->size);
@@ -784,8 +784,8 @@ static int count_unmerged_entries(void)
784 {
785 int i, ret = 0;
786
787 - for (i = 0; i < active_nr; i++)
788 - if (ce_stage(active_cache[i]))
787 + for (i = 0; i < the_index.cache_nr; i++)
788 + if (ce_stage(the_index.cache[i]))
789 ret++;
790
791 return ret;
builtin/mv.c
+10 -9
@@ -87,7 +87,7 @@ static void prepare_move_submodule(const char *src, int first,
87 const char **submodule_gitfile)
88 {
89 struct strbuf submodule_dotgit = STRBUF_INIT;
90 - if (!S_ISGITLINK(active_cache[first]->ce_mode))
90 + if (!S_ISGITLINK(the_index.cache[first]->ce_mode))
91 die(_("Directory %s is in index and no submodule?"), src);
92 if (!is_staging_gitmodules_ok(&the_index))
93 die(_("Please stage your changes to .gitmodules or stash them to proceed"));
@@ -111,8 +111,8 @@ static int index_range_of_same_dir(const char *src, int length,
111 die(_("%.*s is in index"), len_w_slash, src_w_slash);
112
113 first = -1 - first;
114 - for (last = first; last < active_nr; last++) {
115 - const char *path = active_cache[last]->name;
114 + for (last = first; last < the_index.cache_nr; last++) {
115 + const char *path = the_index.cache[last]->name;
116 if (strncmp(path, src_w_slash, len_w_slash))
117 break;
118 }
@@ -143,7 +143,7 @@ static int empty_dir_has_sparse_contents(const char *name)
143 pos = -pos - 1;
144 if (pos >= the_index.cache_nr)
145 goto free_return;
146 - ce = active_cache[pos];
146 + ce = the_index.cache[pos];
147 if (strncmp(with_slash, ce->name, length))
148 goto free_return;
149 if (ce_skip_worktree(ce))
@@ -268,7 +268,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
268 bad = _("bad source");
269 goto act_on_entry;
270 }
271 - ce = active_cache[pos];
271 + ce = the_index.cache[pos];
272 if (!ce_skip_worktree(ce)) {
273 bad = _("bad source");
274 goto act_on_entry;
@@ -331,7 +331,7 @@ dir_check:
331 dst_len = strlen(dst);
332
333 for (j = 0; j < last - first; j++) {
334 - const struct cache_entry *ce = active_cache[first + j];
334 + const struct cache_entry *ce = the_index.cache[first + j];
335 const char *path = ce->name;
336 source[argc + j] = path;
337 destination[argc + j] =
@@ -472,7 +472,8 @@ remove_entry:
472 assert(pos >= 0);
473 if (!(mode & SPARSE) && !lstat(src, &st))
474 sparse_and_dirty = ie_modified(&the_index,
475 - active_cache[pos], &st,
475 + the_index.cache[pos],
476 + &st,
477 0);
478 rename_index_entry_at(&the_index, pos, dst);
479
@@ -489,7 +490,7 @@ remove_entry:
490 path_in_sparse_checkout(dst, &the_index)) {
491 /* from out-of-cone to in-cone */
492 int dst_pos = cache_name_pos(dst, strlen(dst));
492 - struct cache_entry *dst_ce = active_cache[dst_pos];
493 + struct cache_entry *dst_ce = the_index.cache[dst_pos];
494
495 dst_ce->ce_flags &= ~CE_SKIP_WORKTREE;
496
@@ -500,7 +501,7 @@ remove_entry:
501 !path_in_sparse_checkout(dst, &the_index)) {
502 /* from in-cone to out-of-cone */
503 int dst_pos = cache_name_pos(dst, strlen(dst));
503 - struct cache_entry *dst_ce = active_cache[dst_pos];
504 + struct cache_entry *dst_ce = the_index.cache[dst_pos];
505
506 /*
507 * if src is clean, it will suffice to remove it
builtin/read-tree.c
+1 -1
@@ -253,7 +253,7 @@ int cmd_read_tree(int argc, const char **argv, const char *cmd_prefix)
253 if (nr_trees == 1 && !opts.prefix)
254 opts.skip_cache_tree_update = 1;
255
256 - cache_tree_free(&active_cache_tree);
256 + cache_tree_free(&the_index.cache_tree);
257 for (i = 0; i < nr_trees; i++) {
258 struct tree *tree = trees[i];
259 parse_tree(tree);
builtin/reset.c
+1 -1
@@ -161,7 +161,7 @@ static void update_index_from_diff(struct diff_queue_struct *q,
161 * to properly construct the reset sparse directory.
162 */
163 pos = cache_name_pos(one->path, strlen(one->path));
164 - if ((pos >= 0 && ce_skip_worktree(active_cache[pos])) ||
164 + if ((pos >= 0 && ce_skip_worktree(the_index.cache[pos])) ||
165 (pos < 0 && !path_in_sparse_checkout(one->path, &the_index)))
166 ce->ce_flags |= CE_SKIP_WORKTREE;
167
builtin/rm.c
+7 -7
@@ -35,8 +35,8 @@ static int get_ours_cache_pos(const char *path, int pos)
35 {
36 int i = -pos - 1;
37
38 - while ((i < active_nr) && !strcmp(active_cache[i]->name, path)) {
39 - if (ce_stage(active_cache[i]) == 2)
38 + while ((i < the_index.cache_nr) && !strcmp(the_index.cache[i]->name, path)) {
39 + if (ce_stage(the_index.cache[i]) == 2)
40 return i;
41 i++;
42 }
@@ -78,7 +78,7 @@ static void submodules_absorb_gitdir_if_needed(void)
78 if (pos < 0)
79 continue;
80 }
81 - ce = active_cache[pos];
81 + ce = the_index.cache[pos];
82
83 if (!S_ISGITLINK(ce->ce_mode) ||
84 !file_exists(ce->name) ||
@@ -127,11 +127,11 @@ static int check_local_mod(struct object_id *head, int index_only)
127 if (pos < 0)
128 continue;
129
130 - if (!S_ISGITLINK(active_cache[pos]->ce_mode) ||
130 + if (!S_ISGITLINK(the_index.cache[pos]->ce_mode) ||
131 is_empty_dir(name))
132 continue;
133 }
134 - ce = active_cache[pos];
134 + ce = the_index.cache[pos];
135
136 if (lstat(ce->name, &st) < 0) {
137 if (!is_missing_file_error(errno))
@@ -303,8 +303,8 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
303 if (pathspec_needs_expanded_index(&the_index, &pathspec))
304 ensure_full_index(&the_index);
305
306 - for (i = 0; i < active_nr; i++) {
307 - const struct cache_entry *ce = active_cache[i];
306 + for (i = 0; i < the_index.cache_nr; i++) {
307 + const struct cache_entry *ce = the_index.cache[i];
308
309 if (!include_sparse &&
310 (ce_skip_worktree(ce) ||
builtin/stash.c
+4 -4
@@ -454,10 +454,10 @@ static void unstage_changes_unless_new(struct object_id *orig_tree)
454 * path, but left it out of the working tree, then clear the
455 * SKIP_WORKTREE bit and write it to the working tree.
456 */
457 - if (pos >= 0 && ce_skip_worktree(active_cache[pos])) {
457 + if (pos >= 0 && ce_skip_worktree(the_index.cache[pos])) {
458 struct stat st;
459
460 - ce = active_cache[pos];
460 + ce = the_index.cache[pos];
461 if (!lstat(ce->name, &st)) {
462 /* Conflicting path present; relocate it */
463 struct strbuf new_path = STRBUF_INIT;
@@ -1520,8 +1520,8 @@ static int do_push_stash(const struct pathspec *ps, const char *stash_msg, int q
1520
1521 /* TODO: audit for interaction with sparse-index. */
1522 ensure_full_index(&the_index);
1523 - for (i = 0; i < active_nr; i++)
1524 - ce_path_match(&the_index, active_cache[i], ps,
1523 + for (i = 0; i < the_index.cache_nr; i++)
1524 + ce_path_match(&the_index, the_index.cache[i], ps,
1525 ps_matched);
1526
1527 if (report_path_error(ps_matched, ps)) {
builtin/submodule--helper.c
+7 -7
@@ -199,8 +199,8 @@ static int module_list_compute(const char **argv,
199 if (read_cache() < 0)
200 die(_("index file corrupt"));
201
202 - for (i = 0; i < active_nr; i++) {
203 - const struct cache_entry *ce = active_cache[i];
202 + for (i = 0; i < the_index.cache_nr; i++) {
203 + const struct cache_entry *ce = the_index.cache[i];
204
205 if (!match_pathspec(&the_index, pathspec, ce->name, ce_namelen(ce),
206 0, ps_matched, 1) ||
@@ -209,8 +209,8 @@ static int module_list_compute(const char **argv,
209
210 ALLOC_GROW(list->entries, list->nr + 1, list->alloc);
211 list->entries[list->nr++] = ce;
212 - while (i + 1 < active_nr &&
213 - !strcmp(ce->name, active_cache[i + 1]->name))
212 + while (i + 1 < the_index.cache_nr &&
213 + !strcmp(ce->name, the_index.cache[i + 1]->name))
214 /*
215 * Skip entries with the same name in different stages
216 * to make sure an entry is returned only once.
@@ -3255,15 +3255,15 @@ static void die_on_index_match(const char *path, int force)
3255 * need to check ps_matched[0] to know if a cache
3256 * entry matched.
3257 */
3258 - for (i = 0; i < active_nr; i++) {
3259 - ce_path_match(&the_index, active_cache[i], &ps,
3258 + for (i = 0; i < the_index.cache_nr; i++) {
3259 + ce_path_match(&the_index, the_index.cache[i], &ps,
3260 ps_matched);
3261
3262 if (ps_matched[0]) {
3263 if (!force)
3264 die(_("'%s' already exists in the index"),
3265 path);
3266 - if (!S_ISGITLINK(active_cache[i]->ce_mode))
3266 + if (!S_ISGITLINK(the_index.cache[i]->ce_mode))
3267 die(_("'%s' already exists in the index "
3268 "and is not a submodule"), path);
3269 break;
builtin/update-index.c
+23 -23
@@ -239,14 +239,14 @@ static int mark_ce_flags(const char *path, int flag, int mark)
239 int namelen = strlen(path);
240 int pos = cache_name_pos(path, namelen);
241 if (0 <= pos) {
242 - mark_fsmonitor_invalid(&the_index, active_cache[pos]);
242 + mark_fsmonitor_invalid(&the_index, the_index.cache[pos]);
243 if (mark)
244 - active_cache[pos]->ce_flags |= flag;
244 + the_index.cache[pos]->ce_flags |= flag;
245 else
246 - active_cache[pos]->ce_flags &= ~flag;
247 - active_cache[pos]->ce_flags |= CE_UPDATE_IN_BASE;
246 + the_index.cache[pos]->ce_flags &= ~flag;
247 + the_index.cache[pos]->ce_flags |= CE_UPDATE_IN_BASE;
248 cache_tree_invalidate_path(&the_index, path);
249 - active_cache_changed |= CE_ENTRY_CHANGED;
249 + the_index.cache_changed |= CE_ENTRY_CHANGED;
250 return 0;
251 }
252 return -1;
@@ -335,7 +335,7 @@ static int process_directory(const char *path, int len, struct stat *st)
335
336 /* Exact match: file or existing gitlink */
337 if (pos >= 0) {
338 - const struct cache_entry *ce = active_cache[pos];
338 + const struct cache_entry *ce = the_index.cache[pos];
339 if (S_ISGITLINK(ce->ce_mode)) {
340
341 /* Do nothing to the index if there is no HEAD! */
@@ -350,8 +350,8 @@ static int process_directory(const char *path, int len, struct stat *st)
350
351 /* Inexact match: is there perhaps a subdirectory match? */
352 pos = -pos-1;
353 - while (pos < active_nr) {
354 - const struct cache_entry *ce = active_cache[pos++];
353 + while (pos < the_index.cache_nr) {
354 + const struct cache_entry *ce = the_index.cache[pos++];
355
356 if (strncmp(ce->name, path, len))
357 break;
@@ -382,7 +382,7 @@ static int process_path(const char *path, struct stat *st, int stat_errno)
382 return error("'%s' is beyond a symbolic link", path);
383
384 pos = cache_name_pos(path, len);
385 - ce = pos < 0 ? NULL : active_cache[pos];
385 + ce = pos < 0 ? NULL : the_index.cache[pos];
386 if (ce && ce_skip_worktree(ce)) {
387 /*
388 * working directory version is assumed "good"
@@ -444,7 +444,7 @@ static void chmod_path(char flip, const char *path)
444 pos = cache_name_pos(path, strlen(path));
445 if (pos < 0)
446 goto fail;
447 - ce = active_cache[pos];
447 + ce = the_index.cache[pos];
448 if (chmod_index_entry(&the_index, ce, flip) < 0)
449 goto fail;
450
@@ -642,8 +642,8 @@ static int unresolve_one(const char *path)
642 if (0 <= pos) {
643 /* already merged */
644 pos = unmerge_index_entry_at(&the_index, pos);
645 - if (pos < active_nr) {
646 - const struct cache_entry *ce = active_cache[pos];
645 + if (pos < the_index.cache_nr) {
646 + const struct cache_entry *ce = the_index.cache[pos];
647 if (ce_stage(ce) &&
648 ce_namelen(ce) == namelen &&
649 !memcmp(ce->name, path, namelen))
@@ -656,8 +656,8 @@ static int unresolve_one(const char *path)
656 * want to do anything in the former case.
657 */
658 pos = -pos-1;
659 - if (pos < active_nr) {
660 - const struct cache_entry *ce = active_cache[pos];
659 + if (pos < the_index.cache_nr) {
660 + const struct cache_entry *ce = the_index.cache[pos];
661 if (ce_namelen(ce) == namelen &&
662 !memcmp(ce->name, path, namelen)) {
663 fprintf(stderr,
@@ -752,8 +752,8 @@ static int do_reupdate(const char **paths,
752 */
753 has_head = 0;
754 redo:
755 - for (pos = 0; pos < active_nr; pos++) {
756 - const struct cache_entry *ce = active_cache[pos];
755 + for (pos = 0; pos < the_index.cache_nr; pos++) {
756 + const struct cache_entry *ce = the_index.cache[pos];
757 struct cache_entry *old = NULL;
758 int save_nr;
759 char *path;
@@ -782,12 +782,12 @@ static int do_reupdate(const char **paths,
782 * path anymore, in which case, under 'allow_remove',
783 * or worse yet 'allow_replace', active_nr may decrease.
784 */
785 - save_nr = active_nr;
785 + save_nr = the_index.cache_nr;
786 path = xstrdup(ce->name);
787 update_one(path);
788 free(path);
789 discard_cache_entry(old);
790 - if (save_nr != active_nr)
790 + if (save_nr != the_index.cache_nr)
791 goto redo;
792 }
793 clear_pathspec(&pathspec);
@@ -813,7 +813,7 @@ static int refresh(struct refresh_params *o, unsigned int flag)
813 * refresh_cache() as these are no actual errors.
814 * cmd_status() does the same.
815 */
816 - active_cache_changed |= SOMETHING_CHANGED;
816 + the_index.cache_changed |= SOMETHING_CHANGED;
817 }
818 return 0;
819 }
@@ -951,7 +951,7 @@ static enum parse_opt_result unresolve_callback(
951 *has_errors = do_unresolve(ctx->argc, ctx->argv,
952 prefix, prefix ? strlen(prefix) : 0);
953 if (*has_errors)
954 - active_cache_changed = 0;
954 + the_index.cache_changed = 0;
955
956 ctx->argv += ctx->argc - 1;
957 ctx->argc = 1;
@@ -972,7 +972,7 @@ static enum parse_opt_result reupdate_callback(
972 setup_work_tree();
973 *has_errors = do_reupdate(ctx->argv + 1, prefix);
974 if (*has_errors)
975 - active_cache_changed = 0;
975 + the_index.cache_changed = 0;
976
977 ctx->argv += ctx->argc - 1;
978 ctx->argc = 1;
@@ -1178,7 +1178,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
1178 INDEX_FORMAT_LB, INDEX_FORMAT_UB);
1179
1180 if (the_index.version != preferred_index_format)
1181 - active_cache_changed |= SOMETHING_CHANGED;
1181 + the_index.cache_changed |= SOMETHING_CHANGED;
1182 the_index.version = preferred_index_format;
1183 }
1184
@@ -1290,7 +1290,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
1290 report(_("fsmonitor disabled"));
1291 }
1292
1293 - if (active_cache_changed || force_write) {
1293 + if (the_index.cache_changed || force_write) {
1294 if (newfd < 0) {
1295 if (refresh_args.flags & REFRESH_QUIET)
1296 exit(128);
cache.h
-3
@@ -436,10 +436,7 @@ void prefetch_cache_entries(const struct index_state *istate,
436 #ifdef USE_THE_INDEX_COMPATIBILITY_MACROS
437 extern struct index_state the_index;
438
439 -#define active_cache (the_index.cache)
439 #define active_nr (the_index.cache_nr)
441 -#define active_cache_changed (the_index.cache_changed)
442 -#define active_cache_tree (the_index.cache_tree)
440
441 #define read_cache() repo_read_index(the_repository)
442 #define read_cache_from(path) read_index_from(&the_index, (path), (get_git_dir()))
contrib/coccinelle/index-compatibility.cocci
+22
@@ -1,3 +1,25 @@
1 +// the_index.* variables
2 +@@
3 +@@
4 +(
5 +- active_cache
6 ++ the_index.cache
7 +|
8 +- active_cache_changed
9 ++ the_index.cache_changed
10 +|
11 +- active_cache_tree
12 ++ the_index.cache_tree
13 +)
14 +
15 +@@
16 +identifier f != prepare_to_commit;
17 +@@
18 + f(...) {<...
19 +- active_nr
20 ++ the_index.cache_nr
21 + ...>}
22 +
23 // "the_repository" simple cases
24 @@
25 @@
contrib/coccinelle/index-compatibility.pending.cocci
-17
@@ -1,20 +1,3 @@
1 -// the_index.* variables
2 -@@
3 -@@
4 -(
5 -- active_cache
6 -+ the_index.cache
7 -|
8 -- active_nr
9 -+ the_index.cache_nr
10 -|
11 -- active_cache_changed
12 -+ the_index.cache_changed
13 -|
14 -- active_cache_tree
15 -+ the_index.cache_tree
16 -)
17 -
1 // "the_repository" simple cases
2 @@
3 @@
t/helper/test-dump-cache-tree.c
+1 -1
@@ -67,7 +67,7 @@ int cmd__dump_cache_tree(int ac, const char **av)
67 istate = the_index;
68 istate.cache_tree = another;
69 cache_tree_update(&istate, WRITE_TREE_DRY_RUN);
70 - ret = dump_cache_tree(active_cache_tree, another, "");
70 + ret = dump_cache_tree(the_index.cache_tree, another, "");
71 cache_tree_free(&another);
72
73 return ret;
t/helper/test-scrap-cache-tree.c
+2 -2
@@ -12,8 +12,8 @@ int cmd__scrap_cache_tree(int ac, const char **av)
12 hold_locked_index(&index_lock, LOCK_DIE_ON_ERROR);
13 if (read_cache() < 0)
14 die("unable to read index file");
15 - cache_tree_free(&active_cache_tree);
16 - active_cache_tree = NULL;
15 + cache_tree_free(&the_index.cache_tree);
16 + the_index.cache_tree = NULL;
17 if (write_locked_index(&the_index, &index_lock, COMMIT_LOCK))
18 die("unable to write index file");
19 return 0;