diff options
author | Victor Garcia <victor@tuenti.com> | 2013-11-08 12:14:31 +0100 |
---|---|---|
committer | Victor Garcia <victor@tuenti.com> | 2013-11-08 12:14:31 +0100 |
commit | 40b99d05b4a1221768c25c889180c12d2f43be8b (patch) | |
tree | 6fbf4f41fb843571598025a1d123899b0233c873 /src | |
parent | 99feb98897fa1daa0ff3fd70b17ccc9d9a51f1d0 (diff) | |
download | libgit2-40b99d05b4a1221768c25c889180c12d2f43be8b.tar.gz |
splitting funcionality in two methods to avoid ambiguity with NULL
Diffstat (limited to 'src')
-rw-r--r-- | src/clone.c | 2 | ||||
-rw-r--r-- | src/remote.c | 39 | ||||
-rw-r--r-- | src/repository.c | 2 |
3 files changed, 35 insertions, 8 deletions
diff --git a/src/clone.c b/src/clone.c index 8d99e8fc8..657243945 100644 --- a/src/clone.c +++ b/src/clone.c @@ -309,7 +309,7 @@ static int create_and_configure_origin( const char *name; name = options->remote_name ? options->remote_name : "origin"; - if ((error = git_remote_create(&origin, repo, name, url, NULL)) < 0) + if ((error = git_remote_create(&origin, repo, name, url)) < 0) goto on_error; if (options->ignore_cert_errors) diff --git a/src/remote.c b/src/remote.c index b812c91dd..b97cc9e79 100644 --- a/src/remote.c +++ b/src/remote.c @@ -174,7 +174,7 @@ static int ensure_remote_doesnot_exist(git_repository *repo, const char *name) } -int git_remote_create(git_remote **out, git_repository *repo, const char *name, const char *url, const char *fetch) +int git_remote_create(git_remote **out, git_repository *repo, const char *name, const char *url) { git_buf buf = GIT_BUF_INIT; git_remote *remote = NULL; @@ -186,11 +186,38 @@ int git_remote_create(git_remote **out, git_repository *repo, const char *name, if ((error = ensure_remote_doesnot_exist(repo, name)) < 0) return error; - if (fetch == NULL) { - if (git_buf_printf(&buf, "+refs/heads/*:refs/remotes/%s/*", name) < 0) - return -1; - fetch = git_buf_cstr(&buf); - } + if (git_buf_printf(&buf, "+refs/heads/*:refs/remotes/%s/*", name) < 0) + return -1; + + if (create_internal(&remote, repo, name, url, git_buf_cstr(&buf)) < 0) + goto on_error; + + git_buf_free(&buf); + + if (git_remote_save(remote) < 0) + goto on_error; + + *out = remote; + + return 0; + +on_error: + git_buf_free(&buf); + git_remote_free(remote); + return -1; +} + +int git_remote_create_with_fetchspec(git_remote **out, git_repository *repo, const char *name, const char *url, const char *fetch) +{ + git_buf buf = GIT_BUF_INIT; + git_remote *remote = NULL; + int error; + + if ((error = ensure_remote_name_is_valid(name)) < 0) + return error; + + if ((error = ensure_remote_doesnot_exist(repo, name)) < 0) + return error; if (create_internal(&remote, repo, name, url, fetch) < 0) goto on_error; diff --git a/src/repository.c b/src/repository.c index f1eff165c..dcc02e4fb 100644 --- a/src/repository.c +++ b/src/repository.c @@ -1473,7 +1473,7 @@ static int repo_init_create_origin(git_repository *repo, const char *url) int error; git_remote *remote; - if (!(error = git_remote_create(&remote, repo, GIT_REMOTE_ORIGIN, url, NULL))) { + if (!(error = git_remote_create(&remote, repo, GIT_REMOTE_ORIGIN, url))) { git_remote_free(remote); } |