13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
17
"""BzrDir logic. The BzrDir is the basic control directory used by bzr.
189
192
transport.ensure_base()
190
193
require_stacking = (stacked_on is not None)
191
194
format = self.cloning_metadir(require_stacking)
195
# Bug: We create a metadir without knowing if it can support stacking,
196
# we should look up the policy needs first.
192
197
result = format.initialize_on_transport(transport)
193
198
repository_policy = None
384
389
stack_on_pwd=None, require_stacking=False):
385
390
"""Return an object representing a policy to use.
387
This controls whether a new repository is created, or a shared
388
repository used instead.
392
This controls whether a new repository is created, and the format of
393
that repository, or some existing shared repository used instead.
390
395
If stack_on is supplied, will not seek a containing shared repo.
831
838
BzrDir._check_supported(format, _unsupported)
832
839
return format.open(transport, _found=True)
834
def open_branch(self, unsupported=False):
841
def open_branch(self, unsupported=False, ignore_fallbacks=False):
835
842
"""Open the branch object at this BzrDir if one is present.
837
844
If unsupported is True, then no longer supported branch formats can
1012
1019
result_format = self._format.__class__()
1015
branch = self.open_branch()
1022
branch = self.open_branch(ignore_fallbacks=True)
1016
1023
source_repository = branch.repository
1017
1024
result_format._branch_format = branch._format
1018
1025
except errors.NotBranchError:
1200
class BzrDirHooks(hooks.Hooks):
1201
"""Hooks for BzrDir operations."""
1204
"""Create the default hooks."""
1205
hooks.Hooks.__init__(self)
1206
self.create_hook(hooks.HookPoint('pre_open',
1207
"Invoked before attempting to open a BzrDir with the transport "
1208
"that the open will use.", (1, 14), None))
1210
# install the default hooks
1211
BzrDir.hooks = BzrDirHooks()
1193
1214
class BzrDirPreSplitOut(BzrDir):
1194
1215
"""A common class for the all-in-one formats."""
1337
1358
format = BzrDirFormat.get_default_format()
1338
1359
return not isinstance(self._format, format.__class__)
1340
def open_branch(self, unsupported=False):
1361
def open_branch(self, unsupported=False, ignore_fallbacks=False):
1341
1362
"""See BzrDir.open_branch."""
1342
1363
from bzrlib.branch import BzrBranchFormat4
1343
1364
format = BzrBranchFormat4()
1591
def open_branch(self, unsupported=False):
1612
def open_branch(self, unsupported=False, ignore_fallbacks=False):
1592
1613
"""See BzrDir.open_branch."""
1593
1614
format = self.find_branch_format()
1594
1615
self._check_supported(format, unsupported)
1595
return format.open(self, _found=True)
1616
return format.open(self, _found=True, ignore_fallbacks=ignore_fallbacks)
1597
1618
def open_repository(self, unsupported=False):
1598
1619
"""See BzrDir.open_repository."""
2449
2470
self.snapshot_ie(previous_entries, ie, w, rev_id)
2452
@symbol_versioning.deprecated_method(symbol_versioning.one_one)
2453
def get_parents(self, revision_ids):
2454
for revision_id in revision_ids:
2455
yield self.revisions[revision_id].parent_ids
2457
2473
def get_parent_map(self, revision_ids):
2458
2474
"""See graph._StackedParentsProvider.get_parent_map"""
2459
2475
return dict((revision_id, self.revisions[revision_id])
2814
2830
# Always return a RemoteRepositoryFormat object, but if a specific bzr
2815
2831
# repository format has been asked for, tell the RemoteRepositoryFormat
2816
2832
# that it should use that for init() etc.
2817
result = remote.RemoteRepositoryFormat()
2833
result = remote.RemoteRepositoryFormat()
2818
2834
custom_format = getattr(self, '_repository_format', None)
2819
2835
if custom_format:
2820
# We will use the custom format to create repositories over the
2821
# wire; expose its details like rich_root_data for code to query
2822
2836
if isinstance(custom_format, remote.RemoteRepositoryFormat):
2823
result._custom_format = custom_format._custom_format
2837
return custom_format
2839
# We will use the custom format to create repositories over the
2840
# wire; expose its details like rich_root_data for code to
2825
2842
result._custom_format = custom_format
3130
3147
Creates the desired repository in the bzrdir we already have.
3149
stack_on = self._get_full_stack_on()
3151
# Stacking is desired. requested by the target, but does the place it
3152
# points at support stacking? If it doesn't then we should
3153
# not implicitly upgrade. We check this here.
3154
format = self._bzrdir._format
3155
if not (format.repository_format.supports_external_lookups
3156
and format.get_branch_format().supports_stacking()):
3157
# May need to upgrade - but only do if the target also
3158
# supports stacking. Note that this currently wastes
3159
# network round trips to check - but we only do this
3160
# when the source can't stack so it will fade away
3161
# as people do upgrade.
3163
target_dir = BzrDir.open(stack_on,
3164
possible_transports=[self._bzrdir.root_transport])
3165
except errors.NotBranchError:
3166
# Nothing there, don't change formats
3170
target_branch = target_dir.open_branch()
3171
except errors.NotBranchError:
3172
# No branch, don't change formats
3175
branch_format = target_branch._format
3176
repo_format = target_branch.repository._format
3177
if not (branch_format.supports_stacking()
3178
and repo_format.supports_external_lookups):
3179
# Doesn't stack itself, don't force an upgrade
3182
# Does support stacking, use its format.
3183
format.repository_format = repo_format
3184
format.set_branch_format(branch_format)
3185
note('Source format does not support stacking, '
3186
'using format: \'%s\'\n %s\n',
3187
branch_format.get_format_description(),
3188
repo_format.get_format_description())
3189
if not self._require_stacking:
3190
# We have picked up automatic stacking somewhere.
3191
note('Using default stacking branch %s at %s', self._stack_on,
3132
3193
repository = self._bzrdir.create_repository(shared=shared)
3133
3194
self._add_fallback(repository,
3134
3195
possible_transports=[self._bzrdir.transport])
3247
3308
format_registry.register_metadir('rich-root-pack',
3248
3309
'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack4',
3249
3310
help='New in 1.0: A variant of pack-0.92 that supports rich-root data '
3250
'(needed for bzr-svn).',
3311
'(needed for bzr-svn and bzr-git).',
3251
3312
branch_format='bzrlib.branch.BzrBranchFormat6',
3252
3313
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3262
3323
format_registry.register_metadir('1.6.1-rich-root',
3263
3324
'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack5RichRoot',
3264
3325
help='A variant of 1.6 that supports rich-root data '
3265
'(needed for bzr-svn).',
3326
'(needed for bzr-svn and bzr-git).',
3266
3327
branch_format='bzrlib.branch.BzrBranchFormat7',
3267
3328
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3277
3338
format_registry.register_metadir('1.9-rich-root',
3278
3339
'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack6RichRoot',
3279
3340
help='A variant of 1.9 that supports rich-root data '
3280
'(needed for bzr-svn).',
3341
'(needed for bzr-svn and bzr-git).',
3281
3342
branch_format='bzrlib.branch.BzrBranchFormat7',
3282
3343
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3291
3352
format_registry.register_metadir('development-wt5-rich-root',
3292
3353
'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack6RichRoot',
3293
3354
help='A variant of development-wt5 that supports rich-root data '
3294
'(needed for bzr-svn).',
3355
'(needed for bzr-svn and bzr-git).',
3295
3356
branch_format='bzrlib.branch.BzrBranchFormat7',
3296
3357
tree_format='bzrlib.workingtree.WorkingTreeFormat5',
3297
3358
experimental=True,
3347
3408
experimental=True,
3410
# The following format should be an alias for the rich root equivalent
3411
# of the default format
3412
format_registry.register_metadir('default-rich-root',
3413
'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack4',
3414
help='Default format, rich root variant. (needed for bzr-svn and bzr-git).',
3415
branch_format='bzrlib.branch.BzrBranchFormat6',
3416
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3349
3419
# The current format that is made on 'bzr init'.
3350
3420
format_registry.set_default('pack-0.92')