Mercurial > hg
comparison mercurial/bundle2.py @ 24034:9881a1437799
bundle2.unbundlepart: raise payloadchunks from a closure to a method
In a future patch, seek() will need to make a new chunk iterator for
the stream; this places it somewhere it can be called multiple times.
author | Eric Sumner <ericsumner@fb.com> |
---|---|
date | Wed, 14 Jan 2015 14:32:22 -0800 |
parents | 3daef83a1873 |
children | 7eb26415bef6 |
comparison
equal
deleted
inserted
replaced
24033:ed5e8a9598ce | 24034:9881a1437799 |
---|---|
850 # user friendly UI | 850 # user friendly UI |
851 self.params = dict(self.mandatoryparams) | 851 self.params = dict(self.mandatoryparams) |
852 self.params.update(dict(self.advisoryparams)) | 852 self.params.update(dict(self.advisoryparams)) |
853 self.mandatorykeys = frozenset(p[0] for p in mandatoryparams) | 853 self.mandatorykeys = frozenset(p[0] for p in mandatoryparams) |
854 | 854 |
855 def _payloadchunks(self): | |
856 payloadsize = self._unpack(_fpayloadsize)[0] | |
857 self.ui.debug('payload chunk size: %i\n' % payloadsize) | |
858 while payloadsize: | |
859 if payloadsize == flaginterrupt: | |
860 # interruption detection, the handler will now read a | |
861 # single part and process it. | |
862 interrupthandler(self.ui, self._fp)() | |
863 elif payloadsize < 0: | |
864 msg = 'negative payload chunk size: %i' % payloadsize | |
865 raise error.BundleValueError(msg) | |
866 else: | |
867 yield self._readexact(payloadsize) | |
868 payloadsize = self._unpack(_fpayloadsize)[0] | |
869 self.ui.debug('payload chunk size: %i\n' % payloadsize) | |
870 | |
855 def _readheader(self): | 871 def _readheader(self): |
856 """read the header and setup the object""" | 872 """read the header and setup the object""" |
857 typesize = self._unpackheader(_fparttypesize)[0] | 873 typesize = self._unpackheader(_fparttypesize)[0] |
858 self.type = self._fromheader(typesize) | 874 self.type = self._fromheader(typesize) |
859 self.ui.debug('part type: "%s"\n' % self.type) | 875 self.ui.debug('part type: "%s"\n' % self.type) |
881 advparams = [] | 897 advparams = [] |
882 for key, value in advsizes: | 898 for key, value in advsizes: |
883 advparams.append((self._fromheader(key), self._fromheader(value))) | 899 advparams.append((self._fromheader(key), self._fromheader(value))) |
884 self._initparams(manparams, advparams) | 900 self._initparams(manparams, advparams) |
885 ## part payload | 901 ## part payload |
886 def payloadchunks(): | 902 self._payloadstream = util.chunkbuffer(self._payloadchunks()) |
887 payloadsize = self._unpack(_fpayloadsize)[0] | |
888 self.ui.debug('payload chunk size: %i\n' % payloadsize) | |
889 while payloadsize: | |
890 if payloadsize == flaginterrupt: | |
891 # interruption detection, the handler will now read a | |
892 # single part and process it. | |
893 interrupthandler(self.ui, self._fp)() | |
894 elif payloadsize < 0: | |
895 msg = 'negative payload chunk size: %i' % payloadsize | |
896 raise error.BundleValueError(msg) | |
897 else: | |
898 yield self._readexact(payloadsize) | |
899 payloadsize = self._unpack(_fpayloadsize)[0] | |
900 self.ui.debug('payload chunk size: %i\n' % payloadsize) | |
901 self._payloadstream = util.chunkbuffer(payloadchunks()) | |
902 # we read the data, tell it | 903 # we read the data, tell it |
903 self._initialized = True | 904 self._initialized = True |
904 | 905 |
905 def read(self, size=None): | 906 def read(self, size=None): |
906 """read payload data""" | 907 """read payload data""" |