Ejemplo n.º 1
0
 def _map_loose_object(self, sha):
     """
     :return: memory map of that file to allow random read access
     :raise BadObject: if object could not be located"""
     db_path = self.db_path(self.object_path(bin_to_hex(sha)))
     try:
         return file_contents_ro_filepath(db_path, flags=self._fd_open_flags)
     except OSError, e:
         if e.errno != ENOENT:
             # try again without noatime
             try:
                 return file_contents_ro_filepath(db_path)
             except OSError:
                 raise BadObject(sha)
             # didn't work because of our flag, don't try it again
             self._fd_open_flags = 0
         else:
             raise BadObject(sha)
Ejemplo n.º 2
0
	def _map_loose_object(self, sha):
		"""
		:return: memory map of that file to allow random read access
		:raise BadObject: if object could not be located"""
		db_path = self.db_path(self.object_path(bin_to_hex(sha)))
		try:
			return file_contents_ro_filepath(db_path, flags=self._fd_open_flags)
		except OSError,e:
			if e.errno != ENOENT:
				# try again without noatime
				try:
					return file_contents_ro_filepath(db_path)
				except OSError:
					raise BadObject(sha)
				# didn't work because of our flag, don't try it again
				self._fd_open_flags = 0
			else:
				raise BadObject(sha)
Ejemplo n.º 3
0
    def _read_from_file(self):
        try:
            fmap = file_contents_ro_filepath(self._path, stream=True, allow_mmap=True)
        except OSError:
            # it is possible and allowed that the file doesn't exist !
            return
        # END handle invalid log

        try:
            self._deserialize(fmap)
        finally:
            fmap.close()
Ejemplo n.º 4
0
 def iter_entries(cls, stream):
     """
     :return: Iterator yielding RefLogEntry instances, one for each line read 
         sfrom the given stream.
     :param stream: file-like object containing the revlog in its native format
         or basestring instance pointing to a file to read"""
     new_entry = RefLogEntry.from_line
     if isinstance(stream, basestring):
         stream = file_contents_ro_filepath(stream)
     #END handle stream type
     while True:
         line = stream.readline()
         if not line:
             return
         yield new_entry(line.strip())
Ejemplo n.º 5
0
 def iter_entries(cls, stream):
     """
     :return: Iterator yielding RefLogEntry instances, one for each line read 
         sfrom the given stream.
     :param stream: file-like object containing the revlog in its native format
         or basestring instance pointing to a file to read"""
     new_entry = RefLogEntry.from_line
     if isinstance(stream, basestring):
         stream = file_contents_ro_filepath(stream)
     # END handle stream type
     while True:
         line = stream.readline()
         if not line:
             return
         yield new_entry(line.strip())
Ejemplo n.º 6
0
 def iter_entries(
         cls, stream: Union[str, 'BytesIO', mmap]) -> Iterator[RefLogEntry]:
     """
     :return: Iterator yielding RefLogEntry instances, one for each line read
         sfrom the given stream.
     :param stream: file-like object containing the revlog in its native format
         or string instance pointing to a file to read"""
     new_entry = RefLogEntry.from_line
     if isinstance(stream, str):
         # default args return mmap on py>3
         _stream = file_contents_ro_filepath(stream)
         assert isinstance(_stream, mmap)
     else:
         _stream = stream
     # END handle stream type
     while True:
         line = _stream.readline()
         if not line:
             return
         yield new_entry(line.strip())