瀏覽代碼

Add support for client init args in get_transport_and_path

If you want to pass arguments to the client construction, without re–
producing the logic in get_transport_and_path which decides on the
appropriate client class to use, you're pretty much out of luck.  So,
accept and pass through keyword arguments.
Sam Vilain 13 年之前
父節點
當前提交
d0a0f9c62a
共有 1 個文件被更改,包括 7 次插入6 次删除
  1. 7 6
      dulwich/client.py

+ 7 - 6
dulwich/client.py

@@ -762,7 +762,7 @@ class HttpGitClient(GitClient):
         return refs
 
 
-def get_transport_and_path(uri):
+def get_transport_and_path(uri, **kwargs):
     """Obtain a git client from a URI or path.
 
     :param uri: URI or path
@@ -770,23 +770,24 @@ def get_transport_and_path(uri):
     """
     parsed = urlparse.urlparse(uri)
     if parsed.scheme == 'git':
-        return TCPGitClient(parsed.hostname, port=parsed.port), parsed.path
+        return (TCPGitClient(parsed.hostname, port=parsed.port, **kwargs),
+                parsed.path)
     elif parsed.scheme == 'git+ssh':
         return SSHGitClient(parsed.hostname, port=parsed.port,
-                            username=parsed.username), parsed.path
+                            username=parsed.username, **kwargs), parsed.path
     elif parsed.scheme in ('http', 'https'):
         return HttpGitClient(urlparse.urlunparse(parsed)), parsed.path
 
     if parsed.scheme and not parsed.netloc:
         # SSH with no user@, zero or one leading slash.
-        return SSHGitClient(parsed.scheme), parsed.path
+        return SSHGitClient(parsed.scheme, **kwargs), parsed.path
     elif parsed.scheme:
         raise ValueError('Unknown git protocol scheme: %s' % parsed.scheme)
     elif '@' in parsed.path and ':' in parsed.path:
         # SSH with user@host:foo.
         user_host, path = parsed.path.split(':')
         user, host = user_host.rsplit('@')
-        return SSHGitClient(host, username=user), path
+        return SSHGitClient(host, username=user, **kwargs), path
 
     # Otherwise, assume it's a local path.
-    return SubprocessGitClient(), uri
+    return SubprocessGitClient(**kwargs), uri