~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/mutabletree.py

  • Committer: Aaron Bentley
  • Date: 2009-03-14 00:09:42 UTC
  • mto: This revision was merged to the branch mainline in revision 4196.
  • Revision ID: aaron@aaronbentley.com-20090314000942-03n04smifnkwlram
Move all rename-guessing into RenameMap

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
    add,
29
29
    bzrdir,
30
30
    hooks,
31
 
    progress,
32
 
    rename_map,
33
31
    symbol_versioning,
34
 
    ui,
35
32
    )
36
33
from bzrlib.osutils import dirname
37
34
from bzrlib.revisiontree import RevisionTree
38
35
from bzrlib.trace import mutter, warning
39
36
""")
40
37
 
41
 
from cStringIO import StringIO
42
 
 
43
38
from bzrlib import (
44
39
    errors,
45
40
    osutils,
237
232
        """Helper function for add - sets the entries of kinds."""
238
233
        raise NotImplementedError(self._gather_kinds)
239
234
 
240
 
    def guess_renames(self):
241
 
        """Guess which files to rename, and perform the rename.
242
 
 
243
 
        We assume that unversioned files and missing files indicate that
244
 
        versioned files have been renamed outside of Bazaar.
245
 
        """
246
 
        missing_files = set()
247
 
        missing_parents = {}
248
 
        candidate_files = set()
249
 
        basis = self.basis_tree()
250
 
        basis.lock_read()
251
 
        try:
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)
259
 
                    else:
260
 
                        #other kinds are not handled
261
 
                        pass
262
 
                if versioned == (False, False):
263
 
                    if self.is_ignored(paths[1]):
264
 
                        continue
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()
274
 
            try:
275
 
                pp = progress.ProgressPhase('Guessing renames', 2, task)
276
 
                pp.next_phase()
277
 
                rn.add_file_edge_hashes(basis, missing_files)
278
 
                pp.next_phase()
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,
282
 
                               missing_parents))
283
 
            finally:
284
 
                task.finished()
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)
293
 
        finally:
294
 
            basis.unlock()
295
 
 
296
235
    def get_file_with_stat(self, file_id, path=None):
297
236
        """Get a file handle and stat object for file_id.
298
237