~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-01 08:22:11 UTC
  • Revision ID: mbp@sourcefrog.net-20050401082211-da0a0e8911740407
- basic support for moving files to different directories - have not done support for renaming them yet, but should be straightforward - some tests, but many cases are not handled yet i think

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
from inventory import InventoryEntry, Inventory
29
29
from osutils import isdir, quotefn, isfile, uuid, sha_file, username, chomp, \
30
30
     format_date, compact_date, pumpfile, user_email, rand_bytes, splitpath, \
31
 
     joinpath, sha_string, file_kind, local_time_offset
 
31
     joinpath, sha_string, file_kind, local_time_offset, appendpath
32
32
from store import ImmutableStore
33
33
from revision import Revision
34
34
from errors import bailout
697
697
 
698
698
 
699
699
 
 
700
    def rename(self, from_paths, to_name):
 
701
        """Rename files.
 
702
 
 
703
        If to_name exists and is a directory, the files are moved into
 
704
        it, keeping their old names.  If it is a directory, 
 
705
 
 
706
        Note that to_name is only the last component of the new name;
 
707
        this doesn't change the directory.
 
708
        """
 
709
        ## TODO: Option to move IDs only
 
710
        assert not isinstance(from_paths, basestring)
 
711
        tree = self.working_tree()
 
712
        inv = tree.inventory
 
713
        dest_dir = isdir(self.abspath(to_name))
 
714
        if dest_dir:
 
715
            # TODO: Wind back properly if some can't be moved?
 
716
            dest_dir_id = inv.path2id(to_name)
 
717
            if not dest_dir_id and to_name != '':
 
718
                bailout("destination %r is not a versioned directory" % to_name)
 
719
            for f in from_paths:
 
720
                name_tail = splitpath(f)[-1]
 
721
                dest_path = appendpath(to_name, name_tail)
 
722
                print "%s => %s" % (f, dest_path)
 
723
                inv.rename(inv.path2id(f), dest_dir_id, name_tail)
 
724
                os.rename(self.abspath(f), self.abspath(dest_path))
 
725
            self._write_inventory(inv)
 
726
        else:
 
727
            if len(from_paths) != 1:
 
728
                bailout("when moving multiple files, destination must be a directory")
 
729
            bailout("rename to non-directory %r not implemented sorry" % to_name)
 
730
 
 
731
 
 
732
 
700
733
    def show_status(branch, show_all=False):
701
734
        """Display single-line status for non-ignored working files.
702
735