~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/clone.py

sync with bzr.dev mainline

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
55
56
 
56
57
def copy_branch(branch_from, to_location, revision=None, basis_branch=None):
57
58
    """Copy branch_from into the existing directory to_location.
86
87
            os.mkdir(to_location)
87
88
        branch_to = Branch.initialize(to_location)
88
89
        mutter("copy branch from %s to %s", branch_from, branch_to)
89
 
        branch_to.set_root_id(branch_from.get_root_id())
90
 
        branch_to.append_revision(*history)
 
90
        branch_to.working_tree().set_root_id(branch_from.get_root_id())
91
91
        _copy_control_weaves(branch_from, branch_to)
92
92
        _copy_text_weaves(branch_from, branch_to)
93
93
        _copy_revision_store(branch_from, branch_to)
 
94
        branch_to.set_parent(branch_from.base)
 
95
        # must be done *after* history is copied across
 
96
        branch_to.append_revision(*history)
94
97
        build_working_dir(to_location)
95
 
        branch_to.set_parent(branch_from.base)
96
98
        mutter("copied")
97
99
        return branch_to
98
100
    finally:
99
101
        branch_from.unlock()
100
102
 
101
103
 
102
 
def _get_truncated_history(branch_from, revision):
 
104
def _get_truncated_history(branch_from, revision_id):
103
105
    history = branch_from.revision_history()
104
 
    if revision is None:
 
106
    if revision_id is None:
105
107
        return history
106
108
    try:
107
 
        idx = history.index(revision)
 
109
        idx = history.index(revision_id)
108
110
    except ValueError:
109
 
        raise InvalidRevisionId('revision {%s} is not on the mainline of %s' 
110
 
                                % (revision, branch_from))
 
111
        raise InvalidRevisionId(revision_id=revision, branch=branch_from)
111
112
    return history[:idx+1]
112
113
 
113
114
def _copy_text_weaves(branch_from, branch_to):
151
152
    mutter("copy branch from %s to %s", branch_from, br_to)
152
153
    if basis_branch is not None:
153
154
        basis_branch.push_stores(br_to)
154
 
    br_to.set_root_id(branch_from.get_root_id())
 
155
    br_to.working_tree().set_root_id(branch_from.get_root_id())
155
156
    if revision is None:
156
157
        revision = branch_from.last_revision()
157
158
    br_to.update_revisions(branch_from, stop_revision=revision)