/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 breezy/transform.py

merge iter-entries-by-dir-specific-files

Show diffs side-by-side

added added

removed removed

Lines of Context:
69
69
    viewitems,
70
70
    viewvalues,
71
71
    )
 
72
from .tree import (
 
73
    find_previous_path,
 
74
    )
72
75
 
73
76
 
74
77
ROOT_PARENT = "root-parent"
308
311
            return self._r_new_id[file_id]
309
312
        else:
310
313
            try:
311
 
                next(self._tree.iter_entries_by_dir([file_id]))
312
 
            except StopIteration:
 
314
                path = self._tree.id2path(file_id)
 
315
            except errors.NoSuchId:
313
316
                if file_id in self._non_present_ids:
314
317
                    return self._non_present_ids[file_id]
315
318
                else:
317
320
                    self._non_present_ids[file_id] = trans_id
318
321
                    return trans_id
319
322
            else:
320
 
                return self.trans_id_tree_file_id(file_id)
 
323
                return self.trans_id_tree_path(path)
321
324
 
322
325
    def trans_id_tree_path(self, path):
323
326
        """Determine (and maybe set) the transaction ID for a tree path."""
909
912
        from_path = self._tree_id_paths.get(from_trans_id)
910
913
        if from_versioned:
911
914
            # get data from working tree if versioned
912
 
            from_entry = self._tree.iter_entries_by_dir([file_id]).next()[1]
 
915
            from_entry = self._tree.iter_entries_by_dir(
 
916
                    specific_file_ids=[file_id]).next()[1]
913
917
            from_name = from_entry.name
914
918
            from_parent = from_entry.parent_id
915
919
        else:
1772
1776
            new_path_file_ids = dict((t, self.final_file_id(t)) for p, t in
1773
1777
                                     new_paths)
1774
1778
            entries = self._tree.iter_entries_by_dir(
1775
 
                viewvalues(new_path_file_ids))
 
1779
                specific_file_ids=viewvalues(new_path_file_ids))
1776
1780
            old_paths = dict((e.file_id, p) for p, e in entries)
1777
1781
            final_kinds = {}
1778
1782
            for num, (path, trans_id) in enumerate(new_paths):
1955
1959
        file_id = self.tree_file_id(parent_id)
1956
1960
        if file_id is None:
1957
1961
            return
1958
 
        entry = self._tree.iter_entries_by_dir([file_id]).next()[1]
 
1962
        entry = self._tree.iter_entries_by_dir(
 
1963
                specific_file_ids=[file_id]).next()[1]
1959
1964
        children = getattr(entry, 'children', {})
1960
1965
        for child in children:
1961
1966
            childpath = joinpath(path, child)
2182
2187
        for entry, trans_id in self._make_inv_entries(todo):
2183
2188
            yield entry
2184
2189
 
2185
 
    def iter_entries_by_dir(self, specific_file_ids=None, yield_parents=False):
 
2190
    def iter_entries_by_dir(self, specific_file_ids=None, specific_files=None,
 
2191
                            yield_parents=False):
2186
2192
        # This may not be a maximally efficient implementation, but it is
2187
2193
        # reasonably straightforward.  An implementation that grafts the
2188
2194
        # TreeTransform changes onto the tree's iter_entries_by_dir results
2189
2195
        # might be more efficient, but requires tricky inferences about stack
2190
2196
        # position.
 
2197
        if specific_files is not None and specific_file_ids is not None:
 
2198
            raise ValueError('both specific_files and specific_file_ids set')
 
2199
        if specific_files is not None:
 
2200
            specific_file_ids = [self.path2id(p) for p in specific_files]
2191
2201
        ordered_ids = self._list_files_by_dir()
2192
2202
        for entry, trans_id in self._make_inv_entries(ordered_ids,
2193
2203
            specific_file_ids, yield_parents=yield_parents):
2255
2265
                    self._transform._tree.id2path(file_id), file_id)
2256
2266
        return self._stat_limbo_file(file_id).st_mtime
2257
2267
 
2258
 
    def _file_size(self, entry, stat_value):
2259
 
        path = self.id2path(entry.file_id)
2260
 
        return self.get_file_size(path, entry.file_id)
2261
 
 
2262
2268
    def get_file_size(self, path, file_id=None):
2263
2269
        """See Tree.get_file_size"""
2264
2270
        if file_id is None:
2623
2629
                        else:
2624
2630
                            divert.add(file_id)
2625
2631
                    if (file_id not in divert and
2626
 
                        _content_match(tree, entry, file_id, kind,
 
2632
                        _content_match(tree, entry, tree_path, file_id, kind,
2627
2633
                        target_path)):
2628
2634
                        tt.delete_contents(tt.trans_id_tree_path(tree_path))
2629
2635
                        if kind == 'directory':
2735
2741
    return by_parent[old_parent]
2736
2742
 
2737
2743
 
2738
 
def _content_match(tree, entry, file_id, kind, target_path):
 
2744
def _content_match(tree, entry, tree_path, file_id, kind, target_path):
2739
2745
    if entry.kind != kind:
2740
2746
        return False
2741
2747
    if entry.kind == "directory":
2742
2748
        return True
2743
 
    path = tree.id2path(file_id)
2744
2749
    if entry.kind == "file":
2745
2750
        f = file(target_path, 'rb')
2746
2751
        try:
2747
 
            if tree.get_file_text(path, file_id) == f.read():
 
2752
            if tree.get_file_text(tree_path, file_id) == f.read():
2748
2753
                return True
2749
2754
        finally:
2750
2755
            f.close()
2751
2756
    elif entry.kind == "symlink":
2752
 
        if tree.get_symlink_target(path, file_id) == os.readlink(target_path):
 
2757
        if tree.get_symlink_target(tree_path, file_id) == os.readlink(target_path):
2753
2758
            return True
2754
2759
    return False
2755
2760
 
2925
2930
                        if basis_tree is None:
2926
2931
                            basis_tree = working_tree.basis_tree()
2927
2932
                            basis_tree.lock_read()
2928
 
                        try:
2929
 
                            basis_path = basis_tree.id2path(file_id)
2930
 
                        except errors.NoSuchId:
 
2933
                        basis_path = find_previous_path(working_tree, basis_tree, wt_path)
 
2934
                        if basis_path is None:
2931
2935
                            if target_kind is None and not target_versioned:
2932
2936
                                keep_content = True
2933
2937
                        else:
2964
2968
                        basis_tree = working_tree.basis_tree()
2965
2969
                        basis_tree.lock_read()
2966
2970
                    new_sha1 = target_tree.get_file_sha1(target_path, file_id)
2967
 
                    try:
2968
 
                        basis_path = basis_tree.id2path(file_id)
2969
 
                    except errors.NoSuchId:
2970
 
                        basis_path = None
 
2971
                    basis_path = find_previous_path(target_tree, basis_tree, target_path)
2971
2972
                    if (basis_path is not None and
2972
2973
                        new_sha1 == basis_tree.get_file_sha1(basis_path, file_id)):
2973
2974
                        if file_id in merge_modified:
3102
3103
                        if file_id is None:
3103
3104
                            file_id = tt.inactive_file_id(trans_id)
3104
3105
                        _, entry = next(path_tree.iter_entries_by_dir(
3105
 
                            [file_id]))
 
3106
                            specific_file_ids=[file_id]))
3106
3107
                        # special-case the other tree root (move its
3107
3108
                        # children to current root)
3108
3109
                        if entry.parent_id is None: