Skip to content

Commit 5d478f5

Browse files
mhaggergitster
authored andcommitted
refs: do not invalidate the packed-refs cache unnecessarily
Now that we keep track of the packed-refs file metadata, we can detect when the packed-refs file has been modified since we last read it, and we do so automatically every time that get_packed_ref_cache() is called. So there is no need to invalidate the cache automatically when lock_packed_refs() is called; usually the old copy will still be valid. Signed-off-by: Michael Haggerty <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 98eeb09 commit 5d478f5

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

refs.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2136,11 +2136,14 @@ int lock_packed_refs(int flags)
21362136
{
21372137
struct packed_ref_cache *packed_ref_cache;
21382138

2139-
/* Discard the old cache because it might be invalid: */
2140-
clear_packed_ref_cache(&ref_cache);
21412139
if (hold_lock_file_for_update(&packlock, git_path("packed-refs"), flags) < 0)
21422140
return -1;
2143-
/* Read the current packed-refs while holding the lock: */
2141+
/*
2142+
* Get the current packed-refs while holding the lock. If the
2143+
* packed-refs file has been modified since we last read it,
2144+
* this will automatically invalidate the cache and re-read
2145+
* the packed-refs file.
2146+
*/
21442147
packed_ref_cache = get_packed_ref_cache(&ref_cache);
21452148
packed_ref_cache->lock = &packlock;
21462149
/* Increment the reference count to prevent it from being freed: */

0 commit comments

Comments
 (0)