mercurial/revlog.py
changeset 47408 f7f082bc0e7c
parent 47405 34cc102c73f5
child 47419 5e44936b82be
equal deleted inserted replaced
47407:1efe3cdef53a 47408:f7f082bc0e7c
   485         except IOError as inst:
   485         except IOError as inst:
   486             if inst.errno != errno.ENOENT:
   486             if inst.errno != errno.ENOENT:
   487                 raise
   487                 raise
   488             return b''
   488             return b''
   489 
   489 
   490     def _loadindex(self):
   490     def _loadindex(self, docket=None):
   491 
   491 
   492         new_header, mmapindexthreshold, force_nodemap = self._init_opts()
   492         new_header, mmapindexthreshold, force_nodemap = self._init_opts()
   493 
   493 
   494         if self.postfix is not None:
   494         if self.postfix is not None:
   495             entry_point = b'%s.i.%s' % (self.radix, self.postfix)
   495             entry_point = b'%s.i.%s' % (self.radix, self.postfix)
   496         elif self._trypending and self.opener.exists(b'%s.i.a' % self.radix):
   496         elif self._trypending and self.opener.exists(b'%s.i.a' % self.radix):
   497             entry_point = b'%s.i.a' % self.radix
   497             entry_point = b'%s.i.a' % self.radix
   498         else:
   498         else:
   499             entry_point = b'%s.i' % self.radix
   499             entry_point = b'%s.i' % self.radix
   500 
   500 
   501         entry_data = b''
   501         if docket is not None:
   502         self._initempty = True
   502             self._docket = docket
   503         entry_data = self._get_data(entry_point, mmapindexthreshold)
   503             self._docket_file = entry_point
   504         if len(entry_data) > 0:
       
   505             header = INDEX_HEADER.unpack(entry_data[:4])[0]
       
   506             self._initempty = False
       
   507         else:
   504         else:
   508             header = new_header
   505             entry_data = b''
   509 
   506             self._initempty = True
   510         self._format_flags = header & ~0xFFFF
   507             entry_data = self._get_data(entry_point, mmapindexthreshold)
   511         self._format_version = header & 0xFFFF
   508             if len(entry_data) > 0:
   512 
   509                 header = INDEX_HEADER.unpack(entry_data[:4])[0]
   513         supported_flags = SUPPORTED_FLAGS.get(self._format_version)
   510                 self._initempty = False
   514         if supported_flags is None:
       
   515             msg = _(b'unknown version (%d) in revlog %s')
       
   516             msg %= (self._format_version, self.display_id)
       
   517             raise error.RevlogError(msg)
       
   518         elif self._format_flags & ~supported_flags:
       
   519             msg = _(b'unknown flags (%#04x) in version %d revlog %s')
       
   520             display_flag = self._format_flags >> 16
       
   521             msg %= (display_flag, self._format_version, self.display_id)
       
   522             raise error.RevlogError(msg)
       
   523 
       
   524         features = FEATURES_BY_VERSION[self._format_version]
       
   525         self._inline = features[b'inline'](self._format_flags)
       
   526         self._generaldelta = features[b'generaldelta'](self._format_flags)
       
   527         self.hassidedata = features[b'sidedata']
       
   528 
       
   529         if not features[b'docket']:
       
   530             self._indexfile = entry_point
       
   531             index_data = entry_data
       
   532         else:
       
   533             self._docket_file = entry_point
       
   534             if self._initempty:
       
   535                 self._docket = docketutil.default_docket(self, header)
       
   536             else:
   511             else:
   537                 self._docket = docketutil.parse_docket(
   512                 header = new_header
   538                     self, entry_data, use_pending=self._trypending
   513 
   539                 )
   514             self._format_flags = header & ~0xFFFF
       
   515             self._format_version = header & 0xFFFF
       
   516 
       
   517             supported_flags = SUPPORTED_FLAGS.get(self._format_version)
       
   518             if supported_flags is None:
       
   519                 msg = _(b'unknown version (%d) in revlog %s')
       
   520                 msg %= (self._format_version, self.display_id)
       
   521                 raise error.RevlogError(msg)
       
   522             elif self._format_flags & ~supported_flags:
       
   523                 msg = _(b'unknown flags (%#04x) in version %d revlog %s')
       
   524                 display_flag = self._format_flags >> 16
       
   525                 msg %= (display_flag, self._format_version, self.display_id)
       
   526                 raise error.RevlogError(msg)
       
   527 
       
   528             features = FEATURES_BY_VERSION[self._format_version]
       
   529             self._inline = features[b'inline'](self._format_flags)
       
   530             self._generaldelta = features[b'generaldelta'](self._format_flags)
       
   531             self.hassidedata = features[b'sidedata']
       
   532 
       
   533             if not features[b'docket']:
       
   534                 self._indexfile = entry_point
       
   535                 index_data = entry_data
       
   536             else:
       
   537                 self._docket_file = entry_point
       
   538                 if self._initempty:
       
   539                     self._docket = docketutil.default_docket(self, header)
       
   540                 else:
       
   541                     self._docket = docketutil.parse_docket(
       
   542                         self, entry_data, use_pending=self._trypending
       
   543                     )
       
   544 
       
   545         if self._docket is not None:
   540             self._indexfile = self._docket.index_filepath()
   546             self._indexfile = self._docket.index_filepath()
   541             index_data = b''
   547             index_data = b''
   542             index_size = self._docket.index_end
   548             index_size = self._docket.index_end
   543             if index_size > 0:
   549             if index_size > 0:
   544                 index_data = self._get_data(
   550                 index_data = self._get_data(