~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/history.py

  • Committer: Ian Clatworthy
  • Date: 2010-04-22 08:52:59 UTC
  • mfrom: (405.1.8 small-cleanups)
  • Revision ID: ian.clatworthy@canonical.com-20100422085259-1nb59i53emu2ny5b
Merge John's minor cleanups

Show diffs side-by-side

added added

removed removed

Lines of Context:
152
152
                filename=rich_filename(paths[1], kind),
153
153
                file_id=file_id))
154
154
 
155
 
# The lru_cache is not thread-safe, so we need a lock around it for
156
 
# all threads.
157
 
rev_info_memory_cache_lock = threading.RLock()
158
155
 
159
156
class RevInfoMemoryCache(object):
160
157
    """A store that validates values against the revids they were stored with.
178
175
        If a value was stored under `key`, with the same revid, return it.
179
176
        Otherwise return None.
180
177
        """
181
 
        rev_info_memory_cache_lock.acquire()
182
 
        try:
183
 
            cached = self._cache.get(key)
184
 
        finally:
185
 
            rev_info_memory_cache_lock.release()
 
178
        cached = self._cache.get(key)
186
179
        if cached is None:
187
180
            return None
188
181
        stored_revid, data = cached
194
187
    def set(self, key, revid, data):
195
188
        """Store `data` under `key`, to be checked against `revid` on get().
196
189
        """
197
 
        rev_info_memory_cache_lock.acquire()
198
 
        try:
199
 
            self._cache[key] = (revid, data)
200
 
        finally:
201
 
            rev_info_memory_cache_lock.release()
 
190
        self._cache[key] = (revid, data)
202
191
 
203
192
# Used to store locks that prevent multiple threads from building a 
204
193
# revision graph for the same branch at the same time, because that can
294
283
        else:
295
284
            self._file_change_cache = None
296
285
        self._branch = branch
297
 
        self._branch_tags = None
298
286
        self._inventory_cache = {}
299
287
        self._branch_nick = self._branch.get_config().get_nickname()
300
288
        self.log = logging.getLogger('loggerhead.%s' % (self._branch_nick,))
665
653
        """
666
654
        message, short_message = clean_message(revision.message)
667
655
 
668
 
        if self._branch_tags is None:
669
 
            self._branch_tags = self._branch.tags.get_reverse_tag_dict()
 
656
        tags = self._branch.tags.get_reverse_tag_dict()
670
657
 
671
658
        revtags = None
672
 
        if revision.revision_id in self._branch_tags:
673
 
          revtags = ', '.join(self._branch_tags[revision.revision_id])
 
659
        if tags.has_key(revision.revision_id):
 
660
          revtags = ', '.join(tags[revision.revision_id])
674
661
 
675
662
        entry = {
676
663
            'revid': revision.revision_id,