Skip to content

Commit 29fefaf

Browse files
avargitster
authored andcommitted
sparse-index API: BUG() out on NULL ensure_full_index()
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 34110cd wants to pass us a NULL "dst_index". Let's instead do the NULL check in unpack_trees() itself. 1. 4300f84 (sparse-index: implement ensure_full_index(), 2021-03-30) 2. 0c18c05 (read-cache: ensure full index, 2021-04-01) 3. 34110cd (Make 'unpack_trees()' have a separate source and destination index, 2008-03-06) 4. 6863df3 (unpack-trees: ensure full index, 2021-03-30) Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Acked-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d2cdf2c commit 29fefaf

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

sparse-index.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ void expand_index(struct index_state *istate, struct pattern_list *pl)
299299
* If the index is already full, then keep it full. We will convert
300300
* it to a sparse index on write, if possible.
301301
*/
302-
if (!istate || istate->sparse_index == INDEX_EXPANDED)
302+
if (istate->sparse_index == INDEX_EXPANDED)
303303
return;
304304

305305
/*
@@ -424,6 +424,8 @@ void expand_index(struct index_state *istate, struct pattern_list *pl)
424424

425425
void ensure_full_index(struct index_state *istate)
426426
{
427+
if (!istate)
428+
BUG("ensure_full_index() must get an index!");
427429
expand_index(istate, NULL);
428430
}
429431

unpack-trees.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1880,7 +1880,8 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
18801880
prepare_repo_settings(repo);
18811881
if (repo->settings.command_requires_full_index) {
18821882
ensure_full_index(o->src_index);
1883-
ensure_full_index(o->dst_index);
1883+
if (o->dst_index)
1884+
ensure_full_index(o->dst_index);
18841885
}
18851886

18861887
if (o->reset == UNPACK_RESET_OVERWRITE_UNTRACKED &&

0 commit comments

Comments
 (0)