static void check_fromurl(const char *expected_result, const char *input, int should_fail) { git_buf buf = GIT_BUF_INIT; assert(should_fail || expected_result); if (!should_fail) { cl_git_pass(git_path_fromurl(&buf, input)); cl_assert_equal_s(expected_result, git_buf_cstr(&buf)); } else cl_git_fail(git_path_fromurl(&buf, input)); git_buf_dispose(&buf); }
int git_path_from_url_or_path(git_buf *local_path_out, const char *url_or_path) { if (git_path_is_local_file_url(url_or_path)) return git_path_fromurl(local_path_out, url_or_path); else return git_buf_sets(local_path_out, url_or_path); }
int git_clone__should_clone_local(const char *url_or_path, git_clone_local_t local) { git_buf fromurl = GIT_BUF_INIT; const char *path = url_or_path; bool is_url, is_local; if (local == GIT_CLONE_NO_LOCAL) return 0; if ((is_url = git_path_is_local_file_url(url_or_path)) != 0) { if (git_path_fromurl(&fromurl, url_or_path) < 0) { is_local = -1; goto done; } path = fromurl.ptr; } is_local = (!is_url || local != GIT_CLONE_LOCAL_AUTO) && git_path_isdir(path); done: git_buf_free(&fromurl); return is_local; }
/* * Try to open the url as a git directory. The direction doesn't * matter in this case because we're calulating the heads ourselves. */ static int local_connect(git_transport *transport, int direction) { git_repository *repo; int error; transport_local *t = (transport_local *) transport; const char *path; git_buf buf = GIT_BUF_INIT; GIT_UNUSED(direction); /* The repo layer doesn't want the prefix */ if (!git__prefixcmp(transport->url, "file://")) { if (git_path_fromurl(&buf, transport->url) < 0) { git_buf_free(&buf); return -1; } 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 < 0) return -1; t->repo = repo; if (store_refs(t) < 0) return -1; t->parent.connected = 1; return 0; }