示例#1
0
	def _assert_pack_file(self, pack, version, size):
		assert pack.version() == 2
		assert pack.size() == size
		assert len(pack.checksum()) == 20
		
		num_obj = 0
		for obj in pack.stream_iter():
			num_obj += 1
			info = pack.info(obj.pack_offset)
			stream = pack.stream(obj.pack_offset)
			
			assert info.pack_offset == stream.pack_offset
			assert info.type_id == stream.type_id
			assert hasattr(stream, 'read')
			
			# it should be possible to read from both streams
			assert obj.read() == stream.read()
			
			streams = pack.collect_streams(obj.pack_offset)
			assert streams
			
			# read the stream
			try:
				dstream = DeltaApplyReader.new(streams)
			except ValueError:
				# ignore these, old git versions use only ref deltas, 
				# which we havent resolved ( as we are without an index )
				# Also ignore non-delta streams
				continue
			# END get deltastream
			
			# read all
			data = dstream.read()
			assert len(data) == dstream.size
			
			# test seek
			dstream.seek(0)
			assert dstream.read() == data
			
			
			# read chunks
			# NOTE: the current implementation is safe, it basically transfers
			# all calls to the underlying memory map
			
		# END for each object
		assert num_obj == size
	def _assert_pack_file(self, pack, version, size):
		assert pack.version() == 2
		assert pack.size() == size
		assert len(pack.checksum()) == 20
		
		num_obj = 0
		for obj in pack.stream_iter():
			num_obj += 1
			info = pack.info(obj.pack_offset)
			stream = pack.stream(obj.pack_offset)
			
			assert info.pack_offset == stream.pack_offset
			assert info.type_id == stream.type_id
			assert hasattr(stream, 'read')
			
			# it should be possible to read from both streams
			assert obj.read() == stream.read()
			
			streams = pack.collect_streams(obj.pack_offset)
			assert streams
			
			# read the stream
			try:
				dstream = DeltaApplyReader.new(streams)
			except ValueError:
				# ignore these, old git versions use only ref deltas, 
				# which we havent resolved ( as we are without an index )
				# Also ignore non-delta streams
				continue
			# END get deltastream
			
			# read all
			data = dstream.read()
			assert len(data) == dstream.size
			
			# test seek
			dstream.seek(0)
			assert dstream.read() == data
			
			
			# read chunks
			# NOTE: the current implementation is safe, it basically transfers
			# all calls to the underlying memory map
			
		# END for each object
		assert num_obj == size
示例#3
0
    def _object(self, sha, as_stream, index=-1):
        """:return: OInfo or OStream object providing information about the given sha
        :param index: if not -1, its assumed to be the sha's index in the IndexFile"""
        # its a little bit redundant here, but it needs to be efficient
        if index < 0:
            index = self._sha_to_index(sha)
        if sha is None:
            sha = self._index.sha(index)
        # END assure sha is present ( in output )
        offset = self._index.offset(index)
        type_id, uncomp_size, data_rela_offset = pack_object_header_info(
            self._pack._cursor.use_region(offset).buffer())
        if as_stream:
            if type_id not in delta_types:
                packstream = self._pack.stream(offset)
                return OStream(sha, packstream.type, packstream.size,
                               packstream.stream)
            # END handle non-deltas

            # produce a delta stream containing all info
            # To prevent it from applying the deltas when querying the size,
            # we extract it from the delta stream ourselves
            streams = self.collect_streams_at_offset(offset)
            dstream = DeltaApplyReader.new(streams)

            return ODeltaStream(sha, dstream.type, None, dstream)
        else:
            if type_id not in delta_types:
                return OInfo(sha, type_id_to_type_map[type_id], uncomp_size)
            # END handle non-deltas

            # deltas are a little tougher - unpack the first bytes to obtain
            # the actual target size, as opposed to the size of the delta data
            streams = self.collect_streams_at_offset(offset)
            buf = streams[0].read(512)
            offset, src_size = msb_size(buf)
            offset, target_size = msb_size(buf, offset)

            # collect the streams to obtain the actual object type
            if streams[-1].type_id in delta_types:
                raise BadObject(sha, "Could not resolve delta object")
            return OInfo(sha, streams[-1].type, target_size)
示例#4
0
文件: pack.py 项目: yarikoptic/gitdb
    def _object(self, sha, as_stream, index=-1):
        """:return: OInfo or OStream object providing information about the given sha
        :param index: if not -1, its assumed to be the sha's index in the IndexFile"""
        # its a little bit redundant here, but it needs to be efficient
        if index < 0:
            index = self._sha_to_index(sha)
        if sha is None:
            sha = self._index.sha(index)
        # END assure sha is present ( in output )
        offset = self._index.offset(index)
        type_id, uncomp_size, data_rela_offset = pack_object_header_info(self._pack._cursor.use_region(offset).buffer())
        if as_stream:
            if type_id not in delta_types:
                packstream = self._pack.stream(offset)
                return OStream(sha, packstream.type, packstream.size, packstream.stream)
            # END handle non-deltas

            # produce a delta stream containing all info
            # To prevent it from applying the deltas when querying the size,
            # we extract it from the delta stream ourselves
            streams = self.collect_streams_at_offset(offset)
            dstream = DeltaApplyReader.new(streams)

            return ODeltaStream(sha, dstream.type, None, dstream)
        else:
            if type_id not in delta_types:
                return OInfo(sha, type_id_to_type_map[type_id], uncomp_size)
            # END handle non-deltas

            # deltas are a little tougher - unpack the first bytes to obtain
            # the actual target size, as opposed to the size of the delta data
            streams = self.collect_streams_at_offset(offset)
            buf = streams[0].read(512)
            offset, src_size = msb_size(buf)
            offset, target_size = msb_size(buf, offset)

            # collect the streams to obtain the actual object type
            if streams[-1].type_id in delta_types:
                raise BadObject(sha, "Could not resolve delta object")
            return OInfo(sha, streams[-1].type, target_size)