255
255
def copy_content_into(self, destination, revision_id=None, basis=None):
256
"""Make a complete copy of the content in self into destination."""
256
"""Make a complete copy of the content in self into destination.
258
This is a destructive operation! Do not use it on existing
257
261
destination.lock_write()
264
destination.set_make_working_trees(self.make_working_trees())
265
except NotImplementedError:
259
267
# optimised paths:
260
268
# compatible stores
261
269
if self._compatible_formats(destination):
321
329
bzrdir.BzrDirFormat6)):
322
330
result = a_bzrdir.open_repository()
324
result = self._format.initialize(a_bzrdir)
332
result = self._format.initialize(a_bzrdir, shared=self.is_shared())
325
333
self.copy_content_into(result, revision_id, basis)
513
521
return self.get_inventory(revision_id)
525
"""Return True if this repository is flagged as a shared repository."""
526
# FIXME format 4-6 cannot be shared, this is technically faulty.
527
return self.control_files._transport.has('shared-storage')
516
530
def revision_tree(self, revision_id):
517
531
"""Return Tree for a revision on this branch.
569
583
return self.control_files.get_transaction()
571
585
@needs_write_lock
586
def set_make_working_trees(self, new_value):
587
"""Set the policy flag for making working trees when creating branches.
589
This only applies to branches that use this repository.
591
The default is 'True'.
592
:param new_value: True to restore the default, False to disable making
595
# FIXME: split out into a new class/strategy ?
596
if isinstance(self._format, (RepositoryFormat4,
599
raise NotImplementedError(self.set_make_working_trees)
602
self.control_files._transport.delete('no-working-trees')
603
except errors.NoSuchFile:
606
self.control_files.put_utf8('no-working-trees', '')
608
def make_working_trees(self):
609
"""Returns the policy for making working trees on new branches."""
610
# FIXME: split out into a new class/strategy ?
611
if isinstance(self._format, (RepositoryFormat4,
615
return not self.control_files._transport.has('no-working-trees')
572
618
def sign_revision(self, revision_id, gpg_strategy):
573
619
plaintext = Testament.from_revision(self, revision_id).as_short_text()
574
620
self.store_revision_signature(gpg_strategy, plaintext, revision_id)
630
676
raise NotImplementedError(self.get_format_string)
632
def initialize(self, a_bzrdir, _internal=False):
633
"""Create a weave repository.
635
TODO: when creating split out bzr branch formats, move this to a common
636
base for Format5, Format6. or something like that.
678
def initialize(self, a_bzrdir, shared=False):
679
"""Initialize a repository of this format in a_bzrdir.
681
:param a_bzrdir: The bzrdir to put the new repository in it.
682
:param shared: The repository should be initialized as a sharable one.
684
This may raise UninitializableFormat if shared repository are not
685
compatible the a_bzrdir.
638
from bzrlib.weavefile import write_weave_v5
639
from bzrlib.weave import Weave
642
# always initialized when the bzrdir is.
643
return Repository(None, branch_format=None, _format=self, a_bzrdir=a_bzrdir)
645
# Create an empty weave
647
bzrlib.weavefile.write_weave_v5(Weave(), sio)
648
empty_weave = sio.getvalue()
650
mutter('creating repository in %s.', a_bzrdir.transport.base)
651
dirs = ['revision-store', 'weaves']
652
lock_file = 'branch-lock'
653
files = [('inventory.weave', StringIO(empty_weave)),
656
# FIXME: RBC 20060125 dont peek under the covers
657
# NB: no need to escape relative paths that are url safe.
658
control_files = LockableFiles(a_bzrdir.transport, 'branch-lock')
659
control_files.lock_write()
660
control_files._transport.mkdir_multi(dirs,
661
mode=control_files._dir_mode)
663
for file, content in files:
664
control_files.put(file, content)
666
control_files.unlock()
667
return Repository(None, branch_format=None, _format=self, a_bzrdir=a_bzrdir)
669
688
def is_supported(self):
670
689
"""Is this format supported?
699
718
del klass._formats[format.get_format_string()]
702
class RepositoryFormat4(RepositoryFormat):
721
class PreSplitOutRepositoryFormat(RepositoryFormat):
722
"""Base class for the pre split out repository formats."""
724
def initialize(self, a_bzrdir, shared=False, _internal=False):
725
"""Create a weave repository.
727
TODO: when creating split out bzr branch formats, move this to a common
728
base for Format5, Format6. or something like that.
730
from bzrlib.weavefile import write_weave_v5
731
from bzrlib.weave import Weave
734
raise errors.IncompatibleFormat(self, a_bzrdir._format)
737
# always initialized when the bzrdir is.
738
return Repository(None, branch_format=None, _format=self, a_bzrdir=a_bzrdir)
740
# Create an empty weave
742
bzrlib.weavefile.write_weave_v5(Weave(), sio)
743
empty_weave = sio.getvalue()
745
mutter('creating repository in %s.', a_bzrdir.transport.base)
746
dirs = ['revision-store', 'weaves']
747
lock_file = 'branch-lock'
748
files = [('inventory.weave', StringIO(empty_weave)),
751
# FIXME: RBC 20060125 dont peek under the covers
752
# NB: no need to escape relative paths that are url safe.
753
control_files = LockableFiles(a_bzrdir.transport, 'branch-lock')
754
control_files.lock_write()
755
control_files._transport.mkdir_multi(dirs,
756
mode=control_files._dir_mode)
758
for file, content in files:
759
control_files.put(file, content)
761
control_files.unlock()
762
return Repository(None, branch_format=None, _format=self, a_bzrdir=a_bzrdir)
765
class RepositoryFormat4(PreSplitOutRepositoryFormat):
703
766
"""Bzr repository format 4.
705
768
This repository format has:
715
778
super(RepositoryFormat4, self).__init__()
716
779
self._matchingbzrdir = bzrdir.BzrDirFormat4()
718
def initialize(self, url, _internal=False):
781
def initialize(self, url, shared=False, _internal=False):
719
782
"""Format 4 branches cannot be created."""
720
783
raise errors.UninitializableFormat(self)
765
828
- hash subdirectory based stores.
766
829
- TextStores for revisions and signatures.
767
830
- a format marker of its own
831
- an optional 'shared-storage' flag
770
834
def get_format_string(self):
771
835
"""See RepositoryFormat.get_format_string()."""
772
836
return "Bazaar-NG Repository format 7"
774
def initialize(self, a_bzrdir):
838
def initialize(self, a_bzrdir, shared=False):
775
839
"""Create a weave repository.
841
:param shared: If true the repository will be initialized as a shared
777
844
from bzrlib.weavefile import write_weave_v5
778
845
from bzrlib.weave import Weave
802
869
control_files.put(file, content)
803
870
for file, content in utf8_files:
804
871
control_files.put_utf8(file, content)
873
control_files.put_utf8('shared-storage', '')
806
875
control_files.unlock()
807
876
return Repository(None, branch_format=None, _format=self, a_bzrdir=a_bzrdir)