diff options
| author | Carlos Martín Nieto <carlos@cmartin.tk> | 2011-11-18 21:28:07 +0100 |
|---|---|---|
| committer | Carlos Martín Nieto <carlos@cmartin.tk> | 2011-11-18 21:39:34 +0100 |
| commit | 617bfdf47fbe307070dcd084a4e3ea410823c88c (patch) | |
| tree | 1d6e64a6a4201eac53eac285464d13e3283881b6 /src/remote.c | |
| parent | 95057b85034a226ed5f9bcd7a461a296bbdb7bd9 (diff) | |
| download | libgit2-617bfdf47fbe307070dcd084a4e3ea410823c88c.tar.gz | |
Add a name to a remote created from the API
Make it a bit more resilient.
Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk>
Diffstat (limited to 'src/remote.c')
| -rw-r--r-- | src/remote.c | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/remote.c b/src/remote.c index 6ac3bc168..d541cd0cb 100644 --- a/src/remote.c +++ b/src/remote.c @@ -56,22 +56,34 @@ 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) +int git_remote_new(git_remote **out, git_repository *repo, const char *url, const char *name) { git_remote *remote; + if (url == NULL) + return git__throw(GIT_EINVALIDARGS, "No URL was given"); + remote = git__malloc(sizeof(git_remote)); if (remote == NULL) return GIT_ENOMEM; memset(remote, 0x0, sizeof(git_remote)); remote->repo = repo; + remote->url = git__strdup(url); if (remote->url == NULL) { git__free(remote); return GIT_ENOMEM; } + if (name != NULL) { + remote->name = git__strdup(name); + if (remote->name == NULL) { + git__free(remote); + return GIT_ENOMEM; + } + } + *out = remote; return GIT_SUCCESS; } |
