/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

  • Committer: Breezy landing bot
  • Author(s): Jelmer Vernooij
  • Date: 2018-03-24 01:32:52 UTC
  • mfrom: (6885.5.13 extract-paths2ids)
  • Revision ID: breezy.the.bot@gmail.com-20180324013252-y0cxym737louztrv
Add a new Tree.find_related_paths_across_trees() method and pass files rather than file ids in various places.

Merged from https://code.launchpad.net/~jelmer/brz/extract-paths2ids/+merge/341923

Show diffs side-by-side

added added

removed removed

Lines of Context:
894
894
                to_trans_ids[to_file_id] = trans_id
895
895
        return from_trans_ids, to_trans_ids
896
896
 
897
 
    def _from_file_data(self, from_trans_id, from_versioned, file_id):
 
897
    def _from_file_data(self, from_trans_id, from_versioned, from_path):
898
898
        """Get data about a file in the from (tree) state
899
899
 
900
900
        Return a (name, parent, kind, executable) tuple
902
902
        from_path = self._tree_id_paths.get(from_trans_id)
903
903
        if from_versioned:
904
904
            # get data from working tree if versioned
905
 
            from_entry = self._tree.iter_entries_by_dir([file_id]).next()[1]
 
905
            from_entry = self._tree.iter_entries_by_dir(
 
906
                    specific_files=[from_path]).next()[1]
906
907
            from_name = from_entry.name
907
908
            from_parent = from_entry.parent_id
908
909
        else:
971
972
            else:
972
973
                to_versioned = True
973
974
 
974
 
            from_name, from_parent, from_kind, from_executable = \
975
 
                self._from_file_data(from_trans_id, from_versioned, file_id)
976
 
 
977
 
            to_name, to_parent, to_kind, to_executable = \
978
 
                self._to_file_data(to_trans_id, from_trans_id, from_executable)
979
 
 
980
975
            if not from_versioned:
981
976
                from_path = None
982
977
            else:
985
980
                to_path = None
986
981
            else:
987
982
                to_path = final_paths.get_path(to_trans_id)
 
983
 
 
984
            from_name, from_parent, from_kind, from_executable = \
 
985
                self._from_file_data(from_trans_id, from_versioned, from_path)
 
986
 
 
987
            to_name, to_parent, to_kind, to_executable = \
 
988
                self._to_file_data(to_trans_id, from_trans_id, from_executable)
 
989
 
988
990
            if from_kind != to_kind:
989
991
                modified = True
990
992
            elif to_kind in ('file', 'symlink') and (
1763
1765
                inventory_delta.append((path, None, file_id, None))
1764
1766
            new_path_file_ids = dict((t, self.final_file_id(t)) for p, t in
1765
1767
                                     new_paths)
1766
 
            entries = self._tree.iter_entries_by_dir(
1767
 
                viewvalues(new_path_file_ids))
1768
 
            old_paths = dict((e.file_id, p) for p, e in entries)
1769
1768
            final_kinds = {}
1770
1769
            for num, (path, trans_id) in enumerate(new_paths):
1771
1770
                if (num % 10) == 0:
1793
1792
                    new_entry = inventory.make_entry(kind,
1794
1793
                        self.final_name(trans_id),
1795
1794
                        parent_file_id, file_id)
1796
 
                old_path = old_paths.get(new_entry.file_id)
 
1795
                try:
 
1796
                    old_path = self._tree.id2path(new_entry.file_id)
 
1797
                except errors.NoSuchId:
 
1798
                    old_path = None
1797
1799
                new_executability = self._new_executability.get(trans_id)
1798
1800
                if new_executability is not None:
1799
1801
                    new_entry.executable = new_executability
1944
1946
            path = self._tree_id_paths[parent_id]
1945
1947
        except KeyError:
1946
1948
            return
1947
 
        file_id = self.tree_file_id(parent_id)
1948
 
        if file_id is None:
1949
 
            return
1950
 
        entry = self._tree.iter_entries_by_dir([file_id]).next()[1]
 
1949
        entry = self._tree.iter_entries_by_dir(
 
1950
                specific_files=[path]).next()[1]
1951
1951
        children = getattr(entry, 'children', {})
1952
1952
        for child in children:
1953
1953
            childpath = joinpath(path, child)
2127
2127
            if self._transform.final_file_id(trans_id) is None:
2128
2128
                yield self._final_paths._determine_path(trans_id)
2129
2129
 
2130
 
    def _make_inv_entries(self, ordered_entries, specific_file_ids=None,
 
2130
    def _make_inv_entries(self, ordered_entries, specific_files=None,
2131
2131
        yield_parents=False):
2132
2132
        for trans_id, parent_file_id in ordered_entries:
2133
2133
            file_id = self._transform.final_file_id(trans_id)
2134
2134
            if file_id is None:
2135
2135
                continue
2136
 
            if (specific_file_ids is not None
2137
 
                and file_id not in specific_file_ids):
 
2136
            if (specific_files is not None and
 
2137
                unicode(self._final_paths.get_path(trans_id)) not in specific_files):
2138
2138
                continue
2139
2139
            kind = self._transform.final_kind(trans_id)
2140
2140
            if kind is None:
2170
2170
        for entry, trans_id in self._make_inv_entries(todo):
2171
2171
            yield entry
2172
2172
 
2173
 
    def iter_entries_by_dir(self, specific_file_ids=None, yield_parents=False):
 
2173
    def iter_entries_by_dir(self, specific_files=None, yield_parents=False):
2174
2174
        # This may not be a maximally efficient implementation, but it is
2175
2175
        # reasonably straightforward.  An implementation that grafts the
2176
2176
        # TreeTransform changes onto the tree's iter_entries_by_dir results
2178
2178
        # position.
2179
2179
        ordered_ids = self._list_files_by_dir()
2180
2180
        for entry, trans_id in self._make_inv_entries(ordered_ids,
2181
 
            specific_file_ids, yield_parents=yield_parents):
 
2181
            specific_files, yield_parents=yield_parents):
2182
2182
            yield unicode(self._final_paths.get_path(trans_id)), entry
2183
2183
 
2184
2184
    def _iter_entries_for_dir(self, dir_path):
3077
3077
                        if file_id is None:
3078
3078
                            file_id = tt.inactive_file_id(trans_id)
3079
3079
                        _, entry = next(path_tree.iter_entries_by_dir(
3080
 
                            [file_id]))
 
3080
                            specific_files=[path_tree.id2path(file_id)]))
3081
3081
                        # special-case the other tree root (move its
3082
3082
                        # children to current root)
3083
3083
                        if entry.parent_id is None: