~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transform.py

bzrlib.transform.TreeTransform.tree_kind and
bzrlib.transform.TransformPreview.tree_kind also return None instead of
raising NoSuchFile.

Show diffs side-by-side

added added

removed removed

Lines of Context:
315
315
 
316
316
    def delete_contents(self, trans_id):
317
317
        """Schedule the contents of a path entry for deletion"""
318
 
        # Ensure that the object exists in the WorkingTree, this will raise an
319
 
        # exception if there is a problem
320
 
        self.tree_kind(trans_id)
321
 
        self._removed_contents.add(trans_id)
 
318
        kind = self.tree_kind(trans_id)
 
319
        if kind is not None:
 
320
            self._removed_contents.add(trans_id)
322
321
 
323
322
    def cancel_deletion(self, trans_id):
324
323
        """Cancel a scheduled deletion"""
389
388
        changed_kind = set(self._removed_contents)
390
389
        changed_kind.intersection_update(self._new_contents)
391
390
        changed_kind.difference_update(new_ids)
392
 
        changed_kind = (t for t in changed_kind if self.tree_kind(t) !=
393
 
                        self.final_kind(t))
 
391
        changed_kind = (t for t in changed_kind
 
392
                        if self.tree_kind(t) != self.final_kind(t))
394
393
        new_ids.update(changed_kind)
395
394
        return sorted(FinalPaths(self).get_paths(new_ids))
396
395
 
406
405
        elif trans_id in self._removed_contents:
407
406
            return None
408
407
        else:
409
 
            # FIXME?: One step forward, one step backwards, tree_kind raise
410
 
            # NoSuchFile instead of returning None -- vila 20100415
411
 
            try:
412
 
                kind = self.tree_kind(trans_id)
413
 
            except errors.NoSuchFile:
414
 
                kind = None
415
 
            return kind
 
408
            return self.tree_kind(trans_id)
416
409
 
417
410
    def tree_file_id(self, trans_id):
418
411
        """Determine the file id associated with the trans_id in the tree"""
631
624
        """Check for overwrites (not permitted on Win32)"""
632
625
        conflicts = []
633
626
        for trans_id in self._new_contents:
634
 
            try:
635
 
                self.tree_kind(trans_id)
636
 
            except NoSuchFile:
 
627
            if self.tree_kind(trans_id) is None:
637
628
                continue
638
629
            if trans_id not in self._removed_contents:
639
630
                conflicts.append(('overwrite', trans_id,
1407
1398
    def tree_kind(self, trans_id):
1408
1399
        """Determine the file kind in the working tree.
1409
1400
 
1410
 
        Raises NoSuchFile if the file does not exist
 
1401
        :returns: The file kind or None if the file does not exist
1411
1402
        """
1412
1403
        path = self._tree_id_paths.get(trans_id)
1413
1404
        if path is None:
1414
 
            raise NoSuchFile(None)
 
1405
            return None
1415
1406
        try:
1416
1407
            return file_kind(self._tree.abspath(path))
1417
 
        except OSError, e:
1418
 
            if e.errno != errno.ENOENT:
1419
 
                raise
1420
 
            else:
1421
 
                raise NoSuchFile(path)
 
1408
        except errors.NoSuchFile:
 
1409
            return None
1422
1410
 
1423
1411
    def _set_mode(self, trans_id, mode_id, typefunc):
1424
1412
        """Set the mode of new file contents.
1712
1700
    def tree_kind(self, trans_id):
1713
1701
        path = self._tree_id_paths.get(trans_id)
1714
1702
        if path is None:
1715
 
            raise NoSuchFile(None)
 
1703
            return None
1716
1704
        file_id = self._tree.path2id(path)
1717
 
        return self._tree.kind(file_id)
 
1705
        try:
 
1706
            return self._tree.kind(file_id)
 
1707
        except errors.NoSuchFile:
 
1708
            return None
1718
1709
 
1719
1710
    def _set_mode(self, trans_id, mode_id, typefunc):
1720
1711
        """Set the mode of new file contents.