~jelmer/brz-git/urls

« back to all changes in this revision

Viewing changes to urls.py

  • Committer: Jelmer Vernooij
  • Date: 2018-04-02 13:20:10 UTC
  • Revision ID: jelmer@jelmer.uk-20180402132010-wksdm108u015hlln
Use parse_rsync_url from dulwich.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
from breezy.urlutils import URL, quote
22
22
 
 
23
from dulwich.client import parse_rsync_url
 
24
 
23
25
 
24
26
KNOWN_GIT_SCHEMES = ['git+ssh', 'git', 'http', 'https', 'ftp']
25
27
 
26
28
 
27
 
def parse_git_url(location):
28
 
    """Parse a rsync-style URL."""
29
 
    if ':' in location and '@' not in location:
30
 
        # SSH with no user@, zero or one leading slash.
31
 
        (host, path) = location.split(':', 1)
32
 
        user = None
33
 
    elif ':' in location:
34
 
        # SSH with user@host:foo.
35
 
        user_host, path = location.split(':', 1)
36
 
        if '@' in user_host:
37
 
            user, host = user_host.rsplit('@', 1)
38
 
        else:
39
 
            user = None
40
 
            host = user_host
41
 
    else:
42
 
        raise ValueError('missing : in location')
43
 
    return (user, host, path)
44
 
 
45
 
 
46
29
def git_url_to_bzr_url(location):
47
30
    url = URL.from_string(location)
48
31
    if url.scheme not in KNOWN_GIT_SCHEMES:
49
32
        try:
50
 
            (username, host, path) = parse_git_url(location)
 
33
            (username, host, path) = parse_rsync_url(location)
51
34
        except ValueError:
52
35
            url = URL(
53
36
                scheme='file', quoted_user=None, quoted_password=None,