]> git.ipfire.org Git - thirdparty/git.git/commitdiff
repository.c: free the "path cache" in repo_clear()
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>
Fri, 4 Mar 2022 18:32:17 +0000 (19:32 +0100)
committerJunio C Hamano <gitster@pobox.com>
Fri, 4 Mar 2022 21:24:19 +0000 (13:24 -0800)
The "struct path_cache" added in 102de880d24 (path.c: migrate global
git_path_* to take a repository argument, 2018-05-17) is only used
directly by code in repository.[ch] (but populated in path.[ch]).

Let's move this code to repository.[ch], and stop leaking this memory
when we run repo_clear(). To avoid the cast change it from a "const
char *" to a "char *".

This also removes the "PATH_CACHE_INIT" macro, which has never been
used for anything. For the "struct repository" we already make a hard
assumption that it (and "the_repository") can be identically
initialized by making it a "static" variable, so making use of a
"PATH_CACHE_INIT" somewhere would have been confusing.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
path.h
repository.c
repository.h

diff --git a/path.h b/path.h
index b68691a86b80417a82e5124aef37b9c8a9a02c95..0a59c85a62eda03acd290fa564b7e197288e26ad 100644 (file)
--- a/path.h
+++ b/path.h
@@ -169,20 +169,6 @@ void report_linked_checkout_garbage(void);
                return r->cached_paths.var; \
        }
 
-struct path_cache {
-       const char *squash_msg;
-       const char *merge_msg;
-       const char *merge_rr;
-       const char *merge_mode;
-       const char *merge_head;
-       const char *merge_autostash;
-       const char *auto_merge;
-       const char *fetch_head;
-       const char *shallow;
-};
-
-#define PATH_CACHE_INIT { 0 }
-
 const char *git_path_squash_msg(struct repository *r);
 const char *git_path_merge_msg(struct repository *r);
 const char *git_path_merge_rr(struct repository *r);
index 34610c5a33e013169de14189274fd4ed42512a96..9b86f3f121495bb4e2a7138c6d5868e806836520 100644 (file)
@@ -240,6 +240,20 @@ out:
        return ret;
 }
 
+static void repo_clear_path_cache(struct repo_path_cache *cache)
+{
+       FREE_AND_NULL(cache->squash_msg);
+       FREE_AND_NULL(cache->squash_msg);
+       FREE_AND_NULL(cache->merge_msg);
+       FREE_AND_NULL(cache->merge_rr);
+       FREE_AND_NULL(cache->merge_mode);
+       FREE_AND_NULL(cache->merge_head);
+       FREE_AND_NULL(cache->merge_autostash);
+       FREE_AND_NULL(cache->auto_merge);
+       FREE_AND_NULL(cache->fetch_head);
+       FREE_AND_NULL(cache->shallow);
+}
+
 void repo_clear(struct repository *repo)
 {
        FREE_AND_NULL(repo->gitdir);
@@ -280,6 +294,8 @@ void repo_clear(struct repository *repo)
                remote_state_clear(repo->remote_state);
                FREE_AND_NULL(repo->remote_state);
        }
+
+       repo_clear_path_cache(&repo->cached_paths);
 }
 
 int repo_read_index(struct repository *repo)
index ca837cb9e914aaaf85c39f323ae671ab4eb8c8cb..e29f361703d2b37dd8b8121d88a26bebe88e070b 100644 (file)
@@ -44,6 +44,18 @@ struct repo_settings {
        int core_multi_pack_index;
 };
 
+struct repo_path_cache {
+       char *squash_msg;
+       char *merge_msg;
+       char *merge_rr;
+       char *merge_mode;
+       char *merge_head;
+       char *merge_autostash;
+       char *auto_merge;
+       char *fetch_head;
+       char *shallow;
+};
+
 struct repository {
        /* Environment */
        /*
@@ -82,7 +94,7 @@ struct repository {
        /*
         * Contains path to often used file names.
         */
-       struct path_cache cached_paths;
+       struct repo_path_cache cached_paths;
 
        /*
         * Path to the repository's graft file.