cocci & cache.h: apply a selection of "pending" index-compatibility

Apply a selection of rules in "index-compatibility.pending.cocci" tree-wide, and in doing so migrate them to "index-compatibility.cocci". As in preceding commits the only manual changes here are the macro removals in "cache.h", and the update to the '*.cocci" rules. The rest of the C code changes are the result of applying those updated rules. Move rules for some rarely used cache compatibility macros from "index-compatibility.pending.cocci" to "index-compatibility.cocci" and apply them. 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 031b2033e0b5c6276bbd93f276e1698f925fb498
11 files changed +40 -41
builtin/checkout.c
+3 -2
@@ -160,7 +160,8 @@ static int update_some(const struct object_id *oid, struct strbuf *base,
160 }
161 }
162
163 - add_cache_entry(ce, ADD_CACHE_OK_TO_ADD | ADD_CACHE_OK_TO_REPLACE);
163 + add_index_entry(&the_index, ce,
164 + ADD_CACHE_OK_TO_ADD | ADD_CACHE_OK_TO_REPLACE);
165 return 0;
166 }
167
@@ -744,7 +745,7 @@ static int merge_working_tree(const struct checkout_opts *opts,
745 if (read_cache_preload(NULL) < 0)
746 return error(_("index file corrupt"));
747
747 - resolve_undo_clear();
748 + resolve_undo_clear_index(&the_index);
749 if (opts->new_orphan_branch && opts->orphan_from_empty_tree) {
750 if (new_branch_info->commit)
751 BUG("'switch --orphan' should never accept a commit as starting point");
builtin/commit.c
+1 -1
@@ -305,7 +305,7 @@ static void add_remove_files(struct string_list *list)
305 if (add_to_index(&the_index, p->string, &st, 0))
306 die(_("updating files failed"));
307 } else
308 - remove_file_from_cache(p->string);
308 + remove_file_from_index(&the_index, p->string);
309 }
310 }
311
builtin/merge.c
+1 -1
@@ -1397,7 +1397,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
1397 else
1398 die(_("You have not concluded your cherry-pick (CHERRY_PICK_HEAD exists)."));
1399 }
1400 - resolve_undo_clear();
1400 + resolve_undo_clear_index(&the_index);
1401
1402 if (option_edit < 0)
1403 option_edit = default_edit_option();
builtin/mv.c
+3 -1
@@ -471,7 +471,9 @@ remove_entry:
471 pos = cache_name_pos(src, strlen(src));
472 assert(pos >= 0);
473 if (!(mode & SPARSE) && !lstat(src, &st))
474 - sparse_and_dirty = ce_modified(active_cache[pos], &st, 0);
474 + sparse_and_dirty = ie_modified(&the_index,
475 + active_cache[pos], &st,
476 + 0);
477 rename_index_entry_at(&the_index, pos, dst);
478
479 if (ignore_sparse &&
builtin/read-tree.c
+1 -1
@@ -192,7 +192,7 @@ int cmd_read_tree(int argc, const char **argv, const char *cmd_prefix)
192 die(_("You need to resolve your current index first"));
193 stage = opts.merge = 1;
194 }
195 - resolve_undo_clear();
195 + resolve_undo_clear_index(&the_index);
196
197 for (i = 0; i < argc; i++) {
198 const char *arg = argv[i];
builtin/reset.c
+3 -2
@@ -145,7 +145,7 @@ static void update_index_from_diff(struct diff_queue_struct *q,
145 struct cache_entry *ce;
146
147 if (!is_in_reset_tree && !intent_to_add) {
148 - remove_file_from_cache(one->path);
148 + remove_file_from_index(&the_index, one->path);
149 continue;
150 }
151
@@ -172,7 +172,8 @@ static void update_index_from_diff(struct diff_queue_struct *q,
172 ce->ce_flags |= CE_INTENT_TO_ADD;
173 set_object_name_for_intent_to_add_entry(ce);
174 }
175 - add_cache_entry(ce, ADD_CACHE_OK_TO_ADD | ADD_CACHE_OK_TO_REPLACE);
175 + add_index_entry(&the_index, ce,
176 + ADD_CACHE_OK_TO_ADD | ADD_CACHE_OK_TO_REPLACE);
177 }
178 }
179
builtin/rm.c
+2 -2
@@ -168,7 +168,7 @@ static int check_local_mod(struct object_id *head, int index_only)
168 * Is the index different from the file in the work tree?
169 * If it's a submodule, is its work tree modified?
170 */
171 - if (ce_match_stat(ce, &st, 0) ||
171 + if (ie_match_stat(&the_index, ce, &st, 0) ||
172 (S_ISGITLINK(ce->ce_mode) &&
173 bad_to_remove_submodule(ce->name,
174 SUBMODULE_REMOVAL_DIE_ON_ERROR |
@@ -386,7 +386,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
386 if (!quiet)
387 printf("rm '%s'\n", path);
388
389 - if (remove_file_from_cache(path))
389 + if (remove_file_from_index(&the_index, path))
390 die(_("git rm: unable to remove %s"), path);
391 }
392
builtin/update-index.c
+11 -11
@@ -256,7 +256,7 @@ static int remove_one_path(const char *path)
256 {
257 if (!allow_remove)
258 return error("%s: does not exist and --remove not passed", path);
259 - if (remove_file_from_cache(path))
259 + if (remove_file_from_index(&the_index, path))
260 return error("%s: cannot remove from the index", path);
261 return 0;
262 }
@@ -281,7 +281,7 @@ static int add_one_path(const struct cache_entry *old, const char *path, int len
281 struct cache_entry *ce;
282
283 /* Was the old index entry already up-to-date? */
284 - if (old && !ce_stage(old) && !ce_match_stat(old, st, 0))
284 + if (old && !ce_stage(old) && !ie_match_stat(&the_index, old, st, 0))
285 return 0;
286
287 ce = make_empty_cache_entry(&the_index, len);
@@ -298,7 +298,7 @@ static int add_one_path(const struct cache_entry *old, const char *path, int len
298 }
299 option = allow_add ? ADD_CACHE_OK_TO_ADD : 0;
300 option |= allow_replace ? ADD_CACHE_OK_TO_REPLACE : 0;
301 - if (add_cache_entry(ce, option)) {
301 + if (add_index_entry(&the_index, ce, option)) {
302 discard_cache_entry(ce);
303 return error("%s: cannot add to the index - missing --add option?", path);
304 }
@@ -390,7 +390,7 @@ static int process_path(const char *path, struct stat *st, int stat_errno)
390 * On the other hand, removing it from index should work
391 */
392 if (!ignore_skip_worktree_entries && allow_remove &&
393 - remove_file_from_cache(path))
393 + remove_file_from_index(&the_index, path))
394 return error("%s: cannot remove from the index", path);
395 return 0;
396 }
@@ -429,7 +429,7 @@ static int add_cacheinfo(unsigned int mode, const struct object_id *oid,
429 ce->ce_flags |= CE_VALID;
430 option = allow_add ? ADD_CACHE_OK_TO_ADD : 0;
431 option |= allow_replace ? ADD_CACHE_OK_TO_REPLACE : 0;
432 - if (add_cache_entry(ce, option))
432 + if (add_index_entry(&the_index, ce, option))
433 return error("%s: cannot add to the index - missing --add option?",
434 path);
435 report("add '%s'", path);
@@ -488,7 +488,7 @@ static void update_one(const char *path)
488 }
489
490 if (force_remove) {
491 - if (remove_file_from_cache(path))
491 + if (remove_file_from_index(&the_index, path))
492 die("git update-index: unable to remove %s", path);
493 report("remove '%s'", path);
494 return;
@@ -571,7 +571,7 @@ static void read_index_info(int nul_term_line)
571
572 if (!mode) {
573 /* mode == 0 means there is no such path -- remove */
574 - if (remove_file_from_cache(path_name))
574 + if (remove_file_from_index(&the_index, path_name))
575 die("git update-index: unable to remove %s",
576 ptr);
577 }
@@ -686,13 +686,13 @@ static int unresolve_one(const char *path)
686 goto free_return;
687 }
688
689 - remove_file_from_cache(path);
690 - if (add_cache_entry(ce_2, ADD_CACHE_OK_TO_ADD)) {
689 + remove_file_from_index(&the_index, path);
690 + if (add_index_entry(&the_index, ce_2, ADD_CACHE_OK_TO_ADD)) {
691 error("%s: cannot add our version to the index.", path);
692 ret = -1;
693 goto free_return;
694 }
695 - if (!add_cache_entry(ce_3, ADD_CACHE_OK_TO_ADD))
695 + if (!add_index_entry(&the_index, ce_3, ADD_CACHE_OK_TO_ADD))
696 return 0;
697 error("%s: cannot add their version to the index.", path);
698 ret = -1;
@@ -850,7 +850,7 @@ static int resolve_undo_clear_callback(const struct option *opt,
850 {
851 BUG_ON_OPT_NEG(unset);
852 BUG_ON_OPT_ARG(arg);
853 - resolve_undo_clear();
853 + resolve_undo_clear_index(&the_index);
854 return 0;
855 }
856
cache.h
-5
@@ -446,13 +446,8 @@ extern struct index_state the_index;
446 #define read_cache_preload(pathspec) repo_read_index_preload(the_repository, (pathspec), 0)
447 #define discard_cache() discard_index(&the_index)
448 #define cache_name_pos(name, namelen) index_name_pos(&the_index,(name),(namelen))
449 -#define add_cache_entry(ce, option) add_index_entry(&the_index, (ce), (option))
450 -#define remove_file_from_cache(path) remove_file_from_index(&the_index, (path))
449 #define refresh_cache(flags) refresh_index(&the_index, (flags), NULL, NULL, NULL)
450 #define refresh_and_write_cache(refresh_flags, write_flags, gentle) repo_refresh_and_write_index(the_repository, (refresh_flags), (write_flags), (gentle), NULL, NULL, NULL)
453 -#define ce_match_stat(ce, st, options) ie_match_stat(&the_index, (ce), (st), (options))
454 -#define ce_modified(ce, st, options) ie_modified(&the_index, (ce), (st), (options))
455 -#define resolve_undo_clear() resolve_undo_clear_index(&the_index)
451 #define hold_locked_index(lock_file, flags) repo_hold_locked_index(the_repository, (lock_file), (flags))
452 #endif
453
contrib/coccinelle/index-compatibility.cocci
+15
@@ -39,6 +39,21 @@
39 |
40 - add_file_to_cache
41 + add_file_to_index
42 +|
43 +- add_cache_entry
44 ++ add_index_entry
45 +|
46 +- remove_file_from_cache
47 ++ remove_file_from_index
48 +|
49 +- ce_match_stat
50 ++ ie_match_stat
51 +|
52 +- ce_modified
53 ++ ie_modified
54 +|
55 +- resolve_undo_clear
56 ++ resolve_undo_clear_index
57 )
58 (
59 + &the_index,
contrib/coccinelle/index-compatibility.pending.cocci
-15
@@ -38,21 +38,6 @@
38 |
39 - cache_name_pos
40 + index_name_pos
41 -|
42 -- add_cache_entry
43 -+ add_index_entry
44 -|
45 -- remove_file_from_cache
46 -+ remove_file_from_index
47 -|
48 -- ce_match_stat
49 -+ ie_match_stat
50 -|
51 -- ce_modified
52 -+ ie_modified
53 -|
54 -- resolve_undo_clear
55 -+ resolve_undo_clear_index
41 )
42 (
43 + &the_index,