diff options
author | Carlos Martín Nieto <carlos@cmartin.tk> | 2012-05-03 20:25:56 +0200 |
---|---|---|
committer | Carlos Martín Nieto <carlos@cmartin.tk> | 2012-05-03 20:28:49 +0200 |
commit | 8e210931ca5d57b6ca7bc16b41598faa9339bc09 (patch) | |
tree | da738a93013dcd6c92e9249385b72956b5b1a74b | |
parent | 0ed572d4f529ff778e4a38b53445912c3e85d2ef (diff) | |
download | libgit2-8e210931ca5d57b6ca7bc16b41598faa9339bc09.tar.gz |
remotes: change git_remote_new's signature
Add a fetch refspec arguemnt and make the arguments (name, url,
refspec), as that order makes more sense.
-rw-r--r-- | examples/network/fetch.c | 2 | ||||
-rw-r--r-- | examples/network/ls-remote.c | 2 | ||||
-rw-r--r-- | include/git2/remote.h | 5 | ||||
-rw-r--r-- | src/remote.c | 19 | ||||
-rw-r--r-- | tests-clar/network/remotelocal.c | 2 | ||||
-rw-r--r-- | tests-clar/network/remotes.c | 2 |
6 files changed, 20 insertions, 12 deletions
diff --git a/examples/network/fetch.c b/examples/network/fetch.c index 23046bd09..f4a044984 100644 --- a/examples/network/fetch.c +++ b/examples/network/fetch.c @@ -69,7 +69,7 @@ int fetch(git_repository *repo, int argc, char **argv) // Figure out whether it's a named remote or a URL printf("Fetching %s\n", argv[1]); if (git_remote_load(&remote, repo, argv[1]) < 0) { - if (git_remote_new(&remote, repo, argv[1], NULL) < 0) + if (git_remote_new(&remote, repo, NULL, argv[1], NULL) < 0) return -1; } diff --git a/examples/network/ls-remote.c b/examples/network/ls-remote.c index 02d432e8b..958a88651 100644 --- a/examples/network/ls-remote.c +++ b/examples/network/ls-remote.c @@ -19,7 +19,7 @@ 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, url, NULL); + error = git_remote_new(&remote, repo, NULL, url, NULL); if (error < GIT_SUCCESS) goto cleanup; diff --git a/include/git2/remote.h b/include/git2/remote.h index 5794f8d16..41ca7dbac 100644 --- a/include/git2/remote.h +++ b/include/git2/remote.h @@ -38,11 +38,12 @@ GIT_BEGIN_DECL * * @param out pointer to the new remote object * @param repo the associtated repository - * @param url the remote repository's URL * @param name the remote's name + * @param url the remote repository's URL + * @param fetch the fetch refspec to use for this remote * @return GIT_SUCCESS or an error code */ -GIT_EXTERN(int) git_remote_new(git_remote **out, git_repository *repo, const char *url, const char *name); +GIT_EXTERN(int) git_remote_new(git_remote **out, git_repository *repo, const char *name, const char *url, const char *fetch); /** * Get the information for a particular remote diff --git a/src/remote.c b/src/remote.c index 4dea89e3a..ca61091e0 100644 --- a/src/remote.c +++ b/src/remote.c @@ -54,7 +54,7 @@ static int parse_remote_refspec(git_config *cfg, git_refspec *refspec, const cha return refspec_parse(refspec, val); } -int git_remote_new(git_remote **out, git_repository *repo, const char *url, const char *name) +int git_remote_new(git_remote **out, git_repository *repo, const char *name, const char *url, const char *fetch) { git_remote *remote; @@ -78,8 +78,17 @@ int git_remote_new(git_remote **out, git_repository *repo, const char *url, cons GITERR_CHECK_ALLOC(remote->name); } + if (fetch != NULL) { + if (refspec_parse(&remote->fetch, fetch) < 0) + goto on_error; + } + *out = remote; return 0; + +on_error: + git_remote_free(remote); + return -1; } int git_remote_load(git_remote **out, git_repository *repo, const char *name) @@ -474,19 +483,17 @@ int git_remote_list(git_strarray *remotes_list, git_repository *repo) int git_remote_add(git_remote **out, git_repository *repo, const char *name, const char *url) { git_buf buf = GIT_BUF_INIT; - if (git_remote_new(out, repo, url, name) < 0) - return -1; if (git_buf_printf(&buf, "refs/heads/*:refs/remotes/%s/*", name) < 0) - goto on_error; + return -1; - if (git_remote_set_fetchspec(*out, git_buf_cstr(&buf)) < 0) + if (git_remote_new(out, repo, name, url, git_buf_cstr(&buf)) < 0) goto on_error; git_buf_free(&buf); if (git_remote_save(*out) < 0) - return -1; + goto on_error; return 0; diff --git a/tests-clar/network/remotelocal.c b/tests-clar/network/remotelocal.c index e154226d9..35fa072ef 100644 --- a/tests-clar/network/remotelocal.c +++ b/tests-clar/network/remotelocal.c @@ -85,7 +85,7 @@ static void connect_to_local_repository(const char *local_repository) { build_local_file_url(&file_path_buf, local_repository); - cl_git_pass(git_remote_new(&remote, repo, git_buf_cstr(&file_path_buf), NULL)); + cl_git_pass(git_remote_new(&remote, repo, NULL, git_buf_cstr(&file_path_buf), NULL)); cl_git_pass(git_remote_connect(remote, GIT_DIR_FETCH)); } diff --git a/tests-clar/network/remotes.c b/tests-clar/network/remotes.c index c7e4afbbb..6e5d79b62 100644 --- a/tests-clar/network/remotes.c +++ b/tests-clar/network/remotes.c @@ -57,7 +57,7 @@ void test_network_remotes__save(void) git_remote_free(_remote); /* Set up the remote and save it to config */ - cl_git_pass(git_remote_new(&_remote, _repo, "git://github.com/libgit2/libgit2", "upstream")); + cl_git_pass(git_remote_new(&_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_save(_remote)); |