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>
This commit is contained in:
Nguyễn Thái Ngọc Duy 2019-01-24 15:29:12 +07:00 committed by Junio C Hamano
parent 150fe065f7
commit f8adbec9fe
55 changed files with 58 additions and 24 deletions

1
attr.c
View File

@ -7,7 +7,6 @@
* an insanely large number of attributes. * an insanely large number of attributes.
*/ */
#define NO_THE_INDEX_COMPATIBILITY_MACROS
#include "cache.h" #include "cache.h"
#include "config.h" #include "config.h"
#include "exec-cmd.h" #include "exec-cmd.h"

View File

@ -3,6 +3,7 @@
* *
* Copyright (C) 2006 Linus Torvalds * Copyright (C) 2006 Linus Torvalds
*/ */
#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "cache.h" #include "cache.h"
#include "config.h" #include "config.h"
#include "builtin.h" #include "builtin.h"

View File

@ -3,6 +3,7 @@
* *
* Based on git-am.sh by Junio C Hamano. * Based on git-am.sh by Junio C Hamano.
*/ */
#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "cache.h" #include "cache.h"
#include "config.h" #include "config.h"
#include "builtin.h" #include "builtin.h"

View File

@ -1007,7 +1007,8 @@ parse_done:
long bottom, top; long bottom, top;
if (parse_range_arg(range_list.items[range_i].string, if (parse_range_arg(range_list.items[range_i].string,
nth_line_cb, &sb, lno, anchor, nth_line_cb, &sb, lno, anchor,
&bottom, &top, sb.path, &the_index)) &bottom, &top, sb.path,
the_repository->index))
usage(blame_usage); usage(blame_usage);
if ((!lno && (top || bottom)) || lno < bottom) if ((!lno && (top || bottom)) || lno < bottom)
die(Q_("file %s has only %lu line", die(Q_("file %s has only %lu line",

View File

@ -3,6 +3,7 @@
* *
* Copyright (C) Linus Torvalds, 2005 * Copyright (C) Linus Torvalds, 2005
*/ */
#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "cache.h" #include "cache.h"
#include "config.h" #include "config.h"
#include "builtin.h" #include "builtin.h"

View File

@ -1,3 +1,4 @@
#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "builtin.h" #include "builtin.h"
#include "cache.h" #include "cache.h"
#include "config.h" #include "config.h"

View File

@ -1,3 +1,4 @@
#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "builtin.h" #include "builtin.h"
#include "cache.h" #include "cache.h"
#include "config.h" #include "config.h"

View File

@ -4,6 +4,7 @@
* Copyright (C) 2005 Linus Torvalds * Copyright (C) 2005 Linus Torvalds
* *
*/ */
#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "builtin.h" #include "builtin.h"
#include "config.h" #include "config.h"
#include "lockfile.h" #include "lockfile.h"

View File

@ -1,3 +1,4 @@
#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "builtin.h" #include "builtin.h"
#include "config.h" #include "config.h"
#include "checkout.h" #include "checkout.h"

View File

@ -6,6 +6,7 @@
* Based on git-clean.sh by Pavel Roskin * Based on git-clean.sh by Pavel Roskin
*/ */
#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "builtin.h" #include "builtin.h"
#include "cache.h" #include "cache.h"
#include "config.h" #include "config.h"

View File

@ -8,6 +8,7 @@
* Clone a repository into a different directory that does not yet exist. * Clone a repository into a different directory that does not yet exist.
*/ */
#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "builtin.h" #include "builtin.h"
#include "config.h" #include "config.h"
#include "lockfile.h" #include "lockfile.h"

View File

@ -5,6 +5,7 @@
* Based on git-commit.sh by Junio C Hamano and Linus Torvalds * Based on git-commit.sh by Junio C Hamano and Linus Torvalds
*/ */
#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "cache.h" #include "cache.h"
#include "config.h" #include "config.h"
#include "lockfile.h" #include "lockfile.h"

View File

@ -1,3 +1,4 @@
#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "cache.h" #include "cache.h"
#include "config.h" #include "config.h"
#include "lockfile.h" #include "lockfile.h"

View File

@ -3,6 +3,7 @@
* *
* Copyright (C) Linus Torvalds, 2005 * Copyright (C) Linus Torvalds, 2005
*/ */
#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "cache.h" #include "cache.h"
#include "config.h" #include "config.h"
#include "diff.h" #include "diff.h"

View File

@ -1,3 +1,4 @@
#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "cache.h" #include "cache.h"
#include "config.h" #include "config.h"
#include "diff.h" #include "diff.h"

View File

@ -1,3 +1,4 @@
#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "cache.h" #include "cache.h"
#include "config.h" #include "config.h"
#include "diff.h" #include "diff.h"

View File

@ -3,6 +3,7 @@
* *
* Copyright (c) 2006 Junio C Hamano * Copyright (c) 2006 Junio C Hamano
*/ */
#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "cache.h" #include "cache.h"
#include "config.h" #include "config.h"
#include "lockfile.h" #include "lockfile.h"

View File

@ -11,6 +11,7 @@
* *
* Copyright (C) 2016 Johannes Schindelin * Copyright (C) 2016 Johannes Schindelin
*/ */
#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "cache.h" #include "cache.h"
#include "config.h" #include "config.h"
#include "builtin.h" #include "builtin.h"

View File

@ -1,3 +1,4 @@
#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "builtin.h" #include "builtin.h"
#include "cache.h" #include "cache.h"
#include "repository.h" #include "repository.h"

View File

@ -3,6 +3,7 @@
* *
* Copyright (c) 2006 Junio C Hamano * Copyright (c) 2006 Junio C Hamano
*/ */
#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "cache.h" #include "cache.h"
#include "repository.h" #include "repository.h"
#include "config.h" #include "config.h"

View File

@ -40,7 +40,8 @@ static void hash_fd(int fd, const char *type, const char *path, unsigned flags,
if (fstat(fd, &st) < 0 || if (fstat(fd, &st) < 0 ||
(literally (literally
? hash_literally(&oid, fd, type, flags) ? hash_literally(&oid, fd, type, flags)
: index_fd(&the_index, &oid, fd, &st, type_from_string(type), path, flags))) : index_fd(the_repository->index, &oid, fd, &st,
type_from_string(type), path, flags)))
die((flags & HASH_WRITE_OBJECT) die((flags & HASH_WRITE_OBJECT)
? "Unable to add %s to database" ? "Unable to add %s to database"
: "Unable to hash %s", path); : "Unable to hash %s", path);

View File

@ -4,6 +4,7 @@
* (C) Copyright 2006 Linus Torvalds * (C) Copyright 2006 Linus Torvalds
* 2006 Junio Hamano * 2006 Junio Hamano
*/ */
#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "cache.h" #include "cache.h"
#include "config.h" #include "config.h"
#include "refs.h" #include "refs.h"

View File

@ -5,7 +5,6 @@
* *
* Copyright (C) Linus Torvalds, 2005 * Copyright (C) Linus Torvalds, 2005
*/ */
#define NO_THE_INDEX_COMPATIBILITY_MACROS
#include "cache.h" #include "cache.h"
#include "repository.h" #include "repository.h"
#include "config.h" #include "config.h"

View File

@ -1,3 +1,4 @@
#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "builtin.h" #include "builtin.h"
#include "run-command.h" #include "run-command.h"

View File

@ -7,6 +7,7 @@
* *
* Pretend we resolved the heads, but declare our tree trumps everybody else. * Pretend we resolved the heads, but declare our tree trumps everybody else.
*/ */
#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "git-compat-util.h" #include "git-compat-util.h"
#include "builtin.h" #include "builtin.h"
#include "diff.h" #include "diff.h"

View File

@ -1,3 +1,4 @@
#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "builtin.h" #include "builtin.h"
#include "tree-walk.h" #include "tree-walk.h"
#include "xdiff-interface.h" #include "xdiff-interface.h"
@ -76,7 +77,8 @@ static void *result(struct merge_list *entry, unsigned long *size)
their = NULL; their = NULL;
if (entry) if (entry)
their = entry->blob; their = entry->blob;
return merge_blobs(&the_index, path, base, our, their, size); return merge_blobs(the_repository->index, path,
base, our, their, size);
} }
static void *origin(struct merge_list *entry, unsigned long *size) static void *origin(struct merge_list *entry, unsigned long *size)

View File

@ -6,6 +6,7 @@
* Based on git-merge.sh by Junio C Hamano. * Based on git-merge.sh by Junio C Hamano.
*/ */
#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "cache.h" #include "cache.h"
#include "config.h" #include "config.h"
#include "parse-options.h" #include "parse-options.h"

View File

@ -3,6 +3,7 @@
* *
* Copyright (C) 2006 Johannes Schindelin * Copyright (C) 2006 Johannes Schindelin
*/ */
#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "builtin.h" #include "builtin.h"
#include "config.h" #include "config.h"
#include "pathspec.h" #include "pathspec.h"

View File

@ -970,7 +970,7 @@ static int no_try_delta(const char *path)
if (!check) if (!check)
check = attr_check_initl("delta", NULL); check = attr_check_initl("delta", NULL);
git_check_attr(&the_index, path, check); git_check_attr(the_repository->index, path, check);
if (ATTR_FALSE(check->items[0].value)) if (ATTR_FALSE(check->items[0].value))
return 1; return 1;
return 0; return 0;

View File

@ -5,6 +5,7 @@
* *
* Fetch one or more remote refs and merge it/them into the current HEAD. * Fetch one or more remote refs and merge it/them into the current HEAD.
*/ */
#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "cache.h" #include "cache.h"
#include "config.h" #include "config.h"
#include "builtin.h" #include "builtin.h"

View File

@ -4,6 +4,7 @@
* Copyright (C) Linus Torvalds, 2005 * Copyright (C) Linus Torvalds, 2005
*/ */
#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "cache.h" #include "cache.h"
#include "config.h" #include "config.h"
#include "lockfile.h" #include "lockfile.h"

View File

@ -1,3 +1,4 @@
#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "builtin.h" #include "builtin.h"
#include "cache.h" #include "cache.h"
#include "config.h" #include "config.h"

View File

@ -4,6 +4,7 @@
* Copyright (c) 2018 Pratik Karki * Copyright (c) 2018 Pratik Karki
*/ */
#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "builtin.h" #include "builtin.h"
#include "run-command.h" #include "run-command.h"
#include "exec-cmd.h" #include "exec-cmd.h"

View File

@ -295,7 +295,7 @@ static int import_object(struct object_id *oid, enum object_type type,
close(fd); close(fd);
return -1; return -1;
} }
if (index_fd(&the_index, oid, fd, &st, type, NULL, flags) < 0) if (index_fd(the_repository->index, oid, fd, &st, type, NULL, flags) < 0)
return error(_("unable to write object to database")); return error(_("unable to write object to database"));
/* index_fd close()s fd for us */ /* index_fd close()s fd for us */
} }

