~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/clone.py

[merge] 0.7-bugfix: Fix fileid_involved to unescape xml characters, fix StubServer to handle paramiko > 1.5.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
78
78
        note("basis_branch is not supported for fast weave copy yet.")
79
79
    branch_from.lock_read()
80
80
    try:
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,
84
 
                                      basis_branch)
85
81
        history = _get_truncated_history(branch_from, revision)
86
82
        if not bzrlib.osutils.lexists(to_location):
87
83
            os.mkdir(to_location)
88
84
        branch_to = Branch.initialize(to_location)
89
85
        mutter("copy branch from %s to %s", branch_from, branch_to)
90
86
        branch_to.working_tree().set_root_id(branch_from.get_root_id())
91
 
        _copy_control_weaves(branch_from, branch_to)
92
 
        _copy_text_weaves(branch_from, branch_to)
93
 
        _copy_revision_store(branch_from, branch_to)
 
87
        _copy_control_weaves(branch_from, branch_to, history)
 
88
        _copy_text_weaves(branch_from, branch_to, history)
 
89
        _copy_revision_store(branch_from, branch_to, history)
94
90
        branch_to.set_parent(branch_from.base)
95
91
        # must be done *after* history is copied across
96
92
        branch_to.append_revision(*history)
100
96
    finally:
101
97
        branch_from.unlock()
102
98
 
103
 
 
104
99
def _get_truncated_history(branch_from, revision_id):
105
100
    history = branch_from.revision_history()
106
101
    if revision_id is None:
111
106
        raise InvalidRevisionId(revision_id=revision, branch=branch_from)
112
107
    return history[:idx+1]
113
108
 
114
 
def _copy_text_weaves(branch_from, branch_to):
115
 
    copy_all(branch_from.weave_store, branch_to.weave_store)
116
 
 
117
 
 
118
 
def _copy_revision_store(branch_from, branch_to):
119
 
    copy_all(branch_from.revision_store, branch_to.revision_store)
120
 
 
121
 
 
122
 
def _copy_control_weaves(branch_from, branch_to):
 
109
def _copy_text_weaves(branch_from, branch_to, history):
 
110
    from_set = set(branch_from.get_ancestry(history[-1])[1:])
 
111
    file_ids = branch_from.fileid_involved_by_set( from_set )
 
112
    branch_to.weave_store.copy_multi(branch_from.weave_store, file_ids )
 
113
 
 
114
def _copy_revision_store(branch_from, branch_to, history):
 
115
    # copy all revision
 
116
    from_set = set(branch_from.get_ancestry(history[-1])[1:])
 
117
    branch_to.revision_store.copy_multi(branch_from.revision_store, from_set )
 
118
 
 
119
def _copy_control_weaves(branch_from, branch_to, history):
123
120
    to_control = branch_to.control_weaves
124
121
    from_control = branch_from.control_weaves
 
122
    # TODO Goffredo 20051215: we need only the minimal revision !!!!!
125
123
    to_control.copy_multi(from_control, ['inventory'])
126
124
 
127
 
    
128
 
def copy_branch_slower(branch_from, to_location, revision=None, basis_branch=None):
129
 
    """Copy branch_from into the existing directory to_location.
130
 
 
131
 
    revision
132
 
        If not None, only revisions up to this point will be copied.
133
 
        The head of the new branch will be that revision.  Must be a
134
 
        revid or None.
135
 
 
136
 
    to_location -- The destination directory; must either exist and be 
137
 
        empty, or not exist, in which case it is created.
138
 
 
139
 
    revno
140
 
        The revision to copy up to
141
 
 
142
 
    basis_branch
143
 
        A local branch to copy revisions from, related to branch_from. 
144
 
        This is used when branching from a remote (slow) branch, and we have
145
 
        a local branch that might contain some relevant revisions.
146
 
    """
147
 
    assert isinstance(branch_from, Branch)
148
 
    assert isinstance(to_location, basestring)
149
 
    if not bzrlib.osutils.lexists(to_location):
150
 
        os.mkdir(to_location)
151
 
    br_to = Branch.initialize(to_location)
152
 
    mutter("copy branch from %s to %s", branch_from, br_to)
153
 
    if basis_branch is not None:
154
 
        basis_branch.push_stores(br_to)
155
 
    br_to.working_tree().set_root_id(branch_from.get_root_id())
156
 
    if revision is None:
157
 
        revision = branch_from.last_revision()
158
 
    br_to.update_revisions(branch_from, stop_revision=revision)
159
 
    build_working_dir(to_location)
160
 
    br_to.set_parent(branch_from.base)
161
 
    mutter("copied")
162
 
    return br_to