git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
To: git@vger.kernel.org
Cc: "Taylor Blau" <me@ttaylorr.com>,
	"Junio C Hamano" <gitster@pobox.com>,
	"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Subject: [PATCH 04/12] read-cache API & users: make discard_index() return void
Date: Fri, 18 Nov 2022 12:30:58 +0100	[thread overview]
Message-ID: <patch-04.12-362a14a0539-20221118T112205Z-avarab@gmail.com> (raw)
In-Reply-To: <cover-00.12-00000000000-20221118T112205Z-avarab@gmail.com>

The discard_index() function has not returned non-zero since
7a51ed66f65 (Make on-disk index representation separate from in-core
one, 2008-01-14), but we've had various code in-tree still acting as
though that might be the case.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 add-interactive.c |  8 ++++----
 add-patch.c       |  3 ++-
 builtin/merge.c   |  3 ++-
 cache.h           |  2 +-
 read-cache.c      |  4 +---
 sequencer.c       | 15 +++++++++------
 6 files changed, 19 insertions(+), 16 deletions(-)

diff --git a/add-interactive.c b/add-interactive.c
index ecc5ae1b249..ae1839c04a7 100644
--- a/add-interactive.c
+++ b/add-interactive.c
@@ -530,8 +530,8 @@ static int get_modified_files(struct repository *r,
 	struct collection_status s = { 0 };
 	int i;
 
-	if (discard_index(r->index) < 0 ||
-	    repo_read_index_preload(r, ps, 0) < 0)
+	discard_index(r->index);
+	if (repo_read_index_preload(r, ps, 0) < 0)
 		return error(_("could not read index"));
 
 	prefix_item_list_clear(files);
@@ -1156,8 +1156,8 @@ int run_add_i(struct repository *r, const struct pathspec *ps)
 		    _("staged"), _("unstaged"), _("path"));
 	opts.list_opts.header = header.buf;
 
