summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authornulltoken <emeric.fermas@gmail.com>2011-12-28 11:36:18 +0100
committernulltoken <emeric.fermas@gmail.com>2011-12-28 20:40:08 +0100
commite2580375dc76f46dce9963225449fcc872e86b0b (patch)
treed09787c425186553b20c11650cd1eb1c7d43963a /src
parent2017a15d6ca7f756dcf036499a02e15393609c83 (diff)
downloadlibgit2-e2580375dc76f46dce9963225449fcc872e86b0b.tar.gz
transport: make local transport accept a file Uri containing percent-encoded characters
This makes libgit2 compliant with the following scenario $ git ls-remote file:///d:/temp/dwm%20tinou 732d790b702db4b8985f5104fc44642654f6a6b6 HEAD 732d790b702db4b8985f5104fc44642654f6a6b6 refs/heads/master 732d790b702db4b8985f5104fc44642654f6a6b6 refs/remotes/origin/HEAD 732d790b702db4b8985f5104fc44642654f6a6b6 refs/remotes/origin/master $ mv "/d/temp/dwm tinou" /d/temp/dwm+tinou $ git ls-remote file:///d:/temp/dwm%20tinou fatal: 'd:/temp/dwm tinou' does not appear to be a git repository fatal: The remote end hung up unexpectedly $ git ls-remote file:///d:/temp/dwm+tinou 732d790b702db4b8985f5104fc44642654f6a6b6 HEAD 732d790b702db4b8985f5104fc44642654f6a6b6 refs/heads/master 732d790b702db4b8985f5104fc44642654f6a6b6 refs/remotes/origin/HEAD 732d790b702db4b8985f5104fc44642654f6a6b6 refs/remotes/origin/master
Diffstat (limited to 'src')
-rw-r--r--src/transports/local.c27
1 files changed, 15 insertions, 12 deletions
diff --git a/src/transports/local.c b/src/transports/local.c
index 2937da06d..a2135e73e 100644
--- a/src/transports/local.c
+++ b/src/transports/local.c
@@ -13,6 +13,8 @@
#include "refs.h"
#include "transport.h"
#include "posix.h"
+#include "path.h"
+#include "buffer.h"
typedef struct {
git_transport parent;
@@ -148,7 +150,6 @@ static int local_ls(git_transport *transport, git_headlist_cb list_cb, void *pay
return GIT_SUCCESS;
}
-
/*
* Try to open the url as a git directory. The direction doesn't
* matter in this case because we're calulating the heads ourselves.
@@ -159,24 +160,26 @@ static int local_connect(git_transport *transport, int GIT_UNUSED(direction))
int error;
transport_local *t = (transport_local *) transport;
const char *path;
+ git_buf buf = GIT_BUF_INIT;
+
GIT_UNUSED_ARG(direction);
/* The repo layer doesn't want the prefix */
if (!git__prefixcmp(transport->url, "file://")) {
- path = transport->url + strlen("file://");
-
-#ifdef _MSC_VER
- /* skip the leading slash on windows before the drive letter */
- if (*path != '/')
- return git__throw(GIT_EINVALIDPATH, "Invalid local uri '%s'.", transport->url);
-
- path++;
-#endif
-
- } else
+ error = git_path_fromurl(&buf, transport->url);
+ if (error < GIT_SUCCESS) {
+ git_buf_free(&buf);
+ return git__rethrow(error, "Failed to parse remote path");
+ }
+ path = git_buf_cstr(&buf);
+
+ } else /* We assume transport->url is already a path */
path = transport->url;
error = git_repository_open(&repo, path);
+
+ git_buf_free(&buf);
+
if (error < GIT_SUCCESS)
return git__rethrow(error, "Failed to open remote");