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
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())
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.
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
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.
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
598
def get_weave(name, prefixed=False):
600
name = safe_unicode(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,
608
if a_bzrdir._control_files._transport.should_cache():
609
ws.enable_cache = True
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
673
def get_weave(name, prefixed=False):
675
name = safe_unicode(name)
678
relpath = self.control_files._escape(name)
679
weave_transport = self.control_files._transport.clone(relpath)
680
ws = WeaveStore(weave_transport, prefixed=prefixed,
683
if self.control_files._transport.should_cache():
684
ws.enable_cache = True
688
662
def is_shared(self):
689
663
"""Return True if this repository is flagged as a shared repository."""
812
786
raise errors.NoSuchRevision(self, revision_id)
814
788
result.add_ghost(revision_id)
789
# mark it as done so we dont try for it again.
790
done.add(revision_id)
816
792
parent_ids = vf.get_parents_with_ghosts(revision_id)
817
793
for parent_id in parent_ids:
900
876
raise NotImplementedError(self.get_format_string)
878
def get_format_description(self):
879
"""Return the short desciption for this format."""
880
raise NotImplementedError(self.get_format_description)
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)
934
versionedfile_class=WeaveFile):
914
versionedfile_class=WeaveFile,
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,
941
versionedfile_class=versionedfile_class)
922
versionedfile_class=versionedfile_class,
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()
1054
def get_format_description(self):
1055
"""See RepositoryFormat.get_format_description()."""
1056
return "Repository format 4"
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()
1103
def get_format_description(self):
1104
"""See RepositoryFormat.get_format_description()."""
1105
return "Weave repository format 5"
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()
1133
def get_format_description(self):
1134
"""See RepositoryFormat.get_format_description()."""
1135
return "Weave repository format 6"
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"
1206
def get_format_description(self):
1207
"""See RepositoryFormat.get_format_description()."""
1208
return "Weave repository format 7"
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
1287
This format was introduced in bzr 0.8.
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('',
1296
versionedfile_class=KnitVersionedFile)
1292
return VersionedFileStore(
1295
file_mode=control_files._file_mode,
1296
versionedfile_class=KnitVersionedFile,
1297
versionedfile_kwargs={'factory':KnitPlainFactory()},
1298
1300
def get_format_string(self):
1299
1301
"""See RepositoryFormat.get_format_string()."""
1300
1302
return "Bazaar-NG Knit Repository Format 1"
1304
def get_format_description(self):
1305
"""See RepositoryFormat.get_format_description()."""
1306
return "Knit repository format 1"
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,
1310
versionedfile_class=KnitVersionedFile)
1316
versionedfile_class=KnitVersionedFile,
1317
versionedfile_kwargs={'delta':False, 'factory':KnitPlainFactory()},
1311
1320
return KnitRevisionStore(versioned_file_store)
1313
1322
def _get_text_store(self, transport, control_files):
1315
1324
return self._get_versioned_file_store('knits',
1318
versionedfile_class=KnitVersionedFile)
1327
versionedfile_class=KnitVersionedFile,
1320
1330
def initialize(self, a_bzrdir, shared=False):
1321
1331
"""Create a knit format 1 repository.
1333
:param a_bzrdir: bzrdir to contain the new repository; must already
1323
1335
:param shared: If true the repository will be initialized as a shared
1325
XXX NOTE that this current uses a Weave for testing and will become
1326
A Knit in due course.
1328
from bzrlib.weavefile import write_weave_v5
1329
from bzrlib.weave import Weave
1331
# Create an empty weave
1333
bzrlib.weavefile.write_weave_v5(Weave(), sio)
1334
empty_weave = sio.getvalue()
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
dirs = ['revision-store', 'knits']
1340
1341
utf8_files = [('format', self.get_format_string())]
1342
1343
self._upload_blank_content(a_bzrdir, dirs, files, utf8_files, shared)
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."""
1513
_matching_repo_format = _default_format
1514
_matching_repo_format = RepositoryFormat7()
1514
1515
"""Repository format for testing with."""