70
71
def __init__(self, transport, branch_format, _format=None, a_bzrdir=None):
71
72
object.__init__(self)
72
73
if transport is not None:
74
warn("Repository.__init__(..., transport=XXX): The transport parameter is "
75
"deprecated and was never in a supported release. Please use "
76
"bzrdir.open_repository() or bzrdir.open_branch().repository.",
73
79
self.control_files = LockableFiles(transport.clone(bzrlib.BZRDIR), 'README')
75
81
# TODO: clone into repository if needed
76
self.control_files = LockableFiles(a_bzrdir.transport, 'README')
82
self.control_files = LockableFiles(a_bzrdir.get_repository_transport(None), 'README')
78
84
dir_mode = self.control_files._dir_mode
79
85
file_mode = self.control_files._file_mode
142
148
self.weave_store = get_weave('weaves', prefixed=True)
143
149
self.revision_store = get_store('revision-store', compressed=False,
151
elif isinstance(self._format, RepositoryFormat7):
152
self.control_weaves = get_weave('')
153
self.weave_store = get_weave('weaves', prefixed=True)
154
self.revision_store = get_store('revision-store', compressed=False,
145
156
self.revision_store.register_suffix('sig')
147
158
def lock_write(self):
319
330
to have a single line per file/directory, and to have
320
331
fileid="" and revision="" on that line.
322
assert (isinstance(self._format, RepositoryFormat5) or
323
isinstance(self._format, RepositoryFormat6)), \
324
"fileid_involved only supported for branches which store inventory as xml"
333
assert isinstance(self._format, (RepositoryFormat5,
335
RepositoryFormat7)), \
336
"fileid_involved only supported for branches which store inventory as unnested xml"
326
338
w = self.get_inventory_weave()
485
497
"""The known formats."""
500
def find_format(klass, a_bzrdir):
501
"""Return the format for the repository object in a_bzrdir."""
503
transport = a_bzrdir.get_repository_transport(None)
504
format_string = transport.get("format").read()
505
return klass._formats[format_string]
506
except errors.NoSuchFile:
507
raise errors.NoRepositoryPresent(a_bzrdir)
509
raise errors.UnknownFormatError(format_string)
488
512
def get_default_format(klass):
489
513
"""Return the current default format."""
490
514
return klass._default_format
620
644
super(RepositoryFormat6, self).__init__()
621
645
self._matchingbzrdir = bzrdir.BzrDirFormat6()
648
class RepositoryFormat7(RepositoryFormat):
651
This repository format has:
652
- weaves for file texts and inventory
653
- hash subdirectory based stores.
654
- TextStores for revisions and signatures.
655
- a format marker of its own
658
def get_format_string(self):
659
"""See RepositoryFormat.get_format_string()."""
660
return "Bazaar-NG Repository format 7"
662
def initialize(self, a_bzrdir):
663
"""Create a weave repository.
665
from bzrlib.weavefile import write_weave_v5
666
from bzrlib.weave import Weave
668
# Create an empty weave
670
bzrlib.weavefile.write_weave_v5(Weave(), sio)
671
empty_weave = sio.getvalue()
673
mutter('creating repository in %s.', a_bzrdir.transport.base)
674
dirs = ['revision-store', 'weaves']
675
files = [('inventory.weave', StringIO(empty_weave)),
677
utf8_files = [('format', self.get_format_string())]
679
# FIXME: RBC 20060125 dont peek under the covers
680
# NB: no need to escape relative paths that are url safe.
682
repository_transport = a_bzrdir.get_repository_transport(self)
683
repository_transport.put(lock_file, StringIO()) # TODO get the file mode from the bzrdir lock files., mode=file_mode)
684
control_files = LockableFiles(repository_transport, 'lock')
685
control_files.lock_write()
686
control_files._transport.mkdir_multi(dirs,
687
mode=control_files._dir_mode)
689
for file, content in files:
690
control_files.put(file, content)
691
for file, content in utf8_files:
692
control_files.put_utf8(file, content)
694
control_files.unlock()
695
return Repository(None, branch_format=None, _format=self, a_bzrdir=a_bzrdir)
698
super(RepositoryFormat7, self).__init__()
699
self._matchingbzrdir = bzrdir.BzrDirMetaFormat1()
623
702
# formats which have no format string are not discoverable
624
703
# and not independently creatable, so are not registered.
625
# __default_format = RepositoryFormatXXX()
626
# RepositoryFormat.register_format(__default_format)
627
# RepositoryFormat.set_default_format(__default_format)
704
__default_format = RepositoryFormat7()
705
RepositoryFormat.register_format(__default_format)
706
RepositoryFormat.set_default_format(__default_format)
628
707
_legacy_formats = [RepositoryFormat4(),
629
708
RepositoryFormat5(),
630
709
RepositoryFormat6()]