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
18
"""Old weave-based repository formats"""
20
from StringIO import StringIO
30
from bzrlib.decorators import needs_read_lock, needs_write_lock
31
from bzrlib.repository import (
33
MetaDirRepositoryFormat,
37
from bzrlib.store.text import TextStore
38
from bzrlib.trace import mutter
41
class AllInOneRepository(Repository):
42
"""Legacy support - the repository behaviour for all-in-one branches."""
44
_serializer = xml5.serializer_v5
46
def __init__(self, _format, a_bzrdir, _revision_store, control_store, text_store):
47
# we reuse one control files instance.
48
dir_mode = a_bzrdir._control_files._dir_mode
49
file_mode = a_bzrdir._control_files._file_mode
51
def get_store(name, compressed=True, prefixed=False):
52
# FIXME: This approach of assuming stores are all entirely compressed
53
# or entirely uncompressed is tidy, but breaks upgrade from
54
# some existing branches where there's a mixture; we probably
55
# still want the option to look for both.
56
relpath = a_bzrdir._control_files._escape(name)
57
store = TextStore(a_bzrdir._control_files._transport.clone(relpath),
58
prefixed=prefixed, compressed=compressed,
63
# not broken out yet because the controlweaves|inventory_store
64
# and text_store | weave_store bits are still different.
65
if isinstance(_format, RepositoryFormat4):
66
# cannot remove these - there is still no consistent api
67
# which allows access to this old info.
68
self.inventory_store = get_store('inventory-store')
69
text_store = get_store('text-store')
70
super(AllInOneRepository, self).__init__(_format, a_bzrdir, a_bzrdir._control_files, _revision_store, control_store, text_store)
72
def get_commit_builder(self, branch, parents, config, timestamp=None,
73
timezone=None, committer=None, revprops=None,
75
self._check_ascii_revisionid(revision_id, self.get_commit_builder)
76
return Repository.get_commit_builder(self, branch, parents, config,
77
timestamp, timezone, committer, revprops, revision_id)
81
"""AllInOne repositories cannot be shared."""
85
def set_make_working_trees(self, new_value):
86
"""Set the policy flag for making working trees when creating branches.
88
This only applies to branches that use this repository.
90
The default is 'True'.
91
:param new_value: True to restore the default, False to disable making
94
raise NotImplementedError(self.set_make_working_trees)
96
def make_working_trees(self):
97
"""Returns the policy for making working trees on new branches."""
101
class WeaveMetaDirRepository(MetaDirRepository):
102
"""A subclass of MetaDirRepository to set weave specific policy."""
104
_serializer = xml5.serializer_v5
106
def get_commit_builder(self, branch, parents, config, timestamp=None,
107
timezone=None, committer=None, revprops=None,
109
self._check_ascii_revisionid(revision_id, self.get_commit_builder)
110
return MetaDirRepository.get_commit_builder(self, branch, parents,
111
config, timestamp, timezone, committer, revprops, revision_id)
114
class PreSplitOutRepositoryFormat(RepositoryFormat):
115
"""Base class for the pre split out repository formats."""
117
rich_root_data = False
118
supports_tree_reference = False
120
def initialize(self, a_bzrdir, shared=False, _internal=False):
121
"""Create a weave repository.
123
TODO: when creating split out bzr branch formats, move this to a common
124
base for Format5, Format6. or something like that.
127
raise errors.IncompatibleFormat(self, a_bzrdir._format)
130
# always initialized when the bzrdir is.
131
return self.open(a_bzrdir, _found=True)
133
# Create an empty weave
135
weavefile.write_weave_v5(weave.Weave(), sio)
136
empty_weave = sio.getvalue()
138
mutter('creating repository in %s.', a_bzrdir.transport.base)
139
dirs = ['revision-store', 'weaves']
140
files = [('inventory.weave', StringIO(empty_weave)),
143
# FIXME: RBC 20060125 don't peek under the covers
144
# NB: no need to escape relative paths that are url safe.
145
control_files = lockable_files.LockableFiles(a_bzrdir.transport,
146
'branch-lock', lockable_files.TransportLock)
147
control_files.create_lock()
148
control_files.lock_write()
149
control_files._transport.mkdir_multi(dirs,
150
mode=control_files._dir_mode)
152
for file, content in files:
153
control_files.put(file, content)
155
control_files.unlock()
156
return self.open(a_bzrdir, _found=True)
158
def _get_control_store(self, repo_transport, control_files):
159
"""Return the control store for this repository."""
160
return self._get_versioned_file_store('',
165
def _get_text_store(self, transport, control_files):
166
"""Get a store for file texts for this format."""
167
raise NotImplementedError(self._get_text_store)
169
def open(self, a_bzrdir, _found=False):
170
"""See RepositoryFormat.open()."""
172
# we are being called directly and must probe.
173
raise NotImplementedError
175
repo_transport = a_bzrdir.get_repository_transport(None)
176
control_files = a_bzrdir._control_files
177
text_store = self._get_text_store(repo_transport, control_files)
178
control_store = self._get_control_store(repo_transport, control_files)
179
_revision_store = self._get_revision_store(repo_transport, control_files)
180
return AllInOneRepository(_format=self,
182
_revision_store=_revision_store,
183
control_store=control_store,
184
text_store=text_store)
186
def check_conversion_target(self, target_format):
190
class RepositoryFormat4(PreSplitOutRepositoryFormat):
191
"""Bzr repository format 4.
193
This repository format has:
195
- TextStores for texts, inventories,revisions.
197
This format is deprecated: it indexes texts using a text id which is
198
removed in format 5; initialization and write support for this format
202
_matchingbzrdir = bzrdir.BzrDirFormat4()
205
super(RepositoryFormat4, self).__init__()
207
def get_format_description(self):
208
"""See RepositoryFormat.get_format_description()."""
209
return "Repository format 4"
211
def initialize(self, url, shared=False, _internal=False):
212
"""Format 4 branches cannot be created."""
213
raise errors.UninitializableFormat(self)
215
def is_supported(self):
216
"""Format 4 is not supported.
218
It is not supported because the model changed from 4 to 5 and the
219
conversion logic is expensive - so doing it on the fly was not
224
def _get_control_store(self, repo_transport, control_files):
225
"""Format 4 repositories have no formal control store at this point.
227
This will cause any control-file-needing apis to fail - this is desired.
231
def _get_revision_store(self, repo_transport, control_files):
232
"""See RepositoryFormat._get_revision_store()."""
233
from bzrlib.xml4 import serializer_v4
234
return self._get_text_rev_store(repo_transport,
237
serializer=serializer_v4)
239
def _get_text_store(self, transport, control_files):
240
"""See RepositoryFormat._get_text_store()."""
243
class RepositoryFormat5(PreSplitOutRepositoryFormat):
244
"""Bzr control format 5.
246
This repository format has:
247
- weaves for file texts and inventory
249
- TextStores for revisions and signatures.
252
_versionedfile_class = weave.WeaveFile
253
_matchingbzrdir = bzrdir.BzrDirFormat5()
256
super(RepositoryFormat5, self).__init__()
258
def get_format_description(self):
259
"""See RepositoryFormat.get_format_description()."""
260
return "Weave repository format 5"
262
def _get_revision_store(self, repo_transport, control_files):
263
"""See RepositoryFormat._get_revision_store()."""
264
"""Return the revision store object for this a_bzrdir."""
265
return self._get_text_rev_store(repo_transport,
270
def _get_text_store(self, transport, control_files):
271
"""See RepositoryFormat._get_text_store()."""
272
return self._get_versioned_file_store('weaves', transport, control_files, prefixed=False)
275
class RepositoryFormat6(PreSplitOutRepositoryFormat):
276
"""Bzr control format 6.
278
This repository format has:
279
- weaves for file texts and inventory
280
- hash subdirectory based stores.
281
- TextStores for revisions and signatures.
284
_versionedfile_class = weave.WeaveFile
285
_matchingbzrdir = bzrdir.BzrDirFormat6()
288
super(RepositoryFormat6, self).__init__()
290
def get_format_description(self):
291
"""See RepositoryFormat.get_format_description()."""
292
return "Weave repository format 6"
294
def _get_revision_store(self, repo_transport, control_files):
295
"""See RepositoryFormat._get_revision_store()."""
296
return self._get_text_rev_store(repo_transport,
302
def _get_text_store(self, transport, control_files):
303
"""See RepositoryFormat._get_text_store()."""
304
return self._get_versioned_file_store('weaves', transport, control_files)
307
class RepositoryFormat7(MetaDirRepositoryFormat):
310
This repository format has:
311
- weaves for file texts and inventory
312
- hash subdirectory based stores.
313
- TextStores for revisions and signatures.
314
- a format marker of its own
315
- an optional 'shared-storage' flag
316
- an optional 'no-working-trees' flag
319
_versionedfile_class = weave.WeaveFile
321
def _get_control_store(self, repo_transport, control_files):
322
"""Return the control store for this repository."""
323
return self._get_versioned_file_store('',
328
def get_format_string(self):
329
"""See RepositoryFormat.get_format_string()."""
330
return "Bazaar-NG Repository format 7"
332
def get_format_description(self):
333
"""See RepositoryFormat.get_format_description()."""
334
return "Weave repository format 7"
336
def check_conversion_target(self, target_format):
339
def _get_revision_store(self, repo_transport, control_files):
340
"""See RepositoryFormat._get_revision_store()."""
341
return self._get_text_rev_store(repo_transport,
348
def _get_text_store(self, transport, control_files):
349
"""See RepositoryFormat._get_text_store()."""
350
return self._get_versioned_file_store('weaves',
354
def initialize(self, a_bzrdir, shared=False):
355
"""Create a weave repository.
357
:param shared: If true the repository will be initialized as a shared
360
# Create an empty weave
362
weavefile.write_weave_v5(weave.Weave(), sio)
363
empty_weave = sio.getvalue()
365
mutter('creating repository in %s.', a_bzrdir.transport.base)
366
dirs = ['revision-store', 'weaves']
367
files = [('inventory.weave', StringIO(empty_weave)),
369
utf8_files = [('format', self.get_format_string())]
371
self._upload_blank_content(a_bzrdir, dirs, files, utf8_files, shared)
372
return self.open(a_bzrdir=a_bzrdir, _found=True)
374
def open(self, a_bzrdir, _found=False, _override_transport=None):
375
"""See RepositoryFormat.open().
377
:param _override_transport: INTERNAL USE ONLY. Allows opening the
378
repository at a slightly different url
379
than normal. I.e. during 'upgrade'.
382
format = RepositoryFormat.find_format(a_bzrdir)
383
assert format.__class__ == self.__class__
384
if _override_transport is not None:
385
repo_transport = _override_transport
387
repo_transport = a_bzrdir.get_repository_transport(None)
388
control_files = lockable_files.LockableFiles(repo_transport,
389
'lock', lockdir.LockDir)
390
text_store = self._get_text_store(repo_transport, control_files)
391
control_store = self._get_control_store(repo_transport, control_files)
392
_revision_store = self._get_revision_store(repo_transport, control_files)
393
return WeaveMetaDirRepository(_format=self,
395
control_files=control_files,
396
_revision_store=_revision_store,
397
control_store=control_store,
398
text_store=text_store)
401
_legacy_formats = [RepositoryFormat4(),