~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: mbp at sourcefrog
  • Date: 2005-04-05 06:49:02 UTC
  • Revision ID: mbp@sourcefrog.net-20050405064902-0ddd0e6b29762088
new "rename" command

Show diffs side-by-side

added added

removed removed

Lines of Context:
702
702
            precursor = p
703
703
 
704
704
 
 
705
    def rename_one(self, from_rel, to_rel):
 
706
        tree = self.working_tree()
 
707
        inv = tree.inventory
 
708
        if not tree.has_filename(from_rel):
 
709
            bailout("can't rename: old working file %r does not exist" % from_rel)
 
710
        if tree.has_filename(to_rel):
 
711
            bailout("can't rename: new working file %r already exists" % to_rel)
 
712
            
 
713
        file_id = inv.path2id(from_rel)
 
714
        if file_id == None:
 
715
            bailout("can't rename: old name %r is not versioned" % from_rel)
 
716
 
 
717
        if inv.path2id(to_rel):
 
718
            bailout("can't rename: new name %r is already versioned" % to_rel)
 
719
 
 
720
        to_dir, to_tail = os.path.split(to_rel)
 
721
        to_dir_id = inv.path2id(to_dir)
 
722
        if to_dir_id == None and to_dir != '':
 
723
            bailout("can't determine destination directory id for %r" % to_dir)
 
724
 
 
725
        mutter("rename_one:")
 
726
        mutter("  file_id    {%s}" % file_id)
 
727
        mutter("  from_rel   %r" % from_rel)
 
728
        mutter("  to_rel     %r" % to_rel)
 
729
        mutter("  to_dir     %r" % to_dir)
 
730
        mutter("  to_dir_id  {%s}" % to_dir_id)
 
731
            
 
732
        inv.rename(file_id, to_dir_id, to_tail)
 
733
        os.rename(self.abspath(from_rel), self.abspath(to_rel))
 
734
 
 
735
        self._write_inventory(inv)
 
736
            
 
737
 
705
738
 
706
739
    def rename(self, from_paths, to_name):
707
740
        """Rename files.