/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to parser.py

fix from Pieter de Bie - hack around broken front-ends

Show diffs side-by-side

added added

removed removed

Lines of Context:
253
253
# the first bit is \w*, not \w+.) Also git-fast-import code says the
254
254
# space before the email is optional.
255
255
_WHO_AND_WHEN_RE = re.compile(r'([^<]*)<(.+)> (.+)')
 
256
_WHO_RE = re.compile(r'([^<]*)<(.+)>')
256
257
 
257
258
 
258
259
class ImportParser(LineBasedParser):
337
338
        mark = self._get_mark_if_any()
338
339
        author = self._get_user_info('commit', 'author', False)
339
340
        committer = self._get_user_info('commit', 'committer')
340
 
        message = self._get_data('commit', 'message').decode('utf_8')
 
341
        message = self._get_data('commit', 'message')
 
342
        try:
 
343
            message = message.decode('utf_8')
 
344
        except UnicodeDecodeError:
 
345
            # TODO: output a warning here about a broken front-end
 
346
            pass
341
347
        from_ = self._get_from()
342
348
        merges = []
343
349
        while True:
379
385
    def _parse_tag(self, name):
380
386
        """Parse a tag command."""
381
387
        from_ = self._get_from('tag')
382
 
        tagger = self._get_user_info('tag', 'tagger')
 
388
        tagger = self._get_user_info('tag', 'tagger', accept_just_who=True)
383
389
        message = self._get_data('tag', 'message').decode('utf_8')
384
390
        return commands.TagCommand(name, from_, tagger, message)
385
391
 
412
418
            self.push_line(line)
413
419
            return None
414
420
 
415
 
    def _get_user_info(self, cmd, section, required=True):
 
421
    def _get_user_info(self, cmd, section, required=True,
 
422
        accept_just_who=False):
416
423
        """Parse a user section."""
417
424
        line = self.next_line()
418
425
        if line.startswith(section + ' '):
419
 
            return self._who_when(line[len(section + ' '):], cmd, section)
 
426
            return self._who_when(line[len(section + ' '):], cmd, section,
 
427
                accept_just_who=accept_just_who)
420
428
        elif required:
421
429
            self.abort(errors.MissingSection, cmd, section)
422
430
        else:
442
450
        else:
443
451
            self.abort(errors.MissingSection, required_for, section)
444
452
 
445
 
    def _who_when(self, s, cmd, section):
 
453
    def _who_when(self, s, cmd, section, accept_just_who=False):
446
454
        """Parse who and when information from a string.
447
455
        
448
456
        :return: a tuple of (name,email,timestamp,timezone). name may be
461
469
                    format = 'rfc2822'
462
470
                self.date_parser = dates.DATE_PARSERS_BY_NAME[format]
463
471
            when = self.date_parser(datestr)
464
 
            name = match.group(1)
465
 
            if len(name) > 0:
466
 
                if name[-1] == " ":
467
 
                    name = name[:-1].decode('utf_8')
468
 
            return (name,match.group(2),when[0],when[1])
469
472
        else:
470
 
            self.abort(errors.BadFormat, cmd, section, s)
 
473
            match = _WHO_RE.search(s)
 
474
            if accept_just_who and match:
 
475
                # HACK around missing time
 
476
                # TODO: output a warning here
 
477
                when = dates.DATE_PARSERS_BY_NAME['now']('now')
 
478
            else:
 
479
                self.abort(errors.BadFormat, cmd, section, s)
 
480
        name = match.group(1)
 
481
        if len(name) > 0:
 
482
            if name[-1] == " ":
 
483
                name = name[:-1].decode('utf_8')
 
484
        return (name,match.group(2),when[0],when[1])
471
485
 
472
486
    def _path(self, s):
473
487
        """Parse a path."""