diff mbox series

[v8,04/14] merge-index: drop the index

Message ID 20220809185429.20098-5-alban.gruin@gmail.com (mailing list archive)
State New, archived
Headers show
Series Rewrite the remaining merge strategies from shell to C | expand

Commit Message

Alban Gruin Aug. 9, 2022, 6:54 p.m. UTC
In an effort to reduce the usage of the global index throughout the
codebase, this removes references to it in `git merge-index'.

Signed-off-by: Alban Gruin <alban.gruin@gmail.com>
---
 builtin/merge-index.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/builtin/merge-index.c b/builtin/merge-index.c
index f66cc515d8..9d74b6e85c 100644
--- a/builtin/merge-index.c
+++ b/builtin/merge-index.c
@@ -1,4 +1,3 @@ 
-#define USE_THE_INDEX_COMPATIBILITY_MACROS
 #include "builtin.h"
 #include "merge-strategies.h"
 #include "run-command.h"
@@ -38,6 +37,7 @@  static int merge_one_file_spawn(struct index_state *istate,
 int cmd_merge_index(int argc, const char **argv, const char *prefix)
 {
 	int i, force_file = 0, err = 0, one_shot = 0, quiet = 0;
+	struct repository *r = the_repository;
 
 	/* Without this we cannot rely on waitpid() to tell
 	 * what happened to our children.
@@ -47,10 +47,11 @@  int cmd_merge_index(int argc, const char **argv, const char *prefix)
 	if (argc < 3)
 		usage("git merge-index [-o] [-q] <merge-program> (-a | [--] [<filename>...])");
 
-	read_cache();
+	if (repo_read_index(r) < 0)
+		die("invalid index");
 
 	/* TODO: audit for interaction with sparse-index. */
-	ensure_full_index(&the_index);
+	ensure_full_index(r->index);
 
 	i = 1;
 	if (!strcmp(argv[i], "-o")) {
@@ -72,13 +73,13 @@  int cmd_merge_index(int argc, const char **argv, const char *prefix)
 				continue;
 			}
 			if (!strcmp(arg, "-a")) {
-				err |= merge_all_index(&the_index, one_shot, quiet,
+				err |= merge_all_index(r->index, one_shot, quiet,
 						       merge_one_file_spawn, NULL);
 				continue;
 			}
 			die("git merge-index: unknown option %s", arg);
 		}
-		err |= merge_index_path(&the_index, one_shot, quiet, arg,
+		err |= merge_index_path(r->index, one_shot, quiet, arg,
 					merge_one_file_spawn, NULL);
 	}