Commit 29f27599 by Ben Straub

Rename remote creation APIs

git_remote_add -> git_remote_create
git_remote_new -> git_remote_create_inmemory
parent 316bca69
...@@ -76,7 +76,7 @@ int fetch(git_repository *repo, int argc, char **argv) ...@@ -76,7 +76,7 @@ int fetch(git_repository *repo, int argc, char **argv)
// Figure out whether it's a named remote or a URL // Figure out whether it's a named remote or a URL
printf("Fetching %s for repo %p\n", argv[1], repo); printf("Fetching %s for repo %p\n", argv[1], repo);
if (git_remote_load(&remote, repo, argv[1]) < 0) { if (git_remote_load(&remote, repo, argv[1]) < 0) {
if (git_remote_new(&remote, repo, NULL, argv[1], NULL) < 0) if (git_remote_create_inmemory(&remote, repo, NULL, argv[1], NULL) < 0)
return -1; return -1;
} }
......
...@@ -21,7 +21,7 @@ static int use_unnamed(git_repository *repo, const char *url) ...@@ -21,7 +21,7 @@ static int use_unnamed(git_repository *repo, const char *url)
// Create an instance of a remote from the URL. The transport to use // Create an instance of a remote from the URL. The transport to use
// is detected from the URL // is detected from the URL
error = git_remote_new(&remote, repo, NULL, url, NULL); error = git_remote_create_inmemory(&remote, repo, NULL, url, NULL);
if (error < 0) if (error < 0)
goto cleanup; goto cleanup;
......
...@@ -42,9 +42,24 @@ typedef int (*git_remote_rename_problem_cb)(const char *problematic_refspec, voi ...@@ -42,9 +42,24 @@ typedef int (*git_remote_rename_problem_cb)(const char *problematic_refspec, voi
*/ */
/** /**
* Add a remote with the default fetch refspec to the repository's configuration
*
* @param out the resulting remote
* @param repo the repository in which to create the remote
* @param name the remote's name
* @param url the remote's url
* @return 0 or an error code
*/
GIT_EXTERN(int) git_remote_create(
git_remote **out,
git_repository *repo,
const char *name,
const char *url);
/**
* Create a remote in memory * Create a remote in memory
* *
* Create a remote with the default refspecs in memory. You can use * Create a remote with the given refspec in memory. You can use
* this when you have a URL instead of a remote's name. * this when you have a URL instead of a remote's name.
* *
* The name, when provided, will be checked for validity. * The name, when provided, will be checked for validity.
...@@ -57,7 +72,12 @@ typedef int (*git_remote_rename_problem_cb)(const char *problematic_refspec, voi ...@@ -57,7 +72,12 @@ typedef int (*git_remote_rename_problem_cb)(const char *problematic_refspec, voi
* @param fetch the fetch refspec to use for this remote. May be NULL for defaults. * @param fetch the fetch refspec to use for this remote. May be NULL for defaults.
* @return 0, GIT_EINVALIDSPEC or an error code * @return 0, GIT_EINVALIDSPEC or an error code
*/ */
GIT_EXTERN(int) git_remote_new(git_remote **out, git_repository *repo, const char *name, const char *url, const char *fetch); GIT_EXTERN(int) git_remote_create_inmemory(
git_remote **out,
git_repository *repo,
const char *name,
const char *url,
const char *fetch);
/** /**
* Sets the owning repository for the remote. This is only allowed on * Sets the owning repository for the remote. This is only allowed on
...@@ -301,17 +321,6 @@ GIT_EXTERN(int) git_remote_supported_url(const char* url); ...@@ -301,17 +321,6 @@ GIT_EXTERN(int) git_remote_supported_url(const char* url);
GIT_EXTERN(int) git_remote_list(git_strarray *out, git_repository *repo); GIT_EXTERN(int) git_remote_list(git_strarray *out, git_repository *repo);
/** /**
* Add a remote with the default fetch refspec to the repository's configuration
*
* @param out the resulting remote
* @param repo the repository in which to create the remote
* @param name the remote's name
* @param url the remote's url
* @return 0 or an error code
*/
GIT_EXTERN(int) git_remote_add(git_remote **out, git_repository *repo, const char *name, const char *url);
/**
* Choose whether to check the server's certificate (applies to HTTPS only) * Choose whether to check the server's certificate (applies to HTTPS only)
* *
* @param remote the remote to configure * @param remote the remote to configure
......
...@@ -267,7 +267,7 @@ static int create_and_configure_origin( ...@@ -267,7 +267,7 @@ static int create_and_configure_origin(
int error; int error;
git_remote *origin = NULL; git_remote *origin = NULL;
if ((error = git_remote_add(&origin, repo, options->remote_name, url)) < 0) if ((error = git_remote_create(&origin, repo, options->remote_name, url)) < 0)
goto on_error; goto on_error;
git_remote_set_cred_acquire_cb(origin, options->cred_acquire_cb, git_remote_set_cred_acquire_cb(origin, options->cred_acquire_cb,
......
...@@ -83,7 +83,7 @@ cleanup: ...@@ -83,7 +83,7 @@ cleanup:
return error; return error;
} }
int git_remote_new(git_remote **out, git_repository *repo, const char *name, const char *url, const char *fetch) int git_remote_create_inmemory(git_remote **out, git_repository *repo, const char *name, const char *url, const char *fetch)
{ {
git_remote *remote; git_remote *remote;
git_buf fetchbuf = GIT_BUF_INIT; git_buf fetchbuf = GIT_BUF_INIT;
...@@ -998,7 +998,7 @@ int git_remote_list(git_strarray *remotes_list, git_repository *repo) ...@@ -998,7 +998,7 @@ int git_remote_list(git_strarray *remotes_list, git_repository *repo)
return 0; return 0;
} }
int git_remote_add(git_remote **out, git_repository *repo, const char *name, const char *url) int git_remote_create(git_remote **out, git_repository *repo, const char *name, const char *url)
{ {
git_buf buf = GIT_BUF_INIT; git_buf buf = GIT_BUF_INIT;
int error; int error;
...@@ -1009,7 +1009,7 @@ int git_remote_add(git_remote **out, git_repository *repo, const char *name, con ...@@ -1009,7 +1009,7 @@ int git_remote_add(git_remote **out, git_repository *repo, const char *name, con
if (git_buf_printf(&buf, "+refs/heads/*:refs/remotes/%s/*", name) < 0) if (git_buf_printf(&buf, "+refs/heads/*:refs/remotes/%s/*", name) < 0)
return -1; return -1;
if (git_remote_new(out, repo, name, url, git_buf_cstr(&buf)) < 0) if (git_remote_create_inmemory(out, repo, name, url, git_buf_cstr(&buf)) < 0)
goto on_error; goto on_error;
git_buf_free(&buf); git_buf_free(&buf);
......
...@@ -1140,7 +1140,7 @@ static int repo_init_create_origin(git_repository *repo, const char *url) ...@@ -1140,7 +1140,7 @@ static int repo_init_create_origin(git_repository *repo, const char *url)
int error; int error;
git_remote *remote; git_remote *remote;
if (!(error = git_remote_add(&remote, repo, GIT_REMOTE_ORIGIN, url))) { if (!(error = git_remote_create(&remote, repo, GIT_REMOTE_ORIGIN, url))) {
error = git_remote_save(remote); error = git_remote_save(remote);
git_remote_free(remote); git_remote_free(remote);
} }
......
...@@ -42,7 +42,7 @@ static void do_fetch(const char *url, git_remote_autotag_option_t flag, int n) ...@@ -42,7 +42,7 @@ static void do_fetch(const char *url, git_remote_autotag_option_t flag, int n)
callbacks.update_tips = update_tips; callbacks.update_tips = update_tips;
counter = 0; counter = 0;
cl_git_pass(git_remote_add(&remote, _repo, "test", url)); cl_git_pass(git_remote_create(&remote, _repo, "test", url));
git_remote_set_callbacks(remote, &callbacks); git_remote_set_callbacks(remote, &callbacks);
git_remote_set_autotag(remote, flag); git_remote_set_autotag(remote, flag);
cl_git_pass(git_remote_connect(remote, GIT_DIRECTION_FETCH)); cl_git_pass(git_remote_connect(remote, GIT_DIRECTION_FETCH));
......
...@@ -21,7 +21,7 @@ void test_network_fetchlocal__complete(void) ...@@ -21,7 +21,7 @@ void test_network_fetchlocal__complete(void)
const char *url = cl_git_fixture_url("testrepo.git"); const char *url = cl_git_fixture_url("testrepo.git");
cl_git_pass(git_repository_init(&repo, "foo", true)); cl_git_pass(git_repository_init(&repo, "foo", true));
cl_git_pass(git_remote_add(&origin, repo, GIT_REMOTE_ORIGIN, url)); cl_git_pass(git_remote_create(&origin, repo, GIT_REMOTE_ORIGIN, url));
cl_git_pass(git_remote_connect(origin, GIT_DIRECTION_FETCH)); cl_git_pass(git_remote_connect(origin, GIT_DIRECTION_FETCH));
cl_git_pass(git_remote_download(origin, transfer_cb, &callcount)); cl_git_pass(git_remote_download(origin, transfer_cb, &callcount));
cl_git_pass(git_remote_update_tips(origin)); cl_git_pass(git_remote_update_tips(origin));
...@@ -47,7 +47,7 @@ void test_network_fetchlocal__partial(void) ...@@ -47,7 +47,7 @@ void test_network_fetchlocal__partial(void)
cl_assert_equal_i(1, (int)refnames.count); cl_assert_equal_i(1, (int)refnames.count);
url = cl_git_fixture_url("testrepo.git"); url = cl_git_fixture_url("testrepo.git");
cl_git_pass(git_remote_add(&origin, repo, GIT_REMOTE_ORIGIN, url)); cl_git_pass(git_remote_create(&origin, repo, GIT_REMOTE_ORIGIN, url));
cl_git_pass(git_remote_connect(origin, GIT_DIRECTION_FETCH)); cl_git_pass(git_remote_connect(origin, GIT_DIRECTION_FETCH));
cl_git_pass(git_remote_download(origin, transfer_cb, &callcount)); cl_git_pass(git_remote_download(origin, transfer_cb, &callcount));
cl_git_pass(git_remote_update_tips(origin)); cl_git_pass(git_remote_update_tips(origin));
......
...@@ -166,7 +166,7 @@ void test_network_push__initialize(void) ...@@ -166,7 +166,7 @@ void test_network_push__initialize(void)
_remote = NULL; _remote = NULL;
if (_remote_url) { if (_remote_url) {
cl_git_pass(git_remote_add(&_remote, _repo, "test", _remote_url)); cl_git_pass(git_remote_create(&_remote, _repo, "test", _remote_url));
git_remote_set_cred_acquire_cb(_remote, cred_acquire_cb, &cred_acquire_called); git_remote_set_cred_acquire_cb(_remote, cred_acquire_cb, &cred_acquire_called);
record_callbacks_data_clear(&_record_cbs_data); record_callbacks_data_clear(&_record_cbs_data);
......
...@@ -50,7 +50,7 @@ static void connect_to_local_repository(const char *local_repository) ...@@ -50,7 +50,7 @@ static void connect_to_local_repository(const char *local_repository)
{ {
git_buf_sets(&file_path_buf, cl_git_path_url(local_repository)); git_buf_sets(&file_path_buf, cl_git_path_url(local_repository));
cl_git_pass(git_remote_new(&remote, repo, NULL, git_buf_cstr(&file_path_buf), NULL)); cl_git_pass(git_remote_create_inmemory(&remote, repo, NULL, git_buf_cstr(&file_path_buf), NULL));
cl_git_pass(git_remote_connect(remote, GIT_DIRECTION_FETCH)); cl_git_pass(git_remote_connect(remote, GIT_DIRECTION_FETCH));
} }
......
...@@ -154,7 +154,7 @@ void test_network_remoterename__renaming_an_inmemory_remote_persists_it(void) ...@@ -154,7 +154,7 @@ void test_network_remoterename__renaming_an_inmemory_remote_persists_it(void)
assert_config_entry_existence(_repo, "remote.durable.url", false); assert_config_entry_existence(_repo, "remote.durable.url", false);
cl_git_pass(git_remote_new(&remote, _repo, NULL, "git://github.com/libgit2/durable.git", NULL)); cl_git_pass(git_remote_create_inmemory(&remote, _repo, NULL, "git://github.com/libgit2/durable.git", NULL));
assert_config_entry_existence(_repo, "remote.durable.url", false); assert_config_entry_existence(_repo, "remote.durable.url", false);
...@@ -176,7 +176,7 @@ void test_network_remoterename__renaming_an_inmemory_nameless_remote_notifies_th ...@@ -176,7 +176,7 @@ void test_network_remoterename__renaming_an_inmemory_nameless_remote_notifies_th
assert_config_entry_existence(_repo, "remote.volatile.url", false); assert_config_entry_existence(_repo, "remote.volatile.url", false);
cl_git_pass(git_remote_new( cl_git_pass(git_remote_create_inmemory(
&remote, &remote,
_repo, _repo,
NULL, NULL,
......
...@@ -108,7 +108,7 @@ void test_network_remotes__save(void) ...@@ -108,7 +108,7 @@ void test_network_remotes__save(void)
_remote = NULL; _remote = NULL;
/* Set up the remote and save it to config */ /* Set up the remote and save it to config */
cl_git_pass(git_remote_new(&_remote, _repo, "upstream", "git://github.com/libgit2/libgit2", NULL)); cl_git_pass(git_remote_create_inmemory(&_remote, _repo, "upstream", "git://github.com/libgit2/libgit2", NULL));
cl_git_pass(git_remote_set_fetchspec(_remote, "refs/heads/*:refs/remotes/upstream/*")); cl_git_pass(git_remote_set_fetchspec(_remote, "refs/heads/*:refs/remotes/upstream/*"));
cl_git_pass(git_remote_set_pushspec(_remote, "refs/heads/*:refs/heads/*")); cl_git_pass(git_remote_set_pushspec(_remote, "refs/heads/*:refs/heads/*"));
cl_git_pass(git_remote_set_pushurl(_remote, "git://github.com/libgit2/libgit2_push")); cl_git_pass(git_remote_set_pushurl(_remote, "git://github.com/libgit2/libgit2_push"));
...@@ -229,7 +229,7 @@ void test_network_remotes__add(void) ...@@ -229,7 +229,7 @@ void test_network_remotes__add(void)
git_remote_free(_remote); git_remote_free(_remote);
_remote = NULL; _remote = NULL;
cl_git_pass(git_remote_add(&_remote, _repo, "addtest", "http://github.com/libgit2/libgit2")); cl_git_pass(git_remote_create(&_remote, _repo, "addtest", "http://github.com/libgit2/libgit2"));
git_remote_free(_remote); git_remote_free(_remote);
_remote = NULL; _remote = NULL;
...@@ -248,14 +248,14 @@ void test_network_remotes__cannot_add_a_nameless_remote(void) ...@@ -248,14 +248,14 @@ void test_network_remotes__cannot_add_a_nameless_remote(void)
cl_assert_equal_i( cl_assert_equal_i(
GIT_EINVALIDSPEC, GIT_EINVALIDSPEC,
git_remote_add(&remote, _repo, NULL, "git://github.com/libgit2/libgit2")); git_remote_create(&remote, _repo, NULL, "git://github.com/libgit2/libgit2"));
} }
void test_network_remotes__cannot_save_a_nameless_remote(void) void test_network_remotes__cannot_save_a_nameless_remote(void)
{ {
git_remote *remote; git_remote *remote;
cl_git_pass(git_remote_new(&remote, _repo, NULL, "git://github.com/libgit2/libgit2", NULL)); cl_git_pass(git_remote_create_inmemory(&remote, _repo, NULL, "git://github.com/libgit2/libgit2", NULL));
cl_assert_equal_i(GIT_EINVALIDSPEC, git_remote_save(remote)); cl_assert_equal_i(GIT_EINVALIDSPEC, git_remote_save(remote));
git_remote_free(remote); git_remote_free(remote);
...@@ -267,12 +267,12 @@ void test_network_remotes__cannot_add_a_remote_with_an_invalid_name(void) ...@@ -267,12 +267,12 @@ void test_network_remotes__cannot_add_a_remote_with_an_invalid_name(void)
cl_assert_equal_i( cl_assert_equal_i(
GIT_EINVALIDSPEC, GIT_EINVALIDSPEC,
git_remote_add(&remote, _repo, "Inv@{id", "git://github.com/libgit2/libgit2")); git_remote_create(&remote, _repo, "Inv@{id", "git://github.com/libgit2/libgit2"));
cl_assert_equal_p(remote, NULL); cl_assert_equal_p(remote, NULL);
cl_assert_equal_i( cl_assert_equal_i(
GIT_EINVALIDSPEC, GIT_EINVALIDSPEC,
git_remote_add(&remote, _repo, "", "git://github.com/libgit2/libgit2")); git_remote_create(&remote, _repo, "", "git://github.com/libgit2/libgit2"));
cl_assert_equal_p(remote, NULL); cl_assert_equal_p(remote, NULL);
} }
...@@ -282,12 +282,12 @@ void test_network_remotes__cannot_initialize_a_remote_with_an_invalid_name(void) ...@@ -282,12 +282,12 @@ void test_network_remotes__cannot_initialize_a_remote_with_an_invalid_name(void)
cl_assert_equal_i( cl_assert_equal_i(
GIT_EINVALIDSPEC, GIT_EINVALIDSPEC,
git_remote_new(&remote, _repo, "Inv@{id", "git://github.com/libgit2/libgit2", NULL)); git_remote_create_inmemory(&remote, _repo, "Inv@{id", "git://github.com/libgit2/libgit2", NULL));
cl_assert_equal_p(remote, NULL); cl_assert_equal_p(remote, NULL);
cl_assert_equal_i( cl_assert_equal_i(
GIT_EINVALIDSPEC, GIT_EINVALIDSPEC,
git_remote_new(&remote, _repo, "", "git://github.com/libgit2/libgit2", NULL)); git_remote_create_inmemory(&remote, _repo, "", "git://github.com/libgit2/libgit2", NULL));
cl_assert_equal_p(remote, NULL); cl_assert_equal_p(remote, NULL);
} }
...@@ -331,7 +331,7 @@ void test_network_remotes__check_structure_version(void) ...@@ -331,7 +331,7 @@ void test_network_remotes__check_structure_version(void)
git_remote_free(_remote); git_remote_free(_remote);
_remote = NULL; _remote = NULL;
cl_git_pass(git_remote_new(&_remote, _repo, NULL, "test-protocol://localhost", NULL)); cl_git_pass(git_remote_create_inmemory(&_remote, _repo, NULL, "test-protocol://localhost", NULL));
transport.version = 0; transport.version = 0;
cl_git_fail(git_remote_set_transport(_remote, &transport)); cl_git_fail(git_remote_set_transport(_remote, &transport));
...@@ -350,7 +350,7 @@ void test_network_remotes__dangling(void) ...@@ -350,7 +350,7 @@ void test_network_remotes__dangling(void)
git_remote_free(_remote); git_remote_free(_remote);
_remote = NULL; _remote = NULL;
cl_git_pass(git_remote_new(&_remote, NULL, "upstream", "git://github.com/libgit2/libgit2", NULL)); cl_git_pass(git_remote_create_inmemory(&_remote, NULL, "upstream", "git://github.com/libgit2/libgit2", NULL));
cl_git_pass(git_remote_rename(_remote, "newname", NULL, NULL)); cl_git_pass(git_remote_rename(_remote, "newname", NULL, NULL));
cl_assert_equal_s(git_remote_name(_remote), "newname"); cl_assert_equal_s(git_remote_name(_remote), "newname");
......
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