summaryrefslogtreecommitdiff
path: root/refs.c
diff options
context:
space:
mode:
authorMichael Haggerty <mhagger@alum.mit.edu>2013-06-20 08:37:54 (GMT)
committerJunio C Hamano <gitster@pobox.com>2013-06-20 22:50:17 (GMT)
commit5d478f5ca1792e7576ac13aaf75f09099ce99afb (patch)
treef56bfe08efd52d5c419ed2f0875e37b9c26c10cb /refs.c
parent98eeb09e8acb6cbe0b0da3b1772b6676fe6d167f (diff)
downloadgit-5d478f5ca1792e7576ac13aaf75f09099ce99afb.zip
git-5d478f5ca1792e7576ac13aaf75f09099ce99afb.tar.gz
git-5d478f5ca1792e7576ac13aaf75f09099ce99afb.tar.bz2
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>
Diffstat (limited to 'refs.c')
-rw-r--r--refs.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/refs.c b/refs.c
index 787cc1c..038e5c7 100644
--- a/refs.c
+++ b/refs.c
@@ -2136,11 +2136,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: */