[PATCH 12/12] refs: do not invalidate the packed-refs cache unnecessarily
- From
Michael Haggerty <mhagger@alum.mit.edu>
- Date
- Jun 11, 2013, 21:48 UTC
- Message-ID
- <1370987312-6761-13-git-send-email-mhagger@alum.mit.edu>
- In-Reply-To
- <1370987312-6761-1-git-send-email-mhagger@alum.mit.edu>
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> --- This patch is optional. It makes the assumption that the metadata stored in stat_validity are adequate to reliably detect when the packed-refs file has changed. Given that we are about to rewrite the file, it is perhaps even more crucial not to make a mistake in this codepath than in others. So if the stat_validity check is not considered safe enough, it might be prudent to omit this patch and continue to reload the packed-refs data here unconditionally.
refs.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/refs.c b/refs.c index aa4641b..d9cbfc4 100644 --- a/refs.c +++ b/refs.c @@ -2134,12 +2134,15 @@ int lock_packed_refs(struct lock_file *lock, int flags) int fd; struct packed_ref_cache *packed_ref_cache; - /* Discard the old cache because it might be invalid: */ - clear_packed_ref_cache(&ref_cache); fd = hold_lock_file_for_update(lock, git_path("packed-refs"), flags); if (fd < 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 = lock; packed_ref_cache->fd = fd;
-- 1.8.3