Skip to content

Commit 866b43e

Browse files
dschogitster
authored andcommitted
do_read_index(): always mark index as initialized unless erroring out
In 913e0e9 (unpack_trees(): protect the handcrafted in-core index from read_cache(), 2008-08-23) a flag was introduced into the `index_state` structure to indicate whether it had been initialized (or more correctly: read and parsed). There was one code path that was not handled, though: when the index file does not yet exist (but the `must_exist` parameter is set to 0 to indicate that that's okay). In this instance, Git wants to go forward with a new, pristine Git index, almost as if the file had existed and contained no index entries or extensions. Since Git wants to handle this situation the same as if an "empty" Git index file existed, let's set the `initialized` flag also in that case. This is necessary to prepare for fixing the bug where the condition `cache_nr == 0` is incorrectly used as an indicator that the index was already read, and the condition `initialized != 0` needs to be used instead. Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0d1bd1d commit 866b43e

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

read-cache.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2330,6 +2330,7 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist)
23302330
if (fd < 0) {
23312331
if (!must_exist && errno == ENOENT) {
23322332
set_new_index_sparsity(istate);
2333+
istate->initialized = 1;
23332334
return 0;
23342335
}
23352336
die_errno(_("%s: index file open failed"), path);

0 commit comments

Comments
 (0)