summaryrefslogtreecommitdiff
path: root/read-cache.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2018-02-13 21:39:14 (GMT)
committerJunio C Hamano <gitster@pobox.com>2018-02-13 21:39:14 (GMT)
commitdd0c256b67d1b128655c42ae126fa3397b1f9ede (patch)
treea2c7abcf6d0ccc8a89f2185070343d6402a4b7f4 /read-cache.c
parent39a1dd80f8e9542603904bdf2e62d140a88c7e38 (diff)
parentef5b3a6c5e24c54ba4436e225b9431c63ab163f0 (diff)
downloadgit-dd0c256b67d1b128655c42ae126fa3397b1f9ede.zip
git-dd0c256b67d1b128655c42ae126fa3397b1f9ede.tar.gz
git-dd0c256b67d1b128655c42ae126fa3397b1f9ede.tar.bz2
Merge branch 'nd/shared-index-fix'
Code clean-up. * nd/shared-index-fix: read-cache: don't write index twice if we can't write shared index read-cache.c: move tempfile creation/cleanup out of write_shared_index read-cache.c: change type of "temp" in write_shared_index()
Diffstat (limited to 'read-cache.c')
-rw-r--r--read-cache.c40
1 files changed, 22 insertions, 18 deletions
diff --git a/read-cache.c b/read-cache.c
index 9e0aeff..9925a94 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -2471,32 +2471,21 @@ static int clean_shared_index_files(const char *current_hex)
}
static int write_shared_index(struct index_state *istate,
- struct lock_file *lock, unsigned flags)
+ struct tempfile **temp)
{
- struct tempfile *temp;
struct split_index *si = istate->split_index;
int ret;
- temp = mks_tempfile(git_path("sharedindex_XXXXXX"));
- if (!temp) {
- hashclr(si->base_sha1);
- return do_write_locked_index(istate, lock, flags);
- }
move_cache_to_base_index(istate);
- ret = do_write_index(si->base, temp, 1);
- if (ret) {
- delete_tempfile(&temp);
+ ret = do_write_index(si->base, *temp, 1);
+ if (ret)
return ret;
- }
- ret = adjust_shared_perm(get_tempfile_path(temp));
+ ret = adjust_shared_perm(get_tempfile_path(*temp));
if (ret) {
- int save_errno = errno;
- error("cannot fix permission bits on %s", get_tempfile_path(temp));
- delete_tempfile(&temp);
- errno = save_errno;
+ error("cannot fix permission bits on %s", get_tempfile_path(*temp));
return ret;
}
- ret = rename_tempfile(&temp,
+ ret = rename_tempfile(temp,
git_path("sharedindex.%s", sha1_to_hex(si->base->sha1)));
if (!ret) {
hashcpy(si->base_sha1, si->base->sha1);
@@ -2564,7 +2553,22 @@ int write_locked_index(struct index_state *istate, struct lock_file *lock,
new_shared_index = istate->cache_changed & SPLIT_INDEX_ORDERED;
if (new_shared_index) {
- ret = write_shared_index(istate, lock, flags);
+ struct tempfile *temp;
+ int saved_errno;
+
+ temp = mks_tempfile(git_path("sharedindex_XXXXXX"));
+ if (!temp) {
+ hashclr(si->base_sha1);
+ ret = do_write_locked_index(istate, lock, flags);
+ goto out;
+ }
+ ret = write_shared_index(istate, &temp);
+
+ saved_errno = errno;
+ if (is_tempfile_active(temp))
+ delete_tempfile(&temp);
+ errno = saved_errno;
+
if (ret)
goto out;
}