summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan Wilcox <rwilcox@wilcoxd.com>2012-02-29 17:37:18 -0500
committerRyan Wilcox <rwilcox@wilcoxd.com>2012-02-29 17:37:18 -0500
commit58448910a0591c38959bd26de23cbe97e243b0af (patch)
treee073f43522a7ca321dd4bb5f8f7a5dcea6c131fe
parent17b3d9b92b9132be116e4ecfae736de025c5158f (diff)
downloadlibgit2-58448910a0591c38959bd26de23cbe97e243b0af.tar.gz
implement support for username@host:path URLs in transport_find_fn()
-rw-r--r--src/transport.c28
-rw-r--r--tests-clar/network/remotes.c10
2 files changed, 35 insertions, 3 deletions
diff --git a/src/transport.c b/src/transport.c
index 672eb6e8a..523a9fce2 100644
--- a/src/transport.c
+++ b/src/transport.c
@@ -10,6 +10,8 @@
#include "git2/net.h"
#include "transport.h"
+#include <regex.h>
+
static struct {
char *prefix;
git_transport_cb fn;
@@ -28,15 +30,35 @@ static struct {
static git_transport_cb transport_find_fn(const char *url)
{
size_t i = 0;
+ regex_t preg;
+ int error;
+ git_transport_cb output = NULL;
- /* 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;
}
- return NULL;
+
+ // next, see if it matches un-schemed SSH paths used by Git
+ // if it does not match, it must be a local transport method
+ // use the slightly old fashioned :alnum: instead of \w or :word:, because
+ // both are Perl extensions to the Regular Expression language (and not available here)
+ error = regcomp(&preg, "^[[:alnum:]_]+@[[:alnum:]_]+\\.[[:alnum:]_]+:.+\\.git$", REG_EXTENDED);
+ if (error < 0)
+ goto cleanup;
+
+ int rc = regexec(&preg, url, 0, NULL, 0);
+ if ( rc == REG_NOMATCH )
+ output = NULL; // a match was not found - it's probably a file system path
+ else
+ output = &git_transport_git; // a match was found!
+
+cleanup:
+ regfree(&preg);
+
+ return output;
}
/**************
diff --git a/tests-clar/network/remotes.c b/tests-clar/network/remotes.c
index 36b945f9a..4cf473d70 100644
--- a/tests-clar/network/remotes.c
+++ b/tests-clar/network/remotes.c
@@ -30,6 +30,16 @@ void test_network_remotes__parsing(void)
cl_assert(!strcmp(git_remote_url(_remote), "git://github.com/libgit2/libgit2"));
}
+void test_network_remotes__parsing_ssh_remote(void)
+{
+ cl_assert( git_remote_valid_url("git@github.com:libgit2/libgit2.git") );
+}
+
+void test_network_remotes__parsing_local_path(void)
+{
+ cl_assert( !git_remote_valid_url("/home/git/repos/libgit2.git") );
+}
+
void test_network_remotes__refspec_parsing(void)
{
cl_assert(!strcmp(git_refspec_src(_refspec), "refs/heads/*"));