Browse Source

Teach ./bin/dulwich about SSH

John Carr 16 năm trước cách đây
mục cha
commit
cd7ac56172
2 tập tin đã thay đổi với 22 bổ sung9 xóa
  1. 18 7
      bin/dulwich
  2. 4 2
      dulwich/client.py

+ 18 - 7
bin/dulwich

@@ -20,16 +20,26 @@
 import sys
 from getopt import getopt
 
+def get_transport_and_path(uri):
+    from dulwich.client import TCPGitClient, SSHGitClient
+    for handler, transport in (("git://", TCPGitClient), ("git+ssh://", SSHGitClient)):
+        if uri.startswith(handler):
+            host, path = uri[len(handler):].split("/", 1)
+            return transport(host), "/"+path
+    return None, None
+
 def cmd_fetch_pack(args):
-	from dulwich.client import TCPGitClient, SimpleFetchGraphWalker
+	from dulwich.client import SimpleFetchGraphWalker
 	from dulwich.repo import Repo
 	opts, args = getopt(args, "", ["all"])
 	opts = dict(opts)
 	if not ":" in args[0]:
 		print "Usage: dulwich fetch-pack [--all] host:path [REF...]"
 		sys.exit(1)
-	(host, path) = args.pop(0).split(":", 1)
-	client = TCPGitClient(host)
+        client, path = get_transport_and_path(args.pop(0))
+        if not client:
+            print "Must be git:// or git+ssh://"
+            sys.exit(1)
 	if "--all" in opts:
 		determine_wants = lambda x: [y for y in x.values() if not y in r.object_store]
 	else:
@@ -137,7 +147,7 @@ def cmd_init(args):
 
 
 def cmd_clone(args):
-	from dulwich.client import TCPGitClient, SimpleFetchGraphWalker
+	from dulwich.client import SimpleFetchGraphWalker
 	from dulwich.repo import Repo
 	import os
 	import sys
@@ -151,9 +161,10 @@ def cmd_clone(args):
 	if not ":" in args[0]:
 		print "Usage: dulwich clone host:path [PATH]"
 		sys.exit(1)
-	(host, host_path) = args.pop(0).split(":", 1)
-	client = TCPGitClient(host)
-
+        client, host_path = get_transport_and_path(args.pop(0))
+        if not client:
+            print "Must be git:// or git+ssh://"
+            sys.exit(1)
 	if len(args) > 0:
 		path = args.pop(0)
 	else:

+ 4 - 2
dulwich/client.py

@@ -16,8 +16,10 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 # MA  02110-1301, USA.
 
+import os
 import select
 import socket
+import subprocess
 from dulwich.protocol import Protocol, TCP_GIT_PORT, extract_capabilities
 
 class SimpleFetchGraphWalker(object):
@@ -198,12 +200,12 @@ class SSHGitClient(GitClient):
         self.port = port
 
     def send_pack(self, path):
-        remote = get_ssh_vendor().connect_ssh(self.host, "git-receive-pack %s" % path, port=self.port)
+        remote = get_ssh_vendor().connect_ssh(self.host, ["git-receive-pack %s" % path], port=self.port)
         client = GitClient(remote.proc.stdin.fileno(), remote.recv, remote.send)
         client.send_pack(path)
 
     def fetch_pack(self, path, determine_wants, graph_walker, pack_data, progress):
-        remote = get_ssh_vendor().connect_ssh(self.host, "git-upload-pack %s" % path, port=self.port)
+        remote = get_ssh_vendor().connect_ssh(self.host, ["git-upload-pack %s" % path], port=self.port)
         client = GitClient(remote.proc.stdin.fileno(), remote.recv, remote.send)
         client.fetch_pack(path, determine_wants, graph_walker, pack_data, progress)