~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-24 15:47:32 UTC
  • mto: This revision was merged to the branch mainline in revision 4241.
  • Revision ID: aaron@aaronbentley.com-20090324154732-bwkvi4dx3o90a7dq
Add output, emit minimal inventory delta.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
from bzrlib import (
21
21
    osutils,
22
22
    progress,
 
23
    trace,
23
24
)
24
25
from bzrlib.ui import ui_factory
25
26
 
202
203
        return missing_files, missing_parents, candidate_files
203
204
 
204
205
    @classmethod
205
 
    def guess_renames(klass, tree):
 
206
    def guess_renames(klass, tree, dry_run=False):
206
207
        """Guess which files to rename, and perform the rename.
207
208
 
208
209
        We assume that unversioned files and missing files indicate that
235
236
                                                   missing_parents)
236
237
                matches.update(parents_matches)
237
238
            pp.next_phase()
238
 
            rn._update_tree(required_parents, matches)
 
239
            delta = rn._make_inventory_delta(matches)
 
240
            for old, new, file_id, entry in delta:
 
241
                trace.note("%s => %s", old, new)
 
242
            if not dry_run:
 
243
                tree.add(required_parents)
 
244
                tree.apply_inventory_delta(delta)
239
245
        finally:
240
246
            task.finished()
241
247
 
242
 
    def _update_tree(self, required_parents, matches):
243
 
        self.tree.add(required_parents)
 
248
    def _make_inventory_delta(self, matches):
244
249
        delta = []
245
250
        file_id_matches = dict((f, p) for p, f in matches.items())
246
251
        for old_path, entry in self.tree.iter_entries_by_dir(matches.values()):
249
254
            parent_id = matches.get(parent_path)
250
255
            if parent_id is None:
251
256
                parent_id = self.tree.path2id(parent_path)
 
257
            if entry.name == new_name and entry.parent_id == parent_id:
 
258
                continue
252
259
            new_entry = entry.copy()
253
260
            new_entry.parent_id = parent_id
254
261
            new_entry.name = new_name
255
262
            delta.append((old_path, new_path, new_entry.file_id, new_entry))
256
 
        self.tree.apply_inventory_delta(delta)
 
263
        return delta