diff options
author | Carlos Martín Nieto <carlos@cmartin.tk> | 2012-03-05 22:32:41 +0400 |
---|---|---|
committer | Carlos Martín Nieto <carlos@cmartin.tk> | 2012-03-05 22:32:41 +0400 |
commit | 864ac49e317dc8dfd683a1017c05584bd7a8864c (patch) | |
tree | 1262c7a1524fe2bc192fb3b493e76707062021a7 /src/transport.c | |
parent | c4c4bc1fd83a6682c72702cc8d25b784c9ba3cbb (diff) | |
parent | 4f8efc97c1ee06bc113443f028ba7821a7af7920 (diff) |
Merge branch 'ssh-urls' into development
Diffstat (limited to 'src/transport.c')
-rw-r--r-- | src/transport.c | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/src/transport.c b/src/transport.c index 785ddc35d..4910f2433 100644 --- a/src/transport.c +++ b/src/transport.c @@ -9,6 +9,7 @@ #include "git2/remote.h" #include "git2/net.h" #include "transport.h" +#include "path.h" static struct { char *prefix; @@ -29,13 +30,20 @@ static git_transport_cb transport_find_fn(const char *url) { size_t i = 0; - /* TODO: Parse "example.com:project.git" as an SSH URL */ - + // First, check to see if it's an obvious URL, which a URL scheme for (i = 0; i < GIT_TRANSPORT_COUNT; ++i) { if (!strncasecmp(url, transports[i].prefix, strlen(transports[i].prefix))) return transports[i].fn; } + /* still here? Check to see if the path points to a file on the local file system */ + if ((git_path_exists(url) == GIT_SUCCESS) && git_path_isdir(url)) + return &git_transport_local; + + /* It could be a SSH remote path. Check to see if there's a : */ + if (strrchr(url, ':')) + return &git_transport_dummy; /* SSH is an unsupported transport mechanism in this version of libgit2 */ + return NULL; } @@ -57,12 +65,8 @@ int git_transport_new(git_transport **out, const char *url) fn = transport_find_fn(url); - /* - * If we haven't found the transport, we assume we mean a - * local file. - */ if (fn == NULL) - fn = &git_transport_local; + return git__throw(GIT_EINVALIDARGS, "Unsupported URL or non-existent path"); error = fn(&transport); if (error < GIT_SUCCESS) @@ -83,3 +87,9 @@ int git_remote_valid_url(const char *url) return transport_find_fn(url) != NULL; } +int git_remote_supported_url(const char* url) +{ + git_transport_cb transport_fn = transport_find_fn(url); + + return ((transport_fn != NULL) && (transport_fn != &git_transport_dummy)); +} |