54
71
# some existing branches where there's a mixture; we probably
55
72
# still want the option to look for both.
56
73
relpath = a_bzrdir._control_files._escape(name)
57
store = TextStore(a_bzrdir._control_files._transport.clone(relpath),
74
store = TextStore(a_bzrdir.transport.clone(relpath),
58
75
prefixed=prefixed, compressed=compressed,
60
77
file_mode=file_mode)
61
#if self._transport.should_cache():
62
# cache_path = os.path.join(self.cache_root, name)
63
# os.mkdir(cache_path)
64
# store = bzrlib.store.CachedStore(store, cache_path)
67
80
# not broken out yet because the controlweaves|inventory_store
68
# and text_store | weave_store bits are still different.
81
# and texts bits are still different.
69
82
if isinstance(_format, RepositoryFormat4):
70
83
# cannot remove these - there is still no consistent api
71
84
# which allows access to this old info.
72
85
self.inventory_store = get_store('inventory-store')
73
text_store = get_store('text-store')
74
super(AllInOneRepository, self).__init__(_format, a_bzrdir, a_bzrdir._control_files, _revision_store, control_store, text_store)
86
self._text_store = get_store('text-store')
87
super(AllInOneRepository, self).__init__(_format, a_bzrdir, a_bzrdir._control_files)
88
self._fetch_order = 'topological'
89
self._fetch_reconcile = True
92
def _all_possible_ids(self):
93
"""Return all the possible revisions that we could find."""
94
if 'evil' in debug.debug_flags:
95
mutter_callsite(3, "_all_possible_ids scales with size of history.")
96
return [key[-1] for key in self.inventories.keys()]
99
def _all_revision_ids(self):
100
"""Returns a list of all the revision ids in the repository.
102
These are in as much topological order as the underlying store can
103
present: for weaves ghosts may lead to a lack of correctness until
104
the reweave updates the parents list.
106
return [key[-1] for key in self.revisions.keys()]
108
def _activate_new_inventory(self):
109
"""Put a replacement inventory.new into use as inventories."""
110
# Copy the content across
111
t = self.bzrdir._control_files._transport
112
t.copy('inventory.new.weave', 'inventory.weave')
113
# delete the temp inventory
114
t.delete('inventory.new.weave')
115
# Check we can parse the new weave properly as a sanity check
116
self.inventories.keys()
118
def _backup_inventory(self):
119
t = self.bzrdir._control_files._transport
120
t.copy('inventory.weave', 'inventory.backup.weave')
122
def _temp_inventories(self):
123
t = self.bzrdir._control_files._transport
124
return self._format._get_inventories(t, self, 'inventory.new')
76
126
def get_commit_builder(self, branch, parents, config, timestamp=None,
77
127
timezone=None, committer=None, revprops=None,
78
128
revision_id=None):
79
129
self._check_ascii_revisionid(revision_id, self.get_commit_builder)
80
return Repository.get_commit_builder(self, branch, parents, config,
81
timestamp, timezone, committer, revprops, revision_id)
130
result = CommitBuilder(self, parents, config, timestamp, timezone,
131
committer, revprops, revision_id)
132
self.start_write_group()
136
def get_revisions(self, revision_ids):
137
revs = self._get_revisions(revision_ids)
140
def _inventory_add_lines(self, revision_id, parents, lines,
142
"""Store lines in inv_vf and return the sha1 of the inventory."""
143
present_parents = self.get_graph().get_parent_map(parents)
145
for parent in parents:
146
if parent in present_parents:
147
final_parents.append((parent,))
148
return self.inventories.add_lines((revision_id,), final_parents, lines,
149
check_content=check_content)[0]
84
151
def is_shared(self):
85
152
"""AllInOne repositories cannot be shared."""
95
162
:param new_value: True to restore the default, False to disable making
98
raise NotImplementedError(self.set_make_working_trees)
165
raise errors.RepositoryUpgradeRequired(self.bzrdir.root_transport.base)
100
167
def make_working_trees(self):
101
168
"""Returns the policy for making working trees on new branches."""
105
class WeaveMetaDirRepository(MetaDirRepository):
171
def revision_graph_can_have_wrong_parents(self):
172
# XXX: This is an old format that we don't support full checking on, so
173
# just claim that checking for this inconsistency is not required.
177
class WeaveMetaDirRepository(MetaDirVersionedFileRepository):
106
178
"""A subclass of MetaDirRepository to set weave specific policy."""
108
180
_serializer = xml5.serializer_v5
182
def __init__(self, _format, a_bzrdir, control_files):
183
super(WeaveMetaDirRepository, self).__init__(_format, a_bzrdir, control_files)
184
self._fetch_order = 'topological'
185
self._fetch_reconcile = True
188
def _all_possible_ids(self):
189
"""Return all the possible revisions that we could find."""
190
if 'evil' in debug.debug_flags:
191
mutter_callsite(3, "_all_possible_ids scales with size of history.")
192
return [key[-1] for key in self.inventories.keys()]
195
def _all_revision_ids(self):
196
"""Returns a list of all the revision ids in the repository.
198
These are in as much topological order as the underlying store can
199
present: for weaves ghosts may lead to a lack of correctness until
200
the reweave updates the parents list.
202
return [key[-1] for key in self.revisions.keys()]
204
def _activate_new_inventory(self):
205
"""Put a replacement inventory.new into use as inventories."""
206
# Copy the content across
208
t.copy('inventory.new.weave', 'inventory.weave')
209
# delete the temp inventory
210
t.delete('inventory.new.weave')
211
# Check we can parse the new weave properly as a sanity check
212
self.inventories.keys()
214
def _backup_inventory(self):
216
t.copy('inventory.weave', 'inventory.backup.weave')
218
def _temp_inventories(self):
220
return self._format._get_inventories(t, self, 'inventory.new')
110
222
def get_commit_builder(self, branch, parents, config, timestamp=None,
111
223
timezone=None, committer=None, revprops=None,
112
224
revision_id=None):
113
225
self._check_ascii_revisionid(revision_id, self.get_commit_builder)
114
return MetaDirRepository.get_commit_builder(self, branch, parents,
115
config, timestamp, timezone, committer, revprops, revision_id)
226
result = CommitBuilder(self, parents, config, timestamp, timezone,
227
committer, revprops, revision_id)
228
self.start_write_group()
232
def get_revision(self, revision_id):
233
"""Return the Revision object for a named revision"""
234
r = self.get_revision_reconcile(revision_id)
237
def _inventory_add_lines(self, revision_id, parents, lines,
239
"""Store lines in inv_vf and return the sha1 of the inventory."""
240
present_parents = self.get_graph().get_parent_map(parents)
242
for parent in parents:
243
if parent in present_parents:
244
final_parents.append((parent,))
245
return self.inventories.add_lines((revision_id,), final_parents, lines,
246
check_content=check_content)[0]
248
def revision_graph_can_have_wrong_parents(self):
118
252
class PreSplitOutRepositoryFormat(RepositoryFormat):
140
272
empty_weave = sio.getvalue()
142
274
mutter('creating repository in %s.', a_bzrdir.transport.base)
143
dirs = ['revision-store', 'weaves']
144
files = [('inventory.weave', StringIO(empty_weave)),
147
276
# FIXME: RBC 20060125 don't peek under the covers
148
277
# NB: no need to escape relative paths that are url safe.
149
278
control_files = lockable_files.LockableFiles(a_bzrdir.transport,
150
'branch-lock', lockable_files.TransportLock)
279
'branch-lock', lockable_files.TransportLock)
151
280
control_files.create_lock()
152
281
control_files.lock_write()
153
control_files._transport.mkdir_multi(dirs,
154
mode=control_files._dir_mode)
282
transport = a_bzrdir.transport
156
for file, content in files:
157
control_files.put(file, content)
284
transport.mkdir_multi(['revision-store', 'weaves'],
285
mode=a_bzrdir._get_dir_mode())
286
transport.put_bytes_non_atomic('inventory.weave', empty_weave)
159
288
control_files.unlock()
160
289
return self.open(a_bzrdir, _found=True)
162
def _get_control_store(self, repo_transport, control_files):
163
"""Return the control store for this repository."""
164
return self._get_versioned_file_store('',
169
def _get_text_store(self, transport, control_files):
170
"""Get a store for file texts for this format."""
171
raise NotImplementedError(self._get_text_store)
173
291
def open(self, a_bzrdir, _found=False):
174
292
"""See RepositoryFormat.open()."""
228
def _get_control_store(self, repo_transport, control_files):
229
"""Format 4 repositories have no formal control store at this point.
231
This will cause any control-file-needing apis to fail - this is desired.
346
def _get_inventories(self, repo_transport, repo, name='inventory'):
347
# No inventories store written so far.
235
def _get_revision_store(self, repo_transport, control_files):
236
"""See RepositoryFormat._get_revision_store()."""
350
def _get_revisions(self, repo_transport, repo):
237
351
from bzrlib.xml4 import serializer_v4
238
return self._get_text_rev_store(repo_transport,
241
serializer=serializer_v4)
243
def _get_text_store(self, transport, control_files):
244
"""See RepositoryFormat._get_text_store()."""
352
return RevisionTextStore(repo_transport.clone('revision-store'),
353
serializer_v4, True, versionedfile.PrefixMapper(),
354
repo.is_locked, repo.is_write_locked)
356
def _get_signatures(self, repo_transport, repo):
357
return SignatureTextStore(repo_transport.clone('revision-store'),
358
False, versionedfile.PrefixMapper(),
359
repo.is_locked, repo.is_write_locked)
361
def _get_texts(self, repo_transport, repo):
247
365
class RepositoryFormat5(PreSplitOutRepositoryFormat):
259
377
def __init__(self):
260
378
super(RepositoryFormat5, self).__init__()
379
self._fetch_order = 'topological'
380
self._fetch_reconcile = True
262
382
def get_format_description(self):
263
383
"""See RepositoryFormat.get_format_description()."""
264
384
return "Weave repository format 5"
266
def _get_revision_store(self, repo_transport, control_files):
267
"""See RepositoryFormat._get_revision_store()."""
268
"""Return the revision store object for this a_bzrdir."""
269
return self._get_text_rev_store(repo_transport,
274
def _get_text_store(self, transport, control_files):
275
"""See RepositoryFormat._get_text_store()."""
276
return self._get_versioned_file_store('weaves', transport, control_files, prefixed=False)
386
def _get_inventories(self, repo_transport, repo, name='inventory'):
387
mapper = versionedfile.ConstantMapper(name)
388
return versionedfile.ThunkedVersionedFiles(repo_transport,
389
weave.WeaveFile, mapper, repo.is_locked)
391
def _get_revisions(self, repo_transport, repo):
392
from bzrlib.xml5 import serializer_v5
393
return RevisionTextStore(repo_transport.clone('revision-store'),
394
serializer_v5, False, versionedfile.PrefixMapper(),
395
repo.is_locked, repo.is_write_locked)
397
def _get_signatures(self, repo_transport, repo):
398
return SignatureTextStore(repo_transport.clone('revision-store'),
399
False, versionedfile.PrefixMapper(),
400
repo.is_locked, repo.is_write_locked)
402
def _get_texts(self, repo_transport, repo):
403
mapper = versionedfile.PrefixMapper()
404
base_transport = repo_transport.clone('weaves')
405
return versionedfile.ThunkedVersionedFiles(base_transport,
406
weave.WeaveFile, mapper, repo.is_locked)
279
409
class RepositoryFormat6(PreSplitOutRepositoryFormat):
291
421
def __init__(self):
292
422
super(RepositoryFormat6, self).__init__()
423
self._fetch_order = 'topological'
424
self._fetch_reconcile = True
294
426
def get_format_description(self):
295
427
"""See RepositoryFormat.get_format_description()."""
296
428
return "Weave repository format 6"
298
def _get_revision_store(self, repo_transport, control_files):
299
"""See RepositoryFormat._get_revision_store()."""
300
return self._get_text_rev_store(repo_transport,
306
def _get_text_store(self, transport, control_files):
307
"""See RepositoryFormat._get_text_store()."""
308
return self._get_versioned_file_store('weaves', transport, control_files)
430
def _get_inventories(self, repo_transport, repo, name='inventory'):
431
mapper = versionedfile.ConstantMapper(name)
432
return versionedfile.ThunkedVersionedFiles(repo_transport,
433
weave.WeaveFile, mapper, repo.is_locked)
435
def _get_revisions(self, repo_transport, repo):
436
from bzrlib.xml5 import serializer_v5
437
return RevisionTextStore(repo_transport.clone('revision-store'),
438
serializer_v5, False, versionedfile.HashPrefixMapper(),
439
repo.is_locked, repo.is_write_locked)
441
def _get_signatures(self, repo_transport, repo):
442
return SignatureTextStore(repo_transport.clone('revision-store'),
443
False, versionedfile.HashPrefixMapper(),
444
repo.is_locked, repo.is_write_locked)
446
def _get_texts(self, repo_transport, repo):
447
mapper = versionedfile.HashPrefixMapper()
448
base_transport = repo_transport.clone('weaves')
449
return versionedfile.ThunkedVersionedFiles(base_transport,
450
weave.WeaveFile, mapper, repo.is_locked)
311
453
class RepositoryFormat7(MetaDirRepositoryFormat):
340
476
def check_conversion_target(self, target_format):
343
def _get_revision_store(self, repo_transport, control_files):
344
"""See RepositoryFormat._get_revision_store()."""
345
return self._get_text_rev_store(repo_transport,
352
def _get_text_store(self, transport, control_files):
353
"""See RepositoryFormat._get_text_store()."""
354
return self._get_versioned_file_store('weaves',
479
def _get_inventories(self, repo_transport, repo, name='inventory'):
480
mapper = versionedfile.ConstantMapper(name)
481
return versionedfile.ThunkedVersionedFiles(repo_transport,
482
weave.WeaveFile, mapper, repo.is_locked)
484
def _get_revisions(self, repo_transport, repo):
485
from bzrlib.xml5 import serializer_v5
486
return RevisionTextStore(repo_transport.clone('revision-store'),
487
serializer_v5, True, versionedfile.HashPrefixMapper(),
488
repo.is_locked, repo.is_write_locked)
490
def _get_signatures(self, repo_transport, repo):
491
return SignatureTextStore(repo_transport.clone('revision-store'),
492
True, versionedfile.HashPrefixMapper(),
493
repo.is_locked, repo.is_write_locked)
495
def _get_texts(self, repo_transport, repo):
496
mapper = versionedfile.HashPrefixMapper()
497
base_transport = repo_transport.clone('weaves')
498
return versionedfile.ThunkedVersionedFiles(base_transport,
499
weave.WeaveFile, mapper, repo.is_locked)
358
501
def initialize(self, a_bzrdir, shared=False):
359
502
"""Create a weave repository.
386
529
format = RepositoryFormat.find_format(a_bzrdir)
387
assert format.__class__ == self.__class__
388
530
if _override_transport is not None:
389
531
repo_transport = _override_transport
391
533
repo_transport = a_bzrdir.get_repository_transport(None)
392
534
control_files = lockable_files.LockableFiles(repo_transport,
393
535
'lock', lockdir.LockDir)
394
text_store = self._get_text_store(repo_transport, control_files)
395
control_store = self._get_control_store(repo_transport, control_files)
396
_revision_store = self._get_revision_store(repo_transport, control_files)
397
return WeaveMetaDirRepository(_format=self,
399
control_files=control_files,
400
_revision_store=_revision_store,
401
control_store=control_store,
402
text_store=text_store)
536
result = WeaveMetaDirRepository(_format=self, a_bzrdir=a_bzrdir,
537
control_files=control_files)
538
result.revisions = self._get_revisions(repo_transport, result)
539
result.signatures = self._get_signatures(repo_transport, result)
540
result.inventories = self._get_inventories(repo_transport, result)
541
result.texts = self._get_texts(repo_transport, result)
542
result._transport = repo_transport
546
class TextVersionedFiles(VersionedFiles):
547
"""Just-a-bunch-of-files based VersionedFile stores."""
549
def __init__(self, transport, compressed, mapper, is_locked, can_write):
550
self._compressed = compressed
551
self._transport = transport
552
self._mapper = mapper
557
self._is_locked = is_locked
558
self._can_write = can_write
560
def add_lines(self, key, parents, lines):
561
"""Add a revision to the store."""
562
if not self._is_locked():
563
raise errors.ObjectNotLocked(self)
564
if not self._can_write():
565
raise errors.ReadOnlyError(self)
567
raise ValueError('bad idea to put / in %r' % (key,))
568
text = ''.join(lines)
570
text = bytes_to_gzip(text)
571
path = self._map(key)
572
self._transport.put_bytes_non_atomic(path, text, create_parent_dir=True)
574
def insert_record_stream(self, stream):
576
for record in stream:
577
# Raise an error when a record is missing.
578
if record.storage_kind == 'absent':
579
raise errors.RevisionNotPresent([record.key[0]], self)
580
# adapt to non-tuple interface
581
if record.storage_kind == 'fulltext':
582
self.add_lines(record.key, None,
583
osutils.split_lines(record.get_bytes_as('fulltext')))
585
adapter_key = record.storage_kind, 'fulltext'
587
adapter = adapters[adapter_key]
589
adapter_factory = adapter_registry.get(adapter_key)
590
adapter = adapter_factory(self)
591
adapters[adapter_key] = adapter
592
lines = osutils.split_lines(adapter.get_bytes(
593
record, record.get_bytes_as(record.storage_kind)))
595
self.add_lines(record.key, None, lines)
596
except RevisionAlreadyPresent:
599
def _load_text(self, key):
600
if not self._is_locked():
601
raise errors.ObjectNotLocked(self)
602
path = self._map(key)
604
text = self._transport.get_bytes(path)
605
compressed = self._compressed
606
except errors.NoSuchFile:
608
# try without the .gz
611
text = self._transport.get_bytes(path)
613
except errors.NoSuchFile:
618
text = GzipFile(mode='rb', fileobj=StringIO(text)).read()
622
return self._mapper.map(key) + self._ext
625
class RevisionTextStore(TextVersionedFiles):
626
"""Legacy thunk for format 4 repositories."""
628
def __init__(self, transport, serializer, compressed, mapper, is_locked,
630
"""Create a RevisionTextStore at transport with serializer."""
631
TextVersionedFiles.__init__(self, transport, compressed, mapper,
632
is_locked, can_write)
633
self._serializer = serializer
635
def _load_text_parents(self, key):
636
text = self._load_text(key)
639
parents = self._serializer.read_revision_from_string(text).parent_ids
640
return text, tuple((parent,) for parent in parents)
642
def get_parent_map(self, keys):
645
parents = self._load_text_parents(key)[1]
648
result[key] = parents
651
def get_record_stream(self, keys, sort_order, include_delta_closure):
653
text, parents = self._load_text_parents(key)
655
yield AbsentContentFactory(key)
657
yield FulltextContentFactory(key, parents, None, text)
660
if not self._is_locked():
661
raise errors.ObjectNotLocked(self)
663
for quoted_relpath in self._transport.iter_files_recursive():
664
relpath = urllib.unquote(quoted_relpath)
665
path, ext = os.path.splitext(relpath)
668
if '.sig' not in relpath:
669
relpaths.add(relpath)
670
paths = list(relpaths)
671
return set([self._mapper.unmap(path) for path in paths])
674
class SignatureTextStore(TextVersionedFiles):
675
"""Legacy thunk for format 4-7 repositories."""
677
def __init__(self, transport, compressed, mapper, is_locked, can_write):
678
TextVersionedFiles.__init__(self, transport, compressed, mapper,
679
is_locked, can_write)
680
self._ext = '.sig' + self._ext
682
def get_parent_map(self, keys):
685
text = self._load_text(key)
691
def get_record_stream(self, keys, sort_order, include_delta_closure):
693
text = self._load_text(key)
695
yield AbsentContentFactory(key)
697
yield FulltextContentFactory(key, None, None, text)
700
if not self._is_locked():
701
raise errors.ObjectNotLocked(self)
703
for quoted_relpath in self._transport.iter_files_recursive():
704
relpath = urllib.unquote(quoted_relpath)
705
path, ext = os.path.splitext(relpath)
708
if not relpath.endswith('.sig'):
710
relpaths.add(relpath[:-4])
711
paths = list(relpaths)
712
return set([self._mapper.unmap(path) for path in paths])
405
714
_legacy_formats = [RepositoryFormat4(),
406
715
RepositoryFormat5(),