Skip to content

Commit

Permalink
cache.h: flip NO_THE_INDEX_COMPATIBILITY_MACROS switch
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>
  • Loading branch information
pclouds authored and gitster committed Jan 24, 2019
1 parent 150fe06 commit f8adbec
Show file tree
Hide file tree
Showing 55 changed files with 58 additions and 24 deletions.
1 change: 0 additions & 1 deletion attr.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
* an insanely large number of attributes.
*/

#define NO_THE_INDEX_COMPATIBILITY_MACROS
#include "cache.h"
#include "config.h"
#include "exec-cmd.h"
Expand Down
1 change: 1 addition & 0 deletions builtin/add.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*
* Copyright (C) 2006 Linus Torvalds
*/
#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "cache.h"
#include "config.h"
#include "builtin.h"
Expand Down
1 change: 1 addition & 0 deletions builtin/am.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*
* Based on git-am.sh by Junio C Hamano.
*/
#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "cache.h"
#include "config.h"
#include "builtin.h"
Expand Down
3 changes: 2 additions & 1 deletion builtin/blame.c
Original file line number Diff line number Diff line change
Expand Up @@ -1007,7 +1007,8 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
long bottom, top;
if (parse_range_arg(range_list.items[range_i].string,
nth_line_cb, &sb, lno, anchor,
&bottom, &top, sb.path, &the_index))
&bottom, &top, sb.path,
the_repository->index))
usage(blame_usage);
if ((!lno && (top || bottom)) || lno < bottom)
die(Q_("file %s has only %lu line",
Expand Down
1 change: 1 addition & 0 deletions builtin/cat-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*
* Copyright (C) Linus Torvalds, 2005
*/
#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "cache.h"
#include "config.h"
#include "builtin.h"
Expand Down
1 change: 1 addition & 0 deletions builtin/check-attr.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "builtin.h"
#include "cache.h"
#include "config.h"
Expand Down
1 change: 1 addition & 0 deletions builtin/check-ignore.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "builtin.h"
#include "cache.h"
#include "config.h"
Expand Down
1 change: 1 addition & 0 deletions builtin/checkout-index.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Copyright (C) 2005 Linus Torvalds
*
*/
#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "builtin.h"
#include "config.h"
#include "lockfile.h"
Expand Down
1 change: 1 addition & 0 deletions builtin/checkout.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "builtin.h"
#include "config.h"
#include "checkout.h"
Expand Down
1 change: 1 addition & 0 deletions builtin/clean.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Based on git-clean.sh by Pavel Roskin
*/

#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "builtin.h"
#include "cache.h"
#include "config.h"
Expand Down
1 change: 1 addition & 0 deletions builtin/clone.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* Clone a repository into a different directory that does not yet exist.
*/

#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "builtin.h"
#include "config.h"
#include "lockfile.h"
Expand Down
1 change: 1 addition & 0 deletions builtin/commit.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* Based on git-commit.sh by Junio C Hamano and Linus Torvalds
*/

#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "cache.h"
#include "config.h"
#include "lockfile.h"
Expand Down
1 change: 1 addition & 0 deletions builtin/describe.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "cache.h"
#include "config.h"
#include "lockfile.h"
Expand Down
1 change: 1 addition & 0 deletions builtin/diff-files.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*
* Copyright (C) Linus Torvalds, 2005
*/
#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "cache.h"
#include "config.h"
#include "diff.h"
Expand Down
1 change: 1 addition & 0 deletions builtin/diff-index.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "cache.h"
#include "config.h"
#include "diff.h"
Expand Down
1 change: 1 addition & 0 deletions builtin/diff-tree.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "cache.h"
#include "config.h"
#include "diff.h"
Expand Down
1 change: 1 addition & 0 deletions builtin/diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*
* Copyright (c) 2006 Junio C Hamano
*/
#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "cache.h"
#include "config.h"
#include "lockfile.h"
Expand Down
1 change: 1 addition & 0 deletions builtin/difftool.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*
* Copyright (C) 2016 Johannes Schindelin
*/
#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "cache.h"
#include "config.h"
#include "builtin.h"
Expand Down
1 change: 1 addition & 0 deletions builtin/fsck.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "builtin.h"
#include "cache.h"
#include "repository.h"
Expand Down
1 change: 1 addition & 0 deletions builtin/grep.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*
* Copyright (c) 2006 Junio C Hamano
*/
#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "cache.h"
#include "repository.h"
#include "config.h"
Expand Down
3 changes: 2 additions & 1 deletion builtin/hash-object.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ static void hash_fd(int fd, const char *type, const char *path, unsigned flags,
if (fstat(fd, &st) < 0 ||
(literally
? 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)
? "Unable to add %s to database"
: "Unable to hash %s", path);
Expand Down
1 change: 1 addition & 0 deletions builtin/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* (C) Copyright 2006 Linus Torvalds
* 2006 Junio Hamano
*/
#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "cache.h"
#include "config.h"
#include "refs.h"
Expand Down
1 change: 0 additions & 1 deletion builtin/ls-files.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*
* Copyright (C) Linus Torvalds, 2005
*/
#define NO_THE_INDEX_COMPATIBILITY_MACROS
#include "cache.h"
#include "repository.h"
#include "config.h"
Expand Down
1 change: 1 addition & 0 deletions builtin/merge-index.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "builtin.h"
#include "run-command.h"

Expand Down
1 change: 1 addition & 0 deletions builtin/merge-ours.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*
* Pretend we resolved the heads, but declare our tree trumps everybody else.
*/
#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "git-compat-util.h"
#include "builtin.h"
#include "diff.h"
Expand Down
4 changes: 3 additions & 1 deletion builtin/merge-tree.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "builtin.h"
#include "tree-walk.h"
#include "xdiff-interface.h"
Expand Down Expand Up @@ -76,7 +77,8 @@ static void *result(struct merge_list *entry, unsigned long *size)
their = NULL;
if (entry)
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)
Expand Down
1 change: 1 addition & 0 deletions builtin/merge.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Based on git-merge.sh by Junio C Hamano.
*/

#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "cache.h"
#include "config.h"
#include "parse-options.h"
Expand Down
1 change: 1 addition & 0 deletions builtin/mv.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*
* Copyright (C) 2006 Johannes Schindelin
*/
#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "builtin.h"
#include "config.h"
#include "pathspec.h"
Expand Down
2 changes: 1 addition & 1 deletion builtin/pack-objects.c
Original file line number Diff line number Diff line change
Expand Up @@ -970,7 +970,7 @@ static int no_try_delta(const char *path)

if (!check)
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))
return 1;
return 0;
Expand Down
1 change: 1 addition & 0 deletions builtin/pull.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*
* Fetch one or more remote refs and merge it/them into the current HEAD.
*/
#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "cache.h"
#include "config.h"
#include "builtin.h"
Expand Down
1 change: 1 addition & 0 deletions builtin/read-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Copyright (C) Linus Torvalds, 2005
*/

