summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorVicent Martí <tanoku@gmail.com>2012-05-08 13:42:11 -0700
committerVicent Martí <tanoku@gmail.com>2012-05-08 13:42:11 -0700
commit1f796cd1807180bbf20d094954fd7909c6ef1ac7 (patch)
tree76cf03ff7b162da11c22b5d8b76c671149dd299d /src
parent19579847f6b4ee6942253f2a6311a936e4ac05ac (diff)
parentbaaa8a447ed6da152038770805464485d5d7bb21 (diff)
downloadlibgit2-1f796cd1807180bbf20d094954fd7909c6ef1ac7.tar.gz
Merge pull request #676 from carlosmn/remotes
Add git_remote_add() and change signature for _new()
Diffstat (limited to 'src')
-rw-r--r--src/config_file.c12
-rw-r--r--src/remote.c34
2 files changed, 39 insertions, 7 deletions
diff --git a/src/config_file.c b/src/config_file.c
index 746d9655c..4ccec2bc1 100644
--- a/src/config_file.c
+++ b/src/config_file.c
@@ -258,18 +258,17 @@ static int config_set(git_config_file *cfg, const char *name, const char *value)
GITERR_CHECK_ALLOC(var->value);
}
+ if (config_write(b, key, NULL, value) < 0) {
+ cvar_free(var);
+ return -1;
+ }
+
git_strmap_insert2(b->values, key, var, old_var, rval);
if (rval < 0)
return -1;
if (old_var != NULL)
cvar_free(old_var);
- if (config_write(b, key, NULL, value) < 0) {
- git_strmap_delete(b->values, var->key);
- cvar_free(var);
- return -1;
- }
-
return 0;
}
@@ -1018,6 +1017,7 @@ static int config_write(diskfile_backend *cfg, const char *key, const regex_t *p
pre_end = post_start = cfg->reader.read_ptr;
git__free(current_section);
+ current_section = NULL;
if (parse_section_header(cfg, &current_section) < 0)
goto rewrite_fail;
diff --git a/src/remote.c b/src/remote.c
index 6a1390dba..a5cfc822e 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)
@@ -476,3 +485,26 @@ 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_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)
+ goto on_error;
+
+ git_buf_free(&buf);
+
+ if (git_remote_save(*out) < 0)
+ goto on_error;
+
+ return 0;
+
+on_error:
+ git_buf_free(&buf);
+ git_remote_free(*out);
+ return -1;
+}