/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/transform.py

  • Committer: Vincent Ladeuil
  • Date: 2009-10-06 14:40:37 UTC
  • mto: (4728.1.2 integration)
  • mto: This revision was merged to the branch mainline in revision 4731.
  • Revision ID: v.ladeuil+lp@free.fr-20091006144037-o76rgosv9hj3td0y
Simplify mutable_tree.has_changes() and update call sites.

* bzrlib/workingtree.py:
(WorkingTree.merge_from_branch): Add a force parameter. Replace
the check_basis() call by the corresponding code, taken the new
'force' parameter into account.

* bzrlib/tests/test_status.py:
(TestStatus.make_multiple_pending_tree): Add force=True on
supplementary merges.

* bzrlib/tests/test_reconfigure.py:
(TestReconfigure): Add a test for pending merges.

* bzrlib/tests/test_msgeditor.py:
(MsgEditorTest.make_multiple_pending_tree): Add force=True on
supplementary merges.

* bzrlib/tests/blackbox/test_uncommit.py:
(TestUncommit.test_uncommit_octopus_merge): Add force=True on
supplementary merges.

* bzrlib/send.py:
(send): Use the simplified has_changes(). Fix typo in comment too.

* bzrlib/reconfigure.py:
(Reconfigure._check): Use the simplified has_changes().

* bzrlib/mutabletree.py:
(MutableTree.has_changes): Make the tree parameter optional but
retain it for tests. Add a pending merges check.

* bzrlib/merge.py:
(Merger.ensure_revision_trees, Merger.file_revisions,
Merger.check_basis, Merger.compare_basis): Deprecate.

* bzrlib/bundle/apply_bundle.py:
(merge_bundle): Replace the check_basis() call by the
corresponding code.

* bzrlib/builtins.py:
(cmd_remove_tree.run, cmd_push.run, cmd_merge.run): Use the
simplified has_changes().
(cmd_merge.run): Replace the check_basis call() by the corresponding
code (minus the alredy done has_changes() check).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2006, 2007, 2008, 2009 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
17
17
import os
18
18
import errno
19
19
from stat import S_ISREG, S_IEXEC
20
 
import time
21
20
 
22
21
from bzrlib.lazy_import import lazy_import
23
22
lazy_import(globals(), """
25
24
    annotate,
26
25
    bencode,
27
26
    bzrdir,
28
 
    commit,
29
27
    delta,
30
28
    errors,
31
29
    inventory,
32
30
    multiparent,
33
31
    osutils,
34
32
    revision as _mod_revision,
35
 
    ui,
36
33
    )
37
34
""")
38
35
from bzrlib.errors import (DuplicateKey, MalformedTransform, NoSuchFile,
39
 
                           ReusingTransform, CantMoveRoot,
 
36
                           ReusingTransform, NotVersionedError, CantMoveRoot,
40
37
                           ExistingLimbo, ImmortalLimbo, NoFinalPath,
41
38
                           UnableCreateSymlink)
42
39
from bzrlib.filters import filtered_output_bytes, ContentFilterContext
51
48
    splitpath,
52
49
    supports_executable,
53
50
)
54
 
from bzrlib.progress import ProgressPhase
 
