Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Schindelin <johannes.schindelin@gmx.de>2023-06-29 16:23:08 +0300
committerJunio C Hamano <gitster@pobox.com>2023-06-29 22:20:04 +0300
commit866b43e6442f16d0073ae9ce8d79b6cb1161b1a9 (patch)
treeb8e02d4b8875ba5953724d032c640da1111708ce /read-cache.c
parent0d1bd1dfb37ef25e1911777c94129fc769ffec38 (diff)
do_read_index(): always mark index as initialized unless erroring out
In 913e0e99b6a (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 <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'read-cache.c')
-rw-r--r--read-cache.c1
1 files changed, 1 insertions, 0 deletions
diff --git a/read-cache.c b/read-cache.c
index 35e5657877..1ac4defff3 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -2330,6 +2330,7 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist)
if (fd < 0) {
if (!must_exist && errno == ENOENT) {
set_new_index_sparsity(istate);
+ istate->initialized = 1;
return 0;
}
die_errno(_("%s: index file open failed"), path);