git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Derrick Stolee via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: pclouds@gmail.com, gitster@pobox.com,
	Derrick Stolee <derrickstolee@github.com>,
	Derrick Stolee <dstolee@microsoft.com>
Subject: [PATCH 01/12] merge-index: drop index compatibility macros
Date: Fri, 01 Jan 2021 13:06:57 +0000	[thread overview]
Message-ID: <68d88b651c74659eb171e88d701b89d11e7f5f24.1609506428.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.830.git.1609506428.gitgitgadget@gmail.com>

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(-)

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");
-- 
gitgitgadget


  reply	other threads:[~2021-01-01 13:08 UTC|newest]

Thread overview: 65+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-01 13:06 [PATCH 00/12] Remove more index compatibility macros Derrick Stolee via GitGitGadget
2021-01-01 13:06 ` Derrick Stolee via GitGitGadget [this message]
2021-01-03 23:31   ` [PATCH 01/12] merge-index: drop " Alban Gruin
2021-01-04 11:08     ` Derrick Stolee
2021-01-01 13:06 ` [PATCH 02/12] mv: remove " Derrick Stolee via GitGitGadget
2021-01-01 13:06 ` [PATCH 03/12] rm: remove compatilibity macros Derrick Stolee via GitGitGadget
2021-01-01 13:07 ` [PATCH 04/12] update-index: drop the_index, the_repository Derrick Stolee via GitGitGadget
2021-01-01 21:05   ` Elijah Newren
2021-01-04  0:56     ` Derrick Stolee
2021-01-01 13:07 ` [PATCH 05/12] update-index: use istate->cache over active_cache Derrick Stolee via GitGitGadget
2021-01-01 13:07 ` [PATCH 06/12] update-index: use index->cache_nr over active_nr Derrick Stolee via GitGitGadget
2021-01-01 13:07 ` [PATCH 07/12] update-index: use istate->cache_changed Derrick Stolee via GitGitGadget
2021-01-01 13:07 ` [PATCH 08/12] update-index: use index_name_pos() over cache_name_pos() Derrick Stolee via GitGitGadget
2021-01-01 13:07 ` [PATCH 09/12] update-index: use remove_file_from_index() Derrick Stolee via GitGitGadget
2021-01-01 13:07 ` [PATCH 10/12] update-index: use add_index_entry() Derrick Stolee via GitGitGadget
2021-01-01 13:07 ` [PATCH 11/12] update-index: replace several compatibility macros Derrick Stolee via GitGitGadget
2021-01-01 13:07 ` [PATCH 12/12] update-index: remove ce_match_stat(), all macros Derrick Stolee via GitGitGadget
2021-01-01 21:12   ` Elijah Newren
2021-01-01 21:16 ` [PATCH 00/12] Remove more index compatibility macros Elijah Newren
2021-01-02  6:12 ` Eric Sunshine
2021-01-04  1:01   ` Derrick Stolee
2021-01-04  6:22     ` Eric Sunshine
2021-01-05  4:41       ` Derrick Stolee
2021-01-05  4:42 ` [PATCH v2 00/14] " Derrick Stolee via GitGitGadget
2021-01-05  4:42   ` [PATCH v2 01/14] mv: remove " Derrick Stolee via GitGitGadget
2021-01-05  4:42   ` [PATCH v2 02/14] rm: remove compatilibity macros Derrick Stolee via GitGitGadget
2021-01-05  4:42   ` [PATCH v2 03/14] update-index: drop the_index, the_repository Derrick Stolee via GitGitGadget
2021-01-05  4:42   ` [PATCH v2 04/14] update-index: use istate->cache over active_cache Derrick Stolee via GitGitGadget
2021-01-05  4:42   ` [PATCH v2 05/14] update-index: use index->cache_nr over active_nr Derrick Stolee via GitGitGadget
2021-01-05  4:42   ` [PATCH v2 06/14] update-index: use istate->cache_changed Derrick Stolee via GitGitGadget
2021-01-05  4:42   ` [PATCH v2 07/14] update-index: use index_name_pos() over cache_name_pos() Derrick Stolee via GitGitGadget
2021-01-05  4:42   ` [PATCH v2 08/14] update-index: use remove_file_from_index() Derrick Stolee via GitGitGadget
2021-01-05  4:42   ` [PATCH v2 09/14] update-index: use add_index_entry() Derrick Stolee via GitGitGadget
2021-01-05  4:42   ` [PATCH v2 10/14] update-index: replace several compatibility macros Derrick Stolee via GitGitGadget
2021-01-05  4:43   ` [PATCH v2 11/14] update-index: remove ce_match_stat(), all macros Derrick Stolee via GitGitGadget
2021-01-05  4:43   ` [PATCH v2 12/14] update-index: reduce static globals, part 1 Derrick Stolee via GitGitGadget
2021-01-05  4:43   ` [PATCH v2 13/14] update-index: reduce static globals, part 2 Derrick Stolee via GitGitGadget
2021-01-05  4:43   ` [PATCH v2 14/14] update-index: remove static globals from callbacks Derrick Stolee via GitGitGadget
2021-01-07  5:09     ` Eric Sunshine
2021-01-07 11:19       ` Derrick Stolee
2021-01-07 18:53         ` Eric Sunshine
2021-01-07 19:57           ` Junio C Hamano
2021-01-08  1:52             ` Derrick Stolee
2021-01-08 20:02   ` [PATCH v3 00/14] Remove more index compatibility macros Derrick Stolee via GitGitGadget
2021-01-08 20:02     ` [PATCH v3 01/14] mv: remove " Derrick Stolee via GitGitGadget
2021-01-08 20:02     ` [PATCH v3 02/14] rm: remove compatilibity macros Derrick Stolee via GitGitGadget
2021-01-08 20:02     ` [PATCH v3 03/14] update-index: drop the_index, the_repository Derrick Stolee via GitGitGadget
2021-01-08 20:02     ` [PATCH v3 04/14] update-index: use istate->cache over active_cache Derrick Stolee via GitGitGadget
2021-01-08 20:02     ` [PATCH v3 05/14] update-index: use istate->cache_nr over active_nr Derrick Stolee via GitGitGadget
2021-01-08 20:02     ` [PATCH v3 06/14] update-index: use istate->cache_changed Derrick Stolee via GitGitGadget
2021-01-08 20:02     ` [PATCH v3 07/14] update-index: use index_name_pos() over cache_name_pos() Derrick Stolee via GitGitGadget
2021-01-08 20:02     ` [PATCH v3 08/14] update-index: use remove_file_from_index() Derrick Stolee via GitGitGadget
2021-01-08 20:02     ` [PATCH v3 09/14] update-index: use add_index_entry() Derrick Stolee via GitGitGadget
2021-01-08 20:02     ` [PATCH v3 10/14] update-index: replace several compatibility macros Derrick Stolee via GitGitGadget
2021-01-08 20:02     ` [PATCH v3 11/14] update-index: remove ce_match_stat(), all macros Derrick Stolee via GitGitGadget
2021-01-08 20:02     ` [PATCH v3 12/14] update-index: reduce static globals, part 1 Derrick Stolee via GitGitGadget
2021-01-08 20:02     ` [PATCH v3 13/14] update-index: reduce static globals, part 2 Derrick Stolee via GitGitGadget
2021-01-08 20:02     ` [PATCH v3 14/14] update-index: remove static globals from callbacks Derrick Stolee via GitGitGadget
2021-01-10  7:03     ` [PATCH v3 00/14] Remove more index compatibility macros Junio C Hamano
2021-01-10  7:32       ` Eric Sunshine
2021-01-10 11:57       ` Derrick Stolee
2021-01-25 13:04       ` Derrick Stolee
2021-01-06  3:55 ` [PATCH 00/12] " Junio C Hamano
2021-01-06 11:35   ` Derrick Stolee
2021-01-06 20:52     ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=68d88b651c74659eb171e88d701b89d11e7f5f24.1609506428.git.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=derrickstolee@github.com \
    --cc=dstolee@microsoft.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=pclouds@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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 NNTP newsgroup(s).