146
142
return "git/Breezy/%s" % breezy_version
149
def is_github_url(url):
150
(scheme, user, password, host, port,
151
path) = urlutils.parse_url(url)
152
return host in ("github.com", "gopkg.in")
155
145
class RemoteGitProber(Prober):
158
def priority(klass, transport):
159
# This is a surprisingly good heuristic to determine whether this
160
# prober is more likely to succeed than the Bazaar one.
161
if 'git' in transport.base:
165
147
def probe_http_transport(self, transport):
166
148
# This function intentionally doesn't use any of the support code under
167
149
# breezy.git, since it's called for every repository that's
168
150
# accessed over HTTP, whether it's Git, Bzr or something else.
169
151
# Importing Dulwich and the other support code adds unnecessray slowdowns.
170
base_url = urlutils.strip_segment_parameters(transport.external_url())
152
from .. import urlutils
153
base_url, _ = urlutils.split_segment_parameters(
154
transport.external_url())
171
155
url = urlutils.URL.from_string(base_url)
172
156
url.user = url.quoted_user = None
173
157
url.password = url.quoted_password = None
175
158
url = urlutils.join(str(url), "info/refs") + "?service=git-upload-pack"
176
159
headers = {"Content-Type": "application/x-git-upload-pack-request",
177
160
"Accept": "application/x-git-upload-pack-result",
179
if is_github_url(url):
162
(scheme, user, password, host, port,
163
path) = urlutils.parse_url(url)
164
if host == "github.com":
180
165
# GitHub requires we lie.
181
166
# https://github.com/dulwich/dulwich/issues/562
182
headers["User-Agent"] = user_agent_for_github()
167
req.add_header("User-Agent", user_agent_for_github())
183
168
elif host == "bazaar.launchpad.net":
184
169
# Don't attempt Git probes against bazaar.launchpad.net; pad.lv/1744830
185
170
raise brz_errors.NotBranchError(transport.base)
186
171
resp = transport.request('GET', url, headers=headers)
187
172
if resp.status in (404, 405):
188
173
raise brz_errors.NotBranchError(transport.base)
189
elif resp.status != 200:
190
raise brz_errors.InvalidHttpResponse(
175
raise errors.InvalidHttpResponse(
191
176
url, 'Unable to handle http code %d' % resp.status)
193
ct = resp.getheader("Content-Type")
194
if ct and ct.startswith("application/x-git"):
178
headers = resp.headers
179
ct = headers.get("Content-Type")
181
raise brz_errors.NotBranchError(transport.base)
182
if ct.startswith("application/x-git"):
195
183
from .remote import RemoteGitControlDirFormat
196
184
return RemoteGitControlDirFormat()
198
186
from .dir import (
199
187
BareLocalGitControlDirFormat,
201
189
ret = BareLocalGitControlDirFormat()
202
190
ret._refs_text = resp.read()
204
raise brz_errors.NotBranchError(transport.base)
206
193
def probe_transport(self, transport):