[RFC] [PATCH] rewrite host.name:path as ssh://host.name/path
Alexis S. L. Carvalho
alexis at cecm.usp.br
Tue Mar 18 02:40:12 CDT 2008
People often ask why "hg push user at example.com:path/to/repo"
doesn't work. Here's a patch that makes it work.
Basic heuristic: if we couldn't find the scheme (http/file/ssh/...),
there's a colon after the second character (to avoid problems with drive
letters on windows), there's no os.sep before the colon and the path
doesn't exist, assume it's a "hostname:path" ssh repo and translate it
into ssh://hostname/path .
To specify the port, you'll have to use the current URL syntax.
Hmm... I should've updated the help text of hg pull...
Comments?
Alexis
# HG changeset patch
# User Alexis S. L. Carvalho <alexis at cecm.usp.br>
# Date 1205825463 10800
# Node ID 945cd1c2953790d2bd7e505c0627e4f364c7c5fa
# Parent 653ddd1d7cd79654545c528b31b80ecf2aea7c83
rewrite host.name:path as ssh://host.name/path
diff -r 653ddd1d7cd7 -r 945cd1c29537 mercurial/hg.py
--- a/mercurial/hg.py Tue Mar 18 04:07:39 2008 -0300
+++ b/mercurial/hg.py Tue Mar 18 04:31:03 2008 -0300
@@ -40,7 +40,14 @@ def _lookup(path):
c = path.find(':')
if c > 0:
scheme = path[:c]
- thing = schemes.get(scheme) or schemes['file']
+ thing = schemes.get(scheme)
+ if thing is None:
+ if (c > 1 and path.find(os.sep, 0, c) < 0 and
+ (not os.altsep or path.find(os.altsep, 0, c) < 0)
+ and not os.path.exists(path)):
+ thing = schemes['ssh']
+ else:
+ thing = schemes['file']
try:
return thing(path)
except TypeError:
diff -r 653ddd1d7cd7 -r 945cd1c29537 mercurial/sshrepo.py
--- a/mercurial/sshrepo.py Tue Mar 18 04:07:39 2008 -0300
+++ b/mercurial/sshrepo.py Tue Mar 18 04:31:03 2008 -0300
@@ -235,4 +235,13 @@ class sshrepository(remoterepository):
def stream_out(self):
return self.do_cmd('stream_out')
-instance = sshrepository
+def instance(ui, path, create=0):
+ if not path.startswith('ssh://'):
+ # host.name:path
+ try:
+ host, pathname = path.split(':', 1)
+ except ValueError:
+ raise util.Abort(_('unable to parse %s as an ssh repository')
+ % path)
+ path = 'ssh://%s/%s' % (host, pathname)
+ return sshrepository(ui, path, create)
diff -r 653ddd1d7cd7 -r 945cd1c29537 tests/test-ssh
--- a/tests/test-ssh Tue Mar 18 04:07:39 2008 -0300
+++ b/tests/test-ssh Tue Mar 18 04:31:03 2008 -0300
@@ -81,8 +81,8 @@ echo "# find outgoing"
echo "# find outgoing"
hg out ssh://user@dummy/remote
-echo "# find incoming on the remote side"
-hg incoming -R ../remote -e "python ../dummyssh" ssh://user@dummy/local
+echo "# find incoming on the remote side with user at host:path syntax"
+hg incoming -R ../remote -e "python ../dummyssh" user at dummy:local
echo "# push"
hg push
diff -r 653ddd1d7cd7 -r 945cd1c29537 tests/test-ssh.out
--- a/tests/test-ssh.out Tue Mar 18 04:07:39 2008 -0300
+++ b/tests/test-ssh.out Tue Mar 18 04:31:03 2008 -0300
@@ -41,8 +41,8 @@ date: Mon Jan 12 13:46:40 1970 +0
date: Mon Jan 12 13:46:40 1970 +0000
summary: add
-# find incoming on the remote side
-comparing with ssh://user@dummy/local
+# find incoming on the remote side with user at host:path syntax
+comparing with user at dummy:local
searching for changes
changeset: 1:572896fe480d
tag: tip
More information about the Mercurial-devel
mailing list