51
49
def __init__(self, to_repository, from_repository, last_revision=None,
52
find_ghosts=True, fetch_spec=None):
50
pb=None, find_ghosts=True, fetch_spec=None):
53
51
"""Create a repo fetcher.
55
53
:param last_revision: If set, try to limit to the data this revision
57
55
:param find_ghosts: If True search the entire history for ghosts.
56
:param _write_group_acquired_callable: Don't use; this parameter only
57
exists to facilitate a hack done in InterPackRepo.fetch. We would
58
like to remove this parameter.
59
:param pb: ProgressBar object to use; deprecated and ignored.
60
This method will just create one on top of the stack.
59
# repository.fetch has the responsibility for short-circuiting
60
# attempts to copy between a repository and itself.
63
symbol_versioning.warn(
64
symbol_versioning.deprecated_in((1, 14, 0))
65
% "pb parameter to RepoFetcher.__init__")
66
# and for simplicity it is in fact ignored
67
if to_repository.has_same_location(from_repository):
68
# repository.fetch should be taking care of this case.
69
raise errors.BzrError('RepoFetcher run '
70
'between two objects at the same location: '
71
'%r and %r' % (to_repository, from_repository))
61
72
self.to_repository = to_repository
62
73
self.from_repository = from_repository
63
74
self.sink = to_repository._get_sink()
126
137
resume_tokens, missing_keys = self.sink.insert_stream(
127
138
stream, from_format, [])
128
139
if self.to_repository._fallback_repositories:
140
# Find all the parent revisions referenced by the stream, but
141
# not present in the stream, and make sure we have their
143
revision_ids = search.get_keys()
144
parent_maps = self.to_repository.get_parent_map(revision_ids)
146
map(parents.update, parent_maps.itervalues())
147
parents.difference_update(revision_ids)
148
parents.discard(NULL_REVISION)
129
149
missing_keys.update(
130
self._parent_inventories(search.get_keys()))
150
('inventories', rev_id) for rev_id in parents)
132
152
pb.update("Missing keys")
133
153
stream = source.get_stream_for_missing_keys(missing_keys)
159
179
if self._last_revision is NULL_REVISION:
160
180
# explicit limit of no revisions needed
162
return self.to_repository.search_missing_revision_ids(
163
self.from_repository, self._last_revision,
164
find_ghosts=self.find_ghosts)
166
def _parent_inventories(self, revision_ids):
167
# Find all the parent revisions referenced by the stream, but
168
# not present in the stream, and make sure we send their
170
parent_maps = self.to_repository.get_parent_map(revision_ids)
172
map(parents.update, parent_maps.itervalues())
173
parents.discard(NULL_REVISION)
174
parents.difference_update(revision_ids)
175
missing_keys = set(('inventories', rev_id) for rev_id in parents)
182
if (self._last_revision is not None and
183
self.to_repository.has_revision(self._last_revision)):
186
return self.to_repository.search_missing_revision_ids(
187
self.from_repository, self._last_revision,
188
find_ghosts=self.find_ghosts)
189
except errors.NoSuchRevision, e:
190
raise InstallFailed([self._last_revision])
179
193
class Inter1and2Helper(object):
246
260
# yet, and are unlikely to in non-rich-root environments anyway.
247
261
root_id_order.sort(key=operator.itemgetter(0))
248
262
# Create a record stream containing the roots to create.
249
if len(revs) > self.known_graph_threshold:
250
graph = self.source.get_known_graph_ancestry(revs)
251
new_roots_stream = _new_root_data_stream(
252
root_id_order, rev_id_to_root_id, parent_map, self.source, graph)
253
return [('texts', new_roots_stream)]
256
def _new_root_data_stream(
257
root_keys_to_create, rev_id_to_root_id_map, parent_map, repo, graph=None):
258
"""Generate a texts substream of synthesised root entries.
260
Used in fetches that do rich-root upgrades.
262
:param root_keys_to_create: iterable of (root_id, rev_id) pairs describing
263
the root entries to create.
264
:param rev_id_to_root_id_map: dict of known rev_id -> root_id mappings for
265
calculating the parents. If a parent rev_id is not found here then it
266
will be recalculated.
267
:param parent_map: a parent map for all the revisions in
269
:param graph: a graph to use instead of repo.get_graph().
271
for root_key in root_keys_to_create:
272
root_id, rev_id = root_key
273
parent_keys = _parent_keys_for_root_version(
274
root_id, rev_id, rev_id_to_root_id_map, parent_map, repo, graph)
275
yield versionedfile.FulltextContentFactory(
276
root_key, parent_keys, None, '')
279
def _parent_keys_for_root_version(
280
root_id, rev_id, rev_id_to_root_id_map, parent_map, repo, graph=None):
281
"""Get the parent keys for a given root id.
283
A helper function for _new_root_data_stream.
285
# Include direct parents of the revision, but only if they used the same
286
# root_id and are heads.
287
rev_parents = parent_map[rev_id]
289
for parent_id in rev_parents:
290
if parent_id == NULL_REVISION:
292
if parent_id not in rev_id_to_root_id_map:
293
# We probably didn't read this revision, go spend the extra effort
296
tree = repo.revision_tree(parent_id)
297
except errors.NoSuchRevision:
298
# Ghost, fill out rev_id_to_root_id in case we encounter this
300
# But set parent_root_id to None since we don't really know
301
parent_root_id = None
303
parent_root_id = tree.get_root_id()
304
rev_id_to_root_id_map[parent_id] = None
306
# rev_id_to_root_id_map[parent_id] = parent_root_id
307
# memory consumption maybe?
309
parent_root_id = rev_id_to_root_id_map[parent_id]
310
if root_id == parent_root_id:
311
# With stacking we _might_ want to refer to a non-local revision,
312
# but this code path only applies when we have the full content
313
# available, so ghosts really are ghosts, not just the edge of
315
parent_ids.append(parent_id)
317
# root_id may be in the parent anyway.
319
tree = repo.revision_tree(parent_id)
320
except errors.NoSuchRevision:
321
# ghost, can't refer to it.
325
parent_ids.append(tree.inventory[root_id].revision)
326
except errors.NoSuchId:
329
# Drop non-head parents
331
graph = repo.get_graph()
332
heads = graph.heads(parent_ids)
334
for parent_id in parent_ids:
335
if parent_id in heads and parent_id not in selected_ids:
336
selected_ids.append(parent_id)
337
parent_keys = [(root_id, parent_id) for parent_id in selected_ids]
264
for key in root_id_order:
265
root_id, rev_id = key
266
rev_parents = parent_map[rev_id]
267
# We drop revision parents with different file-ids, because
268
# that represents a rename of the root to a different location
269
# - its not actually a parent for us. (We could look for that
270
# file id in the revision tree at considerably more expense,
271
# but for now this is sufficient (and reconcile will catch and
272
# correct this anyway).
273
# When a parent revision is a ghost, we guess that its root id
274
# was unchanged (rather than trimming it from the parent list).
275
parent_keys = tuple((root_id, parent) for parent in rev_parents
276
if parent != NULL_REVISION and
277
rev_id_to_root_id.get(parent, root_id) == root_id)
278
yield FulltextContentFactory(key, parent_keys, None, '')
279
return [('texts', yield_roots())]