git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH 00/15] Kill the_index part 1, expose it
@ 2018-06-16  5:41 Nguyễn Thái Ngọc Duy
  2018-06-16  5:41 ` [PATCH 01/15] contrib: add cocci script to replace index compat macros Nguyễn Thái Ngọc Duy
                   ` (16 more replies)
  0 siblings, 17 replies; 32+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2018-06-16  5:41 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

This is the beginning of the end of the_index. The problem with
the_index is it lets library code anywhere access it freely. This is
not good because from high level you may not realize that the_index is
being used while you don't want to touch index at all, or you want to
use a different index instead.

This is a long series, 86 patches [1], so I'm going to split and
submit it in 15-20 patches at a time. The first two parts are trivial
though and could be safely fast tracked if needed.

This is the first part, which kills the use of index compat macros
outside builtin/ and expose the_index in all library code. Later on we
will ban the_index from one file each time until it's gone for good.

"struct index_state *" will be passed from builtin/ through the call
chain to the function that needs it. In some cases, "struct
repository *" will be passed instead when the whole operation spans
more than just the index.  By the end, the_index becomes part of
"index compat macros" and cannot be used outside builtin/

Part one is mechanical conversion with the help of coccinelle. The
only real patches are the first and the last one.

[1] https://gitlab.com/pclouds/git/commits/really-kill-the-index

Nguyễn Thái Ngọc Duy (15):
  contrib: add cocci script to replace index compat macros
  apply.c: stop using index compat macros
  blame.c: stop using index compat macros
  check-racy.c: stop using index compat macros
  diff-lib.c: stop using index compat macros
  diff.c: stop using index compat macros
  entry.c: stop using index compat macros
  merge-recursive.c: stop using index compat macros
  merge.c: stop using index compat macros
  rerere.c: stop using index compat macros
  revision.c: stop using index compat macros
  sequencer.c: stop using index compat macros
  sha1-name.c: stop using index compat macros
  wt-status.c: stop using index compat macros
  cache.h: flip NO_THE_INDEX_COMPATIBILITY_MACROS switch

 apply.c                               |  34 ++---
 attr.c                                |   1 -
 blame.c                               |  19 +--
 builtin/add.c                         |   1 +
 builtin/am.c                          |   1 +
 builtin/check-attr.c                  |   1 +
 builtin/check-ignore.c                |   1 +
 builtin/checkout-index.c              |   1 +
 builtin/checkout.c                    |   1 +
 builtin/clean.c                       |   1 +
 builtin/commit.c                      |   1 +
 builtin/describe.c                    |   1 +
 builtin/diff-files.c                  |   1 +
 builtin/diff-index.c                  |   1 +
 builtin/diff-tree.c                   |   1 +
 builtin/diff.c                        |   1 +
 builtin/fsck.c                        |   1 +
 builtin/ls-files.c                    |   1 -
 builtin/merge-index.c                 |   1 +
 builtin/merge-ours.c                  |   1 +
 builtin/merge.c                       |   1 +
 builtin/mv.c                          |   1 +
 builtin/pull.c                        |   1 +
 builtin/read-tree.c                   |   1 +
 builtin/reset.c                       |   1 +
 builtin/rev-parse.c                   |   1 +
 builtin/rm.c                          |   1 +
 builtin/submodule--helper.c           |   1 +
 builtin/update-index.c                |   1 +
 cache.h                               |   2 +-
 check-racy.c                          |  10 +-
 contrib/coccinelle/index-compat.cocci | 184 ++++++++++++++++++++++++++
 convert.c                             |   1 -
 diff-lib.c                            |   8 +-
 diff.c                                |  12 +-
 dir.c                                 |   1 -
 entry.c                               |   3 +-
 merge-recursive.c                     |  65 ++++-----
 merge.c                               |  14 +-
 name-hash.c                           |   1 -
 pathspec.c                            |   1 -
 read-cache.c                          |   1 -
 rerere.c                              |  36 ++---
 revision.c                            |  14 +-
 sequencer.c                           |  32 ++---
 sha1-name.c                           |  22 +--
 submodule.c                           |   1 -
 t/helper/test-dump-untracked-cache.c  |   1 +
 t/helper/test-tool.h                  |   2 +
 tree.c                                |   1 -
 unpack-trees.c                        |   1 -
 wt-status.c                           |  24 ++--
 52 files changed, 363 insertions(+), 154 deletions(-)
 create mode 100644 contrib/coccinelle/index-compat.cocci

-- 
2.18.0.rc0.333.g22e6ee6cdf


^ permalink raw reply	[flat|nested] 32+ messages in thread

* [PATCH 01/15] contrib: add cocci script to replace index compat macros
  2018-06-16  5:41 [PATCH 00/15] Kill the_index part 1, expose it Nguyễn Thái Ngọc Duy
@ 2018-06-16  5:41 ` Nguyễn Thái Ngọc Duy
  2018-06-19 11:35   ` Derrick Stolee
  2018-06-16  5:41 ` [PATCH 02/15] apply.c: stop using " Nguyễn Thái Ngọc Duy
                   ` (15 subsequent siblings)
  16 siblings, 1 reply; 32+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2018-06-16  5:41 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

Index compat macros are going to be removed to expose the_index and
then reorganized to use the right index instead of simply the_index
because sometimes we want to use a different index.

This cocci script can help with the first step. It can be used later
on on even builtin/ when we start to reorganize code in there, but for
now this is the script that performs all the conversion outside
builtin/

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 contrib/coccinelle/index-compat.cocci | 184 ++++++++++++++++++++++++++
 1 file changed, 184 insertions(+)
 create mode 100644 contrib/coccinelle/index-compat.cocci

diff --git a/contrib/coccinelle/index-compat.cocci b/contrib/coccinelle/index-compat.cocci
new file mode 100644
index 0000000000..ca46711eb6
--- /dev/null
+++ b/contrib/coccinelle/index-compat.cocci
@@ -0,0 +1,184 @@
+@@
+@@
+-active_cache
++the_index.cache
+
+@@
+@@
+-active_nr
++the_index.cache_nr
+
+@@
+@@
+-active_alloc
++the_index.cache_alloc
+
+@@
+@@
+-active_cache_changed
++the_index.cache_changed
+
+@@
+@@
+-active_cache_tree
++the_index.cache_tree
+
+@@
+@@
+- read_cache()
++ read_index(&the_index)
+
+@@
+expression path;
+@@
+- read_cache_from(path)
++ read_index_from(&the_index, path, get_git_dir())
+
+@@
+expression pathspec;
+@@
+- read_cache_preload(pathspec)
++ read_index_preload(&the_index, pathspec)
+
+@@
+@@
+- is_cache_unborn()
++ is_index_unborn(&the_index)
+
+@@
+@@
+- read_cache_unmerged()
++ read_index_unmerged(&the_index)
+
+@@
+@@
+- discard_cache()
++ discard_index(&the_index)
+
+@@
+@@
+- unmerged_cache()
++ unmerged_index(&the_index)
+
+@@
+expression name;
+expression namelen;
+@@
+- cache_name_pos(name, namelen)
++ index_name_pos(&the_index, name, namelen)
+
+@@
+expression ce;
+expression option;
+@@
+- add_cache_entry(ce, option)
++ add_index_entry(&the_index, ce, option)
+
+@@
+expression pos;
+expression new_name;
+@@
+- rename_cache_entry_at(pos, new_name)
++ rename_index_entry_at(&the_index, pos, new_name)
+
+@@
+expression pos;
+@@
+- remove_cache_entry_at(pos)
++ remove_index_entry_at(&the_index, pos)
+
+@@
+expression path;
+@@
+- remove_file_from_cache(path)
++ remove_file_from_index(&the_index, path)
+
+@@
+expression path;
+expression st;
+expression flags;
+@@
+- add_to_cache(path, st, flags)
++ add_to_index(&the_index, path, st, flags)
+
+@@
+expression path;
+expression flags;
+@@
+- add_file_to_cache(path, flags)
++ add_file_to_index(&the_index, path, flags)
+
+@@
+expression ce;
+expression flip;
+@@
+-chmod_cache_entry(ce, flip)
++chmod_index_entry(&the_index, ce, flip)
+
+@@
+expression flags;
+@@
+-refresh_cache(flags)
++refresh_index(&the_index, flags, NULL, NULL, NULL)
+
+@@
+expression ce;
+expression st;
+expression options;
+@@
+-ce_match_stat(ce, st, options)
++ie_match_stat(&the_index, ce, st, options)
+
+@@
+expression ce;
+expression st;
+expression options;
+@@
+-ce_modified(ce, st, options)
++ie_modified(&the_index, ce, st, options)
+
+@@
+expression name;
+expression namelen;
+@@
+-cache_dir_exists(name, namelen)
++index_dir_exists(&the_index, name, namelen)
+
+@@
+expression name;
+expression namelen;
+expression igncase;
+@@
+-cache_file_exists(name, namelen, igncase)
++index_file_exists(&the_index, name, namelen, igncase)
+
+@@
+expression name;
+expression namelen;
+@@
+-cache_name_is_other(name, namelen)
++index_name_is_other(&the_index, name, namelen)
+
+@@
+@@
+-resolve_undo_clear()
++resolve_undo_clear_index(&the_index)
+
+@@
+expression at;
+@@
+-unmerge_cache_entry_at(at)
++unmerge_index_entry_at(&the_index, at)
+
+@@
+expression pathspec;
+@@
+-unmerge_cache(pathspec)
++unmerge_index(&the_index, pathspec)
+
+@@
+expression path;
+expression sz;
+@@
+-read_blob_data_from_cache(path, sz)
++read_blob_data_from_index(&the_index, path, sz)
-- 
2.18.0.rc0.333.g22e6ee6cdf


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH 02/15] apply.c: stop using index compat macros
  2018-06-16  5:41 [PATCH 00/15] Kill the_index part 1, expose it Nguyễn Thái Ngọc Duy
  2018-06-16  5:41 ` [PATCH 01/15] contrib: add cocci script to replace index compat macros Nguyễn Thái Ngọc Duy
@ 2018-06-16  5:41 ` Nguyễn Thái Ngọc Duy
  2018-06-25 17:27   ` Junio C Hamano
  2018-06-16  5:41 ` [PATCH 03/15] blame.c: " Nguyễn Thái Ngọc Duy
                   ` (14 subsequent siblings)
  16 siblings, 1 reply; 32+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2018-06-16  5:41 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 apply.c | 34 +++++++++++++++++++---------------
 1 file changed, 19 insertions(+), 15 deletions(-)

diff --git a/apply.c b/apply.c
index d79e61591b..57a7d3cafd 100644
--- a/apply.c
+++ b/apply.c
@@ -3378,7 +3378,8 @@ static int verify_index_match(const struct cache_entry *ce, struct stat *st)
 			return -1;
 		return 0;
 	}
-	return ce_match_stat(ce, st, CE_MATCH_IGNORE_VALID|CE_MATCH_IGNORE_SKIP_WORKTREE);
+	return ie_match_stat(&the_index, ce, st,
+			     CE_MATCH_IGNORE_VALID | CE_MATCH_IGNORE_SKIP_WORKTREE);
 }
 
 #define SUBMODULE_PATCH_WITHOUT_INDEX 1
@@ -3511,10 +3512,10 @@ static int load_current(struct apply_state *state,
 	if (!patch->is_new)
 		BUG("patch to %s is not a creation", patch->old_name);
 
-	pos = cache_name_pos(name, strlen(name));
+	pos = index_name_pos(&the_index, name, strlen(name));
 	if (pos < 0)
 		return error(_("%s: does not exist in index"), name);
-	ce = active_cache[pos];
+	ce = the_index.cache[pos];
 	if (lstat(name, &st)) {
 		if (errno != ENOENT)
 			return error_errno("%s", name);
@@ -3680,13 +3681,14 @@ static int check_preimage(struct apply_state *state,
 	}
 
 	if (state->check_index && !previous) {
-		int pos = cache_name_pos(old_name, strlen(old_name));
+		int pos = index_name_pos(&the_index, old_name,
+					 strlen(old_name));
 		if (pos < 0) {
 			if (patch->is_new < 0)
 				goto is_new;
 			return error(_("%s: does not exist in index"), old_name);
 		}
-		*ce = active_cache[pos];
+		*ce = the_index.cache[pos];
 		if (stat_ret < 0) {
 			if (checkout_target(&the_index, *ce, st))
 				return -1;
@@ -3735,7 +3737,7 @@ static int check_to_create(struct apply_state *state,
 	struct stat nst;
 
 	if (state->check_index &&
-	    cache_name_pos(new_name, strlen(new_name)) >= 0 &&
+	    index_name_pos(&the_index, new_name, strlen(new_name)) >= 0 &&
 	    !ok_if_exists)
 		return EXISTS_IN_INDEX;
 	if (state->cached)
@@ -3824,7 +3826,8 @@ static int path_is_beyond_symlink_1(struct apply_state *state, struct strbuf *na
 		if (state->check_index) {
 			struct cache_entry *ce;
 
-			ce = cache_file_exists(name->buf, name->len, ignore_case);
+			ce = index_file_exists(&the_index, name->buf,
+					       name->len, ignore_case);
 			if (ce && S_ISLNK(ce->ce_mode))
 				return 1;
 		} else {
@@ -3999,9 +4002,10 @@ static int check_patch_list(struct apply_state *state, struct patch *patch)
 static int read_apply_cache(struct apply_state *state)
 {
 	if (state->index_file)
-		return read_cache_from(state->index_file);
+		return read_index_from(&the_index, state->index_file,
+				       get_git_dir());
 	else
-		return read_cache();
+		return read_index(&the_index);
 }
 
 /* This function tries to read the object name from the current index */
@@ -4012,10 +4016,10 @@ static int get_current_oid(struct apply_state *state, const char *path,
 
 	if (read_apply_cache(state) < 0)
 		return -1;
-	pos = cache_name_pos(path, strlen(path));
+	pos = index_name_pos(&the_index, path, strlen(path));
 	if (pos < 0)
 		return -1;
-	oidcpy(oid, &active_cache[pos]->oid);
+	oidcpy(oid, &the_index.cache[pos]->oid);
 	return 0;
 }
 
@@ -4243,7 +4247,7 @@ static void patch_stats(struct apply_state *state, struct patch *patch)
 static int remove_file(struct apply_state *state, struct patch *patch, int rmdir_empty)
 {
 	if (state->update_index) {
-		if (remove_file_from_cache(patch->old_name) < 0)
+		if (remove_file_from_index(&the_index, patch->old_name) < 0)
 			return error(_("unable to remove %s from index"), patch->old_name);
 	}
 	if (!state->cached) {
@@ -4297,7 +4301,7 @@ static int add_index_file(struct apply_state *state,
 				       "for newly created file %s"), path);
 		}
 	}
-	if (add_cache_entry(ce, ADD_CACHE_OK_TO_ADD) < 0) {
+	if (add_index_entry(&the_index, ce, ADD_CACHE_OK_TO_ADD) < 0) {
 		free(ce);
 		return error(_("unable to add cache entry for %s"), path);
 	}
@@ -4431,7 +4435,7 @@ static int add_conflicted_stages_file(struct apply_state *state,
 	ce_size = cache_entry_size(namelen);
 	mode = patch->new_mode ? patch->new_mode : (S_IFREG | 0644);
 
-	remove_file_from_cache(patch->new_name);
+	remove_file_from_index(&the_index, patch->new_name);
 	for (stage = 1; stage < 4; stage++) {
 		if (is_null_oid(&patch->threeway_stage[stage - 1]))
 			continue;
@@ -4441,7 +4445,7 @@ static int add_conflicted_stages_file(struct apply_state *state,
 		ce->ce_flags = create_ce_flags(stage);
 		ce->ce_namelen = namelen;
 		oidcpy(&ce->oid, &patch->threeway_stage[stage - 1]);
-		if (add_cache_entry(ce, ADD_CACHE_OK_TO_ADD) < 0) {
+		if (add_index_entry(&the_index, ce, ADD_CACHE_OK_TO_ADD) < 0) {
 			free(ce);
 			return error(_("unable to add cache entry for %s"),
 				     patch->new_name);
-- 
2.18.0.rc0.333.g22e6ee6cdf


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH 03/15] blame.c: stop using index compat macros
  2018-06-16  5:41 [PATCH 00/15] Kill the_index part 1, expose it Nguyễn Thái Ngọc Duy
  2018-06-16  5:41 ` [PATCH 01/15] contrib: add cocci script to replace index compat macros Nguyễn Thái Ngọc Duy
  2018-06-16  5:41 ` [PATCH 02/15] apply.c: stop using " Nguyễn Thái Ngọc Duy
@ 2018-06-16  5:41 ` Nguyễn Thái Ngọc Duy
  2018-06-16  5:41 ` [PATCH 04/15] check-racy.c: " Nguyễn Thái Ngọc Duy
                   ` (13 subsequent siblings)
  16 siblings, 0 replies; 32+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2018-06-16  5:41 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 blame.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/blame.c b/blame.c
index 14d0e0b575..c357cf2f49 100644
--- a/blame.c
+++ b/blame.c
@@ -85,11 +85,11 @@ static void verify_working_tree_path(struct commit *work_tree, const char *path)
 			return;
 	}
 
-	pos = cache_name_pos(path, strlen(path));
+	pos = index_name_pos(&the_index, path, strlen(path));
 	if (pos >= 0)
 		; /* path is in the index */
-	else if (-1 - pos < active_nr &&
-		 !strcmp(active_cache[-1 - pos]->name, path))
+	else if (-1 - pos < the_index.cache_nr &&
+		 !strcmp(the_index.cache[-1 - pos]->name, path))
 		; /* path is in the index, unmerged */
 	else
 		die("no such path '%s' in HEAD", path);
@@ -159,7 +159,7 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt,
 	unsigned mode;
 	struct strbuf msg = STRBUF_INIT;
 
-	read_cache();
+	read_index(&the_index);
 	time(&now);
 	commit = alloc_commit_node();
 	commit->object.parsed = 1;
@@ -240,14 +240,14 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt,
 	 * bits; we are not going to write this index out -- we just
 	 * want to run "diff-index --cached".
 	 */
-	discard_cache();
-	read_cache();
+	discard_index(&the_index);
+	read_index(&the_index);
 
 	len = strlen(path);
 	if (!mode) {
-		int pos = cache_name_pos(path, len);
+		int pos = index_name_pos(&the_index, path, len);
 		if (0 <= pos)
-			mode = active_cache[pos]->ce_mode;
+			mode = the_index.cache[pos]->ce_mode;
 		else
 			/* Let's not bother reading from HEAD tree */
 			mode = S_IFREG | 0644;
@@ -259,7 +259,8 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt,
 	ce->ce_flags = create_ce_flags(0);
 	ce->ce_namelen = len;
 	ce->ce_mode = create_ce_mode(mode);
-	add_cache_entry(ce, ADD_CACHE_OK_TO_ADD|ADD_CACHE_OK_TO_REPLACE);
+	add_index_entry(&the_index, ce,
+			ADD_CACHE_OK_TO_ADD | ADD_CACHE_OK_TO_REPLACE);
 
 	cache_tree_invalidate_path(&the_index, path);
 
-- 
2.18.0.rc0.333.g22e6ee6cdf


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH 04/15] check-racy.c: stop using index compat macros
  2018-06-16  5:41 [PATCH 00/15] Kill the_index part 1, expose it Nguyễn Thái Ngọc Duy
                   ` (2 preceding siblings ...)
  2018-06-16  5:41 ` [PATCH 03/15] blame.c: " Nguyễn Thái Ngọc Duy
@ 2018-06-16  5:41 ` Nguyễn Thái Ngọc Duy
  2018-06-16  5:41 ` [PATCH 05/15] diff-lib.c: " Nguyễn Thái Ngọc Duy
                   ` (12 subsequent siblings)
  16 siblings, 0 replies; 32+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2018-06-16  5:41 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 check-racy.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/check-racy.c b/check-racy.c
index 24b6542352..485d7ab8f8 100644
--- a/check-racy.c
+++ b/check-racy.c
@@ -6,9 +6,9 @@ int main(int ac, char **av)
 	int dirty, clean, racy;
 
 	dirty = clean = racy = 0;
-	read_cache();
-	for (i = 0; i < active_nr; i++) {
-		struct cache_entry *ce = active_cache[i];
+	read_index(&the_index);
+	for (i = 0; i < the_index.cache_nr; i++) {
+		struct cache_entry *ce = the_index.cache[i];
 		struct stat st;
 
 		if (lstat(ce->name, &st)) {
@@ -16,9 +16,9 @@ int main(int ac, char **av)
 			continue;
 		}
 
-		if (ce_match_stat(ce, &st, 0))
+		if (ie_match_stat(&the_index, ce, &st, 0))
 			dirty++;
-		else if (ce_match_stat(ce, &st, CE_MATCH_RACY_IS_DIRTY))
+		else if (ie_match_stat(&the_index, ce, &st, CE_MATCH_RACY_IS_DIRTY))
 			racy++;
 		else
 			clean++;
-- 
2.18.0.rc0.333.g22e6ee6cdf


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH 05/15] diff-lib.c: stop using index compat macros
  2018-06-16  5:41 [PATCH 00/15] Kill the_index part 1, expose it Nguyễn Thái Ngọc Duy
                   ` (3 preceding siblings ...)
  2018-06-16  5:41 ` [PATCH 04/15] check-racy.c: " Nguyễn Thái Ngọc Duy
@ 2018-06-16  5:41 ` Nguyễn Thái Ngọc Duy
  2018-06-16  5:41 ` [PATCH 06/15] diff.c: " Nguyễn Thái Ngọc Duy
                   ` (11 subsequent siblings)
  16 siblings, 0 replies; 32+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2018-06-16  5:41 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 diff-lib.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/diff-lib.c b/diff-lib.c
