When a split-index file is created, let's update the mtime of the shared index file that the split-index file is referencing. In a following commit we will make shared index file expire depending on their mtime, so updating the mtime makes sure that the shared index file will not be deleted soon. Signed-off-by: Christian Couder <chriscool@xxxxxxxxxxxxx> --- read-cache.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/read-cache.c b/read-cache.c index 280b01bd6c..42688261f7 100644 --- a/read-cache.c +++ b/read-cache.c @@ -1685,6 +1685,19 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist) die("index file corrupt"); } +/* + * Signal that the shared index is used by updating its mtime. + * + * This way, shared index can be removed if they have not been used + * for some time. It's ok to fail to update the mtime if we are on a + * read only file system. + */ +void freshen_shared_index(char *base_sha1_hex) +{ + const char *shared_index = git_path("sharedindex.%s", base_sha1_hex); + check_and_freshen_file(shared_index, 1); +} + int read_index_from(struct index_state *istate, const char *path) { struct split_index *split_index; @@ -2276,6 +2289,8 @@ int write_locked_index(struct index_state *istate, struct lock_file *lock, int ret = write_shared_index(istate, lock, flags); if (ret) return ret; + } else { + freshen_shared_index(sha1_to_hex(si->base_sha1)); } return write_split_index(istate, lock, flags); -- 2.11.0.49.g2414764.dirty