/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/transform.py

Merge with path_content_summary

Show diffs side-by-side

added added

removed removed

Lines of Context:
1391
1391
        except KeyError:
1392
1392
            return
1393
1393
        file_id = self.tree_file_id(parent_id)
 
1394
        if file_id is None:
 
1395
            return
1394
1396
        children = getattr(self._tree.inventory[file_id], 'children', {})
1395
1397
        for child in children:
1396
1398
            childpath = joinpath(path, child)
1470
1472
                      trees=[], require_versioned=require_versioned))
1471
1473
        return result
1472
1474
 
1473
 
    def _path2id_last_transform_segment(self, path):
1474
 
        segments = list(reversed(splitpath(path)))
 
1475
    def _path2trans_id(self, path):
 
1476
        segments = splitpath(path)
1475
1477
        cur_parent = self._transform.root
1476
 
        while len(segments) > 0:
1477
 
            cur_segment = segments.pop()
1478
 
            for child in self._by_parent.get(cur_parent, []):
 
1478
        for cur_segment in segments:
 
1479
            for child in self._all_children(cur_parent):
1479
1480
                if self._transform.final_name(child) == cur_segment:
1480
1481
                    cur_parent = child
1481
1482
                    break
1482
1483
            else:
1483
 
                segments.append(cur_segment)
1484
 
                break
1485
 
        return cur_parent, list(reversed(segments))
1486
 
 
1487
 
    def _candidate_treepath(self, trans_segment, segments):
1488
 
        parent_path = self._final_paths.get_path(trans_segment)
1489
 
        tree_path = pathjoin(*([parent_path] + segments))
1490
 
        return tree_path
1491
 
 
1492
 
    def _valid_path2id(self, file_id, tree_path, trans_segment):
1493
 
        """Determine whether a file_id corresponds to a path.
1494
 
 
1495
 
        We do by seeing if the trans_segment is actually the last parent that
1496
 
        is mentioned in the transform.  If a more recent parent is mentioned,
1497
 
        in the transform, it it would be the trans_segment unless it has been
1498
 
        renamed.  Therefore, the parent has been renamed and the path is not
1499
 
        valid.
1500
 
 
1501
 
        :param file_id: The file_id that may correspond to tree_path
1502
 
        :param tree_path: The path of the file_id in the tree
1503
 
        :param trans_segment: The last parent of the file which is mentioned
1504
 
            in the transform.
1505
 
        """
1506
 
        cur_trans_id = self._transform._tree_path_ids.get(tree_path)
1507
 
        while cur_trans_id != trans_segment:
1508
 
            if cur_trans_id is not None:
1509
 
                # If there was an entry for this file, and the path was
1510
 
                # correct we would have handled it already.  So the path must
1511
 
                # be wrong.
1512
 
                if cur_trans_id in self._transform._new_parent:
1513
 
                    return False
1514
 
            file_id = self._transform._tree.iter_entries_by_dir(
1515
 
                [file_id]).next()[1].parent_id
1516
 
            tree_path = self._transform._tree.id2path(file_id)
1517
 
            cur_trans_id = self._transform._tree_path_ids.get(tree_path)
1518
 
        return True
1519
 
 
1520
 
    def _path_info(self, path):
1521
 
        trans_segment, segments = self._path2id_last_transform_segment(path)
1522
 
        if len(segments) == 0:
1523
 
            tree_path = self._transform._tree_id_paths.get(trans_segment)
1524
 
            return trans_segment, tree_path
1525
 
        tree_path = self._candidate_treepath(trans_segment, segments)
1526
 
        return self._transform.trans_id_tree_path(tree_path), tree_path
 
1484
                return None
 
1485
        return cur_parent
1527
1486
 
1528
1487
    def path2id(self, path):
1529
 
        trans_segment, segments = self._path2id_last_transform_segment(path)
1530
 
        if len(segments) == 0:
1531
 
            return self._transform.final_file_id(trans_segment)
1532
 
        tree_path = self._candidate_treepath(trans_segment, segments)
1533
 
        tree_file_id = self._transform._tree.path2id(tree_path)
1534
 
        if self._valid_path2id(tree_file_id, tree_path, trans_segment):
1535
 
            return tree_file_id
1536
 
        else:
1537
 
            return None
 
1488
        return self._transform.final_file_id(self._path2trans_id(path))
1538
1489
 
1539
1490
    def id2path(self, file_id):
1540
1491
        trans_id = self._transform.trans_id_file_id(file_id)
1616
1567
        return self._transform._tree.is_executable(file_id, path)
1617
1568
 
1618
1569
    def path_content_summary(self, path):
1619
 
        trans_id, tree_path = self._path_info(path)
 
1570
        trans_id = self._path2trans_id(path)
1620
1571
        tt = self._transform
 
1572
        tree_path = tt._tree_id_paths.get(trans_id)
1621
1573
        kind = tt._new_contents.get(trans_id)
1622
1574
        if kind is None:
1623
 
            if trans_id in tt._removed_contents:
 
1575
            if tree_path is None or trans_id in tt._removed_contents:
1624
1576
                return 'missing', None, None, None
1625
1577
            summary = tt._tree.path_content_summary(tree_path)
1626
1578
            kind, size, executable, link_or_sha1 = summary