/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/git/interrepo.py

  • Committer: Jelmer Vernooij
  • Date: 2018-11-11 04:08:32 UTC
  • mto: (7143.16.20 even-more-cleanups)
  • mto: This revision was merged to the branch mainline in revision 7175.
  • Revision ID: jelmer@jelmer.uk-20181111040832-nsljjynzzwmznf3h
Run autopep8.

Show diffs side-by-side

added added

removed removed

Lines of Context:
125
125
        raise NotImplementedError(self.fetch_refs)
126
126
 
127
127
    def search_missing_revision_ids(self,
128
 
            find_ghosts=True, revision_ids=None, if_present_ids=None,
129
 
            limit=None):
 
128
                                    find_ghosts=True, revision_ids=None, if_present_ids=None,
 
129
                                    limit=None):
130
130
        if limit is not None:
131
131
            raise FetchLimitUnsupported(self)
132
132
        git_shas = []
145
145
                    raise NoSuchRevision(revid, self.source)
146
146
                git_shas.append(git_sha)
147
147
            walker = Walker(self.source_store,
148
 
                include=git_shas, exclude=[
149
 
                    sha for sha in self.target.controldir.get_refs_container().as_dict().values()
150
 
                    if sha != ZERO_SHA])
 
148
                            include=git_shas, exclude=[
 
149
                                sha for sha in self.target.controldir.get_refs_container().as_dict().values()
 
150
                                if sha != ZERO_SHA])
151
151
            missing_revids = set()
152
152
            for entry in walker:
153
153
                for (kind, type_data) in self.source_store.lookup_git_sha(entry.commit.id):
220
220
                for revid in stop_revids:
221
221
                    sha1 = revid_sha_map.get(revid)
222
222
                    if (not revid in missing and
223
 
                        self._revision_needs_fetching(sha1, revid)):
 
223
                            self._revision_needs_fetching(sha1, revid)):
224
224
                        missing.add(revid)
225
225
                        new_stop_revids.append(revid)
226
226
                stop_revids = set()
272
272
                    except KeyError:
273
273
                        gitid = self.source_store._lookup_revision_sha1(revid)
274
274
                if gitid.startswith(SYMREF):
275
 
                    self.target_refs.set_symbolic_ref(name, gitid[len(SYMREF):])
 
275
                    self.target_refs.set_symbolic_ref(
 
276
                        name, gitid[len(SYMREF):])
276
277
                else:
277
278
                    try:
278
279
                        old_git_id = old_refs[name][0]
296
297
                object_generator = MissingObjectsIterator(
297
298
                    self.source_store, self.source, pb)
298
299
                for (old_revid, git_sha) in object_generator.import_revisions(
299
 
                    todo, lossy=lossy):
 
300
                        todo, lossy=lossy):
300
301
                    if lossy:
301
 
                        new_revid = self.mapping.revision_id_foreign_to_bzr(git_sha)
 
302
                        new_revid = self.mapping.revision_id_foreign_to_bzr(
 
303
                            git_sha)
302
304
                    else:
303
305
                        new_revid = old_revid
304
306
                        try:
313
315
                pb.finished()
314
316
 
315
317
    def fetch(self, revision_id=None, pb=None, find_ghosts=False,
316
 
            fetch_spec=None, mapped_refs=None):
 
318
              fetch_spec=None, mapped_refs=None):
317
319
        if mapped_refs is not None:
318
320
            stop_revisions = mapped_refs
319
321
        elif revision_id is not None:
323
325
            if recipe[0] in ("search", "proxy-search"):
324
326
                stop_revisions = [(None, revid) for revid in recipe[1]]
325
327
            else:
326
 
                raise AssertionError("Unsupported search result type %s" % recipe[0])
 
328
                raise AssertionError(
 
329
                    "Unsupported search result type %s" % recipe[0])
327
330
        else:
328
 
            stop_revisions = [(None, revid) for revid in self.source.all_revision_ids()]
 
331
            stop_revisions = [(None, revid)
 
332
                              for revid in self.source.all_revision_ids()]
329
333
        self._warn_slow()
330
334
        try:
331
335
            self.fetch_objects(stop_revisions, lossy=False)
347
351
            raise NoPushSupport(self.source, self.target, self.mapping)
348
352
        unpeel_map = UnpeelMap.from_repository(self.source)
349
353
        revidmap = {}
 
354
 
350
355
        def git_update_refs(old_refs):
351
356
            ret = {}
352
 
            self.old_refs = dict([(k, (v, None)) for (k, v) in viewitems(old_refs)])
 
357
            self.old_refs = dict([(k, (v, None))
 
358
                                  for (k, v) in viewitems(old_refs)])
353
359
            self.new_refs = update_refs(self.old_refs)
354
360
            for name, (gitid, revid) in viewitems(self.new_refs):
355
361
                if gitid is None:
356
362
                    git_sha = self.source_store._lookup_revision_sha1(revid)
357
 
                    gitid = unpeel_map.re_unpeel_tag(git_sha, old_refs.get(name))
 
363
                    gitid = unpeel_map.re_unpeel_tag(
 
364
                        git_sha, old_refs.get(name))
358
365
                if not overwrite:
