~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/repository.py

  • Committer: Robert Collins
  • Date: 2006-02-21 12:42:57 UTC
  • mto: (1563.1.5 integration)
  • mto: This revision was merged to the branch mainline in revision 1568.
  • Revision ID: robertc@robertcollins.net-20060221124257-8ee8f4b0b3b45ac3
Add a new format for what will become knit, and the surrounding logic to upgrade repositories within metadirs, and tests for the same.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
import xml.sax.saxutils
21
21
 
22
22
 
23
 
import bzrlib.bzrdir as bzrdir
24
23
from bzrlib.decorators import needs_read_lock, needs_write_lock
25
24
import bzrlib.errors as errors
26
25
from bzrlib.errors import InvalidRevisionId
124
123
        For instance, if the repository is at URL/.bzr/repository,
125
124
        Repository.open(URL) -> a Repository instance.
126
125
        """
127
 
        control = bzrdir.BzrDir.open(base)
 
126
        control = bzrlib.bzrdir.BzrDir.open(base)
128
127
        return control.open_repository()
129
128
 
130
129
    def copy_content_into(self, destination, revision_id=None, basis=None):
158
157
            result = a_bzrdir.create_repository()
159
158
        # FIXME RBC 20060209 split out the repository type to avoid this check ?
160
159
        elif isinstance(a_bzrdir._format,
161
 
                      (bzrdir.BzrDirFormat4,
162
 
                       bzrdir.BzrDirFormat5,
163
 
                       bzrdir.BzrDirFormat6)):
 
160
                      (bzrlib.bzrdir.BzrDirFormat4,
 
161
                       bzrlib.bzrdir.BzrDirFormat5,
 
162
                       bzrlib.bzrdir.BzrDirFormat6)):
164
163
            result = a_bzrdir.open_repository()
165
164
        else:
166
165
            result = self._format.initialize(a_bzrdir, shared=self.is_shared())
743
742
 
744
743
    def __init__(self):
745
744
        super(RepositoryFormat4, self).__init__()
746
 
        self._matchingbzrdir = bzrdir.BzrDirFormat4()
 
745
        self._matchingbzrdir = bzrlib.bzrdir.BzrDirFormat4()
747
746
 
748
747
    def initialize(self, url, shared=False, _internal=False):
749
748
        """Format 4 branches cannot be created."""
776
775
 
777
776
    def __init__(self):
778
777
        super(RepositoryFormat5, self).__init__()
779
 
        self._matchingbzrdir = bzrdir.BzrDirFormat5()
 
778
        self._matchingbzrdir = bzrlib.bzrdir.BzrDirFormat5()
780
779
 
781
780
    def _get_revision_store(self, repo_transport, control_files):
782
781
        """See RepositoryFormat._get_revision_store()."""
798
797
 
799
798
    def __init__(self):
800
799
        super(RepositoryFormat6, self).__init__()
801
 
        self._matchingbzrdir = bzrdir.BzrDirFormat6()
 
800
        self._matchingbzrdir = bzrlib.bzrdir.BzrDirFormat6()
802
801
 
803
802
    def _get_revision_store(self, repo_transport, control_files):
804
803
        """See RepositoryFormat._get_revision_store()."""
812
811
class MetaDirRepositoryFormat(RepositoryFormat):
813
812
    """Common base class for the new repositories using the metadir layour."""
814
813
 
 
814
    def __init__(self):
 
815
        super(MetaDirRepositoryFormat, self).__init__()
 
816
        self._matchingbzrdir = bzrlib.bzrdir.BzrDirMetaFormat1()
 
817
 
815
818
    def _create_control_files(self, a_bzrdir):
816
819
        """Create the required files and the initial control_files object."""
817
820
        # FIXME: RBC 20060125 dont peek under the covers
831
834
                                   prefixed=True,
832
835
                                   )
833
836
 
834
 
    def open(self, a_bzrdir, _found=False):
835
 
        """See RepositoryFormat.open()."""
 
837
    def open(self, a_bzrdir, _found=False, _override_transport=None):
 
838
        """See RepositoryFormat.open().
 
839
        
 
840
        :param _override_transport: INTERNAL USE ONLY. Allows opening the
 
841
                                    repository at a slightly different url
 
842
                                    than normal. I.e. during 'upgrade'.
 
