190
191
# may need to copy content in
191
192
repository_policy = result.determine_repository_policy(
194
make_working_trees = local_repo.make_working_trees()
195
if isinstance(result, RemoteBzrDir):
196
make_working_trees = None
193
197
result_repo = repository_policy.acquire_repository(
194
local_repo.make_working_trees(),
195
local_repo.is_shared())
198
make_working_trees, local_repo.is_shared())
196
199
result_repo.fetch(local_repo, revision_id=revision_id)
197
200
# 1 if there is a branch present
198
201
# make sure its content is available in the target repository
2654
class RepositoryPolicy(object):
2655
"""Base class for other policies to inherit from"""
2657
class RepositoryAcquisitionPolicy(object):
2658
"""Abstract base class for repository acquisition policies.
2660
A repository acquisition policy decides how a BzrDir acquires a repository
2661
for a branch that is being created. The most basic policy decision is
2662
whether to create a new repository or use an existing one.
2660
2665
def configure_branch(self, branch):
2661
2666
"""Apply any configuration data from this policy to the branch.
2667
2672
def acquire_repository(self, make_working_trees=None, shared=False):
2668
"""Apply any configuration data from this policy to the branch"""
2669
raise NotImplemented(RepositoryPolicy.acquire_repository)
2672
class CreateRepository(RepositoryPolicy):
2673
"""Acquire a repository for this bzrdir.
2675
Implementations may create a new repository or use a pre-exising
2677
:param make_working_trees: If creating a repository, set
2678
make_working_trees to this value (if non-None)
2679
:param shared: If creating a repository, make it shared if True
2680
:return: A repository
2682
raise NotImplemented(RepositoryAcquisitionPolicy.acquire_repository)
2685
class CreateRepository(RepositoryAcquisitionPolicy):
2673
2686
"""A policy of creating a new repository"""
2675
2688
def __init__(self, bzrdir):
2676
RepositoryPolicy.__init__(self)
2689
RepositoryAcquisitionPolicy.__init__(self)
2677
2690
self._bzrdir = bzrdir
2679
2692
def acquire_repository(self, make_working_trees=None, shared=False):
2680
"""Implementation of RepositoryPolicy.acquire_repository
2693
"""Implementation of RepositoryAcquisitionPolicy.acquire_repository
2682
Creates the desired repository
2695
Creates the desired repository in the bzrdir we already have.
2684
2697
repository = self._bzrdir.create_repository(shared=shared)
2685
2698
if make_working_trees is not None:
2687
2700
return repository
2690
class UseExistingRepository(RepositoryPolicy):
2703
class UseExistingRepository(RepositoryAcquisitionPolicy):
2691
2704
"""A policy of reusing an existing repository"""
2693
2706
def __init__(self, repository):
2694
RepositoryPolicy.__init__(self)
2707
RepositoryAcquisitionPolicy.__init__(self)
2695
2708
self._repository = repository
2697
2710
def acquire_repository(self, make_working_trees=None, shared=False):
2698
"""Implementation of RepositoryPolicy.acquire_repository
2711
"""Implementation of RepositoryAcquisitionPolicy.acquire_repository
2700
2713
Returns an existing repository to use