summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2013-07-24 19:21:02 -0700
committerJunio C Hamano <gitster@pobox.com>2013-07-24 19:21:02 -0700
commit29143fc4e3e5236aa57a1f1ef63f775491159782 (patch)
treee0f64b9317ceac018bf1d58cb7668d73a3dd4104
parent0c544a22f9297b305949bd77f15183aa8fffd8fc (diff)
parent5d478f5ca1792e7576ac13aaf75f09099ce99afb (diff)
downloadgit-29143fc4e3e5236aa57a1f1ef63f775491159782.tar.gz
Merge branch 'mh/ref-races-optim-invalidate-cached'
* mh/ref-races-optim-invalidate-cached: refs: do not invalidate the packed-refs cache unnecessarily
-rw-r--r--refs.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/refs.c b/refs.c
index 4302206649..a3f2302292 100644
--- a/refs.c
+++ b/refs.c
@@ -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: */