51
from bzrlib.progress import DummyProgress, ProgressPhase
55
52
from bzrlib.symbol_versioning import (
56
53
        deprecated_function,
57
54
        deprecated_in,
81
78
class TreeTransformBase(object):
82
79
    """The base class for TreeTransform and its kin."""
83
80
 
84
 
    def __init__(self, tree, pb=None,
 
81
    def __init__(self, tree, pb=DummyProgress(),
85
82
                 case_sensitive=True):
86
83
        """Constructor.
87
84
 
88
85
        :param tree: The tree that will be transformed, but not necessarily
89
86
            the output tree.
90
 
        :param pb: ignored
 
87
        :param pb: A ProgressTask indicating how much progress is being made
91
88
        :param case_sensitive: If True, the target of the transform is
92
89
            case sensitive, not just case preserving.
93
90
        """
164
161
 
165
162
    def adjust_path(self, name, parent, trans_id):
166
163
        """Change the path that is assigned to a transaction id."""
167
 
        if parent is None:
168
 
            raise ValueError("Parent trans-id may not be None")
169
164
        if trans_id == self._new_root:
170
165
            raise CantMoveRoot
171
166
        self._new_name[trans_id] = name
172
167
        self._new_parent[trans_id] = parent
 
168
        if parent == ROOT_PARENT:
 
169
            if self._new_root is not None:
 
170
                raise ValueError("Cannot have multiple roots.")
 
171
            self._new_root = trans_id
173
172
 
174
173
    def adjust_root_path(self, name, parent):
175
174
        """Emulate moving the root by moving all children, instead.
203
202
        self.version_file(old_root_file_id, old_root)
204
203
        self.unversion_file(self._new_root)
205
204
 
206
 
    def fixup_new_roots(self):
207
 
        """Reinterpret requests to change the root directory
208
 
 
209
 
        Instead of creating a root directory, or moving an existing directory,
210
 
        all the attributes and children of the new root are applied to the
211
 
        existing root directory.
212
 
 
213
 
        This means that the old root trans-id becomes obsolete, so it is
214
 
        recommended only to invoke this after the root trans-id has become
215
 
        irrelevant.
216
 
        """
217
 
        new_roots = [k for k, v in self._new_parent.iteritems() if v is
218
 
                     ROOT_PARENT]
219
 
        if len(new_roots) < 1:
220
 
            return
221
 
        if len(new_roots) != 1:
222
 
            raise ValueError('A tree cannot have two roots!')
223
 
        if self._new_root is None:
224
 
            self._new_root = new_roots[0]
225
 
            return
226
 
        old_new_root = new_roots[0]
227
 
        # TODO: What to do if a old_new_root is present, but self._new_root is
228
 
        #       not listed as being removed? This code explicitly unversions
229
 
        #       the old root and versions it with the new file_id. Though that
230
 
        #       seems like an incomplete delta
231
 
 
232
 
        # unversion the new root's directory.
233
 
        file_id = self.final_file_id(old_new_root)
234
 
        if old_new_root in self._new_id:
235
 
            self.cancel_versioning(old_new_root)
236
 
        else:
237
 
            self.unversion_file(old_new_root)
238
 
        # if, at this stage, root still has an old file_id, zap it so we can
239
 
        # stick a new one in.
240
 
        if (self.tree_file_id(self._new_root) is not None and
241
 
            self._new_root not in self._removed_id):
242
 
            self.unversion_file(self._new_root)
243
 
        self.version_file(file_id, self._new_root)
244
 
 
245
 
        # Now move children of new root into old root directory.
246
 
        # Ensure all children are registered with the transaction, but don't
247
 
        # use directly-- some tree children have new parents
248
 
        list(self.iter_tree_children(old_new_root))
249
 
        # Move all children of new root into old root directory.
250
 
        for child in self.by_parent().get(old_new_root, []):
251
 
            self.adjust_path(self.final_name(child), self._new_root, child)
252
 
 
253
 
        # Ensure old_new_root has no directory.
254
 
        if old_new_root in self._new_contents:
255
 
            self.cancel_creation(old_new_root)
256
 
        else:
257
 
            self.delete_contents(old_new_root)
258
 
 
259
 
        # prevent deletion of root directory.
260
 
        if self._new_root in self._removed_contents:
261
 
            self.cancel_deletion(self._new_root)
262
 
 
263
 
        # destroy path info for old_new_root.
264
 
        del self._new_parent[old_new_root]
265
 
        del self._new_name[old_new_root]
266
 
 
267
205
    def trans_id_tree_file_id(self, inventory_id):
268
206
        """Determine the transaction id of a working tree file.
269
207
 
315
253
 
316
254
    def delete_contents(self, trans_id):
317
255
        """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
256
        self.tree_kind(trans_id)
321
257
        self._removed_contents.add(trans_id)
322
258
 
928
864
        """
929
865
        return _PreviewTree(self)
930
866
 
931
 
    def commit(self, branch, message, merge_parents=None, strict=False,
932
 
               timestamp=None, timezone=None, committer=None, authors=None,
933
 
               revprops=None, revision_id=None):
 
867
    def commit(self, branch, message, merge_parents=None, strict=False):
934
868
        """Commit the result of this TreeTransform to a branch.
935
869
 
936
870
        :param branch: The branch to commit to.
937
871
        :param message: The message to attach to the commit.
938
 
        :param merge_parents: Additional parent revision-ids specified by
939
 
            pending merges.
940
 
        :param strict: If True, abort the commit if there are unversioned
941
 
            files.
942
 
        :param timestamp: if not None, seconds-since-epoch for the time and
943
 
            date.  (May be a float.)
944
 
        :param timezone: Optional timezone for timestamp, as an offset in
945
 
            seconds.
946
 
        :param committer: Optional committer in email-id format.
947
 
            (e.g. "J Random Hacker <jrandom@example.com>")
948
 
        :param authors: Optional list of authors in email-id format.
949
 
        :param revprops: Optional dictionary of revision properties.
950
 
        :param revision_id: Optional revision id.  (Specifying a revision-id
951
 
            may reduce performance for some non-native formats.)
 
872
        :param merge_parents: Additional parents specified by pending merges.
952
873
        :return: The revision_id of the revision committed.
953
874
        """
954
875
        self._check_malformed()
971
892
        if self._tree.get_revision_id() != last_rev_id:
972
893
            raise ValueError('TreeTransform not based on branch basis: %s' %
973
894
                             self._tree.get_revision_id())
974
 
        revprops = commit.Commit.update_revprops(revprops, branch, authors)
975
 
        builder = branch.get_commit_builder(parent_ids,
976
 
                                            timestamp=timestamp,
977
 
                                            timezone=timezone,
978
 
                                            committer=committer,
979
 
                                            revprops=revprops,
980
 
                                            revision_id=revision_id)
 
895
        builder = branch.get_commit_builder(parent_ids)
981
896
        preview = self.get_preview_tree()
982
897
        list(builder.record_iter_changes(preview, last_rev_id,
983
898
                                         self.iter_changes()))
1085
1000
class DiskTreeTransform(TreeTransformBase):
1086
1001
    """Tree transform storing its contents on disk."""
1087
1002
 
1088
 
    def __init__(self, tree, limbodir, pb=None,
 
1003
    def __init__(self, tree, limbodir, pb=DummyProgress(),
1089
1004
                 case_sensitive=True):
1090
1005
        """Constructor.
1091
1006
        :param tree: The tree that will be transformed, but not necessarily
1092
1007
            the output tree.
1093
1008
        :param limbodir: A directory where new files can be stored until
1094
1009
            they are installed in their proper places
1095
 
        :param pb: ignored
 
1010
        :param pb: A ProgressBar indicating how much progress is being made
1096
1011
        :param case_sensitive: If True, the target of the transform is
1097
1012
            case sensitive, not just case preserving.
1098
1013
        """
1108
1023
        self._limbo_children_names = {}
1109
1024
        # List of transform ids that need to be renamed from limbo into place
1110
1025
        self._needs_rename = set()
1111
 
        self._creation_mtime = None
1112
1026
 
1113
1027
    def finalize(self):
1114
1028
        """Release the working tree lock, if held, clean up limbo dir.
1140
1054
    def _limbo_name(self, trans_id):
1141
1055
        """Generate the limbo name of a file"""
1142
1056
        limbo_name = self._limbo_files.get(trans_id)
1143
 
        if limbo_name is None:
1144
 
            limbo_name = self._generate_limbo_path(trans_id)
1145
 
            self._limbo_files[trans_id] = limbo_name
 
1057
        if limbo_name is not None:
 
1058
            return limbo_name
 
1059
        parent = self._new_parent.get(trans_id)
 
1060
        # if the parent directory is already in limbo (e.g. when building a
 
1061
        # tree), choose a limbo name inside the parent, to reduce further
 
1062
        # renames.
 
1063
        use_direct_path = False
 
1064
        if self._new_contents.get(parent) == 'directory':
 
1065
            filename = self._new_name.get(trans_id)
 
1066
            if filename is not None:
 
1067
                if parent not in self._limbo_children:
 
1068
                    self._limbo_children[parent] = set()
 
1069
                    self._limbo_children_names[parent] = {}
 
1070
                    use_direct_path = True
 
1071
                # the direct path can only be used if no other file has
 
1072
                # already taken this pathname, i.e. if the name is unused, or
 
1073
                # if it is already associated with this trans_id.
 
1074
                elif self._case_sensitive_target:
 
1075
                    if (self._limbo_children_names[parent].get(filename)
 
1076
                        in (trans_id, None)):
 
1077
                        use_direct_path = True
 
1078
                else:
 
1079
                    for l_filename, l_trans_id in\
 
1080
                        self._limbo_children_names[parent].iteritems():
 
1081
                        if l_trans_id == trans_id:
 
1082
                            continue
 
1083
                        if l_filename.lower() == filename.lower():
 
1084
                            break
 
1085
                    else:
 
1086
                        use_direct_path = True
 
1087
 
 
1088
        if use_direct_path:
 
1089
            limbo_name = pathjoin(self._limbo_files[parent], filename)
 
1090
            self._limbo_children[parent].add(trans_id)
 
1091
            self._limbo_children_names[parent][filename] = trans_id
 
1092
        else:
 
1093
            limbo_name = pathjoin(self._limbodir, trans_id)
 
1094
            self._needs_rename.add(trans_id)
 
1095
        self._limbo_files[trans_id] = limbo_name
1146
1096
        return limbo_name
1147
1097
 
1148
 
    def _generate_limbo_path(self, trans_id):
1149
 
        """Generate a limbo path using the trans_id as the relative path.
1150
 
 
1151
 
        This is suitable as a fallback, and when the transform should not be
1152
 
        sensitive to the path encoding of the limbo directory.
1153
 
        """
1154
 
        self._needs_rename.add(trans_id)
1155
 
        return pathjoin(self._limbodir, trans_id)
1156
 
 
1157
1098
    def adjust_path(self, name, parent, trans_id):
1158
1099
        previous_parent = self._new_parent.get(trans_id)
1159
1100
        previous_name = self._new_name.get(trans_id)
1161
1102
        if (trans_id in self._limbo_files and
1162
1103
            trans_id not in self._needs_rename):
1163
1104
            self._rename_in_limbo([trans_id])
1164
 
            if previous_parent != parent:
1165
 
                self._limbo_children[previous_parent].remove(trans_id)
1166
 
            if previous_parent != parent or previous_name != name:
1167
 
                del self._limbo_children_names[previous_parent][previous_name]
 
1105
            self._limbo_children[previous_parent].remove(trans_id)
 
1106
            del self._limbo_children_names[previous_parent][previous_name]
1168
1107
 
1169
1108
    def _rename_in_limbo(self, trans_ids):
1170
1109
        """Fix limbo names so that the right final path is produced.
1182
1121
            if trans_id not in self._new_contents:
1183
1122
                continue
1184
1123
            new_path = self._limbo_name(trans_id)
1185
 
            osutils.rename(old_path, new_path)
1186
 
            for descendant in self._limbo_descendants(trans_id):
1187
 
                desc_path = self._limbo_files[descendant]
1188
 
                desc_path = new_path + desc_path[len(old_path):]
1189
 
                self._limbo_files[descendant] = desc_path
1190
 
 
1191
 
    def _limbo_descendants(self, trans_id):
1192
 
        """Return the set of trans_ids whose limbo paths descend from this."""
1193
 
        descendants = set(self._limbo_children.get(trans_id, []))
1194
 
        for descendant in list(descendants):
1195
 
            descendants.update(self._limbo_descendants(descendant))
1196
 
        return descendants
 
1124
            os.rename(old_path, new_path)
1197
1125
 
1198
1126
    def create_file(self, contents, trans_id, mode_id=None):
1199
1127
        """Schedule creation of a new file.
1221
1149
            f.writelines(contents)
1222
1150
        finally:
1223
1151
            f.close()
1224
 
        self._set_mtime(name)
1225
1152
        self._set_mode(trans_id, mode_id, S_ISREG)
1226
1153
 
1227
1154
    def _read_file_chunks(self, trans_id):
1234
1161
    def _read_symlink_target(self, trans_id):
1235
1162
        return os.readlink(self._limbo_name(trans_id))
1236
1163
 
1237
 
    def _set_mtime(self, path):
1238
 
        """All files that are created get the same mtime.
1239
 
 
1240
 
        This time is set by the first object to be created.
1241
 
        """
1242
 
        if self._creation_mtime is None:
1243
 
            self._creation_mtime = time.time()
1244
 
        os.utime(path, (self._creation_mtime, self._creation_mtime))
1245
 
 
1246
1164
    def create_hardlink(self, path, trans_id):
1247
1165
        """Schedule creation of a hard link"""
1248
1166
        name = self._limbo_name(trans_id)
1362
1280
    FileMover does not delete files until it is sure that a rollback will not
1363
1281
    happen.
1364
1282
    """
1365
 
    def __init__(self, tree, pb=None):
 
1283
    def __init__(self, tree, pb=DummyProgress()):
1366
1284
        """Note: a tree_write lock is taken on the tree.
1367
1285
 
1368
1286
        Use TreeTransform.finalize() to release the lock (can be omitted if
1478
1396
                continue
1479
1397
            yield self.trans_id_tree_path(childpath)
1480
1398
 
1481
 
    def _generate_limbo_path(self, trans_id):
1482
 
        """Generate a limbo path using the final path if possible.
1483
 
 
1484
 
        This optimizes the performance of applying the tree transform by
1485
 
        avoiding renames.  These renames can be avoided only when the parent
1486
 
        directory is already scheduled for creation.
1487
 
 
1488
 
        If the final path cannot be used, falls back to using the trans_id as
1489
 
        the relpath.
1490
 
        """
1491
 
        parent = self._new_parent.get(trans_id)
1492
 
        # if the parent directory is already in limbo (e.g. when building a
1493
 
        # tree), choose a limbo name inside the parent, to reduce further
1494
 
        # renames.
1495
 
        use_direct_path = False
1496
 
        if self._new_contents.get(parent) == 'directory':
1497
 
            filename = self._new_name.get(trans_id)
1498
 
            if filename is not None:
1499
 
                if parent not in self._limbo_children:
1500
 
                    self._limbo_children[parent] = set()
1501
 
                    self._limbo_children_names[parent] = {}
1502
 
                    use_direct_path = True
1503
 
                # the direct path can only be used if no other file has
1504
 
                # already taken this pathname, i.e. if the name is unused, or
1505
 
                # if it is already associated with this trans_id.
1506
 
                elif self._case_sensitive_target:
1507
 
                    if (self._limbo_children_names[parent].get(filename)
1508
 
                        in (trans_id, None)):
1509
 
                        use_direct_path = True
1510
 
                else:
1511
 
                    for l_filename, l_trans_id in\
1512
 
                        self._limbo_children_names[parent].iteritems():
1513
 
                        if l_trans_id == trans_id:
1514
 
                            continue
1515
 
                        if l_filename.lower() == filename.lower():
1516
 
                            break
1517
 
                    else:
1518
 
                        use_direct_path = True
1519
 
 
1520
 
        if not use_direct_path:
1521
 
            return DiskTreeTransform._generate_limbo_path(self, trans_id)
1522
 
 
1523
 
        limbo_name = pathjoin(self._limbo_files[parent], filename)
1524
 
        self._limbo_children[parent].add(trans_id)
1525
 
        self._limbo_children_names[parent][filename] = trans_id
1526
 
        return limbo_name
1527
 
 
1528
 
 
1529
1399
    def apply(self, no_conflicts=False, precomputed_delta=None, _mover=None):
1530
1400
        """Apply all changes to the inventory and filesystem.
1531
1401
 
1651
1521
                child_pb.update('removing file', num, len(tree_paths))
1652
1522
                full_path = self._tree.abspath(path)
1653
1523
                if trans_id in self._removed_contents:
1654
 
                    delete_path = os.path.join(self._deletiondir, trans_id)
1655
 
                    mover.pre_delete(full_path, delete_path)
1656
 
                elif (trans_id in self._new_name
1657
 
                      or trans_id in self._new_parent):
 
1524
                    mover.pre_delete(full_path, os.path.join(self._deletiondir,
 
1525
                                     trans_id))
 
1526
                elif trans_id in self._new_name or trans_id in \
 
1527
                    self._new_parent:
1658
1528
                    try:
1659
1529
                        mover.rename(full_path, self._limbo_name(trans_id))
1660
1530
                    except OSError, e:
1714
1584
    unversioned files in the input tree.
1715
1585
    """
1716
1586
 
1717
 
    def __init__(self, tree, pb=None, case_sensitive=True):
 
1587
    def __init__(self, tree, pb=DummyProgress(), case_sensitive=True):
1718
1588
        tree.lock_read()
1719
1589
        limbodir = osutils.mkdtemp(prefix='bzr-limbo-')
1720
1590
        DiskTreeTransform.__init__(self, tree, limbodir, pb, case_sensitive)
1820
1690
            executable = self.is_executable(file_id, path)
1821
1691
        return kind, executable, None
1822
1692
 
1823
 
    def is_locked(self):
1824
 
        return False
1825
 
 
1826
1693
    def lock_read(self):
1827
1694
        # Perhaps in theory, this should lock the TreeTransform?
1828
 
        return self
 
1695
        pass
1829
1696
 
1830
1697
    def unlock(self):
1831
1698
        pass
2074
1941
                statval = os.lstat(limbo_name)
2075
1942
                size = statval.st_size
2076
1943
                if not supports_executable():
2077
 
                    executable = False
 
1944
                    executable = None
2078
1945
                else:
2079
1946
                    executable = statval.st_mode & S_IEXEC
2080
1947
            else:
2082
1949
                executable = None
2083
1950
            if kind == 'symlink':
2084
1951
                link_or_sha1 = os.readlink(limbo_name).decode(osutils._fs_enc)
2085
 
        executable = tt._new_executability.get(trans_id, executable)
 
1952
        if supports_executable():
 
1953
            executable = tt._new_executability.get(trans_id, executable)
2086
1954
        return kind, size, executable, link_or_sha1
2087
1955
 
2088
1956
    def iter_changes(self, from_tree, include_unchanged=False,
2401
2269
        new_desired_files = desired_files
2402
2270
    else:
2403
2271
        iter = accelerator_tree.iter_changes(tree, include_unchanged=True)
2404
 
        unchanged = [(f, p[1]) for (f, p, c, v, d, n, k, e)
2405
 
                     in iter if not (c or e[0] != e[1])]
2406
 
        if accelerator_tree.supports_content_filtering():
2407
 
            unchanged = [(f, p) for (f, p) in unchanged
2408
 
                         if not accelerator_tree.iter_search_rules([p]).next()]
2409
 
        unchanged = dict(unchanged)
 
2272
        unchanged = dict((f, p[1]) for (f, p, c, v, d, n, k, e)
 
2273
                         in iter if not (c or e[0] != e[1]))
2410
2274
        new_desired_files = []
2411
2275
        count = 0
2412
2276
        for file_id, (trans_id, tree_path) in desired_files:
2535
2399
        tt.create_directory(trans_id)
2536
2400
 
2537
2401
 
2538
 
def create_from_tree(tt, trans_id, tree, file_id, bytes=None,
2539
 
    filter_tree_path=None):
2540
 
    """Create new file contents according to tree contents.
2541
 
    
2542
 
    :param filter_tree_path: the tree path to use to lookup
2543
 
      content filters to apply to the bytes output in the working tree.
2544
 
      This only applies if the working tree supports content filtering.
2545
 
    """
 
2402
def create_from_tree(tt, trans_id, tree, file_id, bytes=None):
 
2403
    """Create new file contents according to tree contents."""
2546
2404
    kind = tree.kind(file_id)
2547
2405
    if kind == 'directory':
2548
2406
        tt.create_directory(trans_id)
2553
2411
                bytes = tree_file.readlines()
2554
2412
            finally:
2555
2413
                tree_file.close()
2556
 
        wt = tt._tree
2557
 
        if wt.supports_content_filtering() and filter_tree_path is not None:
2558
 
            filters = wt._content_filter_stack(filter_tree_path)
2559
 
            bytes = filtered_output_bytes(bytes, filters,
2560
 
                ContentFilterContext(filter_tree_path, tree))
2561
2414
        tt.create_file(bytes, trans_id)
2562
2415
    elif kind == "symlink":
2563
2416
        tt.create_symlink(tree.get_symlink_target(file_id), trans_id)
2615
2468
 
2616
2469
 
2617
2470
def revert(working_tree, target_tree, filenames, backups=False,
2618
 
           pb=None, change_reporter=None):
 
2471
           pb=DummyProgress(), change_reporter=None):
2619
2472
    """Revert a working tree's contents to those of a target tree."""
2620
2473
    target_tree.lock_read()
2621
 
    pb = ui.ui_factory.nested_progress_bar()
2622
2474
    tt = TreeTransform(working_tree, pb)
2623
2475
    try:
2624
2476
        pp = ProgressPhase("Revert phase", 3, pb)
2643
2495
def _prepare_revert_transform(working_tree, target_tree, tt, filenames,
2644
2496
                              backups, pp, basis_tree=None,
2645
2497
                              merge_modified=None):
 
2498
    pp.next_phase()
2646
2499
    child_pb = bzrlib.ui.ui_factory.nested_progress_bar()
2647
2500
    try:
2648
2501
        if merge_modified is None:
2652
2505
                                      merge_modified, basis_tree)
2653
2506
    finally:
2654
2507
        child_pb.finished()
 
2508
    pp.next_phase()
2655
2509
    child_pb = bzrlib.ui.ui_factory.nested_progress_bar()
2656
2510
    try:
2657
2511
        raw_conflicts = resolve_conflicts(tt, child_pb,
2750
2604
                    parent_trans = ROOT_PARENT
2751
2605
                else:
2752
2606
                    parent_trans = tt.trans_id_file_id(parent[1])
2753
 
                if parent[0] is None and versioned[0]:
2754
 
                    tt.adjust_root_path(name[1], parent_trans)
2755
 
                else:
2756
 
                    tt.adjust_path(name[1], parent_trans, trans_id)
 
2607
                tt.adjust_path(name[1], parent_trans, trans_id)
2757
2608
            if executable[0] != executable[1] and kind[1] == "file":
2758
2609
                tt.set_executability(executable[1], trans_id)
2759
 
        if working_tree.supports_content_filtering():
2760
 
            for index, ((trans_id, mode_id), bytes) in enumerate(
2761
 
                target_tree.iter_files_bytes(deferred_files)):
2762
 
                file_id = deferred_files[index][0]
2763
 
                # We're reverting a tree to the target tree so using the
2764
 
                # target tree to find the file path seems the best choice
2765
 
                # here IMO - Ian C 27/Oct/2009
2766
 
                filter_tree_path = target_tree.id2path(file_id)
2767
 
                filters = working_tree._content_filter_stack(filter_tree_path)
2768
 
                bytes = filtered_output_bytes(bytes, filters,
2769
 
                    ContentFilterContext(filter_tree_path, working_tree))
2770
 
                tt.create_file(bytes, trans_id, mode_id)
2771
 
        else:
2772
 
            for (trans_id, mode_id), bytes in target_tree.iter_files_bytes(
2773
 
                deferred_files):
2774
 
                tt.create_file(bytes, trans_id, mode_id)
2775
 
        tt.fixup_new_roots()
 
2610
        for (trans_id, mode_id), bytes in target_tree.iter_files_bytes(
 
2611
            deferred_files):
 
2612
            tt.create_file(bytes, trans_id, mode_id)
2776
2613
    finally:
2777
2614
        if basis_tree is not None:
2778
2615
            basis_tree.unlock()
2779
2616
    return merge_modified
2780
2617
 
2781
2618
 
2782
 
def resolve_conflicts(tt, pb=None, pass_func=None):
 
2619
def resolve_conflicts(tt, pb=DummyProgress(), pass_func=None):
2783
2620
    """Make many conflict-resolution attempts, but die if they fail"""
2784
2621
    if pass_func is None:
2785
2622
        pass_func = conflict_pass
2786
2623
    new_conflicts = set()
2787
 
    pb = ui.ui_factory.nested_progress_bar()
2788
2624
    try:
2789
2625
        for n in range(10):
2790
2626
            pb.update('Resolution pass', n+1, 10)
2794
2630
            new_conflicts.update(pass_func(tt, conflicts))
2795
2631
        raise MalformedTransform(conflicts=conflicts)
2796
2632
    finally:
2797
 
        pb.finished()
 
2633
        pb.clear()
2798
2634
 
2799
2635
 
2800
2636
def conflict_pass(tt, conflicts, path_tree=None):
2849
2685
                        # special-case the other tree root (move its
2850
2686
                        # children to current root)
2851
2687
                        if entry.parent_id is None:
2852
 
                            create = False
 
2688
                            create=False
2853
2689
                            moved = _reparent_transform_children(
2854
2690
                                tt, trans_id, tt.root)
2855
2691
                            for child in moved:
2923
2759
        self.pending_deletions = []
2924
2760
 
2925
2761
    def rename(self, from_, to):
2926
 
        """Rename a file from one path to another."""
 
2762
        """Rename a file from one path to another.  Functions like os.rename"""
2927
2763
        try:
2928
 
            osutils.rename(from_, to)
 
2764
            os.rename(from_, to)
2929
2765
        except OSError, e:
2930
2766
            if e.errno in (errno.EEXIST, errno.ENOTEMPTY):
2931
2767
                raise errors.FileExists(to, str(e))
2945
2781
    def rollback(self):
2946
2782
        """Reverse all renames that have been performed"""
2947
2783
        for from_, to in reversed(self.past_renames):
2948
 
            osutils.rename(to, from_)
 
2784
            os.rename(to, from_)
2949
2785
        # after rollback, don't reuse _FileMover
2950
2786
        past_renames = None
2951
2787
        pending_deletions = None