359
366
                    if remote_divergence(old_refs.get(name), gitid, self.source_store):
360
367
                        raise DivergedBranches(self.source, self.target)
363
370
        self._warn_slow()
364
371
        with self.source_store.lock_read():
365
372
            new_refs = self.target.send_pack(git_update_refs,
366
 
                    self.source_store.generate_lossy_pack_data)
 
373
                                             self.source_store.generate_lossy_pack_data)
367
374
        # FIXME: revidmap?
368
375
        return revidmap, self.old_refs, self.new_refs
369
376
 
397
404
 
398
405
    def get_determine_wants_heads(self, wants, include_tags=False):
399
406
        wants = set(wants)
 
407
 
400
408
        def determine_wants(refs):
401
409
            potential = set(wants)
402
410
            if include_tags:
423
431
        self.fetch(revision_id, find_ghosts=False)
424
432
 
425
433
    def search_missing_revision_ids(self,
426
 
            find_ghosts=True, revision_ids=None, if_present_ids=None,
427
 
            limit=None):
 
434
                                    find_ghosts=True, revision_ids=None, if_present_ids=None,
 
435
                                    limit=None):
428
436
        if limit is not None:
429
437
            raise FetchLimitUnsupported(self)
430
438
        if revision_ids is None and if_present_ids is None:
474
482
 
475
483
    def get_determine_wants_heads(self, wants, include_tags=False):
476
484
        wants = set(wants)
 
485
 
477
486
        def determine_wants(refs):
478
487
            potential = set(wants)
479
488
            if include_tags:
482
491
                        continue
483
492
                    if unpeeled == ZERO_SHA:
484
493
                        continue
485
 
                    potential.add(self.source.controldir.get_peeled(k) or unpeeled)
 
494
                    potential.add(
 
495
                        self.source.controldir.get_peeled(k) or unpeeled)
486
496
            return list(potential - self._target_has_shas(potential))
487
497
        return determine_wants
488
498
 
523
533
                interesting_heads = recipe[1]
524
534
            else:
525
535
                raise AssertionError("Unsupported search result type %s" %
526
 
                        recipe[0])
 
536
                                     recipe[0])
527
537
        else:
528
538
            interesting_heads = None
529
539
 
534
544
            determine_wants = self.determine_wants_all
535
545
 
536
546
        (pack_hint, _, remote_refs) = self.fetch_objects(determine_wants,
537
 
            mapping)
 
547
                                                         mapping)
538
548
        if pack_hint is not None and self.target._format.pack_compresses:
539
549
            self.target.pack(hint=pack_hint)
540
550
        return remote_refs
571
581
                trace.mutter("Importing %d new revisions",
572
582
                             len(wants_recorder.wants))
573
583
                (pack_hint, last_rev) = import_git_objects(self.target,
574
 
                    mapping, objects_iter, store, wants_recorder.wants, pb,
575
 
                    limit)
 
584
                                                           mapping, objects_iter, store, wants_recorder.wants, pb,
 
585
                                                           limit)
576
586
                return (pack_hint, last_rev, wants_recorder.remote_refs)
577
587
            finally:
578
588
                pb.finished()
607
617
            target_git_object_retriever.lock_write()
608
618
            try:
609
619
                (pack_hint, last_rev) = import_git_objects(self.target,
610
 
                    mapping, self.source._git.object_store,
611
 
                    target_git_object_retriever, wants, pb, limit)
 
620
                                                           mapping, self.source._git.object_store,
 
621
                                                           target_git_object_retriever, wants, pb, limit)
612
622
                return (pack_hint, last_rev, remote_refs)
613
623
            finally:
614
624
                target_git_object_retriever.unlock()
637
647
            raise LossyPushToSameVCS(self.source, self.target)
638
648
        old_refs = self.target.controldir.get_refs_container()
639
649
        ref_changes = {}
 
650
 
640
651
        def determine_wants(heads):
641
 
            old_refs = dict([(k, (v, None)) for (k, v) in viewitems(heads.as_dict())])
 
652
            old_refs = dict([(k, (v, None))
 
653
                             for (k, v) in viewitems(heads.as_dict())])
642
654
            new_refs = update_refs(old_refs)
643
655
            ref_changes.update(new_refs)
644
656
            return [sha1 for (sha1, bzr_revid) in viewvalues(new_refs)]
681
693
        elif fetch_spec is None and revision_id is None:
682
694
            determine_wants = self.determine_wants_all
683
695
        else:
684
 
            determine_wants = self.get_determine_wants_revids(args, include_tags=include_tags)
 
696
            determine_wants = self.get_determine_wants_revids(
 
697
                args, include_tags=include_tags)
685
698
        wants_recorder = DetermineWantsRecorder(determine_wants)
686
699
        self.fetch_objects(wants_recorder, mapping, limit=limit)
687
700
        return wants_recorder.remote_refs
714
727
        progress = DefaultProgressReporter(pb).progress
715
728
        try:
716
729
            refs = self.source._git.fetch(
717
 
                    self.target._git, determine_wants,
718
 
                    progress=progress)
 
730
                self.target._git, determine_wants,
 
731
                progress=progress)
719
732
        finally:
720
733
            pb.finished()
721
734
        return (None, None, refs)