summaryrefslogtreecommitdiff
path: root/read-cache.c
diff options
context:
space:
mode:
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>2018-01-24 09:38:29 (GMT)
committerJunio C Hamano <gitster@pobox.com>2018-01-24 18:09:18 (GMT)
commitef5b3a6c5e24c54ba4436e225b9431c63ab163f0 (patch)
treeaf11b8f8180dff20a3cee936c7935e455ab3d963 /read-cache.c
parent59f9d2dd60f97c55c92c3273903f64048a27e513 (diff)
downloadgit-ef5b3a6c5e24c54ba4436e225b9431c63ab163f0.zip
git-ef5b3a6c5e24c54ba4436e225b9431c63ab163f0.tar.gz
git-ef5b3a6c5e24c54ba4436e225b9431c63ab163f0.tar.bz2
read-cache: don't write index twice if we can't write shared index
In a0a967568e ("update-index --split-index: do not split if $GIT_DIR is read only", 2014-06-13), we tried to make sure we can still write an index, even if the shared index can not be written. We did so by just calling 'do_write_locked_index()' just before 'write_shared_index()'. 'do_write_locked_index()' always at least closes the tempfile nowadays, and used to close or commit the lockfile if COMMIT_LOCK or CLOSE_LOCK were given at the time this feature was introduced. COMMIT_LOCK or CLOSE_LOCK is passed in by most callers of 'write_locked_index()'. After calling 'write_shared_index()', we call 'write_split_index()', which calls 'do_write_locked_index()' again, which then tries to use the closed lockfile again, but in fact fails to do so as it's already closed. This eventually leads to a segfault. Make sure to write the main index only once. [nd: most of the commit message and investigation done by Thomas, I only tweaked the solution a bit] Helped-by: Thomas Gummerer <t.gummerer@gmail.com> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'read-cache.c')
-rw-r--r--read-cache.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/read-cache.c b/read-cache.c
index c568643..c58c0a9 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -2561,8 +2561,9 @@ int write_locked_index(struct index_state *istate, struct lock_file *lock,
if (!temp) {
hashclr(si->base_sha1);
ret = do_write_locked_index(istate, lock, flags);
- } else
- ret = write_shared_index(istate, &temp);
+ goto out;
+ }
+ ret = write_shared_index(istate, &temp);
saved_errno = errno;
if (is_tempfile_active(temp))