Skip to content

Commit 6dd1f0e

Browse files
newrengitster
authored andcommitted
merge-ort: make a separate function for freeing struct collisions
This commit makes no functional changes, it's just some code movement in preparation for later changes. Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 51e41e4 commit 6dd1f0e

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

merge-ort.c

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2259,6 +2259,27 @@ static void compute_collisions(struct strmap *collisions,
22592259
}
22602260
}
22612261

2262+
static void free_collisions(struct strmap *collisions)
2263+
{
2264+
struct hashmap_iter iter;
2265+
struct strmap_entry *entry;
2266+
2267+
/* Free each value in the collisions map */
2268+
strmap_for_each_entry(collisions, &iter, entry) {
2269+
struct collision_info *info = entry->value;
2270+
string_list_clear(&info->source_files, 0);
2271+
}
2272+
/*
2273+
* In compute_collisions(), we set collisions.strdup_strings to 0
2274+
* so that we wouldn't have to make another copy of the new_path
2275+
* allocated by apply_dir_rename(). But now that we've used them
2276+
* and have no other references to these strings, it is time to
2277+
* deallocate them.
2278+
*/
2279+
free_strmap_strings(collisions);
2280+
strmap_clear(collisions, 1);
2281+
}
2282+
22622283
static char *check_for_directory_rename(struct merge_options *opt,
22632284
const char *path,
22642285
unsigned side_index,
@@ -3029,8 +3050,6 @@ static int collect_renames(struct merge_options *opt,
30293050
int i, clean = 1;
30303051
struct strmap collisions;
30313052
struct diff_queue_struct *side_pairs;
3032-
struct hashmap_iter iter;
3033-
struct strmap_entry *entry;
30343053
struct rename_info *renames = &opt->priv->renames;
30353054

30363055
side_pairs = &renames->pairs[side_index];
@@ -3076,20 +3095,7 @@ static int collect_renames(struct merge_options *opt,
30763095
result->queue[result->nr++] = p;
30773096
}
30783097

3079-
/* Free each value in the collisions map */
3080-
strmap_for_each_entry(&collisions, &iter, entry) {
3081-
struct collision_info *info = entry->value;
3082-
string_list_clear(&info->source_files, 0);
3083-
}
3084-
/*
3085-
* In compute_collisions(), we set collisions.strdup_strings to 0
3086-
* so that we wouldn't have to make another copy of the new_path
3087-
* allocated by apply_dir_rename(). But now that we've used them
3088-
* and have no other references to these strings, it is time to
3089-
* deallocate them.
3090-
*/
3091-
free_strmap_strings(&collisions);
3092-
strmap_clear(&collisions, 1);
3098+
free_collisions(&collisions);
30933099
return clean;
30943100
}
30953101

0 commit comments

Comments
 (0)