View File

@ -7,6 +7,7 @@
* *
* Copyright (c) 2005, 2006 Linus Torvalds and Junio C Hamano * Copyright (c) 2005, 2006 Linus Torvalds and Junio C Hamano
*/ */
#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "builtin.h" #include "builtin.h"
#include "config.h" #include "config.h"
#include "lockfile.h" #include "lockfile.h"

View File

@ -3,6 +3,7 @@
* *
* Copyright (C) Linus Torvalds, 2005 * Copyright (C) Linus Torvalds, 2005
*/ */
#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "cache.h" #include "cache.h"
#include "config.h" #include "config.h"
#include "commit.h" #include "commit.h"

View File

@ -3,6 +3,7 @@
* *
* Copyright (C) Linus Torvalds 2006 * Copyright (C) Linus Torvalds 2006
*/ */
#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "builtin.h" #include "builtin.h"
#include "config.h" #include "config.h"
#include "lockfile.h" #include "lockfile.h"

View File

@ -1,3 +1,4 @@
#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "builtin.h" #include "builtin.h"
#include "repository.h" #include "repository.h"
#include "cache.h" #include "cache.h"

View File

@ -3,6 +3,7 @@
* *
* Copyright (C) Linus Torvalds, 2005 * Copyright (C) Linus Torvalds, 2005
*/ */
#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "cache.h" #include "cache.h"
#include "config.h" #include "config.h"
#include "lockfile.h" #include "lockfile.h"

