~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/repository.py

  • Committer: abentley
  • Date: 2006-04-20 23:47:53 UTC
  • mfrom: (1681 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1683.
  • Revision ID: abentley@lappy-20060420234753-6a6874b76f09f86d
Merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
import bzrlib.gpg as gpg
26
26
from bzrlib.graph import Graph
27
27
from bzrlib.inter import InterObject
28
 
from bzrlib.knit import KnitVersionedFile
 
28
from bzrlib.knit import KnitVersionedFile, KnitPlainFactory
29
29
from bzrlib.lockable_files import LockableFiles, TransportLock
30
30
from bzrlib.lockdir import LockDir
31
31
from bzrlib.osutils import safe_unicode
33
33
from bzrlib.store.versioned import VersionedFileStore, WeaveStore
34
34
from bzrlib.store.text import TextStore
35
35
from bzrlib.symbol_versioning import *
36
 
from bzrlib.trace import mutter
 
36
from bzrlib.trace import mutter, note
37
37
from bzrlib.tree import RevisionTree
38
38
from bzrlib.tsort import topo_sort
39
39
from bzrlib.testament import Testament
96
96
            else:
97
97
                # yes, this is not suitable for adding with ghosts.
98
98
                self.add_inventory(rev_id, inv, rev.parent_ids)
99
 
        self._revision_store.add_revision(rev, self.get_transaction())   
 
99
        self._revision_store.add_revision(rev, self.get_transaction())
100
100
 
101
101
    @needs_read_lock
102
102
    def _all_possible_ids(self):
143
143
        getting file texts, inventories and revisions, then
144
144
        this construct will accept instances of those things.
145
145
        """
146
 
        object.__init__(self)
 
146
        super(Repository, self).__init__()
147
147
        self._format = _format
148
148
        # the following are part of the public API for Repository:
149
149
        self.bzrdir = a_bzrdir
156
156
        # 
157
157
        self.control_store = control_store
158
158
        self.control_weaves = control_store
 
159
        # TODO: make sure to construct the right store classes, etc, depending
 
160
        # on whether escaping is required.
159
161
 
160
162
    def lock_write(self):
161
163
        self.control_files.lock_write()
595
597
        dir_mode = a_bzrdir._control_files._dir_mode
596
598
        file_mode = a_bzrdir._control_files._file_mode
597
599
 
598
 
        def get_weave(name, prefixed=False):
599
 
            if name:
600
 
                name = safe_unicode(name)
601
 
            else:
602
 
                name = ''
603
 
            relpath = a_bzrdir._control_files._escape(name)
604
 
            weave_transport = a_bzrdir._control_files._transport.clone(relpath)
605
 
            ws = WeaveStore(weave_transport, prefixed=prefixed,
606
 
                            dir_mode=dir_mode,
607
 
                            file_mode=file_mode)
608
 
            if a_bzrdir._control_files._transport.should_cache():
609
 
                ws.enable_cache = True
610
 
            return ws
611
 
 
612
600
        def get_store(name, compressed=True, prefixed=False):
613
601
            # FIXME: This approach of assuming stores are all entirely compressed
614
602
            # or entirely uncompressed is tidy, but breaks upgrade from 
670
658
        dir_mode = self.control_files._dir_mode
671
659
        file_mode = self.control_files._file_mode
672
660
 
673
 
        def get_weave(name, prefixed=False):
674
 
            if name:
675
 
                name = safe_unicode(name)
676
 
            else:
677
 
                name = ''
678
 
            relpath = self.control_files._escape(name)
679
 
            weave_transport = self.control_files._transport.clone(relpath)
680
 
            ws = WeaveStore(weave_transport, prefixed=prefixed,
681
 
                            dir_mode=dir_mode,
682
 
                            file_mode=file_mode)
683
 
            if self.control_files._transport.should_cache():
684
 
                ws.enable_cache = True
685
 
            return ws
686
 
 
687
661
    @needs_read_lock
688
662
    def is_shared(self):
689
663
        """Return True if this repository is flagged as a shared repository."""
797
771
        """
798
772
        result = Graph()
799
773
        vf = self._get_revision_vf()
800
 
        versions = vf.versions()
 
774
        versions = set(vf.versions())
801
775
        if not revision_ids:
802
776
            pending = set(self.all_revision_ids())
803
777
            required = set([])
812
786
                    raise errors.NoSuchRevision(self, revision_id)
813
787
                # a ghost
814
788
                result.add_ghost(revision_id)
 
789
                # mark it as done so we dont try for it again.
 
790
                done.add(revision_id)
815
791
                continue
816
792
            parent_ids = vf.get_parents_with_ghosts(revision_id)
817
793
            for parent_id in parent_ids:
821
797
                    # no, queue it.
822
798
                    pending.add(parent_id)
823
799
            result.add_node(revision_id, parent_ids)
824
 
            done.add(result)
 
800
            done.add(revision_id)
825
801
        return result
826
802
 
827
803
    def _get_revision_vf(self):
899
875
        """
900
876
        raise NotImplementedError(self.get_format_string)
901
877
 
 
878
    def get_format_description(self):
 
879
        """Return the short desciption for this format."""
 
880
        raise NotImplementedError(self.get_format_description)
 
881
 
902
882
    def _get_revision_store(self, repo_transport, control_files):
903
883
        """Return the revision store object for this a_bzrdir."""
904
884
        raise NotImplementedError(self._get_revision_store)
931
911
                                  transport,
932
912
                                  control_files,
933
913
                                  prefixed=True,
934
 
                                  versionedfile_class=WeaveFile):
 
914
                                  versionedfile_class=WeaveFile,
 
915
                                  escaped=False):
935
916
        weave_transport = control_files._transport.clone(name)
936
917
        dir_mode = control_files._dir_mode
937
918
        file_mode = control_files._file_mode
938
919
        return VersionedFileStore(weave_transport, prefixed=prefixed,
939
 
                                dir_mode=dir_mode,
940
 
                                file_mode=file_mode,
941
 
                                versionedfile_class=versionedfile_class)
 
920
                                  dir_mode=dir_mode,
 
921
                                  file_mode=file_mode,
 
922
                                  versionedfile_class=versionedfile_class,
 
923
                                  escaped=escaped)
942
924
 
943
925
    def initialize(self, a_bzrdir, shared=False):
944
926
        """Initialize a repository of this format in a_bzrdir.
1069
1051
        super(RepositoryFormat4, self).__init__()
1070
1052
        self._matchingbzrdir = bzrlib.bzrdir.BzrDirFormat4()
1071
1053
 
 
1054
    def get_format_description(self):
 
1055
        """See RepositoryFormat.get_format_description()."""
 
1056
        return "Repository format 4"
 
1057
 
1072
1058
    def initialize(self, url, shared=False, _internal=False):
1073
1059
        """Format 4 branches cannot be created."""
1074
1060
        raise errors.UninitializableFormat(self)
1114
1100
        super(RepositoryFormat5, self).__init__()
1115
1101
        self._matchingbzrdir = bzrlib.bzrdir.BzrDirFormat5()
1116
1102
 
 
1103
    def get_format_description(self):
 
1104
        """See RepositoryFormat.get_format_description()."""
 
1105
        return "Weave repository format 5"
 
1106
 
1117
1107
    def _get_revision_store(self, repo_transport, control_files):
1118
1108
        """See RepositoryFormat._get_revision_store()."""
1119
1109
        """Return the revision store object for this a_bzrdir."""
1140
1130
        super(RepositoryFormat6, self).__init__()
1141
1131
        self._matchingbzrdir = bzrlib.bzrdir.BzrDirFormat6()
1142
1132
 
 
1133
    def get_format_description(self):
 
1134
        """See RepositoryFormat.get_format_description()."""
 
1135
        return "Weave repository format 6"
 
1136
 
1143
1137
    def _get_revision_store(self, repo_transport, control_files):
1144
1138
        """See RepositoryFormat._get_revision_store()."""
1145
1139
        return self._get_text_rev_store(repo_transport,
1209
1203
        """See RepositoryFormat.get_format_string()."""
1210
1204
        return "Bazaar-NG Repository format 7"
1211
1205
 
 
1206
    def get_format_description(self):
 
1207
        """See RepositoryFormat.get_format_description()."""
 
1208
        return "Weave repository format 7"
 
1209
 
1212
1210
    def _get_revision_store(self, repo_transport, control_files):
1213
1211
        """See RepositoryFormat._get_revision_store()."""
1214
1212
        return self._get_text_rev_store(repo_transport,
1285
1283
     - an optional 'shared-storage' flag
1286
1284
     - an optional 'no-working-trees' flag
1287
1285
     - a LockDir lock
 
1286
 
 
1287
    This format was introduced in bzr 0.8.
1288
1288
    """
1289
1289
 
1290
1290
    def _get_control_store(self, repo_transport, control_files):
1291
1291
        """Return the control store for this repository."""
1292
 
        return self._get_versioned_file_store('',
1293
 
                                              repo_transport,
1294
 
                                              control_files,
1295
 
                                              prefixed=False,
1296
 
                                              versionedfile_class=KnitVersionedFile)
 
1292
        return VersionedFileStore(
 
1293
            repo_transport,
 
1294
            prefixed=False,
 
1295
            file_mode=control_files._file_mode,
 
1296
            versionedfile_class=KnitVersionedFile,
 
1297
            versionedfile_kwargs={'factory':KnitPlainFactory()},
 
1298
            )
1297
1299
 
1298
1300
    def get_format_string(self):
1299
1301
        """See RepositoryFormat.get_format_string()."""
1300
1302
        return "Bazaar-NG Knit Repository Format 1"
1301
1303
 
 
1304
    def get_format_description(self):
 
1305
        """See RepositoryFormat.get_format_description()."""
 
1306
        return "Knit repository format 1"
 
1307
 
1302
1308
    def _get_revision_store(self, repo_transport, control_files):
1303
1309
        """See RepositoryFormat._get_revision_store()."""
1304
1310
        from bzrlib.store.revision.knit import KnitRevisionStore
1305
1311
        versioned_file_store = VersionedFileStore(
1306
1312
            repo_transport,
1307
 
            file_mode = control_files._file_mode,
 
1313
            file_mode=control_files._file_mode,
1308
1314
            prefixed=False,
1309
1315
            precious=True,
1310
 
            versionedfile_class=KnitVersionedFile)
 
1316
            versionedfile_class=KnitVersionedFile,
 
1317
            versionedfile_kwargs={'delta':False, 'factory':KnitPlainFactory()},
 
1318
            escaped=True,
 
1319
            )
1311
1320
        return KnitRevisionStore(versioned_file_store)
1312
1321
 
1313
1322
    def _get_text_store(self, transport, control_files):
1315
1324
        return self._get_versioned_file_store('knits',
1316
1325
                                              transport,
1317
1326
                                              control_files,
1318
 
                                              versionedfile_class=KnitVersionedFile)
 
1327
                                              versionedfile_class=KnitVersionedFile,
 
1328
                                              escaped=True)
1319
1329
 
1320
1330
    def initialize(self, a_bzrdir, shared=False):
1321
1331
        """Create a knit format 1 repository.
1322
1332
 
 
1333
        :param a_bzrdir: bzrdir to contain the new repository; must already
 
1334
            be initialized.
1323
1335
        :param shared: If true the repository will be initialized as a shared
1324
1336
                       repository.
1325
 
        XXX NOTE that this current uses a Weave for testing and will become 
1326
 
            A Knit in due course.
1327
1337
        """
1328
 
        from bzrlib.weavefile import write_weave_v5
1329
 
        from bzrlib.weave import Weave
1330
 
 
1331
 
        # Create an empty weave
1332
 
        sio = StringIO()
1333
 
        bzrlib.weavefile.write_weave_v5(Weave(), sio)
1334
 
        empty_weave = sio.getvalue()
1335
 
 
1336
1338
        mutter('creating repository in %s.', a_bzrdir.transport.base)
1337
 
        dirs = ['revision-store', 'knits', 'control']
1338
 
        files = [('control/inventory.weave', StringIO(empty_weave)), 
1339
 
                 ]
 
1339
        dirs = ['revision-store', 'knits']
 
1340
        files = []
1340
1341
        utf8_files = [('format', self.get_format_string())]
1341
1342
        
1342
1343
        self._upload_blank_content(a_bzrdir, dirs, files, utf8_files, shared)
1379
1380
 
1380
1381
# formats which have no format string are not discoverable
1381
1382
# and not independently creatable, so are not registered.
1382
 
_default_format = RepositoryFormat7()
 
1383
RepositoryFormat.register_format(RepositoryFormat7())
 
1384
_default_format = RepositoryFormatKnit1()
1383
1385
RepositoryFormat.register_format(_default_format)
1384
 
RepositoryFormat.register_format(RepositoryFormatKnit1())
1385
1386
RepositoryFormat.set_default_format(_default_format)
1386
1387
_legacy_formats = [RepositoryFormat4(),
1387
1388
                   RepositoryFormat5(),
1510
1511
class InterWeaveRepo(InterRepository):
1511
1512
    """Optimised code paths between Weave based repositories."""
1512
1513
 
1513
 
    _matching_repo_format = _default_format
 
1514
    _matching_repo_format = RepositoryFormat7()
1514
1515
    """Repository format for testing with."""
1515
1516
 
1516
1517
    @staticmethod
1791
1792
        """
1792
1793
        self.pb = pb
1793
1794
        self.count = 0
1794
 
        self.total = 3
 
1795
        self.total = 4
1795
1796
        # this is only useful with metadir layouts - separated repo content.
1796
1797
        # trigger an assertion if not such
1797
1798
        repo._format.get_format_string()