diff options
author | Carlos Martín Nieto <cmn@dwim.me> | 2014-12-21 15:31:03 +0000 |
---|---|---|
committer | Carlos Martín Nieto <cmn@dwim.me> | 2015-03-03 18:35:12 +0100 |
commit | 9a97f49e3aa15edc479fc590f4b28fc44c155c40 (patch) | |
tree | b85de2d396b9d0d408f688212c0cdc74347ea7b3 /src/checkout.c | |
parent | 76f034180aee96fcc1fffd5267ccbc6ada68482a (diff) | |
download | libgit2-cmn/config-borrow-entry.tar.gz |
config: borrow refcounted referencescmn/config-borrow-entry
This changes the get_entry() method to return a refcounted version of
the config entry, which you have to free when you're done.
This allows us to avoid freeing the memory in which the entry is stored
on a refresh, which may happen at any time for a live config.
For this reason, get_string() has been forbidden on live configs and a
new function get_string_buf() has been added, which stores the string in
a git_buf which the user then owns.
The functions which parse the string value takea advantage of the
borrowing to parse safely and then release the entry.
Diffstat (limited to 'src/checkout.c')
-rw-r--r-- | src/checkout.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/checkout.c b/src/checkout.c index c06928138..b106c110c 100644 --- a/src/checkout.c +++ b/src/checkout.c @@ -2390,25 +2390,27 @@ static int checkout_data_init( if ((data->opts.checkout_strategy & (GIT_CHECKOUT_CONFLICT_STYLE_MERGE | GIT_CHECKOUT_CONFLICT_STYLE_DIFF3)) == 0) { - const char *conflict_style; + git_config_entry *conflict_style = NULL; git_config *cfg = NULL; if ((error = git_repository_config__weakptr(&cfg, repo)) < 0 || - (error = git_config_get_string(&conflict_style, cfg, "merge.conflictstyle")) < 0 || + (error = git_config_get_entry(&conflict_style, cfg, "merge.conflictstyle")) < 0 || error == GIT_ENOTFOUND) ; else if (error) goto cleanup; - else if (strcmp(conflict_style, "merge") == 0) + else if (strcmp(conflict_style->value, "merge") == 0) data->opts.checkout_strategy |= GIT_CHECKOUT_CONFLICT_STYLE_MERGE; - else if (strcmp(conflict_style, "diff3") == 0) + else if (strcmp(conflict_style->value, "diff3") == 0) data->opts.checkout_strategy |= GIT_CHECKOUT_CONFLICT_STYLE_DIFF3; else { giterr_set(GITERR_CHECKOUT, "unknown style '%s' given for 'merge.conflictstyle'", conflict_style); error = -1; + git_config_entry_free(conflict_style); goto cleanup; } + git_config_entry_free(conflict_style); } if ((error = git_vector_init(&data->removes, 0, git__strcmp_cb)) < 0 || |