/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 bzrlib/dirstate.py

  • Committer: John Arbash Meinel
  • Date: 2008-06-05 16:27:16 UTC
  • mfrom: (3475 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3476.
  • Revision ID: john@arbash-meinel.com-20080605162716-a3hn238tnctbfd8j
merge bzr.dev, resolve NEWS

Show diffs side-by-side

added added

removed removed

Lines of Context:
393
393
        # faster than three separate encodes.
394
394
        utf8path = (dirname + '/' + basename).strip('/').encode('utf8')
395
395
        dirname, basename = osutils.split(utf8path)
396
 
        assert file_id.__class__ == str, \
397
 
            "must be a utf8 file_id not %s" % (type(file_id))
 
396
        # uses __class__ for speed; the check is needed for safety
 
397
        if file_id.__class__ is not str:
 
398
            raise AssertionError(
 
399
                "must be a utf8 file_id not %s" % (type(file_id), ))
398
400
        # Make sure the file_id does not exist in this tree
399
401
        file_id_entry = self._get_entry(0, fileid_utf8=file_id)
400
402
        if file_id_entry != (None, None):
456
458
        if not present:
457
459
            block.insert(entry_index, entry_data)
458
460
        else:
459
 
            assert block[entry_index][1][0][0] == 'a', " %r(%r) already added" % (basename, file_id)
 
461
            if block[entry_index][1][0][0] != 'a':
 
462
                raise AssertionError(" %r(%r) already added" % (basename, file_id))
460
463
            block[entry_index][1][0] = entry_data[1][0]
461
464
 
462
465
        if kind == 'directory':
481
484
        # If _dirblock_state was in memory, we should just return info from
482
485
        # there, this function is only meant to handle when we want to read
483
486
        # part of the disk.
484
 
        assert self._dirblock_state == DirState.NOT_IN_MEMORY
 
487
        if self._dirblock_state != DirState.NOT_IN_MEMORY:
 
488
            raise AssertionError("bad dirblock state %r" % self._dirblock_state)
485
489
 
486
490
        # The disk representation is generally info + '\0\n\0' at the end. But
487
491
        # for bisecting, it is easier to treat this as '\0' + info + '\0\n'
673
677
        # If _dirblock_state was in memory, we should just return info from
674
678
        # there, this function is only meant to handle when we want to read
675
679
        # part of the disk.
676
 
        assert self._dirblock_state == DirState.NOT_IN_MEMORY
677
 
 
 
680
        if self._dirblock_state != DirState.NOT_IN_MEMORY:
 
681
            raise AssertionError("bad dirblock state %r" % self._dirblock_state)
678
682
        # The disk representation is generally info + '\0\n\0' at the end. But
679
683
        # for bisecting, it is easier to treat this as '\0' + info + '\0\n'
680
684
        # Because it means we can sync on the '\n'
967
971
        # the basename of the directory must be the end of its full name.
968
972
        if not (parent_block_index == -1 and
969
973
            parent_block_index == -1 and dirname == ''):
970
 
            assert dirname.endswith(
971
 
                self._dirblocks[parent_block_index][1][parent_row_index][0][1])
 
974
            if not dirname.endswith(
 
975
                    self._dirblocks[parent_block_index][1][parent_row_index][0][1]):
 
976
                raise AssertionError("bad dirname %r" % dirname)
972
977
        block_index, present = self._find_block_index_from_key((dirname, '', ''))
973
978
        if not present:
974
979
            ## In future, when doing partial parsing, this should load and 
986
991
            to prevent unneeded overhead when callers have a sorted list already.
987
992
        :return: Nothing.
988
993
        """
989
 
        assert new_entries[0][0][0:2] == ('', ''), \
990
 
            "Missing root row %r" % (new_entries[0][0],)
 
994
        if new_entries[0][0][0:2] != ('', ''):
 
995
            raise AssertionError(
 
996
                "Missing root row %r" % (new_entries[0][0],))
991
997
        # The two blocks here are deliberate: the root block and the 
992
998
        # contents-of-root block.
993
999
        self._dirblocks = [('', []), ('', [])]
1015
1021
        # The above loop leaves the "root block" entries mixed with the
1016
1022
        # "contents-of-root block". But we don't want an if check on
1017
1023
        # all entries, so instead we just fix it up here.
1018
 
        assert self._dirblocks[1] == ('', [])
 
1024
        if self._dirblocks[1] != ('', []):
 
1025
            raise ValueError("bad dirblock start %r" % (self._dirblocks[1],))
1019
1026
        root_block = []
1020
1027
        contents_of_root_block = []
1021
1028
        for entry in self._dirblocks[0][1]:
1175
1182
        self._read_dirblocks_if_needed()
1176
1183
        insertions = {}
1177
1184
        removals = {}
1178
 
        for old_path, new_path, file_id, inv_entry in sorted(delta,
1179
 
                                                             reverse=True):
1180
 
            assert file_id not in insertions
1181
 
            assert file_id not in removals
 
1185
        for old_path, new_path, file_id, inv_entry in sorted(delta, reverse=True):
 
1186
            if (file_id in insertions) or (file_id in removals):
 
1187
                raise AssertionError("repeated file id in delta %r" % (file_id,))
1182
1188
            if old_path is not None:
1183
1189
                old_path = old_path.encode('utf-8')
1184
1190
                removals[file_id] = old_path
1312
1318
                        source_path = entry[0][0] + '/' + entry[0][1]
1313
1319
                    else:
1314
1320
                        source_path = entry[0][1]
1315
 
                    target_path = new_path_utf8 + source_path[len(old_path):]
 
1321
                    if new_path_utf8:
 
1322
                        target_path = new_path_utf8 + source_path[len(old_path):]
 
1323
                    else:
 
1324
                        if old_path == '':
 
1325
                            raise AssertionError("cannot rename directory to"
 
1326
                                " itself")
 
1327
                        target_path = source_path[len(old_path) + 1:]
1316
1328
                    adds.append((None, target_path, entry[0][2], entry[1][1], False))
1317
1329
                    deletes.append(
1318
1330
                        (source_path, target_path, entry[0][2], None, False))
1354
1366
        # their children, so we can process it linearly.
1355
1367
        absent = 'ar'
1356
1368
        for old_path, new_path, file_id, new_details, real_add in adds:
1357
 
            assert old_path is None
1358
1369
            # the entry for this file_id must be in tree 0.
1359
1370
            entry = self._get_entry(0, file_id, new_path)
1360
1371
            if entry[0] is None or entry[0][2] != file_id:
1379
1390
        """
1380
1391
        absent = 'ar'
1381
1392
        for old_path, new_path, file_id, new_details in changes:
1382
 
            assert old_path == new_path
1383
1393
            # the entry for this file_id must be in tree 0.
1384
1394
            entry = self._get_entry(0, file_id, new_path)
1385
1395
            if entry[0] is None or entry[0][2] != file_id:
1407
1417
        """
1408
1418
        null = DirState.NULL_PARENT_DETAILS
1409
1419
        for old_path, new_path, file_id, _, real_delete in deletes:
1410
 
            if real_delete:
1411
 
                assert new_path is None
1412
 
            else:
1413
 
                assert new_path is not None
 
1420
            if real_delete != (new_path is None):
 
1421
                raise AssertionError("bad delete delta")
1414
1422
            # the entry for this file_id must be in tree 1.
1415
1423
            dirname, basename = osutils.split(old_path)
1416
1424
            block_index, entry_index, dir_present, file_present = \
1731
1739
        """
1732
1740
        self._read_dirblocks_if_needed()
1733
1741
        if path_utf8 is not None:
1734
 
            assert path_utf8.__class__ == str, ('path_utf8 is not a str: %s %s'
1735
 
                % (type(path_utf8), path_utf8))
 
1742
            if type(path_utf8) is not str:
 
1743
                raise AssertionError('path_utf8 is not a str: %s %s'
 
1744
                    % (type(path_utf8), path_utf8))
1736
1745
            # path lookups are faster
1737
1746
            dirname, basename = osutils.split(path_utf8)
1738
1747
            block_index, entry_index, dir_present, file_present = \
1740
1749
            if not file_present:
1741
1750
                return None, None
1742
1751
            entry = self._dirblocks[block_index][1][entry_index]
1743
 
            assert entry[0][2] and entry[1][tree_index][0] not in ('a', 'r'), 'unversioned entry?!?!'
 
1752
            if not (entry[0][2] and entry[1][tree_index][0] not in ('a', 'r')):
 
1753
                raise AssertionError('unversioned entry?')
1744
1754
            if fileid_utf8:
1745
1755
                if entry[0][2] != fileid_utf8:
1746
1756
                    self._changes_aborted = True
1748
1758
                                          ' tree_index, file_id and path')
