mercurial/pure/parsers.py
changeset 46860 1dc86c2a43ce
parent 46858 85e3a630cad9
child 46974 3c9208702db3
equal deleted inserted replaced
46859:c6e23fb4bfb4 46860:1dc86c2a43ce
    42     return int(int(offset) << 16 | type)
    42     return int(int(offset) << 16 | type)
    43 
    43 
    44 
    44 
    45 class BaseIndexObject(object):
    45 class BaseIndexObject(object):
    46     # Format of an index entry according to Python's `struct` language
    46     # Format of an index entry according to Python's `struct` language
    47     index_format = revlog_constants.INDEX_ENTRY_V1.format
    47     index_format = revlog_constants.INDEX_ENTRY_V1
    48     # Size of a C unsigned long long int, platform independent
    48     # Size of a C unsigned long long int, platform independent
    49     big_int_size = struct.calcsize(b'>Q')
    49     big_int_size = struct.calcsize(b'>Q')
    50     # Size of a C long int, platform independent
    50     # Size of a C long int, platform independent
    51     int_size = struct.calcsize(b'>i')
    51     int_size = struct.calcsize(b'>i')
    52     # Size of the entire index format
    52     # Size of the entire index format
    97         return self._lgt + len(self._extra)
    97         return self._lgt + len(self._extra)
    98 
    98 
    99     def append(self, tup):
    99     def append(self, tup):
   100         if '_nodemap' in vars(self):
   100         if '_nodemap' in vars(self):
   101             self._nodemap[tup[7]] = len(self)
   101             self._nodemap[tup[7]] = len(self)
   102         data = _pack(self.index_format, *tup)
   102         data = self.index_format.pack(*tup)
   103         self._extra.append(data)
   103         self._extra.append(data)
   104 
   104 
   105     def _check_index(self, i):
   105     def _check_index(self, i):
   106         if not isinstance(i, int):
   106         if not isinstance(i, int):
   107             raise TypeError(b"expecting int indexes")
   107             raise TypeError(b"expecting int indexes")
   115         if i >= self._lgt:
   115         if i >= self._lgt:
   116             data = self._extra[i - self._lgt]
   116             data = self._extra[i - self._lgt]
   117         else:
   117         else:
   118             index = self._calculate_index(i)
   118             index = self._calculate_index(i)
   119             data = self._data[index : index + self.index_size]
   119             data = self._data[index : index + self.index_size]
   120         r = _unpack(self.index_format, data)
   120         r = self.index_format.unpack(data)
   121         if self._lgt and i == 0:
   121         if self._lgt and i == 0:
   122             r = (offset_type(0, gettype(r[0])),) + r[1:]
   122             r = (offset_type(0, gettype(r[0])),) + r[1:]
   123         return r
   123         return r
   124 
   124 
   125 
   125 
   241     cls = InlinedIndexObject2 if revlogv2 else InlinedIndexObject
   241     cls = InlinedIndexObject2 if revlogv2 else InlinedIndexObject
   242     return cls(data, inline), (0, data)
   242     return cls(data, inline), (0, data)
   243 
   243 
   244 
   244 
   245 class Index2Mixin(object):
   245 class Index2Mixin(object):
   246     index_format = revlog_constants.INDEX_ENTRY_V2.format
   246     index_format = revlog_constants.INDEX_ENTRY_V2
   247     index_size = revlog_constants.INDEX_ENTRY_V2.size
   247     index_size = revlog_constants.INDEX_ENTRY_V2.size
   248     null_item = (0, 0, 0, -1, -1, -1, -1, nullid, 0, 0)
   248     null_item = (0, 0, 0, -1, -1, -1, -1, nullid, 0, 0)
   249 
   249 
   250     def replace_sidedata_info(self, i, sidedata_offset, sidedata_length):
   250     def replace_sidedata_info(self, i, sidedata_offset, sidedata_length):
   251         """
   251         """