#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "cache.h"
#include "config.h"
#include "lockfile.h"
Expand Down
1 change: 1 addition & 0 deletions builtin/rebase--interactive.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "builtin.h"
#include "cache.h"
#include "config.h"
Expand Down
1 change: 1 addition & 0 deletions builtin/rebase.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Copyright (c) 2018 Pratik Karki
*/

#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "builtin.h"
#include "run-command.h"
#include "exec-cmd.h"
Expand Down
2 changes: 1 addition & 1 deletion builtin/replace.c
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ static int import_object(struct object_id *oid, enum object_type type,
close(fd);
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"));
/* index_fd close()s fd for us */
}
Expand Down
1 change: 1 addition & 0 deletions builtin/reset.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*
* Copyright (c) 2005, 2006 Linus Torvalds and Junio C Hamano
*/
#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "builtin.h"
#include "config.h"
#include "lockfile.h"
Expand Down
1 change: 1 addition & 0 deletions builtin/rev-parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*
* Copyright (C) Linus Torvalds, 2005
*/
#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "cache.h"
#include "config.h"
#include "commit.h"
Expand Down
1 change: 1 addition & 0 deletions builtin/rm.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*
* Copyright (C) Linus Torvalds 2006
*/
#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "builtin.h"
#include "config.h"
#include "lockfile.h"
Expand Down
1 change: 1 addition & 0 deletions builtin/submodule--helper.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "builtin.h"
#include "repository.h"
#include "cache.h"
Expand Down
1 change: 1 addition & 0 deletions builtin/update-index.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*
* Copyright (C) Linus Torvalds, 2005
*/
#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "cache.h"
#include "config.h"
#include "lockfile.h"
Expand Down
1 change: 1 addition & 0 deletions builtin/write-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*
* Copyright (C) Linus Torvalds, 2005
*/
#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "builtin.h"
#include "cache.h"
#include "config.h"
Expand Down
2 changes: 1 addition & 1 deletion cache-tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

#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)
{
return write_index_as_tree(oid, &the_index, get_index_file(), flags, prefix);
Expand Down
6 changes: 3 additions & 3 deletions cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,6 @@ struct index_state {
struct mem_pool *ce_mem_pool;
};

extern struct index_state the_index;

/* Name hashing */
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);
Expand Down Expand Up @@ -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);

#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_nr (the_index.cache_nr)
#define active_alloc (the_index.cache_alloc)
Expand Down
1 change: 0 additions & 1 deletion convert.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#define NO_THE_INDEX_COMPATIBILITY_MACROS
#include "cache.h"
#include "config.h"
#include "object-store.h"
Expand Down
1 change: 0 additions & 1 deletion dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
* Copyright (C) Linus Torvalds, 2005-2006
* Junio Hamano, 2005-2006
*/
#define NO_THE_INDEX_COMPATIBILITY_MACROS
#include "cache.h"
#include "config.h"
#include "dir.h"
Expand Down
4 changes: 2 additions & 2 deletions git.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");

validate_cache_entries(&the_index);
validate_cache_entries(the_repository->index);
status = p->fn(argc, argv, prefix);
validate_cache_entries(&the_index);
validate_cache_entries(the_repository->index);

if (status)
return status;
Expand Down
1 change: 0 additions & 1 deletion name-hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*
* Copyright (C) 2008 Linus Torvalds
*/
#define NO_THE_INDEX_COMPATIBILITY_MACROS
#include "cache.h"
#include "thread-utils.h"

Expand Down
1 change: 0 additions & 1 deletion pathspec.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#define NO_THE_INDEX_COMPATIBILITY_MACROS
#include "cache.h"
#include "config.h"
#include "dir.h"
Expand Down
2 changes: 0 additions & 2 deletions read-cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
*
* Copyright (C) Linus Torvalds, 2005
*/
#define NO_THE_INDEX_COMPATIBILITY_MACROS
#include "cache.h"
#include "config.h"
#include "diff.h"
Expand Down Expand Up @@ -95,7 +94,6 @@ static struct mem_pool *find_mem_pool(struct index_state *istate)
return *pool_ptr;
}

struct index_state the_index;
static const char *alternate_index_output;

static void set_index_entry(struct index_state *istate, int nr, struct cache_entry *ce)
Expand Down
Loading

0 comments on commit f8adbec

Please sign in to comment.