~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-04-02 16:35:02 UTC
  • mfrom: (3193.8.39 guess-renames)
  • Revision ID: pqm@pqm.ubuntu.com-20090402163502-ryn8zr2giilw5bki
(abentley) Change guess-renames to mv --auto, add --dry-run

Show diffs side-by-side

added added

removed removed

Lines of Context:
722
722
    takes_args = ['names*']
723
723
    takes_options = [Option("after", help="Move only the bzr identifier"
724
724
        " of the file, because the file has already been moved."),
 
725
        Option('auto', help='Automatically guess renames.'),
 
726
        Option('dry-run', help='Avoid making changes when guessing renames.'),
725
727
        ]
726
728
    aliases = ['move', 'rename']
727
729
    encoding_type = 'replace'
728
730
 
729
 
    def run(self, names_list, after=False):
 
731
    def run(self, names_list, after=False, auto=False, dry_run=False):
 
732
        if auto:
 
733
            return self.run_auto(names_list, after, dry_run)
 
734
        elif dry_run:
 
735
            raise errors.BzrCommandError('--dry-run requires --auto.')
730
736
        if names_list is None:
731
737
            names_list = []
732
 
 
733
738
        if len(names_list) < 2:
734
739
            raise errors.BzrCommandError("missing file argument")
735
740
        tree, rel_names = tree_files(names_list, canonicalize=False)
739
744
        finally:
740
745
            tree.unlock()
741
746
 
 
747
    def run_auto(self, names_list, after, dry_run):
 
748
        if names_list is not None and len(names_list) > 1:
 
749
            raise errors.BzrCommandError('Only one path may be specified to'
 
750
                                         ' --auto.')
 
751
        if after:
 
752
            raise errors.BzrCommandError('--after cannot be specified with'
 
753
                                         ' --auto.')
 
754
        work_tree, file_list = tree_files(names_list, default_branch='.')
 
755
        work_tree.lock_write()
 
756
        try:
 
757
            rename_map.RenameMap.guess_renames(work_tree, dry_run)
 
758
        finally:
 
759
            work_tree.unlock()
 
760
 
742
761
    def _run(self, tree, names_list, rel_names, after):
743
762
        into_existing = osutils.isdir(names_list[-1])
744
763
        if into_existing and len(names_list) == 2:
5268
5287
            urlutils.unescape_for_display(to_branch.base, 'utf-8'))
5269
5288
 
5270
5289
 
5271
 
class cmd_guess_renames(Command):
5272
 
    """Guess which files have been have been renamed, based on their content.
5273
 
 
5274
 
    Only versioned files which have been deleted are candidates for rename
5275
 
    detection, and renames to ignored files will not be detected.
5276
 
    """
5277
 
 
5278
 
    def run(self):
5279
 
        work_tree, file_list = tree_files(None, default_branch='.')
5280
 
        work_tree.lock_write()
5281
 
        try:
5282
 
            rename_map.RenameMap.guess_renames(work_tree)
5283
 
        finally:
5284
 
            work_tree.unlock()
5285
 
 
5286
 
 
5287
5290
class cmd_view(Command):
5288
5291
    """Manage filtered views.
5289
5292