Parcourir la source

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 il y a 13 ans
Parent
commit
d0a0f9c62a
1 fichiers modifiés avec 7 ajouts et 6 suppressions
  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