~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transform.py

  • Committer: Parth Malwankar
  • Date: 2010-07-14 08:53:58 UTC
  • mto: (5050.3.7 2.2)
  • mto: This revision was merged to the branch mainline in revision 5365.
  • Revision ID: parth.malwankar@gmail.com-20100714085358-6un4ny0cn908spkq
better error message for RecursiveBind

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
 
        kind = self.tree_kind(trans_id)
319
 
        if kind is not None:
320
 
            self._removed_contents.add(trans_id)
 
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)
321
322
 
322
323
    def cancel_deletion(self, trans_id):
323
324
        """Cancel a scheduled deletion"""
388
389
        changed_kind = set(self._removed_contents)
389
390
        changed_kind.intersection_update(self._new_contents)
390
391
        changed_kind.difference_update(new_ids)
391
 
        changed_kind = (t for t in changed_kind
392
 
                        if self.tree_kind(t) != self.final_kind(t))
 
392
        changed_kind = (t for t in changed_kind if self.tree_kind(t) !=
 
393
                        self.final_kind(t))
393
394
        new_ids.update(changed_kind)
394
395
        return sorted(FinalPaths(self).get_paths(new_ids))
395
396
 
396
397
    def final_kind(self, trans_id):
397
398
        """Determine the final file kind, after any changes applied.
398
399
 
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)
 
400
        Raises NoSuchFile if the file does not exist/has no contents.
 
401
        (It is conceivable that a path would be created without the
 
402
        corresponding contents insertion command)
402
403
        """
403
404
        if trans_id in self._new_contents:
404
405
            return self._new_contents[trans_id]
405
406
        elif trans_id in self._removed_contents:
406
 
            return None
 
407
            raise NoSuchFile(None)
407
408
        else:
408
409
            return self.tree_kind(trans_id)
409
410
 
595
596
        """
596
597
        conflicts = []
597
598
        for trans_id in self._new_id.iterkeys():
598
 
            kind = self.final_kind(trans_id)
599
 
            if kind is None:
 
599
            try:
 
600
                kind = self.final_kind(trans_id)
 
601
            except NoSuchFile:
600
602
                conflicts.append(('versioning no contents', trans_id))
601
603
                continue
602
604
            if not InventoryEntry.versionable_kind(kind):
616
618
            if self.final_file_id(trans_id) is None:
617
619
                conflicts.append(('unversioned executability', trans_id))
618
620
            else:
619
 
                if self.final_kind(trans_id) != "file":
 
621
                try:
 
622
                    non_file = self.final_kind(trans_id) != "file"
 
623
                except NoSuchFile:
 
624
                    non_file = True
 
625
                if non_file is True:
620
626
                    conflicts.append(('non-file executability', trans_id))
621
627
        return conflicts
622
628
 
624
630
        """Check for overwrites (not permitted on Win32)"""
625
631
        conflicts = []
626
632
        for trans_id in self._new_contents:
627
 
            if self.tree_kind(trans_id) is None:
 
633
            try:
 
634
                self.tree_kind(trans_id)
 
635
            except NoSuchFile:
628
636
                continue
629
637
            if trans_id not in self._removed_contents:
630
638
                conflicts.append(('overwrite', trans_id,
644
652
            last_name = None
645
653
            last_trans_id = None
646
654
            for name, trans_id in name_ids:
647
 
                kind = self.final_kind(trans_id)
 
655
                try:
 
656
                    kind = self.final_kind(trans_id)
 
657
                except NoSuchFile:
 
658
                    kind = None
648
659
                file_id = self.final_file_id(trans_id)
649
660
                if kind is None and file_id is None:
650
661
                    continue
676
687
                continue
677
688
            if not self._any_contents(children):
678
689
                continue
679
 
            kind = self.final_kind(parent_id)
 
690
            for child in children:
 
691
                try:
 
692
                    self.final_kind(child)
 
693
                except NoSuchFile:
 
694
                    continue
 
695
            try:
 
696
                kind = self.final_kind(parent_id)
 
697
            except NoSuchFile:
 
698
                kind = None
680
699
            if kind is None:
681
700
                conflicts.append(('missing parent', parent_id))
682
701
            elif kind != "directory":
686
705
    def _any_contents(self, trans_ids):
687
706
        """Return true if any of the trans_ids, will have contents."""
688
707
        for trans_id in trans_ids:
689
 
            if self.final_kind(trans_id) is not None:
690
 
                return True
 
708
            try:
 
709
                kind = self.final_kind(trans_id)
 
710
            except NoSuchFile:
 
711
                continue
 
712
            return True
691
713
        return False
692
714
 
693
715
    def _set_executability(self, path, trans_id):
823
845
        Return a (name, parent, kind, executable) tuple
824
846
        """
825
847
        to_name = self.final_name(to_trans_id)
826
 
        to_kind = self.final_kind(to_trans_id)
 
848
        try:
 
849
            to_kind = self.final_kind(to_trans_id)
 
850
        except NoSuchFile:
 
851
            to_kind = None
827
852
        to_parent = self.final_file_id(self.final_parent(to_trans_id))
828
853
        if to_trans_id in self._new_executability:
829
854
            to_executable = self._new_executability[to_trans_id]
1157
1182
            if trans_id not in self._new_contents:
1158
1183
                continue
1159
1184
            new_path = self._limbo_name(trans_id)
1160
 
            os.rename(old_path, new_path)
 
1185
            osutils.rename(old_path, new_path)
1161
1186
            for descendant in self._limbo_descendants(trans_id):
1162
1187
                desc_path = self._limbo_files[descendant]
