Skip to content

Commit 29143fc

Browse files
committed
Merge branch 'mh/ref-races-optim-invalidate-cached'
* mh/ref-races-optim-invalidate-cached: refs: do not invalidate the packed-refs cache unnecessarily
2 parents 0c544a2 + 5d478f5 commit 29143fc

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
@@ -2174,11 +2174,14 @@ int lock_packed_refs(int flags)
21742174
{
21752175
struct packed_ref_cache *packed_ref_cache;
21762176

2177-
/* Discard the old cache because it might be invalid: */
2178-
clear_packed_ref_cache(&ref_cache);
21792177
if (hold_lock_file_for_update(&packlock, git_path("packed-refs"), flags) < 0)
21802178
return -1;
2181-
/* Read the current packed-refs while holding the lock: */
2179+
/*
2180+
* Get the current packed-refs while holding the lock. If the
2181+
* packed-refs file has been modified since we last read it,
2182+
* this will automatically invalidate the cache and re-read
2183+
* the packed-refs file.
2184+
*/
21822185
packed_ref_cache = get_packed_ref_cache(&ref_cache);
21832186
packed_ref_cache->lock = &packlock;
21842187
/* Increment the reference count to prevent it from being freed: */

0 commit comments

Comments
 (0)