237
232
"""Helper function for add - sets the entries of kinds."""
238
233
raise NotImplementedError(self._gather_kinds)
240
def guess_renames(self):
241
"""Guess which files to rename, and perform the rename.
243
We assume that unversioned files and missing files indicate that
244
versioned files have been renamed outside of Bazaar.
246
missing_files = set()
248
candidate_files = set()
249
basis = self.basis_tree()
252
iterator = self.iter_changes(basis, want_unversioned=True)
253
for (file_id, paths, changed_content, versioned, parent, name,
254
kind, executable) in iterator:
255
if kind[1] is None and versioned[1]:
256
missing_parents.setdefault(parent[0], set()).add(file_id)
257
if kind[0] == 'file':
258
missing_files.add(file_id)
260
#other kinds are not handled
262
if versioned == (False, False):
263
if self.is_ignored(paths[1]):
265
if kind[1] == 'file':
266
candidate_files.add(paths[1])
267
if kind[1] == 'directory':
268
for directory, children in self.walkdirs(paths[1]):
269
for child in children:
270
if child[2] == 'file':
271
candidate_files.add(child[0])
272
rn = rename_map.RenameMap()
273
task = ui.ui_factory.nested_progress_bar()
275
pp = progress.ProgressPhase('Guessing renames', 2, task)
277
rn.add_file_edge_hashes(basis, missing_files)
279
matches = rn.file_match(self, candidate_files)
280
required_parents = rn.get_required_parents(matches, self)
281
matches.update(rn.match_parents(required_parents,
285
self.add(set(required_parents) - set(matches))
286
reversed = dict((v, k) for k, v in matches.iteritems())
287
child_to_parent = sorted(
288
matches.values(), key=lambda x: reversed[x], reverse=True)
289
self.unversion(child_to_parent)
290
paths_forward = sorted(matches.keys())
291
file_ids_forward = [matches[p] for p in paths_forward]
292
self.add(paths_forward, file_ids_forward)
296
235
def get_file_with_stat(self, file_id, path=None):
297
236
"""Get a file handle and stat object for file_id.