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>
Christian Couder committed
Feb 27, 2017 at 19:00 UTC
0d59ffb47ed58f519bfa2796d38364496735ab19
1 file changed
+26
-3
read-cache.c
+26
-3
@@ -1682,6 +1682,19 @@ unmap:
1682
die("index file corrupt");
1683
}
1684
1685
+/*
1686
+ * Signal that the shared index is used by updating its mtime.
1687
+ *
1688
+ * This way, shared index can be removed if they have not been used
1689
+ * for some time.
1690
+ */
1691
+static void freshen_shared_index(char *base_sha1_hex, int warn)
1692
+{
1693
+ const char *shared_index = git_path("sharedindex.%s", base_sha1_hex);
1694
+ if (!check_and_freshen_file(shared_index, 1) && warn)
1695
+ warning("could not freshen shared index '%s'", shared_index);
1696
+}
1697
+
1698
int read_index_from(struct index_state *istate, const char *path)
1699
{
1700
struct split_index *split_index;
@@ -2253,6 +2266,7 @@ static int too_many_not_shared_entries(struct index_state *istate)
2266
int write_locked_index(struct index_state *istate, struct lock_file *lock,
2267
unsigned flags)
2268
{
2269
+ int new_shared_index, ret;
2270
struct split_index *si = istate->split_index;
2271
2272
if (!si || alternate_index_output ||
@@ -2269,13 +2283,22 @@ int write_locked_index(struct index_state *istate, struct lock_file *lock,
2283
}
2284
if (too_many_not_shared_entries(istate))
2285
istate->cache_changed |= SPLIT_INDEX_ORDERED;
2272
- if (istate->cache_changed & SPLIT_INDEX_ORDERED) {
2273
- int ret = write_shared_index(istate, lock, flags);
2286
+
2287
+ new_shared_index = istate->cache_changed & SPLIT_INDEX_ORDERED;
2288
+
2289
+ if (new_shared_index) {
2290
+ ret = write_shared_index(istate, lock, flags);
2291
if (ret)
2292
return ret;
2293
}
2294
2278
- return write_split_index(istate, lock, flags);
2295
+ ret = write_split_index(istate, lock, flags);
2296
+
2297
+ /* Freshen the shared index only if the split-index was written */
2298
+ if (!ret && !new_shared_index)
2299
+ freshen_shared_index(sha1_to_hex(si->base_sha1), 1);
2300
+
2301
+ return ret;
2302
}
2303
2304
/*