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 <newren@palantir.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Elijah Newren committed
Jul 5, 2022 at 01:33 UTC
6dd1f0e9d446e9ec1da3583eb7d6959716fc31f6
1 file changed
+22
-16
merge-ort.c
+22
-16
@@ -2259,6 +2259,27 @@ static void compute_collisions(struct strmap *collisions,
2259
}
2260
}
2261
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
+
2283
static char *check_for_directory_rename(struct merge_options *opt,
2284
const char *path,
2285
unsigned side_index,
@@ -3029,8 +3050,6 @@ static int collect_renames(struct merge_options *opt,
3050
int i, clean = 1;
3051
struct strmap collisions;
3052
struct diff_queue_struct *side_pairs;
3032
- struct hashmap_iter iter;
3033
- struct strmap_entry *entry;
3053
struct rename_info *renames = &opt->priv->renames;
3054
3055
side_pairs = &renames->pairs[side_index];
@@ -3076,20 +3095,7 @@ static int collect_renames(struct merge_options *opt,
3095
result->queue[result->nr++] = p;
3096
}
3097
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);
3099
return clean;
3100
}
3101