1749
1759
            return entry
1750
1760
        else:
1751
 
            assert fileid_utf8 is not None
1752
1761
            possible_keys = self._get_id_index().get(fileid_utf8, None)
1753
1762
            if not possible_keys:
1754
1763
                return None, None
1773
1782
                    if entry[1][tree_index][0] == 'a':
1774
1783
                        # there is no home for this entry in this tree
1775
1784
                        return None, None
1776
 
                    assert entry[1][tree_index][0] == 'r', \
1777
 
                        "entry %r has invalid minikind %r for tree %r" \
1778
 
                        % (entry,
1779
 
                           entry[1][tree_index][0],
1780
 
                           tree_index)
 
1785
                    if entry[1][tree_index][0] != 'r':
 
1786
                        raise AssertionError(
 
1787
                            "entry %r has invalid minikind %r for tree %r" \
 
1788
                            % (entry,
 
1789
                               entry[1][tree_index][0],
 
1790
                               tree_index))
1781
1791
                    real_path = entry[1][tree_index][1]
1782
1792
                    return self._get_entry(tree_index, fileid_utf8=fileid_utf8,
1783
1793
                        path_utf8=real_path)
1826
1836
        kind = inv_entry.kind
1827
1837
        minikind = DirState._kind_to_minikind[kind]
