mercurial/branchmap.py
changeset 42602 c7d236b55a3e
parent 42214 9893d7aa7420
child 42603 3018749a71bb
equal deleted inserted replaced
42601:862f6bddacce 42602:c7d236b55a3e
   118 
   118 
   119 def _unknownnode(node):
   119 def _unknownnode(node):
   120     """ raises ValueError when branchcache found a node which does not exists
   120     """ raises ValueError when branchcache found a node which does not exists
   121     """
   121     """
   122     raise ValueError(r'node %s does not exist' % pycompat.sysstr(hex(node)))
   122     raise ValueError(r'node %s does not exist' % pycompat.sysstr(hex(node)))
       
   123 
       
   124 def _branchcachedesc(repo):
       
   125     if repo.filtername is not None:
       
   126         return 'branch cache (%s)' % repo.filtername
       
   127     else:
       
   128         return 'branch cache'
   123 
   129 
   124 class branchcache(object):
   130 class branchcache(object):
   125     """A dict like object that hold branches heads cache.
   131     """A dict like object that hold branches heads cache.
   126 
   132 
   127     This cache is used to avoid costly computations to determine all the
   133     This cache is used to avoid costly computations to determine all the
   239         except (IOError, OSError):
   245         except (IOError, OSError):
   240             return None
   246             return None
   241 
   247 
   242         except Exception as inst:
   248         except Exception as inst:
   243             if repo.ui.debugflag:
   249             if repo.ui.debugflag:
   244                 msg = 'invalid branchheads cache'
   250                 msg = 'invalid %s: %s\n'
   245                 if repo.filtername is not None:
   251                 repo.ui.debug(msg % (_branchcachedesc(repo),
   246                     msg += ' (%s)' % repo.filtername
   252                                      pycompat.bytestr(inst)))
   247                 msg += ': %s\n'
       
   248                 repo.ui.debug(msg % pycompat.bytestr(inst))
       
   249             bcache = None
   253             bcache = None
   250 
   254 
   251         finally:
   255         finally:
   252             if f:
   256             if f:
   253                 f.close()
   257                 f.close()
   349                         state = 'c'
   353                         state = 'c'
   350                     else:
   354                     else:
   351                         state = 'o'
   355                         state = 'o'
   352                     f.write("%s %s %s\n" % (hex(node), state, label))
   356                     f.write("%s %s %s\n" % (hex(node), state, label))
   353             f.close()
   357             f.close()
   354             repo.ui.log('branchcache',
   358             repo.ui.log('branchcache', 'wrote %s with %d labels and %d nodes\n',
   355                         'wrote %s branch cache with %d labels and %d nodes\n',
   359                         _branchcachedesc(repo), len(self._entries), nodecount)
   356                         repo.filtername, len(self._entries), nodecount)
       
   357         except (IOError, OSError, error.Abort) as inst:
   360         except (IOError, OSError, error.Abort) as inst:
   358             # Abort may be raised by read only opener, so log and continue
   361             # Abort may be raised by read only opener, so log and continue
   359             repo.ui.debug("couldn't write branch cache: %s\n" %
   362             repo.ui.debug("couldn't write branch cache: %s\n" %
   360                           stringutil.forcebytestr(inst))
   363                           stringutil.forcebytestr(inst))
   361 
   364 
   422                     self.tipnode = cl.node(tiprev)
   425                     self.tipnode = cl.node(tiprev)
   423                     self.tiprev = tiprev
   426                     self.tiprev = tiprev
   424         self.filteredhash = scmutil.filteredhash(repo, self.tiprev)
   427         self.filteredhash = scmutil.filteredhash(repo, self.tiprev)
   425 
   428 
   426         duration = util.timer() - starttime
   429         duration = util.timer() - starttime
   427         repo.ui.log('branchcache', 'updated %s branch cache in %.4f seconds\n',
   430         repo.ui.log('branchcache', 'updated %s in %.4f seconds\n',
   428                     repo.filtername or b'None', duration)
   431                     _branchcachedesc(repo), duration)
   429 
   432 
   430         self.write(repo)
   433         self.write(repo)
   431 
   434 
   432 
   435 
   433 class remotebranchcache(branchcache):
   436 class remotebranchcache(branchcache):