git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 09/11] {builtin/*,repository}.c: add & use "USE_THE_INDEX_VARIABLE"

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Nov 19, 2022, 13:07 UTC
Message-ID
<patch-v2-09.11-429eecc78ec-20221119T125551Z-avarab@gmail.com>
In-Reply-To
<cover-v2-00.11-00000000000-20221119T125550Z-avarab@gmail.com>

Split up the "USE_THE_INDEX_COMPATIBILITY_MACROS" into that setting and a more narrow "USE_THE_INDEX_VARIABLE". In the case of these built-ins we only need "the_index" variable, but not the compatibility wrapper for functions we're not using.

Let's then have some users of "USE_THE_INDEX_COMPATIBILITY_MACROS" use this more narrow and descriptive define.

For context: The USE_THE_INDEX_COMPATIBILITY_MACROS macro was added to test-tool.h in f8adbec9fea (cache.h: flip NO_THE_INDEX_COMPATIBILITY_MACROS switch, 2019-01-24).

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 builtin/cat-file.c   | 2 +-
 builtin/difftool.c   | 2 +-
 builtin/merge-tree.c | 2 +-
 builtin/pull.c       | 2 +-
 cache.h              | 6 +++++-
 repository.c         | 2 +-
 6 files changed, 10 insertions(+), 6 deletions(-)
diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index fa7bd891692..b3be58b1fb0 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -3,7 +3,7 @@
  *
  * Copyright (C) Linus Torvalds, 2005
  */
-#define USE_THE_INDEX_COMPATIBILITY_MACROS
+#define USE_THE_INDEX_VARIABLE
 #include "cache.h"
 #include "config.h"
 #include "builtin.h"
diff --git a/builtin/difftool.c b/builtin/difftool.c
index d7f08c8a7fa..d9b76226f6a 100644
--- a/builtin/difftool.c
+++ b/builtin/difftool.c
@@ -11,7 +11,7 @@
  *
  * Copyright (C) 2016 Johannes Schindelin
  */
-#define USE_THE_INDEX_COMPATIBILITY_MACROS
+#define USE_THE_INDEX_VARIABLE
 #include "cache.h"
 #include "config.h"
 #include "builtin.h"
diff --git a/builtin/merge-tree.c b/builtin/merge-tree.c
index fe853aa8f91..e3767087bbf 100644
--- a/builtin/merge-tree.c
+++ b/builtin/merge-tree.c
@@ -1,4 +1,4 @@
-#define USE_THE_INDEX_COMPATIBILITY_MACROS
+#define USE_THE_INDEX_VARIABLE
 #include "builtin.h"
 #include "tree-walk.h"
 #include "xdiff-interface.h"
diff --git a/builtin/pull.c b/builtin/pull.c
index 4a2a6db2dce..1ab4de0005d 100644
--- a/builtin/pull.c
+++ b/builtin/pull.c
@@ -5,7 +5,7 @@
  *
  * Fetch one or more remote refs and merge it/them into the current HEAD.
  */
-#define USE_THE_INDEX_COMPATIBILITY_MACROS
+#define USE_THE_INDEX_VARIABLE
 #include "cache.h"
 #include "config.h"
 #include "builtin.h"
diff --git a/cache.h b/cache.h
index 805e25f9a67..707806d2125 100644
--- a/cache.h
+++ b/cache.h
@@ -433,9 +433,11 @@ typedef int (*must_prefetch_predicate)(const struct cache_entry *);
 void prefetch_cache_entries(const struct index_state *istate,
 			    must_prefetch_predicate must_prefetch);
 
-#ifdef USE_THE_INDEX_COMPATIBILITY_MACROS
+#if defined(USE_THE_INDEX_COMPATIBILITY_MACROS) || defined(USE_THE_INDEX_VARIABLE)
 extern struct index_state the_index;
 
+#ifndef USE_THE_INDEX_VARIABLE
+#ifdef USE_THE_INDEX_COMPATIBILITY_MACROS
 #define active_nr (the_index.cache_nr)
 
 #define read_cache() repo_read_index(the_repository)
@@ -447,6 +449,8 @@ extern struct index_state the_index;
 #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)
 #define hold_locked_index(lock_file, flags) repo_hold_locked_index(the_repository, (lock_file), (flags))
 #endif
+#endif
+#endif
 
 #define TYPE_BITS 3
 
diff --git a/repository.c b/repository.c
index 5d166b692c8..3427085fd6d 100644
--- a/repository.c
+++ b/repository.c
@@ -2,7 +2,7 @@
  * not really _using_ the compat macros, just make sure the_index
  * declaration matches the definition in this file.
  */
-#define USE_THE_INDEX_COMPATIBILITY_MACROS
+#define USE_THE_INDEX_VARIABLE
 #include "cache.h"
 #include "repository.h"
 #include "object-store.h"
-- 
2.38.0.1509.g9445af83948
Previous: Ævar Arnfjörð BjarmasonNext: Ævar Arnfjörð Bjarmason
Message 30 of 32 in “tree-wide: chip away at USE_THE_INDEX_COMPATIBILITY_MACROS”
  1. 00/12 tree-wide: chip away at USE_THE_INDEX_COMPATIBILITY_MACROSÆvar Arnfjörð Bjarmason, Nov 18, 2022
  2. 01/12 cache.h: remove unused "the_index" compat macrosÆvar Arnfjörð Bjarmason, Nov 18, 2022
  3. 02/12 builtin/{grep,log}.: don't define "USE_THE_INDEX_COMPATIBILITY_MACROS"Ævar Arnfjörð Bjarmason, Nov 18, 2022
  4. 03/12 cocci & cache.h: remove rarely used "the_index" compat macrosÆvar Arnfjörð Bjarmason, Nov 18, 2022
  5. 04/12 read-cache API & users: make discard_index() return voidÆvar Arnfjörð Bjarmason, Nov 18, 2022
  6. 05/12 cocci: add a index-compatibility.pending.cocciÆvar Arnfjörð Bjarmason, Nov 18, 2022
  7. 06/12 cocci & cache.h: apply a selection of "pending" index-compatibilityÆvar Arnfjörð Bjarmason, Nov 18, 2022
  8. 07/12 cocci & cache.h: apply variable section of "pending" index-compatibilityÆvar Arnfjörð Bjarmason, Nov 18, 2022
  9. 08/12 cocci: apply "pending" index-compatibility to "t/helper/*.c"Ævar Arnfjörð Bjarmason, Nov 18, 2022
  10. 09/12 {builtin/*,repository}.c: add & use "USE_THE_INDEX_VARIABLE"Ævar Arnfjörð Bjarmason, Nov 18, 2022
  11. Taylor BlauNov 18, 2022
  12. 10/12 cache.h & test-tool.h: add & use "USE_THE_INDEX_VARIABLE"Ævar Arnfjörð Bjarmason, Nov 18, 2022
  13. Taylor BlauNov 18, 2022
  14. 12/12 builtin/*: remove or amend "USE_THE_INDEX_COMPATIBILITY_MACROS"Ævar Arnfjörð Bjarmason, Nov 18, 2022
  15. Taylor BlauNov 18, 2022
  16. Ævar Arnfjörð BjarmasonNov 18, 2022
  17. Taylor BlauNov 18, 2022
  18. 11/12 cocci: apply "pending" index-compatibility to some "builtin/*.c"Ævar Arnfjörð Bjarmason, Nov 18, 2022
  19. Phillip WoodNov 18, 2022
  20. Ævar Arnfjörð BjarmasonNov 18, 2022
  21. 00/11 tree-wide: chip away at USE_THE_INDEX_COMPATIBILITY_MACROSÆvar Arnfjörð Bjarmason, Nov 19, 2022
  22. 01/11 cache.h: remove unused "the_index" compat macrosÆvar Arnfjörð Bjarmason, Nov 19, 2022
  23. 02/11 builtin/{grep,log}.: don't define "USE_THE_INDEX_COMPATIBILITY_MACROS"Ævar Arnfjörð Bjarmason, Nov 19, 2022
  24. 03/11 cocci & cache.h: remove rarely used "the_index" compat macrosÆvar Arnfjörð Bjarmason, Nov 19, 2022
  25. 04/11 read-cache API & users: make discard_index() return voidÆvar Arnfjörð Bjarmason, Nov 19, 2022
  26. 05/11 cocci: add a index-compatibility.pending.cocciÆvar Arnfjörð Bjarmason, Nov 19, 2022
  27. 06/11 cocci & cache.h: apply a selection of "pending" index-compatibilityÆvar Arnfjörð Bjarmason, Nov 19, 2022
  28. 08/11 cocci: apply "pending" index-compatibility to "t/helper/*.c"Ævar Arnfjörð Bjarmason, Nov 19, 2022
  29. 07/11 cocci & cache.h: apply variable section of "pending" index-compatibilityÆvar Arnfjörð Bjarmason, Nov 19, 2022
  30. 09/11 {builtin/*,repository}.c: add & use "USE_THE_INDEX_VARIABLE"Ævar Arnfjörð Bjarmason, Nov 19, 2022
  31. 10/11 cache.h & test-tool.h: add & use "USE_THE_INDEX_VARIABLE"Ævar Arnfjörð Bjarmason, Nov 19, 2022
  32. 11/11 cocci: apply "pending" index-compatibility to some "builtin/*.c"Ævar Arnfjörð Bjarmason, Nov 19, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.