Mercurial > public > mercurial-scm > hg
comparison mercurial/branchmap.py @ 51462:9007387a227c
branchcache: move head writing in a `_write_headers` method
Same rational: this will help having format variants.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Mon, 26 Feb 2024 15:26:08 +0100 |
parents | 09782c097035 |
children | 4188a0570ba1 |
comparison
equal
deleted
inserted
replaced
51461:09782c097035 | 51462:9007387a227c |
---|---|
579 self._delayed = True | 579 self._delayed = True |
580 return | 580 return |
581 try: | 581 try: |
582 filename = self._filename(repo) | 582 filename = self._filename(repo) |
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 self._write_header(f) |
585 if self.filteredhash is not None: | |
586 cachekey.append(hex(self.filteredhash)) | |
587 f.write(b" ".join(cachekey) + b'\n') | |
588 nodecount = self._write_heads(f) | 585 nodecount = self._write_heads(f) |
589 repo.ui.log( | 586 repo.ui.log( |
590 b'branchcache', | 587 b'branchcache', |
591 b'wrote %s with %d labels and %d nodes\n', | 588 b'wrote %s with %d labels and %d nodes\n', |
592 _branchcachedesc(repo), | 589 _branchcachedesc(repo), |
598 # Abort may be raised by read only opener, so log and continue | 595 # Abort may be raised by read only opener, so log and continue |
599 repo.ui.debug( | 596 repo.ui.debug( |
600 b"couldn't write branch cache: %s\n" | 597 b"couldn't write branch cache: %s\n" |
601 % stringutil.forcebytestr(inst) | 598 % stringutil.forcebytestr(inst) |
602 ) | 599 ) |
600 | |
601 def _write_header(self, fp) -> None: | |
602 """write the branch cache header to a file""" | |
603 cachekey = [hex(self.tipnode), b'%d' % self.tiprev] | |
604 if self.filteredhash is not None: | |
605 cachekey.append(hex(self.filteredhash)) | |
606 fp.write(b" ".join(cachekey) + b'\n') | |
603 | 607 |
604 def _write_heads(self, fp) -> int: | 608 def _write_heads(self, fp) -> int: |
605 """write list of heads to a file | 609 """write list of heads to a file |
606 | 610 |
607 Return the number of heads written.""" | 611 Return the number of heads written.""" |