From: Junio C Hamano Date: Thu, 22 Mar 2018 21:24:10 +0000 (-0700) Subject: Merge branch 'tg/split-index-fixes' into maint X-Git-Tag: v2.16.3~29 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/b0e0fc267bfb270b0ccf48ff17179c9c315dc2a9 Merge branch 'tg/split-index-fixes' into maint 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 --- b0e0fc267bfb270b0ccf48ff17179c9c315dc2a9 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 d8b975a571,add5f9f50a..fd755c32cf --- 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-build-and-tests.sh index d3a094603f,0000000000..3e23e65f9e mode 100755,000000..100755 --- a/ci/run-build-and-tests.sh +++ b/ci/run-build-and-tests.sh @@@ -1,15 -1,0 +1,19 @@@ +#!/bin/sh +# +# Build and test Git +# + +. ${0%/*}/lib-travisci.sh + +ln -s $HOME/travis-cache/.prove t/.prove + +make --jobs=2 +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; }