~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/bzrdir.py

  • Committer: Martin Pool
  • Date: 2006-04-12 04:45:32 UTC
  • mfrom: (1608.2.13 bzr.mbp.escape-stores)
  • mto: This revision was merged to the branch mainline in revision 1657.
  • Revision ID: mbp@sourcefrog.net-20060412044532-fc8c5c9408aae88b
[merge][wip] Storage escaping

Show diffs side-by-side

added added

removed removed

Lines of Context:
884
884
        """
885
885
        raise NotImplementedError(self.get_converter)
886
886
 
887
 
    def initialize(self, url):
888
 
        """Create a bzr control dir at this url and return an opened copy."""
889
 
        # Since we don't have a .bzr directory, inherit the
 
887
    def initialize(self, url, _cloning=False):
 
888
        """Create a bzr control dir at this url and return an opened copy.
 
889
        
 
890
        Subclasses should typically override initialize_on_transport
 
891
        instead of this method.
 
892
        """
 
893
        return self.initialize_on_transport(get_transport(url),
 
894
                _cloning=_cloning)
 
895
 
 
896
    def initialize_on_transport(self, transport, _cloning=False):
 
897
        """Initialize a new bzrdir in the base directory of a Transport."""
 
898
        # Since we don'transport have a .bzr directory, inherit the
890
899
        # mode from the root directory
891
 
        t = get_transport(url)
892
 
        temp_control = LockableFiles(t, '', TransportLock)
 
900
        temp_control = LockableFiles(transport, '', TransportLock)
893
901
        temp_control._transport.mkdir('.bzr',
894
902
                                      # FIXME: RBC 20060121 dont peek under
895
903
                                      # the covers
896
904
                                      mode=temp_control._dir_mode)
897
905
        file_mode = temp_control._file_mode
898
906
        del temp_control
899
 
        mutter('created control directory in ' + t.base)
900
 
        control = t.clone('.bzr')
 
907
        mutter('created control directory in ' + transport.base)
 
908
        control = transport.clone('.bzr')
901
909
        utf8_files = [('README', 
902
910
                       "This is a Bazaar-NG control directory.\n"
903
911
                       "Do not change any files in this directory.\n"),
904
912
                      ('branch-format', self.get_format_string()),
905
913
                      ]
906
914
        # NB: no need to escape relative paths that are url safe.
907
 
        control_files = LockableFiles(control, self._lock_file_name, self._lock_class)
 
915
        control_files = LockableFiles(control, self._lock_file_name, 
 
916
                                      self._lock_class)
908
917
        control_files.create_lock()
909
918
        control_files.lock_write()
910
919
        try:
912
921
                control_files.put_utf8(file, content)
913
922
        finally:
914
923
            control_files.unlock()
915
 
        return self.open(t, _found=True)
 
924
        return self.open(transport, _found=True)
916
925
 
917
926
    def is_supported(self):
918
927
        """Is this format supported?
982
991
        # there is one and only one upgrade path here.
983
992
        return ConvertBzrDir4To5()
984
993
        
985
 
    def initialize(self, url):
 
994
    def initialize_on_transport(self, transport, _cloning=False):
986
995
        """Format 4 branches cannot be created."""
987
996
        raise errors.UninitializableFormat(self)
988
997
 
1028
1037
        # there is one and only one upgrade path here.
1029
1038
        return ConvertBzrDir5To6()
1030
1039
        
1031
 
    def initialize(self, url, _cloning=False):
 
1040
    def initialize_on_transport(self, transport, _cloning=False):
1032
1041
        """Format 5 dirs always have working tree, branch and repository.
1033
1042
        
1034
1043
        Except when they are being cloned.
1036
1045
        from bzrlib.branch import BzrBranchFormat4
1037
1046
        from bzrlib.repository import RepositoryFormat5
1038
1047
        from bzrlib.workingtree import WorkingTreeFormat2
1039
 
        result = super(BzrDirFormat5, self).initialize(url)
 
1048
        result = (super(BzrDirFormat5, self)
 
1049
                  .initialize_on_transport(transport, _cloning))
1040
1050
        RepositoryFormat5().initialize(result, _internal=True)
1041
1051
        if not _cloning:
1042
1052
            BzrBranchFormat4().initialize(result)
1075
1085
        # there is one and only one upgrade path here.
1076
1086
        return ConvertBzrDir6ToMeta()
1077
1087
        
1078
 
    def initialize(self, url, _cloning=False):
 
1088
    def initialize_on_transport(self, transport, _cloning=False):
1079
1089
        """Format 6 dirs always have working tree, branch and repository.
1080
1090
        
1081
1091
        Except when they are being cloned.
1083
1093
        from bzrlib.branch import BzrBranchFormat4
1084
1094
        from bzrlib.repository import RepositoryFormat6
1085
1095
        from bzrlib.workingtree import WorkingTreeFormat2
1086
 
        result = super(BzrDirFormat6, self).initialize(url)
 
1096
        result = (super(BzrDirFormat6, self)
 
1097
                  .initialize_on_transport(transport, _cloning))
1087
1098
        RepositoryFormat6().initialize(result, _internal=True)
1088
1099
        if not _cloning:
1089
1100
            BzrBranchFormat4().initialize(result)
1545
1556
        return BzrDir.open(self.bzrdir.root_transport.base)
1546
1557
 
1547
1558
    def _convert_to_prefixed(self):
1548
 
        from bzrlib.store import hash_prefix
 
1559
        from bzrlib.store import TransportStore
1549
1560
        self.bzrdir.transport.delete('branch-format')
1550
1561
        for store_name in ["weaves", "revision-store"]:
1551
 
            self.pb.note("adding prefixes to %s" % store_name) 
 
1562
            self.pb.note("adding prefixes to %s" % store_name)
1552
1563
            store_transport = self.bzrdir.transport.clone(store_name)
 
1564
            store = TransportStore(store_transport, prefixed=True)
1553
1565
            for urlfilename in store_transport.list_dir('.'):
1554
1566
                filename = urlunescape(urlfilename)
1555
1567
                if (filename.endswith(".weave") or
1558
1570
                    file_id = os.path.splitext(filename)[0]
1559
1571
                else:
1560
1572
                    file_id = filename
1561
 
                prefix_dir = hash_prefix(file_id)
 
1573
                prefix_dir = store.hash_prefix(file_id)
1562
1574
                # FIXME keep track of the dirs made RBC 20060121
1563
1575
                try:
1564
1576
                    store_transport.move(filename, prefix_dir + '/' + filename)