43
43
# TODO: Avoid repeatedly opening weaves so many times.
45
# XXX: This doesn't handle ghost (not present in branch) revisions at
48
# - get a list of revisions that need to be pulled in
49
# - for each one, pull in that revision file
50
# and get the inventory, and store the inventory with right
52
# - and get the ancestry, and store that with right parents too
53
# - and keep a note of all file ids and version seen
54
# - then go through all files; for each one get the weave,
55
# and add in all file versions
46
59
def greedy_fetch(to_branch, from_branch, revision, pb):
47
60
f = Fetcher(to_branch, from_branch, revision, pb)
67
80
self._load_histories()
68
81
revs_to_fetch = self._compare_ancestries()
69
82
self._copy_revisions(revs_to_fetch)
70
# - get a list of revisions that need to be pulled in
71
# - for each one, pull in that revision file
72
# and get the inventory, and store the inventory with right
74
# - and get the ancestry, and store that with right parents too
75
# - and keep a note of all file ids and version seen
76
# - then go through all files; for each one get the weave,
77
# and add in all file versions
80
84
def _load_histories(self):
81
85
"""Load histories of both branches, up to the limit."""
162
166
from_parents = map(from_weave.idx_to_name, from_weave.parents(from_idx))
163
167
text_lines = from_weave.get(from_idx)
164
168
to_weave = self.to_branch.weave_store.get_weave_or_empty(file_id)
165
if rev_id in to_weave._name_map:
166
warning('version {%s} already present in weave of file {%s}',
169
169
to_parents = map(to_weave.lookup, from_parents)
170
# it's ok to add even if the text is already there
170
171
to_weave.add(rev_id, to_parents, text_lines)
171
172
self.to_branch.weave_store.put_weave(file_id, to_weave)
174
def has_revision(branch, revision_id):
176
branch.get_revision_xml_file(revision_id)
178
except bzrlib.errors.NoSuchRevision:
182
def old_greedy_fetch(to_branch, from_branch, revision=None, pb=None):
183
"""Copy all history from one branch to another.
186
If set, copy only up to this point in the source branch.
188
@returns: number copied, missing ids
190
from_history = from_branch.revision_history()
191
required_revisions = set(from_history)
193
if revision is not None:
194
required_revisions.add(revision)
196
rev_index = from_history.index(revision)
199
if rev_index is not None:
200
from_history = from_history[:rev_index + 1]
202
from_history = [revision]
203
to_history = to_branch.revision_history()
205
for rev_id in from_history:
206
if not has_revision(to_branch, rev_id):
207
missing.append(rev_id)
209
# recurse down through the revision graph, looking for things that
212
while len(missing) > 0:
213
installed, failed = to_branch.install_revisions(from_branch,
214
revision_ids=missing,
217
required_failed = failed.intersection(required_revisions)
218
if len(required_failed) > 0:
219
raise bzrlib.errors.InstallFailed(required_failed)
220
for rev_id in failed:
221
note("Failed to install %s" % rev_id)
222
all_failed.update(failed)
224
for rev_id in missing:
226
revision = from_branch.get_revision(rev_id)
227
except bzrlib.errors.NoSuchRevision:
228
if revision in from_history:
232
for parent in [p.revision_id for p in revision.parents]:
233
if not has_revision(to_branch, parent):
234
new_missing.add(parent)
235
missing = new_missing
236
return count, all_failed
239
def old_install_revisions(branch, other, revision_ids, pb):
240
"""Copy revisions from other branch into branch.
242
This is a lower-level function used by a pull or a merge. It
243
incorporates some history from one branch into another, but
244
does not update the revision history or operate on the working
248
Sequence of revisions to copy.
251
Progress bar for copying.
254
if hasattr(other.revision_store, "prefetch"):
255
other.revision_store.prefetch(revision_ids)
256
if hasattr(other.inventory_store, "prefetch"):
257
other.inventory_store.prefetch(revision_ids)
260
pb = bzrlib.ui.ui_factory.progress_bar()
267
for i, rev_id in enumerate(revision_ids):
268
pb.update('fetching revision', i+1, len(revision_ids))
270
rev = other.get_revision(rev_id)
271
except bzrlib.errors.NoSuchRevision:
275
revisions.append(rev)
276
inv = other.get_inventory(rev_id)
277
for key, entry in inv.iter_entries():
278
if entry.text_id is None:
280
if entry.text_id not in branch.text_store:
281
needed_texts.add(entry.text_id)
285
count, cp_fail = branch.text_store.copy_multi(other.text_store,
287
count, cp_fail = branch.inventory_store.copy_multi(other.inventory_store,
289
count, cp_fail = branch.revision_store.copy_multi(other.revision_store,
292
assert len(cp_fail) == 0
293
return count, failures