Mercurial > public > mercurial-scm > hg
comparison mercurial/bundle2.py @ 25320:697d8953b04d
bundle2: handle new line in 'indebug' function
Now that we have a prefix, it make sense to assume all output will be on a
single line.
author | Pierre-Yves David <pierre-yves.david@fb.com> |
---|---|
date | Tue, 26 May 2015 23:01:39 -0700 |
parents | c3ef4f3b8680 |
children | b44ee346211f |
comparison
equal
deleted
inserted
replaced
25319:c3ef4f3b8680 | 25320:697d8953b04d |
---|---|
177 """debug regarding output stream (bundling)""" | 177 """debug regarding output stream (bundling)""" |
178 ui.debug('bundle2-output: %s\n' % message) | 178 ui.debug('bundle2-output: %s\n' % message) |
179 | 179 |
180 def indebug(ui, message): | 180 def indebug(ui, message): |
181 """debug on input stream (unbundling)""" | 181 """debug on input stream (unbundling)""" |
182 ui.debug('bundle2-input: %s' % message) | 182 ui.debug('bundle2-input: %s\n' % message) |
183 | 183 |
184 def validateparttype(parttype): | 184 def validateparttype(parttype): |
185 """raise ValueError if a parttype contains invalid character""" | 185 """raise ValueError if a parttype contains invalid character""" |
186 if _parttypeforbidden.search(parttype): | 186 if _parttypeforbidden.search(parttype): |
187 raise ValueError(parttype) | 187 raise ValueError(parttype) |
348 try: | 348 try: |
349 try: | 349 try: |
350 handler = parthandlermapping.get(part.type) | 350 handler = parthandlermapping.get(part.type) |
351 if handler is None: | 351 if handler is None: |
352 raise error.UnsupportedPartError(parttype=part.type) | 352 raise error.UnsupportedPartError(parttype=part.type) |
353 indebug(op.ui, 'found a handler for part %r\n' % part.type) | 353 indebug(op.ui, 'found a handler for part %r' % part.type) |
354 unknownparams = part.mandatorykeys - handler.params | 354 unknownparams = part.mandatorykeys - handler.params |
355 if unknownparams: | 355 if unknownparams: |
356 unknownparams = list(unknownparams) | 356 unknownparams = list(unknownparams) |
357 unknownparams.sort() | 357 unknownparams.sort() |
358 raise error.UnsupportedPartError(parttype=part.type, | 358 raise error.UnsupportedPartError(parttype=part.type, |
359 params=unknownparams) | 359 params=unknownparams) |
360 except error.UnsupportedPartError, exc: | 360 except error.UnsupportedPartError, exc: |
361 if part.mandatory: # mandatory parts | 361 if part.mandatory: # mandatory parts |
362 raise | 362 raise |
363 indebug(op.ui, 'ignoring unsupported advisory part %s\n' % exc) | 363 indebug(op.ui, 'ignoring unsupported advisory part %s' % exc) |
364 return # skip to part processing | 364 return # skip to part processing |
365 | 365 |
366 # handler is called outside the above try block so that we don't | 366 # handler is called outside the above try block so that we don't |
367 # risk catching KeyErrors from anything other than the | 367 # risk catching KeyErrors from anything other than the |
368 # parthandlermapping lookup (any KeyError raised by handler() | 368 # parthandlermapping lookup (any KeyError raised by handler() |
561 raise util.Abort(_('not a Mercurial bundle')) | 561 raise util.Abort(_('not a Mercurial bundle')) |
562 unbundlerclass = formatmap.get(version) | 562 unbundlerclass = formatmap.get(version) |
563 if unbundlerclass is None: | 563 if unbundlerclass is None: |
564 raise util.Abort(_('unknown bundle version %s') % version) | 564 raise util.Abort(_('unknown bundle version %s') % version) |
565 unbundler = unbundlerclass(ui, fp) | 565 unbundler = unbundlerclass(ui, fp) |
566 indebug(ui, 'start processing of %s stream\n' % header) | 566 indebug(ui, 'start processing of %s stream' % header) |
567 return unbundler | 567 return unbundler |
568 | 568 |
569 class unbundle20(unpackermixin): | 569 class unbundle20(unpackermixin): |
570 """interpret a bundle2 stream | 570 """interpret a bundle2 stream |
571 | 571 |
578 super(unbundle20, self).__init__(fp) | 578 super(unbundle20, self).__init__(fp) |
579 | 579 |
580 @util.propertycache | 580 @util.propertycache |
581 def params(self): | 581 def params(self): |
582 """dictionary of stream level parameters""" | 582 """dictionary of stream level parameters""" |
583 indebug(self.ui, 'reading bundle2 stream parameters\n') | 583 indebug(self.ui, 'reading bundle2 stream parameters') |
584 params = {} | 584 params = {} |
585 paramssize = self._unpack(_fstreamparamsize)[0] | 585 paramssize = self._unpack(_fstreamparamsize)[0] |
586 if paramssize < 0: | 586 if paramssize < 0: |
587 raise error.BundleValueError('negative bundle param size: %i' | 587 raise error.BundleValueError('negative bundle param size: %i' |
588 % paramssize) | 588 % paramssize) |
611 if name[0] not in string.letters: | 611 if name[0] not in string.letters: |
612 raise ValueError('non letter first character: %r' % name) | 612 raise ValueError('non letter first character: %r' % name) |
613 # Some logic will be later added here to try to process the option for | 613 # Some logic will be later added here to try to process the option for |
614 # a dict of known parameter. | 614 # a dict of known parameter. |
615 if name[0].islower(): | 615 if name[0].islower(): |
616 indebug(self.ui, "ignoring unknown parameter %r\n" % name) | 616 indebug(self.ui, "ignoring unknown parameter %r" % name) |
617 else: | 617 else: |
618 raise error.UnsupportedPartError(params=(name,)) | 618 raise error.UnsupportedPartError(params=(name,)) |
619 | 619 |
620 | 620 |
621 def iterparts(self): | 621 def iterparts(self): |
622 """yield all parts contained in the stream""" | 622 """yield all parts contained in the stream""" |
623 # make sure param have been loaded | 623 # make sure param have been loaded |
624 self.params | 624 self.params |
625 indebug(self.ui, 'start extraction of bundle2 parts\n') | 625 indebug(self.ui, 'start extraction of bundle2 parts') |
626 headerblock = self._readpartheader() | 626 headerblock = self._readpartheader() |
627 while headerblock is not None: | 627 while headerblock is not None: |
628 part = unbundlepart(self.ui, headerblock, self._fp) | 628 part = unbundlepart(self.ui, headerblock, self._fp) |
629 yield part | 629 yield part |
630 part.seek(0, 2) | 630 part.seek(0, 2) |
631 headerblock = self._readpartheader() | 631 headerblock = self._readpartheader() |
632 indebug(self.ui, 'end of bundle2 stream\n') | 632 indebug(self.ui, 'end of bundle2 stream') |
633 | 633 |
634 def _readpartheader(self): | 634 def _readpartheader(self): |
635 """reads a part header size and return the bytes blob | 635 """reads a part header size and return the bytes blob |
636 | 636 |
637 returns None if empty""" | 637 returns None if empty""" |
638 headersize = self._unpack(_fpartheadersize)[0] | 638 headersize = self._unpack(_fpartheadersize)[0] |
639 if headersize < 0: | 639 if headersize < 0: |
640 raise error.BundleValueError('negative part header size: %i' | 640 raise error.BundleValueError('negative part header size: %i' |
641 % headersize) | 641 % headersize) |
642 indebug(self.ui, 'part header size: %i\n' % headersize) | 642 indebug(self.ui, 'part header size: %i' % headersize) |
643 if headersize: | 643 if headersize: |
644 return self._readexact(headersize) | 644 return self._readexact(headersize) |
645 return None | 645 return None |
646 | 646 |
647 def compressed(self): | 647 def compressed(self): |
829 if headersize: | 829 if headersize: |
830 return self._readexact(headersize) | 830 return self._readexact(headersize) |
831 return None | 831 return None |
832 | 832 |
833 def __call__(self): | 833 def __call__(self): |
834 indebug(self.ui, 'bundle2 stream interruption, looking for a part.\n') | 834 indebug(self.ui, 'bundle2 stream interruption, looking for a part.') |
835 headerblock = self._readpartheader() | 835 headerblock = self._readpartheader() |
836 if headerblock is None: | 836 if headerblock is None: |
837 indebug(self.ui, 'no part found during interruption.\n') | 837 indebug(self.ui, 'no part found during interruption.') |
838 return | 838 return |
839 part = unbundlepart(self.ui, headerblock, self._fp) | 839 part = unbundlepart(self.ui, headerblock, self._fp) |
840 op = interruptoperation(self.ui) | 840 op = interruptoperation(self.ui) |
841 _processpart(op, part) | 841 _processpart(op, part) |
842 | 842 |
916 'Unknown chunk %d' % chunknum | 916 'Unknown chunk %d' % chunknum |
917 super(unbundlepart, self).seek(self._chunkindex[chunknum][1]) | 917 super(unbundlepart, self).seek(self._chunkindex[chunknum][1]) |
918 | 918 |
919 pos = self._chunkindex[chunknum][0] | 919 pos = self._chunkindex[chunknum][0] |
920 payloadsize = self._unpack(_fpayloadsize)[0] | 920 payloadsize = self._unpack(_fpayloadsize)[0] |
921 indebug(self.ui, 'payload chunk size: %i\n' % payloadsize) | 921 indebug(self.ui, 'payload chunk size: %i' % payloadsize) |
922 while payloadsize: | 922 while payloadsize: |
923 if payloadsize == flaginterrupt: | 923 if payloadsize == flaginterrupt: |
924 # interruption detection, the handler will now read a | 924 # interruption detection, the handler will now read a |
925 # single part and process it. | 925 # single part and process it. |
926 interrupthandler(self.ui, self._fp)() | 926 interrupthandler(self.ui, self._fp)() |
934 if chunknum == len(self._chunkindex): | 934 if chunknum == len(self._chunkindex): |
935 self._chunkindex.append((pos, | 935 self._chunkindex.append((pos, |
936 super(unbundlepart, self).tell())) | 936 super(unbundlepart, self).tell())) |
937 yield result | 937 yield result |
938 payloadsize = self._unpack(_fpayloadsize)[0] | 938 payloadsize = self._unpack(_fpayloadsize)[0] |
939 indebug(self.ui, 'payload chunk size: %i\n' % payloadsize) | 939 indebug(self.ui, 'payload chunk size: %i' % payloadsize) |
940 | 940 |
941 def _findchunk(self, pos): | 941 def _findchunk(self, pos): |
942 '''for a given payload position, return a chunk number and offset''' | 942 '''for a given payload position, return a chunk number and offset''' |
943 for chunk, (ppos, fpos) in enumerate(self._chunkindex): | 943 for chunk, (ppos, fpos) in enumerate(self._chunkindex): |
944 if ppos == pos: | 944 if ppos == pos: |
949 | 949 |
950 def _readheader(self): | 950 def _readheader(self): |
951 """read the header and setup the object""" | 951 """read the header and setup the object""" |
952 typesize = self._unpackheader(_fparttypesize)[0] | 952 typesize = self._unpackheader(_fparttypesize)[0] |
953 self.type = self._fromheader(typesize) | 953 self.type = self._fromheader(typesize) |
954 indebug(self.ui, 'part type: "%s"\n' % self.type) | 954 indebug(self.ui, 'part type: "%s"' % self.type) |
955 self.id = self._unpackheader(_fpartid)[0] | 955 self.id = self._unpackheader(_fpartid)[0] |
956 indebug(self.ui, 'part id: "%s"\n' % self.id) | 956 indebug(self.ui, 'part id: "%s"' % self.id) |
957 # extract mandatory bit from type | 957 # extract mandatory bit from type |
958 self.mandatory = (self.type != self.type.lower()) | 958 self.mandatory = (self.type != self.type.lower()) |
959 self.type = self.type.lower() | 959 self.type = self.type.lower() |
960 ## reading parameters | 960 ## reading parameters |
961 # param count | 961 # param count |
962 mancount, advcount = self._unpackheader(_fpartparamcount) | 962 mancount, advcount = self._unpackheader(_fpartparamcount) |
963 indebug(self.ui, 'part parameters: %i\n' % (mancount + advcount)) | 963 indebug(self.ui, 'part parameters: %i' % (mancount + advcount)) |
964 # param size | 964 # param size |
965 fparamsizes = _makefpartparamsizes(mancount + advcount) | 965 fparamsizes = _makefpartparamsizes(mancount + advcount) |
966 paramsizes = self._unpackheader(fparamsizes) | 966 paramsizes = self._unpackheader(fparamsizes) |
967 # make it a list of couple again | 967 # make it a list of couple again |
968 paramsizes = zip(paramsizes[::2], paramsizes[1::2]) | 968 paramsizes = zip(paramsizes[::2], paramsizes[1::2]) |