48
48
if not os.path.exists(cache_path):
49
49
os.mkdir(cache_path)
51
# keep a separate cache for the diffs, because they're very time-consuming to fetch.
51
52
self._changes_filename = os.path.join(cache_path, 'changes')
53
self._changes_diffs_filename = os.path.join(cache_path, 'changes-diffs')
53
55
# use a lockfile since the cache folder could be shared across different processes.
54
56
self._lock = LockFile(os.path.join(cache_path, 'lock'))
76
def get_changes(self, revid_list):
79
def get_changes(self, revid_list, get_diffs=False):
78
81
get a list of changes by their revision_ids. any changes missing
79
82
from the cache are fetched by calling L{History.get_change_uncached}
80
83
and inserted into the cache before returning.
82
cache = shelve.open(self._changes_filename, 'c', protocol=2)
88
for revid in revid_list:
89
# if the revid is in unicode, use the utf-8 encoding as the key
90
srevid = util.to_utf8(revid)
93
out.append(cache[srevid])
95
#self.log.debug('Entry cache miss: %r' % (revid,))
97
fetch_list.append(revid)
98
sfetch_list.append(srevid)
100
if len(fetch_list) > 0:
101
# some revisions weren't in the cache; fetch them
102
changes = self.history.get_changes_uncached(fetch_list)
103
if len(changes) == 0:
105
for i in xrange(len(revid_list)):
107
cache[sfetch_list.pop(0)] = out[i] = changes.pop(0)
86
cache = shelve.open(self._changes_diffs_filename, 'c', protocol=2)
88
cache = shelve.open(self._changes_filename, 'c', protocol=2)
93
for revid in revid_list:
94
# if the revid is in unicode, use the utf-8 encoding as the key
95
srevid = util.to_utf8(revid)
98
out.append(cache[srevid])
100
#self.log.debug('Entry cache miss: %r' % (revid,))
102
fetch_list.append(revid)
103
sfetch_list.append(srevid)
105
if len(fetch_list) > 0:
106
# some revisions weren't in the cache; fetch them
107
changes = self.history.get_changes_uncached(fetch_list, get_diffs)
110
for i in xrange(len(revid_list)):
112
cache[sfetch_list.pop(0)] = out[i] = changes.pop(0)
114
cache = shelve.open(self._changes_filename, 'c', protocol=2)
118
def full(self, get_diffs=False):
120
cache = shelve.open(self._changes_diffs_filename, 'c', protocol=2)
122
cache = shelve.open(self._changes_filename, 'c', protocol=2)
116
124
return (len(cache) >= len(self.history.get_revision_history())) and (util.to_utf8(self.history.last_revid) in cache)
122
130
cache = shelve.open(self._changes_filename, 'c', protocol=2)
133
cache = shelve.open(self._changes_diffs_filename, 'c', protocol=2)
127
138
def check_rebuild(self, max_time=3600):