~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transform.py

transform.final_kind() now returns None instead of raising NoSuchFile.

* bzrlib/transform.py:
(TreeTransformBase.final_kind): Just return None instead of
raising NoSuchFile since all callers just do that while catching
the exception.
(TreeTransformBase._improper_versioning)
(TreeTransformBase._executability_conflicts)
(TreeTransformBase._duplicate_entries)
(TreeTransformBase._parent_type_conflicts)
(TreeTransformBase._any_contents, TreeTransformBase._to_file_data)
(TreeTransform._generate_inventory_delta)
(_PreviewTree._make_inv_entries, _PreviewTree.walkdirs): Fix call
sites.

* bzrlib/tests/test_transform.py:
(TestTreeTransform.test_build): The single test needing a fix for
final_kind returning None...

* bzrlib/merge.py:
(Merge3Merger.fix_root, Merge3Merger.fix_root)
(Merge3Merger._merge_executable): Simplify final_kind() uses.

Show diffs side-by-side

added added

removed removed

Lines of Context:
396
396
    def final_kind(self, trans_id):
397
397
        """Determine the final file kind, after any changes applied.
398
398
 
399
 
        Raises NoSuchFile if the file does not exist/has no contents.
400
 
        (It is conceivable that a path would be created without the
401
 
        corresponding contents insertion command)
 
399
        :return: None if the file does not exist/has no contents.  (It is
 
400
            conceivable that a path would be created without the corresponding
 
401
            contents insertion command)
402
402
        """
403
403
        if trans_id in self._new_contents:
404
404
            return self._new_contents[trans_id]
405
405
        elif trans_id in self._removed_contents:
406
 
            raise NoSuchFile(None)
 
406
            return None
407
407
        else:
408
 
            return self.tree_kind(trans_id)
 
408
            # FIXME?: One step forward, one step backwards, tree_kind raise
 
409
            # NoSuchFile instead of returning None -- vila 20100415
 
410
            try:
 
411
                kind = self.tree_kind(trans_id)
 
412
            except errors.NoSuchFile:
 
413
                kind = None
 
414
            return kind
409
415
 
410
416
    def tree_file_id(self, trans_id):
411
417
        """Determine the file id associated with the trans_id in the tree"""
595
601
        """
596
602
        conflicts = []
597
603
        for trans_id in self._new_id.iterkeys():
598
 
            try:
599
 
                kind = self.final_kind(trans_id)
600
 
            except NoSuchFile:
 
604
            kind = self.final_kind(trans_id)
 
605
            if kind is None:
601
606
                conflicts.append(('versioning no contents', trans_id))
602
607
                continue
603
608
            if not InventoryEntry.versionable_kind(kind):
617
622
            if self.final_file_id(trans_id) is None:
618
623
                conflicts.append(('unversioned executability', trans_id))
619
624
            else:
620
 
                try:
621
 
                    non_file = self.final_kind(trans_id) != "file"
622
 
                except NoSuchFile:
623
 
                    non_file = True
624
 
                if non_file is True:
 
625
                if self.final_kind(trans_id) != "file":
625
626
                    conflicts.append(('non-file executability', trans_id))
626
627
        return conflicts
627
628
 
651
652
            last_name = None
652
653
            last_trans_id = None
653
654
            for name, trans_id in name_ids:
654
 
                try:
655
 
                    kind = self.final_kind(trans_id)
656
 
                except NoSuchFile:
657
 
                    kind = None
 
655
                kind = self.final_kind(trans_id)
658
656
                file_id = self.final_file_id(trans_id)
659
657
                if kind is None and file_id is None:
660
658
                    continue
687
685
            if not self._any_contents(children):
688
686
                continue
689
687
            for child in children:
690
 
                try:
691
 
                    self.final_kind(child)
692
 
                except NoSuchFile:
 
688
                if self.final_kind(child) is None:
693
689
                    continue
694
 
            try:
695
 
                kind = self.final_kind(parent_id)
696
 
            except NoSuchFile:
697
 
                kind = None
 
690
            kind = self.final_kind(parent_id)
698
691
            if kind is None:
699
692
                conflicts.append(('missing parent', parent_id))
700
693
            elif kind != "directory":
704
697
    def _any_contents(self, trans_ids):
705
698
        """Return true if any of the trans_ids, will have contents."""
706
699
        for trans_id in trans_ids:
707
 
            try:
708
 
                kind = self.final_kind(trans_id)
709
 
            except NoSuchFile:
 
700
            if self.final_kind(trans_id) is None:
710
701
                continue
711
702
            return True
712
703
        return False
844
835
        Return a (name, parent, kind, executable) tuple
845
836
        """
846
837
        to_name = self.final_name(to_trans_id)
847
 
        try:
848
 
            to_kind = self.final_kind(to_trans_id)
849
 
        except NoSuchFile:
850
 
            to_kind = None
 
838
        to_kind = self.final_kind(to_trans_id)
851
839
        to_parent = self.final_file_id(self.final_parent(to_trans_id))
852
840
        if to_trans_id in self._new_executability:
853
841
            to_executable = self._new_executability[to_trans_id]
1583
1571
                if file_id is None:
1584
1572
                    continue
1585
1573
                needs_entry = False
1586
 
                try:
1587
 
                    kind = self.final_kind(trans_id)
1588
 
                except NoSuchFile:
 
1574
                kind = self.final_kind(trans_id)
 
1575
                if kind is None:
1589
1576
                    kind = self._tree.stored_kind(file_id)
1590
1577
                parent_trans_id = self.final_parent(trans_id)
1591
1578
                parent_file_id = new_path_file_ids.get(parent_trans_id)
1904
1891
            if (specific_file_ids is not None
1905
1892
                and file_id not in specific_file_ids):
1906
1893
                continue
1907
 
            try:
1908
 
                kind = self._transform.final_kind(trans_id)
1909
 
            except NoSuchFile:
 
1894
            kind = self._transform.final_kind(trans_id)
 
1895
            if kind is None:
1910
1896
                kind = self._transform._tree.stored_kind(file_id)
1911
1897
            new_entry = inventory.make_entry(
1912
1898
                kind,
2144
2130
                path_from_root = self._final_paths.get_path(child_id)
2145
2131
                basename = self._transform.final_name(child_id)
2146
2132
                file_id = self._transform.final_file_id(child_id)
2147
 
                try:
2148
 
                    kind = self._transform.final_kind(child_id)
 
2133
                kind  = self._transform.final_kind(child_id)
 
2134
                if kind is not None:
2149
2135
                    versioned_kind = kind
2150
 
                except NoSuchFile:
 
2136
                else:
2151
2137
                    kind = 'unknown'
2152
2138
                    versioned_kind = self._transform._tree.stored_kind(file_id)
2153
2139
                if versioned_kind == 'directory':