126
125
raise NotImplementedError(self.fetch_refs)
128
127
def search_missing_revision_ids(self,
129
find_ghosts=True, revision_ids=None, if_present_ids=None,
128
find_ghosts=True, revision_ids=None,
129
if_present_ids=None, limit=None):
131
130
if limit is not None:
132
131
raise FetchLimitUnsupported(self)
146
145
raise NoSuchRevision(revid, self.source)
147
146
git_shas.append(git_sha)
148
walker = Walker(self.source_store,
149
include=git_shas, exclude=[
150
151
sha for sha in self.target.controldir.get_refs_container().as_dict().values()
151
152
if sha != ZERO_SHA])
152
153
missing_revids = set()
153
154
for entry in walker:
154
for (kind, type_data) in self.source_store.lookup_git_sha(entry.commit.id):
155
for (kind, type_data) in self.source_store.lookup_git_sha(
155
157
if kind == "commit":
156
158
missing_revids.add(type_data[0])
157
159
return self.source.revision_ids_to_search_result(missing_revids)
220
222
new_stop_revids = []
221
223
for revid in stop_revids:
222
224
sha1 = revid_sha_map.get(revid)
223
if (not revid in missing and
224
self._revision_needs_fetching(sha1, revid)):
225
if (revid not in missing and
226
self._revision_needs_fetching(sha1, revid)):
225
227
missing.add(revid)
226
228
new_stop_revids.append(revid)
227
229
stop_revids = set()
251
252
if not v.startswith(SYMREF):
253
for (kind, type_data) in self.source_store.lookup_git_sha(v):
254
if kind == "commit" and self.source.has_revision(type_data[0]):
254
for (kind, type_data) in self.source_store.lookup_git_sha(
256
if kind == "commit" and self.source.has_revision(
255
258
revid = type_data[0]
266
269
old_refs = self._get_target_bzr_refs()
267
270
new_refs = update_refs(old_refs)
268
271
revidmap = self.fetch_objects(
269
[(git_sha, bzr_revid) for (git_sha, bzr_revid) in new_refs.values() if git_sha is None or not git_sha.startswith(SYMREF)], lossy=lossy)
272
[(git_sha, bzr_revid)
273
for (git_sha, bzr_revid) in new_refs.values()
274
if git_sha is None or not git_sha.startswith(SYMREF)],
270
276
for name, (gitid, revid) in viewitems(new_refs):
271
277
if gitid is None:
275
281
gitid = self.source_store._lookup_revision_sha1(revid)
276
282
if gitid.startswith(SYMREF):
277
self.target_refs.set_symbolic_ref(name, gitid[len(SYMREF):])
283
self.target_refs.set_symbolic_ref(
284
name, gitid[len(SYMREF):])
280
287
old_git_id = old_refs[name][0]
288
295
def fetch_objects(self, revs, lossy, limit=None):
289
296
if not lossy and not self.mapping.roundtripping:
290
297
for git_sha, bzr_revid in revs:
291
if bzr_revid is not None and needs_roundtripping(self.source, bzr_revid):
298
if (bzr_revid is not None and
299
needs_roundtripping(self.source, bzr_revid)):
292
300
raise NoPushSupport(self.source, self.target, self.mapping,
294
302
with self.source_store.lock_read():
299
307
object_generator = MissingObjectsIterator(
300
308
self.source_store, self.source, pb)
301
309
for (old_revid, git_sha) in object_generator.import_revisions(
304
new_revid = self.mapping.revision_id_foreign_to_bzr(git_sha)
312
new_revid = self.mapping.revision_id_foreign_to_bzr(
306
315
new_revid = old_revid
318
327
def fetch(self, revision_id=None, pb=None, find_ghosts=False,
319
fetch_spec=None, mapped_refs=None):
328
fetch_spec=None, mapped_refs=None):
320
329
if mapped_refs is not None:
321
330
stop_revisions = mapped_refs
322
331
elif revision_id is not None:
326
335
if recipe[0] in ("search", "proxy-search"):
327
336
stop_revisions = [(None, revid) for revid in recipe[1]]
329
raise AssertionError("Unsupported search result type %s" % recipe[0])
338
raise AssertionError(
339
"Unsupported search result type %s" % recipe[0])
331
stop_revisions = [(None, revid) for revid in self.source.all_revision_ids()]
341
stop_revisions = [(None, revid)
342
for revid in self.source.all_revision_ids()]
332
343
self._warn_slow()
334
345
self.fetch_objects(stop_revisions, lossy=False)
350
361
raise NoPushSupport(self.source, self.target, self.mapping)
351
362
unpeel_map = UnpeelMap.from_repository(self.source)
353
365
def git_update_refs(old_refs):
355
self.old_refs = dict([(k, (v, None)) for (k, v) in viewitems(old_refs)])
368
k: (v, None) for (k, v) in viewitems(old_refs)}
356
369
new_refs = update_refs(self.old_refs)
357
370
for name, (gitid, revid) in viewitems(new_refs):
358
371
if gitid is None:
359
372
git_sha = self.source_store._lookup_revision_sha1(revid)
360
gitid = unpeel_map.re_unpeel_tag(git_sha, old_refs.get(name))
373
gitid = unpeel_map.re_unpeel_tag(
374
git_sha, old_refs.get(name))
361
375
if not overwrite:
362
if remote_divergence(old_refs.get(name), gitid, self.source_store):
376
if remote_divergence(
377
old_refs.get(name), gitid, self.source_store):
363
378
raise DivergedBranches(self.source, self.target)
364
379
ret[name] = gitid
366
381
self._warn_slow()
367
382
with self.source_store.lock_read():
368
new_refs = self.target.send_pack(git_update_refs,
369
self.source_store.generate_lossy_pack_data)
383
new_refs = self.target.send_pack(
384
git_update_refs, self.source_store.generate_lossy_pack_data)
370
385
# FIXME: revidmap?
371
386
return revidmap, self.old_refs, new_refs
401
416
def get_determine_wants_heads(self, wants, include_tags=False):
402
417
wants = set(wants)
403
419
def determine_wants(refs):
404
potential = set(wants)
421
for k, v in viewitems(refs):
422
if k.endswith(ANNOTATED_TAG_SUFFIX):
423
unpeel_lookup[v] = refs[k[:-len(ANNOTATED_TAG_SUFFIX)]]
424
potential = set([unpeel_lookup.get(w, w) for w in wants])
406
for k, unpeeled in viewitems(refs):
426
for k, sha in viewitems(refs):
407
427
if k.endswith(ANNOTATED_TAG_SUFFIX):
409
429
if not is_tag(k):
411
if unpeeled == ZERO_SHA:
413
potential.add(unpeeled)
414
434
return list(potential - self._target_has_shas(potential))
415
435
return determine_wants
426
446
self.fetch(revision_id, find_ghosts=False)
428
448
def search_missing_revision_ids(self,
429
find_ghosts=True, revision_ids=None, if_present_ids=None,
449
find_ghosts=True, revision_ids=None,
450
if_present_ids=None, limit=None):
431
451
if limit is not None:
432
452
raise FetchLimitUnsupported(self)
433
453
if revision_ids is None and if_present_ids is None:
475
495
potential.add(self.source.controldir.get_peeled(k) or v)
476
496
return list(potential - self._target_has_shas(potential))
478
def get_determine_wants_heads(self, wants, include_tags=False):
480
def determine_wants(refs):
481
potential = set(wants)
483
for k, unpeeled in viewitems(refs):
486
if unpeeled == ZERO_SHA:
488
potential.add(self.source.controldir.get_peeled(k) or unpeeled)
489
return list(potential - self._target_has_shas(potential))
490
return determine_wants
492
498
def _warn_slow(self):
493
499
if not config.GlobalConfig().suppress_warning('slow_intervcs_push'):
501
507
:param determine_wants: determine_wants callback
502
508
:param mapping: BzrGitMapping to use
503
509
:param limit: Maximum number of commits to import.
504
:return: Tuple with pack hint, last imported revision id and remote refs
510
:return: Tuple with pack hint, last imported revision id and remote
506
513
raise NotImplementedError(self.fetch_objects)
537
544
determine_wants = self.determine_wants_all
539
546
(pack_hint, _, remote_refs) = self.fetch_objects(determine_wants,
541
548
if pack_hint is not None and self.target._format.pack_compresses:
542
549
self.target.pack(hint=pack_hint)
543
550
return remote_refs
573
580
wants_recorder, graph_walker, store.get_raw)
574
581
trace.mutter("Importing %d new revisions",
575
582
len(wants_recorder.wants))
576
(pack_hint, last_rev) = import_git_objects(self.target,
577
mapping, objects_iter, store, wants_recorder.wants, pb,
583
(pack_hint, last_rev) = import_git_objects(
584
self.target, mapping, objects_iter, store,
585
wants_recorder.wants, pb, limit)
579
586
return (pack_hint, last_rev, wants_recorder.remote_refs)
603
610
self._warn_slow()
604
611
remote_refs = self.source.controldir.get_refs_container().as_dict()
605
612
wants = determine_wants(remote_refs)
607
613
pb = ui.ui_factory.nested_progress_bar()
608
614
target_git_object_retriever = get_object_store(self.target, mapping)
610
616
target_git_object_retriever.lock_write()
612
(pack_hint, last_rev) = import_git_objects(self.target,
613
mapping, self.source._git.object_store,
618
(pack_hint, last_rev) = import_git_objects(
619
self.target, mapping, self.source._git.object_store,
614
620
target_git_object_retriever, wants, pb, limit)
615
621
return (pack_hint, last_rev, remote_refs)
640
646
raise LossyPushToSameVCS(self.source, self.target)
641
647
old_refs = self.target.controldir.get_refs_container()
643
650
def determine_wants(heads):
644
old_refs = dict([(k, (v, None)) for (k, v) in viewitems(heads.as_dict())])
651
old_refs = dict([(k, (v, None))
652
for (k, v) in viewitems(heads.as_dict())])
645
653
new_refs = update_refs(old_refs)
646
654
ref_changes.update(new_refs)
647
655
return [sha1 for (sha1, bzr_revid) in viewvalues(new_refs)]
651
659
new_refs = self.target.controldir.get_refs_container()
652
660
return None, old_refs, new_refs
654
def fetch_objects(self, determine_wants, mapping=None, limit=None, lossy=False):
662
def fetch_objects(self, determine_wants, mapping=None, limit=None,
655
664
raise NotImplementedError(self.fetch_objects)
657
666
def _target_has_shas(self, shas):
658
return set([sha for sha in shas if sha in self.target._git.object_store])
668
[sha for sha in shas if sha in self.target._git.object_store])
660
670
def fetch(self, revision_id=None, find_ghosts=False,
661
mapping=None, fetch_spec=None, branches=None, limit=None, include_tags=False):
671
mapping=None, fetch_spec=None, branches=None, limit=None,
662
673
if mapping is None:
663
674
mapping = self.source.get_mapping()
664
675
if revision_id is not None:
684
695
elif fetch_spec is None and revision_id is None:
685
696
determine_wants = self.determine_wants_all
687
determine_wants = self.get_determine_wants_revids(args, include_tags=include_tags)
698
determine_wants = self.get_determine_wants_revids(
699
args, include_tags=include_tags)
688
700
wants_recorder = DetermineWantsRecorder(determine_wants)
689
701
self.fetch_objects(wants_recorder, mapping, limit=limit)
690
702
return wants_recorder.remote_refs
708
720
class InterLocalGitLocalGitRepository(InterGitGitRepository):
710
def fetch_objects(self, determine_wants, mapping=None, limit=None, lossy=False):
722
def fetch_objects(self, determine_wants, mapping=None, limit=None,
712
725
raise LossyPushToSameVCS(self.source, self.target)
713
726
if limit is not None:
714
727
raise FetchLimitUnsupported(self)
715
refs = self.source._git.fetch(self.target._git, determine_wants)
728
from .remote import DefaultProgressReporter
729
pb = ui.ui_factory.nested_progress_bar()
730
progress = DefaultProgressReporter(pb).progress
732
refs = self.source._git.fetch(
733
self.target._git, determine_wants,
716
737
return (None, None, refs)
725
746
class InterRemoteGitLocalGitRepository(InterGitGitRepository):
727
def fetch_objects(self, determine_wants, mapping=None, limit=None, lossy=False):
748
def fetch_objects(self, determine_wants, mapping=None, limit=None,
729
751
raise LossyPushToSameVCS(self.source, self.target)
730
752
if limit is not None:
731
753
raise FetchLimitUnsupported(self)
732
754
graphwalker = self.target._git.get_graph_walker()
733
if CAPABILITY_THIN_PACK in self.source.controldir._client._fetch_capabilities:
755
if (CAPABILITY_THIN_PACK in
756
self.source.controldir._client._fetch_capabilities):
734
757
# TODO(jelmer): Avoid reading entire file into memory and
735
758
# only processing it after the whole file has been fetched.