1163
1188
                desc_path = new_path + desc_path[len(old_path):]
1394
1419
    def tree_kind(self, trans_id):
1395
1420
        """Determine the file kind in the working tree.
1396
1421
 
1397
 
        :returns: The file kind or None if the file does not exist
 
1422
        Raises NoSuchFile if the file does not exist
1398
1423
        """
1399
1424
        path = self._tree_id_paths.get(trans_id)
1400
1425
        if path is None:
1401
 
            return None
 
1426
            raise NoSuchFile(None)
1402
1427
        try:
1403
1428
            return file_kind(self._tree.abspath(path))
1404
 
        except errors.NoSuchFile:
1405
 
            return None
 
1429
        except OSError, e:
 
1430
            if e.errno != errno.ENOENT:
 
1431
                raise
 
1432
            else:
 
1433
                raise NoSuchFile(path)
1406
1434
 
1407
1435
    def _set_mode(self, trans_id, mode_id, typefunc):
1408
1436
        """Set the mode of new file contents.
1577
1605
                if file_id is None:
1578
1606
                    continue
1579
1607
                needs_entry = False
1580
 
                kind = self.final_kind(trans_id)
1581
 
                if kind is None:
 
1608
                try:
 
1609
                    kind = self.final_kind(trans_id)
 
1610
                except NoSuchFile:
1582
1611
                    kind = self._tree.stored_kind(file_id)
1583
1612
                parent_trans_id = self.final_parent(trans_id)
1584
1613
                parent_file_id = new_path_file_ids.get(parent_trans_id)
1696
1725
    def tree_kind(self, trans_id):
1697
1726
        path = self._tree_id_paths.get(trans_id)
1698
1727
        if path is None:
1699
 
            return None
 
1728
            raise NoSuchFile(None)
1700
1729
        file_id = self._tree.path2id(path)
1701
 
        try:
1702
 
            return self._tree.kind(file_id)
1703
 
        except errors.NoSuchFile:
1704
 
            return None
 
1730
        return self._tree.kind(file_id)
1705
1731
 
1706
1732
    def _set_mode(self, trans_id, mode_id, typefunc):
1707
1733
        """Set the mode of new file contents.
1903
1929
            if (specific_file_ids is not None
1904
1930
                and file_id not in specific_file_ids):
1905
1931
                continue
1906
 
            kind = self._transform.final_kind(trans_id)
1907
 
            if kind is None:
 
1932
            try:
 
1933
                kind = self._transform.final_kind(trans_id)
 
1934
            except NoSuchFile:
1908
1935
                kind = self._transform._tree.stored_kind(file_id)
1909
1936
            new_entry = inventory.make_entry(
1910
1937
                kind,
2142
2169
                path_from_root = self._final_paths.get_path(child_id)
2143
2170
                basename = self._transform.final_name(child_id)
2144
2171
                file_id = self._transform.final_file_id(child_id)
2145
 
                kind  = self._transform.final_kind(child_id)
2146
 
                if kind is not None:
 
2172
                try:
 
2173
                    kind = self._transform.final_kind(child_id)
2147
2174
                    versioned_kind = kind
2148
 
                else:
 
2175
                except NoSuchFile:
2149
2176
                    kind = 'unknown'
2150
2177
                    versioned_kind = self._transform._tree.stored_kind(file_id)
2151
2178
                if versioned_kind == 'directory':
2502
2529
        raise errors.BadFileKindError(name, kind)
2503
2530
 
2504
2531
 
 
2532
@deprecated_function(deprecated_in((1, 9, 0)))
 
2533
def create_by_entry(tt, entry, tree, trans_id, lines=None, mode_id=None):
 
2534
    """Create new file contents according to an inventory entry.
 
2535
 
 
2536
    DEPRECATED.  Use create_from_tree instead.
 
2537
    """
 
2538
    if entry.kind == "file":
 
2539
        if lines is None:
 
2540
            lines = tree.get_file(entry.file_id).readlines()
 
2541
        tt.create_file(lines, trans_id, mode_id=mode_id)
 
2542
    elif entry.kind == "symlink":
 
2543
        tt.create_symlink(tree.get_symlink_target(entry.file_id), trans_id)
 
2544
    elif entry.kind == "directory":
 
2545
        tt.create_directory(trans_id)
 
2546
 
 
2547
 
2505
2548
def create_from_tree(tt, trans_id, tree, file_id, bytes=None,
2506
2549
    filter_tree_path=None):
2507
2550
    """Create new file contents according to tree contents.
2892
2935
    def rename(self, from_, to):
2893
2936
        """Rename a file from one path to another."""
2894
2937
        try:
2895
 
            os.rename(from_, to)
2896
 
        except OSError, e:
 
2938
            osutils.rename(from_, to)
 
2939
        except (IOError, OSError), e:
2897
2940
            if e.errno in (errno.EEXIST, errno.ENOTEMPTY):
2898
2941
                raise errors.FileExists(to, str(e))
2899
2942
            # normal OSError doesn't include filenames so it's hard to see where
2915
2958
        """Reverse all renames that have been performed"""
2916
2959
        for from_, to in reversed(self.past_renames):
2917
2960
            try:
2918
 
                os.rename(to, from_)
2919
 
            except OSError, e:
 
2961
                osutils.rename(to, from_)
 
2962
            except (OSError, IOError), e:
2920
2963
                raise errors.TransformRenameFailed(to, from_, str(e), e.errno)                
2921
2964
        # after rollback, don't reuse _FileMover
2922
2965
        past_renames = None