13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
17
"""Deprecated weave-based repository formats.
65
58
class AllInOneRepository(Repository):
66
59
"""Legacy support - the repository behaviour for all-in-one branches."""
69
def _serializer(self):
70
return xml5.serializer_v5
72
def _escape(self, file_or_path):
73
if not isinstance(file_or_path, basestring):
74
file_or_path = '/'.join(file_or_path)
75
if file_or_path == '':
77
return urlutils.escape(osutils.safe_unicode(file_or_path))
61
_serializer = xml5.serializer_v5
79
63
def __init__(self, _format, a_bzrdir):
80
64
# we reuse one control files instance.
84
68
def get_store(name, compressed=True, prefixed=False):
85
69
# FIXME: This approach of assuming stores are all entirely compressed
86
# or entirely uncompressed is tidy, but breaks upgrade from
87
# some existing branches where there's a mixture; we probably
70
# or entirely uncompressed is tidy, but breaks upgrade from
71
# some existing branches where there's a mixture; we probably
88
72
# still want the option to look for both.
89
relpath = self._escape(name)
73
relpath = a_bzrdir._control_files._escape(name)
90
74
store = TextStore(a_bzrdir.transport.clone(relpath),
91
75
prefixed=prefixed, compressed=compressed,
96
80
# not broken out yet because the controlweaves|inventory_store
97
81
# and texts bits are still different.
98
82
if isinstance(_format, RepositoryFormat4):
99
# cannot remove these - there is still no consistent api
83
# cannot remove these - there is still no consistent api
100
84
# which allows access to this old info.
101
85
self.inventory_store = get_store('inventory-store')
102
86
self._text_store = get_store('text-store')
103
87
super(AllInOneRepository, self).__init__(_format, a_bzrdir, a_bzrdir._control_files)
88
self._fetch_order = 'topological'
89
self._fetch_reconcile = True
106
92
def _all_possible_ids(self):
113
99
def _all_revision_ids(self):
114
"""Returns a list of all the revision ids in the repository.
100
"""Returns a list of all the revision ids in the repository.
116
These are in as much topological order as the underlying store can
102
These are in as much topological order as the underlying store can
117
103
present: for weaves ghosts may lead to a lack of correctness until
118
104
the reweave updates the parents list.
191
177
class WeaveMetaDirRepository(MetaDirVersionedFileRepository):
192
178
"""A subclass of MetaDirRepository to set weave specific policy."""
180
_serializer = xml5.serializer_v5
194
182
def __init__(self, _format, a_bzrdir, control_files):
195
183
super(WeaveMetaDirRepository, self).__init__(_format, a_bzrdir, control_files)
196
self._serializer = _format._serializer
184
self._fetch_order = 'topological'
185
self._fetch_reconcile = True
199
188
def _all_possible_ids(self):
206
195
def _all_revision_ids(self):
207
"""Returns a list of all the revision ids in the repository.
196
"""Returns a list of all the revision ids in the repository.
209
These are in as much topological order as the underlying store can
198
These are in as much topological order as the underlying store can
210
199
present: for weaves ghosts may lead to a lack of correctness until
211
200
the reweave updates the parents list.
267
256
supports_tree_reference = False
268
257
supports_ghosts = False
269
258
supports_external_lookups = False
270
supports_chks = False
271
_fetch_order = 'topological'
272
_fetch_reconcile = True
275
260
def initialize(self, a_bzrdir, shared=False, _internal=False):
276
261
"""Create a weave repository."""
280
265
if not _internal:
281
266
# always initialized when the bzrdir is.
282
267
return self.open(a_bzrdir, _found=True)
284
269
# Create an empty weave
286
271
weavefile.write_weave_v5(weave.Weave(), sio)
287
272
empty_weave = sio.getvalue()
289
274
mutter('creating repository in %s.', a_bzrdir.transport.base)
291
276
# FIXME: RBC 20060125 don't peek under the covers
292
277
# NB: no need to escape relative paths that are url safe.
293
278
control_files = lockable_files.LockableFiles(a_bzrdir.transport,
299
284
transport.mkdir_multi(['revision-store', 'weaves'],
300
285
mode=a_bzrdir._get_dir_mode())
301
transport.put_bytes_non_atomic('inventory.weave', empty_weave,
302
mode=a_bzrdir._get_file_mode())
286
transport.put_bytes_non_atomic('inventory.weave', empty_weave)
304
288
control_files.unlock()
305
289
return self.open(a_bzrdir, _found=True)
317
301
result.signatures = self._get_signatures(repo_transport, result)
318
302
result.inventories = self._get_inventories(repo_transport, result)
319
303
result.texts = self._get_texts(repo_transport, result)
320
result.chk_bytes = None
306
def check_conversion_target(self, target_format):
324
310
class RepositoryFormat4(PreSplitOutRepositoryFormat):
325
311
"""Bzr repository format 4.
336
322
_matchingbzrdir = bzrdir.BzrDirFormat4()
325
super(RepositoryFormat4, self).__init__()
326
self._fetch_order = 'topological'
327
self._fetch_reconcile = True
338
329
def get_format_description(self):
339
330
"""See RepositoryFormat.get_format_description()."""
340
331
return "Repository format 4"
347
338
"""Format 4 is not supported.
349
340
It is not supported because the model changed from 4 to 5 and the
350
conversion logic is expensive - so doing it on the fly was not
341
conversion logic is expensive - so doing it on the fly was not
383
374
_versionedfile_class = weave.WeaveFile
384
375
_matchingbzrdir = bzrdir.BzrDirFormat5()
386
def _serializer(self):
387
return xml5.serializer_v5
378
super(RepositoryFormat5, self).__init__()
379
self._fetch_order = 'topological'
380
self._fetch_reconcile = True
389
382
def get_format_description(self):
390
383
"""See RepositoryFormat.get_format_description()."""
391
384
return "Weave repository format 5"
393
def network_name(self):
394
"""The network name for this format is the control dirs disk label."""
395
return self._matchingbzrdir.get_format_string()
397
386
def _get_inventories(self, repo_transport, repo, name='inventory'):
398
387
mapper = versionedfile.ConstantMapper(name)
399
388
return versionedfile.ThunkedVersionedFiles(repo_transport,
400
389
weave.WeaveFile, mapper, repo.is_locked)
402
391
def _get_revisions(self, repo_transport, repo):
392
from bzrlib.xml5 import serializer_v5
403
393
return RevisionTextStore(repo_transport.clone('revision-store'),
404
xml5.serializer_v5, False, versionedfile.PrefixMapper(),
394
serializer_v5, False, versionedfile.PrefixMapper(),
405
395
repo.is_locked, repo.is_write_locked)
407
397
def _get_signatures(self, repo_transport, repo):
428
418
_versionedfile_class = weave.WeaveFile
429
419
_matchingbzrdir = bzrdir.BzrDirFormat6()
431
def _serializer(self):
432
return xml5.serializer_v5
422
super(RepositoryFormat6, self).__init__()
423
self._fetch_order = 'topological'
424
self._fetch_reconcile = True
434
426
def get_format_description(self):
435
427
"""See RepositoryFormat.get_format_description()."""
436
428
return "Weave repository format 6"
438
def network_name(self):
439
"""The network name for this format is the control dirs disk label."""
440
return self._matchingbzrdir.get_format_string()
442
430
def _get_inventories(self, repo_transport, repo, name='inventory'):
443
431
mapper = versionedfile.ConstantMapper(name)
444
432
return versionedfile.ThunkedVersionedFiles(repo_transport,
445
433
weave.WeaveFile, mapper, repo.is_locked)
447
435
def _get_revisions(self, repo_transport, repo):
436
from bzrlib.xml5 import serializer_v5
448
437
return RevisionTextStore(repo_transport.clone('revision-store'),
449
xml5.serializer_v5, False, versionedfile.HashPrefixMapper(),
438
serializer_v5, False, versionedfile.HashPrefixMapper(),
450
439
repo.is_locked, repo.is_write_locked)
452
441
def _get_signatures(self, repo_transport, repo):
476
465
_versionedfile_class = weave.WeaveFile
477
466
supports_ghosts = False
478
supports_chks = False
480
_fetch_order = 'topological'
481
_fetch_reconcile = True
484
def _serializer(self):
485
return xml5.serializer_v5
487
468
def get_format_string(self):
488
469
"""See RepositoryFormat.get_format_string()."""
492
473
"""See RepositoryFormat.get_format_description()."""
493
474
return "Weave repository format 7"
476
def check_conversion_target(self, target_format):
495
479
def _get_inventories(self, repo_transport, repo, name='inventory'):
496
480
mapper = versionedfile.ConstantMapper(name)
497
481
return versionedfile.ThunkedVersionedFiles(repo_transport,
498
482
weave.WeaveFile, mapper, repo.is_locked)
500
484
def _get_revisions(self, repo_transport, repo):
485
from bzrlib.xml5 import serializer_v5
501
486
return RevisionTextStore(repo_transport.clone('revision-store'),
502
xml5.serializer_v5, True, versionedfile.HashPrefixMapper(),
487
serializer_v5, True, versionedfile.HashPrefixMapper(),
503
488
repo.is_locked, repo.is_write_locked)
505
490
def _get_signatures(self, repo_transport, repo):
527
512
mutter('creating repository in %s.', a_bzrdir.transport.base)
528
513
dirs = ['revision-store', 'weaves']
529
files = [('inventory.weave', StringIO(empty_weave)),
514
files = [('inventory.weave', StringIO(empty_weave)),
531
516
utf8_files = [('format', self.get_format_string())]
533
518
self._upload_blank_content(a_bzrdir, dirs, files, utf8_files, shared)
534
519
return self.open(a_bzrdir=a_bzrdir, _found=True)
536
521
def open(self, a_bzrdir, _found=False, _override_transport=None):
537
522
"""See RepositoryFormat.open().
539
524
:param _override_transport: INTERNAL USE ONLY. Allows opening the
540
525
repository at a slightly different url
541
526
than normal. I.e. during 'upgrade'.
554
539
result.signatures = self._get_signatures(repo_transport, result)
555
540
result.inventories = self._get_inventories(repo_transport, result)
556
541
result.texts = self._get_texts(repo_transport, result)
557
result.chk_bytes = None
558
542
result._transport = repo_transport
664
648
result[key] = parents
667
def get_known_graph_ancestry(self, keys):
668
"""Get a KnownGraph instance with the ancestry of keys."""
670
parent_map = self.get_parent_map(keys)
671
kg = _mod_graph.KnownGraph(parent_map)
674
651
def get_record_stream(self, keys, sort_order, include_delta_closure):
676
653
text, parents = self._load_text_parents(key)
688
665
path, ext = os.path.splitext(relpath)
691
if not relpath.endswith('.sig'):
668
if '.sig' not in relpath:
692
669
relpaths.add(relpath)
693
670
paths = list(relpaths)
694
671
return set([self._mapper.unmap(path) for path in paths])