]> git.ipfire.org Git - thirdparty/git.git/commitdiff
config: fix constness of out parameter for `git_config_get_expiry()`
authorPatrick Steinhardt <ps@pks.im>
Fri, 16 Aug 2024 10:44:57 +0000 (12:44 +0200)
committerJunio C Hamano <gitster@pobox.com>
Fri, 16 Aug 2024 16:46:24 +0000 (09:46 -0700)
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>
builtin/gc.c
config.c
config.h
read-cache.c

index 72bac2554fc4b9c26140cdfc10100db6b5dd6774..e7406bf667b3d94021c7307f625cf9f7d88d61be 100644 (file)
@@ -167,9 +167,9 @@ static void gc_config(void)
        git_config_get_bool("gc.autodetach", &detach_auto);
        git_config_get_bool("gc.cruftpacks", &cruft_packs);
        git_config_get_ulong("gc.maxcruftsize", &max_cruft_size);
-       git_config_get_expiry("gc.pruneexpire", &prune_expire);
-       git_config_get_expiry("gc.worktreepruneexpire", &prune_worktrees_expire);
-       git_config_get_expiry("gc.logexpiry", &gc_log_expire);
+       git_config_get_expiry("gc.pruneexpire", (char **) &prune_expire);
+       git_config_get_expiry("gc.worktreepruneexpire", (char **) &prune_worktrees_expire);
+       git_config_get_expiry("gc.logexpiry", (char **) &gc_log_expire);
 
        git_config_get_ulong("gc.bigpackthreshold", &big_pack_threshold);
        git_config_get_ulong("pack.deltacachesize", &max_delta_cache_size);
index 6421894614092428780e80b57d2d3f0ca21c975c..dfa4df1417992c7716048e5218c10f4a08edfadf 100644 (file)
--- a/config.c
+++ b/config.c
@@ -2766,9 +2766,9 @@ int git_config_get_pathname(const char *key, char **dest)
        return repo_config_get_pathname(the_repository, key, dest);
 }
 
-int git_config_get_expiry(const char *key, const char **output)
+int git_config_get_expiry(const char *key, char **output)
 {
-       int ret = git_config_get_string(key, (char **)output);
+       int ret = git_config_get_string(key, output);
        if (ret)
                return ret;
        if (strcmp(*output, "now")) {
index 54b47dec9e2709ee958c9e3d70e67eddec07944e..4801391c32ca5e953c5d44edc22ed7d1967dff0c 100644 (file)
--- a/config.h
+++ b/config.h
@@ -701,7 +701,7 @@ int git_config_get_split_index(void);
 int git_config_get_max_percent_split_change(void);
 
 /* This dies if the configured or default date is in the future */
-int git_config_get_expiry(const char *key, const char **output);
+int git_config_get_expiry(const char *key, char **output);
 
 /* parse either "this many days" integer, or "5.days.ago" approxidate */
 int git_config_get_expiry_in_days(const char *key, timestamp_t *, timestamp_t now);
index 48bf24f87c00c15e5a4b249b26eabc624546f901..7f393ee687dd8ad72b4e5c2caf94e12bf3f92022 100644 (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;