mercurial/branchmap.py
changeset 51464 09782c097035
parent 51463 87b830e4de35
child 51465 9007387a227c
equal deleted inserted replaced
51463:87b830e4de35 51464:09782c097035
   583             with repo.cachevfs(filename, b"w", atomictemp=True) as f:
   583             with repo.cachevfs(filename, b"w", atomictemp=True) as f:
   584                 cachekey = [hex(self.tipnode), b'%d' % self.tiprev]
   584                 cachekey = [hex(self.tipnode), b'%d' % self.tiprev]
   585                 if self.filteredhash is not None:
   585                 if self.filteredhash is not None:
   586                     cachekey.append(hex(self.filteredhash))
   586                     cachekey.append(hex(self.filteredhash))
   587                 f.write(b" ".join(cachekey) + b'\n')
   587                 f.write(b" ".join(cachekey) + b'\n')
   588                 nodecount = 0
   588                 nodecount = self._write_heads(f)
   589                 for label, nodes in sorted(self._entries.items()):
       
   590                     label = encoding.fromlocal(label)
       
   591                     for node in nodes:
       
   592                         nodecount += 1
       
   593                         if node in self._closednodes:
       
   594                             state = b'c'
       
   595                         else:
       
   596                             state = b'o'
       
   597                         f.write(b"%s %s %s\n" % (hex(node), state, label))
       
   598             repo.ui.log(
   589             repo.ui.log(
   599                 b'branchcache',
   590                 b'branchcache',
   600                 b'wrote %s with %d labels and %d nodes\n',
   591                 b'wrote %s with %d labels and %d nodes\n',
   601                 _branchcachedesc(repo),
   592                 _branchcachedesc(repo),
   602                 len(self._entries),
   593                 len(self._entries),
   607             # Abort may be raised by read only opener, so log and continue
   598             # Abort may be raised by read only opener, so log and continue
   608             repo.ui.debug(
   599             repo.ui.debug(
   609                 b"couldn't write branch cache: %s\n"
   600                 b"couldn't write branch cache: %s\n"
   610                 % stringutil.forcebytestr(inst)
   601                 % stringutil.forcebytestr(inst)
   611             )
   602             )
       
   603 
       
   604     def _write_heads(self, fp) -> int:
       
   605         """write list of heads to a file
       
   606 
       
   607         Return the number of heads written."""
       
   608         nodecount = 0
       
   609         for label, nodes in sorted(self._entries.items()):
       
   610             label = encoding.fromlocal(label)
       
   611             for node in nodes:
       
   612                 nodecount += 1
       
   613                 if node in self._closednodes:
       
   614                     state = b'c'
       
   615                 else:
       
   616                     state = b'o'
       
   617                 fp.write(b"%s %s %s\n" % (hex(node), state, label))
       
   618         return nodecount
   612 
   619 
   613     def _verifybranch(self, branch):
   620     def _verifybranch(self, branch):
   614         """verify head nodes for the given branch."""
   621         """verify head nodes for the given branch."""
   615         if not self._verify_node:
   622         if not self._verify_node:
   616             return
   623             return