1
# Copyright (C) 2005, 2006, 2007 Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
"""Deprecated weave-based repository formats.
19
Weave based formats scaled linearly with history size and could not represent
23
from StringIO import StringIO
34
from bzrlib.decorators import needs_read_lock, needs_write_lock
35
from bzrlib.repository import (
38
MetaDirRepositoryFormat,
42
from bzrlib.store.text import TextStore
43
from bzrlib.trace import mutter
46
class AllInOneRepository(Repository):
47
"""Legacy support - the repository behaviour for all-in-one branches."""
49
_serializer = xml5.serializer_v5
51
def __init__(self, _format, a_bzrdir, _revision_store, control_store, text_store):
52
# we reuse one control files instance.
53
dir_mode = a_bzrdir._control_files._dir_mode
54
file_mode = a_bzrdir._control_files._file_mode
56
def get_store(name, compressed=True, prefixed=False):
57
# FIXME: This approach of assuming stores are all entirely compressed
58
# or entirely uncompressed is tidy, but breaks upgrade from
59
# some existing branches where there's a mixture; we probably
60
# still want the option to look for both.
61
relpath = a_bzrdir._control_files._escape(name)
62
store = TextStore(a_bzrdir._control_files._transport.clone(relpath),
63
prefixed=prefixed, compressed=compressed,
68
# not broken out yet because the controlweaves|inventory_store
69
# and text_store | weave_store bits are still different.
70
if isinstance(_format, RepositoryFormat4):
71
# cannot remove these - there is still no consistent api
72
# which allows access to this old info.
73
self.inventory_store = get_store('inventory-store')
74
text_store = get_store('text-store')
75
super(AllInOneRepository, self).__init__(_format, a_bzrdir, a_bzrdir._control_files, _revision_store, control_store, text_store)
77
def get_commit_builder(self, branch, parents, config, timestamp=None,
78
timezone=None, committer=None, revprops=None,
80
self._check_ascii_revisionid(revision_id, self.get_commit_builder)
81
revision_id = osutils.safe_revision_id(revision_id)
82
result = WeaveCommitBuilder(self, parents, config, timestamp, timezone,
83
committer, revprops, revision_id)
84
self.start_write_group()
89
"""AllInOne repositories cannot be shared."""
93
def set_make_working_trees(self, new_value):
94
"""Set the policy flag for making working trees when creating branches.
96
This only applies to branches that use this repository.
98
The default is 'True'.
99
:param new_value: True to restore the default, False to disable making
102
raise NotImplementedError(self.set_make_working_trees)
104
def make_working_trees(self):
105
"""Returns the policy for making working trees on new branches."""
109
class WeaveMetaDirRepository(MetaDirRepository):
110
"""A subclass of MetaDirRepository to set weave specific policy."""
112
_serializer = xml5.serializer_v5
114
def get_commit_builder(self, branch, parents, config, timestamp=None,
115
timezone=None, committer=None, revprops=None,
117
self._check_ascii_revisionid(revision_id, self.get_commit_builder)
118
revision_id = osutils.safe_revision_id(revision_id)
119
result = WeaveCommitBuilder(self, parents, config, timestamp, timezone,
120
committer, revprops, revision_id)
121
self.start_write_group()
125
class PreSplitOutRepositoryFormat(RepositoryFormat):
126
"""Base class for the pre split out repository formats."""
128
rich_root_data = False
129
supports_tree_reference = False
131
def initialize(self, a_bzrdir, shared=False, _internal=False):
132
"""Create a weave repository.
134
TODO: when creating split out bzr branch formats, move this to a common
135
base for Format5, Format6. or something like that.
138
raise errors.IncompatibleFormat(self, a_bzrdir._format)
141
# always initialized when the bzrdir is.
142
return self.open(a_bzrdir, _found=True)
144
# Create an empty weave
146
weavefile.write_weave_v5(weave.Weave(), sio)
147
empty_weave = sio.getvalue()
149
mutter('creating repository in %s.', a_bzrdir.transport.base)
150
dirs = ['revision-store', 'weaves']
151
files = [('inventory.weave', StringIO(empty_weave)),
154
# FIXME: RBC 20060125 don't peek under the covers
155
# NB: no need to escape relative paths that are url safe.
156
control_files = lockable_files.LockableFiles(a_bzrdir.transport,
157
'branch-lock', lockable_files.TransportLock)
158
control_files.create_lock()
159
control_files.lock_write()
160
control_files._transport.mkdir_multi(dirs,
161
mode=control_files._dir_mode)
163
for file, content in files:
164
control_files.put(file, content)
166
control_files.unlock()
167
return self.open(a_bzrdir, _found=True)
169
def _get_control_store(self, repo_transport, control_files):
170
"""Return the control store for this repository."""
171
return self._get_versioned_file_store('',
176
def _get_text_store(self, transport, control_files):
177
"""Get a store for file texts for this format."""
178
raise NotImplementedError(self._get_text_store)
180
def open(self, a_bzrdir, _found=False):
181
"""See RepositoryFormat.open()."""
183
# we are being called directly and must probe.
184
raise NotImplementedError
186
repo_transport = a_bzrdir.get_repository_transport(None)
187
control_files = a_bzrdir._control_files
188
text_store = self._get_text_store(repo_transport, control_files)
189
control_store = self._get_control_store(repo_transport, control_files)
190
_revision_store = self._get_revision_store(repo_transport, control_files)
191
return AllInOneRepository(_format=self,
193
_revision_store=_revision_store,
194
control_store=control_store,
195
text_store=text_store)
197
def check_conversion_target(self, target_format):
201
class RepositoryFormat4(PreSplitOutRepositoryFormat):
202
"""Bzr repository format 4.
204
This repository format has:
206
- TextStores for texts, inventories,revisions.
208
This format is deprecated: it indexes texts using a text id which is
209
removed in format 5; initialization and write support for this format
213
_matchingbzrdir = bzrdir.BzrDirFormat4()
216
super(RepositoryFormat4, self).__init__()
218
def get_format_description(self):
219
"""See RepositoryFormat.get_format_description()."""
220
return "Repository format 4"
222
def initialize(self, url, shared=False, _internal=False):
223
"""Format 4 branches cannot be created."""
224
raise errors.UninitializableFormat(self)
226
def is_supported(self):
227
"""Format 4 is not supported.
229
It is not supported because the model changed from 4 to 5 and the
230
conversion logic is expensive - so doing it on the fly was not
235
def _get_control_store(self, repo_transport, control_files):
236
"""Format 4 repositories have no formal control store at this point.
238
This will cause any control-file-needing apis to fail - this is desired.
242
def _get_revision_store(self, repo_transport, control_files):
243
"""See RepositoryFormat._get_revision_store()."""
244
from bzrlib.xml4 import serializer_v4
245
return self._get_text_rev_store(repo_transport,
248
serializer=serializer_v4)
250
def _get_text_store(self, transport, control_files):
251
"""See RepositoryFormat._get_text_store()."""
254
class RepositoryFormat5(PreSplitOutRepositoryFormat):
255
"""Bzr control format 5.
257
This repository format has:
258
- weaves for file texts and inventory
260
- TextStores for revisions and signatures.
263
_versionedfile_class = weave.WeaveFile
264
_matchingbzrdir = bzrdir.BzrDirFormat5()
267
super(RepositoryFormat5, self).__init__()
269
def get_format_description(self):
270
"""See RepositoryFormat.get_format_description()."""
271
return "Weave repository format 5"
273
def _get_revision_store(self, repo_transport, control_files):
274
"""See RepositoryFormat._get_revision_store()."""
275
"""Return the revision store object for this a_bzrdir."""
276
return self._get_text_rev_store(repo_transport,
281
def _get_text_store(self, transport, control_files):
282
"""See RepositoryFormat._get_text_store()."""
283
return self._get_versioned_file_store('weaves', transport, control_files, prefixed=False)
286
class RepositoryFormat6(PreSplitOutRepositoryFormat):
287
"""Bzr control format 6.
289
This repository format has:
290
- weaves for file texts and inventory
291
- hash subdirectory based stores.
292
- TextStores for revisions and signatures.
295
_versionedfile_class = weave.WeaveFile
296
_matchingbzrdir = bzrdir.BzrDirFormat6()
299
super(RepositoryFormat6, self).__init__()
301
def get_format_description(self):
302
"""See RepositoryFormat.get_format_description()."""
303
return "Weave repository format 6"
305
def _get_revision_store(self, repo_transport, control_files):
306
"""See RepositoryFormat._get_revision_store()."""
307
return self._get_text_rev_store(repo_transport,
313
def _get_text_store(self, transport, control_files):
314
"""See RepositoryFormat._get_text_store()."""
315
return self._get_versioned_file_store('weaves', transport, control_files)
318
class RepositoryFormat7(MetaDirRepositoryFormat):
321
This repository format has:
322
- weaves for file texts and inventory
323
- hash subdirectory based stores.
324
- TextStores for revisions and signatures.
325
- a format marker of its own
326
- an optional 'shared-storage' flag
327
- an optional 'no-working-trees' flag
330
_versionedfile_class = weave.WeaveFile
332
def _get_control_store(self, repo_transport, control_files):
333
"""Return the control store for this repository."""
334
return self._get_versioned_file_store('',
339
def get_format_string(self):
340
"""See RepositoryFormat.get_format_string()."""
341
return "Bazaar-NG Repository format 7"
343
def get_format_description(self):
344
"""See RepositoryFormat.get_format_description()."""
345
return "Weave repository format 7"
347
def check_conversion_target(self, target_format):
350
def _get_revision_store(self, repo_transport, control_files):
351
"""See RepositoryFormat._get_revision_store()."""
352
return self._get_text_rev_store(repo_transport,
359
def _get_text_store(self, transport, control_files):
360
"""See RepositoryFormat._get_text_store()."""
361
return self._get_versioned_file_store('weaves',
365
def initialize(self, a_bzrdir, shared=False):
366
"""Create a weave repository.
368
:param shared: If true the repository will be initialized as a shared
371
# Create an empty weave
373
weavefile.write_weave_v5(weave.Weave(), sio)
374
empty_weave = sio.getvalue()
376
mutter('creating repository in %s.', a_bzrdir.transport.base)
377
dirs = ['revision-store', 'weaves']
378
files = [('inventory.weave', StringIO(empty_weave)),
380
utf8_files = [('format', self.get_format_string())]
382
self._upload_blank_content(a_bzrdir, dirs, files, utf8_files, shared)
383
return self.open(a_bzrdir=a_bzrdir, _found=True)
385
def open(self, a_bzrdir, _found=False, _override_transport=None):
386
"""See RepositoryFormat.open().
388
:param _override_transport: INTERNAL USE ONLY. Allows opening the
389
repository at a slightly different url
390
than normal. I.e. during 'upgrade'.
393
format = RepositoryFormat.find_format(a_bzrdir)
394
assert format.__class__ == self.__class__
395
if _override_transport is not None:
396
repo_transport = _override_transport
398
repo_transport = a_bzrdir.get_repository_transport(None)
399
control_files = lockable_files.LockableFiles(repo_transport,
400
'lock', lockdir.LockDir)
401
text_store = self._get_text_store(repo_transport, control_files)
402
control_store = self._get_control_store(repo_transport, control_files)
403
_revision_store = self._get_revision_store(repo_transport, control_files)
404
return WeaveMetaDirRepository(_format=self,
406
control_files=control_files,
407
_revision_store=_revision_store,
408
control_store=control_store,
409
text_store=text_store)
412
class WeaveCommitBuilder(CommitBuilder):
413
"""A builder for weave based repos that don't support ghosts."""
415
def _add_text_to_weave(self, file_id, new_lines, parents):
416
versionedfile = self.repository.weave_store.get_weave_or_empty(
417
file_id, self.repository.get_transaction())
418
result = versionedfile.add_lines(
419
self._new_revision_id, parents, new_lines)[0:2]
420
versionedfile.clear_cache()
424
_legacy_formats = [RepositoryFormat4(),