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 repository formats fused with the branch and workingtree."""
20
from StringIO import StringIO
29
from bzrlib.decorators import needs_read_lock, needs_write_lock
30
from bzrlib.repository import (
32
MetaDirRepositoryFormat,
36
from bzrlib.store.text import TextStore
37
from bzrlib.trace import mutter
40
class AllInOneRepository(Repository):
41
"""Legacy support - the repository behaviour for all-in-one branches."""
43
def __init__(self, _format, a_bzrdir, _revision_store, control_store, text_store):
44
# we reuse one control files instance.
45
dir_mode = a_bzrdir._control_files._dir_mode
46
file_mode = a_bzrdir._control_files._file_mode
48
def get_store(name, compressed=True, prefixed=False):
49
# FIXME: This approach of assuming stores are all entirely compressed
50
# or entirely uncompressed is tidy, but breaks upgrade from
51
# some existing branches where there's a mixture; we probably
52
# still want the option to look for both.
53
relpath = a_bzrdir._control_files._escape(name)
54
store = TextStore(a_bzrdir._control_files._transport.clone(relpath),
55
prefixed=prefixed, compressed=compressed,
58
#if self._transport.should_cache():
59
# cache_path = os.path.join(self.cache_root, name)
60
# os.mkdir(cache_path)
61
# store = bzrlib.store.CachedStore(store, cache_path)
64
# not broken out yet because the controlweaves|inventory_store
65
# and text_store | weave_store bits are still different.
66
if isinstance(_format, RepositoryFormat4):
67
# cannot remove these - there is still no consistent api
68
# which allows access to this old info.
69
self.inventory_store = get_store('inventory-store')
70
text_store = get_store('text-store')
71
super(AllInOneRepository, self).__init__(_format, a_bzrdir, a_bzrdir._control_files, _revision_store, control_store, text_store)
73
def get_commit_builder(self, branch, parents, config, timestamp=None,
74
timezone=None, committer=None, revprops=None,
76
self._check_ascii_revisionid(revision_id, self.get_commit_builder)
77
return Repository.get_commit_builder(self, branch, parents, config,
78
timestamp, timezone, committer, revprops, revision_id)
82
"""AllInOne repositories cannot be shared."""
86
def set_make_working_trees(self, new_value):
87
"""Set the policy flag for making working trees when creating branches.
89
This only applies to branches that use this repository.
91
The default is 'True'.
92
:param new_value: True to restore the default, False to disable making
95
raise NotImplementedError(self.set_make_working_trees)
97
def make_working_trees(self):
98
"""Returns the policy for making working trees on new branches."""
102
class WeaveMetaDirRepository(MetaDirRepository):
103
"""A subclass of MetaDirRepository to set weave specific policy."""
105
def get_commit_builder(self, branch, parents, config, timestamp=None,
106
timezone=None, committer=None, revprops=None,
108
self._check_ascii_revisionid(revision_id, self.get_commit_builder)
109
return MetaDirRepository.get_commit_builder(self, branch, parents,
110
config, timestamp, timezone, committer, revprops, revision_id)
113
class PreSplitOutRepositoryFormat(RepositoryFormat):
114
"""Base class for the pre split out repository formats."""
116
rich_root_data = False
118
def initialize(self, a_bzrdir, shared=False, _internal=False):
119
"""Create a weave repository.
121
TODO: when creating split out bzr branch formats, move this to a common
122
base for Format5, Format6. or something like that.
125
raise errors.IncompatibleFormat(self, a_bzrdir._format)
128
# always initialized when the bzrdir is.
129
return self.open(a_bzrdir, _found=True)
131
# Create an empty weave
133
weavefile.write_weave_v5(weave.Weave(), sio)
134
empty_weave = sio.getvalue()
136
mutter('creating repository in %s.', a_bzrdir.transport.base)
137
dirs = ['revision-store', 'weaves']
138
files = [('inventory.weave', StringIO(empty_weave)),
141
# FIXME: RBC 20060125 don't peek under the covers
142
# NB: no need to escape relative paths that are url safe.
143
control_files = lockable_files.LockableFiles(a_bzrdir.transport,
144
'branch-lock', lockable_files.TransportLock)
145
control_files.create_lock()
146
control_files.lock_write()
147
control_files._transport.mkdir_multi(dirs,
148
mode=control_files._dir_mode)
150
for file, content in files:
151
control_files.put(file, content)
153
control_files.unlock()
154
return self.open(a_bzrdir, _found=True)
156
def _get_control_store(self, repo_transport, control_files):
157
"""Return the control store for this repository."""
158
return self._get_versioned_file_store('',
163
def _get_text_store(self, transport, control_files):
164
"""Get a store for file texts for this format."""
165
raise NotImplementedError(self._get_text_store)
167
def open(self, a_bzrdir, _found=False):
168
"""See RepositoryFormat.open()."""
170
# we are being called directly and must probe.
171
raise NotImplementedError
173
repo_transport = a_bzrdir.get_repository_transport(None)
174
control_files = a_bzrdir._control_files
175
text_store = self._get_text_store(repo_transport, control_files)
176
control_store = self._get_control_store(repo_transport, control_files)
177
_revision_store = self._get_revision_store(repo_transport, control_files)
178
return AllInOneRepository(_format=self,
180
_revision_store=_revision_store,
181
control_store=control_store,
182
text_store=text_store)
184
def check_conversion_target(self, target_format):
188
class RepositoryFormat4(PreSplitOutRepositoryFormat):
189
"""Bzr repository format 4.
191
This repository format has:
193
- TextStores for texts, inventories,revisions.
195
This format is deprecated: it indexes texts using a text id which is
196
removed in format 5; initialization and write support for this format
201
super(RepositoryFormat4, self).__init__()
202
self._matchingbzrdir = bzrdir.BzrDirFormat4()
204
def get_format_description(self):
205
"""See RepositoryFormat.get_format_description()."""
206
return "Repository format 4"
208
def initialize(self, url, shared=False, _internal=False):
209
"""Format 4 branches cannot be created."""
210
raise errors.UninitializableFormat(self)
212
def is_supported(self):
213
"""Format 4 is not supported.
215
It is not supported because the model changed from 4 to 5 and the
216
conversion logic is expensive - so doing it on the fly was not
221
def _get_control_store(self, repo_transport, control_files):
222
"""Format 4 repositories have no formal control store at this point.
224
This will cause any control-file-needing apis to fail - this is desired.
228
def _get_revision_store(self, repo_transport, control_files):
229
"""See RepositoryFormat._get_revision_store()."""
230
from bzrlib.xml4 import serializer_v4
231
return self._get_text_rev_store(repo_transport,
234
serializer=serializer_v4)
236
def _get_text_store(self, transport, control_files):
237
"""See RepositoryFormat._get_text_store()."""
240
class RepositoryFormat5(PreSplitOutRepositoryFormat):
241
"""Bzr control format 5.
243
This repository format has:
244
- weaves for file texts and inventory
246
- TextStores for revisions and signatures.
250
super(RepositoryFormat5, self).__init__()
251
self._matchingbzrdir = bzrdir.BzrDirFormat5()
253
def get_format_description(self):
254
"""See RepositoryFormat.get_format_description()."""
255
return "Weave repository format 5"
257
def _get_revision_store(self, repo_transport, control_files):
258
"""See RepositoryFormat._get_revision_store()."""
259
"""Return the revision store object for this a_bzrdir."""
260
return self._get_text_rev_store(repo_transport,
265
def _get_text_store(self, transport, control_files):
266
"""See RepositoryFormat._get_text_store()."""
267
return self._get_versioned_file_store('weaves', transport, control_files, prefixed=False)
270
class RepositoryFormat6(PreSplitOutRepositoryFormat):
271
"""Bzr control format 6.
273
This repository format has:
274
- weaves for file texts and inventory
275
- hash subdirectory based stores.
276
- TextStores for revisions and signatures.
280
super(RepositoryFormat6, self).__init__()
281
self._matchingbzrdir = bzrdir.BzrDirFormat6()
283
def get_format_description(self):
284
"""See RepositoryFormat.get_format_description()."""
285
return "Weave repository format 6"
287
def _get_revision_store(self, repo_transport, control_files):
288
"""See RepositoryFormat._get_revision_store()."""
289
return self._get_text_rev_store(repo_transport,
295
def _get_text_store(self, transport, control_files):
296
"""See RepositoryFormat._get_text_store()."""
297
return self._get_versioned_file_store('weaves', transport, control_files)
300
class RepositoryFormat7(MetaDirRepositoryFormat):
303
This repository format has:
304
- weaves for file texts and inventory
305
- hash subdirectory based stores.
306
- TextStores for revisions and signatures.
307
- a format marker of its own
308
- an optional 'shared-storage' flag
309
- an optional 'no-working-trees' flag
312
def _get_control_store(self, repo_transport, control_files):
313
"""Return the control store for this repository."""
314
return self._get_versioned_file_store('',
319
def get_format_string(self):
320
"""See RepositoryFormat.get_format_string()."""
321
return "Bazaar-NG Repository format 7"
323
def get_format_description(self):
324
"""See RepositoryFormat.get_format_description()."""
325
return "Weave repository format 7"
327
def check_conversion_target(self, target_format):
330
def _get_revision_store(self, repo_transport, control_files):
331
"""See RepositoryFormat._get_revision_store()."""
332
return self._get_text_rev_store(repo_transport,
339
def _get_text_store(self, transport, control_files):
340
"""See RepositoryFormat._get_text_store()."""
341
return self._get_versioned_file_store('weaves',
345
def initialize(self, a_bzrdir, shared=False):
346
"""Create a weave repository.
348
:param shared: If true the repository will be initialized as a shared
351
# Create an empty weave
353
weavefile.write_weave_v5(weave.Weave(), sio)
354
empty_weave = sio.getvalue()
356
mutter('creating repository in %s.', a_bzrdir.transport.base)
357
dirs = ['revision-store', 'weaves']
358
files = [('inventory.weave', StringIO(empty_weave)),
360
utf8_files = [('format', self.get_format_string())]
362
self._upload_blank_content(a_bzrdir, dirs, files, utf8_files, shared)
363
return self.open(a_bzrdir=a_bzrdir, _found=True)
365
def open(self, a_bzrdir, _found=False, _override_transport=None):
366
"""See RepositoryFormat.open().
368
:param _override_transport: INTERNAL USE ONLY. Allows opening the
369
repository at a slightly different url
370
than normal. I.e. during 'upgrade'.
373
format = RepositoryFormat.find_format(a_bzrdir)
374
assert format.__class__ == self.__class__
375
if _override_transport is not None:
376
repo_transport = _override_transport
378
repo_transport = a_bzrdir.get_repository_transport(None)
379
control_files = lockable_files.LockableFiles(repo_transport,
380
'lock', lockdir.LockDir)
381
text_store = self._get_text_store(repo_transport, control_files)
382
control_store = self._get_control_store(repo_transport, control_files)
383
_revision_store = self._get_revision_store(repo_transport, control_files)
384
return WeaveMetaDirRepository(_format=self,
386
control_files=control_files,
387
_revision_store=_revision_store,
388
control_store=control_store,
389
text_store=text_store)
392
RepositoryFormat7_instance = RepositoryFormat7()
395
_legacy_formats = [RepositoryFormat4(),