94
94
pb = ui.ui_factory.nested_progress_bar()
95
95
pb.show_pct = pb.show_count = False
97
pb.update(gettext("Finding revisions"), 0, 2)
97
pb.update("Finding revisions", 0, 2)
98
98
search_result = self._revids_to_fetch()
99
99
mutter('fetching: %s', search_result)
100
100
if search_result.is_empty():
102
pb.update(gettext("Fetching revisions"), 1, 2)
102
pb.update("Fetching revisions", 1, 2)
103
103
self._fetch_everything_for_search(search_result)
161
161
elif self._last_revision == NULL_REVISION:
162
162
# fetch_spec is None + last_revision is null => empty fetch.
163
163
# explicit limit of no revisions needed
164
return _mod_graph.EmptySearchResult()
164
return graph.EmptySearchResult()
165
165
elif self._last_revision is not None:
166
return _mod_graph.NotInOtherForRevs(self.to_repository,
166
return graph.NotInOtherForRevs(self.to_repository,
167
167
self.from_repository, [self._last_revision],
168
168
find_ghosts=self.find_ghosts).execute()
169
169
else: # self._last_revision is None:
170
return _mod_graph.EverythingNotInOther(self.to_repository,
170
return graph.EverythingNotInOther(self.to_repository,
171
171
self.from_repository,
172
172
find_ghosts=self.find_ghosts).execute()
372
371
self.source_repo = None
373
372
self.target_repo = None
374
373
self.target_repo_kind = None
377
375
def add_revision_ids(self, revision_ids):
378
376
"""Add revision_ids to the set of revision_ids to be fetched."""
379
377
self._explicit_rev_ids.update(revision_ids)
381
379
def make_fetch_spec(self):
382
380
"""Build a SearchResult or PendingAncestryResult or etc."""
383
381
if self.target_repo_kind is None or self.source_repo is None:
384
382
raise AssertionError(
385
383
'Incomplete FetchSpecFactory: %r' % (self.__dict__,))
386
384
if len(self._explicit_rev_ids) == 0 and self.source_branch is None:
387
if self.limit is not None:
388
raise NotImplementedError(
389
"limit is only supported with a source branch set")
390
385
# Caller hasn't specified any revisions or source branch
391
386
if self.target_repo_kind == TargetRepoKinds.EMPTY:
392
return _mod_graph.EverythingResult(self.source_repo)
387
return graph.EverythingResult(self.source_repo)
394
389
# We want everything not already in the target (or target's
396
return _mod_graph.EverythingNotInOther(
391
return graph.EverythingNotInOther(
397
392
self.target_repo, self.source_repo).execute()
398
393
heads_to_fetch = set(self._explicit_rev_ids)
394
tags_to_fetch = set()
399
395
if self.source_branch is not None:
400
must_fetch, if_present_fetch = self.source_branch.heads_to_fetch()
397
tags_to_fetch.update(
398
self.source_branch.tags.get_reverse_tag_dict())
399
except errors.TagsNotSupported:
401
401
if self.source_branch_stop_revision_id is not None:
402
# Replace the tip rev from must_fetch with the stop revision
403
# XXX: this might be wrong if the tip rev is also in the
404
# must_fetch set for other reasons (e.g. it's the tip of
405
# multiple loom threads?), but then it's pretty unclear what it
406
# should mean to specify a stop_revision in that case anyway.
407
must_fetch.discard(self.source_branch.last_revision())
408
must_fetch.add(self.source_branch_stop_revision_id)
409
heads_to_fetch.update(must_fetch)
411
if_present_fetch = set()
402
heads_to_fetch.add(self.source_branch_stop_revision_id)
404
heads_to_fetch.add(self.source_branch.last_revision())
412
405
if self.target_repo_kind == TargetRepoKinds.EMPTY:
413
406
# PendingAncestryResult does not raise errors if a requested head
414
407
# is absent. Ideally it would support the
415
408
# required_ids/if_present_ids distinction, but in practice
416
409
# heads_to_fetch will almost certainly be present so this doesn't
418
all_heads = heads_to_fetch.union(if_present_fetch)
419
ret = _mod_graph.PendingAncestryResult(all_heads, self.source_repo)
420
if self.limit is not None:
421
graph = self.source_repo.get_graph()
422
topo_order = list(graph.iter_topo_order(ret.get_keys()))
423
result_set = topo_order[:self.limit]
424
ret = self.source_repo.revision_ids_to_search_result(result_set)
427
return _mod_graph.NotInOtherForRevs(self.target_repo, self.source_repo,
428
required_ids=heads_to_fetch, if_present_ids=if_present_fetch,
429
limit=self.limit).execute()
411
all_heads = heads_to_fetch.union(tags_to_fetch)
412
return graph.PendingAncestryResult(all_heads, self.source_repo)
413
return graph.NotInOtherForRevs(self.target_repo, self.source_repo,
414
required_ids=heads_to_fetch, if_present_ids=tags_to_fetch