All of lore.kernel.org
 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,
	Elijah Newren <newren@gmail.com>,
	Eric Sunshine <sunshine@sunshineco.com>,
	Alban Gruin <alban.gruin@gmail.com>,
	Derrick Stolee <stolee@gmail.com>,
	Derrick Stolee <derrickstolee@github.com>,
	Derrick Stolee <dstolee@microsoft.com>
Subject: [PATCH v3 13/14] update-index: reduce static globals, part 2
Date: Fri, 08 Jan 2021 20:02:56 +0000	[thread overview]
Message-ID: <a9185af4740d7b7fe2325604045ca8b6df0a52c0.1610136177.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.830.v3.git.1610136177.gitgitgadget@gmail.com>

From: Derrick Stolee <dstolee@microsoft.com>

In order to remove index compatibility macros cleanly, we relied upon
static globals 'repo' and 'istate' to be pointers to the_repository and
the_index, respectively. We can continue reducing the need for these
static globals by modifying method prototypes to use them when
necessary.

Move the remaining 'struct repository *repo' further down the file and
use method parameters to pass it around instead.

The only remaining change is to remove the static global entirely, but
that requires updating the parse-opt callbacks, which need a different
solution.

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
---
 builtin/update-index.c | 29 +++++++++++++++++------------
 1 file changed, 17 insertions(+), 12 deletions(-)

diff --git a/builtin/update-index.c b/builtin/update-index.c
index 9a83603c0db..3e01d62865f 100644
--- a/builtin/update-index.c
+++ b/builtin/update-index.c
@@ -593,9 +593,9 @@ static const char * const update_index_usage[] = {
 
 static struct object_id head_oid;
 static struct object_id merge_head_oid;
-static struct repository *repo;
 
-static struct cache_entry *read_one_ent(const char *which,
+static struct cache_entry *read_one_ent(struct repository *repo,
+					const char *which,
 					struct object_id *ent, const char *path,
 					int namelen, int stage)
 {
@@ -623,7 +623,8 @@ static struct cache_entry *read_one_ent(const char *which,
 	return ce;
 }
 
-static int unresolve_one(const char *path)
+static int unresolve_one(struct repository *repo,
+			 const char *path)
 {
 	int namelen = strlen(path);
 	int pos;
@@ -665,8 +666,8 @@ static int unresolve_one(const char *path)
 	 * stuff HEAD version in stage #2,
 	 * stuff MERGE_HEAD version in stage #3.
 	 */
-	ce_2 = read_one_ent("our", &head_oid, path, namelen, 2);
-	ce_3 = read_one_ent("their", &merge_head_oid, path, namelen, 3);
+	ce_2 = read_one_ent(repo, "our", &head_oid, path, namelen, 2);
+	ce_3 = read_one_ent(repo, "their", &merge_head_oid, path, namelen, 3);
 
 	if (!ce_2 || !ce_3) {
 		ret = -1;
@@ -705,7 +706,8 @@ static void read_head_pointers(void)
 	}
 }
 
-static int do_unresolve(int ac, const char **av,
+static int do_unresolve(struct repository *repo,
+			int ac, const char **av,
 			const char *prefix, int prefix_length)
 {
 	int i;
@@ -719,13 +721,14 @@ static int do_unresolve(int ac, const char **av,
 	for (i = 1; i < ac; i++) {
 		const char *arg = av[i];
 		char *p = prefix_path(prefix, prefix_length, arg);
-		err |= unresolve_one(p);
+		err |= unresolve_one(repo, p);
 		free(p);
 	}
 	return err;
 }
 
-static int do_reupdate(int ac, const char **av,
+static int do_reupdate(struct repository *repo,
+		       int ac, const char **av,
 		       const char *prefix)
 {
 	/* Read HEAD and run update-index on paths that are
@@ -754,7 +757,7 @@ static int do_reupdate(int ac, const char **av,
 		if (ce_stage(ce) || !ce_path_match(repo->index, ce, &pathspec, NULL))
 			continue;
 		if (has_head)
-			old = read_one_ent(NULL, &head_oid,
+			old = read_one_ent(repo, NULL, &head_oid,
 					   ce->name, ce_namelen(ce), 0);
 		if (old && ce->ce_mode == old->ce_mode &&
 		    oideq(&ce->oid, &old->oid)) {
@@ -782,6 +785,8 @@ struct refresh_params {
 	int *has_errors;
 };
 
+static struct repository *repo;
+
 static int refresh(struct refresh_params *o, unsigned int flag)
 {
 	setup_work_tree();
@@ -921,8 +926,8 @@ static enum parse_opt_result unresolve_callback(
 	BUG_ON_OPT_ARG(arg);
 
 	/* consume remaining arguments. */
-	*has_errors = do_unresolve(ctx->argc, ctx->argv,
-				prefix, prefix ? strlen(prefix) : 0);
+	*has_errors = do_unresolve(repo, ctx->argc, ctx->argv,
+				   prefix, prefix ? strlen(prefix) : 0);
 	if (*has_errors)
 		repo->index->cache_changed = 0;
 
@@ -943,7 +948,7 @@ static enum parse_opt_result reupdate_callback(
 
 	/* consume remaining arguments. */
 	setup_work_tree();
-	*has_errors = do_reupdate(ctx->argc, ctx->argv, prefix);
+	*has_errors = do_reupdate(repo, ctx->argc, ctx->argv, prefix);
 	if (*has_errors)
 		repo->index->cache_changed = 0;
 
-- 
gitgitgadget


  parent reply	other threads:[~2021-01-08 20:04 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 ` [PATCH 01/12] merge-index: drop " Derrick Stolee via GitGitGadget
2021-01-03 23:31   ` 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     ` Derrick Stolee via GitGitGadget [this message]
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=a9185af4740d7b7fe2325604045ca8b6df0a52c0.1610136177.git.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=alban.gruin@gmail.com \
    --cc=derrickstolee@github.com \
    --cc=dstolee@microsoft.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=newren@gmail.com \
    --cc=pclouds@gmail.com \
    --cc=stolee@gmail.com \
    --cc=sunshine@sunshineco.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.