@@ -727,13 +727,15 @@ static void add_flattened_path(struct strbuf *out, const char *s)
727
727
out -> buf [i ] = '_' ;
728
728
}
729
729
730
- static char * unique_path (struct strmap * existing_paths ,
730
+ static char * unique_path (struct merge_options * opt ,
731
731
const char * path ,
732
732
const char * branch )
733
733
{
734
+ char * ret = NULL ;
734
735
struct strbuf newpath = STRBUF_INIT ;
735
736
int suffix = 0 ;
736
737
size_t base_len ;
738
+ struct strmap * existing_paths = & opt -> priv -> paths ;
737
739
738
740
strbuf_addf (& newpath , "%s~" , path );
739
741
add_flattened_path (& newpath , branch );
@@ -744,7 +746,11 @@ static char *unique_path(struct strmap *existing_paths,
744
746
strbuf_addf (& newpath , "_%d" , suffix ++ );
745
747
}
746
748
747
- return strbuf_detach (& newpath , NULL );
749
+ /* Track the new path in our memory pool */
750
+ ret = mem_pool_alloc (& opt -> priv -> pool , newpath .len + 1 );
751
+ memcpy (ret , newpath .buf , newpath .len + 1 );
752
+ strbuf_release (& newpath );
753
+ return ret ;
748
754
}
749
755
750
756
/*** Function Grouping: functions related to collect_merge_info() ***/
@@ -3091,12 +3097,11 @@ static int detect_and_process_renames(struct merge_options *opt,
3091
3097
struct tree * side1 ,
3092
3098
struct tree * side2 )
3093
3099
{
3094
- struct diff_queue_struct combined ;
3100
+ struct diff_queue_struct combined = { 0 } ;
3095
3101
struct rename_info * renames = & opt -> priv -> renames ;
3096
- int need_dir_renames , s , clean = 1 ;
3102
+ int need_dir_renames , s , i , clean = 1 ;
3097
3103
unsigned detection_run = 0 ;
3098
3104
3099
- memset (& combined , 0 , sizeof (combined ));
3100
3105
if (!possible_renames (renames ))
3101
3106
goto cleanup ;
3102
3107
@@ -3180,13 +3185,9 @@ static int detect_and_process_renames(struct merge_options *opt,
3180
3185
free (renames -> pairs [s ].queue );
3181
3186
DIFF_QUEUE_CLEAR (& renames -> pairs [s ]);
3182
3187
}
3183
- if (combined .nr ) {
3184
- int i ;
3185
- for (i = 0 ; i < combined .nr ; i ++ )
3186
- pool_diff_free_filepair (& opt -> priv -> pool ,
3187
- combined .queue [i ]);
3188
- free (combined .queue );
3189
- }
3188
+ for (i = 0 ; i < combined .nr ; i ++ )
3189
+ pool_diff_free_filepair (& opt -> priv -> pool , combined .queue [i ]);
3190
+ free (combined .queue );
3190
3191
3191
3192
return clean ;
3192
3193
}
@@ -3684,7 +3685,7 @@ static void process_entry(struct merge_options *opt,
3684
3685
*/
3685
3686
df_file_index = (ci -> dirmask & (1 << 1 )) ? 2 : 1 ;
3686
3687
branch = (df_file_index == 1 ) ? opt -> branch1 : opt -> branch2 ;
3687
- path = unique_path (& opt -> priv -> paths , path , branch );
3688
+ path = unique_path (opt , path , branch );
3688
3689
strmap_put (& opt -> priv -> paths , path , new_ci );
3689
3690
3690
3691
path_msg (opt , path , 0 ,
@@ -3809,14 +3810,12 @@ static void process_entry(struct merge_options *opt,
3809
3810
/* Insert entries into opt->priv_paths */
3810
3811
assert (rename_a || rename_b );
3811
3812
if (rename_a ) {
3812
- a_path = unique_path (& opt -> priv -> paths ,
3813
- path , opt -> branch1 );
3813
+ a_path = unique_path (opt , path , opt -> branch1 );
3814
3814
strmap_put (& opt -> priv -> paths , a_path , ci );
3815
3815
}
3816
3816
3817
3817
if (rename_b )
3818
- b_path = unique_path (& opt -> priv -> paths ,
3819
- path , opt -> branch2 );
3818
+ b_path = unique_path (opt , path , opt -> branch2 );
3820
3819
else
3821
3820
b_path = path ;
3822
3821
strmap_put (& opt -> priv -> paths , b_path , new_ci );
@@ -4204,15 +4203,14 @@ static int record_conflicted_index_entries(struct merge_options *opt)
4204
4203
struct stat st ;
4205
4204
4206
4205
if (!lstat (path , & st )) {
4207
- char * new_name = unique_path (& opt -> priv -> paths ,
4206
+ char * new_name = unique_path (opt ,
4208
4207
path ,
4209
4208
"cruft" );
4210
4209
4211
4210
path_msg (opt , path , 1 ,
4212
4211
_ ("Note: %s not up to date and in way of checking out conflicted version; old copy renamed to %s" ),
4213
4212
path , new_name );
4214
4213
errs |= rename (path , new_name );
4215
- free (new_name );
4216
4214
}
4217
4215
errs |= checkout_entry (ce , & state , NULL , NULL );
4218
4216
}
0 commit comments