Merge lp:~jelmer/brz/cvs-location into lp:brz/3.1

Proposed by Jelmer Vernooij
Status: Merged
Approved by: Jelmer Vernooij
Approved revision: no longer in the source branch.
Merge reported by: The Breezy Bot
Merged at revision: not available
Proposed branch: lp:~jelmer/brz/cvs-location
Merge into: lp:brz/3.1
Diff against target: 117 lines (+45/-18)
2 files modified
breezy/location.py (+38/-18)
breezy/tests/test_location.py (+7/-0)
To merge this branch: bzr merge lp:~jelmer/brz/cvs-location
Reviewer Review Type Date Requested Status
Jelmer Vernooij Approve
Review via email: mp+386472@code.launchpad.net

Commit message

Refactor location string handling to support cvs+ssh URLs.

Description of the change

Refactore location string handling to support cvs+ssh URLs.

To post a comment you must log in.
Revision history for this message
Jelmer Vernooij (jelmer) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'breezy/location.py'
2--- breezy/location.py 2019-11-17 03:58:40 +0000
3+++ breezy/location.py 2020-06-28 23:23:47 +0000
4@@ -45,12 +45,11 @@
5
6 hooks = LocationHooks()
7
8-
9-def rcp_location_to_url(location, scheme='ssh'):
10+def parse_rcp_location(location):
11 """Convert a rcp-style location to a URL.
12
13 :param location: Location to convert, e.g. "foo:bar"
14- :param schenme: URL scheme to return, defaults to "ssh"
15+ :param scheme: URL scheme to return, defaults to "ssh"
16 :return: A URL, e.g. "ssh://foo/bar"
17 :raises ValueError: if this is not a RCP-style URL
18 """
19@@ -59,36 +58,57 @@
20 raise ValueError("Not a RCP URL")
21 if m.group('path').startswith('//'):
22 raise ValueError("Not a RCP URL: already looks like a URL")
23- quoted_user = urlutils.quote(m.group('user')[:-1]) if m.group('user') else None
24+ return (m.group('host'),
25+ m.group('user')[:-1] if m.group('user') else None,
26+ m.group('path'))
27+
28+
29+def rcp_location_to_url(location, scheme='ssh'):
30+ """Convert a rcp-style location to a URL.
31+
32+ :param location: Location to convert, e.g. "foo:bar"
33+ :param scheme: URL scheme to return, defaults to "ssh"
34+ :return: A URL, e.g. "ssh://foo/bar"
35+ :raises ValueError: if this is not a RCP-style URL
36+ """
37+ (host, user, path) = parse_rcp_location(location)
38+ quoted_user = urlutils.quote(user) if user else None
39 url = urlutils.URL(
40 scheme=scheme, quoted_user=quoted_user,
41 port=None, quoted_password=None,
42- quoted_host=urlutils.quote(m.group('host')),
43- quoted_path=urlutils.quote(m.group('path')))
44+ quoted_host=urlutils.quote(host),
45+ quoted_path=urlutils.quote(path))
46 return str(url)
47
48
49-def pserver_to_url(location):
50- """Convert a CVS pserver location string to a URL.
51-
52- :param location: pserver URL
53- :return: A cvs+pserver URL
54- """
55+def parse_cvs_location(location):
56 parts = location.split(':')
57- if parts[0] or parts[1] != 'pserver':
58+ if parts[0] or parts[1] not in ('pserver', 'ssh'):
59 raise ValueError('not a valid pserver location string')
60 try:
61 (username, hostname) = parts[2].split('@', 1)
62 except IndexError:
63 hostname = parts[2]
64 username = None
65+ scheme = parts[1]
66+ path = parts[3]
67+ return (scheme, hostname, username, path)
68+
69+
70+def cvs_to_url(location):
71+ """Convert a CVS pserver location string to a URL.
72+
73+ :param location: pserver URL
74+ :return: A cvs+pserver URL
75+ """
76+ (scheme, host, user, path) = parse_cvs_location(location)
77 return str(urlutils.URL(
78- scheme='cvs+pserver',
79- quoted_user=urlutils.quote(username) if username else None,
80- quoted_host=urlutils.quote(hostname),
81+ scheme='cvs+' + scheme,
82+ quoted_user=urlutils.quote(user) if user else None,
83+ quoted_host=urlutils.quote(host),
84 quoted_password=None,
85 port=None,
86- quoted_path=urlutils.quote(parts[3])))
87+ quoted_path=urlutils.quote(path)))
88
89
90 def location_to_url(location, purpose=None):
91@@ -106,7 +126,7 @@
92 raise AssertionError("location not a byte or unicode string")
93
94 if location.startswith(':pserver:'):
95- return pserver_to_url(location)
96+ return cvs_to_url(location)
97
98 from .directory_service import directories
99 location = directories.dereference(location, purpose)
100
101=== modified file 'breezy/tests/test_location.py'
102--- breezy/tests/test_location.py 2019-11-17 03:58:40 +0000
103+++ breezy/tests/test_location.py 2020-06-28 23:23:47 +0000
104@@ -83,6 +83,13 @@
105 ':pserver:anonymous@odessa.cvs.sourceforge.net:/cvsroot/odess'))
106 self.assertRaises(ValueError, location_to_url, ':pserver:blah')
107
108+ def test_missing_scheme(self):
109+ self.skipTest('need clever guessing of scheme')
110+ self.assertEqual(
111+ 'cvs+pserver://anonymous@savi.cvs.sourceforge.net:/cvsroot/savi',
112+ location_to_url(
113+ 'anonymous@savi.cvs.sourceforge.net:/cvsroot/savi'))
114+
115 def test_rcp_url(self):
116 self.assertEqual(
117 "ssh://example.com/srv/git/bar",

Subscribers

People subscribed via source and target branches