~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transform.py

  • Committer: John Arbash Meinel
  • Date: 2010-02-17 17:11:16 UTC
  • mfrom: (4797.2.17 2.1)
  • mto: (4797.2.18 2.1)
  • mto: This revision was merged to the branch mainline in revision 5055.
  • Revision ID: john@arbash-meinel.com-20100217171116-h7t9223ystbnx5h8
merge bzr.2.1 in preparation for NEWS entry.

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
    multiparent,
32
32
    osutils,
33
33
    revision as _mod_revision,
34
 
    ui,
35
34
    )
36
35
""")
37
36
from bzrlib.errors import (DuplicateKey, MalformedTransform, NoSuchFile,
38
 
                           ReusingTransform, CantMoveRoot,
 
37
                           ReusingTransform, NotVersionedError, CantMoveRoot,
39
38
                           ExistingLimbo, ImmortalLimbo, NoFinalPath,
40
39
                           UnableCreateSymlink)
41
40
from bzrlib.filters import filtered_output_bytes, ContentFilterContext
50
49
    splitpath,
51
50
    supports_executable,
52
51
)
53
 
from bzrlib.progress import ProgressPhase
 
52
from bzrlib.progress import DummyProgress, ProgressPhase
54
53
from bzrlib.symbol_versioning import (
55
54
        deprecated_function,
56
55
        deprecated_in,
80
79
class TreeTransformBase(object):
81
80
    """The base class for TreeTransform and its kin."""
82
81
 
83
 
    def __init__(self, tree, pb=None,
 
82
    def __init__(self, tree, pb=DummyProgress(),
84
83
                 case_sensitive=True):
85
84
        """Constructor.
86
85
 
87
86
        :param tree: The tree that will be transformed, but not necessarily
88
87
            the output tree.
89
 
        :param pb: ignored
 
88
        :param pb: A ProgressTask indicating how much progress is being made
90
89
        :param case_sensitive: If True, the target of the transform is
91
90
            case sensitive, not just case preserving.
92
91
        """
1063
1062
class DiskTreeTransform(TreeTransformBase):
1064
1063
    """Tree transform storing its contents on disk."""
1065
1064
 
1066
 
    def __init__(self, tree, limbodir, pb=None,
 
1065
    def __init__(self, tree, limbodir, pb=DummyProgress(),
1067
1066
                 case_sensitive=True):
1068
1067
        """Constructor.
1069
1068
        :param tree: The tree that will be transformed, but not necessarily
1070
1069
            the output tree.
1071
1070
        :param limbodir: A directory where new files can be stored until
1072
1071
            they are installed in their proper places
1073
 
        :param pb: ignored
 
1072
        :param pb: A ProgressBar indicating how much progress is being made
1074
1073
        :param case_sensitive: If True, the target of the transform is
1075
1074
            case sensitive, not just case preserving.
1076
1075
        """
1160
1159
            if trans_id not in self._new_contents:
1161
1160
                continue
1162
1161
            new_path = self._limbo_name(trans_id)
1163
 
            osutils.rename(old_path, new_path)
 
1162
            os.rename(old_path, new_path)
1164
1163
            for descendant in self._limbo_descendants(trans_id):
1165
1164
                desc_path = self._limbo_files[descendant]
1166
1165
                desc_path = new_path + desc_path[len(old_path):]
1340
1339
    FileMover does not delete files until it is sure that a rollback will not
1341
1340
    happen.
1342
1341
    """
1343
 
    def __init__(self, tree, pb=None):
 
1342
    def __init__(self, tree, pb=DummyProgress()):
1344
1343
        """Note: a tree_write lock is taken on the tree.
1345
1344
 
1346
1345
        Use TreeTransform.finalize() to release the lock (can be omitted if
1692
1691
    unversioned files in the input tree.
1693
1692
    """
1694
1693
 
1695
 
    def __init__(self, tree, pb=None, case_sensitive=True):
 
1694
    def __init__(self, tree, pb=DummyProgress(), case_sensitive=True):
1696
1695
        tree.lock_read()
1697
1696
        limbodir = osutils.mkdtemp(prefix='bzr-limbo-')
