Commit 8bf476ac by Graham Dennis

Factor out code to convert local "url" into a path.

Previously this code was shared between `local_push` and `local_connect`.
parent c7015424
...@@ -156,6 +156,24 @@ on_error: ...@@ -156,6 +156,24 @@ on_error:
return -1; return -1;
} }
static int path_from_url_or_path(git_buf *local_path_out, const char *url_or_path)
{
int error;
/* If url_or_path begins with file:// treat it as a URL */
if (!git__prefixcmp(url_or_path, "file://")) {
if ((error = git_path_fromurl(local_path_out, url_or_path)) < 0) {
return error;
}
} else { /* We assume url_or_path is already a path */
if ((error = git_buf_sets(local_path_out, url_or_path)) < 0) {
return error;
}
}
return 0;
}
/* /*
* Try to open the url as a git directory. The direction doesn't * Try to open the url as a git directory. The direction doesn't
* matter in this case because we're calulating the heads ourselves. * matter in this case because we're calulating the heads ourselves.
...@@ -181,18 +199,13 @@ static int local_connect( ...@@ -181,18 +199,13 @@ static int local_connect(
t->direction = direction; t->direction = direction;
t->flags = flags; t->flags = flags;
/* The repo layer doesn't want the prefix */ /* 'url' may be a url or path; convert to a path */
if (!git__prefixcmp(t->url, "file://")) { if ((error = path_from_url_or_path(&buf, url)) < 0) {
if (git_path_fromurl(&buf, t->url) < 0) {
git_buf_free(&buf); git_buf_free(&buf);
return -1; return error;
} }
path = git_buf_cstr(&buf); path = git_buf_cstr(&buf);
} else { /* We assume transport->url is already a path */
path = t->url;
}
error = git_repository_open(&repo, path); error = git_repository_open(&repo, path);
git_buf_free(&buf); git_buf_free(&buf);
...@@ -350,18 +363,13 @@ static int local_push( ...@@ -350,18 +363,13 @@ static int local_push(
unsigned int i; unsigned int i;
size_t j; size_t j;
/* The repo layer doesn't want the prefix */ /* 'push->remote->url' may be a url or path; convert to a path */
if (!git__prefixcmp(push->remote->url, "file://")) { if ((error = path_from_url_or_path(&buf, push->remote->url)) < 0) {
if (git_path_fromurl(&buf, push->remote->url) < 0) {
git_buf_free(&buf); git_buf_free(&buf);
return -1; return error;
} }
path = git_buf_cstr(&buf); path = git_buf_cstr(&buf);
} else { /* We assume push->remote->url is already a path */
path = push->remote->url;
}
error = git_repository_open(&remote_repo, path); error = git_repository_open(&remote_repo, path);
git_buf_free(&buf); git_buf_free(&buf);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment