143
144
"""Destroy the repository in this ControlDir."""
144
145
raise NotImplementedError(self.destroy_repository)
146
def create_branch(self, name=None):
147
def create_branch(self, name=None, repository=None):
147
148
"""Create a branch in this ControlDir.
149
150
:param name: Name of the colocated branch to create, None for
364
365
:param create_tree_if_local: If true, a working-tree will be created
365
366
when working locally.
368
operation = cleanup.OperationWithCleanups(self._sprout)
369
return operation.run(url, revision_id=revision_id,
370
force_new_repo=force_new_repo, recurse=recurse,
371
possible_transports=possible_transports,
372
accelerator_tree=accelerator_tree, hardlink=hardlink,
373
stacked=stacked, source_branch=source_branch,
374
create_tree_if_local=create_tree_if_local)
376
def _sprout(self, op, url, revision_id=None, force_new_repo=False,
377
recurse='down', possible_transports=None,
378
accelerator_tree=None, hardlink=False, stacked=False,
379
source_branch=None, create_tree_if_local=True):
380
add_cleanup = op.add_cleanup
367
381
target_transport = get_transport(url, possible_transports)
368
382
target_transport.ensure_base()
369
383
cloning_format = self.cloning_metadir(stacked)
388
403
source_repository = self.open_repository()
389
404
except errors.NoRepositoryPresent:
390
405
source_repository = None
407
add_cleanup(source_repository.lock_read().unlock)
409
add_cleanup(source_branch.lock_read().unlock)
391
410
repository_policy = result.determine_repository_policy(
392
411
force_new_repo, stacked_branch_url, require_stacking=stacked)
393
412
result_repo, is_new_repo = repository_policy.acquire_repository()
413
add_cleanup(result_repo.lock_write().unlock)
394
414
is_stacked = stacked or (len(result_repo._fallback_repositories) != 0)
395
415
if is_new_repo and revision_id is not None and not is_stacked:
396
416
fetch_spec = graph.PendingAncestryResult(
412
432
result_branch = result.create_branch()
414
434
result_branch = source_branch.sprout(result,
415
revision_id=revision_id, repository_policy=repository_policy)
435
revision_id=revision_id, repository_policy=repository_policy,
436
repository=result_repo)
416
437
mutter("created new branch %r" % (result_branch,))
418
439
# Create/update the result working tree
420
441
isinstance(target_transport, local.LocalTransport) and
421
442
(result_repo is None or result_repo.make_working_trees())):
422
443
wt = result.create_workingtree(accelerator_tree=accelerator_tree,
444
hardlink=hardlink, from_branch=result_branch)
426
447
if wt.path2id('') is None:
542
563
branch = tree.branch
543
564
return tree, branch
566
def get_config(self):
567
"""Get configuration for this ControlDir."""
568
raise NotImplementedError(self.get_config)
570
def check_conversion_target(self, target_format):
571
"""Check that a bzrdir as a whole can be converted to a new format."""
572
raise NotImplementedError(self.check_conversion_target)
574
def clone(self, url, revision_id=None, force_new_repo=False,
575
preserve_stacking=False):
576
"""Clone this bzrdir and its contents to url verbatim.
578
:param url: The url create the clone at. If url's last component does
579
not exist, it will be created.
580
:param revision_id: The tip revision-id to use for any branch or
581
working tree. If not None, then the clone operation may tune
582
itself to download less data.
583
:param force_new_repo: Do not use a shared repository for the target
584
even if one is available.
585
:param preserve_stacking: When cloning a stacked branch, stack the
586
new branch on top of the other branch's stacked-on branch.
588
return self.clone_on_transport(get_transport(url),
589
revision_id=revision_id,
590
force_new_repo=force_new_repo,
591
preserve_stacking=preserve_stacking)
593
def clone_on_transport(self, transport, revision_id=None,
594
force_new_repo=False, preserve_stacking=False, stacked_on=None,
595
create_prefix=False, use_existing_dir=True):
596
"""Clone this bzrdir and its contents to transport verbatim.
598
:param transport: The transport for the location to produce the clone
599
at. If the target directory does not exist, it will be created.
600
:param revision_id: The tip revision-id to use for any branch or
601
working tree. If not None, then the clone operation may tune
602
itself to download less data.
603
:param force_new_repo: Do not use a shared repository for the target,
604
even if one is available.
605
:param preserve_stacking: When cloning a stacked branch, stack the
606
new branch on top of the other branch's stacked-on branch.
607
:param create_prefix: Create any missing directories leading up to
609
:param use_existing_dir: Use an existing directory if one exists.
611
raise NotImplementedError(self.clone_on_transport)
548
614
class ControlDirFormat(object):
918
988
# appear in chronological order and format descriptions can build
919
989
# on previous ones.
920
990
format_registry = ControlDirFormatRegistry()
992
network_format_registry = registry.FormatRegistry()
993
"""Registry of formats indexed by their network name.
995
The network name for a ControlDirFormat is an identifier that can be used when
996
referring to formats with smart server operations. See
997
ControlDirFormat.network_name() for more detail.