1698
1697
        DiskTreeTransform.__init__(self, tree, limbodir, pb, case_sensitive)
1798
1797
            executable = self.is_executable(file_id, path)
1799
1798
        return kind, executable, None
1800
1799
 
1801
 
    def is_locked(self):
1802
 
        return False
1803
 
 
1804
1800
    def lock_read(self):
1805
1801
        # Perhaps in theory, this should lock the TreeTransform?
1806
 
        return self
 
1802
        pass
1807
1803
 
1808
1804
    def unlock(self):
1809
1805
        pass
2593
2589
 
2594
2590
 
2595
2591
def revert(working_tree, target_tree, filenames, backups=False,
2596
 
           pb=None, change_reporter=None):
 
2592
           pb=DummyProgress(), change_reporter=None):
2597
2593
    """Revert a working tree's contents to those of a target tree."""
2598
2594
    target_tree.lock_read()
2599
 
    pb = ui.ui_factory.nested_progress_bar()
2600
2595
    tt = TreeTransform(working_tree, pb)
2601
2596
    try:
2602
2597
        pp = ProgressPhase("Revert phase", 3, pb)
2621
2616
def _prepare_revert_transform(working_tree, target_tree, tt, filenames,
2622
2617
                              backups, pp, basis_tree=None,
2623
2618
                              merge_modified=None):
 
2619
    pp.next_phase()
2624
2620
    child_pb = bzrlib.ui.ui_factory.nested_progress_bar()
2625
2621
    try:
2626
2622
        if merge_modified is None:
2630
2626
                                      merge_modified, basis_tree)
2631
2627
    finally:
2632
2628
        child_pb.finished()
 
2629
    pp.next_phase()
2633
2630
    child_pb = bzrlib.ui.ui_factory.nested_progress_bar()
2634
2631
    try:
2635
2632
        raw_conflicts = resolve_conflicts(tt, child_pb,
2757
2754
    return merge_modified
2758
2755
 
2759
2756
 
2760
 
def resolve_conflicts(tt, pb=None, pass_func=None):
 
2757
def resolve_conflicts(tt, pb=DummyProgress(), pass_func=None):
2761
2758
    """Make many conflict-resolution attempts, but die if they fail"""
2762
2759
    if pass_func is None:
2763
2760
        pass_func = conflict_pass
2764
2761
    new_conflicts = set()
2765
 
    pb = ui.ui_factory.nested_progress_bar()
2766
2762
    try:
2767
2763
        for n in range(10):
2768
2764
            pb.update('Resolution pass', n+1, 10)
2772
2768
            new_conflicts.update(pass_func(tt, conflicts))
2773
2769
        raise MalformedTransform(conflicts=conflicts)
2774
2770
    finally:
2775
 
        pb.finished()
 
2771
        pb.clear()
2776
2772
 
2777
2773
 
2778
2774
def conflict_pass(tt, conflicts, path_tree=None):
2827
2823
                        # special-case the other tree root (move its
2828
2824
                        # children to current root)
2829
2825
                        if entry.parent_id is None:
2830
 
                            create = False
 
2826
                            create=False
2831
2827
                            moved = _reparent_transform_children(
2832
2828
                                tt, trans_id, tt.root)
2833
2829
                            for child in moved:
2901
2897
        self.pending_deletions = []
2902
2898
 
2903
2899
    def rename(self, from_, to):
2904
 
        """Rename a file from one path to another."""
 
2900
        """Rename a file from one path to another.  Functions like os.rename"""
2905
2901
        try:
2906
 
            osutils.rename(from_, to)
 
2902
            os.rename(from_, to)
2907
2903
        except OSError, e:
2908
2904
            if e.errno in (errno.EEXIST, errno.ENOTEMPTY):
2909
2905
                raise errors.FileExists(to, str(e))
2923
2919
    def rollback(self):
2924
2920
        """Reverse all renames that have been performed"""
2925
2921
        for from_, to in reversed(self.past_renames):
2926
 
            osutils.rename(to, from_)
 
2922
            os.rename(to, from_)
2927
2923
        # after rollback, don't reuse _FileMover
2928
2924
        past_renames = None
2929
2925
        pending_deletions = None