git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
	"Derrick Stolee" <derrickstolee@github.com>,
	"Victoria Dye" <vdye@github.com>,
	"Jeff Hostetler" <jeffhost@microsoft.com>,
	"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Subject: [PATCH v2 3/6] sparse-index API: BUG() out on NULL ensure_full_index()
Date: Thu, 12 Jan 2023 13:55:25 +0100	[thread overview]
Message-ID: <patch-v2-3.6-25e9cff0e97-20230112T124842Z-avarab@gmail.com> (raw)
In-Reply-To: <cover-v2-0.6-00000000000-20230112T124842Z-avarab@gmail.com>

Make the ensure_full_index() function stricter, and have it only
accept a non-NULL "struct index_state". This function (and this
behavior) was added in [1].

The only reason it needed to be this lax was due to interaction with
repo_index_has_changes(). See the addition of that code in [2].

The other reason for why this was needed dates back to interaction
with code added in [3]. In [4] we started calling ensure_full_index()
in unpack_trees(), but the caller added in 34110cd4e39 wants to pass
us a NULL "dst_index". Let's instead do the NULL check in
unpack_trees() itself.

1. 4300f8442a2 (sparse-index: implement ensure_full_index(), 2021-03-30)
2. 0c18c059a15 (read-cache: ensure full index, 2021-04-01)
3. 34110cd4e39 (Make 'unpack_trees()' have a separate source and
   destination index, 2008-03-06)
4. 6863df35503 (unpack-trees: ensure full index, 2021-03-30)

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 sparse-index.c | 4 +++-
 unpack-trees.c | 3 ++-
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/sparse-index.c b/sparse-index.c
index 65a08d33c73..86e3b99870b 100644
--- a/sparse-index.c
+++ b/sparse-index.c
@@ -299,7 +299,7 @@ void expand_index(struct index_state *istate, struct pattern_list *pl)
 	 * If the index is already full, then keep it full. We will convert
 	 * it to a sparse index on write, if possible.
 	 */
-	if (!istate || istate->sparse_index == INDEX_EXPANDED)
+	if (istate->sparse_index == INDEX_EXPANDED)
 		return;
 
 	/*
@@ -424,6 +424,8 @@ void expand_index(struct index_state *istate, struct pattern_list *pl)
 
 void ensure_full_index(struct index_state *istate)
 {
+	if (!istate)
+		BUG("ensure_full_index() must get an index!");
 	expand_index(istate, NULL);
 }
 
diff --git a/unpack-trees.c b/unpack-trees.c
index ea09023b015..2381cd7cac4 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -1880,7 +1880,8 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
 	prepare_repo_settings(repo);
 	if (repo->settings.command_requires_full_index) {
 		ensure_full_index(o->src_index);
-		ensure_full_index(o->dst_index);
+		if (o->dst_index)
+			ensure_full_index(o->dst_index);
 	}
 
 	if (o->reset == UNPACK_RESET_OVERWRITE_UNTRACKED &&
-- 
2.39.0.1205.g2ca064edc27


  parent reply	other threads:[~2023-01-12 12:55 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-10  6:17 [PATCH 0/5] cache API: always have a "istate->repo" Ævar Arnfjörð Bjarmason
2023-01-10  6:17 ` [PATCH 1/5] builtin/difftool.c: { 0 }-initialize rather than using memset() Ævar Arnfjörð Bjarmason
2023-01-10  6:17 ` [PATCH 2/5] sparse-index.c: expand_to_path() can assume non-NULL "istate" Ævar Arnfjörð Bjarmason
2023-01-10  6:17 ` [PATCH 3/5] sparse-index API: fix TODO, BUG() out on NULL ensure_full_index() Ævar Arnfjörð Bjarmason
2023-01-10 10:35   ` Philip Oakley
2023-01-10 12:22     ` Ævar Arnfjörð Bjarmason
2023-01-10 14:58   ` Derrick Stolee
2023-01-10  6:17 ` [PATCH 4/5] read-cache.c: refactor set_new_index_sparsity() for subsequent commit Ævar Arnfjörð Bjarmason
2023-01-10  6:17 ` [PATCH 5/5] treewide: always have a valid "index_state.repo" member Ævar Arnfjörð Bjarmason
2023-01-10 12:24   ` Ævar Arnfjörð Bjarmason
2023-01-10 13:13   ` Jeff Hostetler
2023-01-10 15:08   ` Derrick Stolee
2023-01-10 15:09 ` [PATCH 0/5] cache API: always have a "istate->repo" Derrick Stolee
2023-01-12 12:55 ` [PATCH v2 0/6] " Ævar Arnfjörð Bjarmason
2023-01-12 12:55   ` [PATCH v2 1/6] builtin/difftool.c: { 0 }-initialize rather than using memset() Ævar Arnfjörð Bjarmason
2023-01-12 12:55   ` [PATCH v2 2/6] sparse-index.c: expand_to_path() can assume non-NULL "istate" Ævar Arnfjörð Bjarmason
2023-01-12 12:55   ` Ævar Arnfjörð Bjarmason [this message]
2023-01-12 12:55   ` [PATCH v2 4/6] read-cache.c: refactor set_new_index_sparsity() for subsequent commit Ævar Arnfjörð Bjarmason
2023-01-12 12:55   ` [PATCH v2 5/6] cache API: add a "INDEX_STATE_INIT" macro/function, add release_index() Ævar Arnfjörð Bjarmason
2023-01-12 15:21     ` Derrick Stolee
2023-01-12 16:19       ` Ævar Arnfjörð Bjarmason
2023-01-12 16:47         ` Derrick Stolee
2023-01-12 12:55   ` [PATCH v2 6/6] treewide: always have a valid "index_state.repo" member Ævar Arnfjörð Bjarmason
2023-01-12 15:22     ` Derrick Stolee
2023-01-12 15:23   ` [PATCH v2 0/6] cache API: always have a "istate->repo" Derrick Stolee
2023-01-13 18:29     ` Junio C Hamano
2023-01-13 19:22   ` Junio C Hamano
2023-01-16 13:38     ` Ævar Arnfjörð Bjarmason
2023-01-16 16:53       ` Philip Oakley
2023-01-16 18:39         ` Junio C Hamano
2023-01-17 13:57           ` [PATCH] treewide: always have a valid "index_state.repo" member Ævar Arnfjörð Bjarmason
2023-01-17 15:34             ` Derrick Stolee

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=patch-v2-3.6-25e9cff0e97-20230112T124842Z-avarab@gmail.com \
    --to=avarab@gmail.com \
    --cc=derrickstolee@github.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jeffhost@microsoft.com \
    --cc=vdye@github.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).