~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/rename_map.py

  • Committer: Aaron Bentley
  • Date: 2009-03-13 08:19:06 UTC
  • mto: This revision was merged to the branch mainline in revision 4196.
  • Revision ID: aaron@aaronbentley.com-20090313081906-168g1ihto9jmenjf
Get directory rename handling working.

Show diffs side-by-side

added added

removed removed

Lines of Context:
103
103
 
104
104
    def file_match(self, tree, paths):
105
105
        """Return a mapping from file_ids to the supplied paths."""
 
106
        ordered_hits = self.get_all_hits(tree, paths)
 
107
        ordered_hits.sort(reverse=True)
 
108
        return self._match_hits(ordered_hits)
 
109
 
 
110
    @staticmethod
 
111
    def _match_hits(ordered_hits):
106
112
        seen_file_ids = set()
107
113
        seen_paths = set()
108
114
        path_map = {}
109
 
        ordered_hits = self.get_all_hits(tree, paths)
110
 
        ordered_hits.sort(reverse=True)
111
115
        for count, path, file_id in ordered_hits:
112
116
            if path in seen_paths or file_id in seen_file_ids:
113
117
                continue
125
129
                if tree.path2id(path) is not None:
126
130
                    break
127
131
                required_parents.setdefault(path, []).append(child)
128
 
        return required_parents
 
132
        require_ids = {}
 
133
        for parent, children in required_parents.iteritems():
 
134
            child_file_ids = set()
 
135
            for child in children:
 
136
                file_id = matches.get(child)
 
137
                if file_id is not None:
 
138
                    child_file_ids.add(file_id)
 
139
            require_ids[parent] = child_file_ids
 
140
        return require_ids
 
141
 
 
142
    def match_parents(self, required_parents, missing_parents):
 
143
        ordered_hits = []
 
144
        for file_id, file_id_children in missing_parents.iteritems():
 
145
            for path, path_children in required_parents.iteritems():
 
146
                hits = len(path_children.intersection(file_id_children))
 
147
                if hits > 0:
 
148
                    ordered_hits.append((hits, path, file_id))
 
149
        ordered_hits.sort(reverse=True)
 
150
        return self._match_hits(ordered_hits)