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 <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Michael Haggerty committed Jun 20, 2013 at 10:37 UTC 5d478f5ca1792e7576ac13aaf75f09099ce99afb
1 file changed +6 -3
refs.c
+6 -3
@@ -2136,11 +2136,14 @@ int lock_packed_refs(int flags)
2136 {
2137 struct packed_ref_cache *packed_ref_cache;
2138
2139 - /* Discard the old cache because it might be invalid: */
2140 - clear_packed_ref_cache(&ref_cache);
2139 if (hold_lock_file_for_update(&packlock, git_path("packed-refs"), flags) < 0)
2140 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 + */
2147 packed_ref_cache = get_packed_ref_cache(&ref_cache);
2148 packed_ref_cache->lock = &packlock;
2149 /* Increment the reference count to prevent it from being freed: */