Skip to content

Commit f5d9fbc

Browse files
newrengitster
authored andcommitted
merge-ort: initialize and free new directory rename data structures
Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c09376d commit f5d9fbc

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

merge-ort.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,12 @@ static void free_strmap_strings(struct strmap *map)
308308
static void clear_or_reinit_internal_opts(struct merge_options_internal *opti,
309309
int reinitialize)
310310
{
311+
struct rename_info *renames = &opti->renames;
312+
int i;
311313
void (*strmap_func)(struct strmap *, int) =
312314
reinitialize ? strmap_partial_clear : strmap_clear;
315+
void (*strset_func)(struct strset *) =
316+
reinitialize ? strset_partial_clear : strset_clear;
313317

314318
/*
315319
* 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,
339343
string_list_clear(&opti->paths_to_free, 0);
340344
opti->paths_to_free.strdup_strings = 0;
341345

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+
342363
if (!reinitialize) {
343364
struct hashmap_iter iter;
344365
struct strmap_entry *e;
@@ -1812,6 +1833,9 @@ static struct commit *make_virtual_commit(struct repository *repo,
18121833

18131834
static void merge_start(struct merge_options *opt, struct merge_result *result)
18141835
{
1836+
struct rename_info *renames;
1837+
int i;
1838+
18151839
/* Sanity checks on opt */
18161840
assert(opt->repo);
18171841

@@ -1846,6 +1870,17 @@ static void merge_start(struct merge_options *opt, struct merge_result *result)
18461870
/* Initialization of opt->priv, our internal merge data */
18471871
opt->priv = xcalloc(1, sizeof(*opt->priv));
18481872

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+
18491884
/*
18501885
* Although we initialize opt->priv->paths with strdup_strings=0,
18511886
* that's just to avoid making yet another copy of an allocated

0 commit comments

Comments
 (0)