1
# Copyright (C) 2004, 2005 by Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
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
17
# TODO: This could be done *much* more efficiently by just copying
18
# all the whole weaves and revisions, rather than getting one
21
# TODO: Do we really need to invoke merge() to build the working directory?
22
# That seems a bit of an abstraction inversion.
27
from bzrlib.merge import merge
28
from bzrlib.branch import Branch
29
from bzrlib.trace import mutter
32
def copy_branch(branch_from, to_location, revision=None, basis_branch=None):
33
"""Copy branch_from into the existing directory to_location.
36
If not None, only revisions up to this point will be copied.
37
The head of the new branch will be that revision. Must be a
41
The name of a local directory that exists but is empty.
44
The revision to copy up to
47
A local branch to copy revisions from, related to branch_from
49
assert isinstance(branch_from, Branch)
50
assert isinstance(to_location, basestring)
52
br_to = Branch.initialize(to_location)
53
mutter("copy branch from %s to %s", branch_from, br_to)
54
if basis_branch is not None:
55
basis_branch.push_stores(br_to)
56
br_to.set_root_id(branch_from.get_root_id())
58
revision = branch_from.last_revision()
59
br_to.update_revisions(branch_from, stop_revision=revision)
60
merge((to_location, -1), (to_location, 0), this_dir=to_location,
61
check_clean=False, ignore_zero=True)
62
br_to.set_parent(branch_from.base)