cache.h: flip NO_THE_INDEX_COMPATIBILITY_MACROS switch

By default, index compat macros are off from now on, because they could hide the_index dependency. Only those in builtin can use it. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nguyễn Thái Ngọc Duy committed Jan 24, 2019 at 15:29 UTC f8adbec9feaa7a1ab9814db1115826e87033712e
55 files changed +58 -24
attr.c
-1
@@ -7,7 +7,6 @@
7 * an insanely large number of attributes.
8 */
9
10 -#define NO_THE_INDEX_COMPATIBILITY_MACROS
10 #include "cache.h"
11 #include "config.h"
12 #include "exec-cmd.h"
builtin/add.c
+1
@@ -3,6 +3,7 @@
3 *
4 * Copyright (C) 2006 Linus Torvalds
5 */
6 +#define USE_THE_INDEX_COMPATIBILITY_MACROS
7 #include "cache.h"
8 #include "config.h"
9 #include "builtin.h"
builtin/am.c
+1
@@ -3,6 +3,7 @@
3 *
4 * Based on git-am.sh by Junio C Hamano.
5 */
6 +#define USE_THE_INDEX_COMPATIBILITY_MACROS
7 #include "cache.h"
8 #include "config.h"
9 #include "builtin.h"
builtin/blame.c
+2 -1
@@ -1007,7 +1007,8 @@ parse_done:
1007 long bottom, top;
1008 if (parse_range_arg(range_list.items[range_i].string,
1009 nth_line_cb, &sb, lno, anchor,
1010 - &bottom, &top, sb.path, &the_index))
1010 + &bottom, &top, sb.path,
1011 + the_repository->index))
1012 usage(blame_usage);
1013 if ((!lno && (top || bottom)) || lno < bottom)
1014 die(Q_("file %s has only %lu line",
builtin/cat-file.c
+1
@@ -3,6 +3,7 @@
3 *
4 * Copyright (C) Linus Torvalds, 2005
5 */
6 +#define USE_THE_INDEX_COMPATIBILITY_MACROS
7 #include "cache.h"
8 #include "config.h"
9 #include "builtin.h"
builtin/check-attr.c
+1
@@ -1,3 +1,4 @@
1 +#define USE_THE_INDEX_COMPATIBILITY_MACROS
2 #include "builtin.h"
3 #include "cache.h"
4 #include "config.h"
builtin/check-ignore.c
+1
@@ -1,3 +1,4 @@
1 +#define USE_THE_INDEX_COMPATIBILITY_MACROS
2 #include "builtin.h"
3 #include "cache.h"
4 #include "config.h"
builtin/checkout-index.c
+1
@@ -4,6 +4,7 @@
4 * Copyright (C) 2005 Linus Torvalds
5 *
6 */
7 +#define USE_THE_INDEX_COMPATIBILITY_MACROS
8 #include "builtin.h"
9 #include "config.h"
10 #include "lockfile.h"
builtin/checkout.c
+1
@@ -1,3 +1,4 @@
1 +#define USE_THE_INDEX_COMPATIBILITY_MACROS
2 #include "builtin.h"
3 #include "config.h"
4 #include "checkout.h"
builtin/clean.c
+1
@@ -6,6 +6,7 @@
6 * Based on git-clean.sh by Pavel Roskin
7 */
8
9 +#define USE_THE_INDEX_COMPATIBILITY_MACROS
10 #include "builtin.h"
11 #include "cache.h"
12 #include "config.h"
builtin/clone.c
+1
@@ -8,6 +8,7 @@
8 * Clone a repository into a different directory that does not yet exist.
9 */
10
11 +#define USE_THE_INDEX_COMPATIBILITY_MACROS
12 #include "builtin.h"
13 #include "config.h"
14 #include "lockfile.h"
builtin/commit.c
+1
@@ -5,6 +5,7 @@
5 * Based on git-commit.sh by Junio C Hamano and Linus Torvalds
6 */
7
8 +#define USE_THE_INDEX_COMPATIBILITY_MACROS
9 #include "cache.h"
10 #include "config.h"
11 #include "lockfile.h"
builtin/describe.c
+1
@@ -1,3 +1,4 @@
1 +#define USE_THE_INDEX_COMPATIBILITY_MACROS
2 #include "cache.h"
3 #include "config.h"
4 #include "lockfile.h"
builtin/diff-files.c
+1
@@ -3,6 +3,7 @@
3 *
4 * Copyright (C) Linus Torvalds, 2005
5 */
6 +#define USE_THE_INDEX_COMPATIBILITY_MACROS
7 #include "cache.h"
8 #include "config.h"
9 #include "diff.h"
builtin/diff-index.c
+1
@@ -1,3 +1,4 @@
1 +#define USE_THE_INDEX_COMPATIBILITY_MACROS
2 #include "cache.h"
3 #include "config.h"
4 #include "diff.h"
builtin/diff-tree.c
+1
@@ -1,3 +1,4 @@
1 +#define USE_THE_INDEX_COMPATIBILITY_MACROS
2 #include "cache.h"
3 #include "config.h"
4 #include "diff.h"
builtin/diff.c
+1
@@ -3,6 +3,7 @@
3 *
4 * Copyright (c) 2006 Junio C Hamano
5 */
6 +#define USE_THE_INDEX_COMPATIBILITY_MACROS
7 #include "cache.h"
8 #include "config.h"
9 #include "lockfile.h"
builtin/difftool.c
+1
@@ -11,6 +11,7 @@
11 *
12 * Copyright (C) 2016 Johannes Schindelin
13 */
14 +#define USE_THE_INDEX_COMPATIBILITY_MACROS
15 #include "cache.h"
16 #include "config.h"
17 #include "builtin.h"
builtin/fsck.c
+1
@@ -1,3 +1,4 @@
1 +#define USE_THE_INDEX_COMPATIBILITY_MACROS
2 #include "builtin.h"
3 #include "cache.h"
4 #include "repository.h"
builtin/grep.c
+1
@@ -3,6 +3,7 @@
3 *
4 * Copyright (c) 2006 Junio C Hamano
5 */
6 +#define USE_THE_INDEX_COMPATIBILITY_MACROS
7 #include "cache.h"
8 #include "repository.h"
9 #include "config.h"
builtin/hash-object.c
+2 -1
@@ -40,7 +40,8 @@ static void hash_fd(int fd, const char *type, const char *path, unsigned flags,
40 if (fstat(fd, &st) < 0 ||
41 (literally
42 ? hash_literally(&oid, fd, type, flags)
43 - : index_fd(&the_index, &oid, fd, &st, type_from_string(type), path, flags)))
43 + : index_fd(the_repository->index, &oid, fd, &st,
44 + type_from_string(type), path, flags)))
45 die((flags & HASH_WRITE_OBJECT)
46 ? "Unable to add %s to database"
47 : "Unable to hash %s", path);
builtin/log.c
+1
@@ -4,6 +4,7 @@
4 * (C) Copyright 2006 Linus Torvalds
5 * 2006 Junio Hamano
6 */
7 +#define USE_THE_INDEX_COMPATIBILITY_MACROS
8 #include "cache.h"
9 #include "config.h"
10 #include "refs.h"
builtin/ls-files.c
-1
@@ -5,7 +5,6 @@
5 *
6 * Copyright (C) Linus Torvalds, 2005
7 */
8 -#define NO_THE_INDEX_COMPATIBILITY_MACROS
8 #include "cache.h"
9 #include "repository.h"
10 #include "config.h"
builtin/merge-index.c
+1
@@ -1,3 +1,4 @@
1 +#define USE_THE_INDEX_COMPATIBILITY_MACROS
2 #include "builtin.h"
3 #include "run-command.h"
4
builtin/merge-ours.c
+1
@@ -7,6 +7,7 @@
7 *
8 * Pretend we resolved the heads, but declare our tree trumps everybody else.
9 */
10 +#define USE_THE_INDEX_COMPATIBILITY_MACROS
11 #include "git-compat-util.h"
12 #include "builtin.h"
13 #include "diff.h"
builtin/merge-tree.c
+3 -1
@@ -1,3 +1,4 @@
1 +#define USE_THE_INDEX_COMPATIBILITY_MACROS
2 #include "builtin.h"
3 #include "tree-walk.h"
4 #include "xdiff-interface.h"
@@ -76,7 +77,8 @@ static void *result(struct merge_list *entry, unsigned long *size)
77 their = NULL;
78 if (entry)
79 their = entry->blob;
79 - return merge_blobs(&the_index, path, base, our, their, size);
80 + return merge_blobs(the_repository->index, path,
81 + base, our, their, size);
82 }
83
84 static void *origin(struct merge_list *entry, unsigned long *size)
builtin/merge.c
+1
@@ -6,6 +6,7 @@
6 * Based on git-merge.sh by Junio C Hamano.
7 */
8
9 +#define USE_THE_INDEX_COMPATIBILITY_MACROS
10 #include "cache.h"
11 #include "config.h"
12 #include "parse-options.h"
builtin/mv.c
+1
@@ -3,6 +3,7 @@
3 *
4 * Copyright (C) 2006 Johannes Schindelin
5 */
6 +#define USE_THE_INDEX_COMPATIBILITY_MACROS
7 #include "builtin.h"
8 #include "config.h"
9 #include "pathspec.h"
builtin/pack-objects.c
+1 -1
@@ -970,7 +970,7 @@ static int no_try_delta(const char *path)
970
971 if (!check)
972 check = attr_check_initl("delta", NULL);
973 - git_check_attr(&the_index, path, check);
973 + git_check_attr(the_repository->index, path, check);
974 if (ATTR_FALSE(check->items[0].value))
975 return 1;
976 return 0;
builtin/pull.c
+1
@@ -5,6 +5,7 @@
5 *
6 * Fetch one or more remote refs and merge it/them into the current HEAD.
7 */
8 +#define USE_THE_INDEX_COMPATIBILITY_MACROS
9 #include "cache.h"
10 #include "config.h"
11 #include "builtin.h"
builtin/read-tree.c
+1
@@ -4,6 +4,7 @@
4 * Copyright (C) Linus Torvalds, 2005
5 */
6
7 +#define USE_THE_INDEX_COMPATIBILITY_MACROS
8 #include "cache.h"
9 #include "config.h"
10 #include "lockfile.h"
builtin/rebase--interactive.c
+1
@@ -1,3 +1,4 @@
1 +#define USE_THE_INDEX_COMPATIBILITY_MACROS
2 #include "builtin.h"
3 #include "cache.h"
4 #include "config.h"
builtin/rebase.c
+1
@@ -4,6 +4,7 @@
4 * Copyright (c) 2018 Pratik Karki
5 */
6
7 +#define USE_THE_INDEX_COMPATIBILITY_MACROS
8 #include "builtin.h"
9 #include "run-command.h"
10 #include "exec-cmd.h"
builtin/replace.c
+1 -1
@@ -295,7 +295,7 @@ static int import_object(struct object_id *oid, enum object_type type,
295 close(fd);
296 return -1;
297 }
298 - if (index_fd(&the_index, oid, fd, &st, type, NULL, flags) < 0)
298 + if (index_fd(the_repository->index, oid, fd, &st, type, NULL, flags) < 0)
299 return error(_("unable to write object to database"));
300 /* index_fd close()s fd for us */
301 }
builtin/reset.c
+1
@@ -7,6 +7,7 @@
7 *
8 * Copyright (c) 2005, 2006 Linus Torvalds and Junio C Hamano
9 */
10 +#define USE_THE_INDEX_COMPATIBILITY_MACROS
11 #include "builtin.h"
12 #include "config.h"
13 #include "lockfile.h"
builtin/rev-parse.c
+1
@@ -3,6 +3,7 @@
3 *
4 * Copyright (C) Linus Torvalds, 2005
5 */
6 +#define USE_THE_INDEX_COMPATIBILITY_MACROS
7 #include "cache.h"
8 #include "config.h"
9 #include "commit.h"
builtin/rm.c
+1
@@ -3,6 +3,7 @@
3 *
4 * Copyright (C) Linus Torvalds 2006
5 */
6 +#define USE_THE_INDEX_COMPATIBILITY_MACROS
7 #include "builtin.h"
8 #include "config.h"
9 #include "lockfile.h"
builtin/submodule--helper.c
+1
@@ -1,3 +1,4 @@
1 +#define USE_THE_INDEX_COMPATIBILITY_MACROS
2 #include "builtin.h"
3 #include "repository.h"
4 #include "cache.h"
builtin/update-index.c
+1
@@ -3,6 +3,7 @@
3 *
4 * Copyright (C) Linus Torvalds, 2005
5 */
6 +#define USE_THE_INDEX_COMPATIBILITY_MACROS
7 #include "cache.h"
8 #include "config.h"
9 #include "lockfile.h"
builtin/write-tree.c
+1
@@ -3,6 +3,7 @@
3 *
4 * Copyright (C) Linus Torvalds, 2005
5 */
6 +#define USE_THE_INDEX_COMPATIBILITY_MACROS
7 #include "builtin.h"
8 #include "cache.h"
9 #include "config.h"
cache-tree.h
+1 -1
@@ -51,7 +51,7 @@ void prime_cache_tree(struct repository *, struct index_state *, struct tree *);
51
52 int cache_tree_matches_traversal(struct cache_tree *, struct name_entry *ent, struct traverse_info *info);
53
54 -#ifndef NO_THE_INDEX_COMPATIBILITY_MACROS
54 +#ifdef USE_THE_INDEX_COMPATIBILITY_MACROS
55 static inline int write_cache_as_tree(struct object_id *oid, int flags, const char *prefix)
56 {
57 return write_index_as_tree(oid, &the_index, get_index_file(), flags, prefix);
cache.h
+3 -3
@@ -338,8 +338,6 @@ struct index_state {
338 struct mem_pool *ce_mem_pool;
339 };
340
341 -extern struct index_state the_index;
342 -
341 /* Name hashing */
342 extern int test_lazy_init_name_hash(struct index_state *istate, int try_threaded);
343 extern void add_name_hash(struct index_state *istate, struct cache_entry *ce);
@@ -401,7 +399,9 @@ struct cache_entry *dup_cache_entry(const struct cache_entry *ce, struct index_s
399 */
400 void validate_cache_entries(const struct index_state *istate);
401
404 -#ifndef NO_THE_INDEX_COMPATIBILITY_MACROS
402 +#ifdef USE_THE_INDEX_COMPATIBILITY_MACROS
403 +extern struct index_state the_index;
404 +
405 #define active_cache (the_index.cache)
406 #define active_nr (the_index.cache_nr)
407 #define active_alloc (the_index.cache_alloc)
convert.c
-1
@@ -1,4 +1,3 @@
1 -#define NO_THE_INDEX_COMPATIBILITY_MACROS
1 #include "cache.h"
2 #include "config.h"
3 #include "object-store.h"
dir.c
-1
@@ -7,7 +7,6 @@
7 * Copyright (C) Linus Torvalds, 2005-2006
8 * Junio Hamano, 2005-2006
9 */
10 -#define NO_THE_INDEX_COMPATIBILITY_MACROS
10 #include "cache.h"
11 #include "config.h"
12 #include "dir.h"
git.c
+2 -2
@@ -417,9 +417,9 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
417
418 trace_argv_printf(argv, "trace: built-in: git");
419
420 - validate_cache_entries(&the_index);
420 + validate_cache_entries(the_repository->index);
421 status = p->fn(argc, argv, prefix);
422 - validate_cache_entries(&the_index);
422 + validate_cache_entries(the_repository->index);
423
424 if (status)
425 return status;
name-hash.c
-1
@@ -5,7 +5,6 @@
5 *
6 * Copyright (C) 2008 Linus Torvalds
7 */
8 -#define NO_THE_INDEX_COMPATIBILITY_MACROS
8 #include "cache.h"
9 #include "thread-utils.h"
10
pathspec.c
-1
@@ -1,4 +1,3 @@
1 -#define NO_THE_INDEX_COMPATIBILITY_MACROS
1 #include "cache.h"
2 #include "config.h"
3 #include "dir.h"
read-cache.c
-2
@@ -3,7 +3,6 @@
3 *
4 * Copyright (C) Linus Torvalds, 2005
5 */
6 -#define NO_THE_INDEX_COMPATIBILITY_MACROS
6 #include "cache.h"
7 #include "config.h"
8 #include "diff.h"
@@ -95,7 +94,6 @@ static struct mem_pool *find_mem_pool(struct index_state *istate)
94 return *pool_ptr;
95 }
96
98 -struct index_state the_index;
97 static const char *alternate_index_output;
98
99 static void set_index_entry(struct index_state *istate, int nr, struct cache_entry *ce)
repository.c
+6
@@ -1,3 +1,8 @@
1 +/*
2 + * not really _using_ the compat macros, just make sure the_index
3 + * declaration matches the definition in this file.
4 + */
5 +#define USE_THE_INDEX_COMPATIBILITY_MACROS
6 #include "cache.h"
7 #include "repository.h"
8 #include "object-store.h"
@@ -9,6 +14,7 @@
14 /* The main repository */
15 static struct repository the_repo;
16 struct repository *the_repository;
17 +struct index_state the_index;
18
19 void initialize_the_repository(void)
20 {
submodule.c
-1
@@ -1,4 +1,3 @@
1 -#define NO_THE_INDEX_COMPATIBILITY_MACROS
1
2 #include "cache.h"
3 #include "repository.h"
t/helper/test-dump-fsmonitor.c
+2 -2
@@ -3,11 +3,11 @@
3
4 int cmd__dump_fsmonitor(int ac, const char **av)
5 {
6 - struct index_state *istate = &the_index;
6 + struct index_state *istate = the_repository->index;
7 int i;
8
9 setup_git_directory();
10 - if (do_read_index(istate, get_index_file(), 0) < 0)
10 + if (do_read_index(istate, the_repository->index_file, 0) < 0)
11 die("unable to read index file");
12 if (!istate->fsmonitor_last_update) {
13 printf("no fsmonitor\n");
t/helper/test-dump-untracked-cache.c
+1
@@ -1,3 +1,4 @@
1 +#define USE_THE_INDEX_COMPATIBILITY_MACROS
2 #include "test-tool.h"
3 #include "cache.h"
4 #include "dir.h"
t/helper/test-tool.h
+1
@@ -1,6 +1,7 @@
1 #ifndef TEST_TOOL_H
2 #define TEST_TOOL_H
3
4 +#define USE_THE_INDEX_COMPATIBILITY_MACROS
5 #include "git-compat-util.h"
6
7 int cmd__chmtime(int argc, const char **argv);
tree.c
-1
@@ -1,4 +1,3 @@
1 -#define NO_THE_INDEX_COMPATIBILITY_MACROS
1 #include "cache.h"
2 #include "cache-tree.h"
3 #include "tree.h"
unpack-trees.c
-1
@@ -1,4 +1,3 @@
1 -#define NO_THE_INDEX_COMPATIBILITY_MACROS
1 #include "cache.h"
2 #include "argv-array.h"
3 #include "repository.h"