Skip to content

Commit

Permalink
Merge branch 'mh/ref-races-optim-invalidate-cached'
Browse files Browse the repository at this point in the history
* mh/ref-races-optim-invalidate-cached:
  refs: do not invalidate the packed-refs cache unnecessarily
  • Loading branch information
Junio C Hamano committed Jul 25, 2013
2 parents 0c544a2 + 5d478f5 commit 29143fc
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions refs.c
Original file line number Diff line number Diff line change
Expand Up @@ -2174,11 +2174,14 @@ int lock_packed_refs(int flags)
{
struct packed_ref_cache *packed_ref_cache;

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

0 comments on commit 29143fc

Please sign in to comment.