Commit 29f27599eab750d2b4b8935a14be8b596b7affe2

Ben Straub 2012-12-20T10:51:09

Rename remote creation APIs git_remote_add -> git_remote_create git_remote_new -> git_remote_create_inmemory

diff --git a/examples/network/fetch.c b/examples/network/fetch.c
index 8048fd6..f81c4fa 100644
--- a/examples/network/fetch.c
+++ b/examples/network/fetch.c
@@ -76,7 +76,7 @@ int fetch(git_repository *repo, int argc, char **argv)
 	// Figure out whether it's a named remote or a URL
 	printf("Fetching %s for repo %p\n", argv[1], repo);
 	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;
 	}
 
diff --git a/examples/network/ls-remote.c b/examples/network/ls-remote.c
index 62131d4..d3e3ed0 100644
--- a/examples/network/ls-remote.c
+++ b/examples/network/ls-remote.c
@@ -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
 	// 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)
 		goto cleanup;
 
diff --git a/include/git2/remote.h b/include/git2/remote.h
index f3b0a94..52404c0 100644
--- a/include/git2/remote.h
+++ b/include/git2/remote.h
@@ -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 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.
  *
  * 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
  * @param fetch the fetch refspec to use for this remote. May be NULL for defaults.
  * @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
@@ -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);
 
 /**
- * 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)
  *
  * @param remote the remote to configure
diff --git a/src/clone.c b/src/clone.c
index fae2458..9c4a5d9 100644
--- a/src/clone.c
+++ b/src/clone.c
@@ -267,7 +267,7 @@ static int create_and_configure_origin(
 	int error;
 	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;
 
 	git_remote_set_cred_acquire_cb(origin, options->cred_acquire_cb,
diff --git a/src/remote.c b/src/remote.c
index 28ce88a..4a5e144 100644
--- a/src/remote.c
+++ b/src/remote.c
@@ -83,7 +83,7 @@ cleanup:
 	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_buf fetchbuf = GIT_BUF_INIT;
@@ -998,7 +998,7 @@ int git_remote_list(git_strarray *remotes_list, git_repository *repo)
 	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;
 	int error;
@@ -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)
 		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;
 
 	git_buf_free(&buf);
diff --git a/src/repository.c b/src/repository.c
index 10ed12b..ea4be9d 100644
--- a/src/repository.c
+++ b/src/repository.c
@@ -1140,7 +1140,7 @@ static int repo_init_create_origin(git_repository *repo, const char *url)
 	int error;
 	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);
 		git_remote_free(remote);
 	}
diff --git a/tests-clar/network/fetch.c b/tests-clar/network/fetch.c
index e724735..cde4f03 100644
--- a/tests-clar/network/fetch.c
+++ b/tests-clar/network/fetch.c
@@ -42,7 +42,7 @@ static void do_fetch(const char *url, git_remote_autotag_option_t flag, int n)
 	callbacks.update_tips = update_tips;
 	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_autotag(remote, flag);
 	cl_git_pass(git_remote_connect(remote, GIT_DIRECTION_FETCH));
diff --git a/tests-clar/network/fetchlocal.c b/tests-clar/network/fetchlocal.c
index 018531c..2494924 100644
--- a/tests-clar/network/fetchlocal.c
+++ b/tests-clar/network/fetchlocal.c
@@ -21,7 +21,7 @@ void test_network_fetchlocal__complete(void)
 	const char *url = cl_git_fixture_url("testrepo.git");
 	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_download(origin, transfer_cb, &callcount));
 	cl_git_pass(git_remote_update_tips(origin));
@@ -47,7 +47,7 @@ void test_network_fetchlocal__partial(void)
 	cl_assert_equal_i(1, (int)refnames.count);
 
 	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_download(origin, transfer_cb, &callcount));
 	cl_git_pass(git_remote_update_tips(origin));
diff --git a/tests-clar/network/push.c b/tests-clar/network/push.c
index cecb5ba..5f0a80c 100644
--- a/tests-clar/network/push.c
+++ b/tests-clar/network/push.c
@@ -166,7 +166,7 @@ void test_network_push__initialize(void)
 	_remote = NULL;
 
 	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);
 		record_callbacks_data_clear(&_record_cbs_data);
diff --git a/tests-clar/network/remotelocal.c b/tests-clar/network/remotelocal.c
index 8376b8b..1839679 100644
--- a/tests-clar/network/remotelocal.c
+++ b/tests-clar/network/remotelocal.c
@@ -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));
 
-	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));
 
 }
diff --git a/tests-clar/network/remoterename.c b/tests-clar/network/remoterename.c
index bd58231..35d197e 100644
--- a/tests-clar/network/remoterename.c
+++ b/tests-clar/network/remoterename.c
@@ -154,7 +154,7 @@ void test_network_remoterename__renaming_an_inmemory_remote_persists_it(void)
 
 	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);
 
@@ -176,7 +176,7 @@ void test_network_remoterename__renaming_an_inmemory_nameless_remote_notifies_th
 
 	assert_config_entry_existence(_repo, "remote.volatile.url", false);
 
-	cl_git_pass(git_remote_new(
+	cl_git_pass(git_remote_create_inmemory(
 		&remote,
 		_repo,
 		NULL,
diff --git a/tests-clar/network/remotes.c b/tests-clar/network/remotes.c
index 651cbef..15e3b03 100644
--- a/tests-clar/network/remotes.c
+++ b/tests-clar/network/remotes.c
@@ -108,7 +108,7 @@ void test_network_remotes__save(void)
 	_remote = NULL;
 
 	/* 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_pushspec(_remote, "refs/heads/*:refs/heads/*"));
 	cl_git_pass(git_remote_set_pushurl(_remote, "git://github.com/libgit2/libgit2_push"));
@@ -229,7 +229,7 @@ void test_network_remotes__add(void)
 	git_remote_free(_remote);
 	_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);
 	_remote = NULL;
@@ -248,14 +248,14 @@ void test_network_remotes__cannot_add_a_nameless_remote(void)
 
 	cl_assert_equal_i(
 		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)
 {
 	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));
 	git_remote_free(remote);
@@ -267,12 +267,12 @@ void test_network_remotes__cannot_add_a_remote_with_an_invalid_name(void)
 
 	cl_assert_equal_i(
 		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_i(
 		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);
 }
 
@@ -282,12 +282,12 @@ void test_network_remotes__cannot_initialize_a_remote_with_an_invalid_name(void)
 
 	cl_assert_equal_i(
 		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_i(
 		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);
 }
 
@@ -331,7 +331,7 @@ void test_network_remotes__check_structure_version(void)
 
 	git_remote_free(_remote);
 	_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;
 	cl_git_fail(git_remote_set_transport(_remote, &transport));
@@ -350,7 +350,7 @@ void test_network_remotes__dangling(void)
 	git_remote_free(_remote);
 	_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_assert_equal_s(git_remote_name(_remote), "newname");