1
# Copyright (C) 2010 Canonical Ltd
1
# Copyright (C) 2010, 2011 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
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)
373
387
# even if the origin was stacked
374
388
stacked_branch_url = None
375
389
if source_branch is not None:
390
add_cleanup(source_branch.lock_read().unlock)
377
392
stacked_branch_url = self.root_transport.base
378
393
source_repository = source_branch.repository
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: