Commit 4dbcf0e6 by Edward Thomson

remote: free the config snapshot

This reverts commit 55522376 and frees the snapshot properly.
parent be343b88
...@@ -192,7 +192,7 @@ static int canonicalize_url(git_buf *out, const char *in) ...@@ -192,7 +192,7 @@ static int canonicalize_url(git_buf *out, const char *in)
static int create_internal(git_remote **out, git_repository *repo, const char *name, const char *url, const char *fetch) static int create_internal(git_remote **out, git_repository *repo, const char *name, const char *url, const char *fetch)
{ {
git_remote *remote; git_remote *remote;
git_config *config = NULL; git_config *config_ro = NULL, *config_rw;
git_buf canonical_url = GIT_BUF_INIT; git_buf canonical_url = GIT_BUF_INIT;
git_buf var = GIT_BUF_INIT; git_buf var = GIT_BUF_INIT;
int error = -1; int error = -1;
...@@ -200,7 +200,7 @@ static int create_internal(git_remote **out, git_repository *repo, const char *n ...@@ -200,7 +200,7 @@ static int create_internal(git_remote **out, git_repository *repo, const char *n
/* name is optional */ /* name is optional */
assert(out && repo && url); assert(out && repo && url);
if ((error = git_repository_config__weakptr(&config, repo)) < 0) if ((error = git_repository_config_snapshot(&config_ro, repo)) < 0)
return error; return error;
remote = git__calloc(1, sizeof(git_remote)); remote = git__calloc(1, sizeof(git_remote));
...@@ -212,7 +212,8 @@ static int create_internal(git_remote **out, git_repository *repo, const char *n ...@@ -212,7 +212,8 @@ static int create_internal(git_remote **out, git_repository *repo, const char *n
(error = canonicalize_url(&canonical_url, url)) < 0) (error = canonicalize_url(&canonical_url, url)) < 0)
goto on_error; goto on_error;
remote->url = apply_insteadof(repo->_config, canonical_url.ptr, GIT_DIRECTION_FETCH); remote->url = apply_insteadof(config_ro, canonical_url.ptr, GIT_DIRECTION_FETCH);
GITERR_CHECK_ALLOC(remote->url);
if (name != NULL) { if (name != NULL) {
remote->name = git__strdup(name); remote->name = git__strdup(name);
...@@ -221,7 +222,8 @@ static int create_internal(git_remote **out, git_repository *repo, const char *n ...@@ -221,7 +222,8 @@ static int create_internal(git_remote **out, git_repository *repo, const char *n
if ((error = git_buf_printf(&var, CONFIG_URL_FMT, name)) < 0) if ((error = git_buf_printf(&var, CONFIG_URL_FMT, name)) < 0)
goto on_error; goto on_error;
if ((error = git_config_set_string(config, var.ptr, canonical_url.ptr)) < 0) if ((error = git_repository_config__weakptr(&config_rw, repo)) < 0 ||
(error = git_config_set_string(config_rw, var.ptr, canonical_url.ptr)) < 0)
goto on_error; goto on_error;
} }
...@@ -233,10 +235,7 @@ static int create_internal(git_remote **out, git_repository *repo, const char *n ...@@ -233,10 +235,7 @@ static int create_internal(git_remote **out, git_repository *repo, const char *n
if (name && (error = write_add_refspec(repo, name, fetch, true)) < 0) if (name && (error = write_add_refspec(repo, name, fetch, true)) < 0)
goto on_error; goto on_error;
if ((error = git_repository_config_snapshot(&config, repo)) < 0) if ((error = lookup_remote_prune_config(remote, config_ro, name)) < 0)
goto on_error;
if ((error = lookup_remote_prune_config(remote, config, name)) < 0)
goto on_error; goto on_error;
/* Move the data over to where the matching functions can find them */ /* Move the data over to where the matching functions can find them */
...@@ -260,6 +259,7 @@ on_error: ...@@ -260,6 +259,7 @@ on_error:
if (error) if (error)
git_remote_free(remote); git_remote_free(remote);
git_config_free(config_ro);
git_buf_free(&canonical_url); git_buf_free(&canonical_url);
git_buf_free(&var); git_buf_free(&var);
return error; return error;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment