config: fix constness of out parameter for git_config_get_expiry()

The type of the out parameter of `git_config_get_expiry()` is a pointer
to a constant string, which creates the impression that ownership of the
returned data wasn't transferred to the caller. This isn't true though
and thus quite misleading.

Adapt the parameter to be of type `char **` and adjust callers
accordingly. While at it, refactor `get_shared_index_expire_date()` to
drop the static `shared_index_expire` variable. It is only used in that
function, and furthermore we would only hit the code where we parse the
expiry date a single time because we already use a static `prepared`
variable to track whether we did parse it.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Patrick Steinhardt
2024-08-16 12:44:57 +02:00
committed by Junio C Hamano
parent 25673b1c47
commit a70a9bf6ee
4 changed files with 15 additions and 9 deletions

View File

@ -3176,18 +3176,24 @@ static int write_split_index(struct index_state *istate,
return ret;
}
static const char *shared_index_expire = "2.weeks.ago";
static unsigned long get_shared_index_expire_date(void)
{
static unsigned long shared_index_expire_date;
static int shared_index_expire_date_prepared;
if (!shared_index_expire_date_prepared) {
const char *shared_index_expire = "2.weeks.ago";
char *value = NULL;
git_config_get_expiry("splitindex.sharedindexexpire",
&shared_index_expire);
&value);
if (value)
shared_index_expire = value;
shared_index_expire_date = approxidate(shared_index_expire);
shared_index_expire_date_prepared = 1;
free(value);
}
return shared_index_expire_date;