merge-ort: initialize and free new directory rename data structures
Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Elijah Newren committed
Jan 7, 2021 at 21:35 UTC
f5d9fbc2e9fde9a9dc08de12ad5ed0c6d7e3fb0a
1 file changed
+35
merge-ort.c
+35
@@ -308,8 +308,12 @@ static void free_strmap_strings(struct strmap *map)
308
static void clear_or_reinit_internal_opts(struct merge_options_internal *opti,
309
int reinitialize)
310
{
311
+ struct rename_info *renames = &opti->renames;
312
+ int i;
313
void (*strmap_func)(struct strmap *, int) =
314
reinitialize ? strmap_partial_clear : strmap_clear;
315
+ void (*strset_func)(struct strset *) =
316
+ reinitialize ? strset_partial_clear : strset_clear;
317
318
/*
319
* 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,
343
string_list_clear(&opti->paths_to_free, 0);
344
opti->paths_to_free.strdup_strings = 0;
345
346
+ /* Free memory used by various renames maps */
347
+ for (i = MERGE_SIDE1; i <= MERGE_SIDE2; ++i) {
348
+ struct hashmap_iter iter;
349
+ struct strmap_entry *entry;
350
+
351
+ strset_func(&renames->dirs_removed[i]);
352
+
353
+ strmap_for_each_entry(&renames->dir_rename_count[i],
354
+ &iter, entry) {
355
+ struct strintmap *counts = entry->value;
356
+ strintmap_clear(counts);
357
+ }
358
+ strmap_func(&renames->dir_rename_count[i], 1);
359
+
360
+ strmap_func(&renames->dir_renames[i], 0);
361
+ }
362
+
363
if (!reinitialize) {
364
struct hashmap_iter iter;
365
struct strmap_entry *e;
@@ -1812,6 +1833,9 @@ static struct commit *make_virtual_commit(struct repository *repo,
1833
1834
static void merge_start(struct merge_options *opt, struct merge_result *result)
1835
{
1836
+ struct rename_info *renames;
1837
+ int i;
1838
+
1839
/* Sanity checks on opt */
1840
assert(opt->repo);
1841
@@ -1846,6 +1870,17 @@ static void merge_start(struct merge_options *opt, struct merge_result *result)
1870
/* Initialization of opt->priv, our internal merge data */
1871
opt->priv = xcalloc(1, sizeof(*opt->priv));
1872
1873
+ /* Initialization of various renames fields */
1874
+ renames = &opt->priv->renames;
1875
+ for (i = MERGE_SIDE1; i <= MERGE_SIDE2; i++) {
1876
+ strset_init_with_options(&renames->dirs_removed[i],
1877
+ NULL, 0);
1878
+ strmap_init_with_options(&renames->dir_rename_count[i],
1879
+ NULL, 1);
1880
+ strmap_init_with_options(&renames->dir_renames[i],
1881
+ NULL, 0);
1882
+ }
1883
+
1884
/*
1885
* Although we initialize opt->priv->paths with strdup_strings=0,
1886
* that's just to avoid making yet another copy of an allocated