From 0ed572d4f529ff778e4a38b53445912c3e85d2ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Thu, 3 May 2012 16:08:33 +0200 Subject: remote: add git_remote_add() Helper function to create a remote with the default settings --- src/remote.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'src/remote.c') diff --git a/src/remote.c b/src/remote.c index 98c256929..4dea89e3a 100644 --- a/src/remote.c +++ b/src/remote.c @@ -470,3 +470,28 @@ 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) +{ + 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; + + if (git_remote_set_fetchspec(*out, git_buf_cstr(&buf)) < 0) + goto on_error; + + git_buf_free(&buf); + + if (git_remote_save(*out) < 0) + return -1; + + return 0; + +on_error: + git_buf_free(&buf); + git_remote_free(*out); + return -1; +} -- cgit v1.2.1 From 8e210931ca5d57b6ca7bc16b41598faa9339bc09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Thu, 3 May 2012 20:25:56 +0200 Subject: 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. --- src/remote.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'src/remote.c') 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; -- cgit v1.2.1