From: Junio C Hamano Date: Tue, 13 Feb 2018 21:39:12 +0000 (-0800) Subject: Merge branch 'tg/split-index-fixes' X-Git-Tag: v2.17.0-rc0~116 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e75c862125f219c983cd2980d1b33ec09a3c34b9;p=thirdparty%2Fgit.git Merge branch 'tg/split-index-fixes' The split-index mode had a few corner case bugs fixed. * tg/split-index-fixes: travis: run tests with GIT_TEST_SPLIT_INDEX split-index: don't write cache tree with null oid entries read-cache: fix reading the shared index for other repos --- e75c862125f219c983cd2980d1b33ec09a3c34b9 diff --cc cache-tree.c index e03e72c34a,e006215edc..0dd6292a94 --- a/cache-tree.c +++ b/cache-tree.c @@@ -606,9 -606,9 +606,9 @@@ int write_index_as_tree(unsigned char * struct lock_file lock_file = LOCK_INIT; int ret = 0; - newfd = hold_lock_file_for_update(&lock_file, index_path, LOCK_DIE_ON_ERROR); + hold_lock_file_for_update(&lock_file, index_path, LOCK_DIE_ON_ERROR); - entries = read_index_from(index_state, index_path); + entries = read_index_from(index_state, index_path, get_git_dir()); if (entries < 0) { ret = WRITE_TREE_UNREADABLE_INDEX; goto out; diff --cc cache.h index 8cdcee5446,add5f9f50a..9cac7bb518 --- a/cache.h +++ b/cache.h @@@ -616,31 -600,13 +617,32 @@@ extern int read_index(struct index_stat extern int read_index_preload(struct index_state *, const struct pathspec *pathspec); extern int do_read_index(struct index_state *istate, const char *path, int must_exist); /* for testting only! */ - extern int read_index_from(struct index_state *, const char *path); + extern int read_index_from(struct index_state *, const char *path, + const char *gitdir); extern int is_index_unborn(struct index_state *); extern int read_index_unmerged(struct index_state *); + +/* For use with `write_locked_index()`. */ #define COMMIT_LOCK (1 << 0) -#define CLOSE_LOCK (1 << 1) + +/* + * Write the index while holding an already-taken lock. Close the lock, + * and if `COMMIT_LOCK` is given, commit it. + * + * Unless a split index is in use, write the index into the lockfile. + * + * With a split index, write the shared index to a temporary file, + * adjust its permissions and rename it into place, then write the + * split index to the lockfile. If the temporary file for the shared + * index cannot be created, fall back to the behavior described in + * the previous paragraph. + * + * With `COMMIT_LOCK`, the lock is always committed or rolled back. + * Without it, the lock is closed, but neither committed nor rolled + * back. + */ extern int write_locked_index(struct index_state *, struct lock_file *lock, unsigned flags); + extern int discard_index(struct index_state *); extern void move_index_extensions(struct index_state *dst, struct index_state *src); extern int unmerged_index(const struct index_state *); diff --cc ci/run-tests.sh index 22355f0091,c7aee5b9ff..9b6fedcc2a --- a/ci/run-tests.sh +++ b/ci/run-tests.sh @@@ -5,9 -5,10 +5,13 @@@ . ${0%/*}/lib-travisci.sh -mkdir -p $HOME/travis-cache ln -s $HOME/travis-cache/.prove t/.prove make --quiet test + if test "$jobname" = "linux-gcc" + then + GIT_TEST_SPLIT_INDEX=YesPlease make --quiet test + fi + +check_unignored_build_artifacts + +save_good_tree diff --cc read-cache.c index 2eb81a66b9,5cd14e2f72..d13ce83794 --- a/read-cache.c +++ b/read-cache.c @@@ -2573,12 -2521,12 +2573,15 @@@ int write_locked_index(struct index_sta ret = write_split_index(istate, lock, flags); /* Freshen the shared index only if the split-index was written */ - if (!ret && !new_shared_index) - freshen_shared_index(sha1_to_hex(si->base_sha1), 1); + if (!ret && !new_shared_index) { + const char *shared_index = git_path("sharedindex.%s", + sha1_to_hex(si->base_sha1)); + freshen_shared_index(shared_index, 1); + } +out: + if (flags & COMMIT_LOCK) + rollback_lock_file(lock); return ret; }