843
        """
836
844
        if not _found:
837
 
            # we are being called directly and must probe.
838
 
            raise NotImplementedError
839
 
        repo_transport = a_bzrdir.get_repository_transport(None)
840
 
        control_files = LockableFiles(a_bzrdir.get_repository_transport(None),
841
 
                                      'lock')
 
845
            format = RepositoryFormat.find_format(a_bzrdir)
 
846
            assert format.__class__ ==  self.__class__
 
847
        if _override_transport is not None:
 
848
            repo_transport = _override_transport
 
849
        else:
 
850
            repo_transport = a_bzrdir.get_repository_transport(None)
 
851
        control_files = LockableFiles(repo_transport, 'lock')
842
852
        revision_store = self._get_revision_store(repo_transport, control_files)
843
853
        return MetaDirRepository(_format=self,
844
854
                                 a_bzrdir=a_bzrdir,
901
911
        self._upload_blank_content(a_bzrdir, dirs, files, utf8_files, shared)
902
912
        return self.open(a_bzrdir=a_bzrdir, _found=True)
903
913
 
904
 
    def __init__(self):
905
 
        super(RepositoryFormat7, self).__init__()
906
 
        self._matchingbzrdir = bzrdir.BzrDirMetaFormat1()
907
 
 
908
914
 
909
915
class RepositoryFormatKnit1(MetaDirRepositoryFormat):
910
916
    """Bzr repository knit format 1.
946
952
        self._upload_blank_content(a_bzrdir, dirs, files, utf8_files, shared)
947
953
        return self.open(a_bzrdir=a_bzrdir, _found=True)
948
954
 
949
 
    def __init__(self):
950
 
        super(RepositoryFormatKnit1, self).__init__()
951
 
        self._matchingbzrdir = bzrdir.BzrDirMetaFormat1()
952
 
 
953
955
 
954
956
# formats which have no format string are not discoverable
955
957
# and not independently creatable, so are not registered.
1311
1313
        # if there are specific combinations we want to use, we can add them 
1312
1314
        # here.
1313
1315
        return result
 
1316
 
 
1317
 
 
1318
class CopyConverter(object):
 
1319
    """A repository conversion tool which just performs a copy of the content.
 
1320
    
 
1321
    This is slow but quite reliable.
 
1322
    """
 
1323
 
 
1324
    def __init__(self, target_format):
 
1325
        """Create a CopyConverter.
 
1326
 
 
1327
        :param target_format: The format the resulting repository should be.
 
1328
        """
 
1329
        self.target_format = target_format
 
1330
        
 
1331
    def convert(self, repo, pb):
 
1332
        """Perform the conversion of to_convert, giving feedback via pb.
 
1333
 
 
1334
        :param to_convert: The disk object to convert.
 
1335
        :param pb: a progress bar to use for progress information.
 
1336
        """
 
1337
        self.pb = pb
 
1338
        self.count = 0
 
1339
        self.total = 3
 
1340
        # this is only useful with metadir layouts - separated repo content.
 
1341
        # trigger an assertion if not such
 
1342
        repo._format.get_format_string()
 
1343
        self.repo_dir = repo.bzrdir
 
1344
        self.step('Moving repository to repository.backup')
 
1345
        self.repo_dir.transport.move('repository', 'repository.backup')
 
1346
        backup_transport =  self.repo_dir.transport.clone('repository.backup')
 
1347
        self.source_repo = repo._format.open(self.repo_dir,
 
1348
            _found=True,
 
1349
            _override_transport=backup_transport)
 
1350
        self.step('Creating new repository')
 
1351
        converted = self.target_format.initialize(self.repo_dir,
 
1352
                                                  self.source_repo.is_shared())
 
1353
        converted.lock_write()
 
1354
        try:
 
1355
            self.step('Copying content into repository.')
 
1356
            self.source_repo.copy_content_into(converted)
 
1357
        finally:
 
1358
            converted.unlock()
 
1359
        self.step('Deleting old repository content.')
 
1360
        self.repo_dir.transport.delete_tree('repository.backup')
 
1361
        self.pb.note('repository converted')
 
1362
 
 
1363
    def step(self, message):
 
1364
        """Update the pb by a step."""
 
1365
        self.count +=1
 
1366
        self.pb.update(message, self.count, self.total)