52
52
from bzrlib.branch import Branch
53
53
from bzrlib.trace import mutter, note
54
54
from bzrlib.store import copy_all
55
from bzrlib.errors import InvalidRevisionId
57
56
def copy_branch(branch_from, to_location, revision=None, basis_branch=None):
58
57
"""Copy branch_from into the existing directory to_location.
76
75
assert isinstance(to_location, basestring)
77
76
if basis_branch is not None:
78
77
note("basis_branch is not supported for fast weave copy yet.")
79
branch_from.lock_read()
81
if not (branch_from.weave_store.listable()
82
and branch_from.revision_store.listable()):
83
return copy_branch_slower(branch_from, to_location, revision,
85
history = _get_truncated_history(branch_from, revision)
86
if not bzrlib.osutils.lexists(to_location):
88
branch_to = Branch.initialize(to_location)
89
mutter("copy branch from %s to %s", branch_from, branch_to)
90
branch_to.set_root_id(branch_from.get_root_id())
91
branch_to.append_revision(*history)
92
_copy_control_weaves(branch_from, branch_to)
93
_copy_text_weaves(branch_from, branch_to)
94
_copy_revision_store(branch_from, branch_to)
95
build_working_dir(to_location)
96
branch_to.set_parent(branch_from.base)
78
history = _get_truncated_history(branch_from, revision)
79
if not bzrlib.osutils.lexists(to_location):
81
branch_to = Branch.initialize(to_location)
82
mutter("copy branch from %s to %s", branch_from, branch_to)
83
branch_to.set_root_id(branch_from.get_root_id())
84
branch_to.append_revision(*history)
85
_copy_control_weaves(branch_from, branch_to)
86
_copy_text_weaves(branch_from, branch_to)
87
_copy_revision_store(branch_from, branch_to)
88
build_working_dir(to_location)
89
branch_to.set_parent(branch_from.base)
103
95
def _get_truncated_history(branch_from, revision):
108
100
idx = history.index(revision)
109
101
except ValueError:
110
raise InvalidRevisionId(revision_id=revision, branch=branch_from)
102
raise InvalidRevisionId('revision {%s} is not on the mainline of %s'
103
% (revision, branch_from))
111
104
return history[:idx+1]
113
106
def _copy_text_weaves(branch_from, branch_to):
107
# TODO: Handle UnlistableStore and fall back to getting a list of
108
# all file-ids and copying them one by one.
114
109
copy_all(branch_from.weave_store, branch_to.weave_store)
117
112
def _copy_revision_store(branch_from, branch_to):
113
# TODO: Copy all revisions mentioned in the ancestry of the selected revision
118
114
copy_all(branch_from.revision_store, branch_to.revision_store)
121
117
def _copy_control_weaves(branch_from, branch_to):
122
118
to_control = branch_to.control_weaves
123
119
from_control = branch_from.control_weaves
124
to_control.copy_multi(from_control, ['inventory'])
120
to_control.copy_multi(from_control, ['inventory', 'ancestry'])
127
123
def copy_branch_slower(branch_from, to_location, revision=None, basis_branch=None):