93
93
"""Construct the current default format repository in a_bzrdir."""
94
94
return RepositoryFormat.get_default_format().initialize(a_bzrdir)
96
def __init__(self, _format, a_bzrdir, control_files, revision_store, text_store):
96
def __init__(self, _format, a_bzrdir, control_files, revision_store, control_store, text_store):
97
97
"""instantiate a Repository.
99
99
:param _format: The format of the repository on disk.
114
114
self.text_store = text_store
115
115
# backwards compatability
116
116
self.weave_store = text_store
117
# not right yet - should be more semantically clear ?
119
self.control_store = control_store
120
self.control_weaves = control_store
118
122
def lock_write(self):
119
123
self.control_files.lock_write()
205
209
def get_revision(self, revision_id):
206
210
"""Return the Revision object for a named revision"""
207
xml_file = self.get_revision_xml_file(revision_id)
210
r = bzrlib.xml5.serializer_v5.read_revision(xml_file)
211
except SyntaxError, e:
212
raise bzrlib.errors.BzrError('failed to unpack revision_xml',
216
assert r.revision_id == revision_id
220
def get_revision_sha1(self, revision_id):
221
"""Hash the stored value of a revision, and return it."""
222
# In the future, revision entries will be signed. At that
223
# point, it is probably best *not* to include the signature
224
# in the revision hash. Because that lets you re-sign
225
# the revision, (add signatures/remove signatures) and still
226
# have all hash pointers stay consistent.
227
# But for now, just hash the contents.
228
return bzrlib.osutils.sha_file(self.get_revision_xml_file(revision_id))
211
if not revision_id or not isinstance(revision_id, basestring):
212
raise InvalidRevisionId(revision_id=revision_id, branch=self)
213
return self._revision_store.get_revision(revision_id,
214
self.get_transaction())
230
216
@needs_write_lock
231
217
def store_revision_signature(self, gpg_strategy, plaintext, revision_id):
467
453
class AllInOneRepository(Repository):
468
454
"""Legacy support - the repository behaviour for all-in-one branches."""
470
def __init__(self, _format, a_bzrdir, revision_store, text_store):
456
def __init__(self, _format, a_bzrdir, revision_store, control_store, text_store):
471
457
# we reuse one control files instance.
472
458
dir_mode = a_bzrdir._control_files._dir_mode
473
459
file_mode = a_bzrdir._control_files._file_mode
505
491
# not broken out yet because the controlweaves|inventory_store
506
492
# and text_store | weave_store bits are still different.
507
493
if isinstance(_format, RepositoryFormat4):
494
# cannot remove these - there is still no consistent api
495
# which allows access to this old info.
508
496
self.inventory_store = get_store('inventory-store')
509
497
text_store = get_store('text-store')
510
elif isinstance(_format, RepositoryFormat5):
511
self.control_weaves = get_weave('')
512
elif isinstance(_format, RepositoryFormat6):
513
self.control_weaves = get_weave('')
515
raise errors.BzrError('unreachable code: unexpected repository'
517
super(AllInOneRepository, self).__init__(_format, a_bzrdir, a_bzrdir._control_files, revision_store, text_store)
498
super(AllInOneRepository, self).__init__(_format, a_bzrdir, a_bzrdir._control_files, revision_store, control_store, text_store)
520
501
class MetaDirRepository(Repository):
521
502
"""Repositories in the new meta-dir layout."""
523
def __init__(self, _format, a_bzrdir, control_files, revision_store, text_store):
504
def __init__(self, _format, a_bzrdir, control_files, revision_store, control_store, text_store):
524
505
super(MetaDirRepository, self).__init__(_format,
530
512
dir_mode = self.control_files._dir_mode
544
526
ws.enable_cache = True
547
if isinstance(self._format, RepositoryFormat7):
548
self.control_weaves = get_weave('')
549
elif isinstance(self._format, RepositoryFormatKnit1):
550
self.control_weaves = get_weave('control')
552
raise errors.BzrError('unreachable code: unexpected repository'
556
530
class RepositoryFormat(object):
557
531
"""A repository format.
596
570
raise errors.UnknownFormatError(format_string)
572
def _get_control_store(self, repo_transport, control_files):
573
"""Return the control store for this repository."""
574
raise NotImplementedError(self._get_control_store)
599
577
def get_default_format(klass):
600
578
"""Return the current default format."""
732
710
control_files.unlock()
733
711
return self.open(a_bzrdir, _found=True)
713
def _get_control_store(self, repo_transport, control_files):
714
"""Return the control store for this repository."""
715
return self._get_versioned_file_store('',
735
720
def _get_text_store(self, transport, control_files):
736
721
"""Get a store for file texts for this format."""
737
722
raise NotImplementedError(self._get_text_store)
745
730
repo_transport = a_bzrdir.get_repository_transport(None)
746
731
control_files = a_bzrdir._control_files
732
text_store = self._get_text_store(repo_transport, control_files)
733
control_store = self._get_control_store(repo_transport, control_files)
747
734
revision_store = self._get_revision_store(repo_transport, control_files)
748
text_store = self._get_text_store(repo_transport, control_files)
749
735
return AllInOneRepository(_format=self,
750
736
a_bzrdir=a_bzrdir,
751
737
revision_store=revision_store,
738
control_store=control_store,
752
739
text_store=text_store)
771
def _get_control_store(self, repo_transport, control_files):
772
"""Format 4 repositories have no formal control store at this point.
774
This will cause any control-file-needing apis to fail - this is desired.
784
778
def _get_revision_store(self, repo_transport, control_files):
785
779
"""See RepositoryFormat._get_revision_store()."""
786
780
return self._get_text_rev_store(repo_transport,
860
854
control_files = LockableFiles(repository_transport, 'lock')
861
855
return control_files
857
def _get_control_store(self, repo_transport, control_files):
858
"""Return the control store for this repository."""
859
return self._get_versioned_file_store('',
863
864
def _get_revision_store(self, repo_transport, control_files):
864
865
"""See RepositoryFormat._get_revision_store()."""
865
866
return self._get_text_rev_store(repo_transport,
885
886
repo_transport = a_bzrdir.get_repository_transport(None)
886
887
control_files = LockableFiles(repo_transport, 'lock')
888
text_store = self._get_text_store(repo_transport, control_files)
889
control_store = self._get_control_store(repo_transport, control_files)
887
890
revision_store = self._get_revision_store(repo_transport, control_files)
888
text_store = self._get_text_store(repo_transport, control_files)
889
891
return MetaDirRepository(_format=self,
890
892
a_bzrdir=a_bzrdir,
891
893
control_files=control_files,
892
894
revision_store=revision_store,
895
control_store=control_store,
893
896
text_store=text_store)
895
898
def _upload_blank_content(self, a_bzrdir, dirs, files, utf8_files, shared):