View File

@ -3,6 +3,7 @@
* *
* Copyright (C) Linus Torvalds, 2005 * Copyright (C) Linus Torvalds, 2005
*/ */
#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "builtin.h" #include "builtin.h"
#include "cache.h" #include "cache.h"
#include "config.h" #include "config.h"

View File

@ -51,7 +51,7 @@ void prime_cache_tree(struct repository *, struct index_state *, struct tree *);
int cache_tree_matches_traversal(struct cache_tree *, struct name_entry *ent, struct traverse_info *info); int cache_tree_matches_traversal(struct cache_tree *, struct name_entry *ent, struct traverse_info *info);
#ifndef NO_THE_INDEX_COMPATIBILITY_MACROS #ifdef USE_THE_INDEX_COMPATIBILITY_MACROS
static inline int write_cache_as_tree(struct object_id *oid, int flags, const char *prefix) static inline int write_cache_as_tree(struct object_id *oid, int flags, const char *prefix)
{ {
return write_index_as_tree(oid, &the_index, get_index_file(), flags, prefix); return write_index_as_tree(oid, &the_index, get_index_file(), flags, prefix);

View File

@ -338,8 +338,6 @@ struct index_state {
struct mem_pool *ce_mem_pool; struct mem_pool *ce_mem_pool;
}; };
extern struct index_state the_index;
/* Name hashing */ /* Name hashing */
extern int test_lazy_init_name_hash(struct index_state *istate, int try_threaded); extern int test_lazy_init_name_hash(struct index_state *istate, int try_threaded);
extern void add_name_hash(struct index_state *istate, struct cache_entry *ce); 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
*/ */
void validate_cache_entries(const struct index_state *istate); void validate_cache_entries(const struct index_state *istate);
#ifndef NO_THE_INDEX_COMPATIBILITY_MACROS #ifdef USE_THE_INDEX_COMPATIBILITY_MACROS
extern struct index_state the_index;
#define active_cache (the_index.cache) #define active_cache (the_index.cache)
#define active_nr (the_index.cache_nr) #define active_nr (the_index.cache_nr)
#define active_alloc (the_index.cache_alloc) #define active_alloc (the_index.cache_alloc)

View File

@ -1,4 +1,3 @@
#define NO_THE_INDEX_COMPATIBILITY_MACROS
#include "cache.h" #include "cache.h"
#include "config.h" #include "config.h"
#include "object-store.h" #include "object-store.h"

1
dir.c
View File

@ -7,7 +7,6 @@
* Copyright (C) Linus Torvalds, 2005-2006 * Copyright (C) Linus Torvalds, 2005-2006
* Junio Hamano, 2005-2006 * Junio Hamano, 2005-2006
*/ */
#define NO_THE_INDEX_COMPATIBILITY_MACROS
#include "cache.h" #include "cache.h"
#include "config.h" #include "config.h"
#include "dir.h" #include "dir.h"

4
git.c
View File

@ -417,9 +417,9 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
trace_argv_printf(argv, "trace: built-in: git"); trace_argv_printf(argv, "trace: built-in: git");
validate_cache_entries(&the_index); validate_cache_entries(the_repository->index);
status = p->fn(argc, argv, prefix); status = p->fn(argc, argv, prefix);
validate_cache_entries(&the_index); validate_cache_entries(the_repository->index);
if (status) if (status)
return status; return status;

View File

@ -5,7 +5,6 @@
* *
* Copyright (C) 2008 Linus Torvalds * Copyright (C) 2008 Linus Torvalds
*/ */
#define NO_THE_INDEX_COMPATIBILITY_MACROS
#include "cache.h" #include "cache.h"
#include "thread-utils.h" #include "thread-utils.h"

View File

@ -1,4 +1,3 @@
#define NO_THE_INDEX_COMPATIBILITY_MACROS
#include "cache.h" #include "cache.h"
#include "config.h" #include "config.h"
#include "dir.h" #include "dir.h"

View File

@ -3,7 +3,6 @@
* *
* Copyright (C) Linus Torvalds, 2005 * Copyright (C) Linus Torvalds, 2005
*/ */
#define NO_THE_INDEX_COMPATIBILITY_MACROS
#include "cache.h" #include "cache.h"
#include "config.h" #include "config.h"
#include "diff.h" #include "diff.h"
@ -95,7 +94,6 @@ static struct mem_pool *find_mem_pool(struct index_state *istate)
return *pool_ptr; return *pool_ptr;
} }
struct index_state the_index;
static const char *alternate_index_output; static const char *alternate_index_output;
static void set_index_entry(struct index_state *istate, int nr, struct cache_entry *ce) static void set_index_entry(struct index_state *istate, int nr, struct cache_entry *ce)

