From 340c4d2a6a594c9338df81d751dadd7ff08efe02 Mon Sep 17 00:00:00 2001 From: Stephen Bash Date: Thu, 21 Oct 2010 18:15:14 -0400 Subject: [PATCH] Attempt to safely rebuild rev_cache if it "seems" out of date This is a sub-optimal solution to the stale rev_cache problem. Basically if verifyrev gets a valid SHA from an external git call that isn't in the rev_dict or tag_set, verifyrev attempt to rebuild the cache. --- tracext/git/PyGIT.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/tracext/git/PyGIT.py b/tracext/git/PyGIT.py index 10c6d8f..07d0c98 100644 --- a/tracext/git/PyGIT.py +++ b/tracext/git/PyGIT.py @@ -19,7 +19,7 @@ import os, re, sys, time, weakref from collections import deque from functools import partial -from threading import Lock +from threading import Lock, RLock from subprocess import Popen, PIPE from operator import itemgetter import cStringIO @@ -256,7 +256,7 @@ def __init__(self, git_dir, log, git_bin='git', git_fs_encoding=None): # caches self.__rev_cache = None - self.__rev_cache_lock = Lock() + self.__rev_cache_lock = RLock() # cache the last 200 commit messages self.__commit_msg_cache = SizedDict(200) @@ -511,6 +511,22 @@ def verifyrev(self, rev): return None return sha[1] + if GitCore.is_sha(rc): + # rev-parse returned a sha that isn't in the rev_dict or the tag_set + # it's possible the cache is out of date + with self.__rev_cache_lock: + # A different thread might have already refreshed cache + _rev_cache = self.rev_cache # update local copy + if rc in _rev_cache.rev_dict: + return rc + + # If we've gotten here, try rebuilding the cache + self.__rev_cache = None + _rev_cache = self.rev_cache # triggers a rebuild + + if rc in _rev_cache.rev_dict: + return rc + return None def shortrev(self, rev, min_len=7):