index 104f954a25..56387e1f63 100644
--- a/diff-lib.c
+++ b/diff-lib.c
@@ -70,7 +70,7 @@ static int match_stat_with_submodule(struct diff_options *diffopt,
 				     struct stat *st, unsigned ce_option,
 				     unsigned *dirty_submodule)
 {
-	int changed = ce_match_stat(ce, st, ce_option);
+	int changed = ie_match_stat(&the_index, ce, st, ce_option);
 	if (S_ISGITLINK(ce->ce_mode)) {
 		struct diff_flags orig_flags = diffopt->flags;
 		if (!diffopt->flags.override_submodule_config)
@@ -98,10 +98,10 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
 
 	if (diff_unmerged_stage < 0)
 		diff_unmerged_stage = 2;
-	entries = active_nr;
+	entries = the_index.cache_nr;
 	for (i = 0; i < entries; i++) {
 		unsigned int oldmode, newmode;
-		struct cache_entry *ce = active_cache[i];
+		struct cache_entry *ce = the_index.cache[i];
 		int changed;
 		unsigned dirty_submodule = 0;
 		const struct object_id *old_oid, *new_oid;
@@ -145,7 +145,7 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
 			dpath->mode = wt_mode;
 
 			while (i < entries) {
-				struct cache_entry *nce = active_cache[i];
+				struct cache_entry *nce = the_index.cache[i];
 				int stage;
 
 				if (strcmp(ce->name, nce->name))
-- 
2.18.0.rc0.333.g22e6ee6cdf


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH 06/15] diff.c: stop using index compat macros
  2018-06-16  5:41 [PATCH 00/15] Kill the_index part 1, expose it Nguyễn Thái Ngọc Duy
                   ` (4 preceding siblings ...)
  2018-06-16  5:41 ` [PATCH 05/15] diff-lib.c: " Nguyễn Thái Ngọc Duy
@ 2018-06-16  5:41 ` Nguyễn Thái Ngọc Duy
  2018-06-16  5:41 ` [PATCH 07/15] entry.c: " Nguyễn Thái Ngọc Duy
                   ` (10 subsequent siblings)
  16 siblings, 0 replies; 32+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2018-06-16  5:41 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 diff.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/diff.c b/diff.c
index 136d44b455..975e095ed2 100644
--- a/diff.c
+++ b/diff.c
@@ -3460,7 +3460,7 @@ static int reuse_worktree_file(const char *name, const struct object_id *oid, in
 	 * by diff-cache --cached, which does read the cache before
 	 * calling us.
 	 */
-	if (!active_cache)
+	if (!the_index.cache)
 		return 0;
 
 	/* We want to avoid the working directory if our caller
@@ -3483,10 +3483,10 @@ static int reuse_worktree_file(const char *name, const struct object_id *oid, in
 		return 0;
 
 	len = strlen(name);
-	pos = cache_name_pos(name, len);
+	pos = index_name_pos(&the_index, name, len);
 	if (pos < 0)
 		return 0;
-	ce = active_cache[pos];
+	ce = the_index.cache[pos];
 
 	/*
 	 * This is not the sha1 we are looking for, or
@@ -3506,7 +3506,7 @@ static int reuse_worktree_file(const char *name, const struct object_id *oid, in
 	 * If ce matches the file in the work tree, we can reuse it.
 	 */
 	if (ce_uptodate(ce) ||
-	    (!lstat(name, &st) && !ce_match_stat(ce, &st, 0)))
+	    (!lstat(name, &st) && !ie_match_stat(&the_index, ce, &st, 0)))
 		return 1;
 
 	return 0;
@@ -4216,14 +4216,14 @@ void diff_setup_done(struct diff_options *options)
 	if (options->detect_rename && options->rename_limit < 0)
 		options->rename_limit = diff_rename_limit_default;
 	if (options->setup & DIFF_SETUP_USE_CACHE) {
-		if (!active_cache)
+		if (!the_index.cache)
 			/* read-cache does not die even when it fails
 			 * so it is safe for us to do this here.  Also
 			 * it does not smudge active_cache or active_nr
 			 * when it fails, so we do not have to worry about
 			 * cleaning it up ourselves either.
 			 */
-			read_cache();
+			read_index(&the_index);
 	}
 	if (hexsz < options->abbrev)
 		options->abbrev = hexsz; /* full */
-- 
2.18.0.rc0.333.g22e6ee6cdf


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH 07/15] entry.c: stop using index compat macros
  2018-06-16  5:41 [PATCH 00/15] Kill the_index part 1, expose it Nguyễn Thái Ngọc Duy
                   ` (5 preceding siblings ...)
  2018-06-16  5:41 ` [PATCH 06/15] diff.c: " Nguyễn Thái Ngọc Duy
@ 2018-06-16  5:41 ` Nguyễn Thái Ngọc Duy
  2018-06-16  5:41 ` [PATCH 08/15] merge-recursive.c: " Nguyễn Thái Ngọc Duy
                   ` (9 subsequent siblings)
  16 siblings, 0 replies; 32+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2018-06-16  5:41 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 entry.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/entry.c b/entry.c
index 2101201a11..ec588289fb 100644
--- a/entry.c
+++ b/entry.c
@@ -421,7 +421,8 @@ int checkout_entry(struct cache_entry *ce,
 
 	if (!check_path(path.buf, path.len, &st, state->base_dir_len)) {
 		const struct submodule *sub;
-		unsigned changed = ce_match_stat(ce, &st, CE_MATCH_IGNORE_VALID|CE_MATCH_IGNORE_SKIP_WORKTREE);
+		unsigned changed = ie_match_stat(&the_index, ce, &st,
+						 CE_MATCH_IGNORE_VALID | CE_MATCH_IGNORE_SKIP_WORKTREE);
 		/*
 		 * Needs to be checked before !changed returns early,
 		 * as the possibly empty directory was not changed
-- 
2.18.0.rc0.333.g22e6ee6cdf


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH 08/15] merge-recursive.c: stop using index compat macros
  2018-06-16  5:41 [PATCH 00/15] Kill the_index part 1, expose it Nguyễn Thái Ngọc Duy
                   ` (6 preceding siblings ...)
  2018-06-16  5:41 ` [PATCH 07/15] entry.c: " Nguyễn Thái Ngọc Duy
@ 2018-06-16  5:41 ` Nguyễn Thái Ngọc Duy
  2018-06-16  5:41 ` [PATCH 09/15] merge.c: " Nguyễn Thái Ngọc Duy
                   ` (8 subsequent siblings)
  16 siblings, 0 replies; 32+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2018-06-16  5:41 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 merge-recursive.c | 65 ++++++++++++++++++++++++-----------------------
 1 file changed, 33 insertions(+), 32 deletions(-)

diff --git a/merge-recursive.c b/merge-recursive.c
index 5eb907f46e..2a9dfe3b33 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -319,7 +319,7 @@ static int add_cacheinfo(struct merge_options *o,
 	if (!ce)
 		return err(o, _("add_cacheinfo failed for path '%s'; merge aborting."), path);
 
-	ret = add_cache_entry(ce, options);
+	ret = add_index_entry(&the_index, ce, options);
 	if (refresh) {
 		struct cache_entry *nce;
 
@@ -327,7 +327,7 @@ static int add_cacheinfo(struct merge_options *o,
 		if (!nce)
 			return err(o, _("add_cacheinfo failed to refresh for path '%s'; merge aborting."), path);
 		if (nce != ce)
-			ret = add_cache_entry(nce, options);
+			ret = add_index_entry(&the_index, nce, options);
 	}
 	return ret;
 }
@@ -365,7 +365,7 @@ static int unpack_trees_start(struct merge_options *o,
 	init_tree_desc_from_tree(t+2, merge);
 
 	rc = unpack_trees(3, t, &o->unpack_opts);
-	cache_tree_free(&active_cache_tree);
+	cache_tree_free(&the_index.cache_tree);
 
 	/*
 	 * Update the_index to match the new results, AFTER saving a copy
@@ -390,11 +390,11 @@ struct tree *write_tree_from_memory(struct merge_options *o)
 {
 	struct tree *result = NULL;
 
-	if (unmerged_cache()) {
+	if (unmerged_index(&the_index)) {
 		int i;
 		fprintf(stderr, "BUG: There are unmerged index entries:\n");
-		for (i = 0; i < active_nr; i++) {
-			const struct cache_entry *ce = active_cache[i];
+		for (i = 0; i < the_index.cache_nr; i++) {
+			const struct cache_entry *ce = the_index.cache[i];
 			if (ce_stage(ce))
 				fprintf(stderr, "BUG: %d %.*s\n", ce_stage(ce),
 					(int)ce_namelen(ce), ce->name);
@@ -402,16 +402,16 @@ struct tree *write_tree_from_memory(struct merge_options *o)
 		BUG("unmerged index entries in merge-recursive.c");
 	}
 
-	if (!active_cache_tree)
-		active_cache_tree = cache_tree();
+	if (!the_index.cache_tree)
+		the_index.cache_tree = cache_tree();
 
-	if (!cache_tree_fully_valid(active_cache_tree) &&
+	if (!cache_tree_fully_valid(the_index.cache_tree) &&
 	    cache_tree_update(&the_index, 0) < 0) {
 		err(o, _("error building trees"));
 		return NULL;
 	}
 
-	result = lookup_tree(&active_cache_tree->oid);
+	result = lookup_tree(&the_index.cache_tree->oid);
 
 	return result;
 }
@@ -488,10 +488,10 @@ static struct string_list *get_unmerged(void)
 
 	unmerged->strdup_strings = 1;
 
-	for (i = 0; i < active_nr; i++) {
+	for (i = 0; i < the_index.cache_nr; i++) {
 		struct string_list_item *item;
 		struct stage_data *e;
-		const struct cache_entry *ce = active_cache[i];
+		const struct cache_entry *ce = the_index.cache[i];
 		if (!ce_stage(ce))
 			continue;
 
@@ -651,7 +651,7 @@ static int update_stages(struct merge_options *opt, const char *path,
 	int clear = 1;
 	int options = ADD_CACHE_OK_TO_ADD | ADD_CACHE_SKIP_DFCHECK;
 	if (clear)
-		if (remove_file_from_cache(path))
+		if (remove_file_from_index(&the_index, path))
 			return -1;
 	if (o)
 		if (add_cacheinfo(opt, o->mode, &o->oid, path, 1, 0, options))
@@ -707,13 +707,14 @@ static int remove_file(struct merge_options *o, int clean,
 	int update_working_directory = !o->call_depth && !no_wd;
 
 	if (update_cache) {
-		if (remove_file_from_cache(path))
+		if (remove_file_from_index(&the_index, path))
 			return -1;
 	}
 	if (update_working_directory) {
 		if (ignore_case) {
 			struct cache_entry *ce;
-			ce = cache_file_exists(path, strlen(path), ignore_case);
+			ce = index_file_exists(&the_index, path, strlen(path),
+					       ignore_case);
 			if (ce && ce_stage(ce) == 0 && strcmp(path, ce->name))
 				return 0;
 		}
@@ -772,12 +773,12 @@ static int dir_in_way(const char *path, int check_working_copy, int empty_ok)
 	strbuf_addstr(&dirpath, path);
 	strbuf_addch(&dirpath, '/');
 
-	pos = cache_name_pos(dirpath.buf, dirpath.len);
+	pos = index_name_pos(&the_index, dirpath.buf, dirpath.len);
 
 	if (pos < 0)
 		pos = -1 - pos;
-	if (pos < active_nr &&
-	    !strncmp(dirpath.buf, active_cache[pos]->name, dirpath.len)) {
+	if (pos < the_index.cache_nr &&
+	    !strncmp(dirpath.buf, the_index.cache[pos]->name, dirpath.len)) {
 		strbuf_release(&dirpath);
 		return 1;
 	}
@@ -839,19 +840,19 @@ static int would_lose_untracked(const char *path)
 	 * update_file()/would_lose_untracked(); see every comment in this
 	 * file which mentions "update_stages".
 	 */
-	int pos = cache_name_pos(path, strlen(path));
+	int pos = index_name_pos(&the_index, path, strlen(path));
 
 	if (pos < 0)
 		pos = -1 - pos;
-	while (pos < active_nr &&
-	       !strcmp(path, active_cache[pos]->name)) {
+	while (pos < the_index.cache_nr &&
+	       !strcmp(path, the_index.cache[pos]->name)) {
 		/*
 		 * If stage #0, it is definitely tracked.
 		 * If it has stage #2 then it was tracked
 		 * before this merge started.  All other
 		 * cases the path was not tracked.
 		 */
-		switch (ce_stage(active_cache[pos])) {
+		switch (ce_stage(the_index.cache[pos])) {
 		case 0:
 		case 2:
 			return 0;
@@ -1466,7 +1467,7 @@ static int handle_change_delete(struct merge_options *o,
 		 * correct; since there is no true "middle point" between
 		 * them, simply reuse the base version for virtual merge base.
 		 */
-		ret = remove_file_from_cache(path);
+		ret = remove_file_from_index(&the_index, path);
 		if (!ret)
 			ret = update_file(o, 0, o_oid, o_mode, update_path);
 	} else {
@@ -1527,7 +1528,7 @@ static int conflict_rename_delete(struct merge_options *o,
 		return -1;
 
 	if (o->call_depth)
-		return remove_file_from_cache(dest->path);
+		return remove_file_from_index(&the_index, dest->path);
 	else
 		return update_stages(o, dest->path, NULL,
 				     rename_branch == o->branch1 ? dest : NULL,
@@ -1662,14 +1663,14 @@ static int conflict_rename_rename_1to2(struct merge_options *o,
 				return -1;
 		}
 		else
-			remove_file_from_cache(a->path);
+			remove_file_from_index(&the_index, a->path);
 		add = filespec_from_entry(&other, ci->dst_entry2, 3 ^ 1);
 		if (add) {
 			if (update_file(o, 0, &add->oid, add->mode, b->path))
 				return -1;
 		}
 		else
-			remove_file_from_cache(b->path);
+			remove_file_from_index(&the_index, b->path);
 	} else if (handle_file(o, a, 2, ci) || handle_file(o, b, 3, ci))
 		return -1;
 
@@ -3063,7 +3064,7 @@ static int merge_content(struct merge_options *o,
 	if (df_conflict_remains || is_dirty) {
 		char *new_path;
 		if (o->call_depth) {
-			remove_file_from_cache(path);
+			remove_file_from_index(&the_index, path);
 		} else {
 			if (!mfi.clean) {
 				if (update_stages(o, path, &one, &a, &b))
@@ -3220,7 +3221,7 @@ static int process_entry(struct merge_options *o,
 			if (update_file(o, 0, oid, mode, new_path))
 				clean_merge = -1;
 			else if (o->call_depth)
-				remove_file_from_cache(path);
+				remove_file_from_index(&the_index, path);
 			free(new_path);
 		} else {
 			output(o, 2, _("Adding %s"), path);
@@ -3284,7 +3285,7 @@ int merge_trees(struct merge_options *o,
 		return -1;
 	}
 
-	if (unmerged_cache()) {
+	if (unmerged_index(&the_index)) {
 		struct string_list *entries;
 		struct rename_info re_info;
 		int i;
@@ -3415,7 +3416,7 @@ int merge_recursive(struct merge_options *o,
 		 * overwritten it: the committed "conflicts" were
 		 * already resolved.
 		 */
-		discard_cache();
+		discard_index(&the_index);
 		saved_b1 = o->branch1;
 		saved_b2 = o->branch2;
 		o->branch1 = "Temporary merge branch 1";
@@ -3431,9 +3432,9 @@ int merge_recursive(struct merge_options *o,
 			return err(o, _("merge returned no commit"));
 	}
 
-	discard_cache();
+	discard_index(&the_index);
 	if (!o->call_depth)
-		read_cache();
+		read_index(&the_index);
 
 	o->ancestor = "merged common ancestors";
 	clean = merge_trees(o, get_commit_tree(h1), get_commit_tree(h2),
-- 
2.18.0.rc0.333.g22e6ee6cdf


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH 09/15] merge.c: stop using index compat macros
  2018-06-16  5:41 [PATCH 00/15] Kill the_index part 1, expose it Nguyễn Thái Ngọc Duy
                   ` (7 preceding siblings ...)
  2018-06-16  5:41 ` [PATCH 08/15] merge-recursive.c: " Nguyễn Thái Ngọc Duy
@ 2018-06-16  5:41 ` Nguyễn Thái Ngọc Duy
  2018-06-16  5:41 ` [PATCH 10/15] rerere.c: " Nguyễn Thái Ngọc Duy
                   ` (7 subsequent siblings)
  16 siblings, 0 replies; 32+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2018-06-16  5:41 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 merge.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/merge.c b/merge.c
index 0783858739..21e6dc09be 100644
--- a/merge.c
+++ b/merge.c
@@ -36,12 +36,12 @@ int index_has_changes(struct strbuf *sb)
 		diff_flush(&opt);
 		return opt.flags.has_changes != 0;
 	} else {
-		for (i = 0; sb && i < active_nr; i++) {
+		for (i = 0; sb && i < the_index.cache_nr; i++) {
 			if (i)
 				strbuf_addch(sb, ' ');
-			strbuf_addstr(sb, active_cache[i]->name);
+			strbuf_addstr(sb, the_index.cache[i]->name);
 		}
-		return !!active_nr;
+		return !!the_index.cache_nr;
 	}
 }
 
@@ -66,10 +66,10 @@ int try_merge_command(const char *strategy, size_t xopts_nr,
 	ret = run_command_v_opt(args.argv, RUN_GIT_CMD);
 	argv_array_clear(&args);
 
-	discard_cache();
-	if (read_cache() < 0)
+	discard_index(&the_index);
+	if (read_index(&the_index) < 0)
 		die(_("failed to read the cache"));
-	resolve_undo_clear();
+	resolve_undo_clear_index(&the_index);
 
 	return ret;
 }
@@ -85,7 +85,7 @@ int checkout_fast_forward(const struct object_id *head,
 	struct dir_struct dir;
 	struct lock_file lock_file = LOCK_INIT;
 
-	refresh_cache(REFRESH_QUIET);
+	refresh_index(&the_index, REFRESH_QUIET, NULL, NULL, NULL);
 
 	if (hold_locked_index(&lock_file, LOCK_REPORT_ON_ERROR) < 0)
 		return -1;
-- 
2.18.0.rc0.333.g22e6ee6cdf


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH 10/15] rerere.c: stop using index compat macros
  2018-06-16  5:41 [PATCH 00/15] Kill the_index part 1, expose it Nguyễn Thái Ngọc Duy
                   ` (8 preceding siblings ...)
  2018-06-16  5:41 ` [PATCH 09/15] merge.c: " Nguyễn Thái Ngọc Duy
@ 2018-06-16  5:41 ` Nguyễn Thái Ngọc Duy
  2018-06-16  5:41 ` [PATCH 11/15] revision.c: " Nguyễn Thái Ngọc Duy
                   ` (6 subsequent siblings)
  16 siblings, 0 replies; 32+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2018-06-16  5:41 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 rerere.c | 36 ++++++++++++++++++------------------
 1 file changed, 18 insertions(+), 18 deletions(-)

diff --git a/rerere.c b/rerere.c
index e0862e2778..810e86d246 100644
--- a/rerere.c
+++ b/rerere.c
@@ -524,7 +524,7 @@ static int handle_file(const char *path, unsigned char *sha1, const char *output
  */
 static int check_one_conflict(int i, int *type)
 {
-	const struct cache_entry *e = active_cache[i];
+	const struct cache_entry *e = the_index.cache[i];
 
 	if (!ce_stage(e)) {
 		*type = RESOLVED;
@@ -532,13 +532,13 @@ static int check_one_conflict(int i, int *type)
 	}
 
 	*type = PUNTED;
-	while (ce_stage(active_cache[i]) == 1)
+	while (ce_stage(the_index.cache[i]) == 1)
 		i++;
 
 	/* Only handle regular files with both stages #2 and #3 */
-	if (i + 1 < active_nr) {
-		const struct cache_entry *e2 = active_cache[i];
-		const struct cache_entry *e3 = active_cache[i + 1];
+	if (i + 1 < the_index.cache_nr) {
+		const struct cache_entry *e2 = the_index.cache[i];
+		const struct cache_entry *e3 = the_index.cache[i + 1];
 		if (ce_stage(e2) == 2 &&
 		    ce_stage(e3) == 3 &&
 		    ce_same_name(e, e3) &&
@@ -548,7 +548,7 @@ static int check_one_conflict(int i, int *type)
 	}
 
 	/* Skip the entries with the same name */
-	while (i < active_nr && ce_same_name(e, active_cache[i]))
+	while (i < the_index.cache_nr && ce_same_name(e, the_index.cache[i]))
 		i++;
 	return i;
 }
@@ -567,12 +567,12 @@ static int check_one_conflict(int i, int *type)
 static int find_conflict(struct string_list *conflict)
 {
 	int i;
-	if (read_cache() < 0)
+	if (read_index(&the_index) < 0)
 		return error("Could not read index");
 
-	for (i = 0; i < active_nr;) {
+	for (i = 0; i < the_index.cache_nr;) {
 		int conflict_type;
-		const struct cache_entry *e = active_cache[i];
+		const struct cache_entry *e = the_index.cache[i];
 		i = check_one_conflict(i, &conflict_type);
 		if (conflict_type == THREE_STAGED)
 			string_list_insert(conflict, (const char *)e->name);
@@ -600,12 +600,12 @@ int rerere_remaining(struct string_list *merge_rr)
 	int i;
 	if (setup_rerere(merge_rr, RERERE_READONLY))
 		return 0;
-	if (read_cache() < 0)
+	if (read_index(&the_index) < 0)
 		return error("Could not read index");
 
-	for (i = 0; i < active_nr;) {
+	for (i = 0; i < the_index.cache_nr;) {
 		int conflict_type;
-		const struct cache_entry *e = active_cache[i];
+		const struct cache_entry *e = the_index.cache[i];
 		i = check_one_conflict(i, &conflict_type);
 		if (conflict_type == PUNTED)
 			string_list_insert(merge_rr, (const char *)e->name);
@@ -712,7 +712,7 @@ static void update_paths(struct string_list *update)
 
 	for (i = 0; i < update->nr; i++) {
 		struct string_list_item *item = &update->items[i];
-		if (add_file_to_cache(item->string, 0))
+		if (add_file_to_index(&the_index, item->string, 0))
 			exit(128);
 		fprintf(stderr, "Staged '%s' using previous resolution.\n",
 			item->string);
@@ -964,16 +964,16 @@ static int handle_cache(const char *path, unsigned char *sha1, const char *outpu
 	 * Reproduce the conflicted merge in-core
 	 */
 	len = strlen(path);
-	pos = cache_name_pos(path, len);
+	pos = index_name_pos(&the_index, path, len);
 	if (0 <= pos)
 		return -1;
 	pos = -pos - 1;
 
-	while (pos < active_nr) {
+	while (pos < the_index.cache_nr) {
 		enum object_type type;
 		unsigned long size;
 
-		ce = active_cache[pos++];
+		ce = the_index.cache[pos++];
 		if (ce_namelen(ce) != len || memcmp(ce->name, path, len))
 			break;
 		i = ce_stage(ce) - 1;
@@ -1102,7 +1102,7 @@ int rerere_forget(struct pathspec *pathspec)
 	struct string_list conflict = STRING_LIST_INIT_DUP;
 	struct string_list merge_rr = STRING_LIST_INIT_DUP;
 
-	if (read_cache() < 0)
+	if (read_index(&the_index) < 0)
 		return error("Could not read index");
 
 	fd = setup_rerere(&merge_rr, RERERE_NOAUTOUPDATE);
@@ -1114,7 +1114,7 @@ int rerere_forget(struct pathspec *pathspec)
 	 * recover the original conflicted state and then
 	 * find the conflicted paths.
 	 */
-	unmerge_cache(pathspec);
+	unmerge_index(&the_index, pathspec);
 	find_conflict(&conflict);
 	for (i = 0; i < conflict.nr; i++) {
 		struct string_list_item *it = &conflict.items[i];
-- 
2.18.0.rc0.333.g22e6ee6cdf


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH 11/15] revision.c: stop using index compat macros
  2018-06-16  5:41 [PATCH 00/15] Kill the_index part 1, expose it Nguyễn Thái Ngọc Duy
                   ` (9 preceding siblings ...)
  2018-06-16  5:41 ` [PATCH 10/15] rerere.c: " Nguyễn Thái Ngọc Duy
@ 2018-06-16  5:41 ` Nguyễn Thái Ngọc Duy
  2018-06-16  5:41 ` [PATCH 12/15] sequencer.c: " Nguyễn Thái Ngọc Duy
                   ` (5 subsequent siblings)
  16 siblings, 0 replies; 32+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2018-06-16  5:41 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 revision.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/revision.c b/revision.c
index 40fd91ff2b..d56ca57717 100644
--- a/revision.c
+++ b/revision.c
@@ -1354,7 +1354,7 @@ void add_index_objects_to_pending(struct rev_info *revs, unsigned int flags)
 {
 	struct worktree **worktrees, **p;
 
-	read_cache();
+	read_index(&the_index);
 	do_add_index_objects_to_pending(revs, &the_index);
 
 	if (revs->single_worktree)
@@ -1495,10 +1495,10 @@ static void prepare_show_merge(struct rev_info *revs)
 	free_commit_list(bases);
 	head->object.flags |= SYMMETRIC_LEFT;
 
-	if (!active_nr)
-		read_cache();
-	for (i = 0; i < active_nr; i++) {
-		const struct cache_entry *ce = active_cache[i];
+	if (!the_index.cache_nr)
+		read_index(&the_index);
+	for (i = 0; i < the_index.cache_nr; i++) {
+		const struct cache_entry *ce = the_index.cache[i];
 		if (!ce_stage(ce))
 			continue;
 		if (ce_path_match(ce, &revs->prune_data, NULL)) {
@@ -1507,8 +1507,8 @@ static void prepare_show_merge(struct rev_info *revs)
 			prune[prune_num-2] = ce->name;
 			prune[prune_num-1] = NULL;
 		}
-		while ((i+1 < active_nr) &&
-		       ce_same_name(ce, active_cache[i+1]))
+		while ((i+1 < the_index.cache_nr) &&
+		       ce_same_name(ce, the_index.cache[i+1]))
 			i++;
 	}
 	clear_pathspec(&revs->prune_data);
-- 
2.18.0.rc0.333.g22e6ee6cdf


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH 12/15] sequencer.c: stop using index compat macros
  2018-06-16  5:41 [PATCH 00/15] Kill the_index part 1, expose it Nguyễn Thái Ngọc Duy
                   ` (10 preceding siblings ...)
  2018-06-16  5:41 ` [PATCH 11/15] revision.c: " Nguyễn Thái Ngọc Duy
@ 2018-06-16  5:41 ` Nguyễn Thái Ngọc Duy
  2018-06-16  5:41 ` [PATCH 13/15] sha1-name.c: " Nguyễn Thái Ngọc Duy
                   ` (4 subsequent siblings)
  16 siblings, 0 replies; 32+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2018-06-16  5:41 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 sequencer.c | 32 ++++++++++++++++----------------
 1 file changed, 16 insertions(+), 16 deletions(-)

diff --git a/sequencer.c b/sequencer.c
index cca968043e..ed8af2a4cd 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -435,7 +435,7 @@ static struct tree *empty_tree(void)
 
 static int error_dirty_index(struct replay_opts *opts)
 {
-	if (read_cache_unmerged())
+	if (read_index_unmerged(&the_index))
 		return error_resolve_conflict(_(action_name(opts)));
 
 	error(_("your local changes would be overwritten by %s."),
@@ -467,7 +467,7 @@ static int fast_forward_to(const struct object_id *to, const struct object_id *f
 	struct strbuf sb = STRBUF_INIT;
 	struct strbuf err = STRBUF_INIT;
 
-	read_cache();
+	read_index(&the_index);
 	if (checkout_fast_forward(from, to, 1))
 		return -1; /* the callee should have complained already */
 
@@ -500,12 +500,12 @@ void append_conflicts_hint(struct strbuf *msgbuf)
 
 	strbuf_addch(msgbuf, '\n');
 	strbuf_commented_addf(msgbuf, "Conflicts:\n");
-	for (i = 0; i < active_nr;) {
-		const struct cache_entry *ce = active_cache[i++];
+	for (i = 0; i < the_index.cache_nr;) {
+		const struct cache_entry *ce = the_index.cache[i++];
 		if (ce_stage(ce)) {
 			strbuf_commented_addf(msgbuf, "\t%s\n", ce->name);
-			while (i < active_nr && !strcmp(ce->name,
-							active_cache[i]->name))
+			while (i < the_index.cache_nr && !strcmp(ce->name,
+								 the_index.cache[i]->name))
 				i++;
 		}
 	}
@@ -525,7 +525,7 @@ static int do_recursive_merge(struct commit *base, struct commit *next,
 	if (hold_locked_index(&index_lock, LOCK_REPORT_ON_ERROR) < 0)
 		return -1;
 
-	read_cache();
+	read_index(&the_index);
 
 	init_merge_options(&o);
 	o.ancestor = base ? base_label : "(empty tree)";
@@ -571,16 +571,16 @@ static int do_recursive_merge(struct commit *base, struct commit *next,
 
 static struct object_id *get_cache_tree_oid(void)
 {
-	if (!active_cache_tree)
-		active_cache_tree = cache_tree();
+	if (!the_index.cache_tree)
+		the_index.cache_tree = cache_tree();
 
-	if (!cache_tree_fully_valid(active_cache_tree))
+	if (!cache_tree_fully_valid(the_index.cache_tree))
 		if (cache_tree_update(&the_index, 0)) {
 			error(_("unable to update cache tree"));
 			return NULL;
 		}
 
-	return &active_cache_tree->oid;
+	return &the_index.cache_tree->oid;
 }
 
 static int is_index_unchanged(void)
@@ -1644,7 +1644,7 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,
 				       NULL, 0))
 			return error_dirty_index(opts);
 	}
-	discard_cache();
+	discard_index(&the_index);
 
 	if (!commit->parents)
 		parent = NULL;
@@ -2637,7 +2637,7 @@ static int do_exec(const char *command_line)
 					  child_env.argv);
 
 	/* force re-reading of the cache */
-	if (discard_cache() < 0 || read_cache() < 0)
+	if (discard_index(&the_index) < 0 || read_index(&the_index) < 0)
 		return error(_("could not read index"));
 
 	dirty = require_clean_work_tree("rebase", NULL, 1, 1);
@@ -2801,7 +2801,7 @@ static int do_reset(const char *name, int len, struct replay_opts *opts)
 	unpack_tree_opts.merge = 1;
 	unpack_tree_opts.update = 1;
 
-	if (read_cache_unmerged()) {
+	if (read_index_unmerged(&the_index)) {
 		rollback_lock_file(&lock);
 		strbuf_release(&ref_name);
 		return error_resolve_conflict(_(action_name(opts)));
@@ -2991,7 +2991,7 @@ static int do_merge(struct commit *commit, const char *arg, int arg_len,
 		commit_list_insert(j->item, &reversed);
 	free_commit_list(bases);
 
-	read_cache();
+	read_index(&the_index);
 	init_merge_options(&o);
 	o.branch1 = "HEAD";
 	o.branch2 = ref_name.buf;
@@ -3016,7 +3016,7 @@ static int do_merge(struct commit *commit, const char *arg, int arg_len,
 	 */
 	ret = !ret;
 
-	if (active_cache_changed &&
+	if (the_index.cache_changed &&
 	    write_locked_index(&the_index, &lock, COMMIT_LOCK)) {
 		ret = error(_("merge: Unable to write new index file"));
 		goto leave_merge;
-- 
2.18.0.rc0.333.g22e6ee6cdf


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH 13/15] sha1-name.c: stop using index compat macros
  2018-06-16  5:41 [PATCH 00/15] Kill the_index part 1, expose it Nguyễn Thái Ngọc Duy
                   ` (11 preceding siblings ...)
  2018-06-16  5:41 ` [PATCH 12/15] sequencer.c: " Nguyễn Thái Ngọc Duy
@ 2018-06-16  5:41 ` Nguyễn Thái Ngọc Duy
  2018-06-16  5:41 ` [PATCH 14/15] wt-status.c: " Nguyễn Thái Ngọc Duy
                   ` (3 subsequent siblings)
  16 siblings, 0 replies; 32+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2018-06-16  5:41 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 sha1-name.c | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/sha1-name.c b/sha1-name.c
index 60d9ef3c7e..8344d9a9e0 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -1560,11 +1560,11 @@ static void diagnose_invalid_index_path(int stage,
 		prefix = "";
 
 	/* Wrong stage number? */
-	pos = cache_name_pos(filename, namelen);
+	pos = index_name_pos(&the_index, filename, namelen);
 	if (pos < 0)
 		pos = -pos - 1;
-	if (pos < active_nr) {
-		ce = active_cache[pos];
+	if (pos < the_index.cache_nr) {
+		ce = the_index.cache[pos];
 		if (ce_namelen(ce) == namelen &&
 		    !memcmp(ce->name, filename, namelen))
 			die("Path '%s' is in the index, but not at stage %d.\n"
@@ -1576,11 +1576,11 @@ static void diagnose_invalid_index_path(int stage,
 	/* Confusion between relative and absolute filenames? */
 	strbuf_addstr(&fullname, prefix);
 	strbuf_addstr(&fullname, filename);
-	pos = cache_name_pos(fullname.buf, fullname.len);
+	pos = index_name_pos(&the_index, fullname.buf, fullname.len);
 	if (pos < 0)
 		pos = -pos - 1;
-	if (pos < active_nr) {
-		ce = active_cache[pos];
+	if (pos < the_index.cache_nr) {
+		ce = the_index.cache[pos];
 		if (ce_namelen(ce) == fullname.len &&
 		    !memcmp(ce->name, fullname.buf, fullname.len))
 			die("Path '%s' is in the index, but not '%s'.\n"
@@ -1672,13 +1672,13 @@ static int get_oid_with_context_1(const char *name,
 		if (flags & GET_OID_RECORD_PATH)
 			oc->path = xstrdup(cp);
 
-		if (!active_cache)
-			read_cache();
-		pos = cache_name_pos(cp, namelen);
+		if (!the_index.cache)
+			read_index(&the_index);
+		pos = index_name_pos(&the_index, cp, namelen);
 		if (pos < 0)
 			pos = -pos - 1;
-		while (pos < active_nr) {
-			ce = active_cache[pos];
+		while (pos < the_index.cache_nr) {
+			ce = the_index.cache[pos];
 			if (ce_namelen(ce) != namelen ||
 			    memcmp(ce->name, cp, namelen))
 				break;
-- 
2.18.0.rc0.333.g22e6ee6cdf


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH 14/15] wt-status.c: stop using index compat macros
  2018-06-16  5:41 [PATCH 00/15] Kill the_index part 1, expose it Nguyễn Thái Ngọc Duy
                   ` (12 preceding siblings ...)
  2018-06-16  5:41 ` [PATCH 13/15] sha1-name.c: " Nguyễn Thái Ngọc Duy
@ 2018-06-16  5:41 ` Nguyễn Thái Ngọc Duy
  2018-06-16  5:41 ` [PATCH 15/15] cache.h: flip NO_THE_INDEX_COMPATIBILITY_MACROS switch Nguyễn Thái Ngọc Duy
                   ` (2 subsequent siblings)
  16 siblings, 0 replies; 32+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2018-06-16  5:41 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 wt-status.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/wt-status.c b/wt-status.c
index d1c05145a4..9859a43ec8 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -499,14 +499,14 @@ static int unmerged_mask(const char *path)
 	int pos, mask;
 	const struct cache_entry *ce;
 
-	pos = cache_name_pos(path, strlen(path));
+	pos = index_name_pos(&the_index, path, strlen(path));
 	if (0 <= pos)
 		return 0;
 
 	mask = 0;
 	pos = -pos-1;
-	while (pos < active_nr) {
-		ce = active_cache[pos++];
+	while (pos < the_index.cache_nr) {
+		ce = the_index.cache[pos++];
 		if (strcmp(ce->name, path) || !ce_stage(ce))
 			break;
 		mask |= (1 << (ce_stage(ce) - 1));
@@ -642,10 +642,10 @@ static void wt_status_collect_changes_initial(struct wt_status *s)
 {
 	int i;
 
-	for (i = 0; i < active_nr; i++) {
+	for (i = 0; i < the_index.cache_nr; i++) {
 		struct string_list_item *it;
 		struct wt_status_change_data *d;
-		const struct cache_entry *ce = active_cache[i];
+		const struct cache_entry *ce = the_index.cache[i];
 
 		if (!ce_path_match(ce, &s->pathspec, NULL))
 			continue;
@@ -702,7 +702,7 @@ static void wt_status_collect_untracked(struct wt_status *s)
 
 	for (i = 0; i < dir.nr; i++) {
 		struct dir_entry *ent = dir.entries[i];
-		if (cache_name_is_other(ent->name, ent->len) &&
+		if (index_name_is_other(&the_index, ent->name, ent->len) &&
 		    dir_path_match(ent, &s->pathspec, 0, NULL))
 			string_list_insert(&s->untracked, ent->name);
 		free(ent);
@@ -710,7 +710,7 @@ static void wt_status_collect_untracked(struct wt_status *s)
 
 	for (i = 0; i < dir.ignored_nr; i++) {
 		struct dir_entry *ent = dir.ignored[i];
-		if (cache_name_is_other(ent->name, ent->len) &&
+		if (index_name_is_other(&the_index, ent->name, ent->len) &&
 		    dir_path_match(ent, &s->pathspec, 0, NULL))
 			string_list_insert(&s->ignored, ent->name);
 		free(ent);
@@ -2180,11 +2180,11 @@ static void wt_porcelain_v2_print_unmerged_entry(
 	 */
 	memset(stages, 0, sizeof(stages));
 	sum = 0;
-	pos = cache_name_pos(it->string, strlen(it->string));
+	pos = index_name_pos(&the_index, it->string, strlen(it->string));
 	assert(pos < 0);
 	pos = -pos-1;
-	while (pos < active_nr) {
-		ce = active_cache[pos++];
+	while (pos < the_index.cache_nr) {
+		ce = the_index.cache[pos++];
 		stage = ce_stage(ce);
 		if (strcmp(ce->name, it->string) || !stage)
 			break;
@@ -2333,7 +2333,7 @@ int has_uncommitted_changes(int ignore_submodules)
 	struct rev_info rev_info;
 	int result;
 
-	if (is_cache_unborn())
+	if (is_index_unborn(&the_index))
 		return 0;
 
 	init_revisions(&rev_info, NULL);
@@ -2356,7 +2356,7 @@ int require_clean_work_tree(const char *action, const char *hint, int ignore_sub
 	int err = 0, fd;
 
 	fd = hold_locked_index(&lock_file, 0);
-	refresh_cache(REFRESH_QUIET);
+	refresh_index(&the_index, REFRESH_QUIET, NULL, NULL, NULL);
 	if (0 <= fd)
 		update_index_if_able(&the_index, &lock_file);
 	rollback_lock_file(&lock_file);
-- 
2.18.0.rc0.333.g22e6ee6cdf


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH 15/15] cache.h: flip NO_THE_INDEX_COMPATIBILITY_MACROS switch
  2018-06-16  5:41 [PATCH 00/15] Kill the_index part 1, expose it Nguyễn Thái Ngọc Duy
                   ` (13 preceding siblings ...)
  2018-06-16  5:41 ` [PATCH 14/15] wt-status.c: " Nguyễn Thái Ngọc Duy
@ 2018-06-16  5:41 ` Nguyễn Thái Ngọc Duy
  2018-06-18 18:53   ` Brandon Williams
  2018-06-17  7:02 ` [PATCH 00/15] Kill the_index part 1, expose it Elijah Newren
  2018-06-19 11:48 ` Derrick Stolee
  16 siblings, 1 reply; 32+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2018-06-16  5:41 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

From now on, by default index compat macros are off because they could
hide the_index dependency. Only those in builtin can use it (and even
so should be avoided if possible).

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 attr.c                               | 1 -
 builtin/add.c                        | 1 +
 builtin/am.c                         | 1 +
 builtin/check-attr.c                 | 1 +
 builtin/check-ignore.c               | 1 +
 builtin/checkout-index.c             | 1 +
 builtin/checkout.c                   | 1 +
 builtin/clean.c                      | 1 +
 builtin/commit.c                     | 1 +
 builtin/describe.c                   | 1 +
 builtin/diff-files.c                 | 1 +
 builtin/diff-index.c                 | 1 +
 builtin/diff-tree.c                  | 1 +
 builtin/diff.c                       | 1 +
 builtin/fsck.c                       | 1 +
 builtin/ls-files.c                   | 1 -
 builtin/merge-index.c                | 1 +
 builtin/merge-ours.c                 | 1 +
 builtin/merge.c                      | 1 +
 builtin/mv.c                         | 1 +
 builtin/pull.c                       | 1 +
 builtin/read-tree.c                  | 1 +
 builtin/reset.c                      | 1 +
 builtin/rev-parse.c                  | 1 +
 builtin/rm.c                         | 1 +
 builtin/submodule--helper.c          | 1 +
 builtin/update-index.c               | 1 +
 cache.h                              | 2 +-
 convert.c                            | 1 -
 dir.c                                | 1 -
 name-hash.c                          | 1 -
 pathspec.c                           | 1 -
 read-cache.c                         | 1 -
 submodule.c                          | 1 -
 t/helper/test-dump-untracked-cache.c | 1 +
 t/helper/test-tool.h                 | 2 ++
 tree.c                               | 1 -
 unpack-trees.c                       | 1 -
 38 files changed, 29 insertions(+), 11 deletions(-)

diff --git a/attr.c b/attr.c
index 067fb9e0c0..d16625661d 100644
--- a/attr.c
+++ b/attr.c
@@ -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"
diff --git a/builtin/add.c b/builtin/add.c
index 8a155dd41e..b93193c3fe 100644
--- a/builtin/add.c
+++ b/builtin/add.c
@@ -3,6 +3,7 @@
  *
  * Copyright (C) 2006 Linus Torvalds
  */
+#define USE_THE_INDEX_COMPATIBILITY_MACROS
 #include "cache.h"
 #include "config.h"
 #include "builtin.h"
diff --git a/builtin/am.c b/builtin/am.c
index 2fc2d1e82c..28af59d183 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -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"
diff --git a/builtin/check-attr.c b/builtin/check-attr.c
index 91444dc044..d9cebd5382 100644
--- a/builtin/check-attr.c
+++ b/builtin/check-attr.c
@@ -1,3 +1,4 @@
+#define USE_THE_INDEX_COMPATIBILITY_MACROS
 #include "builtin.h"
 #include "cache.h"
 #include "config.h"
diff --git a/builtin/check-ignore.c b/builtin/check-ignore.c
index ec9a959e08..599097304b 100644
--- a/builtin/check-ignore.c
+++ b/builtin/check-ignore.c
@@ -1,3 +1,4 @@
+#define USE_THE_INDEX_COMPATIBILITY_MACROS
 #include "builtin.h"
 #include "cache.h"
 #include "config.h"
diff --git a/builtin/checkout-index.c b/builtin/checkout-index.c
index a730f6a1aa..e38ad42dbf 100644
--- a/builtin/checkout-index.c
+++ b/builtin/checkout-index.c
@@ -4,6 +4,7 @@
  * Copyright (C) 2005 Linus Torvalds
  *
  */
+#define USE_THE_INDEX_COMPATIBILITY_MACROS
 #include "builtin.h"
 #include "config.h"
 #include "lockfile.h"
diff --git a/builtin/checkout.c b/builtin/checkout.c
index 2e1d2376d2..2250611407 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -1,3 +1,4 @@
+#define USE_THE_INDEX_COMPATIBILITY_MACROS
 #include "builtin.h"
 #include "config.h"
 #include "checkout.h"
diff --git a/builtin/clean.c b/builtin/clean.c
index fad533a0a7..2258379ecc 100644
--- a/builtin/clean.c
+++ b/builtin/clean.c
@@ -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"
diff --git a/builtin/commit.c b/builtin/commit.c
index a842fea666..98a5b4a8c8 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -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"
diff --git a/builtin/describe.c b/builtin/describe.c
index cf1ae77d7c..4ca234972e 100644
--- a/builtin/describe.c
+++ b/builtin/describe.c
@@ -1,3 +1,4 @@
+#define USE_THE_INDEX_COMPATIBILITY_MACROS
 #include "cache.h"
 #include "config.h"
 #include "lockfile.h"
diff --git a/builtin/diff-files.c b/builtin/diff-files.c
index e88493ffe5..af706b4fce 100644
--- a/builtin/diff-files.c
+++ b/builtin/diff-files.c
@@ -3,6 +3,7 @@
  *
  * Copyright (C) Linus Torvalds, 2005
  */
+#define USE_THE_INDEX_COMPATIBILITY_MACROS
 #include "cache.h"
 #include "config.h"
 #include "diff.h"
diff --git a/builtin/diff-index.c b/builtin/diff-index.c
index 522f4fdffd..c026ffb95e 100644
--- a/builtin/diff-index.c
+++ b/builtin/diff-index.c
@@ -1,3 +1,4 @@
+#define USE_THE_INDEX_COMPATIBILITY_MACROS
 #include "cache.h"
 #include "config.h"
 #include "diff.h"
diff --git a/builtin/diff-tree.c b/builtin/diff-tree.c
index 473615117e..bd2264ed5c 100644
--- a/builtin/diff-tree.c
+++ b/builtin/diff-tree.c
@@ -1,3 +1,4 @@
+#define USE_THE_INDEX_COMPATIBILITY_MACROS
 #include "cache.h"
 #include "config.h"
 #include "diff.h"
diff --git a/builtin/diff.c b/builtin/diff.c
index bfefff3a84..17d7d5c9f5 100644
--- a/builtin/diff.c
+++ b/builtin/diff.c
@@ -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"
diff --git a/builtin/fsck.c b/builtin/fsck.c
index 3ad4f160f9..33cb71d269 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -1,3 +1,4 @@
+#define USE_THE_INDEX_COMPATIBILITY_MACROS
 #include "builtin.h"
 #include "cache.h"
 #include "repository.h"
diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index 88bb2019ad..dbf5d13d91 100644
--- a/builtin/ls-files.c
+++ b/builtin/ls-files.c
@@ -5,7 +5,6 @@
  *
  * Copyright (C) Linus Torvalds, 2005
  */
-#define NO_THE_INDEX_COMPATIBILITY_MACROS
 #include "cache.h"
 #include "repository.h"
 #include "config.h"
diff --git a/builtin/merge-index.c b/builtin/merge-index.c
index c99443b095..38ea6ad6ca 100644
--- a/builtin/merge-index.c
+++ b/builtin/merge-index.c
@@ -1,3 +1,4 @@
+#define USE_THE_INDEX_COMPATIBILITY_MACROS
 #include "builtin.h"
 #include "run-command.h"
 
diff --git a/builtin/merge-ours.c b/builtin/merge-ours.c
index c84c6e05e9..7c4a80ed3b 100644
--- a/builtin/merge-ours.c
+++ b/builtin/merge-ours.c
@@ -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"
diff --git a/builtin/merge.c b/builtin/merge.c
index b00d6f4821..1b540e2194 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -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"
diff --git a/builtin/mv.c b/builtin/mv.c
index 80bb967a63..be15ba7044 100644
--- a/builtin/mv.c
+++ b/builtin/mv.c
@@ -3,6 +3,7 @@
  *
  * Copyright (C) 2006 Johannes Schindelin
  */
+#define USE_THE_INDEX_COMPATIBILITY_MACROS
 #include "builtin.h"
 #include "config.h"
 #include "pathspec.h"
diff --git a/builtin/pull.c b/builtin/pull.c
index 1f2ecf3a88..1c3657dee2 100644
--- a/builtin/pull.c
+++ b/builtin/pull.c
@@ -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"
diff --git a/builtin/read-tree.c b/builtin/read-tree.c
index ebc43eb805..ae6ca3a8c5 100644
--- a/builtin/read-tree.c
+++ b/builtin/read-tree.c
@@ -4,6 +4,7 @@
  * Copyright (C) Linus Torvalds, 2005
  */
 
+#define USE_THE_INDEX_COMPATIBILITY_MACROS
 #include "cache.h"
 #include "config.h"
 #include "lockfile.h"
diff --git a/builtin/reset.c b/builtin/reset.c
index a862c70fab..dd60eec9d6 100644
--- a/builtin/reset.c
+++ b/builtin/reset.c
@@ -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"
diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c
index 4f49e96bfd..b5f8d6a83d 100644
--- a/builtin/rev-parse.c
+++ b/builtin/rev-parse.c
@@ -3,6 +3,7 @@
  *
  * Copyright (C) Linus Torvalds, 2005
  */
+#define USE_THE_INDEX_COMPATIBILITY_MACROS
 #include "cache.h"
 #include "config.h"
 #include "commit.h"
diff --git a/builtin/rm.c b/builtin/rm.c
index 65b448ef8e..e5b77e429d 100644
--- a/builtin/rm.c
+++ b/builtin/rm.c
@@ -3,6 +3,7 @@
  *
  * Copyright (C) Linus Torvalds 2006
  */
+#define USE_THE_INDEX_COMPATIBILITY_MACROS
 #include "builtin.h"
 #include "config.h"
 #include "lockfile.h"
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index bd250ca216..8abe15144b 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -1,3 +1,4 @@
+#define USE_THE_INDEX_COMPATIBILITY_MACROS
 #include "builtin.h"
 #include "repository.h"
 #include "cache.h"
diff --git a/builtin/update-index.c b/builtin/update-index.c
index a8709a26ec..36e837248f 100644
--- a/builtin/update-index.c
+++ b/builtin/update-index.c
@@ -3,6 +3,7 @@
  *
  * Copyright (C) Linus Torvalds, 2005
  */
+#define USE_THE_INDEX_COMPATIBILITY_MACROS
 #include "cache.h"
 #include "config.h"
 #include "lockfile.h"
diff --git a/cache.h b/cache.h
index 89a107a7f7..b3a6d14a36 100644
--- a/cache.h
+++ b/cache.h
@@ -339,7 +339,7 @@ extern void remove_name_hash(struct index_state *istate, struct cache_entry *ce)
 extern void free_name_hash(struct index_state *istate);
 
 
-#ifndef NO_THE_INDEX_COMPATIBILITY_MACROS
+#ifdef USE_THE_INDEX_COMPATIBILITY_MACROS
 #define active_cache (the_index.cache)
 #define active_nr (the_index.cache_nr)
 #define active_alloc (the_index.cache_alloc)
diff --git a/convert.c b/convert.c
index 64d0d30e08..0895dc5994 100644
--- a/convert.c
+++ b/convert.c
@@ -1,4 +1,3 @@
-#define NO_THE_INDEX_COMPATIBILITY_MACROS
 #include "cache.h"
 #include "config.h"
 #include "attr.h"
diff --git a/dir.c b/dir.c
index ccf8b4975e..473c47eb2f 100644
--- a/dir.c
+++ b/dir.c
@@ -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"
diff --git a/name-hash.c b/name-hash.c
index 163849831c..12eaa62980 100644
--- a/name-hash.c
+++ b/name-hash.c
@@ -5,7 +5,6 @@
  *
  * Copyright (C) 2008 Linus Torvalds
  */
-#define NO_THE_INDEX_COMPATIBILITY_MACROS
 #include "cache.h"
 
 struct dir_entry {
diff --git a/pathspec.c b/pathspec.c
index 27cd606786..6997707477 100644
--- a/pathspec.c
+++ b/pathspec.c
@@ -1,4 +1,3 @@
-#define NO_THE_INDEX_COMPATIBILITY_MACROS
 #include "cache.h"
 #include "config.h"
 #include "dir.h"
diff --git a/read-cache.c b/read-cache.c
index 372588260e..2a84ad0797 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -3,7 +3,6 @@
  *
  * Copyright (C) Linus Torvalds, 2005
  */
-#define NO_THE_INDEX_COMPATIBILITY_MACROS
 #include "cache.h"
 #include "config.h"
 #include "tempfile.h"
diff --git a/submodule.c b/submodule.c
index 939d6870ec..c6ae29379d 100644
--- a/submodule.c
+++ b/submodule.c
@@ -1,4 +1,3 @@
-#define NO_THE_INDEX_COMPATIBILITY_MACROS
 
 #include "cache.h"
 #include "repository.h"
diff --git a/t/helper/test-dump-untracked-cache.c b/t/helper/test-dump-untracked-cache.c
index bd92fb305a..56a5ce8abb 100644
--- a/t/helper/test-dump-untracked-cache.c
+++ b/t/helper/test-dump-untracked-cache.c
@@ -1,3 +1,4 @@
+#define USE_THE_INDEX_COMPATIBILITY_MACROS
 #include "cache.h"
 #include "dir.h"
 
diff --git a/t/helper/test-tool.h b/t/helper/test-tool.h
index 7116ddfb94..a7ff69e9f3 100644
--- a/t/helper/test-tool.h
+++ b/t/helper/test-tool.h
@@ -1,6 +1,8 @@
 #ifndef __TEST_TOOL_H__
 #define __TEST_TOOL_H__
 
+#define USE_THE_INDEX_COMPATIBILITY_MACROS
+
 int cmd__chmtime(int argc, const char **argv);
 int cmd__config(int argc, const char **argv);
 int cmd__ctype(int argc, const char **argv);
diff --git a/tree.c b/tree.c
index 244eb5e665..b5ed7bc22b 100644
--- a/tree.c
+++ b/tree.c
@@ -1,4 +1,3 @@
-#define NO_THE_INDEX_COMPATIBILITY_MACROS
 #include "cache.h"
 #include "cache-tree.h"
 #include "tree.h"
diff --git a/unpack-trees.c b/unpack-trees.c
index 3a85a02a77..fd09e812a2 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -1,4 +1,3 @@
-#define NO_THE_INDEX_COMPATIBILITY_MACROS
 #include "cache.h"
 #include "argv-array.h"
 #include "repository.h"
-- 
2.18.0.rc0.333.g22e6ee6cdf


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* Re: [PATCH 00/15] Kill the_index part 1, expose it
  2018-06-16  5:41 [PATCH 00/15] Kill the_index part 1, expose it Nguyễn Thái Ngọc Duy
                   ` (14 preceding siblings ...)
  2018-06-16  5:41 ` [PATCH 15/15] cache.h: flip NO_THE_INDEX_COMPATIBILITY_MACROS switch Nguyễn Thái Ngọc Duy
@ 2018-06-17  7:02 ` Elijah Newren
  2018-06-17  8:49   ` Duy Nguyen
  2018-06-19 11:48 ` Derrick Stolee
  16 siblings, 1 reply; 32+ messages in thread
From: Elijah Newren @ 2018-06-17  7:02 UTC (permalink / raw)
  To: Nguyễn Thái Ngọc Duy; +Cc: Git Mailing List

On Fri, Jun 15, 2018 at 10:41 PM, Nguyễn Thái Ngọc Duy
<pclouds@gmail.com> wrote:
> This is the beginning of the end of the_index. The problem with
> the_index is it lets library code anywhere access it freely. This is
> not good because from high level you may not realize that the_index is
> being used while you don't want to touch index at all, or you want to
> use a different index instead.
>
> This is a long series, 86 patches [1], so I'm going to split and
> submit it in 15-20 patches at a time. The first two parts are trivial
> though and could be safely fast tracked if needed.

You post this small little patch about unpack-trees.c, mentioning you
don't know if it's even correct, and bait me into reviewing it and
then spring on me that it's actually nearly 100 patches that need
review...   Very sneaky.  ;-)

> This is the first part, which kills the use of index compat macros
> outside builtin/ and expose the_index in all library code. Later on we
> will ban the_index from one file each time until it's gone for good.
>
> "struct index_state *" will be passed from builtin/ through the call
> chain to the function that needs it. In some cases, "struct
> repository *" will be passed instead when the whole operation spans
> more than just the index.  By the end, the_index becomes part of
> "index compat macros" and cannot be used outside builtin/
>
> Part one is mechanical conversion with the help of coccinelle. The
> only real patches are the first and the last one.

Thanks for the nice division.  I read through all 15 patches, though I
looked at the first and the last a bit closer.  I'm not familiar with
coccinelle yet, but it at least looked relatively straightforward;
would be good to have someone else double check that patch.  Other
than that, the changes look good to me.

Thanks for working on this!

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 00/15] Kill the_index part 1, expose it
  2018-06-17  7:02 ` [PATCH 00/15] Kill the_index part 1, expose it Elijah Newren
@ 2018-06-17  8:49   ` Duy Nguyen
  2018-06-18 18:41     ` Brandon Williams
  0 siblings, 1 reply; 32+ messages in thread
From: Duy Nguyen @ 2018-06-17  8:49 UTC (permalink / raw)
  To: Elijah Newren; +Cc: Git Mailing List

On Sun, Jun 17, 2018 at 9:02 AM Elijah Newren <newren@gmail.com> wrote:
>
> On Fri, Jun 15, 2018 at 10:41 PM, Nguyễn Thái Ngọc Duy
> <pclouds@gmail.com> wrote:
> > This is the beginning of the end of the_index. The problem with
> > the_index is it lets library code anywhere access it freely. This is
> > not good because from high level you may not realize that the_index is
> > being used while you don't want to touch index at all, or you want to
> > use a different index instead.
> >
> > This is a long series, 86 patches [1], so I'm going to split and
> > submit it in 15-20 patches at a time. The first two parts are trivial
> > though and could be safely fast tracked if needed.
>
> You post this small little patch about unpack-trees.c, mentioning you
> don't know if it's even correct, and bait me into reviewing it and
> then spring on me that it's actually nearly 100 patches that need
> review...   Very sneaky.  ;-)

To be fair, it's all Brandon's fault. If he didn't kick the_index out
of dir.c, it would not conflict with one of my out-of-tree patches in
unpack-trees.c, catch my attention and make me go down this rabbit
hole :D
-- 
Duy

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 00/15] Kill the_index part 1, expose it
  2018-06-17  8:49   ` Duy Nguyen
@ 2018-06-18 18:41     ` Brandon Williams
  2018-06-19 19:00       ` Ben Peart
  0 siblings, 1 reply; 32+ messages in thread
From: Brandon Williams @ 2018-06-18 18:41 UTC (permalink / raw)
  To: Duy Nguyen; +Cc: Elijah Newren, Git Mailing List

On 06/17, Duy Nguyen wrote:
> On Sun, Jun 17, 2018 at 9:02 AM Elijah Newren <newren@gmail.com> wrote:
> >
> > On Fri, Jun 15, 2018 at 10:41 PM, Nguyễn Thái Ngọc Duy
> > <pclouds@gmail.com> wrote:
> > > This is the beginning of the end of the_index. The problem with
> > > the_index is it lets library code anywhere access it freely. This is
> > > not good because from high level you may not realize that the_index is
> > > being used while you don't want to touch index at all, or you want to
> > > use a different index instead.
> > >
> > > This is a long series, 86 patches [1], so I'm going to split and
> > > submit it in 15-20 patches at a time. The first two parts are trivial
> > > though and could be safely fast tracked if needed.
> >
> > You post this small little patch about unpack-trees.c, mentioning you
> > don't know if it's even correct, and bait me into reviewing it and
> > then spring on me that it's actually nearly 100 patches that need
> > review...   Very sneaky.  ;-)
> 
> To be fair, it's all Brandon's fault. If he didn't kick the_index out
> of dir.c, it would not conflict with one of my out-of-tree patches in
> unpack-trees.c, catch my attention and make me go down this rabbit
> hole :D

Haha well this is something I've wanted to do for over a year now, glad
you've decided to run with it :)

I guess I've gotten pretty good at getting people to go down rabbit
holes.  First Stefan with the object store refactoring and now you with
the index stuff.  All because I wanted git to be more object oriented
and have less global state ;) 

-- 
Brandon Williams

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 15/15] cache.h: flip NO_THE_INDEX_COMPATIBILITY_MACROS switch
  2018-06-16  5:41 ` [PATCH 15/15] cache.h: flip NO_THE_INDEX_COMPATIBILITY_MACROS switch Nguyễn Thái Ngọc Duy
@ 2018-06-18 18:53   ` Brandon Williams
  0 siblings, 0 replies; 32+ messages in thread
From: Brandon Williams @ 2018-06-18 18:53 UTC (permalink / raw)
  To: Nguyễn Thái Ngọc Duy; +Cc: git

On 06/16, Nguyễn Thái Ngọc Duy wrote:
> From now on, by default index compat macros are off because they could
> hide the_index dependency. Only those in builtin can use it (and even
> so should be avoided if possible).

This is awesome! Now there aren't any compat macros left in the lib code
and the next set of patches has a good base to work from the eliminate
the_index (which I assume based on other mails from you will become part
of the new USE_THE_INDEX_COMPATIBILITY_MACROS macro once its eliminated
from the lib code).

> 
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> ---
>  attr.c                               | 1 -
>  builtin/add.c                        | 1 +
>  builtin/am.c                         | 1 +
>  builtin/check-attr.c                 | 1 +
>  builtin/check-ignore.c               | 1 +
>  builtin/checkout-index.c             | 1 +
>  builtin/checkout.c                   | 1 +
>  builtin/clean.c                      | 1 +
>  builtin/commit.c                     | 1 +
>  builtin/describe.c                   | 1 +
>  builtin/diff-files.c                 | 1 +
>  builtin/diff-index.c                 | 1 +
>  builtin/diff-tree.c                  | 1 +
>  builtin/diff.c                       | 1 +
>  builtin/fsck.c                       | 1 +
>  builtin/ls-files.c                   | 1 -
>  builtin/merge-index.c                | 1 +
>  builtin/merge-ours.c                 | 1 +
>  builtin/merge.c                      | 1 +
>  builtin/mv.c                         | 1 +
>  builtin/pull.c                       | 1 +
>  builtin/read-tree.c                  | 1 +
>  builtin/reset.c                      | 1 +
>  builtin/rev-parse.c                  | 1 +
>  builtin/rm.c                         | 1 +
>  builtin/submodule--helper.c          | 1 +
>  builtin/update-index.c               | 1 +
>  cache.h                              | 2 +-
>  convert.c                            | 1 -
>  dir.c                                | 1 -
>  name-hash.c                          | 1 -
>  pathspec.c                           | 1 -
>  read-cache.c                         | 1 -
>  submodule.c                          | 1 -
>  t/helper/test-dump-untracked-cache.c | 1 +
>  t/helper/test-tool.h                 | 2 ++
>  tree.c                               | 1 -
>  unpack-trees.c                       | 1 -
>  38 files changed, 29 insertions(+), 11 deletions(-)
> 
> diff --git a/attr.c b/attr.c
> index 067fb9e0c0..d16625661d 100644
> --- a/attr.c
> +++ b/attr.c
> @@ -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"
> diff --git a/builtin/add.c b/builtin/add.c
> index 8a155dd41e..b93193c3fe 100644
> --- a/builtin/add.c
> +++ b/builtin/add.c
> @@ -3,6 +3,7 @@
>   *
>   * Copyright (C) 2006 Linus Torvalds
>   */
> +#define USE_THE_INDEX_COMPATIBILITY_MACROS
>  #include "cache.h"
>  #include "config.h"
>  #include "builtin.h"
> diff --git a/builtin/am.c b/builtin/am.c
> index 2fc2d1e82c..28af59d183 100644
> --- a/builtin/am.c
> +++ b/builtin/am.c
> @@ -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"
> diff --git a/builtin/check-attr.c b/builtin/check-attr.c
> index 91444dc044..d9cebd5382 100644
> --- a/builtin/check-attr.c
> +++ b/builtin/check-attr.c
> @@ -1,3 +1,4 @@
> +#define USE_THE_INDEX_COMPATIBILITY_MACROS
>  #include "builtin.h"
>  #include "cache.h"
>  #include "config.h"
> diff --git a/builtin/check-ignore.c b/builtin/check-ignore.c
> index ec9a959e08..599097304b 100644
> --- a/builtin/check-ignore.c
> +++ b/builtin/check-ignore.c
> @@ -1,3 +1,4 @@
> +#define USE_THE_INDEX_COMPATIBILITY_MACROS
>  #include "builtin.h"
>  #include "cache.h"
>  #include "config.h"
> diff --git a/builtin/checkout-index.c b/builtin/checkout-index.c
> index a730f6a1aa..e38ad42dbf 100644
> --- a/builtin/checkout-index.c
> +++ b/builtin/checkout-index.c
> @@ -4,6 +4,7 @@
>   * Copyright (C) 2005 Linus Torvalds
>   *
>   */
> +#define USE_THE_INDEX_COMPATIBILITY_MACROS
>  #include "builtin.h"
>  #include "config.h"
>  #include "lockfile.h"
> diff --git a/builtin/checkout.c b/builtin/checkout.c
> index 2e1d2376d2..2250611407 100644
> --- a/builtin/checkout.c
> +++ b/builtin/checkout.c
> @@ -1,3 +1,4 @@
> +#define USE_THE_INDEX_COMPATIBILITY_MACROS
>  #include "builtin.h"
>  #include "config.h"
>  #include "checkout.h"
> diff --git a/builtin/clean.c b/builtin/clean.c
> index fad533a0a7..2258379ecc 100644
> --- a/builtin/clean.c
> +++ b/builtin/clean.c
> @@ -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"
> diff --git a/builtin/commit.c b/builtin/commit.c
> index a842fea666..98a5b4a8c8 100644
> --- a/builtin/commit.c
> +++ b/builtin/commit.c
> @@ -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"
> diff --git a/builtin/describe.c b/builtin/describe.c
> index cf1ae77d7c..4ca234972e 100644
> --- a/builtin/describe.c
> +++ b/builtin/describe.c
> @@ -1,3 +1,4 @@
> +#define USE_THE_INDEX_COMPATIBILITY_MACROS
>  #include "cache.h"
>  #include "config.h"
>  #include "lockfile.h"
> diff --git a/builtin/diff-files.c b/builtin/diff-files.c
> index e88493ffe5..af706b4fce 100644
> --- a/builtin/diff-files.c
> +++ b/builtin/diff-files.c
> @@ -3,6 +3,7 @@
>   *
>   * Copyright (C) Linus Torvalds, 2005
>   */
> +#define USE_THE_INDEX_COMPATIBILITY_MACROS
>  #include "cache.h"
>  #include "config.h"
>  #include "diff.h"
> diff --git a/builtin/diff-index.c b/builtin/diff-index.c
> index 522f4fdffd..c026ffb95e 100644
> --- a/builtin/diff-index.c
> +++ b/builtin/diff-index.c
> @@ -1,3 +1,4 @@
> +#define USE_THE_INDEX_COMPATIBILITY_MACROS
>  #include "cache.h"
>  #include "config.h"
>  #include "diff.h"
> diff --git a/builtin/diff-tree.c b/builtin/diff-tree.c
> index 473615117e..bd2264ed5c 100644
> --- a/builtin/diff-tree.c
> +++ b/builtin/diff-tree.c
> @@ -1,3 +1,4 @@
> +#define USE_THE_INDEX_COMPATIBILITY_MACROS
>  #include "cache.h"
>  #include "config.h"
>  #include "diff.h"
> diff --git a/builtin/diff.c b/builtin/diff.c
> index bfefff3a84..17d7d5c9f5 100644
> --- a/builtin/diff.c
> +++ b/builtin/diff.c
> @@ -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"
> diff --git a/builtin/fsck.c b/builtin/fsck.c
> index 3ad4f160f9..33cb71d269 100644
> --- a/builtin/fsck.c
> +++ b/builtin/fsck.c
> @@ -1,3 +1,4 @@
> +#define USE_THE_INDEX_COMPATIBILITY_MACROS
>  #include "builtin.h"
>  #include "cache.h"
>  #include "repository.h"
> diff --git a/builtin/ls-files.c b/builtin/ls-files.c
> index 88bb2019ad..dbf5d13d91 100644
> --- a/builtin/ls-files.c
> +++ b/builtin/ls-files.c
> @@ -5,7 +5,6 @@
>   *
>   * Copyright (C) Linus Torvalds, 2005
>   */
> -#define NO_THE_INDEX_COMPATIBILITY_MACROS
>  #include "cache.h"
>  #include "repository.h"
>  #include "config.h"
> diff --git a/builtin/merge-index.c b/builtin/merge-index.c
> index c99443b095..38ea6ad6ca 100644
> --- a/builtin/merge-index.c
> +++ b/builtin/merge-index.c
> @@ -1,3 +1,4 @@
> +#define USE_THE_INDEX_COMPATIBILITY_MACROS
>  #include "builtin.h"
>  #include "run-command.h"
>  
> diff --git a/builtin/merge-ours.c b/builtin/merge-ours.c
> index c84c6e05e9..7c4a80ed3b 100644
> --- a/builtin/merge-ours.c
> +++ b/builtin/merge-ours.c
> @@ -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"
> diff --git a/builtin/merge.c b/builtin/merge.c
> index b00d6f4821..1b540e2194 100644
> --- a/builtin/merge.c
> +++ b/builtin/merge.c
> @@ -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"
> diff --git a/builtin/mv.c b/builtin/mv.c
> index 80bb967a63..be15ba7044 100644
> --- a/builtin/mv.c
> +++ b/builtin/mv.c
> @@ -3,6 +3,7 @@
>   *
>   * Copyright (C) 2006 Johannes Schindelin
>   */
> +#define USE_THE_INDEX_COMPATIBILITY_MACROS
>  #include "builtin.h"
>  #include "config.h"
>  #include "pathspec.h"
> diff --git a/builtin/pull.c b/builtin/pull.c
> index 1f2ecf3a88..1c3657dee2 100644
> --- a/builtin/pull.c
> +++ b/builtin/pull.c
> @@ -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"
> diff --git a/builtin/read-tree.c b/builtin/read-tree.c
> index ebc43eb805..ae6ca3a8c5 100644
> --- a/builtin/read-tree.c
> +++ b/builtin/read-tree.c
> @@ -4,6 +4,7 @@
>   * Copyright (C) Linus Torvalds, 2005
>   */
>  
> +#define USE_THE_INDEX_COMPATIBILITY_MACROS
>  #include "cache.h"
>  #include "config.h"
>  #include "lockfile.h"
> diff --git a/builtin/reset.c b/builtin/reset.c
> index a862c70fab..dd60eec9d6 100644
> --- a/builtin/reset.c
> +++ b/builtin/reset.c
> @@ -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"
> diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c
> index 4f49e96bfd..b5f8d6a83d 100644
> --- a/builtin/rev-parse.c
> +++ b/builtin/rev-parse.c
> @@ -3,6 +3,7 @@
>   *
>   * Copyright (C) Linus Torvalds, 2005
>   */
> +#define USE_THE_INDEX_COMPATIBILITY_MACROS
>  #include "cache.h"
>  #include "config.h"
>  #include "commit.h"
> diff --git a/builtin/rm.c b/builtin/rm.c
> index 65b448ef8e..e5b77e429d 100644
> --- a/builtin/rm.c
> +++ b/builtin/rm.c
> @@ -3,6 +3,7 @@
>   *
>   * Copyright (C) Linus Torvalds 2006
>   */
> +#define USE_THE_INDEX_COMPATIBILITY_MACROS
>  #include "builtin.h"
>  #include "config.h"
>  #include "lockfile.h"
> diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
> index bd250ca216..8abe15144b 100644
> --- a/builtin/submodule--helper.c
> +++ b/builtin/submodule--helper.c
> @@ -1,3 +1,4 @@
> +#define USE_THE_INDEX_COMPATIBILITY_MACROS
>  #include "builtin.h"
>  #include "repository.h"
>  #include "cache.h"
> diff --git a/builtin/update-index.c b/builtin/update-index.c
> index a8709a26ec..36e837248f 100644
> --- a/builtin/update-index.c
> +++ b/builtin/update-index.c
> @@ -3,6 +3,7 @@
>   *
>   * Copyright (C) Linus Torvalds, 2005
>   */
> +#define USE_THE_INDEX_COMPATIBILITY_MACROS
>  #include "cache.h"
>  #include "config.h"
>  #include "lockfile.h"
> diff --git a/cache.h b/cache.h
> index 89a107a7f7..b3a6d14a36 100644
> --- a/cache.h
> +++ b/cache.h
> @@ -339,7 +339,7 @@ extern void remove_name_hash(struct index_state *istate, struct cache_entry *ce)
>  extern void free_name_hash(struct index_state *istate);
>  
>  
> -#ifndef NO_THE_INDEX_COMPATIBILITY_MACROS
> +#ifdef USE_THE_INDEX_COMPATIBILITY_MACROS
>  #define active_cache (the_index.cache)
>  #define active_nr (the_index.cache_nr)
>  #define active_alloc (the_index.cache_alloc)
> diff --git a/convert.c b/convert.c
> index 64d0d30e08..0895dc5994 100644
> --- a/convert.c
> +++ b/convert.c
> @@ -1,4 +1,3 @@
> -#define NO_THE_INDEX_COMPATIBILITY_MACROS
>  #include "cache.h"
>  #include "config.h"
>  #include "attr.h"
> diff --git a/dir.c b/dir.c
> index ccf8b4975e..473c47eb2f 100644
> --- a/dir.c
> +++ b/dir.c
> @@ -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"
> diff --git a/name-hash.c b/name-hash.c
> index 163849831c..12eaa62980 100644
> --- a/name-hash.c
> +++ b/name-hash.c
> @@ -5,7 +5,6 @@
>   *
>   * Copyright (C) 2008 Linus Torvalds
>   */
> -#define NO_THE_INDEX_COMPATIBILITY_MACROS
>  #include "cache.h"
>  
>  struct dir_entry {
> diff --git a/pathspec.c b/pathspec.c
> index 27cd606786..6997707477 100644
> --- a/pathspec.c
> +++ b/pathspec.c
> @@ -1,4 +1,3 @@
> -#define NO_THE_INDEX_COMPATIBILITY_MACROS
>  #include "cache.h"
>  #include "config.h"
>  #include "dir.h"
> diff --git a/read-cache.c b/read-cache.c
> index 372588260e..2a84ad0797 100644
> --- a/read-cache.c
> +++ b/read-cache.c
> @@ -3,7 +3,6 @@
>   *
>   * Copyright (C) Linus Torvalds, 2005
>   */
> -#define NO_THE_INDEX_COMPATIBILITY_MACROS
>  #include "cache.h"
>  #include "config.h"
>  #include "tempfile.h"
> diff --git a/submodule.c b/submodule.c
> index 939d6870ec..c6ae29379d 100644
> --- a/submodule.c
> +++ b/submodule.c
> @@ -1,4 +1,3 @@
> -#define NO_THE_INDEX_COMPATIBILITY_MACROS
>  
>  #include "cache.h"
>  #include "repository.h"
> diff --git a/t/helper/test-dump-untracked-cache.c b/t/helper/test-dump-untracked-cache.c
> index bd92fb305a..56a5ce8abb 100644
> --- a/t/helper/test-dump-untracked-cache.c
> +++ b/t/helper/test-dump-untracked-cache.c
> @@ -1,3 +1,4 @@
> +#define USE_THE_INDEX_COMPATIBILITY_MACROS
>  #include "cache.h"
>  #include "dir.h"
>  
> diff --git a/t/helper/test-tool.h b/t/helper/test-tool.h
> index 7116ddfb94..a7ff69e9f3 100644
> --- a/t/helper/test-tool.h
> +++ b/t/helper/test-tool.h
> @@ -1,6 +1,8 @@
>  #ifndef __TEST_TOOL_H__
>  #define __TEST_TOOL_H__
>  
> +#define USE_THE_INDEX_COMPATIBILITY_MACROS
> +
>  int cmd__chmtime(int argc, const char **argv);
>  int cmd__config(int argc, const char **argv);
>  int cmd__ctype(int argc, const char **argv);
> diff --git a/tree.c b/tree.c
> index 244eb5e665..b5ed7bc22b 100644
> --- a/tree.c
> +++ b/tree.c
> @@ -1,4 +1,3 @@
> -#define NO_THE_INDEX_COMPATIBILITY_MACROS
>  #include "cache.h"
>  #include "cache-tree.h"
>  #include "tree.h"
> diff --git a/unpack-trees.c b/unpack-trees.c
> index 3a85a02a77..fd09e812a2 100644
> --- a/unpack-trees.c
> +++ b/unpack-trees.c
> @@ -1,4 +1,3 @@
> -#define NO_THE_INDEX_COMPATIBILITY_MACROS
>  #include "cache.h"
>  #include "argv-array.h"
>  #include "repository.h"
> -- 
> 2.18.0.rc0.333.g22e6ee6cdf
> 

-- 
Brandon Williams

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 01/15] contrib: add cocci script to replace index compat macros
  2018-06-16  5:41 ` [PATCH 01/15] contrib: add cocci script to replace index compat macros Nguyễn Thái Ngọc Duy
@ 2018-06-19 11:35   ` Derrick Stolee
  2018-06-19 11:41     ` Derrick Stolee
  0 siblings, 1 reply; 32+ messages in thread
From: Derrick Stolee @ 2018-06-19 11:35 UTC (permalink / raw)
  To: Nguyễn Thái Ngọc Duy, git

On 6/16/2018 1:41 AM, Nguyễn Thái Ngọc Duy wrote:
> Index compat macros are going to be removed to expose the_index and
> then reorganized to use the right index instead of simply the_index
> because sometimes we want to use a different index.
>
> This cocci script can help with the first step. It can be used later
> on on even builtin/ when we start to reorganize code in there, but for
> now this is the script that performs all the conversion outside
> builtin/

I pulled your code and ran `make coccicheck` and got quite a large patch 
as a result.

Perhaps reorder the commits in your large patch with this one at the 
end? It's helpful to see what your mechanical changes are going to be, 
but let's save it for when `make coccicheck` is stable.

>
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> ---
>   contrib/coccinelle/index-compat.cocci | 184 ++++++++++++++++++++++++++
>   1 file changed, 184 insertions(+)
>   create mode 100644 contrib/coccinelle/index-compat.cocci
>
> diff --git a/contrib/coccinelle/index-compat.cocci b/contrib/coccinelle/index-compat.cocci
> new file mode 100644
> index 0000000000..ca46711eb6
> --- /dev/null
> +++ b/contrib/coccinelle/index-compat.cocci
> @@ -0,0 +1,184 @@
> +@@
> +@@
> +-active_cache
> ++the_index.cache
> +
> +@@
> +@@
> +-active_nr
> ++the_index.cache_nr
> +
> +@@
> +@@
> +-active_alloc
> ++the_index.cache_alloc
> +
> +@@
> +@@
> +-active_cache_changed
> ++the_index.cache_changed
> +
> +@@
> +@@
> +-active_cache_tree
> ++the_index.cache_tree
> +
> +@@
> +@@
> +- read_cache()
> ++ read_index(&the_index)
> +
> +@@
> +expression path;
> +@@
> +- read_cache_from(path)
> ++ read_index_from(&the_index, path, get_git_dir())
> +
> +@@
> +expression pathspec;
> +@@
> +- read_cache_preload(pathspec)
> ++ read_index_preload(&the_index, pathspec)
> +
> +@@
> +@@
> +- is_cache_unborn()
> ++ is_index_unborn(&the_index)
> +
> +@@
> +@@
> +- read_cache_unmerged()
> ++ read_index_unmerged(&the_index)
> +
> +@@
> +@@
> +- discard_cache()
> ++ discard_index(&the_index)
> +
> +@@
> +@@
> +- unmerged_cache()
> ++ unmerged_index(&the_index)
> +
> +@@
> +expression name;
> +expression namelen;
> +@@
> +- cache_name_pos(name, namelen)
> ++ index_name_pos(&the_index, name, namelen)
> +
> +@@
> +expression ce;
> +expression option;
> +@@
> +- add_cache_entry(ce, option)
> ++ add_index_entry(&the_index, ce, option)
> +
> +@@
> +expression pos;
> +expression new_name;
> +@@
> +- rename_cache_entry_at(pos, new_name)
> ++ rename_index_entry_at(&the_index, pos, new_name)
> +
> +@@
> +expression pos;
> +@@
> +- remove_cache_entry_at(pos)
> ++ remove_index_entry_at(&the_index, pos)
> +
> +@@
> +expression path;
> +@@
> +- remove_file_from_cache(path)
> ++ remove_file_from_index(&the_index, path)
> +
> +@@
> +expression path;
> +expression st;
> +expression flags;
> +@@
> +- add_to_cache(path, st, flags)
> ++ add_to_index(&the_index, path, st, flags)
> +
> +@@
> +expression path;
> +expression flags;
> +@@
> +- add_file_to_cache(path, flags)
> ++ add_file_to_index(&the_index, path, flags)
> +
> +@@
> +expression ce;
> +expression flip;
> +@@
> +-chmod_cache_entry(ce, flip)
> ++chmod_index_entry(&the_index, ce, flip)
> +
> +@@
> +expression flags;
> +@@
> +-refresh_cache(flags)
> ++refresh_index(&the_index, flags, NULL, NULL, NULL)
> +
> +@@
> +expression ce;
> +expression st;
> +expression options;
> +@@
> +-ce_match_stat(ce, st, options)
> ++ie_match_stat(&the_index, ce, st, options)
> +
> +@@
> +expression ce;
> +expression st;
> +expression options;
> +@@
> +-ce_modified(ce, st, options)
> ++ie_modified(&the_index, ce, st, options)
> +
> +@@
> +expression name;
> +expression namelen;
> +@@
> +-cache_dir_exists(name, namelen)
> ++index_dir_exists(&the_index, name, namelen)
> +
> +@@
> +expression name;
> +expression namelen;
> +expression igncase;
> +@@
> +-cache_file_exists(name, namelen, igncase)
> ++index_file_exists(&the_index, name, namelen, igncase)
> +
> +@@
> +expression name;
> +expression namelen;
> +@@
> +-cache_name_is_other(name, namelen)
> ++index_name_is_other(&the_index, name, namelen)
> +
> +@@
> +@@
> +-resolve_undo_clear()
> ++resolve_undo_clear_index(&the_index)
> +
> +@@
> +expression at;
> +@@
> +-unmerge_cache_entry_at(at)
> ++unmerge_index_entry_at(&the_index, at)
> +
> +@@
> +expression pathspec;
> +@@
> +-unmerge_cache(pathspec)
> ++unmerge_index(&the_index, pathspec)
> +
> +@@
> +expression path;
> +expression sz;
> +@@
> +-read_blob_data_from_cache(path, sz)
> ++read_blob_data_from_index(&the_index, path, sz)


^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 01/15] contrib: add cocci script to replace index compat macros
  2018-06-19 11:35   ` Derrick Stolee
@ 2018-06-19 11:41     ` Derrick Stolee
  2018-06-19 14:51       ` Duy Nguyen
  0 siblings, 1 reply; 32+ messages in thread
From: Derrick Stolee @ 2018-06-19 11:41 UTC (permalink / raw)
  To: git; +Cc: pclouds

Duy,

Here is the patch that was generated by `make coccicheck`.

Thanks,
-Stolee

-->8--

--- builtin/add.c
+++ /tmp/cocci-output-206193-4c91ec-add.c
@@ -38,13 +38,13 @@ static void chmod_pathspec(struct pathsp
 {
 	int i;
 
-	for (i = 0; i < active_nr; i++) {
-		struct cache_entry *ce = active_cache[i];
+	for (i = 0; i < the_index.cache_nr; i++) {
+		struct cache_entry *ce = the_index.cache[i];
 
 		if (pathspec && !ce_path_match(&the_index, ce, pathspec, NULL))
 			continue;
 
-		if (chmod_cache_entry(ce, flip) < 0)
+		if (chmod_index_entry(&the_index, ce, flip) < 0)
 			fprintf(stderr, "cannot chmod %cx '%s'\n", flip, ce->name);
 	}
 }
@@ -129,8 +129,8 @@ static int renormalize_tracked_files(con
 {
 	int i, retval = 0;
 
-	for (i = 0; i < active_nr; i++) {
-		struct cache_entry *ce = active_cache[i];
+	for (i = 0; i < the_index.cache_nr; i++) {
+		struct cache_entry *ce = the_index.cache[i];
 
 		if (ce_stage(ce))
 			continue; /* do not touch unmerged paths */
@@ -138,7 +138,8 @@ static int renormalize_tracked_files(con
 			continue; /* do not touch non blobs */
 		if (pathspec && !ce_path_match(&the_index, ce, pathspec, NULL))
 			continue;
-		retval |= add_file_to_cache(ce->name, flags | HASH_RENORMALIZE);
+		retval |= add_file_to_index(&the_index, ce->name,
+					    flags | HASH_RENORMALIZE);
 	}
 
 	return retval;
@@ -230,7 +231,7 @@ static int edit_patch(int argc, const ch
 
 	git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
 
-	if (read_cache() < 0)
+	if (read_index(&the_index) < 0)
 		die(_("Could not read the index"));
 
 	init_revisions(&rev, the_repository, prefix);
@@ -445,7 +446,7 @@ int cmd_add(int argc, const char **argv,
 		return 0;
 	}
 
-	if (read_cache() < 0)
+	if (read_index(&the_index) < 0)
 		die(_("index file corrupt"));
 
 	die_in_unpopulated_submodule(&the_index, prefix);
--- builtin/am.c
+++ /tmp/cocci-output-206198-3fcbd5-am.c
@@ -1144,7 +1144,7 @@ static void refresh_and_write_cache(void
 	struct lock_file lock_file = LOCK_INIT;
 
 	hold_locked_index(&lock_file, LOCK_DIE_ON_ERROR);
-	refresh_cache(REFRESH_QUIET);
+	refresh_index(&the_index, REFRESH_QUIET, NULL, NULL, NULL);
 	if (write_locked_index(&the_index, &lock_file, COMMIT_LOCK))
 		die(_("unable to write index file"));
 }
@@ -1505,8 +1505,8 @@ static int run_apply(const struct am_sta
 
 	if (index_file) {
 		/* Reload index as apply_all_patches() will have modified it. */
-		discard_cache();
-		read_cache_from(index_file);
+		discard_index(&the_index);
+		read_index_from(&the_index, index_file, get_git_dir());
 	}
 
 	return 0;
@@ -1548,8 +1548,8 @@ static int fall_back_threeway(const stru
 	if (build_fake_ancestor(state, index_path))
 		return error("could not build fake ancestor");
 
-	discard_cache();
-	read_cache_from(index_path);
+	discard_index(&the_index);
+	read_index_from(&the_index, index_path, get_git_dir());
 
 	if (write_index_as_tree(&orig_tree, &the_index, index_path, 0, NULL))
 		return error(_("Repository lacks necessary blobs to fall back on 3-way merge."));
@@ -1581,8 +1581,8 @@ static int fall_back_threeway(const stru
 
 	say(state, stdout, _("Falling back to patching base and 3-way merge..."));
 
-	discard_cache();
-	read_cache();
+	discard_index(&the_index);
+	read_index(&the_index);
 
 	/*
 	 * This is not so wrong. Depending on which base we picked, orig_tree
@@ -1886,7 +1886,7 @@ static void am_resolve(struct am_state *
 		die_user_resolve(state);
 	}
 
-	if (unmerged_cache()) {
+	if (unmerged_index(&the_index)) {
 		printf_ln(_("You still have unmerged paths in your index.\n"
 			"You should 'git add' each file with resolved conflicts to mark them as such.\n"
 			"You might run `git rm` on a file to accept \"deleted by them\" for it."));
@@ -1925,7 +1925,7 @@ static int fast_forward_to(struct tree *
 
 	hold_locked_index(&lock_file, LOCK_DIE_ON_ERROR);
 
-	refresh_cache(REFRESH_QUIET);
+	refresh_index(&the_index, REFRESH_QUIET, NULL, NULL, NULL);
 
 	memset(&opts, 0, sizeof(opts));
 	opts.head_idx = 1;
@@ -2000,7 +2000,7 @@ static int clean_index(const struct obje
 	if (!remote_tree)
 		return error(_("Could not parse object '%s'."), oid_to_hex(remote));
 
-	read_cache_unmerged();
+	read_index_unmerged(&the_index);
 
 	if (fast_forward_to(head_tree, head_tree, 1))
 		return -1;
--- builtin/check-attr.c
+++ /tmp/cocci-output-206211-cd89a4-check-attr.c
@@ -116,7 +116,7 @@ int cmd_check_attr(int argc, const char
 	argc = parse_options(argc, argv, prefix, check_attr_options,
 			     check_attr_usage, PARSE_OPT_KEEP_DASHDASH);
 
-	if (read_cache() < 0) {
+	if (read_index(&the_index) < 0) {
 		die("invalid cache");
 	}
 
--- builtin/check-ignore.c
+++ /tmp/cocci-output-206216-286c84-check-ignore.c
@@ -174,7 +174,7 @@ int cmd_check_ignore(int argc, const cha
 		die(_("--non-matching is only valid with --verbose"));
 
 	/* read_cache() is only necessary so we can watch out for submodules. */
-	if (!no_index && read_cache() < 0)
+	if (!no_index && read_index(&the_index) < 0)
 		die(_("index file corrupt"));
 
 	memset(&dir, 0, sizeof(dir));
--- builtin/checkout-index.c
+++ /tmp/cocci-output-206223-d5d099-checkout-index.c
@@ -48,7 +48,7 @@ static void write_tempfile_record(const
 static int checkout_file(const char *name, const char *prefix)
 {
 	int namelen = strlen(name);
-	int pos = cache_name_pos(name, namelen);
+	int pos = index_name_pos(&the_index, name, namelen);
 	int has_same_name = 0;
 	int did_checkout = 0;
 	int errs = 0;
@@ -56,8 +56,8 @@ static int checkout_file(const char *nam
 	if (pos < 0)
 		pos = -pos - 1;
 
-	while (pos < active_nr) {
-		struct cache_entry *ce = active_cache[pos];
+	while (pos < the_index.cache_nr) {
+		struct cache_entry *ce = the_index.cache[pos];
 		if (ce_namelen(ce) != namelen ||
 		    memcmp(ce->name, name, namelen))
 			break;
@@ -97,8 +97,8 @@ static void checkout_all(const char *pre
 	int i, errs = 0;
 	struct cache_entry *last_ce = NULL;
 
-	for (i = 0; i < active_nr ; i++) {
-		struct cache_entry *ce = active_cache[i];
+	for (i = 0; i < the_index.cache_nr ; i++) {
+		struct cache_entry *ce = the_index.cache[i];
 		if (ce_stage(ce) != checkout_stage
 		    && (CHECKOUT_ALL != checkout_stage || !ce_stage(ce)))
 			continue;
@@ -185,7 +185,7 @@ int cmd_checkout_index(int argc, const c
 	git_config(git_default_config, NULL);
 	prefix_length = prefix ? strlen(prefix) : 0;
 
-	if (read_cache() < 0) {
+	if (read_index(&the_index) < 0) {
 		die("invalid cache");
 	}
 
--- builtin/checkout.c
+++ /tmp/cocci-output-206228-3a013e-checkout.c
@@ -91,9 +91,9 @@ static int update_some(const struct obje
 	 * entry in place. Whether it is UPTODATE or not, checkout_entry will
 	 * do the right thing.
 	 */
-	pos = cache_name_pos(ce->name, ce->ce_namelen);
+	pos = index_name_pos(&the_index, ce->name, ce->ce_namelen);
 	if (pos >= 0) {
-		struct cache_entry *old = active_cache[pos];
+		struct cache_entry *old = the_index.cache[pos];
 		if (ce->ce_mode == old->ce_mode &&
 		    !oidcmp(&ce->oid, &old->oid)) {
 			old->ce_flags |= CE_UPDATE;
@@ -102,7 +102,8 @@ static int update_some(const struct obje
 		}
 	}
 
-	add_cache_entry(ce, ADD_CACHE_OK_TO_ADD | ADD_CACHE_OK_TO_REPLACE);
+	add_index_entry(&the_index, ce,
+			ADD_CACHE_OK_TO_ADD | ADD_CACHE_OK_TO_REPLACE);
 	return 0;
 }
 
@@ -119,17 +120,17 @@ static int read_tree_some(struct tree *t
 
 static int skip_same_name(const struct cache_entry *ce, int pos)
 {
-	while (++pos < active_nr &&
-	       !strcmp(active_cache[pos]->name, ce->name))
+	while (++pos < the_index.cache_nr &&
+	       !strcmp(the_index.cache[pos]->name, ce->name))
 		; /* skip */
 	return pos;
 }
 
 static int check_stage(int stage, const struct cache_entry *ce, int pos)
 {
-	while (pos < active_nr &&
-	       !strcmp(active_cache[pos]->name, ce->name)) {
-		if (ce_stage(active_cache[pos]) == stage)
+	while (pos < the_index.cache_nr &&
+	       !strcmp(the_index.cache[pos]->name, ce->name)) {
+		if (ce_stage(the_index.cache[pos]) == stage)
 			return 0;
 		pos++;
 	}
@@ -144,8 +145,8 @@ static int check_stages(unsigned stages,
 	unsigned seen = 0;
 	const char *name = ce->name;
 
-	while (pos < active_nr) {
-		ce = active_cache[pos];
+	while (pos < the_index.cache_nr) {
+		ce = the_index.cache[pos];
 		if (strcmp(name, ce->name))
 			break;
 		seen |= (1 << ce_stage(ce));
@@ -160,10 +161,11 @@ static int check_stages(unsigned stages,
 static int checkout_stage(int stage, const struct cache_entry *ce, int pos,
 			  const struct checkout *state)
 {
-	while (pos < active_nr &&
-	       !strcmp(active_cache[pos]->name, ce->name)) {
-		if (ce_stage(active_cache[pos]) == stage)
-			return checkout_entry(active_cache[pos], state, NULL);
+	while (pos < the_index.cache_nr &&
+	       !strcmp(the_index.cache[pos]->name, ce->name)) {
+		if (ce_stage(the_index.cache[pos]) == stage)
+			return checkout_entry(the_index.cache[pos], state,
+				              NULL);
 		pos++;
 	}
 	if (stage == 2)
@@ -174,7 +176,7 @@ static int checkout_stage(int stage, con
 
 static int checkout_merged(int pos, const struct checkout *state)
 {
-	struct cache_entry *ce = active_cache[pos];
+	struct cache_entry *ce = the_index.cache[pos];
 	const char *path = ce->name;
 	mmfile_t ancestor, ours, theirs;
 	int status;
@@ -184,7 +186,7 @@ static int checkout_merged(int pos, cons
 	unsigned mode = 0;
 
 	memset(threeway, 0, sizeof(threeway));
-	while (pos < active_nr) {
+	while (pos < the_index.cache_nr) {
 		int stage;
 		stage = ce_stage(ce);
 		if (!stage || strcmp(path, ce->name))
@@ -193,7 +195,7 @@ static int checkout_merged(int pos, cons
 		if (stage == 2)
 			mode = create_ce_mode(ce->ce_mode);
 		pos++;
-		ce = active_cache[pos];
+		ce = the_index.cache[pos];
 	}
 	if (is_null_oid(&threeway[1]) || is_null_oid(&threeway[2]))
 		return error(_("path '%s' does not have necessary versions"), path);
@@ -278,7 +280,7 @@ static int checkout_paths(const struct c
 					   &opts->pathspec);
 
 	hold_locked_index(&lock_file, LOCK_DIE_ON_ERROR);
-	if (read_cache_preload(&opts->pathspec) < 0)
+	if (read_index_preload(&the_index, &opts->pathspec) < 0)
 		return error(_("index file corrupt"));
 
 	if (opts->source_tree)
@@ -290,8 +292,8 @@ static int checkout_paths(const struct c
 	 * Make sure all pathspecs participated in locating the paths
 	 * to be checked out.
 	 */
-	for (pos = 0; pos < active_nr; pos++) {
-		struct cache_entry *ce = active_cache[pos];
+	for (pos = 0; pos < the_index.cache_nr; pos++) {
+		struct cache_entry *ce = the_index.cache[pos];
 		ce->ce_flags &= ~CE_MATCHED;
 		if (!opts->ignore_skipworktree && ce_skip_worktree(ce))
 			continue;
@@ -333,8 +335,8 @@ static int checkout_paths(const struct c
 		unmerge_marked_index(&the_index);
 
 	/* Any unmerged paths? */
-	for (pos = 0; pos < active_nr; pos++) {
-		const struct cache_entry *ce = active_cache[pos];
+	for (pos = 0; pos < the_index.cache_nr; pos++) {
+		const struct cache_entry *ce = the_index.cache[pos];
 		if (ce->ce_flags & CE_MATCHED) {
 			if (!ce_stage(ce))
 				continue;
@@ -360,8 +362,8 @@ static int checkout_paths(const struct c
 	state.istate = &the_index;
 
 	enable_delayed_checkout(&state);
-	for (pos = 0; pos < active_nr; pos++) {
-		struct cache_entry *ce = active_cache[pos];
+	for (pos = 0; pos < the_index.cache_nr; pos++) {
+		struct cache_entry *ce = the_index.cache[pos];
 		if (ce->ce_flags & CE_MATCHED) {
 			if (!ce_stage(ce)) {
 				errs |= checkout_entry(ce, &state, NULL);
@@ -481,10 +483,10 @@ static int merge_working_tree(const stru
 	struct lock_file lock_file = LOCK_INIT;
 
 	hold_locked_index(&lock_file, LOCK_DIE_ON_ERROR);
-	if (read_cache_preload(NULL) < 0)
+	if (read_index_preload(&the_index, NULL) < 0)
 		return error(_("index file corrupt"));
 
-	resolve_undo_clear();
+	resolve_undo_clear_index(&the_index);
 	if (opts->force) {
 		ret = reset_tree(get_commit_tree(new_branch_info->commit),
 				 opts, 1, writeout_error);
@@ -502,15 +504,15 @@ static int merge_working_tree(const stru
 
 		setup_unpack_trees_porcelain(&topts, "checkout");
 
-		refresh_cache(REFRESH_QUIET);
+		refresh_index(&the_index, REFRESH_QUIET, NULL, NULL, NULL);
 
-		if (unmerged_cache()) {
+		if (unmerged_index(&the_index)) {
 			error(_("you need to resolve your current index first"));
 			return 1;
 		}
 
 		/* 2-way merge to the new branch */
-		topts.initial_checkout = is_cache_unborn();
+		topts.initial_checkout = is_index_unborn(&the_index);
 		topts.update = 1;
 		topts.merge = 1;
 		topts.gently = opts->merge && old_branch_info->commit;
@@ -598,10 +600,10 @@ static int merge_working_tree(const stru
 		}
 	}
 
-	if (!active_cache_tree)
-		active_cache_tree = cache_tree();
+	if (!the_index.cache_tree)
+		the_index.cache_tree = cache_tree();
 
-	if (!cache_tree_fully_valid(active_cache_tree))
+	if (!cache_tree_fully_valid(the_index.cache_tree))
 		cache_tree_update(&the_index, WRITE_TREE_SILENT | WRITE_TREE_REPAIR);
 
 	if (write_locked_index(&the_index, &lock_file, COMMIT_LOCK))
--- builtin/clean.c
+++ /tmp/cocci-output-206233-6cec8a-clean.c
@@ -955,7 +955,7 @@ int cmd_clean(int argc, const char **arg
 	if (remove_directories)
 		dir.flags |= DIR_SHOW_IGNORED_TOO | DIR_KEEP_UNTRACKED_CONTENTS;
 
-	if (read_cache() < 0)
+	if (read_index(&the_index) < 0)
 		die(_("index file corrupt"));
 
 	if (!ignored)
@@ -978,7 +978,7 @@ int cmd_clean(int argc, const char **arg
 		struct stat st;
 		const char *rel;
 
-		if (!cache_name_is_other(ent->name, ent->len))
+		if (!index_name_is_other(&the_index, ent->name, ent->len))
 			continue;
 
 		if (pathspec.nr)
--- builtin/commit.c
+++ /tmp/cocci-output-206241-02f1a7-commit.c
@@ -233,8 +233,8 @@ static int list_paths(struct string_list
 		free(max_prefix);
 	}
 
-	for (i = 0; i < active_nr; i++) {
-		const struct cache_entry *ce = active_cache[i];
+	for (i = 0; i < the_index.cache_nr; i++) {
+		const struct cache_entry *ce = the_index.cache[i];
 		struct string_list_item *item;
 
 		if (ce->ce_flags & CE_UPDATE)
@@ -263,10 +263,10 @@ static void add_remove_files(struct stri
 			continue;
 
 		if (!lstat(p->string, &st)) {
-			if (add_to_cache(p->string, &st, 0))
+			if (add_to_index(&the_index, p->string, &st, 0))
 				die(_("updating files failed"));
 		} else
-			remove_file_from_cache(p->string);
+			remove_file_from_index(&the_index, p->string);
 	}
 }
 
@@ -277,7 +277,7 @@ static void create_base_index(const stru
 	struct tree_desc t;
 
 	if (!current_head) {
-		discard_cache();
+		discard_index(&the_index);
 		return;
 	}
 
@@ -304,7 +304,7 @@ static void refresh_cache_or_die(int ref
 	 * refresh_flags contains REFRESH_QUIET, so the only errors
 	 * are for unmerged entries.
 	 */
-	if (refresh_cache(refresh_flags | REFRESH_IN_PORCELAIN))
+	if (refresh_index(&the_index, refresh_flags | REFRESH_IN_PORCELAIN, NULL, NULL, NULL))
 		die_resolve_conflict("commit");
 }
 
@@ -322,7 +322,7 @@ static const char *prepare_index(int arg
 		       PATHSPEC_PREFER_FULL,
 		       prefix, argv);
 
-	if (read_cache_preload(&pathspec) < 0)
+	if (read_index_preload(&the_index, &pathspec) < 0)
 		die(_("index file corrupt"));
 
 	if (interactive) {
@@ -345,8 +345,9 @@ static const char *prepare_index(int arg
 		else
 			unsetenv(INDEX_ENVIRONMENT);
 
-		discard_cache();
-		read_cache_from(get_lock_file_path(&index_lock));
+		discard_index(&the_index);
+		read_index_from(&the_index, get_lock_file_path(&index_lock),
+				get_git_dir());
 		if (update_main_cache_tree(WRITE_TREE_SILENT) == 0) {
 			if (reopen_lock_file(&index_lock) < 0)
 				die(_("unable to write index file"));
@@ -396,8 +397,8 @@ static const char *prepare_index(int arg
 	if (!only && !pathspec.nr) {
 		hold_locked_index(&index_lock, LOCK_DIE_ON_ERROR);
 		refresh_cache_or_die(refresh_flags);
-		if (active_cache_changed
-		    || !cache_tree_fully_valid(active_cache_tree))
+		if (the_index.cache_changed
+		    || !cache_tree_fully_valid(the_index.cache_tree))
 			update_main_cache_tree(WRITE_TREE_SILENT);
 		if (write_locked_index(&the_index, &index_lock,
 				       COMMIT_LOCK | SKIP_IF_UNCHANGED))
@@ -438,13 +439,13 @@ static const char *prepare_index(int arg
 	if (list_paths(&partial, !current_head ? NULL : "HEAD", prefix, &pathspec))
 		exit(1);
 
-	discard_cache();
-	if (read_cache() < 0)
+	discard_index(&the_index);
+	if (read_index(&the_index) < 0)
 		die(_("cannot read the index"));
 
 	hold_locked_index(&index_lock, LOCK_DIE_ON_ERROR);
 	add_remove_files(&partial);
-	refresh_cache(REFRESH_QUIET);
+	refresh_index(&the_index, REFRESH_QUIET, NULL, NULL, NULL);
 	update_main_cache_tree(WRITE_TREE_SILENT);
 	if (write_locked_index(&the_index, &index_lock, 0))
 		die(_("unable to write new_index file"));
@@ -456,14 +457,14 @@ static const char *prepare_index(int arg
 
 	create_base_index(current_head);
 	add_remove_files(&partial);
-	refresh_cache(REFRESH_QUIET);
+	refresh_index(&the_index, REFRESH_QUIET, NULL, NULL, NULL);
 
 	if (write_locked_index(&the_index, &false_lock, 0))
 		die(_("unable to write temporary index file"));
 
-	discard_cache();
+	discard_index(&the_index);
 	ret = get_lock_file_path(&false_lock);
-	read_cache_from(ret);
+	read_index_from(&the_index, ret, get_git_dir());
 out:
 	string_list_clear(&partial, 0);
 	clear_pathspec(&pathspec);
@@ -864,7 +865,7 @@ static int prepare_to_commit(const char
 		struct object_id oid;
 		const char *parent = "HEAD";
 
-		if (!active_nr && read_cache() < 0)
+		if (!the_index.cache_nr && read_index(&the_index) < 0)
 			die(_("Cannot read index"));
 
 		if (amend)
@@ -873,10 +874,10 @@ static int prepare_to_commit(const char
 		if (get_oid(parent, &oid)) {
 			int i, ita_nr = 0;
 
-			for (i = 0; i < active_nr; i++)
-				if (ce_intent_to_add(active_cache[i]))
+			for (i = 0; i < the_index.cache_nr; i++)
+				if (ce_intent_to_add(the_index.cache[i]))
 					ita_nr++;
-			commitable = active_nr - ita_nr > 0;
+			commitable = the_index.cache_nr - ita_nr > 0;
 		} else {
 			/*
 			 * Unless the user did explicitly request a submodule
@@ -926,9 +927,9 @@ static int prepare_to_commit(const char
 		 * and write it out as a tree.  We must do this before we invoke
 		 * the editor and after we invoke run_status above.
 		 */
-		discard_cache();
+		discard_index(&the_index);
 	}
-	read_cache_from(index_file);
+	read_index_from(&the_index, index_file, get_git_dir());
 
 	if (update_main_cache_tree(0)) {
 		error(_("Error building trees"));
--- builtin/diff-files.c
+++ /tmp/cocci-output-206251-46b008-diff-files.c
@@ -66,7 +66,7 @@ int cmd_diff_files(int argc, const char
 	    (rev.diffopt.output_format & DIFF_FORMAT_PATCH))
 		rev.combine_merges = rev.dense_combined_merges = 1;
 
-	if (read_cache_preload(&rev.diffopt.pathspec) < 0) {
+	if (read_index_preload(&the_index, &rev.diffopt.pathspec) < 0) {
 		perror("read_cache_preload");
 		return -1;
 	}
--- builtin/diff-index.c
+++ /tmp/cocci-output-206256-83e320-diff-index.c
@@ -48,11 +48,11 @@ int cmd_diff_index(int argc, const char
 		usage(diff_cache_usage);
 	if (!cached) {
 		setup_work_tree();
-		if (read_cache_preload(&rev.diffopt.pathspec) < 0) {
+		if (read_index_preload(&the_index, &rev.diffopt.pathspec) < 0) {
 			perror("read_cache_preload");
 			return -1;
 		}
-	} else if (read_cache() < 0) {
+	} else if (read_index(&the_index) < 0) {
 		perror("read_cache");
 		return -1;
 	}
--- builtin/diff-tree.c
+++ /tmp/cocci-output-206261-e5cd9c-diff-tree.c
@@ -111,7 +111,7 @@ int cmd_diff_tree(int argc, const char *
 
 	git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
 	init_revisions(opt, the_repository, prefix);
-	if (read_cache() < 0)
+	if (read_index(&the_index) < 0)
 		die(_("index file corrupt"));
 	opt->abbrev = 0;
 	opt->diff = 1;
--- builtin/diff.c
+++ /tmp/cocci-output-206266-07f964-diff.c
@@ -146,11 +146,11 @@ static int builtin_diff_index(struct rev
 		usage(builtin_diff_usage);
 	if (!cached) {
 		setup_work_tree();
-		if (read_cache_preload(&revs->diffopt.pathspec) < 0) {
+		if (read_index_preload(&the_index, &revs->diffopt.pathspec) < 0) {
 			perror("read_cache_preload");
 			return -1;
 		}
-	} else if (read_cache() < 0) {
+	} else if (read_index(&the_index) < 0) {
 		perror("read_cache");
 		return -1;
 	}
@@ -211,9 +211,10 @@ static void refresh_index_quietly(void)
 	fd = hold_locked_index(&lock_file, 0);
 	if (fd < 0)
 		return;
-	discard_cache();
-	read_cache();
-	refresh_cache(REFRESH_QUIET|REFRESH_UNMERGED);
+	discard_index(&the_index);
+	read_index(&the_index);
+	refresh_index(&the_index, REFRESH_QUIET | REFRESH_UNMERGED, NULL,
+		      NULL, NULL);
 	repo_update_index_if_able(the_repository, &lock_file);
 }
 
@@ -248,7 +249,7 @@ static int builtin_diff_files(struct rev
 		revs->combine_merges = revs->dense_combined_merges = 1;
 
 	setup_work_tree();
-	if (read_cache_preload(&revs->diffopt.pathspec) < 0) {
+	if (read_index_preload(&the_index, &revs->diffopt.pathspec) < 0) {
 		perror("read_cache_preload");
 		return -1;
 	}
--- builtin/fsck.c
+++ /tmp/cocci-output-206277-317c6c-fsck.c
@@ -798,16 +798,16 @@ int cmd_fsck(int argc, const char **argv
 	if (keep_cache_objects) {
 		verify_index_checksum = 1;
 		verify_ce_order = 1;
-		read_cache();
-		for (i = 0; i < active_nr; i++) {
+		read_index(&the_index);
+		for (i = 0; i < the_index.cache_nr; i++) {
 			unsigned int mode;
 			struct blob *blob;
 			struct object *obj;
 
-			mode = active_cache[i]->ce_mode;
+			mode = the_index.cache[i]->ce_mode;
 			if (S_ISGITLINK(mode))
 				continue;
-			blob = lookup_blob(&active_cache[i]->oid);
+			blob = lookup_blob(&the_index.cache[i]->oid);
 			if (!blob)
 				continue;
 			obj = &blob->object;
@@ -815,11 +815,11 @@ int cmd_fsck(int argc, const char **argv
 			if (name_objects)
 				add_decoration(fsck_walk_options.object_names,
 					obj,
-					xstrfmt(":%s", active_cache[i]->name));
+					xstrfmt(":%s", the_index.cache[i]->name));
 			mark_object_reachable(obj);
 		}
-		if (active_cache_tree)
-			fsck_cache_tree(active_cache_tree);
+		if (the_index.cache_tree)
+			fsck_cache_tree(the_index.cache_tree);
 	}
 
 	check_connectivity();
--- builtin/merge.c
+++ /tmp/cocci-output-206296-4e0c70-merge.c
@@ -338,7 +338,7 @@ static void restore_state(const struct o
 	run_command_v_opt(args, RUN_GIT_CMD);
 
 	strbuf_release(&sb);
-	refresh_cache(REFRESH_QUIET);
+	refresh_index(&the_index, REFRESH_QUIET, NULL, NULL, NULL);
 }
 
 /* This is called when no merge was necessary. */
@@ -630,7 +630,7 @@ static int read_tree_trivial(struct obje
 	if (!trees[nr_trees++])
 		return -1;
 	opts.fn = threeway_merge;
-	cache_tree_free(&active_cache_tree);
+	cache_tree_free(&the_index.cache_tree);
 	for (i = 0; i < nr_trees; i++) {
 		parse_tree(trees[i]);
 		init_tree_desc(t+i, trees[i]->buffer, trees[i]->size);
@@ -654,7 +654,7 @@ static int try_merge_strategy(const char
 	const char *head_arg = "HEAD";
 
 	hold_locked_index(&lock, LOCK_DIE_ON_ERROR);
-	refresh_cache(REFRESH_QUIET);
+	refresh_index(&the_index, REFRESH_QUIET, NULL, NULL, NULL);
 	if (write_locked_index(&the_index, &lock,
 			       COMMIT_LOCK | SKIP_IF_UNCHANGED))
 		return error(_("Unable to write index."));
@@ -717,8 +717,8 @@ static int count_unmerged_entries(void)
 {
 	int i, ret = 0;
 
-	for (i = 0; i < active_nr; i++)
-		if (ce_stage(active_cache[i]))
+	for (i = 0; i < the_index.cache_nr; i++)
+		if (ce_stage(the_index.cache[i]))
 			ret++;
 
 	return ret;
@@ -812,7 +812,7 @@ static int merge_trivial(struct commit *
 	struct lock_file lock = LOCK_INIT;
 
 	hold_locked_index(&lock, LOCK_DIE_ON_ERROR);
-	refresh_cache(REFRESH_QUIET);
+	refresh_index(&the_index, REFRESH_QUIET, NULL, NULL, NULL);
 	if (write_locked_index(&the_index, &lock,
 			       COMMIT_LOCK | SKIP_IF_UNCHANGED))
 		return error(_("Unable to write index."));
@@ -1237,7 +1237,7 @@ int cmd_merge(int argc, const char **arg
 		goto done;
 	}
 
-	if (read_cache_unmerged())
+	if (read_index_unmerged(&the_index))
 		die_resolve_conflict("merge");
 
 	if (file_exists(git_path_merge_head())) {
@@ -1258,7 +1258,7 @@ int cmd_merge(int argc, const char **arg
 		else
 			die(_("You have not concluded your cherry-pick (CHERRY_PICK_HEAD exists)."));
 	}
-	resolve_undo_clear();
+	resolve_undo_clear_index(&the_index);
 
 	if (verbosity < 0)
 		show_diffstat = 0;
@@ -1458,7 +1458,7 @@ int cmd_merge(int argc, const char **arg
 		 * We are not doing octopus, not fast-forward, and have
 		 * only one common.
 		 */
-		refresh_cache(REFRESH_QUIET);
+		refresh_index(&the_index, REFRESH_QUIET, NULL, NULL, NULL);
 		if (allow_trivial && fast_forward != FF_ONLY) {
 			/* See if it is really trivial. */
 			git_committer_info(IDENT_STRICT);
--- builtin/merge-index.c
+++ /tmp/cocci-output-206303-7bfaf2-merge-index.c
@@ -13,11 +13,11 @@ static int merge_entry(int pos, const ch
 	char hexbuf[4][GIT_MAX_HEXSZ + 1];
 	char ownbuf[4][60];
 
-	if (pos >= active_nr)
+	if (pos >= the_index.cache_nr)
 		die("git merge-index: %s not in the cache", path);
 	found = 0;
 	do {
-		const struct cache_entry *ce = active_cache[pos];
+		const struct cache_entry *ce = the_index.cache[pos];
 		int stage = ce_stage(ce);
 
 		if (strcmp(ce->name, path))
@@ -27,7 +27,7 @@ static int merge_entry(int pos, const ch
 		xsnprintf(ownbuf[stage], sizeof(ownbuf[stage]), "%o", ce->ce_mode);
 		arguments[stage] = hexbuf[stage];
 		arguments[stage + 4] = ownbuf[stage];
-	} while (++pos < active_nr);
+	} while (++pos < the_index.cache_nr);
 	if (!found)
 		die("git merge-index: %s not in the cache", path);
 
@@ -45,7 +45,7 @@ static int merge_entry(int pos, const ch
 
 static void merge_one_path(const char *path)
 {
-	int pos = cache_name_pos(path, strlen(path));
+	int pos = index_name_pos(&the_index, path, strlen(path));
 
 	/*
 	 * If it already exists in the cache as stage0, it's
@@ -58,8 +58,8 @@ static void merge_one_path(const char *p
 static void merge_all(void)
 {
 	int i;
-	for (i = 0; i < active_nr; i++) {
-		const struct cache_entry *ce = active_cache[i];
+	for (i = 0; i < the_index.cache_nr; i++) {
+		const struct cache_entry *ce = the_index.cache[i];
 		if (!ce_stage(ce))
 			continue;
 		i += merge_entry(i, ce->name)-1;
@@ -78,7 +78,7 @@ int cmd_merge_index(int argc, const char
 	if (argc < 3)
 		usage("git merge-index [-o] [-q] <merge-program> (-a | [--] [<filename>...])");
 
-	read_cache();
+	read_index(&the_index);
 
 	i = 1;
 	if (!strcmp(argv[i], "-o")) {
--- builtin/merge-ours.c
+++ /tmp/cocci-output-206308-f9d113-merge-ours.c
@@ -25,7 +25,7 @@ int cmd_merge_ours(int argc, const char
 	 * commit.  The index must match HEAD, or this merge cannot go
 	 * through.
 	 */
-	if (read_cache() < 0)
+	if (read_index(&the_index) < 0)
 		die_errno("read_cache failed");
 	if (index_differs_from("HEAD", NULL, 0))
 		exit(2);
--- builtin/mv.c
+++ /tmp/cocci-output-206317-dcc551-mv.c
@@ -79,7 +79,7 @@ static void prepare_move_submodule(const
 				   const char **submodule_gitfile)
 {
 	struct strbuf submodule_dotgit = STRBUF_INIT;
-	if (!S_ISGITLINK(active_cache[first]->ce_mode))
+	if (!S_ISGITLINK(the_index.cache[first]->ce_mode))
 		die(_("Directory %s is in index and no submodule?"), src);
 	if (!is_staging_gitmodules_ok(&the_index))
 		die(_("Please stage your changes to .gitmodules or stash them to proceed"));
@@ -98,13 +98,13 @@ static int index_range_of_same_dir(const
 	const char *src_w_slash = add_slash(src);
 	int first, last, len_w_slash = length + 1;
 
-	first = cache_name_pos(src_w_slash, len_w_slash);
+	first = index_name_pos(&the_index, src_w_slash, len_w_slash);
 	if (first >= 0)
 		die(_("%.*s is in index"), len_w_slash, src_w_slash);
 
 	first = -1 - first;
-	for (last = first; last < active_nr; last++) {
-		const char *path = active_cache[last]->name;
+	for (last = first; last < the_index.cache_nr; last++) {
+		const char *path = the_index.cache[last]->name;
 		if (strncmp(path, src_w_slash, len_w_slash))
 			break;
 	}
@@ -141,7 +141,7 @@ int cmd_mv(int argc, const char **argv,
 		usage_with_options(builtin_mv_usage, builtin_mv_options);
 
 	hold_locked_index(&lock_file, LOCK_DIE_ON_ERROR);
-	if (read_cache() < 0)
+	if (read_index(&the_index) < 0)
 		die(_("index file corrupt"));
 
 	source = internal_prefix_pathspec(prefix, argv, argc, 0);
@@ -189,7 +189,7 @@ int cmd_mv(int argc, const char **argv,
 				&& lstat(dst, &st) == 0)
 			bad = _("cannot move directory over file");
 		else if (src_is_dir) {
-			int first = cache_name_pos(src, length), last;
+			int first = index_name_pos(&the_index, src, length), last;
 
 			if (first >= 0)
 				prepare_move_submodule(src, first,
@@ -211,7 +211,7 @@ int cmd_mv(int argc, const char **argv,
 				dst_len = strlen(dst);
 
 				for (j = 0; j < last - first; j++) {
-					const char *path = active_cache[first + j]->name;
+					const char *path = the_index.cache[first + j]->name;
 					source[argc + j] = path;
 					destination[argc + j] =
 						prefix_path(dst, dst_len, path + length + 1);
@@ -220,7 +220,7 @@ int cmd_mv(int argc, const char **argv,
 				}
 				argc += last - first;
 			}
-		} else if (cache_name_pos(src, length) < 0)
+		} else if (index_name_pos(&the_index, src, length) < 0)
 			bad = _("not under version control");
 		else if (lstat(dst, &st) == 0 &&
 			 (!ignore_case || strcasecmp(src, dst))) {
@@ -288,9 +288,9 @@ int cmd_mv(int argc, const char **argv,
 		if (mode == WORKING_DIRECTORY)
 			continue;
 
-		pos = cache_name_pos(src, strlen(src));
+		pos = index_name_pos(&the_index, src, strlen(src));
 		assert(pos >= 0);
-		rename_cache_entry_at(pos, dst);
+		rename_index_entry_at(&the_index, pos, dst);
 	}
 
 	if (gitmodules_modified)
--- builtin/pull.c
+++ /tmp/cocci-output-206330-aaaaf5-pull.c
@@ -864,7 +864,7 @@ int cmd_pull(int argc, const char **argv
 	if (opt_rebase < 0)
 		opt_rebase = config_get_rebase();
 
-	if (read_cache_unmerged())
+	if (read_index_unmerged(&the_index))
 		die_resolve_conflict("pull");
 
 	if (file_exists(git_path_merge_head()))
@@ -881,7 +881,7 @@ int cmd_pull(int argc, const char **argv
 		if (opt_autostash != -1)
 			autostash = opt_autostash;
 
-		if (is_null_oid(&orig_head) && !is_cache_unborn())
+		if (is_null_oid(&orig_head) && !is_index_unborn(&the_index))
 			die(_("Updating an unborn branch with changes added to the index."));
 
 		if (!autostash)
--- builtin/read-tree.c
+++ /tmp/cocci-output-206336-40b38a-read-tree.c
@@ -180,11 +180,11 @@ int cmd_read_tree(int argc, const char *
 	 */
 
 	if (opts.reset || opts.merge || opts.prefix) {
-		if (read_cache_unmerged() && (opts.prefix || opts.merge))
+		if (read_index_unmerged(&the_index) && (opts.prefix || opts.merge))
 			die("You need to resolve your current index first");
 		stage = opts.merge = 1;
 	}
-	resolve_undo_clear();
+	resolve_undo_clear_index(&the_index);
 
 	for (i = 0; i < argc; i++) {
 		const char *arg = argv[i];
@@ -220,7 +220,7 @@ int cmd_read_tree(int argc, const char *
 			break;
 		case 2:
 			opts.fn = twoway_merge;
-			opts.initial_checkout = is_cache_unborn();
+			opts.initial_checkout = is_index_unborn(&the_index);
 			break;
 		case 3:
 		default:
@@ -237,7 +237,7 @@ int cmd_read_tree(int argc, const char *
 	if (opts.debug_unpack)
 		opts.fn = debug_merge;
 
-	cache_tree_free(&active_cache_tree);
+	cache_tree_free(&the_index.cache_tree);
 	for (i = 0; i < nr_trees; i++) {
 		struct tree *tree = trees[i];
 		parse_tree(tree);
--- builtin/reset.c
+++ /tmp/cocci-output-206350-640828-reset.c
@@ -71,7 +71,7 @@ static int reset_index(const struct obje
 		opts.reset = 1;
 	}
 
-	read_cache_unmerged();
+	read_index_unmerged(&the_index);
 
 	if (reset_type == KEEP) {
 		struct object_id head_oid;
@@ -131,7 +131,7 @@ static void update_index_from_diff(struc
 		struct cache_entry *ce;
 
 		if (is_missing && !intent_to_add) {
-			remove_file_from_cache(one->path);
+			remove_file_from_index(&the_index, one->path);
 			continue;
 		}
 
@@ -144,7 +144,8 @@ static void update_index_from_diff(struc
 			ce->ce_flags |= CE_INTENT_TO_ADD;
 			set_object_name_for_intent_to_add_entry(ce);
 		}
-		add_cache_entry(ce, ADD_CACHE_OK_TO_ADD | ADD_CACHE_OK_TO_REPLACE);
+		add_index_entry(&the_index, ce,
+				ADD_CACHE_OK_TO_ADD | ADD_CACHE_OK_TO_REPLACE);
 	}
 }
 
@@ -187,7 +188,7 @@ static void set_reflog_message(struct st
 
 static void die_if_unmerged_cache(int reset_type)
 {
-	if (is_merge() || unmerged_cache())
+	if (is_merge() || unmerged_index(&the_index))
 		die(_("Cannot do a %s reset in the middle of a merge."),
 		    _(reset_type_names[reset_type]));
 
@@ -239,7 +240,7 @@ static void parse_args(struct pathspec *
 	}
 	*rev_ret = rev;
 
-	if (read_cache() < 0)
+	if (read_index(&the_index) < 0)
 		die(_("index file corrupt"));
 
 	parse_pathspec(pathspec, 0,
--- builtin/rev-parse.c
+++ /tmp/cocci-output-206356-b7ba64-rev-parse.c
@@ -889,7 +889,7 @@ int cmd_rev_parse(int argc, const char *
 				continue;
 			}
 			if (!strcmp(arg, "--shared-index-path")) {
-				if (read_cache() < 0)
+				if (read_index(&the_index) < 0)
 					die(_("Could not read the index"));
 				if (the_index.split_index) {
 					const struct object_id *oid = &the_index.split_index->base_oid;
--- builtin/rm.c
+++ /tmp/cocci-output-206362-a79cb3-rm.c
@@ -32,8 +32,8 @@ static int get_ours_cache_pos(const char
 {
 	int i = -pos - 1;
 
-	while ((i < active_nr) && !strcmp(active_cache[i]->name, path)) {
-		if (ce_stage(active_cache[i]) == 2)
+	while ((i < the_index.cache_nr) && !strcmp(the_index.cache[i]->name, path)) {
+		if (ce_stage(the_index.cache[i]) == 2)
 			return i;
 		i++;
 	}
@@ -69,13 +69,13 @@ static void submodules_absorb_gitdir_if_
 		int pos;
 		const struct cache_entry *ce;
 
-		pos = cache_name_pos(name, strlen(name));
+		pos = index_name_pos(&the_index, name, strlen(name));
 		if (pos < 0) {
 			pos = get_ours_cache_pos(name, pos);
 			if (pos < 0)
 				continue;
 		}
-		ce = active_cache[pos];
+		ce = the_index.cache[pos];
 
 		if (!S_ISGITLINK(ce->ce_mode) ||
 		    !file_exists(ce->name) ||
@@ -114,7 +114,7 @@ static int check_local_mod(struct object
 		int local_changes = 0;
 		int staged_changes = 0;
 
-		pos = cache_name_pos(name, strlen(name));
+		pos = index_name_pos(&the_index, name, strlen(name));
 		if (pos < 0) {
 			/*
 			 * Skip unmerged entries except for populated submodules
@@ -124,11 +124,11 @@ static int check_local_mod(struct object
 			if (pos < 0)
 				continue;
 
-			if (!S_ISGITLINK(active_cache[pos]->ce_mode) ||
+			if (!S_ISGITLINK(the_index.cache[pos]->ce_mode) ||
 			    is_empty_dir(name))
 				continue;
 		}
-		ce = active_cache[pos];
+		ce = the_index.cache[pos];
 
 		if (lstat(ce->name, &st) < 0) {
 			if (!is_missing_file_error(errno))
@@ -165,7 +165,7 @@ static int check_local_mod(struct object
 		 * Is the index different from the file in the work tree?
 		 * If it's a submodule, is its work tree modified?
 		 */
-		if (ce_match_stat(ce, &st, 0) ||
+		if (ie_match_stat(&the_index, ce, &st, 0) ||
 		    (S_ISGITLINK(ce->ce_mode) &&
 		     bad_to_remove_submodule(ce->name,
 				SUBMODULE_REMOVAL_DIE_ON_ERROR |
@@ -267,7 +267,7 @@ int cmd_rm(int argc, const char **argv,
 
 	hold_locked_index(&lock_file, LOCK_DIE_ON_ERROR);
 
-	if (read_cache() < 0)
+	if (read_index(&the_index) < 0)
 		die(_("index file corrupt"));
 
 	parse_pathspec(&pathspec, 0,
@@ -277,8 +277,8 @@ int cmd_rm(int argc, const char **argv,
 
 	seen = xcalloc(pathspec.nr, 1);
 
-	for (i = 0; i < active_nr; i++) {
-		const struct cache_entry *ce = active_cache[i];
+	for (i = 0; i < the_index.cache_nr; i++) {
+		const struct cache_entry *ce = the_index.cache[i];
 		if (!ce_path_match(&the_index, ce, &pathspec, seen))
 			continue;
 		ALLOC_GROW(list.entry, list.nr + 1, list.alloc);
@@ -342,7 +342,7 @@ int cmd_rm(int argc, const char **argv,
 		if (!quiet)
 			printf("rm '%s'\n", path);
 
-		if (remove_file_from_cache(path))
+		if (remove_file_from_index(&the_index, path))
 			die(_("git rm: unable to remove %s"), path);
 	}
 
--- builtin/submodule--helper.c
+++ /tmp/cocci-output-206373-deb7ed-submodule--helper.c
@@ -325,11 +325,11 @@ static int module_list_compute(int argc,
 	if (pathspec->nr)
 		ps_matched = xcalloc(pathspec->nr, 1);
 
-	if (read_cache() < 0)
+	if (read_index(&the_index) < 0)
 		die(_("index file corrupt"));
 
-	for (i = 0; i < active_nr; i++) {
-		const struct cache_entry *ce = active_cache[i];
+	for (i = 0; i < the_index.cache_nr; i++) {
+		const struct cache_entry *ce = the_index.cache[i];
 
 		if (!match_pathspec(&the_index, pathspec, ce->name, ce_namelen(ce),
 				    0, ps_matched, 1) ||
@@ -338,8 +338,8 @@ static int module_list_compute(int argc,
 
 		ALLOC_GROW(list->entries, list->nr + 1, list->alloc);
 		list->entries[list->nr++] = ce;
-		while (i + 1 < active_nr &&
-		       !strcmp(ce->name, active_cache[i + 1]->name))
+		while (i + 1 < the_index.cache_nr &&
+		       !strcmp(ce->name, the_index.cache[i + 1]->name))
 			/*
 			 * Skip entries with the same name in different stages
 			 * to make sure an entry is returned only once.
--- builtin/update-index.c
+++ /tmp/cocci-output-206382-a11b11-update-index.c
@@ -229,16 +229,16 @@ done:
 static int mark_ce_flags(const char *path, int flag, int mark)
 {
 	int namelen = strlen(path);
-	int pos = cache_name_pos(path, namelen);
+	int pos = index_name_pos(&the_index, path, namelen);
 	if (0 <= pos) {
-		mark_fsmonitor_invalid(&the_index, active_cache[pos]);
+		mark_fsmonitor_invalid(&the_index, the_index.cache[pos]);
 		if (mark)
-			active_cache[pos]->ce_flags |= flag;
+			the_index.cache[pos]->ce_flags |= flag;
 		else
-			active_cache[pos]->ce_flags &= ~flag;
-		active_cache[pos]->ce_flags |= CE_UPDATE_IN_BASE;
+			the_index.cache[pos]->ce_flags &= ~flag;
+		the_index.cache[pos]->ce_flags |= CE_UPDATE_IN_BASE;
 		cache_tree_invalidate_path(&the_index, path);
-		active_cache_changed |= CE_ENTRY_CHANGED;
+		the_index.cache_changed |= CE_ENTRY_CHANGED;
 		return 0;
 	}
 	return -1;
@@ -248,7 +248,7 @@ static int remove_one_path(const char *p
 {
 	if (!allow_remove)
 		return error("%s: does not exist and --remove not passed", path);
-	if (remove_file_from_cache(path))
+	if (remove_file_from_index(&the_index, path))
 		return error("%s: cannot remove from the index", path);
 	return 0;
 }
@@ -273,7 +273,7 @@ static int add_one_path(const struct cac
 	struct cache_entry *ce;
 
 	/* Was the old index entry already up-to-date? */
-	if (old && !ce_stage(old) && !ce_match_stat(old, st, 0))
+	if (old && !ce_stage(old) && !ie_match_stat(&the_index, old, st, 0))
 		return 0;
 
 	size = cache_entry_size(len);
@@ -291,7 +291,7 @@ static int add_one_path(const struct cac
 	}
 	option = allow_add ? ADD_CACHE_OK_TO_ADD : 0;
 	option |= allow_replace ? ADD_CACHE_OK_TO_REPLACE : 0;
-	if (add_cache_entry(ce, option)) {
+	if (add_index_entry(&the_index, ce, option)) {
 		free(ce);
 		return error("%s: cannot add to the index - missing --add option?", path);
 	}
@@ -324,11 +324,11 @@ static int add_one_path(const struct cac
 static int process_directory(const char *path, int len, struct stat *st)
 {
 	struct object_id oid;
-	int pos = cache_name_pos(path, len);
+	int pos = index_name_pos(&the_index, path, len);
 
 	/* Exact match: file or existing gitlink */
 	if (pos >= 0) {
-		const struct cache_entry *ce = active_cache[pos];
+		const struct cache_entry *ce = the_index.cache[pos];
 		if (S_ISGITLINK(ce->ce_mode)) {
 
 			/* Do nothing to the index if there is no HEAD! */
@@ -343,8 +343,8 @@ static int process_directory(const char
 
 	/* Inexact match: is there perhaps a subdirectory match? */
 	pos = -pos-1;
-	while (pos < active_nr) {
-		const struct cache_entry *ce = active_cache[pos++];
+	while (pos < the_index.cache_nr) {
+		const struct cache_entry *ce = the_index.cache[pos++];
 
 		if (strncmp(ce->name, path, len))
 			break;
@@ -374,15 +374,15 @@ static int process_path(const char *path
 	if (has_symlink_leading_path(path, len))
 		return error("'%s' is beyond a symbolic link", path);
 
-	pos = cache_name_pos(path, len);
-	ce = pos < 0 ? NULL : active_cache[pos];
+	pos = index_name_pos(&the_index, path, len);
+	ce = pos < 0 ? NULL : the_index.cache[pos];
 	if (ce && ce_skip_worktree(ce)) {
 		/*
 		 * working directory version is assumed "good"
 		 * so updating it does not make sense.
 		 * On the other hand, removing it from index should work
 		 */
-		if (allow_remove && remove_file_from_cache(path))
+		if (allow_remove && remove_file_from_index(&the_index, path))
 			return error("%s: cannot remove from the index", path);
 		return 0;
 	}
@@ -422,7 +422,7 @@ static int add_cacheinfo(unsigned int mo
 		ce->ce_flags |= CE_VALID;
 	option = allow_add ? ADD_CACHE_OK_TO_ADD : 0;
 	option |= allow_replace ? ADD_CACHE_OK_TO_REPLACE : 0;
-	if (add_cache_entry(ce, option))
+	if (add_index_entry(&the_index, ce, option))
 		return error("%s: cannot add to the index - missing --add option?",
 			     path);
 	report("add '%s'", path);
@@ -434,11 +434,11 @@ static void chmod_path(char flip, const
 	int pos;
 	struct cache_entry *ce;
 
-	pos = cache_name_pos(path, strlen(path));
+	pos = index_name_pos(&the_index, path, strlen(path));
 	if (pos < 0)
 		goto fail;
-	ce = active_cache[pos];
-	if (chmod_cache_entry(ce, flip) < 0)
+	ce = the_index.cache[pos];
+	if (chmod_index_entry(&the_index, ce, flip) < 0)
 		goto fail;
 
 	report("chmod %cx '%s'", flip, path);
@@ -481,7 +481,7 @@ static void update_one(const char *path)
 	}
 
 	if (force_remove) {
-		if (remove_file_from_cache(path))
+		if (remove_file_from_index(&the_index, path))
 			die("git update-index: unable to remove %s", path);
 		report("remove '%s'", path);
 		return;
@@ -563,7 +563,7 @@ static void read_index_info(int nul_term
 
 		if (!mode) {
 			/* mode == 0 means there is no such path -- remove */
-			if (remove_file_from_cache(path_name))
+			if (remove_file_from_index(&the_index, path_name))
 				die("git update-index: unable to remove %s",
 				    ptr);
 		}
@@ -632,12 +632,12 @@ static int unresolve_one(const char *pat
 	struct cache_entry *ce_2 = NULL, *ce_3 = NULL;
 
 	/* See if there is such entry in the index. */
-	pos = cache_name_pos(path, namelen);
+	pos = index_name_pos(&the_index, path, namelen);
 	if (0 <= pos) {
 		/* already merged */
-		pos = unmerge_cache_entry_at(pos);
-		if (pos < active_nr) {
-			const struct cache_entry *ce = active_cache[pos];
+		pos = unmerge_index_entry_at(&the_index, pos);
+		if (pos < the_index.cache_nr) {
+			const struct cache_entry *ce = the_index.cache[pos];
 			if (ce_stage(ce) &&
 			    ce_namelen(ce) == namelen &&
 			    !memcmp(ce->name, path, namelen))
@@ -650,8 +650,8 @@ static int unresolve_one(const char *pat
 		 * want to do anything in the former case.
 		 */
 		pos = -pos-1;
-		if (pos < active_nr) {
-			const struct cache_entry *ce = active_cache[pos];
+		if (pos < the_index.cache_nr) {
+			const struct cache_entry *ce = the_index.cache[pos];
 			if (ce_namelen(ce) == namelen &&
 			    !memcmp(ce->name, path, namelen)) {
 				fprintf(stderr,
@@ -680,13 +680,13 @@ static int unresolve_one(const char *pat
 		goto free_return;
 	}
 
-	remove_file_from_cache(path);
-	if (add_cache_entry(ce_2, ADD_CACHE_OK_TO_ADD)) {
+	remove_file_from_index(&the_index, path);
+	if (add_index_entry(&the_index, ce_2, ADD_CACHE_OK_TO_ADD)) {
 		error("%s: cannot add our version to the index.", path);
 		ret = -1;
 		goto free_return;
 	}
-	if (!add_cache_entry(ce_3, ADD_CACHE_OK_TO_ADD))
+	if (!add_index_entry(&the_index, ce_3, ADD_CACHE_OK_TO_ADD))
 		return 0;
 	error("%s: cannot add their version to the index.", path);
 	ret = -1;
@@ -746,8 +746,8 @@ static int do_reupdate(int ac, const cha
 		 */
 		has_head = 0;
  redo:
-	for (pos = 0; pos < active_nr; pos++) {
-		const struct cache_entry *ce = active_cache[pos];
+	for (pos = 0; pos < the_index.cache_nr; pos++) {
+		const struct cache_entry *ce = the_index.cache[pos];
 		struct cache_entry *old = NULL;
 		int save_nr;
 		char *path;
@@ -766,12 +766,12 @@ static int do_reupdate(int ac, const cha
 		 * path anymore, in which case, under 'allow_remove',
 		 * or worse yet 'allow_replace', active_nr may decrease.
 		 */
-		save_nr = active_nr;
+		save_nr = the_index.cache_nr;
 		path = xstrdup(ce->name);
 		update_one(path);
 		free(path);
 		free(old);
-		if (save_nr != active_nr)
+		if (save_nr != the_index.cache_nr)
 			goto redo;
 	}
 	clear_pathspec(&pathspec);
@@ -786,8 +786,9 @@ struct refresh_params {
 static int refresh(struct refresh_params *o, unsigned int flag)
 {
 	setup_work_tree();
-	read_cache_preload(NULL);
-	*o->has_errors |= refresh_cache(o->flags | flag);
+	read_index_preload(&the_index, NULL);
+	*o->has_errors |= refresh_index(&the_index, o->flags | flag, NULL,
+					NULL, NULL);
 	return 0;
 }
 
@@ -816,7 +817,7 @@ static int chmod_callback(const struct o
 static int resolve_undo_clear_callback(const struct option *opt,
 				const char *arg, int unset)
 {
-	resolve_undo_clear();
+	resolve_undo_clear_index(&the_index);
 	return 0;
 }
 
@@ -900,7 +901,7 @@ static int unresolve_callback(struct par
 	*has_errors = do_unresolve(ctx->argc, ctx->argv,
 				prefix, prefix ? strlen(prefix) : 0);
 	if (*has_errors)
-		active_cache_changed = 0;
+		the_index.cache_changed = 0;
 
 	ctx->argv += ctx->argc - 1;
 	ctx->argc = 1;
@@ -918,7 +919,7 @@ static int reupdate_callback(struct pars
 	*has_errors = do_reupdate(ctx->argc, ctx->argv,
 				prefix, prefix ? strlen(prefix) : 0);
 	if (*has_errors)
-		active_cache_changed = 0;
+		the_index.cache_changed = 0;
 
 	ctx->argv += ctx->argc - 1;
 	ctx->argc = 1;
@@ -1052,7 +1053,7 @@ int cmd_update_index(int argc, const cha
 	if (newfd < 0)
 		lock_error = errno;
 
-	entries = read_cache();
+	entries = read_index(&the_index);
 	if (entries < 0)
 		die("cache corrupted");
 
@@ -1107,7 +1108,7 @@ int cmd_update_index(int argc, const cha
 			    INDEX_FORMAT_LB, INDEX_FORMAT_UB);
 
 		if (the_index.version != preferred_index_format)
-			active_cache_changed |= SOMETHING_CHANGED;
+			the_index.cache_changed |= SOMETHING_CHANGED;
 		the_index.version = preferred_index_format;
 	}
 
@@ -1194,7 +1195,7 @@ int cmd_update_index(int argc, const cha
 		report(_("fsmonitor disabled"));
 	}
 
-	if (active_cache_changed || force_write) {
+	if (the_index.cache_changed || force_write) {
 		if (newfd < 0) {
 			if (refresh_args.flags & REFRESH_QUIET)
 				exit(128);
--- t/helper/test-dump-untracked-cache.c
+++ /tmp/cocci-output-206411-64fa0f-test-dump-untracked-cache.c
@@ -48,7 +48,7 @@ int cmd_main(int ac, const char **av)
 	ignore_untracked_cache_config = 1;
 
 	setup_git_directory();
-	if (read_cache() < 0)
+	if (read_index(&the_index) < 0)
 		die("unable to read index file");
 	uc = the_index.untracked;
 	if (!uc) {
--- t/helper/test-dump-cache-tree.c
+++ /tmp/cocci-output-206428-a636a2-test-dump-cache-tree.c
@@ -60,10 +60,10 @@ int cmd__dump_cache_tree(int ac, const c
 	struct index_state istate;
 	struct cache_tree *another = cache_tree();
 	setup_git_directory();
-	if (read_cache() < 0)
+	if (read_index(&the_index) < 0)
 		die("unable to read index file");
 	istate = the_index;
 	istate.cache_tree = another;
 	cache_tree_update(&istate, WRITE_TREE_DRY_RUN);
-	return dump_cache_tree(active_cache_tree, another, "");
+	return dump_cache_tree(the_index.cache_tree, another, "");
 }
--- t/helper/test-lazy-init-name-hash.c
+++ /tmp/cocci-output-206438-8b586f-test-lazy-init-name-hash.c
@@ -32,7 +32,7 @@ static void dump_run(void)
 	struct dir_entry *dir;
 	struct cache_entry *ce;
 
-	read_cache();
+	read_index(&the_index);
 	if (single) {
 		test_lazy_init_name_hash(&the_index, 0);
 	} else {
@@ -53,7 +53,7 @@ static void dump_run(void)
 		ce = hashmap_iter_next(&iter_cache);
 	}
 
-	discard_cache();
+	discard_index(&the_index);
 }
 
 /*
@@ -70,7 +70,7 @@ static uint64_t time_runs(int try_thread
 
 	for (i = 0; i < count; i++) {
 		t0 = getnanotime();
-		read_cache();
+		read_index(&the_index);
 		t1 = getnanotime();
 		nr_threads_used = test_lazy_init_name_hash(&the_index, try_threaded);
 		t2 = getnanotime();
@@ -93,7 +93,7 @@ static uint64_t time_runs(int try_thread
 				   the_index.cache_nr);
 		fflush(stdout);
 
-		discard_cache();
+		discard_index(&the_index);
 	}
 
 	avg = sum / count;
@@ -117,9 +117,9 @@ static void analyze_run(void)
 	int i;
 	int nr;
 
-	read_cache();
+	read_index(&the_index);
 	cache_nr_limit = the_index.cache_nr;
-	discard_cache();
+	discard_index(&the_index);
 
 	nr = analyze;
 	while (1) {
@@ -132,23 +132,23 @@ static void analyze_run(void)
 			nr = cache_nr_limit;
 
 		for (i = 0; i < count; i++) {
-			read_cache();
+			read_index(&the_index);
 			the_index.cache_nr = nr; /* cheap truncate of index */
 			t1s = getnanotime();
 			test_lazy_init_name_hash(&the_index, 0);
 			t2s = getnanotime();
 			sum_single += (t2s - t1s);
 			the_index.cache_nr = cache_nr_limit;
-			discard_cache();
+			discard_index(&the_index);
 
-			read_cache();
+			read_index(&the_index);
 			the_index.cache_nr = nr; /* cheap truncate of index */
 			t1m = getnanotime();
 			nr_threads_used = test_lazy_init_name_hash(&the_index, 1);
 			t2m = getnanotime();
 			sum_multi += (t2m - t1m);
 			the_index.cache_nr = cache_nr_limit;
-			discard_cache();
+			discard_index(&the_index);
 
 			if (!nr_threads_used)
 				printf("    [size %8d] [single %f]   non-threaded code path used\n",
--- t/helper/test-read-cache.c
+++ /tmp/cocci-output-206449-76a1d5-test-read-cache.c
@@ -8,8 +8,8 @@ int cmd__read_cache(int argc, const char
 		cnt = strtol(argv[1], NULL, 0);
 	setup_git_directory();
 	for (i = 0; i < cnt; i++) {
-		read_cache();
-		discard_cache();
+		read_index(&the_index);
+		discard_index(&the_index);
 	}
 	return 0;
 }
--- t/helper/test-scrap-cache-tree.c
+++ /tmp/cocci-output-206458-4e21e5-test-scrap-cache-tree.c
@@ -10,9 +10,9 @@ int cmd__scrap_cache_tree(int ac, const
 
 	setup_git_directory();
 	hold_locked_index(&index_lock, LOCK_DIE_ON_ERROR);
-	if (read_cache() < 0)
+	if (read_index(&the_index) < 0)
 		die("unable to read index file");
-	active_cache_tree = NULL;
+	the_index.cache_tree = NULL;
 	if (write_locked_index(&the_index, &index_lock, COMMIT_LOCK))
 		die("unable to write index file");
 	return 0;
--- t/helper/test-write-cache.c
+++ /tmp/cocci-output-206472-8a0fe8-test-write-cache.c
@@ -9,7 +9,7 @@ int cmd__write_cache(int argc, const cha
 	if (argc == 2)
 		cnt = strtol(argv[1], NULL, 0);
 	setup_git_directory();
-	read_cache();
+	read_index(&the_index);
 	for (i = 0; i < cnt; i++) {
 		hold_locked_index(&index_lock, LOCK_DIE_ON_ERROR);
 		if (write_locked_index(&the_index, &index_lock, COMMIT_LOCK))

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 00/15] Kill the_index part 1, expose it
  2018-06-16  5:41 [PATCH 00/15] Kill the_index part 1, expose it Nguyễn Thái Ngọc Duy
                   ` (15 preceding siblings ...)
  2018-06-17  7:02 ` [PATCH 00/15] Kill the_index part 1, expose it Elijah Newren
@ 2018-06-19 11:48 ` Derrick Stolee
  2018-06-19 14:48   ` Duy Nguyen
  16 siblings, 1 reply; 32+ messages in thread
From: Derrick Stolee @ 2018-06-19 11:48 UTC (permalink / raw)
  To: Nguyễn Thái Ngọc Duy, git

On 6/16/2018 1:41 AM, Nguyễn Thái Ngọc Duy wrote:
> This is the beginning of the end of the_index. The problem with
> the_index is it lets library code anywhere access it freely. This is
> not good because from high level you may not realize that the_index is
> being used while you don't want to touch index at all, or you want to
> use a different index instead.
>
> This is a long series, 86 patches [1], so I'm going to split and
> submit it in 15-20 patches at a time. The first two parts are trivial
> though and could be safely fast tracked if needed.
>
> This is the first part, which kills the use of index compat macros
> outside builtin/ and expose the_index in all library code. Later on we
> will ban the_index from one file each time until it's gone for good.
>
> "struct index_state *" will be passed from builtin/ through the call
> chain to the function that needs it. In some cases, "struct
> repository *" will be passed instead when the whole operation spans
> more than just the index.  By the end, the_index becomes part of
> "index compat macros" and cannot be used outside builtin/
>
> Part one is mechanical conversion with the help of coccinelle. The
> only real patches are the first and the last one.
>
> [1] https://gitlab.com/pclouds/git/commits/really-kill-the-index

This is a good series, and a good goal!

Outside of dropping [PATCH 01/15] until all the changes are applied, 
this patch looks like a good, mechanical change.

There are a lot of cross-cutting changes happening right now, between 
this series of series and Stefan's series of series. Hopefully after 
2.18 is cut, a lot of these can graduate to master quickly. Personally, 
I find it difficult to base a patch off of multiple in-progress branches 
and would rather work off of a "known good" point like the tip of master.

Thanks,
-Stolee

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 00/15] Kill the_index part 1, expose it
  2018-06-19 11:48 ` Derrick Stolee
@ 2018-06-19 14:48   ` Duy Nguyen
  0 siblings, 0 replies; 32+ messages in thread
From: Duy Nguyen @ 2018-06-19 14:48 UTC (permalink / raw)
  To: Derrick Stolee; +Cc: Git Mailing List

On Tue, Jun 19, 2018 at 1:48 PM Derrick Stolee <stolee@gmail.com> wrote:
> Personally,
> I find it difficult to base a patch off of multiple in-progress branches
> and would rather work off of a "known good" point like the tip of master.

You should always base your patches on 'master' (or even 'maint' if
it's bug fixes that have a chance of entering 'maint'). We all we face
conflicts at some point (mostly when we rebase after something gets
merged to master; or things are merged on 'pu'). But git-rerere should
keep conflict resolution easy (most of the time). I also expect Junio
to kick and scream when patch series conflict badly on 'pu' and he
will decide which one goes first and kick others out temporarily.
-- 
Duy

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 01/15] contrib: add cocci script to replace index compat macros
  2018-06-19 11:41     ` Derrick Stolee
@ 2018-06-19 14:51       ` Duy Nguyen
  2018-06-19 15:21         ` Derrick Stolee
  0 siblings, 1 reply; 32+ messages in thread
From: Duy Nguyen @ 2018-06-19 14:51 UTC (permalink / raw)
  To: Derrick Stolee; +Cc: Git Mailing List

On Tue, Jun 19, 2018 at 1:41 PM Derrick Stolee <stolee@gmail.com> wrote:
>
> Duy,
>
> Here is the patch that was generated by `make coccicheck`.
>
> Thanks,
> -Stolee
>
> -->8--
>
> --- builtin/add.c

Ah right. This is on purpose. I think I mentioned in the commit
message that builtin/ is not touched. Do we run 'make coccicheck'
automatically somewhere? If true, I need to move this script elsewhere
because it's meant to run manually. You run it when you intend to do
more manual fixups afterwards. For builtin/, I think I'll wait until
'struct repository *' conversion is complete then maybe fix them one
by one.

> +++ /tmp/cocci-output-206193-4c91ec-add.c
> @@ -38,13 +38,13 @@ static void chmod_pathspec(struct pathsp
>  {
>         int i;
>
> -       for (i = 0; i < active_nr; i++) {
> -               struct cache_entry *ce = active_cache[i];
> +       for (i = 0; i < the_index.cache_nr; i++) {
> +               struct cache_entry *ce = the_index.cache[i];
>
>                 if (pathspec && !ce_path_match(&the_index, ce, pathspec, NULL))
>                         continue;
>
> -               if (chmod_cache_entry(ce, flip) < 0)
> +               if (chmod_index_entry(&the_index, ce, flip) < 0)
>                         fprintf(stderr, "cannot chmod %cx '%s'\n", flip, ce->name);
>         }
>  }
-- 
Duy

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 01/15] contrib: add cocci script to replace index compat macros
  2018-06-19 14:51       ` Duy Nguyen
@ 2018-06-19 15:21         ` Derrick Stolee
  2018-07-23 12:56           ` SZEDER Gábor
  0 siblings, 1 reply; 32+ messages in thread
From: Derrick Stolee @ 2018-06-19 15:21 UTC (permalink / raw)
  To: Duy Nguyen; +Cc: Git Mailing List, SZEDER Gábor

On 6/19/2018 10:51 AM, Duy Nguyen wrote:
> On Tue, Jun 19, 2018 at 1:41 PM Derrick Stolee <stolee@gmail.com> wrote:
>> Duy,
>>
>> Here is the patch that was generated by `make coccicheck`.
>>
>> Thanks,
>> -Stolee
>>
>> -->8--
>>
>> --- builtin/add.c
> Ah right. This is on purpose. I think I mentioned in the commit
> message that builtin/ is not touched. Do we run 'make coccicheck'
> automatically somewhere? If true, I need to move this script elsewhere
> because it's meant to run manually. You run it when you intend to do
> more manual fixups afterwards. For builtin/, I think I'll wait until
> 'struct repository *' conversion is complete then maybe fix them one
> by one.

I don't think it is part of the CI runs, but some community members run 
this themselves on 'next' and 'master'.

I'm CC'ing Szeder, as he has contributed a fix to my own Coccinelle 
script [1].

[1] 
https://public-inbox.org/git/20180430093153.13040-1-szeder.dev@gmail.com/
     [PATCH] coccinelle: avoid wrong transformation suggestions from 
commit.cocci

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 00/15] Kill the_index part 1, expose it
  2018-06-18 18:41     ` Brandon Williams
@ 2018-06-19 19:00       ` Ben Peart
  0 siblings, 0 replies; 32+ messages in thread
From: Ben Peart @ 2018-06-19 19:00 UTC (permalink / raw)
  To: Brandon Williams, Duy Nguyen; +Cc: Elijah Newren, Git Mailing List



On 6/18/2018 2:41 PM, Brandon Williams wrote:
> On 06/17, Duy Nguyen wrote:
>> On Sun, Jun 17, 2018 at 9:02 AM Elijah Newren <newren@gmail.com> wrote:
>>>
>>> On Fri, Jun 15, 2018 at 10:41 PM, Nguyễn Thái Ngọc Duy
>>> <pclouds@gmail.com> wrote:
>>>> This is the beginning of the end of the_index. The problem with
>>>> the_index is it lets library code anywhere access it freely. This is
>>>> not good because from high level you may not realize that the_index is
>>>> being used while you don't want to touch index at all, or you want to
>>>> use a different index instead.
>>>>
>>>> This is a long series, 86 patches [1], so I'm going to split and
>>>> submit it in 15-20 patches at a time. The first two parts are trivial
>>>> though and could be safely fast tracked if needed.
>>>
>>> You post this small little patch about unpack-trees.c, mentioning you
>>> don't know if it's even correct, and bait me into reviewing it and
>>> then spring on me that it's actually nearly 100 patches that need
>>> review...   Very sneaky.  ;-)
>>
>> To be fair, it's all Brandon's fault. If he didn't kick the_index out
>> of dir.c, it would not conflict with one of my out-of-tree patches in
>> unpack-trees.c, catch my attention and make me go down this rabbit
>> hole :D
> 
> Haha well this is something I've wanted to do for over a year now, glad
> you've decided to run with it :)
> 
> I guess I've gotten pretty good at getting people to go down rabbit
> holes.  First Stefan with the object store refactoring and now you with
> the index stuff.  All because I wanted git to be more object oriented
> and have less global state ;)
> 

Let me join the chorus of voices excited to see someone finally taking 
the plunge to do this!  I'm very happy about seeing this taken through 
to "the end of the_index."

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 02/15] apply.c: stop using index compat macros
  2018-06-16  5:41 ` [PATCH 02/15] apply.c: stop using " Nguyễn Thái Ngọc Duy
@ 2018-06-25 17:27   ` Junio C Hamano
  2018-06-30  8:38     ` Duy Nguyen
  0 siblings, 1 reply; 32+ messages in thread
From: Junio C Hamano @ 2018-06-25 17:27 UTC (permalink / raw)
  To: Nguyễn Thái Ngọc Duy; +Cc: git

Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:

> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> ---
>  apply.c | 34 +++++++++++++++++++---------------
>  1 file changed, 19 insertions(+), 15 deletions(-)

Until all the codepaths that reach these callsites to index_*
functions from cmd_main() are converted to pass "struct index_state
*" throughout, a step like this patch does fundamentally changes
nothing.  The only two issues worth addressing in this area still
remain.  All the lines we see here still depend on the existence of
"the_index" instance, and they can only operate on that single
"the_index" instance and nothing else.

It is true that the dependency has been made more explicit, but it
already is explicit (to see them you just say "no-the-index-macros"
and see what fails to compile).

I see others are enthused with this series, but seeing the changes
like these I am not all that impressed.

Would it become hard to review if we combine this step *and* the
next logical step (i.e. pass the "struct index_state" throughout the
callflow) into a single patch?  The functions in apply.c are fairly
well isolated and there won't be all that heavy interaction with the
outside world if we convert this file (and it alone) without
touchning the other files.  If a division in that direction is
possible, it may make a better orgainzation (i.e.  instead of doing
whole-tree superficial conversion that needs to be fixed up again
later, do a deep full conversion on selected files before going on
to next set of files).


^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 02/15] apply.c: stop using index compat macros
  2018-06-25 17:27   ` Junio C Hamano
@ 2018-06-30  8:38     ` Duy Nguyen
  2018-07-03 18:30       ` Junio C Hamano
  0 siblings, 1 reply; 32+ messages in thread
From: Duy Nguyen @ 2018-06-30  8:38 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

On Mon, Jun 25, 2018 at 10:27:23AM -0700, Junio C Hamano wrote:
> Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:
> 
> > Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> > ---
> >  apply.c | 34 +++++++++++++++++++---------------
> >  1 file changed, 19 insertions(+), 15 deletions(-)
> 
> Until all the codepaths that reach these callsites to index_*
> functions from cmd_main() are converted to pass "struct index_state
> *" throughout, a step like this patch does fundamentally changes
> nothing.  The only two issues worth addressing in this area still
> remain.  All the lines we see here still depend on the existence of
> "the_index" instance, and they can only operate on that single
> "the_index" instance and nothing else.
> 
> It is true that the dependency has been made more explicit, but it
> already is explicit (to see them you just say "no-the-index-macros"
> and see what fails to compile).
> 
> I see others are enthused with this series, but seeing the changes
> like these I am not all that impressed.

I agree there is nothing to be impressed about these patches. These,
standalone, are worthless changes. I would not do this if I could not
delete all these the_index by the end. The changes are separated this
way in order to reduce diff noise (indentation, function name changes)
in later patches.

> 
> Would it become hard to review if we combine this step *and* the
> next logical step (i.e. pass the "struct index_state" throughout the
> callflow) into a single patch? The functions in apply.c are fairly
> well isolated and there won't be all that heavy interaction with the
> outside world if we convert this file (and it alone) without
> touchning the other files.

A singe patch conversion would look like below. But for that to
happen, convert.c, rerere, ws.c and read-cache.c have to be converted
first to not use the_index. A single patch to convert apply.c probably
pulls a lot more outside changes than just apply.c

> If a division in that direction is possible, it may make a better
> orgainzation (i.e.  instead of doing whole-tree superficial
> conversion that needs to be fixed up again later, do a deep full
> conversion on selected files before going on to next set of files).

I think that's the direction in the following patches, where I try to
kick the_index out of one file each time until they are gone.

I'm ok with dropping these patches and incorporate them in the "real
conversion" patches too. Let me know which way you want.

Anyway the "everything in apply.c" patch would look like this, which
is a combined patch of the following commits on my branch [1]

18d1848077 read-cache.c: kill read_index()
e8445d01a5 repository.c: replace hold_locked_index() with repo_hold_locked_index()
cc970ac179 ws.c: remove implicit dependency on the_index
b8a14120c4 rerere.c: remove implicit dependency on the_index
6b68ac65dc ll-merge.c: remove implicit dependency on the_index
5d990e1b71 apply.c: use apply_state->repo->index instead of the_index
cb3f1ad8e8 apply.c: make init_apply_state() take a struct repository
a0bcf49024 apply.c: pass struct apply_state to more functions
4265838aec apply.c: use the right index instead of the_index
4fbbdbca80 read-cache.c: remove an implicit dependency on the_index
ef8bd1e81d convert.c: remove an implicit dependency on the_index

[1] https://gitlab.com/pclouds/git/commits/really-kill-the-index

-- 8< --
diff --git a/apply.c b/apply.c
index 57a7d3cafd..0ec5b1ec57 100644
--- a/apply.c
+++ b/apply.c
@@ -75,10 +75,12 @@ static int parse_ignorewhitespace_option(struct apply_state *state,
 }
 
 int init_apply_state(struct apply_state *state,
+		     struct repository *repo,
 		     const char *prefix)
 {
 	memset(state, 0, sizeof(*state));
 	state->prefix = prefix;
+	state->repo = repo;
 	state->apply = 1;
 	state->line_termination = '\n';
 	state->p_value = 1;
@@ -2126,10 +2128,12 @@ static int parse_chunk(struct apply_state *state, char *buffer, unsigned long si
 
 	if (!use_patch(state, patch))
 		patch->ws_rule = 0;
+	else if (patch->new_name)
+		patch->ws_rule = whitespace_rule(state->repo->index,
+						 patch->new_name);
 	else
-		patch->ws_rule = whitespace_rule(patch->new_name
-						 ? patch->new_name
-						 : patch->old_name);
+		patch->ws_rule = whitespace_rule(state->repo->index,
+						 patch->old_name);
 
 	patchsize = parse_single_patch(state,
 				       buffer + offset + hdrsize,
@@ -3371,14 +3375,16 @@ static struct patch *previous_patch(struct apply_state *state,
 	return previous;
 }
 
-static int verify_index_match(const struct cache_entry *ce, struct stat *st)
+static int verify_index_match(struct apply_state *state,
+			      const struct cache_entry *ce,
+			      struct stat *st)
 {
 	if (S_ISGITLINK(ce->ce_mode)) {
 		if (!S_ISDIR(st->st_mode))
 			return -1;
 		return 0;
 	}
-	return ie_match_stat(&the_index, ce, st,
+	return ie_match_stat(state->repo->index, ce, st,
 			     CE_MATCH_IGNORE_VALID | CE_MATCH_IGNORE_SKIP_WORKTREE);
 }
 
@@ -3460,7 +3466,8 @@ static int load_preimage(struct apply_state *state,
 	return 0;
 }
 
-static int three_way_merge(struct image *image,
+static int three_way_merge(struct apply_state *state,
+			   struct image *image,
 			   char *path,
 			   const struct object_id *base,
 			   const struct object_id *ours,
@@ -3476,7 +3483,9 @@ static int three_way_merge(struct image *image,
 	status = ll_merge(&result, path,
 			  &base_file, "base",
 			  &our_file, "ours",
-			  &their_file, "theirs", NULL);
+			  &their_file, "theirs",
+			  state->repo->index,
+			  NULL);
 	free(base_file.ptr);
 	free(our_file.ptr);
 	free(their_file.ptr);
@@ -3512,17 +3521,17 @@ static int load_current(struct apply_state *state,
 	if (!patch->is_new)
 		BUG("patch to %s is not a creation", patch->old_name);
 
-	pos = index_name_pos(&the_index, name, strlen(name));
+	pos = index_name_pos(state->repo->index, name, strlen(name));
 	if (pos < 0)
 		return error(_("%s: does not exist in index"), name);
-	ce = the_index.cache[pos];
+	ce = state->repo->index->cache[pos];
 	if (lstat(name, &st)) {
 		if (errno != ENOENT)
 			return error_errno("%s", name);
-		if (checkout_target(&the_index, ce, &st))
+		if (checkout_target(state->repo->index, ce, &st))
 			return -1;
 	}
-	if (verify_index_match(ce, &st))
+	if (verify_index_match(state, ce, &st))
 		return error(_("%s: does not match index"), name);
 
 	status = load_patch_target(state, &buf, ce, &st, patch, name, mode);
@@ -3588,7 +3597,7 @@ static int try_threeway(struct apply_state *state,
 	clear_image(&tmp_image);
 
 	/* in-core three-way merge between post and our using pre as base */
-	status = three_way_merge(image, patch->new_name,
+	status = three_way_merge(state, image, patch->new_name,
 				 &pre_oid, &our_oid, &post_oid);
 	if (status < 0) {
 		if (state->apply_verbosity > verbosity_silent)
@@ -3681,19 +3690,19 @@ static int check_preimage(struct apply_state *state,
 	}
 
 	if (state->check_index && !previous) {
-		int pos = index_name_pos(&the_index, old_name,
+		int pos = index_name_pos(state->repo->index, old_name,
 					 strlen(old_name));
 		if (pos < 0) {
 			if (patch->is_new < 0)
 				goto is_new;
 			return error(_("%s: does not exist in index"), old_name);
 		}
-		*ce = the_index.cache[pos];
+		*ce = state->repo->index->cache[pos];
 		if (stat_ret < 0) {
-			if (checkout_target(&the_index, *ce, st))
+			if (checkout_target(state->repo->index, *ce, st))
 				return -1;
 		}
-		if (!state->cached && verify_index_match(*ce, st))
+		if (!state->cached && verify_index_match(state, *ce, st))
 			return error(_("%s: does not match index"), old_name);
 		if (state->cached)
 			st_mode = (*ce)->ce_mode;
@@ -3737,7 +3746,7 @@ static int check_to_create(struct apply_state *state,
 	struct stat nst;
 
 	if (state->check_index &&
-	    index_name_pos(&the_index, new_name, strlen(new_name)) >= 0 &&
+	    index_name_pos(state->repo->index, new_name, strlen(new_name)) >= 0 &&
 	    !ok_if_exists)
 		return EXISTS_IN_INDEX;
 	if (state->cached)
@@ -3826,7 +3835,7 @@ static int path_is_beyond_symlink_1(struct apply_state *state, struct strbuf *na
 		if (state->check_index) {
 			struct cache_entry *ce;
 
-			ce = index_file_exists(&the_index, name->buf,
+			ce = index_file_exists(state->repo->index, name->buf,
 					       name->len, ignore_case);
 			if (ce && S_ISLNK(ce->ce_mode))
 				return 1;
@@ -4002,10 +4011,10 @@ static int check_patch_list(struct apply_state *state, struct patch *patch)
 static int read_apply_cache(struct apply_state *state)
 {
 	if (state->index_file)
-		return read_index_from(&the_index, state->index_file,
+		return read_index_from(state->repo->index, state->index_file,
 				       get_git_dir());
 	else
-		return read_index(&the_index);
+		return repo_read_index(state->repo);
 }
 
 /* This function tries to read the object name from the current index */
@@ -4016,10 +4025,10 @@ static int get_current_oid(struct apply_state *state, const char *path,
 
 	if (read_apply_cache(state) < 0)
 		return -1;
-	pos = index_name_pos(&the_index, path, strlen(path));
+	pos = index_name_pos(state->repo->index, path, strlen(path));
 	if (pos < 0)
 		return -1;
-	oidcpy(oid, &the_index.cache[pos]->oid);
+	oidcpy(oid, &state->repo->index->cache[pos]->oid);
 	return 0;
 }
 
@@ -4094,9 +4103,9 @@ static int build_fake_ancestor(struct apply_state *state, struct patch *list)
 			return error(_("sha1 information is lacking or useless "
 				       "(%s)."), name);
 
-		ce = make_cache_entry(patch->old_mode, oid.hash, name, 0, 0);
+		ce = make_index_entry(&result, patch->old_mode, oid.hash, name, 0, 0);
 		if (!ce)
-			return error(_("make_cache_entry failed for path '%s'"),
+			return error(_("make_index_entry failed for path '%s'"),
 				     name);
 		if (add_index_entry(&result, ce, ADD_CACHE_OK_TO_ADD)) {
 			free(ce);
@@ -4247,7 +4256,7 @@ static void patch_stats(struct apply_state *state, struct patch *patch)
 static int remove_file(struct apply_state *state, struct patch *patch, int rmdir_empty)
 {
 	if (state->update_index) {
-		if (remove_file_from_index(&the_index, patch->old_name) < 0)
+		if (remove_file_from_index(state->repo->index, patch->old_name) < 0)
 			return error(_("unable to remove %s from index"), patch->old_name);
 	}
 	if (!state->cached) {
@@ -4301,7 +4310,7 @@ static int add_index_file(struct apply_state *state,
 				       "for newly created file %s"), path);
 		}
 	}
-	if (add_index_entry(&the_index, ce, ADD_CACHE_OK_TO_ADD) < 0) {
+	if (add_index_entry(state->repo->index, ce, ADD_CACHE_OK_TO_ADD) < 0) {
 		free(ce);
 		return error(_("unable to add cache entry for %s"), path);
 	}
@@ -4315,7 +4324,9 @@ static int add_index_file(struct apply_state *state,
  *   0 if everything went well
  *   1 if a recoverable error happened
  */
-static int try_create_file(const char *path, unsigned int mode, const char *buf, unsigned long size)
+static int try_create_file(struct apply_state *state, const char *path,
+			   unsigned int mode, const char *buf,
+			   unsigned long size)
 {
 	int fd, res;
 	struct strbuf nbuf = STRBUF_INIT;
@@ -4337,7 +4348,7 @@ static int try_create_file(const char *path, unsigned int mode, const char *buf,
 	if (fd < 0)
 		return 1;
 
-	if (convert_to_working_tree(path, buf, size, &nbuf)) {
+	if (convert_to_working_tree(state->repo->index, path, buf, size, &nbuf)) {
 		size = nbuf.len;
 		buf  = nbuf.buf;
 	}
@@ -4373,7 +4384,7 @@ static int create_one_file(struct apply_state *state,
 	if (state->cached)
 		return 0;
 
-	res = try_create_file(path, mode, buf, size);
+	res = try_create_file(state, path, mode, buf, size);
 	if (res < 0)
 		return -1;
 	if (!res)
@@ -4382,7 +4393,7 @@ static int create_one_file(struct apply_state *state,
 	if (errno == ENOENT) {
 		if (safe_create_leading_directories(path))
 			return 0;
-		res = try_create_file(path, mode, buf, size);
+		res = try_create_file(state, path, mode, buf, size);
 		if (res < 0)
 			return -1;
 		if (!res)
@@ -4404,7 +4415,7 @@ static int create_one_file(struct apply_state *state,
 		for (;;) {
 			char newpath[PATH_MAX];
 			mksnpath(newpath, sizeof(newpath), "%s~%u", path, nr);
-			res = try_create_file(newpath, mode, buf, size);
+			res = try_create_file(state, newpath, mode, buf, size);
 			if (res < 0)
 				return -1;
 			if (!res) {
@@ -4435,7 +4446,7 @@ static int add_conflicted_stages_file(struct apply_state *state,
 	ce_size = cache_entry_size(namelen);
 	mode = patch->new_mode ? patch->new_mode : (S_IFREG | 0644);
 
-	remove_file_from_index(&the_index, patch->new_name);
+	remove_file_from_index(state->repo->index, patch->new_name);
 	for (stage = 1; stage < 4; stage++) {
 		if (is_null_oid(&patch->threeway_stage[stage - 1]))
 			continue;
@@ -4445,7 +4456,7 @@ static int add_conflicted_stages_file(struct apply_state *state,
 		ce->ce_flags = create_ce_flags(stage);
 		ce->ce_namelen = namelen;
 		oidcpy(&ce->oid, &patch->threeway_stage[stage - 1]);
-		if (add_index_entry(&the_index, ce, ADD_CACHE_OK_TO_ADD) < 0) {
+		if (add_index_entry(state->repo->index, ce, ADD_CACHE_OK_TO_ADD) < 0) {
 			free(ce);
 			return error(_("unable to add cache entry for %s"),
 				     patch->new_name);
@@ -4619,7 +4630,7 @@ static int write_out_results(struct apply_state *state, struct patch *list)
 		}
 		string_list_clear(&cpath, 0);
 
-		rerere(0);
+		rerere(state->repo, 0);
 	}
 
 	return errs;
@@ -4697,7 +4708,8 @@ static int apply_patch(struct apply_state *state,
 						  state->index_file,
 						  LOCK_DIE_ON_ERROR);
 		else
-			hold_locked_index(&state->lock_file, LOCK_DIE_ON_ERROR);
+			repo_hold_locked_index(state->repo, &state->lock_file,
+					       LOCK_DIE_ON_ERROR);
 	}
 
 	if (state->check_index && read_apply_cache(state) < 0) {
@@ -4893,7 +4905,7 @@ int apply_all_patches(struct apply_state *state,
 	}
 
 	if (state->update_index) {
-		res = write_locked_index(&the_index, &state->lock_file, COMMIT_LOCK);
+		res = write_locked_index(state->repo->index, &state->lock_file, COMMIT_LOCK);
 		if (res) {
 			error(_("Unable to write new index file"));
 			res = -128;
-- 8< --

^ permalink raw reply related	[flat|nested] 32+ messages in thread

* Re: [PATCH 02/15] apply.c: stop using index compat macros
  2018-06-30  8:38     ` Duy Nguyen
@ 2018-07-03 18:30       ` Junio C Hamano
  2018-07-09 14:35         ` Duy Nguyen
  0 siblings, 1 reply; 32+ messages in thread
From: Junio C Hamano @ 2018-07-03 18:30 UTC (permalink / raw)
  To: Duy Nguyen; +Cc: git

Duy Nguyen <pclouds@gmail.com> writes:

> A singe patch conversion would look like below. But for that to
> happen, convert.c, rerere, ws.c and read-cache.c have to be converted
> first to not use the_index.

Yes, that was pretty much what I was driving at.  I do not have any
trouble seeing a patch that converts callees that are deep in the
callchain and are meant to serve helpers to make them capable of
working on arbitrary in-core index instance.  That's a welcome
change that allows us to reuse them in more context (namely, by
callers that want to work on istate that is not the_index
themselves).  Skipping the "intermediate" step like this patch would
force us to focus on converting these lower-layer dependencies.

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 02/15] apply.c: stop using index compat macros
  2018-07-03 18:30       ` Junio C Hamano
@ 2018-07-09 14:35         ` Duy Nguyen
  0 siblings, 0 replies; 32+ messages in thread
From: Duy Nguyen @ 2018-07-09 14:35 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Git Mailing List

On Tue, Jul 3, 2018 at 8:30 PM Junio C Hamano <gitster@pobox.com> wrote:
>
> Duy Nguyen <pclouds@gmail.com> writes:
>
> > A singe patch conversion would look like below. But for that to
> > happen, convert.c, rerere, ws.c and read-cache.c have to be converted
> > first to not use the_index.
>
> Yes, that was pretty much what I was driving at.  I do not have any
> trouble seeing a patch that converts callees that are deep in the
> callchain and are meant to serve helpers to make them capable of
> working on arbitrary in-core index instance.  That's a welcome
> change that allows us to reuse them in more context (namely, by
> callers that want to work on istate that is not the_index
> themselves).  Skipping the "intermediate" step like this patch would
> force us to focus on converting these lower-layer dependencies.

OK I'll drop part one and incorporate the changes in later patches.
-- 
Duy

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 01/15] contrib: add cocci script to replace index compat macros
  2018-06-19 15:21         ` Derrick Stolee
@ 2018-07-23 12:56           ` SZEDER Gábor
  0 siblings, 0 replies; 32+ messages in thread
From: SZEDER Gábor @ 2018-07-23 12:56 UTC (permalink / raw)
  To: Derrick Stolee; +Cc: Nguyễn Thái Ngọc Duy, Git mailing list

On Tue, Jun 19, 2018 at 5:21 PM Derrick Stolee <stolee@gmail.com> wrote:
>
> On 6/19/2018 10:51 AM, Duy Nguyen wrote:

> > Do we run 'make coccicheck'
> > automatically somewhere? If true, I need to move this script elsewhere
> > because it's meant to run manually. You run it when you intend to do
> > more manual fixups afterwards. For builtin/, I think I'll wait until
> > 'struct repository *' conversion is complete then maybe fix them one
> > by one.
>
> I don't think it is part of the CI runs, but some community members run
> this themselves on 'next' and 'master'.

Travis CI does run 'make coccicheck' already, that's the
"StaticAnalysis" build job.

Alas, it's not particularly useful as it is, because Coccinelle's and
in turn 'make coccicheck's exit code only indicates that Coccinelle
managed to finish its analysis without any errors (e.g. no unknown
--options, no missing files, no syntax errors in the semantic patches,
etc.), but it doesn't indicate whether it found any undesired code
patterns to transform or not.

I have been sitting on two patches implementing two different
approaches to improve this situation for several months now (sorry :)
I think I'll just pick the shorter-simpler of the two, and submit it
shortly.

^ permalink raw reply	[flat|nested] 32+ messages in thread

end of thread, other threads:[~2018-07-23 12:56 UTC | newest]

Thread overview: 32+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-16  5:41 [PATCH 00/15] Kill the_index part 1, expose it Nguyễn Thái Ngọc Duy
2018-06-16  5:41 ` [PATCH 01/15] contrib: add cocci script to replace index compat macros Nguyễn Thái Ngọc Duy
2018-06-19 11:35   ` Derrick Stolee
2018-06-19 11:41     ` Derrick Stolee
2018-06-19 14:51       ` Duy Nguyen
2018-06-19 15:21         ` Derrick Stolee
2018-07-23 12:56           ` SZEDER Gábor
2018-06-16  5:41 ` [PATCH 02/15] apply.c: stop using " Nguyễn Thái Ngọc Duy
2018-06-25 17:27   ` Junio C Hamano
2018-06-30  8:38     ` Duy Nguyen
2018-07-03 18:30       ` Junio C Hamano
2018-07-09 14:35         ` Duy Nguyen
2018-06-16  5:41 ` [PATCH 03/15] blame.c: " Nguyễn Thái Ngọc Duy
2018-06-16  5:41 ` [PATCH 04/15] check-racy.c: " Nguyễn Thái Ngọc Duy
2018-06-16  5:41 ` [PATCH 05/15] diff-lib.c: " Nguyễn Thái Ngọc Duy
2018-06-16  5:41 ` [PATCH 06/15] diff.c: " Nguyễn Thái Ngọc Duy
2018-06-16  5:41 ` [PATCH 07/15] entry.c: " Nguyễn Thái Ngọc Duy
2018-06-16  5:41 ` [PATCH 08/15] merge-recursive.c: " Nguyễn Thái Ngọc Duy
2018-06-16  5:41 ` [PATCH 09/15] merge.c: " Nguyễn Thái Ngọc Duy
2018-06-16  5:41 ` [PATCH 10/15] rerere.c: " Nguyễn Thái Ngọc Duy
2018-06-16  5:41 ` [PATCH 11/15] revision.c: " Nguyễn Thái Ngọc Duy
2018-06-16  5:41 ` [PATCH 12/15] sequencer.c: " Nguyễn Thái Ngọc Duy
2018-06-16  5:41 ` [PATCH 13/15] sha1-name.c: " Nguyễn Thái Ngọc Duy
2018-06-16  5:41 ` [PATCH 14/15] wt-status.c: " Nguyễn Thái Ngọc Duy
2018-06-16  5:41 ` [PATCH 15/15] cache.h: flip NO_THE_INDEX_COMPATIBILITY_MACROS switch Nguyễn Thái Ngọc Duy
2018-06-18 18:53   ` Brandon Williams
2018-06-17  7:02 ` [PATCH 00/15] Kill the_index part 1, expose it Elijah Newren
2018-06-17  8:49   ` Duy Nguyen
2018-06-18 18:41     ` Brandon Williams
2018-06-19 19:00       ` Ben Peart
2018-06-19 11:48 ` Derrick Stolee
2018-06-19 14:48   ` Duy Nguyen

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).