[PATCH 1 of 1] url: added support for scp/rsync style URLs for ssh
Thomas Arendsen Hein
thomas at intevation.de
Wed Apr 6 08:36:43 CDT 2011
# HG changeset patch
# User Sascha Wilde <wilde at intevation.de>
# Date 1302096161 -7200
# Node ID 62833deea9f05f44021b401c8093ea86212ac197
# Parent 375872fdadba7266eced67c85e57ffda26fa7500
url: added support for scp/rsync style URLs for ssh
URLs in the form <user>@<host>:<path> are normalized to the
default format: ssh://<user>@<host>/<path>
This breaks the generic "just a scheme and a path" behavior of url.py,
but as it wasn't used by Mercurial (and there always used to be
exceptions) anyway it shouldn't be to much of a loss. So the removed
corresponding tests were removed.
diff -r 375872fdadba -r 62833deea9f0 mercurial/help/urls.txt
--- a/mercurial/help/urls.txt Wed Apr 06 12:48:59 2011 +0200
+++ b/mercurial/help/urls.txt Wed Apr 06 15:22:41 2011 +0200
@@ -5,6 +5,7 @@
http://[user[:pass]@]host[:port]/[path][#revision]
https://[user[:pass]@]host[:port]/[path][#revision]
ssh://[user@]host[:port]/[path][#revision]
+ [user@]host:[path]
Paths in the local filesystem can either point to Mercurial
repositories or to bundle files (as created by :hg:`bundle` or :hg:`
@@ -40,6 +41,10 @@
Alternatively specify "ssh -C" as your ssh command in your
configuration file or with the --ssh command line option.
+- For convenience Mercurial accepts SSH URLs of the for used by tools
+ like scp and rsync:
+
+ example.com:/tmp/repository
These URLs can all be stored in your configuration file with path
aliases under the [paths] section like so::
diff -r 375872fdadba -r 62833deea9f0 mercurial/url.py
--- a/mercurial/url.py Wed Apr 06 12:48:59 2011 +0200
+++ b/mercurial/url.py Wed Apr 06 15:22:41 2011 +0200
@@ -32,12 +32,19 @@
Note that for backward compatibility reasons, bundle URLs do not
take host names. That means 'bundle://../' has a path of '../'.
+ For extra convinience a special form for ssh URLs is recognised,
+ similar to the one used by scp and rsync:
+
+ <user>@<host>:<path>
+
Examples:
>>> url('http://www.ietf.org/rfc/rfc2396.txt')
<url scheme: 'http', host: 'www.ietf.org', path: 'rfc/rfc2396.txt'>
>>> url('ssh://[::1]:2200//home/joe/repo')
<url scheme: 'ssh', host: '[::1]', port: '2200', path: '/home/joe/repo'>
+ >>> url('joe at example.com:/home/joe')
+ <url scheme: 'ssh', user: 'joe', host: 'example.com', path: '/home/joe'>
>>> url('file:///home/joe/repo')
<url scheme: 'file', path: '/home/joe/repo'>
>>> url('bundle:foo')
@@ -89,6 +96,14 @@
self.path = path
return
+ # special case: ssh url of the form [<user>@]<host>:<path>
+ if path and ':' in path:
+ parts = path.split(':', 1)
+ if (parts[0] != 'file' and
+ not ('/' in parts[0] or '\\' in parts[0]) and
+ (not parts[1] or parts[1].startswith('//'))):
+ path = 'ssh://%s/%s' % parts
+
if self._matchscheme(path):
parts = path.split(':', 1)
if parts[0]:
diff -r 375872fdadba -r 62833deea9f0 tests/test-url.py
--- a/tests/test-url.py Wed Apr 06 12:48:59 2011 +0200
+++ b/tests/test-url.py Wed Apr 06 15:22:41 2011 +0200
@@ -104,14 +104,10 @@
>>> url('http://joe:xxx@/foo')
<url scheme: 'http', user: 'joe', passwd: 'xxx', path: 'foo'>
- Just a scheme and a path:
+ Drive letter:
- >>> url('mailto:John.Doe at example.com')
- <url scheme: 'mailto', path: 'John.Doe at example.com'>
>>> url('a:b:c:d')
<url path: 'a:b:c:d'>
- >>> url('aa:bb:cc:dd')
- <url scheme: 'aa', path: 'bb:cc:dd'>
SSH examples:
@@ -127,8 +123,22 @@
<url scheme: 'ssh', host: 'host'>
>>> url('ssh://')
<url scheme: 'ssh'>
- >>> url('ssh:')
- <url scheme: 'ssh'>
+
+ SSH special form:
+
+ >>> url('joe at host:/home/joe')
+ <url scheme: 'ssh', user: 'joe', host: 'host', path: '/home/joe'>
+ >>> url('joe at host:src/fine')
+ <url scheme: 'ssh', user: 'joe', host: 'host', path: 'src/fine'>
+ >>> url('host:/home/doe')
+ <url scheme: 'ssh', host: 'host', path: '/home/doe'>
+ >>> url('host:src')
+ <url scheme: 'ssh', host: 'host', path: 'src'>
+ >>> url('joe at host:')
+ <url scheme: 'ssh', user: 'joe', host: 'host', path: ''>
+ >>> url('host:')
+ <url scheme: 'ssh', host: 'host', path: ''>
+
Non-numeric port:
@@ -163,6 +173,8 @@
<url path: '\\\\foo:bar'>
>>> url('./foo:bar')
<url path: './foo:bar'>
+ >>> url('a/b/c/d.g.f')
+ <url path: 'a/b/c/d.g.f'>
Non-localhost file URL:
More information about the Mercurial-devel
mailing list