summaryrefslogtreecommitdiff
path: root/read-cache.c
diff options
context:
space:
mode:
authorChristian Couder <christian.couder@gmail.com>2017-02-27 18:00:12 (GMT)
committerJunio C Hamano <gitster@pobox.com>2017-03-01 21:34:51 (GMT)
commit0d59ffb47ed58f519bfa2796d38364496735ab19 (patch)
tree38fecadf6a8c5faa32e04caaeea845299fa214a8 /read-cache.c
parent6a5e6f5e4496d5647e9b11352d055efed434029e (diff)
downloadgit-0d59ffb47ed58f519bfa2796d38364496735ab19.zip
git-0d59ffb47ed58f519bfa2796d38364496735ab19.tar.gz
git-0d59ffb47ed58f519bfa2796d38364496735ab19.tar.bz2
read-cache: touch shared index files when used
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@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'read-cache.c')
-rw-r--r--read-cache.c29
1 files changed, 26 insertions, 3 deletions
diff --git a/read-cache.c b/read-cache.c
index fd1c88a..5ea6cee 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -1682,6 +1682,19 @@ unmap:
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.
+ */
+static void freshen_shared_index(char *base_sha1_hex, int warn)
+{
+ const char *shared_index = git_path("sharedindex.%s", base_sha1_hex);
+ if (!check_and_freshen_file(shared_index, 1) && warn)
+ warning("could not freshen shared index '%s'", shared_index);
+}
+
int read_index_from(struct index_state *istate, const char *path)
{
struct split_index *split_index;
@@ -2253,6 +2266,7 @@ static int too_many_not_shared_entries(struct index_state *istate)
int write_locked_index(struct index_state *istate, struct lock_file *lock,
unsigned flags)
{
+ int new_shared_index, ret;
struct split_index *si = istate->split_index;
if (!si || alternate_index_output ||
@@ -2269,13 +2283,22 @@ int write_locked_index(struct index_state *istate, struct lock_file *lock,
}
if (too_many_not_shared_entries(istate))
istate->cache_changed |= SPLIT_INDEX_ORDERED;
- if (istate->cache_changed & SPLIT_INDEX_ORDERED) {
- int ret = write_shared_index(istate, lock, flags);
+
+ new_shared_index = istate->cache_changed & SPLIT_INDEX_ORDERED;
+
+ if (new_shared_index) {
+ ret = write_shared_index(istate, lock, flags);
if (ret)
return ret;
}
- return write_split_index(istate, lock, flags);
+ 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);
+
+ return ret;
}
/*