~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transform.py

Move all features to bzrlib.tests.features in 2.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
    bencode,
33
33
    bzrdir,
34
34
    commit,
 
35
    conflicts,
35
36
    delta,
36
37
    errors,
37
38
    inventory,
225
226
        This means that the old root trans-id becomes obsolete, so it is
226
227
        recommended only to invoke this after the root trans-id has become
227
228
        irrelevant.
 
229
 
228
230
        """
229
231
        new_roots = [k for k, v in self._new_parent.iteritems() if v is
230
232
                     ROOT_PARENT]
231
233
        if len(new_roots) < 1:
 
234
            if self.final_kind(self.root) is None:
 
235
                self.cancel_deletion(self.root)
 
236
            if self.final_file_id(self.root) is None:
 
237
                self.version_file(self.tree_file_id(self.root),
 
238
                                     self.root)
232
239
            return
233
240
        if len(new_roots) != 1:
234
241
            raise ValueError('A tree cannot have two roots!')
236
243
            self._new_root = new_roots[0]
237
244
            return
238
245
        old_new_root = new_roots[0]
239
 
        # TODO: What to do if a old_new_root is present, but self._new_root is
240
 
        #       not listed as being removed? This code explicitly unversions
241
 
        #       the old root and versions it with the new file_id. Though that
242
 
        #       seems like an incomplete delta
243
 
 
244
246
        # unversion the new root's directory.
245
 
        file_id = self.final_file_id(old_new_root)
 
247
        if self.final_kind(self._new_root) is None:
 
248
            file_id = self.final_file_id(old_new_root)
 
249
        else:
 
250
            file_id = self.final_file_id(self._new_root)
246
251
        if old_new_root in self._new_id:
247
252
            self.cancel_versioning(old_new_root)
248
253
        else:
252
257
        if (self.tree_file_id(self._new_root) is not None and
253
258
            self._new_root not in self._removed_id):
254
259
            self.unversion_file(self._new_root)
255
 
        self.version_file(file_id, self._new_root)
 
260
        if file_id is not None:
 
261
            self.version_file(file_id, self._new_root)
256
262
 
257
263
        # Now move children of new root into old root directory.
258
264
        # Ensure all children are registered with the transaction, but don't
1826
1832
        tree_paths.sort(reverse=True)
1827
1833
        child_pb = ui.ui_factory.nested_progress_bar()
1828
1834
        try:
1829
 
            for num, data in enumerate(tree_paths):
1830
 
                path, trans_id = data
 
1835
            for num, (path, trans_id) in enumerate(tree_paths):
 
1836
                # do not attempt to move root into a subdirectory of itself.
 
1837
                if path == '':
 
1838
                    continue
1831
1839
                child_pb.update('removing file', num, len(tree_paths))
1832
1840
                full_path = self._tree.abspath(path)
1833
1841
                if trans_id in self._removed_contents:
2935
2943
                        if basis_tree is None:
2936
2944
                            basis_tree = working_tree.basis_tree()
2937
2945
                            basis_tree.lock_read()
2938
 
                        if file_id in basis_tree:
 
2946
                        if basis_tree.has_id(file_id):
2939
2947
                            if wt_sha1 != basis_tree.get_file_sha1(file_id):
2940
2948
                                keep_content = True
2941
2949
                        elif target_kind is None and not target_versioned:
2971
2979
                        basis_tree = working_tree.basis_tree()
2972
2980
                        basis_tree.lock_read()
2973
2981
                    new_sha1 = target_tree.get_file_sha1(file_id)
2974
 
                    if (file_id in basis_tree and new_sha1 ==
2975
 
                        basis_tree.get_file_sha1(file_id)):
 
2982
                    if (basis_tree.has_id(file_id) and
 
2983
                        new_sha1 == basis_tree.get_file_sha1(file_id)):
2976
2984
                        if file_id in merge_modified:
2977
2985
                            del merge_modified[file_id]
2978
2986
                    else:
3129
3137
        elif c_type == 'unversioned parent':
3130
3138
            file_id = tt.inactive_file_id(conflict[1])
3131
3139
            # special-case the other tree root (move its children instead)
3132
 
            if path_tree and file_id in path_tree:
 
3140
            if path_tree and path_tree.has_id(file_id):
3133
3141
                if path_tree.path2id('') == file_id:
3134
3142
                    # This is the root entry, skip it
3135
3143
                    continue
3153
3161
 
3154
3162
def cook_conflicts(raw_conflicts, tt):
3155
3163
    """Generate a list of cooked conflicts, sorted by file path"""
3156
 
    from bzrlib.conflicts import Conflict
3157
3164
    conflict_iter = iter_cook_conflicts(raw_conflicts, tt)
3158
 
    return sorted(conflict_iter, key=Conflict.sort_key)
 
3165
    return sorted(conflict_iter, key=conflicts.Conflict.sort_key)
3159
3166
 
3160
3167
 
3161
3168
def iter_cook_conflicts(raw_conflicts, tt):
3162
 
    from bzrlib.conflicts import Conflict
3163
3169
    fp = FinalPaths(tt)
3164
3170
    for conflict in raw_conflicts:
3165
3171
        c_type = conflict[0]
3167
3173
        modified_path = fp.get_path(conflict[2])
3168
3174
        modified_id = tt.final_file_id(conflict[2])
3169
3175
        if len(conflict) == 3:
3170
 
            yield Conflict.factory(c_type, action=action, path=modified_path,
3171
 
                                     file_id=modified_id)
 
3176
            yield conflicts.Conflict.factory(
 
3177
                c_type, action=action, path=modified_path, file_id=modified_id)
3172
3178
 
3173
3179
        else:
3174
3180
            conflicting_path = fp.get_path(conflict[3])
3175
3181
            conflicting_id = tt.final_file_id(conflict[3])
3176
 
            yield Conflict.factory(c_type, action=action, path=modified_path,
3177
 
                                   file_id=modified_id,
3178
 
                                   conflict_path=conflicting_path,
3179
 
                                   conflict_file_id=conflicting_id)
 
3182
            yield conflicts.Conflict.factory(
 
3183
                c_type, action=action, path=modified_path,
 
3184
                file_id=modified_id,
 
3185
                conflict_path=conflicting_path,
 
3186
                conflict_file_id=conflicting_id)
3180
3187
 
3181
3188
 
3182
3189
class _FileMover(object):