mercurial/pure/parsers.py
changeset 52585 72af9fa34832
parent 52583 8de9bab826bc
child 52884 8de68446a5bd
equal deleted inserted replaced
52584:30f2e8de0a82 52585:72af9fa34832
   337         else:
   337         else:
   338             # We have nano second information, let us use them !
   338             # We have nano second information, let us use them !
   339             return self_ns == other_ns
   339             return self_ns == other_ns
   340 
   340 
   341     @property
   341     @property
   342     def state(self):
   342     def state(self) -> bytes:
   343         """
   343         """
   344         States are:
   344         States are:
   345           n  normal
   345           n  normal
   346           m  needs merging
   346           m  needs merging
   347           r  marked for removal
   347           r  marked for removal
   516         # Note: we do not need to do anything regarding
   516         # Note: we do not need to do anything regarding
   517         # DIRSTATE_V2_ALL_UNKNOWN_RECORDED and DIRSTATE_V2_ALL_IGNORED_RECORDED
   517         # DIRSTATE_V2_ALL_UNKNOWN_RECORDED and DIRSTATE_V2_ALL_IGNORED_RECORDED
   518         # since we never set _DIRSTATE_V2_HAS_DIRCTORY_MTIME
   518         # since we never set _DIRSTATE_V2_HAS_DIRCTORY_MTIME
   519         return (flags, self._size or 0, self._mtime_s or 0, self._mtime_ns or 0)
   519         return (flags, self._size or 0, self._mtime_s or 0, self._mtime_ns or 0)
   520 
   520 
   521     def _v1_state(self):
   521     def _v1_state(self) -> bytes:
   522         """return a "state" suitable for v1 serialization"""
   522         """return a "state" suitable for v1 serialization"""
   523         if not self.any_tracked:
   523         if not self.any_tracked:
   524             # the object has no state to record, this is -currently-
   524             # the object has no state to record, this is -currently-
   525             # unsupported
   525             # unsupported
   526             raise RuntimeError('untracked item')
   526             raise RuntimeError('untracked item')
   646                 del self._nodemap[n]
   646                 del self._nodemap[n]
   647 
   647 
   648     def clearcaches(self):
   648     def clearcaches(self):
   649         self.__dict__.pop('_nodemap', None)
   649         self.__dict__.pop('_nodemap', None)
   650 
   650 
   651     def __len__(self):
   651     def __len__(self) -> int:
   652         return self._lgt + len(self._extra)
   652         return self._lgt + len(self._extra)
   653 
   653 
   654     def append(self, tup):
   654     def append(self, tup):
   655         if '_nodemap' in vars(self):
   655         if '_nodemap' in vars(self):
   656             self._nodemap[tup[7]] = len(self)
   656             self._nodemap[tup[7]] = len(self)
   706     def pack_header(self, header):
   706     def pack_header(self, header):
   707         """pack header information as binary"""
   707         """pack header information as binary"""
   708         v_fmt = revlog_constants.INDEX_HEADER
   708         v_fmt = revlog_constants.INDEX_HEADER
   709         return v_fmt.pack(header)
   709         return v_fmt.pack(header)
   710 
   710 
   711     def entry_binary(self, rev):
   711     def entry_binary(self, rev) -> bytes:
   712         """return the raw binary string representing a revision"""
   712         """return the raw binary string representing a revision"""
   713         entry = self[rev]
   713         entry = self[rev]
   714         p = revlog_constants.INDEX_ENTRY_V1.pack(*entry[:8])
   714         p = revlog_constants.INDEX_ENTRY_V1.pack(*entry[:8])
   715         if rev == 0:
   715         if rev == 0:
   716             p = p[revlog_constants.INDEX_HEADER.size :]
   716             p = p[revlog_constants.INDEX_HEADER.size :]
   717         return p
   717         return p
   718 
   718 
   719     def headrevs(self, excluded_revs=None, stop_rev=None):
   719     def headrevs(self, excluded_revs=None, stop_rev=None) -> list[int]:
   720         count = len(self)
   720         count = len(self)
   721         if stop_rev is not None:
   721         if stop_rev is not None:
   722             count = min(count, stop_rev)
   722             count = min(count, stop_rev)
   723         if not count:
   723         if not count:
   724             return [nullrev]
   724             return [nullrev]
   734             ishead[e[5]] = ishead[e[6]] = 0  # my parent are not
   734             ishead[e[5]] = ishead[e[6]] = 0  # my parent are not
   735         return [r for r, val in enumerate(ishead) if val]
   735         return [r for r, val in enumerate(ishead) if val]
   736 
   736 
   737 
   737 
   738 class IndexObject(BaseIndexObject):
   738 class IndexObject(BaseIndexObject):
   739     def __init__(self, data):
   739     def __init__(self, data: ByteString):
   740         assert len(data) % self.entry_size == 0, (
   740         assert len(data) % self.entry_size == 0, (
   741             len(data),
   741             len(data),
   742             self.entry_size,
   742             self.entry_size,
   743             len(data) % self.entry_size,
   743             len(data) % self.entry_size,
   744         )
   744         )
   771     through the dedicated `devel.persistent-nodemap` config.
   771     through the dedicated `devel.persistent-nodemap` config.
   772     """
   772     """
   773 
   773 
   774     # TODO: add type info
   774     # TODO: add type info
   775     _nm_docket: Any  # TODO: could be None, but need to handle .tip_rev below
   775     _nm_docket: Any  # TODO: could be None, but need to handle .tip_rev below
   776     _nm_max_idx: Any | None
   776     _nm_max_idx: int | None
   777     _nm_root: Any | None
   777     _nm_root: nodemaputil.Block | None
   778 
   778 
   779     def nodemap_data_all(self):
   779     def nodemap_data_all(self):
   780         """Return bytes containing a full serialization of a nodemap
   780         """Return bytes containing a full serialization of a nodemap
   781 
   781 
   782         The nodemap should be valid for the full set of revisions in the
   782         The nodemap should be valid for the full set of revisions in the
   853 
   853 
   854     def _calculate_index(self, i: int) -> int:
   854     def _calculate_index(self, i: int) -> int:
   855         return self._offsets[i]
   855         return self._offsets[i]
   856 
   856 
   857 
   857 
   858 def parse_index2(data, inline, format=revlog_constants.REVLOGV1):
   858 def parse_index2(
       
   859     data: ByteString, inline, format=revlog_constants.REVLOGV1
       
   860 ) -> tuple[IndexObject | InlinedIndexObject, tuple[int, ByteString] | None]:
   859     if format == revlog_constants.CHANGELOGV2:
   861     if format == revlog_constants.CHANGELOGV2:
   860         return parse_index_cl_v2(data)
   862         return parse_index_cl_v2(data)
   861     if not inline:
   863     if not inline:
   862         if format == revlog_constants.REVLOGV2:
   864         if format == revlog_constants.REVLOGV2:
   863             cls = IndexObject2
   865             cls = IndexObject2