/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: Gustav Hartvigsson
  • Date: 2021-01-09 21:36:27 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20210109213627-h1xwcutzy9m7a99b
Added 'Case Preserving Working Tree Use Cases' from Canonical Wiki

* Addod a page from the Canonical Bazaar wiki
  with information on the scmeatics of case
  perserving filesystems an a case insensitive
  filesystem works.
  
  * Needs re-work, but this will do as it is the
    same inforamoton as what was on the linked
    page in the currint documentation.

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
 
 
27
25
import os
28
26
import sys
29
27
 
30
 
dulwich_minimum_version = (0, 19, 7)
 
28
dulwich_minimum_version = (0, 19, 11)
31
29
 
32
30
from .. import (  # noqa: F401
33
31
    __version__ as breezy_version,
34
32
    errors as brz_errors,
35
33
    trace,
 
34
    urlutils,
36
35
    version_info,
37
36
    )
38
37
 
103
102
 
104
103
class LocalGitProber(Prober):
105
104
 
 
105
    @classmethod
 
106
    def priority(klass, transport):
 
107
        return 10
 
108
 
106
109
    def probe_transport(self, transport):
107
110
        try:
108
111
            external_url = transport.external_url()
112
115
                external_url.startswith("https:")):
113
116
            # Already handled by RemoteGitProber
114
117
            raise brz_errors.NotBranchError(path=transport.base)
115
 
        from .. import urlutils
116
118
        if urlutils.split(transport.base)[1] == ".git":
117
119
            raise brz_errors.NotBranchError(path=transport.base)
118
120
        if not transport.has_any(['objects', '.git/objects', '.git']):
142
144
    return "git/Breezy/%s" % breezy_version
143
145
 
144
146
 
 
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
 
145
153
class RemoteGitProber(Prober):
146
154
 
 
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
 
147
163
    def probe_http_transport(self, transport):
148
 
        from .. import urlutils
149
 
        base_url, _ = urlutils.split_segment_parameters(
150
 
            transport.external_url())
151
 
        url = urlutils.join(base_url, "info/refs") + "?service=git-upload-pack"
152
 
        from ..transport.http import Request
 
164
        # This function intentionally doesn't use any of the support code under
 
165
        # breezy.git, since it's called for every repository that's
 
166
        # accessed over HTTP, whether it's Git, Bzr or something else.
 
167
        # Importing Dulwich and the other support code adds unnecessray slowdowns.
 
168
        base_url = urlutils.strip_segment_parameters(transport.external_url())
 
169
        url = urlutils.URL.from_string(base_url)
 
170
        url.user = url.quoted_user = None
 
171
        url.password = url.quoted_password = None
 
172
        host = url.host
 
173
        url = urlutils.join(str(url), "info/refs") + "?service=git-upload-pack"
153
174
        headers = {"Content-Type": "application/x-git-upload-pack-request",
154
175
                   "Accept": "application/x-git-upload-pack-result",
155
176
                   }
156
 
        req = Request('GET', url, accepted_errors=[200, 403, 404, 405],
157
 
                      headers=headers)
158
 
        (scheme, user, password, host, port,
159
 
         path) = urlutils.parse_url(req.get_full_url())
160
 
        if host == "github.com":
 
177
        if is_github_url(url):
161
178
            # GitHub requires we lie.
162
179
            # https://github.com/dulwich/dulwich/issues/562
163
 
            req.add_header("User-Agent", user_agent_for_github())
164
 
        elif host == "bazaar.launchpad.net":
165
 
            # Don't attempt Git probes against bazaar.launchpad.net; pad.lv/1744830
166
 
            raise brz_errors.NotBranchError(transport.base)
167
 
        resp = transport._perform(req)
168
 
        if resp.code in (404, 405):
169
 
            raise brz_errors.NotBranchError(transport.base)
170
 
        headers = resp.headers
171
 
        ct = headers.get("Content-Type")
172
 
        if ct is None:
173
 
            raise brz_errors.NotBranchError(transport.base)
174
 
        if ct.startswith("application/x-git"):
 
180
            headers["User-Agent"] = user_agent_for_github()
 
181
        resp = transport.request('GET', url, headers=headers)
 
182
        if resp.status in (404, 405):
 
183
            raise brz_errors.NotBranchError(transport.base)
 
184
        elif resp.status == 400 and resp.reason == 'no such method: info':
 
185
            # hgweb :(
 
186
            raise brz_errors.NotBranchError(transport.base)
 
187
        elif resp.status != 200:
 
188
            raise brz_errors.UnexpectedHttpStatus(url, resp.status)
 
189
 
 
190
        ct = resp.getheader("Content-Type")
 
191
        if ct and ct.startswith("application/x-git"):
175
192
            from .remote import RemoteGitControlDirFormat
176
193
            return RemoteGitControlDirFormat()
177
 
        else:
 
194
        elif not ct:
178
195
            from .dir import (
179
196
                BareLocalGitControlDirFormat,
180
197
                )
181
198
            ret = BareLocalGitControlDirFormat()
182
199
            ret._refs_text = resp.read()
183
200
            return ret
 
201
        raise brz_errors.NotBranchError(transport.base)
184
202
 
185
203
    def probe_transport(self, transport):
186
204
        try:
212
230
 
213
231
 
214
232
ControlDirFormat.register_prober(LocalGitProber)
215
 
ControlDirFormat._server_probers.append(RemoteGitProber)
 
233
ControlDirFormat.register_prober(RemoteGitProber)
216
234
 
217
235
register_transport_proto(
218
236
    'git://', help="Access using the Git smart server protocol.")
402
420
def loggerhead_git_hook(branch_app, environ):
403
421
    branch = branch_app.branch
404
422
    config_stack = branch.get_config_stack()
405
 
    if config_stack.get('http_git'):
 
423
    if not config_stack.get('git.http'):
406
424
        return None
407
425
    from .server import git_http_hook
408
426
    return git_http_hook(branch, environ['REQUEST_METHOD'],