merge-recursive: Don't re-sort a list whose order we depend upon

In record_df_conflict_files() we would resort the entries list using df_name_compare to get a convenient ordering. Unfortunately, this broke assumptions of the get_renames() code (via string_list_lookup() calls) which needed the list to be in the standard ordering. When those lookups would fail, duplicate stage_data entries could be inserted, causing the process_renames and process_entry code to fail (in particular, a path that that process_renames had marked as processed would still be processed anyway in process_entry due to the duplicate entry). Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Elijah Newren committed Aug 12, 2011 at 20:23 UTC f701aae0774f4517b46dd866812c269c78f1e198
1 file changed +12 -4
merge-recursive.c
+12 -4
@@ -400,6 +400,7 @@ static void record_df_conflict_files(struct merge_options *o,
400 * and the file need to be present, then the D/F file will be
401 * reinstated with a new unique name at the time it is processed.
402 */
403 + struct string_list df_sorted_entries;
404 const char *last_file = NULL;
405 int last_len = 0;
406 int i;
@@ -412,14 +413,20 @@ static void record_df_conflict_files(struct merge_options *o,
413 return;
414
415 /* Ensure D/F conflicts are adjacent in the entries list. */
415 - qsort(entries->items, entries->nr, sizeof(*entries->items),
416 + memset(&df_sorted_entries, 0, sizeof(struct string_list));
417 + for (i = 0; i < entries->nr; i++) {
418 + struct string_list_item *next = &entries->items[i];
419 + string_list_append(&df_sorted_entries, next->string)->util =
420 + next->util;
421 + }
422 + qsort(df_sorted_entries.items, entries->nr, sizeof(*entries->items),
423 string_list_df_name_compare);
424
425 string_list_clear(&o->df_conflict_file_set, 1);
419 - for (i = 0; i < entries->nr; i++) {
420 - const char *path = entries->items[i].string;
426 + for (i = 0; i < df_sorted_entries.nr; i++) {
427 + const char *path = df_sorted_entries.items[i].string;
428 int len = strlen(path);
422 - struct stage_data *e = entries->items[i].util;
429 + struct stage_data *e = df_sorted_entries.items[i].util;
430
431 /*
432 * Check if last_file & path correspond to a D/F conflict;
@@ -447,6 +454,7 @@ static void record_df_conflict_files(struct merge_options *o,
454 last_file = NULL;
455 }
456 }
457 + string_list_clear(&df_sorted_entries, 0);
458 }
459
460 struct rename {