merge-recursive.c: use string_list_sort instead of qsort
Merge-recursive sorts a string list using a raw qsort(), where it feeds the "items" from one struct but the "nr" and size fields from another struct. This isn't a bug because one list is a copy of the other, but it's unnecessarily confusing (and also caused our recent QSORT() cleanups via coccinelle to miss this call site). Let's use string_list_sort() instead, which is more concise and harder to get wrong. Note that we need to adjust our comparison function, which gets fed only the strings now, not the string_list_items. That's OK because we don't use the "util" field as part of our sort. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Nguyễn Thái Ngọc Duy committed
Nov 24, 2016 at 18:45 UTC
fa6ca11105ccb46b785fd4ed58c333d5ad7f1774
1 file changed
+7
-9
merge-recursive.c
+7
-9
@@ -388,12 +388,10 @@ static struct string_list *get_unmerged(void)
388
return unmerged;
389
}
390
391
-static int string_list_df_name_compare(const void *a, const void *b)
391
+static int string_list_df_name_compare(const char *one, const char *two)
392
{
393
- const struct string_list_item *one = a;
394
- const struct string_list_item *two = b;
395
- int onelen = strlen(one->string);
396
- int twolen = strlen(two->string);
393
+ int onelen = strlen(one);
394
+ int twolen = strlen(two);
395
/*
396
* Here we only care that entries for D/F conflicts are
397
* adjacent, in particular with the file of the D/F conflict
@@ -406,8 +404,8 @@ static int string_list_df_name_compare(const void *a, const void *b)
404
* since in other cases any changes in their order due to
405
* sorting cause no problems for us.
406
*/
409
- int cmp = df_name_compare(one->string, onelen, S_IFDIR,
410
- two->string, twolen, S_IFDIR);
407
+ int cmp = df_name_compare(one, onelen, S_IFDIR,
408
+ two, twolen, S_IFDIR);
409
/*
410
* Now that 'foo' and 'foo/bar' compare equal, we have to make sure
411
* that 'foo' comes before 'foo/bar'.
@@ -451,8 +449,8 @@ static void record_df_conflict_files(struct merge_options *o,
449
string_list_append(&df_sorted_entries, next->string)->util =
450
next->util;
451
}
454
- qsort(df_sorted_entries.items, entries->nr, sizeof(*entries->items),
455
- string_list_df_name_compare);
452
+ df_sorted_entries.cmp = string_list_df_name_compare;
453
+ string_list_sort(&df_sorted_entries);
454
455
string_list_clear(&o->df_conflict_file_set, 1);
456
for (i = 0; i < df_sorted_entries.nr; i++) {