~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transform.py

(gz) Never raise KnownFailure in tests,
 use knownFailure method instead (Martin [gz])

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
from bzrlib import (
31
31
    annotate,
32
32
    bencode,
33
 
    controldir,
 
33
    bzrdir,
34
34
    commit,
35
35
    conflicts,
36
36
    delta,
 
37
    errors,
37
38
    inventory,
38
39
    multiparent,
39
40
    osutils,
41
42
    ui,
42
43
    urlutils,
43
44
    )
44
 
from bzrlib.i18n import gettext
45
45
""")
46
 
from bzrlib.errors import (DuplicateKey, MalformedTransform,
 
46
from bzrlib.errors import (DuplicateKey, MalformedTransform, NoSuchFile,
47
47
                           ReusingTransform, CantMoveRoot,
48
48
                           ExistingLimbo, ImmortalLimbo, NoFinalPath,
49
49
                           UnableCreateSymlink)
561
561
        for trans_id in self._removed_id:
562
562
            file_id = self.tree_file_id(trans_id)
563
563
            if file_id is not None:
564
 
                if self._tree.stored_kind(file_id) == 'directory':
 
564
                # XXX: This seems like something that should go via a different
 
565
                #      indirection.
 
566
                if self._tree.inventory[file_id].kind == 'directory':
565
567
                    parents.append(trans_id)
566
568
            elif self.tree_kind(trans_id) == 'directory':
567
569
                parents.append(trans_id)
776
778
                    to_mode |= 0010 & ~umask
777
779
            else:
778
780
                to_mode = current_mode & ~0111
779
 
            osutils.chmod_if_possible(abspath, to_mode)
 
781
            os.chmod(abspath, to_mode)
780
782
 
781
783
    def _new_entry(self, name, parent_id, file_id):
782
784
        """Helper function to create a new filesystem entry."""
1555
1557
        try:
1556
1558
            limbodir = urlutils.local_path_from_url(
1557
1559
                tree._transport.abspath('limbo'))
1558
 
            osutils.ensure_empty_directory_exists(
1559
 
                limbodir,
1560
 
                errors.ExistingLimbo)
 
1560
            try:
 
1561
                os.mkdir(limbodir)
 
1562
            except OSError, e:
 
1563
                if e.errno == errno.EEXIST:
 
1564
                    raise ExistingLimbo(limbodir)
1561
1565
            deletiondir = urlutils.local_path_from_url(
1562
1566
                tree._transport.abspath('pending-deletion'))
1563
 
            osutils.ensure_empty_directory_exists(
1564
 
                deletiondir,
1565
 
                errors.ExistingPendingDeletion)
 
1567
            try:
 
1568
                os.mkdir(deletiondir)
 
1569
            except OSError, e:
 
1570
                if e.errno == errno.EEXIST:
 
1571
                    raise errors.ExistingPendingDeletion(deletiondir)
1566
1572
        except:
1567
1573
            tree.unlock()
1568
1574
            raise
1631
1637
            else:
1632
1638
                raise
1633
1639
        if typefunc(mode):
1634
 
            osutils.chmod_if_possible(self._limbo_name(trans_id), mode)
 
1640
            os.chmod(self._limbo_name(trans_id), mode)
1635
1641
 
1636
1642
    def iter_tree_children(self, parent_id):
1637
1643
        """Iterate through the entry's tree children, if any"""
1720
1726
        child_pb = ui.ui_factory.nested_progress_bar()
1721
1727
        try:
1722
1728
            if precomputed_delta is None:
1723
 
                child_pb.update(gettext('Apply phase'), 0, 2)
 
1729
                child_pb.update('Apply phase', 0, 2)
1724
1730
                inventory_delta = self._generate_inventory_delta()
1725
1731
                offset = 1
1726
1732
            else:
1731
1737
            else:
1732
1738
                mover = _mover
1733
1739
            try:
1734
 
                child_pb.update(gettext('Apply phase'), 0 + offset, 2 + offset)
 
1740
                child_pb.update('Apply phase', 0 + offset, 2 + offset)
1735
1741
                self._apply_removals(mover)
1736
 
                child_pb.update(gettext('Apply phase'), 1 + offset, 2 + offset)
 
1742
                child_pb.update('Apply phase', 1 + offset, 2 + offset)
1737
1743
                modified_paths = self._apply_insertions(mover)
1738
1744
            except:
1739
1745
                mover.rollback()
1759
1765
        try:
1760
1766
            for num, trans_id in enumerate(self._removed_id):
1761
1767
                if (num % 10) == 0:
1762
 
                    child_pb.update(gettext('removing file'), num, total_entries)
 
1768
                    child_pb.update('removing file', num, total_entries)
1763
1769
                if trans_id == self._new_root:
1764
1770
                    file_id = self._tree.get_root_id()
1765
1771
                else:
1777
1783
            final_kinds = {}
1778
1784
            for num, (path, trans_id) in enumerate(new_paths):
1779
1785
                if (num % 10) == 0:
1780
 
                    child_pb.update(gettext('adding file'),
 
1786
                    child_pb.update('adding file',
1781
1787
                                    num + len(self._removed_id), total_entries)
1782
1788
                file_id = new_path_file_ids[trans_id]
1783
1789
                if file_id is None:
1827
1833
                # do not attempt to move root into a subdirectory of itself.
1828
1834
                if path == '':
1829
1835
                    continue
1830
 
                child_pb.update(gettext('removing file'), num, len(tree_paths))
 
1836
                child_pb.update('removing file', num, len(tree_paths))
1831
1837
                full_path = self._tree.abspath(path)
1832
1838
                if trans_id in self._removed_contents:
1833
1839
                    delete_path = os.path.join(self._deletiondir, trans_id)
1862
1868
        try:
1863
1869
            for num, (path, trans_id) in enumerate(new_paths):
1864
1870
                if (num % 10) == 0:
1865
 
                    child_pb.update(gettext('adding file'), num, len(new_paths))
 
1871
                    child_pb.update('adding file', num, len(new_paths))
1866
1872
                full_path = self._tree.abspath(path)
1867
1873
                if trans_id in self._needs_rename:
1868
1874
                    try:
2540
2546
    file_trans_id = {}
2541
2547
    top_pb = ui.ui_factory.nested_progress_bar()
2542
2548
    pp = ProgressPhase("Build phase", 2, top_pb)
2543
 
    if tree.get_root_id() is not None:
 
2549
    if tree.inventory.root is not None:
2544
2550
        # This is kind of a hack: we should be altering the root
2545
2551
        # as part of the regular tree shape diff logic.
2546
2552
        # The conditional test here is to avoid doing an
2561
2567
        try:
2562
2568
            deferred_contents = []
2563
2569
            num = 0
2564
 
            total = len(tree.all_file_ids())
 
2570
            total = len(tree.inventory)
2565
2571
            if delta_from_tree:
2566
2572
                precomputed_delta = []
2567
2573
            else:
2576
2582
                for dir, files in wt.walkdirs():
2577
2583
                    existing_files.update(f[0] for f in files)
2578
2584
            for num, (tree_path, entry) in \
2579
 
                enumerate(tree.iter_entries_by_dir()):
2580
 
                pb.update(gettext("Building tree"), num - len(deferred_contents), total)
 
2585
                enumerate(tree.inventory.iter_entries_by_dir()):
 
2586
                pb.update("Building tree", num - len(deferred_contents), total)
2581
2587
                if entry.parent_id is None:
2582
2588
                    continue
2583
2589
                reparent = False
2589
2595
                    kind = file_kind(target_path)
2590
2596
                    if kind == "directory":
2591
2597
                        try:
2592
 
                            controldir.ControlDir.open(target_path)
 
2598
                            bzrdir.BzrDir.open(target_path)
2593
2599
                        except errors.NotBranchError:
2594
2600
                            pass
2595
2601
                        else:
2667
2673
                new_desired_files.append((file_id,
2668
2674
                    (trans_id, tree_path, text_sha1)))
2669
2675
                continue
2670
 
            pb.update(gettext('Adding file contents'), count + offset, total)
 
2676
            pb.update('Adding file contents', count + offset, total)
2671
2677
            if hardlink:
2672
2678
                tt.create_hardlink(accelerator_tree.abspath(accelerator_path),
2673
2679
                                   trans_id)
2694
2700
            contents = filtered_output_bytes(contents, filters,
2695
2701
                ContentFilterContext(tree_path, tree))
2696
2702
        tt.create_file(contents, trans_id, sha1=text_sha1)
2697
 
        pb.update(gettext('Adding file contents'), count + offset, total)
 
2703
        pb.update('Adding file contents', count + offset, total)
2698
2704
 
2699
2705
 
2700
2706
def _reparent_children(tt, old_parent, new_parent):
2832
2838
            return new_name
2833
2839
 
2834
2840
 
 
2841
def _entry_changes(file_id, entry, working_tree):
 
2842
    """Determine in which ways the inventory entry has changed.
 
2843
 
 
2844
    Returns booleans: has_contents, content_mod, meta_mod
 
2845
    has_contents means there are currently contents, but they differ
 
2846
    contents_mod means contents need to be modified
 
2847
    meta_mod means the metadata needs to be modified
 
2848
    """
 
2849
    cur_entry = working_tree.inventory[file_id]
 
2850
    try:
 
2851
        working_kind = working_tree.kind(file_id)
 
2852
        has_contents = True
 
2853
    except NoSuchFile:
 
2854
        has_contents = False
 
2855
        contents_mod = True
 
2856
        meta_mod = False
 
2857
    if has_contents is True:
 
2858
        if entry.kind != working_kind:
 
2859
            contents_mod, meta_mod = True, False
 
2860
        else:
 
2861
            cur_entry._read_tree_state(working_tree.id2path(file_id),
 
2862
                                       working_tree)
 
2863
            contents_mod, meta_mod = entry.detect_changes(cur_entry)
 
2864
            cur_entry._forget_tree_state()
 
2865
    return has_contents, contents_mod, meta_mod
 
2866
 
 
2867
 
2835
2868
def revert(working_tree, target_tree, filenames, backups=False,
2836
2869
           pb=None, change_reporter=None):
2837
2870
    """Revert a working tree's contents to those of a target tree."""
3014
3047
    pb = ui.ui_factory.nested_progress_bar()
3015
3048
    try:
3016
3049
        for n in range(10):
3017
 
            pb.update(gettext('Resolution pass'), n+1, 10)
 
3050
            pb.update('Resolution pass', n+1, 10)
3018
3051
            conflicts = tt.find_conflicts()
3019
3052
            if len(conflicts) == 0:
3020
3053
                return new_conflicts
3044
3077
                existing_file, new_file = conflict[2], conflict[1]
3045
3078
            else:
3046
3079
                existing_file, new_file = conflict[1], conflict[2]
3047
 
            new_name = tt.final_name(existing_file) + '.moved'
 
3080
            new_name = tt.final_name(existing_file)+'.moved'
3048
3081
            tt.adjust_path(new_name, final_parent, existing_file)
3049
3082
            new_conflicts.add((c_type, 'Moved existing file to',
3050
3083
                               existing_file, new_file))