29
29
RE_PATH = r"""
30
30
((?P<user>.*)@)?
31
31
(?P<hostname>([^/:]+))
32
- (?P<separator>[:,/])?
32
+ (:(?P<port>\d{1,4}))?
33
+ (?P<separator>/)?
33
34
(?P<path>
34
35
(\w[^:.]*)
35
36
)?
36
37
"""
37
38
39
+ # Valid schemes for svn(1).
40
+ # See Table 1.1 Repository access URLs in SVN Book
41
+ # https://svnbook.red-bean.com/nightly/en/svn.basic.in-action.html#svn.basic.in-action.wc.tbl-1
38
42
RE_SCHEME = r"""
39
43
(?P<scheme>
40
44
(
41
- http|https|
42
- svn\+ssh
45
+ file|http|https|svn|svn\+ssh
43
46
)
44
47
)
45
48
"""
@@ -154,10 +157,12 @@ class SvnURL(URLProtocol, SkipDefaultFieldsReprMixin):
154
157
"""
155
158
156
159
url : str
157
- scheme : str = dataclasses .field (init = False )
158
- hostname : str = dataclasses .field (init = False )
159
- path : str = dataclasses .field (init = False )
160
+ scheme : Optional [str ] = None
160
161
user : Optional [str ] = None
162
+ hostname : str = dataclasses .field (default = "" )
163
+ port : Optional [int ] = None
164
+ separator : str = dataclasses .field (default = "/" )
165
+ path : str = dataclasses .field (default = "" )
161
166
162
167
#
163
168
# commit-ish: ref
@@ -213,9 +218,9 @@ def to_url(self) -> str:
213
218
>>> svn_location
214
219
SvnURL(url=svn+ssh://my-username@my-server/vcs-python/libvcs,
215
220
scheme=svn+ssh,
221
+ user=my-username,
216
222
hostname=my-server,
217
223
path=vcs-python/libvcs,
218
- user=my-username,
219
224
matcher=core-svn)
220
225
221
226
Switch repo libvcs -> vcspull:
@@ -232,12 +237,15 @@ def to_url(self) -> str:
232
237
>>> svn_location.to_url()
233
238
'svn+ssh://tom@my-server/vcs-python/vcspull'
234
239
"""
235
- if self .scheme is not None :
236
- parts = [self .scheme , "://" ]
237
- if self .user :
238
- parts .extend ([self .user , "@" ])
239
- parts += [self .hostname , "/" , self .path ]
240
- else :
241
- parts = [self .user or "svn" , "@" , self .hostname , ":" , self .path ]
240
+ parts = [self .scheme or "ssh" , "://" ]
241
+ if self .user :
242
+ parts .extend ([self .user , "@" ])
243
+
244
+ parts .append (self .hostname )
245
+
246
+ if self .port is not None :
247
+ parts .extend ([":" , f"{ self .port } " ])
248
+
249
+ parts .extend ([self .separator , self .path ])
242
250
243
251
return "" .join (part for part in parts if isinstance (part , str ))
0 commit comments