/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

  • Committer: Aaron Bentley
  • Date: 2008-06-24 14:50:42 UTC
  • mto: (3363.16.1 __contains__)
  • mto: This revision was merged to the branch mainline in revision 3517.
  • Revision ID: aaron@aaronbentley.com-20080624145042-jqvq17asm73jtour
Split path2id into smaller pieces

Show diffs side-by-side

added added

removed removed

Lines of Context:
1469
1469
                      trees=[], require_versioned=require_versioned))
1470
1470
        return result
1471
1471
 
1472
 
    def path2id(self, path):
 
1472
    def _path2id_last_transform_segment(self, path):
1473
1473
        by_parent = self._transform.by_parent()
1474
1474
        segments = list(reversed(splitpath(path)))
1475
1475
        cur_parent = self._transform.root
1482
1482
            else:
1483
1483
                segments.append(cur_segment)
1484
1484
                break
1485
 
        if len(segments) == 0:
1486
 
            return self._transform.final_file_id(cur_parent)
1487
 
        parent_path = self._transform._tree_id_paths[cur_parent]
1488
 
        tree_path = pathjoin(*reversed(segments + [parent_path]))
 
1485
        return cur_parent, list(reversed(segments))
 
1486
 
 
1487
    def _candidate_treepath2id(self, trans_segment, segments):
 
1488
        parent_path = self._transform._tree_id_paths[trans_segment]
 
1489
        tree_path = pathjoin(*([parent_path] + segments))
1489
1490
        tree_file_id = self._transform._tree.path2id(tree_path)
1490
 
        cur_file_id = tree_file_id
 
1491
        return tree_file_id, tree_path
 
1492
 
 
1493
    def _valid_path2id(self, file_id, tree_path, trans_segment):
 
1494
        """Determine whether a file_id corresponds to a path.
 
1495
 
 
1496
        We do by seeing if the trans_segment is actually the last parent that
 
1497
        is mentioned in the transform.  If a more recent parent is mentioned,
 
1498
        in the transform, it it would be the trans_segment unless it has been
 
1499
        renamed.  Therefore, the parent has been renamed and the path is not
 
1500
        valid.
 
1501
 
 
1502
        :param file_id: The file_id that may correspond to tree_path
 
1503
        :param tree_path: The path of the file_id in the tree
 
1504
        :param trans_segment: The last parent of the file which is mentioned
 
1505
            in the transform.
 
1506
        """
1491
1507
        cur_trans_id = self._transform._tree_path_ids.get(tree_path)
1492
 
        while cur_trans_id != cur_parent:
 
1508
        while cur_trans_id != trans_segment:
1493
1509
            if cur_trans_id is not None:
1494
1510
                # If there was an entry for this file, and the path was
1495
1511
                # correct we would have handled it already.  So the path must
1496
1512
                # be wrong.
1497
1513
                if cur_trans_id in self._transform._new_parent:
1498
 
                    return None
1499
 
            cur_file_id = self._transform._tree.iter_entries_by_dir(
1500
 
                [cur_file_id]).next()[1].parent_id
1501
 
            tree_path = self._transform._tree.id2path(cur_file_id)
 
1514
                    return False
 
1515
            file_id = self._transform._tree.iter_entries_by_dir(
 
1516
                [file_id]).next()[1].parent_id
 
1517
            tree_path = self._transform._tree.id2path(file_id)
1502
1518
            cur_trans_id = self._transform._tree_path_ids.get(tree_path)
1503
 
        return tree_file_id
 
1519
        return True
 
1520
 
 
1521
    def path2id(self, path):
 
1522
        trans_segment, segments = self._path2id_last_transform_segment(path)
 
1523
        if len(segments) == 0:
 
1524
            return self._transform.final_file_id(trans_segment)
 
1525
        tree_file_id, tree_path = self._candidate_treepath2id(trans_segment,
 
1526
                                                              segments)
 
1527
        if self._valid_path2id(tree_file_id, tree_path, trans_segment):
 
1528
            return tree_file_id
 
1529
        else:
 
1530
            return None
1504
1531
 
1505
1532
    def id2path(self, file_id):
1506
1533
        trans_id = self._transform.trans_id_file_id(file_id)