Skip to content

Commit a70a9bf

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 25673b1 commit a70a9bf

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed

builtin/gc.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,9 @@ static void gc_config(void)
167167
git_config_get_bool("gc.autodetach", &detach_auto);
168168
git_config_get_bool("gc.cruftpacks", &cruft_packs);
169169
git_config_get_ulong("gc.maxcruftsize", &max_cruft_size);
170-
git_config_get_expiry("gc.pruneexpire", &prune_expire);
171-
git_config_get_expiry("gc.worktreepruneexpire", &prune_worktrees_expire);
172-
git_config_get_expiry("gc.logexpiry", &gc_log_expire);
170+
git_config_get_expiry("gc.pruneexpire", (char **) &prune_expire);
171+
git_config_get_expiry("gc.worktreepruneexpire", (char **) &prune_worktrees_expire);
172+
git_config_get_expiry("gc.logexpiry", (char **) &gc_log_expire);
173173

174174
git_config_get_ulong("gc.bigpackthreshold", &big_pack_threshold);
175175
git_config_get_ulong("pack.deltacachesize", &max_delta_cache_size);

config.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2766,9 +2766,9 @@ int git_config_get_pathname(const char *key, char **dest)
27662766
return repo_config_get_pathname(the_repository, key, dest);
27672767
}
27682768

2769-
int git_config_get_expiry(const char *key, const char **output)
2769+
int git_config_get_expiry(const char *key, char **output)
27702770
{
2771-
int ret = git_config_get_string(key, (char **)output);
2771+
int ret = git_config_get_string(key, output);
27722772
if (ret)
27732773
return ret;
27742774
if (strcmp(*output, "now")) {

config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,7 @@ int git_config_get_split_index(void);
701701
int git_config_get_max_percent_split_change(void);
702702

703703
/* This dies if the configured or default date is in the future */
704-
int git_config_get_expiry(const char *key, const char **output);
704+
int git_config_get_expiry(const char *key, char **output);
705705

706706
/* parse either "this many days" integer, or "5.days.ago" approxidate */
707707
int git_config_get_expiry_in_days(const char *key, timestamp_t *, timestamp_t now);

read-cache.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3176,18 +3176,24 @@ static int write_split_index(struct index_state *istate,
31763176
return ret;
31773177
}
31783178

3179-
static const char *shared_index_expire = "2.weeks.ago";
3180-
31813179
static unsigned long get_shared_index_expire_date(void)
31823180
{
31833181
static unsigned long shared_index_expire_date;
31843182
static int shared_index_expire_date_prepared;
31853183

31863184
if (!shared_index_expire_date_prepared) {
3185+
const char *shared_index_expire = "2.weeks.ago";
3186+
char *value = NULL;
3187+
31873188
git_config_get_expiry("splitindex.sharedindexexpire",
3188-
&shared_index_expire);
3189+
&value);
3190+
if (value)
3191+
shared_index_expire = value;
3192+
31893193
shared_index_expire_date = approxidate(shared_index_expire);
31903194
shared_index_expire_date_prepared = 1;
3195+
3196+
free(value);
31913197
}
31923198

31933199
return shared_index_expire_date;

0 commit comments

Comments
 (0)