/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/remote.py

  • Committer: Breezy landing bot
  • Author(s): Jelmer Vernooij
  • Date: 2018-11-16 18:59:44 UTC
  • mfrom: (7143.15.15 more-cleanups)
  • Revision ID: breezy.the.bot@gmail.com-20181116185944-biefv1sub37qfybm
Sprinkle some PEP8iness.

Merged from https://code.launchpad.net/~jelmer/brz/more-cleanups/+merge/358611

Show diffs side-by-side

added added

removed removed

Lines of Context:
135
135
    def _lookup_revno(self, revid):
136
136
        try:
137
137
            return _quick_lookup_revno(self.source_branch, self.target_branch,
138
 
                revid)
 
138
                                       revid)
139
139
        except GitSmartRemoteNotSupported:
140
140
            return None
141
141
 
191
191
    :param message: Message sent by the remote git server
192
192
    """
193
193
    message = str(message).strip()
194
 
    if (message.startswith("Could not find Repository ") or
195
 
        message == 'Repository not found.' or
196
 
        (message.startswith('Repository ') and message.endswith(' not found.'))):
 
194
    if (message.startswith("Could not find Repository ")
 
195
        or message == 'Repository not found.'
 
196
            or (message.startswith('Repository ') and
 
197
                message.endswith(' not found.'))):
197
198
        return NotBranchError(url, message)
198
199
    if message == "HEAD failed to update":
199
200
        base_url, _ = urlutils.split_segment_parameters(url)
264
265
        if self._host == '':
265
266
            # return dulwich.client.LocalGitClient()
266
267
            return dulwich.client.SubprocessGitClient()
267
 
        return dulwich.client.TCPGitClient(self._host, self._port,
268
 
            report_activity=self._report_activity)
 
268
        return dulwich.client.TCPGitClient(
 
269
            self._host, self._port, report_activity=self._report_activity)
269
270
 
270
271
 
271
272
class SSHSocketWrapper(object):
290
291
        self.bzr_ssh_vendor = ssh._get_ssh_vendor()
291
292
 
292
293
    def run_command(self, host, command, username=None, port=None):
293
 
        connection = self.bzr_ssh_vendor.connect_ssh(username=username,
294
 
            password=None, port=port, host=host, command=command)
 
294
        connection = self.bzr_ssh_vendor.connect_ssh(
 
295
            username=username, password=None, port=port, host=host,
 
296
            command=command)
295
297
        (kind, io_object) = connection.get_sock_or_pipes()
296
298
        if kind == 'socket':
297
299
            return SSHSocketWrapper(io_object)
299
301
            raise AssertionError("Unknown io object kind %r'" % kind)
300
302
 
301
303
 
302
 
#dulwich.client.get_ssh_vendor = DulwichSSHVendor
 
304
# dulwich.client.get_ssh_vendor = DulwichSSHVendor
303
305
 
304
306
 
305
307
class SSHGitSmartTransport(GitSmartTransport):
318
320
            self._client = None
319
321
            return ret
320
322
        location_config = config.LocationConfig(self.base)
321
 
        client = dulwich.client.SSHGitClient(self._host, self._port, self._username,
 
323
        client = dulwich.client.SSHGitClient(
 
324
            self._host, self._port, self._username,
322
325
            report_activity=self._report_activity)
323
326
        # Set up alternate pack program paths
324
327
        upload_pack = location_config.get_user_option('git_upload_pack')
462
465
        if refname != b'HEAD' and refname in self.get_refs_container():
463
466
            raise AlreadyBranchError(self.user_url)
464
467
        if refname in self.get_refs_container():
465
 
            ref_chain, unused_sha = self.get_refs_container().follow(self._get_selected_ref(None))
 
468
            ref_chain, unused_sha = self.get_refs_container().follow(
 
469
                self._get_selected_ref(None))
466
470
            if ref_chain[0] == b'HEAD':
467
471
                refname = ref_chain[1]
468
472
        repo = self.open_repository()
470
474
 
471
475
    def destroy_branch(self, name=None):
472
476
        refname = self._get_selected_ref(name)
 
477
 
473
478
        def get_changed_refs(old_refs):
474
479
            ret = dict(old_refs)
475
 
            if not refname in ret:
 
480
            if refname not in ret:
476
481
                raise NotBranchError(self.user_url)
477
482
            ret[refname] = dulwich.client.ZERO_SHA
478
483
            return ret
 
484
 
479
485
        def generate_pack_data(have, want, ofs_delta=False):
480
486
            return pack_objects_to_data([])
481
487
        self.send_pack(get_changed_refs, generate_pack_data)
507
513
        return None
508
514
 
509
515
    def open_branch(self, name=None, unsupported=False,
510
 
            ignore_fallbacks=False, ref=None, possible_transports=None,
511
 
            nascent_ok=False):
 
516
                    ignore_fallbacks=False, ref=None, possible_transports=None,
 
517
                    nascent_ok=False):
512
518
        repo = self.open_repository()
513
519
        ref = self._get_selected_ref(name, ref)
514
520
        try:
517
523
                        controldir=self)
518
524
        except NotGitRepository:
519
525
            raise NotBranchError(self.root_transport.base,
520
 
                    controldir=self)
 
526
                                 controldir=self)
521
527
        ref_chain, unused_sha = self.get_refs_container().follow(ref)
522
528
        return RemoteGitBranch(self, repo, ref_chain[-1])
523
529
 
534
540
        if self._refs is not None:
535
541
            return self._refs
536
542
        result = self.fetch_pack(lambda x: None, None,
537
 
            lambda x: None, lambda x: trace.mutter("git: %s" % x))
 
543
                                 lambda x: None,
 
544
                                 lambda x: trace.mutter("git: %s" % x))
538
545
        self._refs = remote_refs_dict_to_container(
539
 
                result.refs, result.symrefs)
 
546
            result.refs, result.symrefs)
540
547
        return self._refs
541
548
 
542
549
    def push_branch(self, source, revision_id=None, overwrite=False,
574
581
                        raise errors.NoRoundtrippingSupport(
575
582
                            source, self.open_branch(name=name, nascent_ok=True))
576
583
                if not overwrite:
577
 
                    if remote_divergence(ret.get(refname), new_sha, source_store):
 
584
                    if remote_divergence(ret.get(refname), new_sha,
 
585
                                         source_store):
578
586
                        raise DivergedBranches(
579
 
                                source, self.open_branch(name, nascent_ok=True))
 
587
                            source, self.open_branch(name, nascent_ok=True))
580
588
                ret[refname] = new_sha
581
589
                return ret
582
590
            if lossy:
585
593
                generate_pack_data = source_store.generate_pack_data
586
594
            new_refs = self.send_pack(get_changed_refs, generate_pack_data)
587
595
        push_result.new_revid = repo.lookup_foreign_revision_id(
588
 
                new_refs[refname])
 
596
            new_refs[refname])
589
597
        try:
590
598
            old_remote = self._refs[refname]
591
599
        except KeyError:
596
604
        if old_remote != ZERO_SHA:
597
605
            push_result.branch_push_result = GitBranchPushResult()
598
606
            push_result.branch_push_result.source_branch = source
599
 
            push_result.branch_push_result.target_branch = push_result.target_branch
 
607
            push_result.branch_push_result.target_branch = (
 
608
                push_result.target_branch)
600
609
            push_result.branch_push_result.local_branch = None
601
 
            push_result.branch_push_result.master_branch = push_result.target_branch
 
610
            push_result.branch_push_result.master_branch = (
 
611
                push_result.target_branch)
602
612
            push_result.branch_push_result.old_revid = push_result.old_revid
603
613
            push_result.branch_push_result.new_revid = push_result.new_revid
604
 
            push_result.branch_push_result.new_original_revid = push_result.new_original_revid
 
614
            push_result.branch_push_result.new_original_revid = (
 
615
                push_result.new_original_revid)
605
616
        if source.get_push_location() is None or remember:
606
617
            source.set_push_location(push_result.target_branch.base)
607
618
        return push_result
631
642
                def report_progress(cur, total):
632
643
                    pb.update("generating index", cur, total)
633
644
                self.data.create_index(path,
634
 
                    progress=report_progress)
 
645
                                       progress=report_progress)
635
646
            finally:
636
647
                pb.finished()
637
648
        return load_pack_index(path)
649
660
 
650
661
    def __init__(self, transport, *args, **kwargs):
651
662
        self.transport = transport
652
 
        super(BzrGitHttpClient, self).__init__(transport.external_url(), *args, **kwargs)
 
663
        super(BzrGitHttpClient, self).__init__(
 
664
            transport.external_url(), *args, **kwargs)
653
665
 
654
666
    def _http_request(self, url, headers=None, data=None,
655
667
                      allow_compression=False):
752
764
        else:
753
765
            raise NotBranchError(transport.base)
754
766
        if not _found:
755
 
            pass # TODO(jelmer): Actually probe for something
 
767
            pass  # TODO(jelmer): Actually probe for something
756
768
        return RemoteGitDir(transport, self, client, client_path)
757
769
 
758
770
    def get_format_description(self):
766
778
            external_url = transport.external_url()
767
779
        except InProcessTransport:
768
780
            raise NotBranchError(path=transport.base)
769
 
        return (external_url.startswith("http:") or
770
 
                external_url.startswith("https:") or
771
 
                external_url.startswith("git+") or
772
 
                external_url.startswith("git:"))
 
781
        return (external_url.startswith("http:")
 
782
                or external_url.startswith("https:")
 
783
                or external_url.startswith("git+")
 
784
                or external_url.startswith("git:"))
773
785
 
774
786
 
775
787
class GitRemoteRevisionTree(RevisionTree):
789
801
        # git-upload-archive(1) generaly only supports refs. So let's see if we
790
802
        # can find one.
791
803
        reverse_refs = {
792
 
                v: k for (k, v) in
793
 
                self._repository.controldir.get_refs_container().as_dict().items()}
 
804
            v: k for (k, v) in
 
805
            self._repository.controldir.get_refs_container().as_dict().items()}
794
806
        try:
795
807
            committish = reverse_refs[commit]
796
808
        except KeyError:
798
810
            # Let's hope for the best.
799
811
            committish = commit
800
812
        self._repository.archive(
801
 
                format, committish, f.write,
802
 
                subdirs=([subdir] if subdir else None),
803
 
                prefix=(root+'/') if root else '')
 
813
            format, committish, f.write,
 
814
            subdirs=([subdir] if subdir else None),
 
815
            prefix=(root + '/') if root else '')
804
816
        f.seek(0)
805
817
        return osutils.file_iterator(f)
806
818
 
839
851
        fd, path = tempfile.mkstemp(suffix=".pack")
840
852
        try:
841
853
            self.fetch_pack(determine_wants, graph_walker,
842
 
                lambda x: os.write(fd, x), progress)
 
854
                            lambda x: os.write(fd, x), progress)
843
855
        finally:
844
856
            os.close(fd)
845
857
        if os.path.getsize(path) == 0:
847
859
        return TemporaryPackIterator(path[:-len(".pack")], resolve_ext_ref)
848
860
 
849
861
    def lookup_bzr_revision_id(self, bzr_revid, mapping=None):
850
 
        # This won't work for any round-tripped bzr revisions, but it's a start..
 
862
        # This won't work for any round-tripped bzr revisions, but it's a
 
863
        # start..
851
864
        try:
852
865
            return mapping_registry.revision_id_bzr_to_foreign(bzr_revid)
853
866
        except InvalidRevisionId:
883
896
 
884
897
    def _set_ref(self, name, sha):
885
898
        ref = tag_name_to_ref(name)
 
899
 
886
900
        def get_changed_refs(old_refs):
887
901
            ret = dict(old_refs)
888
902
            if sha == dulwich.client.ZERO_SHA and ref not in ret:
889
903
                raise NoSuchTag(name)
890
904
            ret[ref] = sha
891
905
            return ret
 
906
 
892
907
        def generate_pack_data(have, want, ofs_delta=False):
893
908
            return pack_objects_to_data([])
894
909
        self.repository.send_pack(get_changed_refs, generate_pack_data)
899
914
    def __init__(self, controldir, repository, name):
900
915
        self._sha = None
901
916
        super(RemoteGitBranch, self).__init__(controldir, repository, name,
902
 
                RemoteGitBranchFormat())
 
917
                                              RemoteGitBranchFormat())
903
918
 
904
919
    def last_revision_info(self):
905
920
        raise GitSmartRemoteNotSupported(self.last_revision_info, self)