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

  • Committer: Jelmer Vernooij
  • Date: 2019-03-05 07:32:38 UTC
  • mto: (7290.1.21 work)
  • mto: This revision was merged to the branch mainline in revision 7311.
  • Revision ID: jelmer@jelmer.uk-20190305073238-zlqn981opwnqsmzi
Add appveyor configuration.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 
23
23
"""A GIT branch and repository format implementation for bzr."""
24
24
 
 
25
from __future__ import absolute_import
 
26
 
25
27
import os
26
28
import sys
27
29
 
31
33
    __version__ as breezy_version,
32
34
    errors as brz_errors,
33
35
    trace,
34
 
    urlutils,
35
36
    version_info,
36
37
    )
37
38
 
102
103
 
103
104
class LocalGitProber(Prober):
104
105
 
105
 
    @classmethod
106
 
    def priority(klass, transport):
107
 
        return 10
108
 
 
109
106
    def probe_transport(self, transport):
110
107
        try:
111
108
            external_url = transport.external_url()
115
112
                external_url.startswith("https:")):
116
113
            # Already handled by RemoteGitProber
117
114
            raise brz_errors.NotBranchError(path=transport.base)
 
115
        from .. import urlutils
118
116
        if urlutils.split(transport.base)[1] == ".git":
119
117
            raise brz_errors.NotBranchError(path=transport.base)
120
118
        if not transport.has_any(['objects', '.git/objects', '.git']):
144
142
    return "git/Breezy/%s" % breezy_version
145
143
 
146
144
 
147
 
def is_github_url(url):
148
 
    (scheme, user, password, host, port,
149
 
     path) = urlutils.parse_url(url)
150
 
    return host in ("github.com", "gopkg.in")
151
 
 
152
 
 
153
145
class RemoteGitProber(Prober):
154
146
 
155
 
    @classmethod
156
 
    def priority(klass, transport):
157
 
        # This is a surprisingly good heuristic to determine whether this
158
 
        # prober is more likely to succeed than the Bazaar one.
159
 
        if 'git' in transport.base:
160
 
            return -15
161
 
        return -10
162
 
 
163
147
    def probe_http_transport(self, transport):
164
148
        # This function intentionally doesn't use any of the support code under
165
149
        # breezy.git, since it's called for every repository that's
166
150
        # accessed over HTTP, whether it's Git, Bzr or something else.
167
151
        # Importing Dulwich and the other support code adds unnecessray slowdowns.
168
 
        base_url = urlutils.strip_segment_parameters(transport.external_url())
 
152
        from .. import urlutils
 
153
        base_url, _ = urlutils.split_segment_parameters(
 
154
            transport.external_url())
169
155
        url = urlutils.URL.from_string(base_url)
170
156
        url.user = url.quoted_user = None
171
157
        url.password = url.quoted_password = None
172
 
        host = url.host
173
158
        url = urlutils.join(str(url), "info/refs") + "?service=git-upload-pack"
 
159
        from ..transport.http import Request
174
160
        headers = {"Content-Type": "application/x-git-upload-pack-request",
175
161
                   "Accept": "application/x-git-upload-pack-result",
176
162
                   }
177
 
        if is_github_url(url):
 
163
        req = Request('GET', url, accepted_errors=[200, 403, 404, 405],
 
164
                      headers=headers)
 
165
        (scheme, user, password, host, port,
 
166
         path) = urlutils.parse_url(req.get_full_url())
 
167
        if host == "github.com":
178
168
            # GitHub requires we lie.
179
169
            # https://github.com/dulwich/dulwich/issues/562
180
 
            headers["User-Agent"] = user_agent_for_github()
 
170
            req.add_header("User-Agent", user_agent_for_github())
181
171
        elif host == "bazaar.launchpad.net":
182
172
            # Don't attempt Git probes against bazaar.launchpad.net; pad.lv/1744830
183
173
            raise brz_errors.NotBranchError(transport.base)
184
 
        resp = transport.request('GET', url, headers=headers)
185
 
        if resp.status in (404, 405):
186
 
            raise brz_errors.NotBranchError(transport.base)
187
 
        elif resp.status == 400 and resp.reason == 'no such method: info':
188
 
            # hgweb :(
189
 
            raise brz_errors.NotBranchError(transport.base)
190
 
        elif resp.status != 200:
191
 
            raise brz_errors.UnexpectedHttpStatus(url, resp.status)
192
 
 
193
 
        ct = resp.getheader("Content-Type")
194
 
        if ct and ct.startswith("application/x-git"):
 
174
        resp = transport._perform(req)
 
175
        if resp.code in (404, 405):
 
176
            raise brz_errors.NotBranchError(transport.base)
 
177
        headers = resp.headers
 
178
        ct = headers.get("Content-Type")
 
179
        if ct is None:
 
180
            raise brz_errors.NotBranchError(transport.base)
 
181
        if ct.startswith("application/x-git"):
195
182
            from .remote import RemoteGitControlDirFormat
196
183
            return RemoteGitControlDirFormat()
197
 
        elif not ct:
 
184
        else:
198
185
            from .dir import (
199
186
                BareLocalGitControlDirFormat,
200
187
                )
201
188
            ret = BareLocalGitControlDirFormat()
202
189
            ret._refs_text = resp.read()
203
190
            return ret
204
 
        raise brz_errors.NotBranchError(transport.base)
205
191
 
206
192
    def probe_transport(self, transport):
207
193
        try:
233
219
 
234
220
 
235
221
ControlDirFormat.register_prober(LocalGitProber)
236
 
ControlDirFormat.register_prober(RemoteGitProber)
 
222
ControlDirFormat._server_probers.append(RemoteGitProber)
237
223
 
238
224
register_transport_proto(
239
225
    'git://', help="Access using the Git smart server protocol.")