@matheusbsbs / matheus-bagliano / commits / 0ef95f72f8
Fork 0

pack-objects: free preferred base memory after usage

When adding objects for preferred delta base, the content from tree objects leading to given paths is kept in a cache. This has the potential to grow significantly, especially with large directories as the whole tree object content is loaded in memory, even if in practice the number of those objects is limited to the 256 cache entries plus the $window root tree objects. Still, that can't hurt freeing that up after object enumeration is done, and before more memory is needed for delta search. Signed-off-by: Nicolas Pitre <nico@cam.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nicolas Pitre committed Sep 3, 2009 at 21:54 UTC 0ef95f72f878184fbce8d7c855ab4346c081abed
1 file changed +28
builtin-pack-objects.c
+28
@@ -1012,6 +1012,33 @@ static void add_preferred_base(unsigned char *sha1)
1012 it->pcache.tree_size = size;
1013 }
1014
1015 +static void cleanup_preferred_base(void)
1016 +{
1017 + struct pbase_tree *it;
1018 + unsigned i;
1019 +
1020 + it = pbase_tree;
1021 + pbase_tree = NULL;
1022 + while (it) {
1023 + struct pbase_tree *this = it;
1024 + it = this->next;
1025 + free(this->pcache.tree_data);
1026 + free(this);
1027 + }
1028 +
1029 + for (i = 0; i < ARRAY_SIZE(pbase_tree_cache); i++) {
1030 + if (!pbase_tree_cache[i])
1031 + continue;
1032 + free(pbase_tree_cache[i]->tree_data);
1033 + free(pbase_tree_cache[i]);
1034 + pbase_tree_cache[i] = NULL;
1035 + }
1036 +
1037 + free(done_pbase_paths);
1038 + done_pbase_paths = NULL;
1039 + done_pbase_paths_num = done_pbase_paths_alloc = 0;
1040 +}
1041 +
1042 static void check_object(struct object_entry *entry)
1043 {
1044 if (entry->in_pack) {
@@ -2308,6 +2335,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
2335 rp_av[rp_ac] = NULL;
2336 get_object_list(rp_ac, rp_av);
2337 }
2338 + cleanup_preferred_base();
2339 if (include_tag && nr_result)
2340 for_each_ref(add_ref_tag, NULL);
2341 stop_progress(&progress_state);