]> git.ipfire.org Git - thirdparty/git.git/commitdiff
merge-ort: initialize and free new directory rename data structures
authorElijah Newren <newren@gmail.com>
Thu, 7 Jan 2021 21:35:50 +0000 (21:35 +0000)
committerJunio C Hamano <gitster@pobox.com>
Thu, 7 Jan 2021 23:30:03 +0000 (15:30 -0800)
Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
merge-ort.c

index 652ff730afa7d17f8b1dfa69220aa6caac486060..2e6d41b0a0f43cb0b206fca26ac8da6402fa4cae 100644 (file)
@@ -308,8 +308,12 @@ static void free_strmap_strings(struct strmap *map)
 static void clear_or_reinit_internal_opts(struct merge_options_internal *opti,
                                          int reinitialize)
 {
+       struct rename_info *renames = &opti->renames;
+       int i;
        void (*strmap_func)(struct strmap *, int) =
                reinitialize ? strmap_partial_clear : strmap_clear;
+       void (*strset_func)(struct strset *) =
+               reinitialize ? strset_partial_clear : strset_clear;
 
        /*
         * We marked opti->paths with strdup_strings = 0, so that we
@@ -339,6 +343,23 @@ static void clear_or_reinit_internal_opts(struct merge_options_internal *opti,
        string_list_clear(&opti->paths_to_free, 0);
        opti->paths_to_free.strdup_strings = 0;
 
+       /* Free memory used by various renames maps */
+       for (i = MERGE_SIDE1; i <= MERGE_SIDE2; ++i) {
+               struct hashmap_iter iter;
+               struct strmap_entry *entry;
+
+               strset_func(&renames->dirs_removed[i]);
+
+               strmap_for_each_entry(&renames->dir_rename_count[i],
+                                     &iter, entry) {
+                       struct strintmap *counts = entry->value;
+                       strintmap_clear(counts);
+               }
+               strmap_func(&renames->dir_rename_count[i], 1);
+
+               strmap_func(&renames->dir_renames[i], 0);
+       }
+
        if (!reinitialize) {
                struct hashmap_iter iter;
                struct strmap_entry *e;
@@ -1812,6 +1833,9 @@ static struct commit *make_virtual_commit(struct repository *repo,
 
 static void merge_start(struct merge_options *opt, struct merge_result *result)
 {
+       struct rename_info *renames;
+       int i;
+
        /* Sanity checks on opt */
        assert(opt->repo);
 
@@ -1846,6 +1870,17 @@ static void merge_start(struct merge_options *opt, struct merge_result *result)
        /* Initialization of opt->priv, our internal merge data */
        opt->priv = xcalloc(1, sizeof(*opt->priv));
 
+       /* Initialization of various renames fields */
+       renames = &opt->priv->renames;
+       for (i = MERGE_SIDE1; i <= MERGE_SIDE2; i++) {
+               strset_init_with_options(&renames->dirs_removed[i],
+                                        NULL, 0);
+               strmap_init_with_options(&renames->dir_rename_count[i],
+                                        NULL, 1);
+               strmap_init_with_options(&renames->dir_renames[i],
+                                        NULL, 0);
+       }
+
        /*
         * Although we initialize opt->priv->paths with strdup_strings=0,
         * that's just to avoid making yet another copy of an allocated