cocci & cache.h: remove "USE_THE_INDEX_COMPATIBILITY_MACROS"

Have the last users of "USE_THE_INDEX_COMPATIBILITY_MACROS" use the underlying *_index() variants instead. Now all previous users of "USE_THE_INDEX_COMPATIBILITY_MACROS" have been migrated away from the wrapper macros, and if applicable to use the "USE_THE_INDEX_VARIABLE" added in [1]. Let's leave the "index-compatibility.cocci" in place, even though it won't be doing anything on "master". It will benefit any out-of-tree code that need to use these compatibility macros. We can eventually remove it. 1. bdafeae0b9c (cache.h & test-tool.h: add & use "USE_THE_INDEX_VARIABLE", 2022-11-19) Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Feb 10, 2023 at 11:28 UTC dfd0a89374c6eba332dfa3f5670a29eaf96efa3b
5 files changed +13 -35
builtin/commit.c
+3 -3
@@ -5,7 +5,7 @@
5 * Based on git-commit.sh by Junio C Hamano and Linus Torvalds
6 */
7
8 -#define USE_THE_INDEX_COMPATIBILITY_MACROS
8 +#define USE_THE_INDEX_VARIABLE
9 #include "cache.h"
10 #include "config.h"
11 #include "lockfile.h"
@@ -992,8 +992,8 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
992 const char *parent = "HEAD";
993
994 if (!the_index.cache_nr) {
995 - discard_cache();
996 - if (read_cache() < 0)
995 + discard_index(&the_index);
996 + if (repo_read_index(the_repository) < 0)
997 die(_("Cannot read index"));
998 }
999
builtin/merge.c
+3 -3
@@ -6,7 +6,7 @@
6 * Based on git-merge.sh by Junio C Hamano.
7 */
8
9 -#define USE_THE_INDEX_COMPATIBILITY_MACROS
9 +#define USE_THE_INDEX_VARIABLE
10 #include "cache.h"
11 #include "config.h"
12 #include "parse-options.h"
@@ -390,8 +390,8 @@ static void restore_state(const struct object_id *head,
390 run_command(&cmd);
391
392 refresh_cache:
393 - discard_cache();
394 - if (read_cache() < 0)
393 + discard_index(&the_index);
394 + if (repo_read_index(the_repository) < 0)
395 die(_("could not read index"));
396 }
397
cache.h
+1 -8
@@ -449,15 +449,8 @@ typedef int (*must_prefetch_predicate)(const struct cache_entry *);
449 void prefetch_cache_entries(const struct index_state *istate,
450 must_prefetch_predicate must_prefetch);
451
452 -#if defined(USE_THE_INDEX_COMPATIBILITY_MACROS) || defined(USE_THE_INDEX_VARIABLE)
452 +#ifdef USE_THE_INDEX_VARIABLE
453 extern struct index_state the_index;
454 -
455 -#ifndef USE_THE_INDEX_VARIABLE
456 -#ifdef USE_THE_INDEX_COMPATIBILITY_MACROS
457 -#define read_cache() repo_read_index(the_repository)
458 -#define discard_cache() discard_index(&the_index)
459 -#endif
460 -#endif
454 #endif
455
456 #define TYPE_BITS 3
contrib/coccinelle/index-compatibility.cocci
+6
@@ -23,6 +23,9 @@ identifier ACT = active_cache_tree;
23 @@
24 @@
25 (
26 +- read_cache
27 ++ repo_read_index
28 +|
29 - read_cache_unmerged
30 + repo_read_index_unmerged
31 |
@@ -97,6 +100,9 @@ identifier ACT = active_cache_tree;
100 |
101 - update_main_cache_tree
102 + cache_tree_update
103 +|
104 +- discard_cache
105 ++ discard_index
106 )
107 (
108 + &the_index,
contrib/coccinelle/index-compatibility.pending.cocci deleted
-21
@@ -1,21 +0,0 @@
1 -// "the_repository" simple cases
2 -@@
3 -@@
4 -(
5 -- read_cache
6 -+ repo_read_index
7 -)
8 - (
9 -+ the_repository,
10 - ...)
11 -
12 -// "the_index" simple cases
13 -@@
14 -@@
15 -(
16 -- discard_cache
17 -+ discard_index
18 -)
19 - (
20 -+ &the_index,
21 - ...)