~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transform.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-09-01 18:06:19 UTC
  • mfrom: (5401.1.3 integration)
  • Revision ID: pqm@pqm.ubuntu.com-20100901180619-u0q01om0gjzxxy2i
(vila) Cleanups in bzrlib.transform.py (Vincent Ladeuil)

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
 
397
396
    def final_kind(self, trans_id):
398
397
        """Determine the final file kind, after any changes applied.
399
398
 
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)
 
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)
403
402
        """
404
403
        if trans_id in self._new_contents:
405
404
            return self._new_contents[trans_id]
406
405
        elif trans_id in self._removed_contents:
407
 
            raise NoSuchFile(None)
 
406
            return None
408
407
        else:
409
408
            return self.tree_kind(trans_id)
410
409
 
596
595
        """
597
596
        conflicts = []
598
597
        for trans_id in self._new_id.iterkeys():
599
 
            try:
600
 
                kind = self.final_kind(trans_id)
601
 
            except NoSuchFile:
 
598
            kind = self.final_kind(trans_id)
 
599
            if kind is None:
602
600
                conflicts.append(('versioning no contents', trans_id))
603
601
                continue
604
602
            if not InventoryEntry.versionable_kind(kind):
618
616
            if self.final_file_id(trans_id) is None:
619
617
                conflicts.append(('unversioned executability', trans_id))
620
618
            else:
621
 
                try:
622
 
                    non_file = self.final_kind(trans_id) != "file"
623
 
                except NoSuchFile:
624
 
                    non_file = True
625
 
                if non_file is True:
 
619
                if self.final_kind(trans_id) != "file":
626
620
                    conflicts.append(('non-file executability', trans_id))
627
621
        return conflicts
628
622
 
630
624
        """Check for overwrites (not permitted on Win32)"""
631
625
        conflicts = []
632
626
        for trans_id in self._new_contents:
633
 
            try:
634
 
                self.tree_kind(trans_id)
635
 
            except NoSuchFile:
 
627
            if self.tree_kind(trans_id) is None:
636
628
                continue
637
629
            if trans_id not in self._removed_contents:
638
630
                conflicts.append(('overwrite', trans_id,
652
644
            last_name = None
653
645
            last_trans_id = None
654
646
            for name, trans_id in name_ids:
655
 
                try:
656
 
                    kind = self.final_kind(trans_id)
657
 
                except NoSuchFile:
658
 
                    kind = None
 
647
                kind = self.final_kind(trans_id)
659
648
                file_id = self.final_file_id(trans_id)
660
649
                if kind is None and file_id is None:
661
650
                    continue
687
676
                continue
688
677
            if not self._any_contents(children):
689
678
                continue
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
 
679
            kind = self.final_kind(parent_id)
699
680
            if kind is None:
700
681
                conflicts.append(('missing parent', parent_id))
701
682
            elif kind != "directory":
705
686
    def _any_contents(self, trans_ids):
706
687
        """Return true if any of the trans_ids, will have contents."""
707
688
        for trans_id in trans_ids:
708
 
            try:
709
 
                kind = self.final_kind(trans_id)
710
 
            except NoSuchFile:
711
 
                continue
712
 
            return True
 
689
            if self.final_kind(trans_id) is not None:
 
690
                return True
713
691
        return False
714
692
 
715
693
    def _set_executability(self, path, trans_id):
845
823
        Return a (name, parent, kind, executable) tuple
846
824
        """
847
825
        to_name = self.final_name(to_trans_id)
848
 
        try:
849
 
            to_kind = self.final_kind(to_trans_id)
850
 
        except NoSuchFile:
851
 
            to_kind = None
 
826
        to_kind = self.final_kind(to_trans_id)
852
827
        to_parent = self.final_file_id(self.final_parent(to_trans_id))
853
828
        if to_trans_id in self._new_executability:
854
829
            to_executable = self._new_executability[to_trans_id]
1419
1394
    def tree_kind(self, trans_id):
1420
1395
        """Determine the file kind in the working tree.
1421
1396
 
1422
 
        Raises NoSuchFile if the file does not exist
 
1397
        :returns: The file kind or None if the file does not exist
1423
1398
        """
1424
1399
        path = self._tree_id_paths.get(trans_id)
1425
1400
        if path is None:
1426
 
            raise NoSuchFile(None)
 
1401
            return None
1427
1402
        try:
1428
1403
            return file_kind(self._tree.abspath(path))
1429
 
        except OSError, e:
1430
 
            if e.errno != errno.ENOENT:
1431
 
                raise
1432
 
            else:
1433
 
                raise NoSuchFile(path)
 
1404
        except errors.NoSuchFile:
 
1405
            return None
1434
1406
 
1435
1407
    def _set_mode(self, trans_id, mode_id, typefunc):
1436
1408
        """Set the mode of new file contents.
1605
1577
                if file_id is None:
1606
1578
                    continue
1607
1579
                needs_entry = False
1608
 
                try:
1609
 
                    kind = self.final_kind(trans_id)
1610
 
                except NoSuchFile:
 
1580
                kind = self.final_kind(trans_id)
 
1581
                if kind is None:
1611
1582
                    kind = self._tree.stored_kind(file_id)
1612
1583
                parent_trans_id = self.final_parent(trans_id)
1613
1584
                parent_file_id = new_path_file_ids.get(parent_trans_id)
1725
1696
    def tree_kind(self, trans_id):
1726
1697
        path = self._tree_id_paths.get(trans_id)
1727
1698
        if path is None:
1728
 
            raise NoSuchFile(None)
 
1699
            return None
1729
1700
        file_id = self._tree.path2id(path)
1730
 
        return self._tree.kind(file_id)
 
1701
        try:
 
1702
            return self._tree.kind(file_id)
 
1703
        except errors.NoSuchFile:
 
1704
            return None
1731
1705
 
1732
1706
    def _set_mode(self, trans_id, mode_id, typefunc):
1733
1707
        """Set the mode of new file contents.
1929
1903
            if (specific_file_ids is not None
1930
1904
                and file_id not in specific_file_ids):
1931
1905
                continue
1932
 
            try:
1933
 
                kind = self._transform.final_kind(trans_id)
1934
 
            except NoSuchFile:
 
1906
            kind = self._transform.final_kind(trans_id)
 
1907
            if kind is None:
1935
1908
                kind = self._transform._tree.stored_kind(file_id)
1936
1909
            new_entry = inventory.make_entry(
1937
1910
                kind,
2169
2142
                path_from_root = self._final_paths.get_path(child_id)
2170
2143
                basename = self._transform.final_name(child_id)
2171
2144
                file_id = self._transform.final_file_id(child_id)
2172
 
                try:
2173
 
                    kind = self._transform.final_kind(child_id)
 
2145
                kind  = self._transform.final_kind(child_id)
 
2146
                if kind is not None:
2174
2147
                    versioned_kind = kind
2175
 
                except NoSuchFile:
 
2148
                else:
2176
2149
                    kind = 'unknown'
2177
2150
                    versioned_kind = self._transform._tree.stored_kind(file_id)
2178
2151
                if versioned_kind == 'directory':