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()
This commit is contained in:
commit
dd0c256b67
42
read-cache.c
42
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,
|
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;
|
struct split_index *si = istate->split_index;
|
||||||
int ret;
|
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);
|
move_cache_to_base_index(istate);
|
||||||
ret = do_write_index(si->base, temp, 1);
|
ret = do_write_index(si->base, *temp, 1);
|
||||||
|
if (ret)
|
||||||
|
return ret;
|
||||||
|
ret = adjust_shared_perm(get_tempfile_path(*temp));
|
||||||
if (ret) {
|
if (ret) {
|
||||||
delete_tempfile(&temp);
|
error("cannot fix permission bits on %s", get_tempfile_path(*temp));
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
ret = adjust_shared_perm(get_tempfile_path(temp));
|
ret = rename_tempfile(temp,
|
||||||
if (ret) {
|
|
||||||
int save_errno = errno;
|
|
||||||
error("cannot fix permission bits on %s", get_tempfile_path(temp));
|
|
||||||
delete_tempfile(&temp);
|
|
||||||
errno = save_errno;
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
ret = rename_tempfile(&temp,
|
|
||||||
git_path("sharedindex.%s", sha1_to_hex(si->base->sha1)));
|
git_path("sharedindex.%s", sha1_to_hex(si->base->sha1)));
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
hashcpy(si->base_sha1, si->base->sha1);
|
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;
|
new_shared_index = istate->cache_changed & SPLIT_INDEX_ORDERED;
|
||||||
|
|
||||||
if (new_shared_index) {
|
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)
|
if (ret)
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
@ -401,6 +401,25 @@ done <<\EOF
|
|||||||
0642 -rw-r---w-
|
0642 -rw-r---w-
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
test_expect_success POSIXPERM,SANITY 'graceful handling when splitting index is not allowed' '
|
||||||
|
test_create_repo ro &&
|
||||||
|
(
|
||||||
|
cd ro &&
|
||||||
|
test_commit initial &&
|
||||||
|
git update-index --split-index &&
|
||||||
|
test -f .git/sharedindex.*
|
||||||
|
) &&
|
||||||
|
cp ro/.git/index new-index &&
|
||||||
|
test_when_finished "chmod u+w ro/.git" &&
|
||||||
|
chmod u-w ro/.git &&
|
||||||
|
GIT_INDEX_FILE="$(pwd)/new-index" git -C ro update-index --split-index &&
|
||||||
|
chmod u+w ro/.git &&
|
||||||
|
rm ro/.git/sharedindex.* &&
|
||||||
|
GIT_INDEX_FILE=new-index git ls-files >actual &&
|
||||||
|
echo initial.t >expected &&
|
||||||
|
test_cmp expected actual
|
||||||
|
'
|
||||||
|
|
||||||
test_expect_success 'writing split index with null sha1 does not write cache tree' '
|
test_expect_success 'writing split index with null sha1 does not write cache tree' '
|
||||||
git config core.splitIndex true &&
|
git config core.splitIndex true &&
|
||||||
git config splitIndex.maxPercentChange 0 &&
|
git config splitIndex.maxPercentChange 0 &&
|
||||||
|
Loading…
Reference in New Issue
Block a user