Skip to content

Commit 0d59ffb

Browse files
chriscoolgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6a5e6f5 commit 0d59ffb

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

read-cache.c

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1682,6 +1682,19 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist)
16821682
die("index file corrupt");
16831683
}
16841684

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+
16851698
int read_index_from(struct index_state *istate, const char *path)
16861699
{
16871700
struct split_index *split_index;
@@ -2253,6 +2266,7 @@ static int too_many_not_shared_entries(struct index_state *istate)
22532266
int write_locked_index(struct index_state *istate, struct lock_file *lock,
22542267
unsigned flags)
22552268
{
2269+
int new_shared_index, ret;
22562270
struct split_index *si = istate->split_index;
22572271

22582272
if (!si || alternate_index_output ||
@@ -2269,13 +2283,22 @@ int write_locked_index(struct index_state *istate, struct lock_file *lock,
22692283
}
22702284
if (too_many_not_shared_entries(istate))
22712285
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);
22742291
if (ret)
22752292
return ret;
22762293
}
22772294

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;
22792302
}
22802303

22812304
/*

0 commit comments

Comments
 (0)