##// END OF EJS Templates
bundle2.unbundlepart: implement seek()...
Eric Sumner -
r24037:f0b498cf default
parent child Browse files
Show More
@@ -886,6 +886,15 b' class unbundlepart(unpackermixin):'
886 payloadsize = self._unpack(_fpayloadsize)[0]
886 payloadsize = self._unpack(_fpayloadsize)[0]
887 self.ui.debug('payload chunk size: %i\n' % payloadsize)
887 self.ui.debug('payload chunk size: %i\n' % payloadsize)
888
888
889 def _findchunk(self, pos):
890 '''for a given payload position, return a chunk number and offset'''
891 for chunk, (ppos, fpos) in enumerate(self._chunkindex):
892 if ppos == pos:
893 return chunk, 0
894 elif ppos > pos:
895 return chunk - 1, pos - self._chunkindex[chunk - 1][0]
896 raise ValueError('Unknown chunk')
897
889 def _readheader(self):
898 def _readheader(self):
890 """read the header and setup the object"""
899 """read the header and setup the object"""
891 typesize = self._unpackheader(_fparttypesize)[0]
900 typesize = self._unpackheader(_fparttypesize)[0]
@@ -937,6 +946,31 b' class unbundlepart(unpackermixin):'
937 def tell(self):
946 def tell(self):
938 return self._pos
947 return self._pos
939
948
949 def seek(self, offset, whence=0):
950 if whence == 0:
951 newpos = offset
952 elif whence == 1:
953 newpos = self._pos + offset
954 elif whence == 2:
955 if not self.consumed:
956 self.read()
957 newpos = self._chunkindex[-1][0] - offset
958 else:
959 raise ValueError('Unknown whence value: %r' % (whence,))
960
961 if newpos > self._chunkindex[-1][0] and not self.consumed:
962 self.read()
963 if not 0 <= newpos <= self._chunkindex[-1][0]:
964 raise ValueError('Offset out of range')
965
966 if self._pos != newpos:
967 chunk, internaloffset = self._findchunk(newpos)
968 self._payloadstream = util.chunkbuffer(self._payloadchunks(chunk))
969 adjust = self.read(internaloffset)
970 if len(adjust) != internaloffset:
971 raise util.Abort(_('Seek failed\n'))
972 self._pos = newpos
973
940 capabilities = {'HG2Y': (),
974 capabilities = {'HG2Y': (),
941 'b2x:listkeys': (),
975 'b2x:listkeys': (),
942 'b2x:pushkey': (),
976 'b2x:pushkey': (),
General Comments 0
You need to be logged in to leave comments. Login now