~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/_dirstate_helpers_c.pyx

  • Committer: John Arbash Meinel
  • Date: 2008-09-02 18:51:03 UTC
  • mto: This revision was merged to the branch mainline in revision 3680.
  • Revision ID: john@arbash-meinel.com-20080902185103-camvrjyw7a9efpno
Change from using AssertionError to using DirstateCorrupt in a few places

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
This is the python implementation for DirState functions.
20
20
"""
21
21
 
 
22
from bzrlib import errors
22
23
from bzrlib.dirstate import DirState
23
24
 
24
25
 
477
478
cdef class Reader:
478
479
    """Maintain the current location, and return fields as you parse them."""
479
480
 
 
481
    cdef object state # The DirState object
480
482
    cdef object text # The overall string object
481
483
    cdef char *text_cstr # Pointer to the beginning of text
482
484
    cdef int text_size # Length of text
485
487
    cdef char *cur_cstr # Pointer to the current record
486
488
    cdef char *next # Pointer to the end of this record
487
489
 
488
 
    def __init__(self, text):
 
490
    def __init__(self, text, state):
 
491
        self.state = state
489
492
        self.text = text
490
493
        self.text_cstr = PyString_AsString(text)
491
494
        self.text_size = PyString_Size(text)
506
509
        self.cur_cstr = <char*>memchr(next, c'\0', self.end_cstr - next)
507
510
        if self.cur_cstr == NULL:
508
511
            extra_len = self.end_cstr - next
509
 
            raise AssertionError('failed to find trailing NULL (\\0).'
 
512
            raise errors.DirstateCorrupt(self.state,
 
513
                'failed to find trailing NULL (\\0).'
510
514
                ' Trailing garbage: %r'
511
515
                % safe_string_from_size(next, extra_len))
512
516
        size[0] = self.cur_cstr - next
640
644
        # marker.
641
645
        trailing = self.get_next(&cur_size)
642
646
        if cur_size != 1 or trailing[0] != c'\n':
643
 
            raise AssertionError(
 
647
            raise errors.DirstateCorrupt(self.state,
644
648
                'Bad parse, we expected to end on \\n, not: %d %s: %s'
645
649
                % (cur_size, safe_string_from_size(trailing, cur_size),
646
650
                   ret))
647
651
        return ret
648
652
 
649
 
    def _parse_dirblocks(self, state):
 
653
    def _parse_dirblocks(self):
650
654
        """Parse all dirblocks in the state file."""
651
655
        cdef int num_trees
652
656
        cdef object current_block
656
660
        cdef int expected_entry_count
657
661
        cdef int entry_count
658
662
 
659
 
        num_trees = state._num_present_parents() + 1
660
 
        expected_entry_count = state._num_entries
 
663
        num_trees = self.state._num_present_parents() + 1
 
664
        expected_entry_count = self.state._num_entries
661
665
 
662
666
        # Ignore the first record
663
667
        self._init()
664
668
 
665
669
        current_block = []
666
 
        state._dirblocks = [('', current_block), ('', [])]
 
670
        dirblocks = [('', current_block), ('', [])]
 
671
        self.state._dirblocks = dirblocks
667
672
        obj = ''
668
673
        current_dirname = <void*>obj
669
674
        new_block = 0
681
686
            if new_block:
682
687
                # new block - different dirname
683
688
                current_block = []
684
 
                PyList_Append(state._dirblocks,
 
689
                PyList_Append(dirblocks,
685
690
                              (<object>current_dirname, current_block))
686
691
            PyList_Append(current_block, entry)
687
692
            entry_count = entry_count + 1
688
693
        if entry_count != expected_entry_count:
689
 
            raise AssertionError('We read the wrong number of entries.'
 
694
            raise errors.DirstateCorrupt(self.state,
 
695
                    'We read the wrong number of entries.'
690
696
                    ' We expected to read %s, but read %s'
691
697
                    % (expected_entry_count, entry_count))
692
 
        state._split_root_dirblock_into_contents()
 
698
        self.state._split_root_dirblock_into_contents()
693
699
 
694
700
 
695
701
def _read_dirblocks_c(state):
708
714
    text = state._state_file.read()
709
715
    # TODO: check the crc checksums. crc_measured = zlib.crc32(text)
710
716
 
711
 
    reader = Reader(text)
 
717
    reader = Reader(text, state)
712
718
 
713
 
    reader._parse_dirblocks(state)
 
719
    reader._parse_dirblocks()
714
720
    state._dirblock_state = DirState.IN_MEMORY_UNMODIFIED