| 3307 | } |
| 3308 | |
| 3309 | int write_locked_index(struct index_state *istate, struct lock_file *lock, |
| 3310 | unsigned flags) |
| 3311 | { |
| 3312 | int new_shared_index, ret, test_split_index_env; |
| 3313 | struct split_index *si = istate->split_index; |
| 3314 | |
| 3315 | if (git_env_bool("GIT_TEST_CHECK_CACHE_TREE", 0) && |
| 3316 | cache_tree_verify(the_repository, istate) < 0) |
| 3317 | return -1; |
| 3318 | |
| 3319 | if ((flags & SKIP_IF_UNCHANGED) && !istate->cache_changed) { |
| 3320 | if (flags & COMMIT_LOCK) |
| 3321 | rollback_lock_file(lock); |
| 3322 | return 0; |
| 3323 | } |
| 3324 | |
| 3325 | if (istate->fsmonitor_last_update) |
| 3326 | fill_fsmonitor_bitmap(istate); |
| 3327 | |
| 3328 | test_split_index_env = git_env_bool("GIT_TEST_SPLIT_INDEX", 0); |
| 3329 | |
| 3330 | if ((!si && !test_split_index_env) || |
| 3331 | alternate_index_output || |
| 3332 | (istate->cache_changed & ~EXTMASK)) { |
| 3333 | ret = do_write_locked_index(istate, lock, flags, |
| 3334 | ~WRITE_SPLIT_INDEX_EXTENSION); |
| 3335 | goto out; |
| 3336 | } |
| 3337 | |
| 3338 | if (test_split_index_env) { |
| 3339 | if (!si) { |
| 3340 | si = init_split_index(istate); |
| 3341 | istate->cache_changed |= SPLIT_INDEX_ORDERED; |
| 3342 | } else { |
| 3343 | int v = si->base_oid.hash[0]; |
| 3344 | if ((v & 15) < 6) |
| 3345 | istate->cache_changed |= SPLIT_INDEX_ORDERED; |
| 3346 | } |
| 3347 | } |
| 3348 | if (too_many_not_shared_entries(istate)) |
| 3349 | istate->cache_changed |= SPLIT_INDEX_ORDERED; |
| 3350 | |
| 3351 | new_shared_index = istate->cache_changed & SPLIT_INDEX_ORDERED; |
| 3352 | |
| 3353 | if (new_shared_index) { |
| 3354 | struct tempfile *temp; |
| 3355 | int saved_errno; |
| 3356 | char *path; |
| 3357 | |
| 3358 | /* Same initial permissions as the main .git/index file */ |
| 3359 | path = repo_git_path(the_repository, "sharedindex_XXXXXX"); |
| 3360 | temp = mks_tempfile_sm(path, 0, 0666); |
| 3361 | free(path); |
| 3362 | if (!temp) { |
| 3363 | ret = do_write_locked_index(istate, lock, flags, |
| 3364 | ~WRITE_SPLIT_INDEX_EXTENSION); |
| 3365 | goto out; |
| 3366 | } |