Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport.c')
-rw-r--r--src/transport.c46
1 files changed, 29 insertions, 17 deletions
diff --git a/src/transport.c b/src/transport.c
index 00b79dc6d..5b2cd7ea4 100644
--- a/src/transport.c
+++ b/src/transport.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009-2011 the libgit2 contributors
+ * Copyright (C) 2009-2012 the libgit2 contributors
*
* This file is part of libgit2, distributed under the GNU GPL v2 with
* a Linking Exception. For full terms see the included COPYING file.
@@ -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) == 0) && 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;
}
@@ -43,10 +51,11 @@ static git_transport_cb transport_find_fn(const char *url)
* Public API *
**************/
-int git_transport_dummy(git_transport **GIT_UNUSED(transport))
+int git_transport_dummy(git_transport **transport)
{
- GIT_UNUSED_ARG(transport);
- return git__throw(GIT_ENOTIMPLEMENTED, "This protocol isn't implemented. Sorry");
+ GIT_UNUSED(transport);
+ giterr_set(GITERR_NET, "This transport isn't implemented. Sorry");
+ return -1;
}
int git_transport_new(git_transport **out, const char *url)
@@ -57,24 +66,21 @@ 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;
+ if (fn == NULL) {
+ giterr_set(GITERR_NET, "Unsupported URL protocol");
+ return -1;
+ }
error = fn(&transport);
- if (error < GIT_SUCCESS)
- return git__rethrow(error, "Failed to create new transport");
+ if (error < 0)
+ return error;
transport->url = git__strdup(url);
- if (transport->url == NULL)
- return GIT_ENOMEM;
+ GITERR_CHECK_ALLOC(transport->url);
*out = transport;
- return GIT_SUCCESS;
+ return 0;
}
/* from remote.h */
@@ -83,3 +89,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));
+}