Mercurial > public > mercurial-scm > hg
comparison mercurial/pure/parsers.py @ 51737:d748fd2647f8
pure: stringify builtin exception messages
Builtin exceptions usually want strings, and display with a wierd b'' prefix if
given bytes.
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Thu, 25 Jul 2024 14:40:38 -0400 |
parents | 278af66e6595 |
children | f4733654f144 |
comparison
equal
deleted
inserted
replaced
51736:7226f2626fb1 | 51737:d748fd2647f8 |
---|---|
23 # noinspection PyPackageRequirements | 23 # noinspection PyPackageRequirements |
24 import attr | 24 import attr |
25 | 25 |
26 from .. import ( | 26 from .. import ( |
27 error, | 27 error, |
28 pycompat, | |
28 revlogutils, | 29 revlogutils, |
29 util, | 30 util, |
30 ) | 31 ) |
31 | 32 |
32 from ..revlogutils import nodemap as nodemaputil | 33 from ..revlogutils import nodemap as nodemaputil |
233 wc_tracked=True, | 234 wc_tracked=True, |
234 p1_tracked=True, | 235 p1_tracked=True, |
235 parentfiledata=(mode, size, (mtime, 0, False)), | 236 parentfiledata=(mode, size, (mtime, 0, False)), |
236 ) | 237 ) |
237 else: | 238 else: |
238 raise RuntimeError(b'unknown state: %s' % state) | 239 raise RuntimeError('unknown state: %s' % pycompat.sysstr(state)) |
239 | 240 |
240 def set_possibly_dirty(self): | 241 def set_possibly_dirty(self): |
241 """Mark a file as "possibly dirty" | 242 """Mark a file as "possibly dirty" |
242 | 243 |
243 This means the next status call will have to actually check its content | 244 This means the next status call will have to actually check its content |
649 assert entry[9] == 0 | 650 assert entry[9] == 0 |
650 return self.index_format.pack(*entry[:8]) | 651 return self.index_format.pack(*entry[:8]) |
651 | 652 |
652 def _check_index(self, i): | 653 def _check_index(self, i): |
653 if not isinstance(i, int): | 654 if not isinstance(i, int): |
654 raise TypeError(b"expecting int indexes") | 655 raise TypeError("expecting int indexes") |
655 if i < 0 or i >= len(self): | 656 if i < 0 or i >= len(self): |
656 raise IndexError(i) | 657 raise IndexError(i) |
657 | 658 |
658 def __getitem__(self, i): | 659 def __getitem__(self, i): |
659 if i == -1: | 660 if i == -1: |
709 def _calculate_index(self, i): | 710 def _calculate_index(self, i): |
710 return i * self.entry_size | 711 return i * self.entry_size |
711 | 712 |
712 def __delitem__(self, i): | 713 def __delitem__(self, i): |
713 if not isinstance(i, slice) or not i.stop == -1 or i.step is not None: | 714 if not isinstance(i, slice) or not i.stop == -1 or i.step is not None: |
714 raise ValueError(b"deleting slices only supports a:-1 with step 1") | 715 raise ValueError("deleting slices only supports a:-1 with step 1") |
715 i = i.start | 716 i = i.start |
716 self._check_index(i) | 717 self._check_index(i) |
717 self._stripnodes(i) | 718 self._stripnodes(i) |
718 if i < self._lgt: | 719 if i < self._lgt: |
719 self._data = self._data[: i * self.entry_size] | 720 self._data = self._data[: i * self.entry_size] |
788 if lgt is not None: | 789 if lgt is not None: |
789 self._offsets[count] = off | 790 self._offsets[count] = off |
790 count += 1 | 791 count += 1 |
791 off += self.entry_size + s | 792 off += self.entry_size + s |
792 if off != len(self._data): | 793 if off != len(self._data): |
793 raise ValueError(b"corrupted data") | 794 raise ValueError("corrupted data") |
794 return count | 795 return count |
795 | 796 |
796 def __delitem__(self, i): | 797 def __delitem__(self, i): |
797 if not isinstance(i, slice) or not i.stop == -1 or i.step is not None: | 798 if not isinstance(i, slice) or not i.stop == -1 or i.step is not None: |
798 raise ValueError(b"deleting slices only supports a:-1 with step 1") | 799 raise ValueError("deleting slices only supports a:-1 with step 1") |
799 i = i.start | 800 i = i.start |
800 self._check_index(i) | 801 self._check_index(i) |
801 self._stripnodes(i) | 802 self._stripnodes(i) |
802 if i < self._lgt: | 803 if i < self._lgt: |
803 self._offsets = self._offsets[:i] | 804 self._offsets = self._offsets[:i] |
846 """ | 847 """ |
847 if rev < 0: | 848 if rev < 0: |
848 raise KeyError | 849 raise KeyError |
849 self._check_index(rev) | 850 self._check_index(rev) |
850 if rev < self._lgt: | 851 if rev < self._lgt: |
851 msg = b"cannot rewrite entries outside of this transaction" | 852 msg = "cannot rewrite entries outside of this transaction" |
852 raise KeyError(msg) | 853 raise KeyError(msg) |
853 else: | 854 else: |
854 entry = list(self[rev]) | 855 entry = list(self[rev]) |
855 entry[0] = offset_flags | 856 entry[0] = offset_flags |
856 entry[8] = sidedata_offset | 857 entry[8] = sidedata_offset |