1828
1838
        tree_data = inv_entry.revision
1829
 
        assert tree_data, 'empty revision for the inv_entry %s.' % \
1830
 
            inv_entry.file_id
1831
1839
        if kind == 'directory':
1832
1840
            fingerprint = ''
1833
1841
            size = 0
1966
1974
        parent_line = self._state_file.readline()
1967
1975
        info = parent_line.split('\0')
1968
1976
        num_parents = int(info[0])
1969
 
        assert num_parents == len(info)-2, 'incorrect parent info line'
1970
1977
        self._parents = info[1:-1]
1971
 
 
1972
1978
        ghost_line = self._state_file.readline()
1973
1979
        info = ghost_line.split('\0')
1974
1980
        num_ghosts = int(info[1])
1975
 
        assert num_ghosts == len(info)-3, 'incorrect ghost info line'
1976
1981
        self._ghosts = info[2:-1]
1977
1982
        self._header_state = DirState.IN_MEMORY_UNMODIFIED
1978
1983
        self._end_of_header = self._state_file.tell()
1995
2000
        and their ids. Followed by a newline.
1996
2001
        """
1997
2002
        header = self._state_file.readline()
1998
 
        assert header == DirState.HEADER_FORMAT_3, \
1999
 
            'invalid header line: %r' % (header,)
 
2003
        if header != DirState.HEADER_FORMAT_3:
 
2004
            raise errors.BzrError(
 
2005
                'invalid header line: %r' % (header,))
2000
2006
        crc_line = self._state_file.readline()
2001
 
        assert crc_line.startswith('crc32: '), 'missing crc32 checksum'
 
2007
        if not crc_line.startswith('crc32: '):
 
2008
            raise errors.BzrError('missing crc32 checksum: %r' % crc_line)
2002
2009
        self.crc_expected = int(crc_line[len('crc32: '):-1])
2003
2010
        num_entries_line = self._state_file.readline()
2004
 
        assert num_entries_line.startswith('num_entries: '), 'missing num_entries line'
 
2011
        if not num_entries_line.startswith('num_entries: '):
 
2012
            raise errors.BzrError('missing num_entries line')
2005
2013
        self._num_entries = int(num_entries_line[len('num_entries: '):-1])
2006
2014
 
2007
2015
    def sha1_from_stat(self, path, stat_result, _pack_stat=pack_stat):
2095
2103
        :param new_id: The new id to assign to the path. This must be a utf8
2096
2104
            file id (not unicode, and not None).
2097
2105
        """
2098
 
        assert new_id.__class__ == str, \
2099
 
            "path_id %r is not a plain string" % (new_id,)
2100
2106
        self._read_dirblocks_if_needed()
2101
2107
        if len(path):
2102
2108
            # TODO: logic not written
2398
2404
            # Remove it, its meaningless.
2399
2405
            block = self._find_block(current_old[0])
2400
2406
            entry_index, present = self._find_entry_index(current_old[0], block[1])
2401
 
            assert present, 'could not find entry for %s' % (current_old,)
 
2407
            if not present:
 
2408
                raise AssertionError('could not find entry for %s' % (current_old,))
2402
2409
            block[1].pop(entry_index)
2403
2410
            # if we have an id_index in use, remove this key from it for this id.
2404
2411
            if self._id_index is not None:
2410
2417
        for update_key in all_remaining_keys:
2411
2418
            update_block_index, present = \
2412
2419
                self._find_block_index_from_key(update_key)
2413
 
            assert present, 'could not find block for %s' % (update_key,)
 
2420
            if not present:
 
2421
                raise AssertionError('could not find block for %s' % (update_key,))
2414
2422
            update_entry_index, present = \
2415
2423
                self._find_entry_index(update_key, self._dirblocks[update_block_index][1])
2416
 
            assert present, 'could not find entry for %s' % (update_key,)
 
