Skip to content
This repository was archived by the owner on May 22, 2019. It is now read-only.

Cache fixes #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions tracext/git/PyGIT.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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):
Expand Down