View File

@ -1,3 +1,8 @@
/*
* not really _using_ the compat macros, just make sure the_index
* declaration matches the definition in this file.
*/
#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "cache.h" #include "cache.h"
#include "repository.h" #include "repository.h"
#include "object-store.h" #include "object-store.h"
@ -9,6 +14,7 @@
/* The main repository */ /* The main repository */
static struct repository the_repo; static struct repository the_repo;
struct repository *the_repository; struct repository *the_repository;
struct index_state the_index;
void initialize_the_repository(void) void initialize_the_repository(void)
{ {

View File

@ -1,4 +1,3 @@
#define NO_THE_INDEX_COMPATIBILITY_MACROS
#include "cache.h" #include "cache.h"
#include "repository.h" #include "repository.h"

View File

@ -3,11 +3,11 @@
int cmd__dump_fsmonitor(int ac, const char **av) int cmd__dump_fsmonitor(int ac, const char **av)
{ {
struct index_state *istate = &the_index; struct index_state *istate = the_repository->index;
int i; int i;
setup_git_directory(); setup_git_directory();
if (do_read_index(istate, get_index_file(), 0) < 0) if (do_read_index(istate, the_repository->index_file, 0) < 0)
die("unable to read index file"); die("unable to read index file");
if (!istate->fsmonitor_last_update) { if (!istate->fsmonitor_last_update) {
printf("no fsmonitor\n"); printf("no fsmonitor\n");

View File

@ -1,3 +1,4 @@
#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "test-tool.h" #include "test-tool.h"
#include "cache.h" #include "cache.h"
#include "dir.h" #include "dir.h"

View File

@ -1,6 +1,7 @@
#ifndef TEST_TOOL_H #ifndef TEST_TOOL_H
#define TEST_TOOL_H #define TEST_TOOL_H
#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "git-compat-util.h" #include "git-compat-util.h"
int cmd__chmtime(int argc, const char **argv); int cmd__chmtime(int argc, const char **argv);

1
tree.c
View File

@ -1,4 +1,3 @@
#define NO_THE_INDEX_COMPATIBILITY_MACROS
#include "cache.h" #include "cache.h"
#include "cache-tree.h" #include "cache-tree.h"
#include "tree.h" #include "tree.h"

View File

@ -1,4 +1,3 @@
#define NO_THE_INDEX_COMPATIBILITY_MACROS
#include "cache.h" #include "cache.h"
#include "argv-array.h" #include "argv-array.h"
#include "repository.h" #include "repository.h"