~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/bzrdir.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2006-04-12 08:40:15 UTC
  • mfrom: (1651.1.7 bzr.mbp.escape-stores)
  • Revision ID: pqm@pqm.ubuntu.com-20060412084015-e6472a0717edbca6
(mbp) storage escaping, cleanups

Show diffs side-by-side

added added

removed removed

Lines of Context:
556
556
        """See BzrDir.clone()."""
557
557
        from bzrlib.workingtree import WorkingTreeFormat2
558
558
        self._make_tail(url)
559
 
        result = self._format.initialize(url, _cloning=True)
 
559
        result = self._format._initialize_for_clone(url)
560
560
        basis_repo, basis_branch, basis_tree = self._get_basis_components(basis)
561
561
        self.open_repository().clone(result, revision_id=revision_id, basis=basis_repo)
562
562
        self.open_branch().clone(result, revision_id=revision_id)
644
644
        """See BzrDir.sprout()."""
645
645
        from bzrlib.workingtree import WorkingTreeFormat2
646
646
        self._make_tail(url)
647
 
        result = self._format.initialize(url, _cloning=True)
 
647
        result = self._format._initialize_for_clone(url)
648
648
        basis_repo, basis_branch, basis_tree = self._get_basis_components(basis)
649
649
        try:
650
650
            self.open_repository().clone(result, revision_id=revision_id, basis=basis_repo)
889
889
        raise NotImplementedError(self.get_converter)
890
890
 
891
891
    def initialize(self, url):
892
 
        """Create a bzr control dir at this url and return an opened copy."""
893
 
        # Since we don't have a .bzr directory, inherit the
 
892
        """Create a bzr control dir at this url and return an opened copy.
 
893
        
 
894
        Subclasses should typically override initialize_on_transport
 
895
        instead of this method.
 
896
        """
 
897
        return self.initialize_on_transport(get_transport(url))
 
898
 
 
899
    def initialize_on_transport(self, transport):
 
900
        """Initialize a new bzrdir in the base directory of a Transport."""
 
901
        # Since we don'transport have a .bzr directory, inherit the
894
902
        # mode from the root directory
895
 
        t = get_transport(url)
896
 
        temp_control = LockableFiles(t, '', TransportLock)
 
903
        temp_control = LockableFiles(transport, '', TransportLock)
897
904
        temp_control._transport.mkdir('.bzr',
898
905
                                      # FIXME: RBC 20060121 dont peek under
899
906
                                      # the covers
900
907
                                      mode=temp_control._dir_mode)
901
908
        file_mode = temp_control._file_mode
902
909
        del temp_control
903
 
        mutter('created control directory in ' + t.base)
904
 
        control = t.clone('.bzr')
 
910
        mutter('created control directory in ' + transport.base)
 
911
        control = transport.clone('.bzr')
905
912
        utf8_files = [('README', 
906
913
                       "This is a Bazaar-NG control directory.\n"
907
914
                       "Do not change any files in this directory.\n"),
908
915
                      ('branch-format', self.get_format_string()),
909
916
                      ]
910
917
        # NB: no need to escape relative paths that are url safe.
911
 
        control_files = LockableFiles(control, self._lock_file_name, self._lock_class)
 
918
        control_files = LockableFiles(control, self._lock_file_name, 
 
919
                                      self._lock_class)
912
920
        control_files.create_lock()
913
921
        control_files.lock_write()
914
922
        try:
916
924
                control_files.put_utf8(file, content)
917
925
        finally:
918
926
            control_files.unlock()
919
 
        return self.open(t, _found=True)
 
927
        return self.open(transport, _found=True)
920
928
 
921
929
    def is_supported(self):
922
930
        """Is this format supported?
990
998
        # there is one and only one upgrade path here.
991
999
        return ConvertBzrDir4To5()
992
1000
        
993
 
    def initialize(self, url):
 
1001
    def initialize_on_transport(self, transport):
994
1002
        """Format 4 branches cannot be created."""
995
1003
        raise errors.UninitializableFormat(self)
996
1004
 
1039
1047
        """See BzrDirFormat.get_converter()."""
1040
1048
        # there is one and only one upgrade path here.
1041
1049
        return ConvertBzrDir5To6()
 
1050
 
 
1051
    def _initialize_for_clone(self, url):
 
1052
        return self.initialize_on_transport(get_transport(url), _cloning=True)
1042
1053
        
1043
 
    def initialize(self, url, _cloning=False):
 
1054
    def initialize_on_transport(self, transport, _cloning=False):
1044
1055
        """Format 5 dirs always have working tree, branch and repository.
1045
1056
        
1046
1057
        Except when they are being cloned.
1048
1059
        from bzrlib.branch import BzrBranchFormat4
1049
1060
        from bzrlib.repository import RepositoryFormat5
1050
1061
        from bzrlib.workingtree import WorkingTreeFormat2
1051
 
        result = super(BzrDirFormat5, self).initialize(url)
 
1062
        result = (super(BzrDirFormat5, self).initialize_on_transport(transport))
1052
1063
        RepositoryFormat5().initialize(result, _internal=True)
1053
1064
        if not _cloning:
1054
1065
            BzrBranchFormat4().initialize(result)
1091
1102
        # there is one and only one upgrade path here.
1092
1103
        return ConvertBzrDir6ToMeta()
1093
1104
        
1094
 
    def initialize(self, url, _cloning=False):
 
1105
    def _initialize_for_clone(self, url):
 
1106
        return self.initialize_on_transport(get_transport(url), _cloning=True)
 
1107
 
 
1108
    def initialize_on_transport(self, transport, _cloning=False):
1095
1109
        """Format 6 dirs always have working tree, branch and repository.
1096
1110
        
1097
1111
        Except when they are being cloned.
1099
1113
        from bzrlib.branch import BzrBranchFormat4
1100
1114
        from bzrlib.repository import RepositoryFormat6
1101
1115
        from bzrlib.workingtree import WorkingTreeFormat2
1102
 
        result = super(BzrDirFormat6, self).initialize(url)
 
1116
        result = super(BzrDirFormat6, self).initialize_on_transport(transport)
1103
1117
        RepositoryFormat6().initialize(result, _internal=True)
1104
1118
        if not _cloning:
1105
1119
            BzrBranchFormat4().initialize(result)
1565
1579
        return BzrDir.open(self.bzrdir.root_transport.base)
1566
1580
 
1567
1581
    def _convert_to_prefixed(self):
1568
 
        from bzrlib.store import hash_prefix
 
1582
        from bzrlib.store import TransportStore
1569
1583
        self.bzrdir.transport.delete('branch-format')
1570
1584
        for store_name in ["weaves", "revision-store"]:
1571
 
            self.pb.note("adding prefixes to %s" % store_name) 
 
1585
            self.pb.note("adding prefixes to %s" % store_name)
1572
1586
            store_transport = self.bzrdir.transport.clone(store_name)
 
1587
            store = TransportStore(store_transport, prefixed=True)
1573
1588
            for urlfilename in store_transport.list_dir('.'):
1574
1589
                filename = urlunescape(urlfilename)
1575
1590
                if (filename.endswith(".weave") or
1578
1593
                    file_id = os.path.splitext(filename)[0]
1579
1594
                else:
1580
1595
                    file_id = filename
1581
 
                prefix_dir = hash_prefix(file_id)
 
1596
                prefix_dir = store.hash_prefix(file_id)
1582
1597
                # FIXME keep track of the dirs made RBC 20060121
1583
1598
                try:
1584
1599
                    store_transport.move(filename, prefix_dir + '/' + filename)