2424
            if not present:
 
2425
                raise AssertionError('could not find entry for %s' % (update_key,))
2417
2426
            update_tree_details = self._dirblocks[update_block_index][1][update_entry_index][1]
2418
2427
            # it must not be absent at the moment
2419
 
            assert update_tree_details[0][0] != 'a' # absent
 
2428
            if update_tree_details[0][0] == 'a': # absent
 
2429
                raise AssertionError('bad row %r' % (update_tree_details,))
2420
2430
            update_tree_details[0] = DirState.NULL_PARENT_DETAILS
2421
2431
        self._dirblock_state = DirState.IN_MEMORY_MODIFIED
2422
2432
        return last_reference
2470
2480
                    # the test for existing kinds is different: this can be
2471
2481
                    # factored out to a helper though.
2472
2482
                    other_block_index, present = self._find_block_index_from_key(other_key)
2473
 
                    assert present, 'could not find block for %s' % (other_key,)
 
2483
                    if not present:
 
2484
                        raise AssertionError('could not find block for %s' % (other_key,))
2474
2485
                    other_entry_index, present = self._find_entry_index(other_key,
2475
2486
                                            self._dirblocks[other_block_index][1])
2476
 
                    assert present, 'could not find entry for %s' % (other_key,)
2477
 
                    assert path_utf8 is not None
 
2487
                    if not present:
 
2488
                        raise AssertionError('could not find entry for %s' % (other_key,))
 
2489
                    if path_utf8 is None:
 
2490
                        raise AssertionError('no path')
2478
2491
                    self._dirblocks[other_block_index][1][other_entry_index][1][0] = \
2479
2492
                        ('r', path_utf8, 0, False, '')
2480
2493
 
2486
2499
                    # records.
2487
2500
                    update_block_index, present = \
2488
2501
                        self._find_block_index_from_key(other_key)
2489
 
                    assert present, 'could not find block for %s' % (other_key,)
 
2502
                    if not present:
 
2503
                        raise AssertionError('could not find block for %s' % (other_key,))
2490
2504
                    update_entry_index, present = \
2491
2505
                        self._find_entry_index(other_key, self._dirblocks[update_block_index][1])
2492
 
                    assert present, 'could not find entry for %s' % (other_key,)
 
2506
                    if not present:
 
2507
                        raise AssertionError('could not find entry for %s' % (other_key,))
2493
2508
                    update_details = self._dirblocks[update_block_index][1][update_entry_index][1][lookup_index]
2494
2509
                    if update_details[0] in 'ar': # relocated, absent
2495
2510
                        # its a pointer or absent in lookup_index's tree, use
2513
2528
            # we may have passed entries in the state with this file id already
2514
2529
            # that were absent - where parent entries are - and they need to be
2515
2530
            # converted to relocated.
2516
 
            assert path_utf8 is not None
 
2531
            if path_utf8 is None:
 
2532
                raise AssertionError('no path')
2517
2533
            for entry_key in id_index.setdefault(key[2], set()):
2518
2534
                # TODO:PROFILING: It might be faster to just update
2519
2535
                # rather than checking if we need to, and then overwrite
2524
2540
                    # This is the vertical axis in the matrix, all pointing
2525
2541
                    # to the real path.
2526
2542
                    block_index, present = self._find_block_index_from_key(entry_key)
2527
 
                    assert present
 
2543
                    if not present:
 
2544
                        raise AssertionError('not present: %r', entry_key)
2528
2545
                    entry_index, present = self._find_entry_index(entry_key, self._dirblocks[block_index][1])
2529
 
                    assert present
 
2546
                    if not present:
 
2547
                        raise AssertionError('not present: %r', entry_key)
2530
2548
                    self._dirblocks[block_index][1][entry_index][1][0] = \
2531
2549
                        ('r', path_utf8, 0, False, '')
2532
2550
        # add a containing dirblock if needed.
2563
2581
            if not self._dirblocks[0][0] == '':
2564
2582
                raise AssertionError(
2565
2583
                    "dirblocks don't start with root block:\n" + \
2566
 
                    pformat(dirblocks))
 
2584
                    pformat(self._dirblocks))
2567
2585
        if len(self._dirblocks) > 1:
2568
2586
            if not self._dirblocks[1][0] == '':
2569
2587
                raise AssertionError(
2570
2588
                    "dirblocks missing root directory:\n" + \
2571
 
                    pformat(dirblocks))
 
2589
                    pformat(self._dirblocks))
2572
2590
        # the dirblocks are sorted by their path components, name, and dir id
2573
2591
        dir_names = [d[0].split('/')
2574
2592
                for d in self._dirblocks[1:]]