mercurial/repoview.py
changeset 31069 20027be9f23d
parent 29341 0d83ad967bf8
child 31231 2faf233b88e4
equal deleted inserted replaced
31068:23bcfdd76f96 31069:20027be9f23d
   137         repo.ui.debug('cannot obtain lock to write hidden changesets cache\n')
   137         repo.ui.debug('cannot obtain lock to write hidden changesets cache\n')
   138     finally:
   138     finally:
   139         if wlock:
   139         if wlock:
   140             wlock.release()
   140             wlock.release()
   141 
   141 
   142 def tryreadcache(repo, hideable):
   142 def _readhiddencache(repo, cachefilename, newhash):
   143     """read a cache if the cache exists and is valid, otherwise returns None."""
       
   144     hidden = fh = None
   143     hidden = fh = None
   145     try:
   144     try:
   146         if repo.vfs.exists(cachefile):
   145         if repo.vfs.exists(cachefile):
   147             fh = repo.vfs.open(cachefile, 'rb')
   146             fh = repo.vfs.open(cachefile, 'rb')
   148             version, = struct.unpack(">H", fh.read(2))
   147             version, = struct.unpack(">H", fh.read(2))
   149             oldhash = fh.read(20)
   148             oldhash = fh.read(20)
   150             newhash = cachehash(repo, hideable)
       
   151             if (cacheversion, oldhash) == (version, newhash):
   149             if (cacheversion, oldhash) == (version, newhash):
   152                 # cache is valid, so we can start reading the hidden revs
   150                 # cache is valid, so we can start reading the hidden revs
   153                 data = fh.read()
   151                 data = fh.read()
   154                 count = len(data) / 4
   152                 count = len(data) / 4
   155                 hidden = frozenset(struct.unpack('>%ii' % count, data))
   153                 hidden = frozenset(struct.unpack('>%ii' % count, data))
   163         return None
   161         return None
   164     finally:
   162     finally:
   165         if fh:
   163         if fh:
   166             fh.close()
   164             fh.close()
   167 
   165 
       
   166 def tryreadcache(repo, hideable):
       
   167     """read a cache if the cache exists and is valid, otherwise returns None."""
       
   168     newhash = cachehash(repo, hideable)
       
   169     return _readhiddencache(repo, cachefile, newhash)
       
   170 
   168 def computehidden(repo):
   171 def computehidden(repo):
   169     """compute the set of hidden revision to filter
   172     """compute the set of hidden revision to filter
   170 
   173 
   171     During most operation hidden should be filtered."""
   174     During most operation hidden should be filtered."""
   172     assert not repo.changelog.filteredrevs
   175     assert not repo.changelog.filteredrevs