summaryrefslogtreecommitdiff
path: root/checkout.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2020-08-17 21:33:11 (GMT)
committerJunio C Hamano <gitster@pobox.com>2020-08-17 22:35:47 (GMT)
commit9a53219f69bd470053cf93c3f4d2a77b6d4df3e5 (patch)
treeff39cbe8ca9dd05153de81b7af1c70b6e63b3d7d /checkout.c
parentf1de981e8b6dedccf915095792c9afbe3c989591 (diff)
downloadgit-9a53219f69bd470053cf93c3f4d2a77b6d4df3e5.zip
git-9a53219f69bd470053cf93c3f4d2a77b6d4df3e5.tar.gz
git-9a53219f69bd470053cf93c3f4d2a77b6d4df3e5.tar.bz2
config: drop git_config_get_string_const()
As evidenced by the leak fixes in the previous commit, the "const" in git_config_get_string_const() clearly misleads people into thinking that it does not allocate a copy of the string. We can fix this by renaming it, but it's easier still to just drop it. Of the four remaining callers: - The one in git_config_parse_expiry() still needs to allocate, since that's what its callers expect. We can just use the non-const version and cast our pointer. Slightly ugly, but the damage is contained in one spot. - The two in apply are writing to global "const char *" variables, and need to continue allocating. We often mark these as const because we assign default string literals to them. But in this case we don't do that, so we can just declare them as real "char *" pointers and use the non-const version. - The call in checkout doesn't actually need a copy; it can just use the non-allocating "tmp" version of the function. The function is also mentioned in the MyFirstContribution document. We can swap that call out for the non-allocating "tmp" variant, which fits well in the example given. We'll drop the "configset" and "repo" variants, as well (which are unused). Note that this frees up the "const" name, so we could rename the "tmp" variant back to that. But let's give some time for topics in flight to adapt to the new code before doing so (if we do it too soon, the function semantics will change but the compiler won't alert us). Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'checkout.c')
-rw-r--r--checkout.c3
1 files changed, 1 insertions, 2 deletions
diff --git a/checkout.c b/checkout.c
index c72e9f9..6586e30 100644
--- a/checkout.c
+++ b/checkout.c
@@ -47,7 +47,7 @@ const char *unique_tracking_name(const char *name, struct object_id *oid,
{
struct tracking_name_data cb_data = TRACKING_NAME_DATA_INIT;
const char *default_remote = NULL;
- if (!git_config_get_string_const("checkout.defaultremote", &default_remote))
+ if (!git_config_get_string_tmp("checkout.defaultremote", &default_remote))
cb_data.default_remote = default_remote;
cb_data.src_ref = xstrfmt("refs/heads/%s", name);
cb_data.dst_oid = oid;
@@ -55,7 +55,6 @@ const char *unique_tracking_name(const char *name, struct object_id *oid,
if (dwim_remotes_matched)
*dwim_remotes_matched = cb_data.num_matches;
free(cb_data.src_ref);
- free((char *)default_remote);
if (cb_data.num_matches == 1) {
free(cb_data.default_dst_ref);
free(cb_data.default_dst_oid);