-	if (discard_index(r->index) < 0 ||
-	    repo_read_index(r) < 0 ||
+	discard_index(r->index);
+	if (repo_read_index(r) < 0 ||
 	    repo_refresh_and_write_index(r, REFRESH_QUIET, 0, 1,
 					 NULL, NULL, NULL) < 0)
 		warning(_("could not refresh index"));
diff --git a/add-patch.c b/add-patch.c
index 33ecd8398a1..a86a92e1646 100644
--- a/add-patch.c
+++ b/add-patch.c
@@ -1750,7 +1750,8 @@ int run_add_p(struct repository *r, enum add_p_mode mode,
 		s.mode = &patch_mode_add;
 	s.revision = revision;
 
-	if (discard_index(r->index) < 0 || repo_read_index(r) < 0 ||
+	discard_index(r->index);
+	if (repo_read_index(r) < 0 ||
 	    (!s.mode->index_only &&
 	     repo_refresh_and_write_index(r, REFRESH_QUIET, 0, 1,
 					  NULL, NULL, NULL) < 0) ||
diff --git a/builtin/merge.c b/builtin/merge.c
index da11dfae19e..89fdac24e40 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -390,7 +390,8 @@ static void restore_state(const struct object_id *head,
 	run_command(&cmd);
 
 refresh_cache:
-	if (discard_cache() < 0 || read_cache() < 0)
+	discard_cache();
+	if (read_cache() < 0)
 		die(_("could not read index"));
 }
 
diff --git a/cache.h b/cache.h
index 53dc4341717..489e9e1925b 100644
--- a/cache.h
+++ b/cache.h
@@ -774,7 +774,7 @@ void ensure_full_index(struct index_state *istate);
  */
 int write_locked_index(struct index_state *, struct lock_file *lock, unsigned flags);
 
-int discard_index(struct index_state *);
+void discard_index(struct index_state *);
 void move_index_extensions(struct index_state *dst, struct index_state *src);
 int unmerged_index(const struct index_state *);
 
diff --git a/read-cache.c b/read-cache.c
index 32024029274..46f5e497b14 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -2531,7 +2531,7 @@ int is_index_unborn(struct index_state *istate)
 	return (!istate->cache_nr && !istate->timestamp.sec);
 }
 
-int discard_index(struct index_state *istate)
+void discard_index(struct index_state *istate)
 {
 	/*
 	 * Cache entries in istate->cache[] should have been allocated
@@ -2562,8 +2562,6 @@ int discard_index(struct index_state *istate)
 		mem_pool_discard(istate->ce_mem_pool, should_validate_cache_entries());
 		FREE_AND_NULL(istate->ce_mem_pool);
 	}
-
-	return 0;
 }
 
 /*
diff --git a/sequencer.c b/sequencer.c
index f0f1af4d478..58ad2a77565 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -3564,7 +3564,8 @@ static int do_exec(struct repository *r, const char *command_line)
 	status = run_command(&cmd);
 
 	/* force re-reading of the cache */
-	if (discard_index(r->index) < 0 || repo_read_index(r) < 0)
+	discard_index(r->index);
+	if (repo_read_index(r) < 0)
 		return error(_("could not read index"));
 
 	dirty = require_clean_work_tree(r, "rebase", NULL, 1, 1);
@@ -4028,9 +4029,11 @@ static int do_merge(struct repository *r,
 		ret = run_command(&cmd);
 
 		/* force re-reading of the cache */
-		if (!ret && (discard_index(r->index) < 0 ||
-			     repo_read_index(r) < 0))
-			ret = error(_("could not read index"));
+		if (!ret) {
+			discard_index(r->index);
+			if (repo_read_index(r) < 0)
+				ret = error(_("could not read index"));
+		}
 		goto leave_merge;
 	}
 
@@ -4400,8 +4403,8 @@ void create_autostash(struct repository *r, const char *path)
 		printf(_("Created autostash: %s\n"), buf.buf);
 		if (reset_head(r, &ropts) < 0)
 			die(_("could not reset --hard"));
-		if (discard_index(r->index) < 0 ||
-			repo_read_index(r) < 0)
+		discard_index(r->index);
+		if (repo_read_index(r) < 0)
 			die(_("could not read index"));
 	}
 	strbuf_release(&buf);
-- 
2.38.0.1511.gcdcff1f1dc2


  parent reply	other threads:[~2022-11-18 11:31 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-18 11:30 [PATCH 00/12] tree-wide: chip away at USE_THE_INDEX_COMPATIBILITY_MACROS Ævar Arnfjörð Bjarmason
2022-11-18 11:30 ` [PATCH 01/12] cache.h: remove unused "the_index" compat macros Ævar Arnfjörð Bjarmason
2022-11-18 11:30 ` [PATCH 02/12] builtin/{grep,log}.: don't define "USE_THE_INDEX_COMPATIBILITY_MACROS" Ævar Arnfjörð Bjarmason
2022-11-18 11:30 ` [PATCH 03/12] cocci & cache.h: remove rarely used "the_index" compat macros Ævar Arnfjörð Bjarmason
2022-11-18 11:30 ` Ævar Arnfjörð Bjarmason [this message]
2022-11-18 11:30 ` [PATCH 05/12] cocci: add a index-compatibility.pending.cocci Ævar Arnfjörð Bjarmason
2022-11-18 11:31 ` [PATCH 06/12] cocci & cache.h: apply a selection of "pending" index-compatibility Ævar Arnfjörð Bjarmason
2022-11-18 11:31 ` [PATCH 07/12] cocci & cache.h: apply variable section " Ævar Arnfjörð Bjarmason
2022-11-18 11:31 ` [PATCH 08/12] cocci: apply "pending" index-compatibility to "t/helper/*.c" Ævar Arnfjörð Bjarmason
2022-11-18 11:31 ` [PATCH 09/12] {builtin/*,repository}.c: add & use "USE_THE_INDEX_VARIABLE" Ævar Arnfjörð Bjarmason
2022-11-18 18:41   ` Taylor Blau
2022-11-18 11:31 ` [PATCH 10/12] cache.h & test-tool.h: " Ævar Arnfjörð Bjarmason
2022-11-18 18:41   ` Taylor Blau
2022-11-18 11:31 ` [PATCH 11/12] cocci: apply "pending" index-compatibility to some "builtin/*.c" Ævar Arnfjörð Bjarmason
2022-11-18 11:31 ` [PATCH 12/12] builtin/*: remove or amend "USE_THE_INDEX_COMPATIBILITY_MACROS" Ævar Arnfjörð Bjarmason
2022-11-18 18:42   ` Taylor Blau
2022-11-18 19:27     ` Ævar Arnfjörð Bjarmason
2022-11-18 23:04       ` Taylor Blau
2022-11-18 12:13 ` [PATCH 00/12] tree-wide: chip away at USE_THE_INDEX_COMPATIBILITY_MACROS Phillip Wood
2022-11-18 12:21   ` Ævar Arnfjörð Bjarmason
2022-11-19 13:07 ` [PATCH v2 00/11] " Ævar Arnfjörð Bjarmason
2022-11-19 13:07   ` [PATCH v2 01/11] cache.h: remove unused "the_index" compat macros Ævar Arnfjörð Bjarmason
2022-11-19 13:07   ` [PATCH v2 02/11] builtin/{grep,log}.: don't define "USE_THE_INDEX_COMPATIBILITY_MACROS" Ævar Arnfjörð Bjarmason
2022-11-19 13:07   ` [PATCH v2 03/11] cocci & cache.h: remove rarely used "the_index" compat macros Ævar Arnfjörð Bjarmason
2022-11-19 13:07   ` [PATCH v2 04/11] read-cache API & users: make discard_index() return void Ævar Arnfjörð Bjarmason
2022-11-19 13:07   ` [PATCH v2 05/11] cocci: add a index-compatibility.pending.cocci Ævar Arnfjörð Bjarmason
2022-11-19 13:07   ` [PATCH v2 06/11] cocci & cache.h: apply a selection of "pending" index-compatibility Ævar Arnfjörð Bjarmason
2022-11-19 13:07   ` [PATCH v2 07/11] cocci & cache.h: apply variable section " Ævar Arnfjörð Bjarmason
2022-11-19 13:07   ` [PATCH v2 08/11] cocci: apply "pending" index-compatibility to "t/helper/*.c" Ævar Arnfjörð Bjarmason
2022-11-19 13:07   ` [PATCH v2 09/11] {builtin/*,repository}.c: add & use "USE_THE_INDEX_VARIABLE" Ævar Arnfjörð Bjarmason
2022-11-19 13:07   ` [PATCH v2 10/11] cache.h & test-tool.h: " Ævar Arnfjörð Bjarmason
2022-11-19 13:07   ` [PATCH v2 11/11] cocci: apply "pending" index-compatibility to some "builtin/*.c" Ævar Arnfjörð Bjarmason

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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=patch-04.12-362a14a0539-20221118T112205Z-avarab@gmail.com \
    --to=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=me@ttaylorr.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.
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).