~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/clone.py

  • Committer: Martin Pool
  • Date: 2006-01-23 02:09:39 UTC
  • mfrom: (1534.1.11 integration)
  • Revision ID: mbp@sourcefrog.net-20060123020939-567fb193328ed7a6
[merge] robert's integration

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