276
532
def get_transaction(self):
277
533
return self.control_files.get_transaction()
535
def revision_parents(self, revid):
536
return self.get_inventory_weave().parent_names(revid)
539
def set_make_working_trees(self, new_value):
540
"""Set the policy flag for making working trees when creating branches.
542
This only applies to branches that use this repository.
544
The default is 'True'.
545
:param new_value: True to restore the default, False to disable making
548
# FIXME: split out into a new class/strategy ?
549
if isinstance(self._format, (RepositoryFormat4,
552
raise NotImplementedError(self.set_make_working_trees)
555
self.control_files._transport.delete('no-working-trees')
556
except errors.NoSuchFile:
559
self.control_files.put_utf8('no-working-trees', '')
561
def make_working_trees(self):
562
"""Returns the policy for making working trees on new branches."""
563
# FIXME: split out into a new class/strategy ?
564
if isinstance(self._format, (RepositoryFormat4,
568
return not self.control_files._transport.has('no-working-trees')
279
570
@needs_write_lock
280
571
def sign_revision(self, revision_id, gpg_strategy):
281
572
plaintext = Testament.from_revision(self, revision_id).as_short_text()
282
573
self.store_revision_signature(gpg_strategy, plaintext, revision_id)
576
class AllInOneRepository(Repository):
577
"""Legacy support - the repository behaviour for all-in-one branches."""
579
def __init__(self, _format, a_bzrdir, revision_store):
580
# we reuse one control files instance.
581
dir_mode = a_bzrdir._control_files._dir_mode
582
file_mode = a_bzrdir._control_files._file_mode
584
def get_weave(name, prefixed=False):
586
name = safe_unicode(name)
589
relpath = a_bzrdir._control_files._escape(name)
590
weave_transport = a_bzrdir._control_files._transport.clone(relpath)
591
ws = WeaveStore(weave_transport, prefixed=prefixed,
594
if a_bzrdir._control_files._transport.should_cache():
595
ws.enable_cache = True
598
def get_store(name, compressed=True, prefixed=False):
599
# FIXME: This approach of assuming stores are all entirely compressed
600
# or entirely uncompressed is tidy, but breaks upgrade from
601
# some existing branches where there's a mixture; we probably
602
# still want the option to look for both.
603
relpath = a_bzrdir._control_files._escape(name)
604
store = TextStore(a_bzrdir._control_files._transport.clone(relpath),
605
prefixed=prefixed, compressed=compressed,
608
#if self._transport.should_cache():
609
# cache_path = os.path.join(self.cache_root, name)
610
# os.mkdir(cache_path)
611
# store = bzrlib.store.CachedStore(store, cache_path)
614
# not broken out yet because the controlweaves|inventory_store
615
# and text_store | weave_store bits are still different.
616
if isinstance(_format, RepositoryFormat4):
617
self.inventory_store = get_store('inventory-store')
618
self.text_store = get_store('text-store')
619
elif isinstance(_format, RepositoryFormat5):
620
self.control_weaves = get_weave('')
621
self.weave_store = get_weave('weaves')
622
elif isinstance(_format, RepositoryFormat6):
623
self.control_weaves = get_weave('')
624
self.weave_store = get_weave('weaves', prefixed=True)
626
raise errors.BzrError('unreachable code: unexpected repository'
628
revision_store.register_suffix('sig')
629
super(AllInOneRepository, self).__init__(_format, a_bzrdir, a_bzrdir._control_files, revision_store)
632
class MetaDirRepository(Repository):
633
"""Repositories in the new meta-dir layout."""
635
def __init__(self, _format, a_bzrdir, control_files, revision_store):
636
super(MetaDirRepository, self).__init__(_format,
641
dir_mode = self.control_files._dir_mode
642
file_mode = self.control_files._file_mode
644
def get_weave(name, prefixed=False):
646
name = safe_unicode(name)
649
relpath = self.control_files._escape(name)
650
weave_transport = self.control_files._transport.clone(relpath)
651
ws = WeaveStore(weave_transport, prefixed=prefixed,
654
if self.control_files._transport.should_cache():
655
ws.enable_cache = True
658
if isinstance(self._format, RepositoryFormat7):
659
self.control_weaves = get_weave('')
660
self.weave_store = get_weave('weaves', prefixed=True)
661
elif isinstance(self._format, RepositoryFormatKnit1):
662
self.control_weaves = get_weave('')
663
self.weave_store = get_weave('knits', prefixed=True)
665
raise errors.BzrError('unreachable code: unexpected repository'
669
class RepositoryFormat(object):
670
"""A repository format.
672
Formats provide three things:
673
* An initialization routine to construct repository data on disk.
674
* a format string which is used when the BzrDir supports versioned
676
* an open routine which returns a Repository instance.
678
Formats are placed in an dict by their format string for reference
679
during opening. These should be subclasses of RepositoryFormat
682
Once a format is deprecated, just deprecate the initialize and open
683
methods on the format class. Do not deprecate the object, as the
684
object will be created every system load.
686
Common instance attributes:
687
_matchingbzrdir - the bzrdir format that the repository format was
688
originally written to work with. This can be used if manually
689
constructing a bzrdir and repository, or more commonly for test suite
693
_default_format = None
694
"""The default format used for new repositories."""
697
"""The known formats."""
700
def find_format(klass, a_bzrdir):
701
"""Return the format for the repository object in a_bzrdir."""
703
transport = a_bzrdir.get_repository_transport(None)
704
format_string = transport.get("format").read()
705
return klass._formats[format_string]
706
except errors.NoSuchFile:
707
raise errors.NoRepositoryPresent(a_bzrdir)
709
raise errors.UnknownFormatError(format_string)
712
def get_default_format(klass):
713
"""Return the current default format."""
714
return klass._default_format
716
def get_format_string(self):
717
"""Return the ASCII format string that identifies this format.
719
Note that in pre format ?? repositories the format string is
720
not permitted nor written to disk.
722
raise NotImplementedError(self.get_format_string)
724
def _get_revision_store(self, repo_transport, control_files):
725
"""Return the revision store object for this a_bzrdir."""
726
raise NotImplementedError(self._get_revision_store)
728
def _get_rev_store(self,
734
"""Common logic for getting a revision store for a repository.
736
see self._get_revision_store for the method to
737
get the store for a repository.
740
name = safe_unicode(name)
743
dir_mode = control_files._dir_mode
744
file_mode = control_files._file_mode
745
revision_store =TextStore(transport.clone(name),
747
compressed=compressed,
750
revision_store.register_suffix('sig')
751
return revision_store
753
def initialize(self, a_bzrdir, shared=False):
754
"""Initialize a repository of this format in a_bzrdir.
756
:param a_bzrdir: The bzrdir to put the new repository in it.
757
:param shared: The repository should be initialized as a sharable one.
759
This may raise UninitializableFormat if shared repository are not
760
compatible the a_bzrdir.
763
def is_supported(self):
764
"""Is this format supported?
766
Supported formats must be initializable and openable.
767
Unsupported formats may not support initialization or committing or
768
some other features depending on the reason for not being supported.
772
def open(self, a_bzrdir, _found=False):
773
"""Return an instance of this format for the bzrdir a_bzrdir.
775
_found is a private parameter, do not use it.
777
raise NotImplementedError(self.open)
780
def register_format(klass, format):
781
klass._formats[format.get_format_string()] = format
784
def set_default_format(klass, format):
785
klass._default_format = format
788
def unregister_format(klass, format):
789
assert klass._formats[format.get_format_string()] is format
790
del klass._formats[format.get_format_string()]
793
class PreSplitOutRepositoryFormat(RepositoryFormat):
794
"""Base class for the pre split out repository formats."""
796
def initialize(self, a_bzrdir, shared=False, _internal=False):
797
"""Create a weave repository.
799
TODO: when creating split out bzr branch formats, move this to a common
800
base for Format5, Format6. or something like that.
802
from bzrlib.weavefile import write_weave_v5
803
from bzrlib.weave import Weave
806
raise errors.IncompatibleFormat(self, a_bzrdir._format)
809
# always initialized when the bzrdir is.
810
return self.open(a_bzrdir, _found=True)
812
# Create an empty weave
814
bzrlib.weavefile.write_weave_v5(Weave(), sio)
815
empty_weave = sio.getvalue()
817
mutter('creating repository in %s.', a_bzrdir.transport.base)
818
dirs = ['revision-store', 'weaves']
819
files = [('inventory.weave', StringIO(empty_weave)),
822
# FIXME: RBC 20060125 dont peek under the covers
823
# NB: no need to escape relative paths that are url safe.
824
control_files = LockableFiles(a_bzrdir.transport, 'branch-lock',
826
control_files.create_lock()
827
control_files.lock_write()
828
control_files._transport.mkdir_multi(dirs,
829
mode=control_files._dir_mode)
831
for file, content in files:
832
control_files.put(file, content)
834
control_files.unlock()
835
return self.open(a_bzrdir, _found=True)
837
def open(self, a_bzrdir, _found=False):
838
"""See RepositoryFormat.open()."""
840
# we are being called directly and must probe.
841
raise NotImplementedError
843
repo_transport = a_bzrdir.get_repository_transport(None)
844
control_files = a_bzrdir._control_files
845
revision_store = self._get_revision_store(repo_transport, control_files)
846
return AllInOneRepository(_format=self,
848
revision_store=revision_store)
851
class RepositoryFormat4(PreSplitOutRepositoryFormat):
852
"""Bzr repository format 4.
854
This repository format has:
856
- TextStores for texts, inventories,revisions.
858
This format is deprecated: it indexes texts using a text id which is
859
removed in format 5; initializationa and write support for this format
864
super(RepositoryFormat4, self).__init__()
865
self._matchingbzrdir = bzrlib.bzrdir.BzrDirFormat4()
867
def initialize(self, url, shared=False, _internal=False):
868
"""Format 4 branches cannot be created."""
869
raise errors.UninitializableFormat(self)
871
def is_supported(self):
872
"""Format 4 is not supported.
874
It is not supported because the model changed from 4 to 5 and the
875
conversion logic is expensive - so doing it on the fly was not
880
def _get_revision_store(self, repo_transport, control_files):
881
"""See RepositoryFormat._get_revision_store()."""
882
return self._get_rev_store(repo_transport,
887
class RepositoryFormat5(PreSplitOutRepositoryFormat):
888
"""Bzr control format 5.
890
This repository format has:
891
- weaves for file texts and inventory
893
- TextStores for revisions and signatures.
897
super(RepositoryFormat5, self).__init__()
898
self._matchingbzrdir = bzrlib.bzrdir.BzrDirFormat5()
900
def _get_revision_store(self, repo_transport, control_files):
901
"""See RepositoryFormat._get_revision_store()."""
902
"""Return the revision store object for this a_bzrdir."""
903
return self._get_rev_store(repo_transport,
909
class RepositoryFormat6(PreSplitOutRepositoryFormat):
910
"""Bzr control format 6.
912
This repository format has:
913
- weaves for file texts and inventory
914
- hash subdirectory based stores.
915
- TextStores for revisions and signatures.
919
super(RepositoryFormat6, self).__init__()
920
self._matchingbzrdir = bzrlib.bzrdir.BzrDirFormat6()
922
def _get_revision_store(self, repo_transport, control_files):
923
"""See RepositoryFormat._get_revision_store()."""
924
return self._get_rev_store(repo_transport,
931
class MetaDirRepositoryFormat(RepositoryFormat):
932
"""Common base class for the new repositories using the metadir layour."""
935
super(MetaDirRepositoryFormat, self).__init__()
936
self._matchingbzrdir = bzrlib.bzrdir.BzrDirMetaFormat1()
938
def _create_control_files(self, a_bzrdir):
939
"""Create the required files and the initial control_files object."""
940
# FIXME: RBC 20060125 dont peek under the covers
941
# NB: no need to escape relative paths that are url safe.
942
repository_transport = a_bzrdir.get_repository_transport(self)
943
control_files = LockableFiles(repository_transport, 'lock', LockDir)
944
control_files.create_lock()
947
def _get_revision_store(self, repo_transport, control_files):
948
"""See RepositoryFormat._get_revision_store()."""
949
return self._get_rev_store(repo_transport,
956
def open(self, a_bzrdir, _found=False, _override_transport=None):
957
"""See RepositoryFormat.open().
959
:param _override_transport: INTERNAL USE ONLY. Allows opening the
960
repository at a slightly different url
961
than normal. I.e. during 'upgrade'.
964
format = RepositoryFormat.find_format(a_bzrdir)
965
assert format.__class__ == self.__class__
966
if _override_transport is not None:
967
repo_transport = _override_transport
969
repo_transport = a_bzrdir.get_repository_transport(None)
970
control_files = LockableFiles(repo_transport, 'lock', LockDir)
971
revision_store = self._get_revision_store(repo_transport, control_files)
972
return MetaDirRepository(_format=self,
974
control_files=control_files,
975
revision_store=revision_store)
977
def _upload_blank_content(self, a_bzrdir, dirs, files, utf8_files, shared):
978
"""Upload the initial blank content."""
979
control_files = self._create_control_files(a_bzrdir)
980
control_files.lock_write()
982
control_files._transport.mkdir_multi(dirs,
983
mode=control_files._dir_mode)
984
for file, content in files:
985
control_files.put(file, content)
986
for file, content in utf8_files:
987
control_files.put_utf8(file, content)
989
control_files.put_utf8('shared-storage', '')
991
control_files.unlock()
994
class RepositoryFormat7(MetaDirRepositoryFormat):
997
This repository format has:
998
- weaves for file texts and inventory
999
- hash subdirectory based stores.
1000
- TextStores for revisions and signatures.
1001
- a format marker of its own
1002
- an optional 'shared-storage' flag
1003
- an optional 'no-working-trees' flag
1006
def get_format_string(self):
1007
"""See RepositoryFormat.get_format_string()."""
1008
return "Bazaar-NG Repository format 7"
1010
def initialize(self, a_bzrdir, shared=False):
1011
"""Create a weave repository.
1013
:param shared: If true the repository will be initialized as a shared
1016
from bzrlib.weavefile import write_weave_v5
1017
from bzrlib.weave import Weave
1019
# Create an empty weave
1021
bzrlib.weavefile.write_weave_v5(Weave(), sio)
1022
empty_weave = sio.getvalue()
1024
mutter('creating repository in %s.', a_bzrdir.transport.base)
1025
dirs = ['revision-store', 'weaves']
1026
files = [('inventory.weave', StringIO(empty_weave)),
1028
utf8_files = [('format', self.get_format_string())]
1030
self._upload_blank_content(a_bzrdir, dirs, files, utf8_files, shared)
1031
return self.open(a_bzrdir=a_bzrdir, _found=True)
1034
class RepositoryFormatKnit1(MetaDirRepositoryFormat):
1035
"""Bzr repository knit format 1.
1037
This repository format has:
1038
- knits for file texts and inventory
1039
- hash subdirectory based stores.
1040
- knits for revisions and signatures
1041
- TextStores for revisions and signatures.
1042
- a format marker of its own
1043
- an optional 'shared-storage' flag
1044
- an optional 'no-working-trees' flag
1048
def get_format_string(self):
1049
"""See RepositoryFormat.get_format_string()."""
1050
return "Bazaar-NG Knit Repository Format 1"
1052
def initialize(self, a_bzrdir, shared=False):
1053
"""Create a knit format 1 repository.
1055
:param shared: If true the repository will be initialized as a shared
1057
XXX NOTE that this current uses a Weave for testing and will become
1058
A Knit in due course.
1060
from bzrlib.weavefile import write_weave_v5
1061
from bzrlib.weave import Weave
1063
# Create an empty weave
1065
bzrlib.weavefile.write_weave_v5(Weave(), sio)
1066
empty_weave = sio.getvalue()
1068
mutter('creating repository in %s.', a_bzrdir.transport.base)
1069
dirs = ['revision-store', 'knits']
1070
files = [('inventory.weave', StringIO(empty_weave)),
1072
utf8_files = [('format', self.get_format_string())]
1074
self._upload_blank_content(a_bzrdir, dirs, files, utf8_files, shared)
1075
return self.open(a_bzrdir=a_bzrdir, _found=True)
1078
# formats which have no format string are not discoverable
1079
# and not independently creatable, so are not registered.
1080
_default_format = RepositoryFormat7()
1081
RepositoryFormat.register_format(_default_format)
1082
RepositoryFormat.register_format(RepositoryFormatKnit1())
1083
RepositoryFormat.set_default_format(_default_format)
1084
_legacy_formats = [RepositoryFormat4(),
1085
RepositoryFormat5(),
1086
RepositoryFormat6()]
1089
class InterRepository(object):
1090
"""This class represents operations taking place between two repositories.
1092
Its instances have methods like copy_content and fetch, and contain
1093
references to the source and target repositories these operations can be
1096
Often we will provide convenience methods on 'repository' which carry out
1097
operations with another repository - they will always forward to
1098
InterRepository.get(other).method_name(parameters).
1100
# XXX: FIXME: FUTURE: robertc
1101
# testing of these probably requires a factory in optimiser type, and
1102
# then a test adapter to test each type thoroughly.
1106
"""The available optimised InterRepository types."""
1108
def __init__(self, source, target):
1109
"""Construct a default InterRepository instance. Please use 'get'.
1111
Only subclasses of InterRepository should call
1112
InterRepository.__init__ - clients should call InterRepository.get
1113
instead which will create an optimised InterRepository if possible.
1115
self.source = source
1116
self.target = target
1119
def copy_content(self, revision_id=None, basis=None):
1120
"""Make a complete copy of the content in self into destination.
1122
This is a destructive operation! Do not use it on existing
1125
:param revision_id: Only copy the content needed to construct
1126
revision_id and its parents.
1127
:param basis: Copy the needed data preferentially from basis.
1130
self.target.set_make_working_trees(self.source.make_working_trees())
1131
except NotImplementedError:
1133
# grab the basis available data
1134
if basis is not None:
1135
self.target.fetch(basis, revision_id=revision_id)
1136
# but dont both fetching if we have the needed data now.
1137
if (revision_id not in (None, NULL_REVISION) and
1138
self.target.has_revision(revision_id)):
1140
self.target.fetch(self.source, revision_id=revision_id)
1142
def _double_lock(self, lock_source, lock_target):
1143
"""Take out too locks, rolling back the first if the second throws."""
1148
# we want to ensure that we don't leave source locked by mistake.
1149
# and any error on target should not confuse source.
1150
self.source.unlock()
1154
def fetch(self, revision_id=None, pb=None):
1155
"""Fetch the content required to construct revision_id.
1157
The content is copied from source to target.
1159
:param revision_id: if None all content is copied, if NULL_REVISION no
1161
:param pb: optional progress bar to use for progress reports. If not
1162
provided a default one will be created.
1164
Returns the copied revision count and the failed revisions in a tuple:
1167
from bzrlib.fetch import RepoFetcher
1168
mutter("Using fetch logic to copy between %s(%s) and %s(%s)",
1169
self.source, self.source._format, self.target, self.target._format)
1170
f = RepoFetcher(to_repository=self.target,
1171
from_repository=self.source,
1172
last_revision=revision_id,
1174
return f.count_copied, f.failed_revisions
1177
def get(klass, repository_source, repository_target):
1178
"""Retrieve a InterRepository worker object for these repositories.
1180
:param repository_source: the repository to be the 'source' member of
1181
the InterRepository instance.
1182
:param repository_target: the repository to be the 'target' member of
1183
the InterRepository instance.
1184
If an optimised InterRepository worker exists it will be used otherwise
1185
a default InterRepository instance will be created.
1187
for provider in klass._optimisers:
1188
if provider.is_compatible(repository_source, repository_target):
1189
return provider(repository_source, repository_target)
1190
return InterRepository(repository_source, repository_target)
1192
def lock_read(self):
1193
"""Take out a logical read lock.
1195
This will lock the source branch and the target branch. The source gets
1196
a read lock and the target a read lock.
1198
self._double_lock(self.source.lock_read, self.target.lock_read)
1200
def lock_write(self):
1201
"""Take out a logical write lock.
1203
This will lock the source branch and the target branch. The source gets
1204
a read lock and the target a write lock.
1206
self._double_lock(self.source.lock_read, self.target.lock_write)
1209
def missing_revision_ids(self, revision_id=None):
1210
"""Return the revision ids that source has that target does not.
1212
These are returned in topological order.
1214
:param revision_id: only return revision ids included by this
1217
# generic, possibly worst case, slow code path.
1218
target_ids = set(self.target.all_revision_ids())
1219
if revision_id is not None:
1220
source_ids = self.source.get_ancestry(revision_id)
1221
assert source_ids.pop(0) == None
1223
source_ids = self.source.all_revision_ids()
1224
result_set = set(source_ids).difference(target_ids)
1225
# this may look like a no-op: its not. It preserves the ordering
1226
# other_ids had while only returning the members from other_ids
1227
# that we've decided we need.
1228
return [rev_id for rev_id in source_ids if rev_id in result_set]
1231
def register_optimiser(klass, optimiser):
1232
"""Register an InterRepository optimiser."""
1233
klass._optimisers.add(optimiser)
1236
"""Release the locks on source and target."""
1238
self.target.unlock()
1240
self.source.unlock()
1243
def unregister_optimiser(klass, optimiser):
1244
"""Unregister an InterRepository optimiser."""
1245
klass._optimisers.remove(optimiser)
1248
class InterWeaveRepo(InterRepository):
1249
"""Optimised code paths between Weave based repositories."""
1251
_matching_repo_format = _default_format
1252
"""Repository format for testing with."""
1255
def is_compatible(source, target):
1256
"""Be compatible with known Weave formats.
1258
We dont test for the stores being of specific types becase that
1259
could lead to confusing results, and there is no need to be
1263
return (isinstance(source._format, (RepositoryFormat5,
1265
RepositoryFormat7)) and
1266
isinstance(target._format, (RepositoryFormat5,
1268
RepositoryFormat7)))
1269
except AttributeError:
1273
def copy_content(self, revision_id=None, basis=None):
1274
"""See InterRepository.copy_content()."""
1275
# weave specific optimised path:
1276
if basis is not None:
1277
# copy the basis in, then fetch remaining data.
1278
basis.copy_content_into(self.target, revision_id)
1279
# the basis copy_content_into could misset this.
1281
self.target.set_make_working_trees(self.source.make_working_trees())
1282
except NotImplementedError:
1284
self.target.fetch(self.source, revision_id=revision_id)
1287
self.target.set_make_working_trees(self.source.make_working_trees())
1288
except NotImplementedError:
1290
# FIXME do not peek!
1291
if self.source.control_files._transport.listable():
1292
pb = bzrlib.ui.ui_factory.progress_bar()
1293
copy_all(self.source.weave_store,
1294
self.target.weave_store, pb=pb)
1295
pb.update('copying inventory', 0, 1)
1296
self.target.control_weaves.copy_multi(
1297
self.source.control_weaves, ['inventory'])
1298
copy_all(self.source.revision_store,
1299
self.target.revision_store, pb=pb)
1301
self.target.fetch(self.source, revision_id=revision_id)
1304
def fetch(self, revision_id=None, pb=None):
1305
"""See InterRepository.fetch()."""
1306
from bzrlib.fetch import RepoFetcher
1307
mutter("Using fetch logic to copy between %s(%s) and %s(%s)",
1308
self.source, self.source._format, self.target, self.target._format)
1309
f = RepoFetcher(to_repository=self.target,
1310
from_repository=self.source,
1311
last_revision=revision_id,
1313
return f.count_copied, f.failed_revisions
1316
def missing_revision_ids(self, revision_id=None):
1317
"""See InterRepository.missing_revision_ids()."""
1318
# we want all revisions to satisfy revision_id in source.
1319
# but we dont want to stat every file here and there.
1320
# we want then, all revisions other needs to satisfy revision_id
1321
# checked, but not those that we have locally.
1322
# so the first thing is to get a subset of the revisions to
1323
# satisfy revision_id in source, and then eliminate those that
1324
# we do already have.
1325
# this is slow on high latency connection to self, but as as this
1326
# disk format scales terribly for push anyway due to rewriting
1327
# inventory.weave, this is considered acceptable.
1329
if revision_id is not None:
1330
source_ids = self.source.get_ancestry(revision_id)
1331
assert source_ids.pop(0) == None
1333
source_ids = self.source._all_possible_ids()
1334
source_ids_set = set(source_ids)
1335
# source_ids is the worst possible case we may need to pull.
1336
# now we want to filter source_ids against what we actually
1337
# have in target, but dont try to check for existence where we know
1338
# we do not have a revision as that would be pointless.
1339
target_ids = set(self.target._all_possible_ids())
1340
possibly_present_revisions = target_ids.intersection(source_ids_set)
1341
actually_present_revisions = set(self.target._eliminate_revisions_not_present(possibly_present_revisions))
1342
required_revisions = source_ids_set.difference(actually_present_revisions)
1343
required_topo_revisions = [rev_id for rev_id in source_ids if rev_id in required_revisions]
1344
if revision_id is not None:
1345
# we used get_ancestry to determine source_ids then we are assured all
1346
# revisions referenced are present as they are installed in topological order.
1347
# and the tip revision was validated by get_ancestry.
1348
return required_topo_revisions
1350
# if we just grabbed the possibly available ids, then
1351
# we only have an estimate of whats available and need to validate
1352
# that against the revision records.
1353
return self.source._eliminate_revisions_not_present(required_topo_revisions)
1356
InterRepository.register_optimiser(InterWeaveRepo)
1359
class RepositoryTestProviderAdapter(object):
1360
"""A tool to generate a suite testing multiple repository formats at once.
1362
This is done by copying the test once for each transport and injecting
1363
the transport_server, transport_readonly_server, and bzrdir_format and
1364
repository_format classes into each copy. Each copy is also given a new id()
1365
to make it easy to identify.
1368
def __init__(self, transport_server, transport_readonly_server, formats):
1369
self._transport_server = transport_server
1370
self._transport_readonly_server = transport_readonly_server
1371
self._formats = formats
1373
def adapt(self, test):
1374
result = TestSuite()
1375
for repository_format, bzrdir_format in self._formats:
1376
new_test = deepcopy(test)
1377
new_test.transport_server = self._transport_server
1378
new_test.transport_readonly_server = self._transport_readonly_server
1379
new_test.bzrdir_format = bzrdir_format
1380
new_test.repository_format = repository_format
1381
def make_new_test_id():
1382
new_id = "%s(%s)" % (new_test.id(), repository_format.__class__.__name__)
1383
return lambda: new_id
1384
new_test.id = make_new_test_id()
1385
result.addTest(new_test)
1389
class InterRepositoryTestProviderAdapter(object):
1390
"""A tool to generate a suite testing multiple inter repository formats.
1392
This is done by copying the test once for each interrepo provider and injecting
1393
the transport_server, transport_readonly_server, repository_format and
1394
repository_to_format classes into each copy.
1395
Each copy is also given a new id() to make it easy to identify.
1398
def __init__(self, transport_server, transport_readonly_server, formats):
1399
self._transport_server = transport_server
1400
self._transport_readonly_server = transport_readonly_server
1401
self._formats = formats
1403
def adapt(self, test):
1404
result = TestSuite()
1405
for interrepo_class, repository_format, repository_format_to in self._formats:
1406
new_test = deepcopy(test)
1407
new_test.transport_server = self._transport_server
1408
new_test.transport_readonly_server = self._transport_readonly_server
1409
new_test.interrepo_class = interrepo_class
1410
new_test.repository_format = repository_format
1411
new_test.repository_format_to = repository_format_to
1412
def make_new_test_id():
1413
new_id = "%s(%s)" % (new_test.id(), interrepo_class.__name__)
1414
return lambda: new_id
1415
new_test.id = make_new_test_id()
1416
result.addTest(new_test)
1420
def default_test_list():
1421
"""Generate the default list of interrepo permutations to test."""
1423
# test the default InterRepository between format 6 and the current
1425
# XXX: robertc 20060220 reinstate this when there are two supported
1426
# formats which do not have an optimal code path between them.
1427
result.append((InterRepository,
1428
RepositoryFormat6(),
1429
RepositoryFormatKnit1()))
1430
for optimiser in InterRepository._optimisers:
1431
result.append((optimiser,
1432
optimiser._matching_repo_format,
1433
optimiser._matching_repo_format
1435
# if there are specific combinations we want to use, we can add them
1440
class CopyConverter(object):
1441
"""A repository conversion tool which just performs a copy of the content.
1443
This is slow but quite reliable.
1446
def __init__(self, target_format):
1447
"""Create a CopyConverter.
1449
:param target_format: The format the resulting repository should be.
1451
self.target_format = target_format
1453
def convert(self, repo, pb):
1454
"""Perform the conversion of to_convert, giving feedback via pb.
1456
:param to_convert: The disk object to convert.
1457
:param pb: a progress bar to use for progress information.
1462
# this is only useful with metadir layouts - separated repo content.
1463
# trigger an assertion if not such
1464
repo._format.get_format_string()
1465
self.repo_dir = repo.bzrdir
1466
self.step('Moving repository to repository.backup')
1467
self.repo_dir.transport.move('repository', 'repository.backup')
1468
backup_transport = self.repo_dir.transport.clone('repository.backup')
1469
self.source_repo = repo._format.open(self.repo_dir,
1471
_override_transport=backup_transport)
1472
self.step('Creating new repository')
1473
converted = self.target_format.initialize(self.repo_dir,
1474
self.source_repo.is_shared())
1475
converted.lock_write()
1477
self.step('Copying content into repository.')
1478
self.source_repo.copy_content_into(converted)
1481
self.step('Deleting old repository content.')
1482
self.repo_dir.transport.delete_tree('repository.backup')
1483
self.pb.note('repository converted')
1485
def step(self, message):
1486
"""Update the pb by a step."""
1488
self.pb.update(message, self.count, self.total)