diff mbox series

[01/12] merge-index: drop index compatibility macros

Message ID 68d88b651c74659eb171e88d701b89d11e7f5f24.1609506428.git.gitgitgadget@gmail.com (mailing list archive)
State New
Headers show
Series Remove more index compatibility macros | expand

Commit Message

Derrick Stolee Jan. 1, 2021, 1:06 p.m. UTC
From: Derrick Stolee <dstolee@microsoft.com>

Replace uses of the old macros for the_index and instead pass around a
'struct index_state' pointer. This allows dropping the compatibility
flag.

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
---
 builtin/merge-index.c | 33 ++++++++++++++++++---------------
 1 file changed, 18 insertions(+), 15 deletions(-)

Comments

Alban Gruin Jan. 3, 2021, 11:31 p.m. UTC | #1
Hi Derrick,

Le 01/01/2021 à 14:06, Derrick Stolee via GitGitGadget a écrit :
> From: Derrick Stolee <dstolee@microsoft.com>
> 
> Replace uses of the old macros for the_index and instead pass around a
> 'struct index_state' pointer. This allows dropping the compatibility
> flag.
> 
> Signed-off-by: Derrick Stolee <dstolee@microsoft.com>

I already libified builtin/merge-index.c in ag/merge-strategies-in-c,
and such dropped the_index.  I modified merge_entry(), merge_one_path()
and merge_all() to take a callback, itself taking a repository.  As
such, in my series, these functions take a `struct repository *' instead
of an index state.

I'm not sure how we should proceed with our respective patches.

Cheers,
Alban
Derrick Stolee Jan. 4, 2021, 11:08 a.m. UTC | #2
On 1/3/2021 6:31 PM, Alban Gruin wrote:
> Hi Derrick,
> 
> Le 01/01/2021 à 14:06, Derrick Stolee via GitGitGadget a écrit :
>> From: Derrick Stolee <dstolee@microsoft.com>
>>
>> Replace uses of the old macros for the_index and instead pass around a
>> 'struct index_state' pointer. This allows dropping the compatibility
>> flag.
>>
>> Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
> 
> I already libified builtin/merge-index.c in ag/merge-strategies-in-c,
> and such dropped the_index.  I modified merge_entry(), merge_one_path()
> and merge_all() to take a callback, itself taking a repository.  As
> such, in my series, these functions take a `struct repository *' instead
> of an index state.
> 
> I'm not sure how we should proceed with our respective patches.

Hi Alban,

Sorry I didn't realize that. I'll drop this patch. Thanks for letting
me know!

Thanks,
-Stolee
diff mbox series

Patch

diff --git a/builtin/merge-index.c b/builtin/merge-index.c
index 38ea6ad6ca2..8c7e6b0e6a2 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 "run-command.h"
 
@@ -6,18 +5,19 @@  static const char *pgm;
 static int one_shot, quiet;
 static int err;
 
-static int merge_entry(int pos, const char *path)
+static int merge_entry(struct index_state *istate,
+		       int pos, const char *path)
 {
 	int found;
 	const char *arguments[] = { pgm, "", "", "", path, "", "", "", NULL };
 	char hexbuf[4][GIT_MAX_HEXSZ + 1];
 	char ownbuf[4][60];
 
-	if (pos >= active_nr)
+	if (pos >= istate->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 = istate->cache[pos];
 		int stage = ce_stage(ce);
 
 		if (strcmp(ce->name, path))
@@ -27,7 +27,7 @@  static int merge_entry(int pos, const char *path)
 		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 < istate->cache_nr);
 	if (!found)
 		die("git merge-index: %s not in the cache", path);
 
@@ -43,32 +43,34 @@  static int merge_entry(int pos, const char *path)
 	return found;
 }
 
-static void merge_one_path(const char *path)
+static void merge_one_path(struct index_state *istate,
+			   const char *path)
 {
-	int pos = cache_name_pos(path, strlen(path));
+	int pos = index_name_pos(istate, path, strlen(path));
 
 	/*
 	 * If it already exists in the cache as stage0, it's
 	 * already merged and there is nothing to do.
 	 */
 	if (pos < 0)
-		merge_entry(-pos-1, path);
+		merge_entry(istate, -pos - 1, path);
 }
 
-static void merge_all(void)
+static void merge_all(struct index_state *istate)
 {
 	int i;
-	for (i = 0; i < active_nr; i++) {
-		const struct cache_entry *ce = active_cache[i];
+	for (i = 0; i < istate->cache_nr; i++) {
+		const struct cache_entry *ce = istate->cache[i];
 		if (!ce_stage(ce))
 			continue;
-		i += merge_entry(i, ce->name)-1;
+		i += merge_entry(istate, i, ce->name)-1;
 	}
 }
 
 int cmd_merge_index(int argc, const char **argv, const char *prefix)
 {
 	int i, force_file = 0;
+	struct index_state *istate;
 
 	/* Without this we cannot rely on waitpid() to tell
 	 * what happened to our children.
@@ -78,7 +80,8 @@  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();
+	repo_read_index(the_repository);
+	istate = the_repository->index;
 
 	i = 1;
 	if (!strcmp(argv[i], "-o")) {
@@ -98,12 +101,12 @@  int cmd_merge_index(int argc, const char **argv, const char *prefix)
 				continue;
 			}
 			if (!strcmp(arg, "-a")) {
-				merge_all();
+				merge_all(istate);
 				continue;
 			}
 			die("git merge-index: unknown option %s", arg);
 		}
-		merge_one_path(arg);
+		merge_one_path(istate, arg);
 	}
 	if (err && !quiet)
 		die("merge program failed");