merge-recursive: rename conflict_rename_*() family of functions

These functions were added because processing of these conflicts needed to be deferred until process_entry() in order to get D/F conflicts and such right. The number of these has grown over time, and now include some whose name is misleading: * conflict_rename_normal() is for handling normal file renames; a typical rename may need content merging, but we expect conflicts from that to be more the exception than the rule. * conflict_rename_via_dir() will not be a conflict; it was just an add that turned into a move due to directory rename detection. (If there was a file in the way of the move, that would have been detected and reported earlier.) * conflict_rename_rename_2to1 and conflict_rename_add (the latter of which doesn't exist yet but has been submitted before and I intend to resend) technically might not be conflicts if the colliding paths happen to match exactly. Rename this family of functions to handle_rename_*(). Also rename handle_renames() to detect_and_process_renames() both to make it clearer what it does, and to differentiate it as a pre-processing step from all the handle_rename_*() functions which are called from process_entry(). Acked-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Elijah Newren committed Jun 9, 2018 at 21:16 UTC 8ebe7b057ad866e027365526782cd2e42a0bd106
1 file changed +43 -43
merge-recursive.c
+43 -43
@@ -1410,10 +1410,10 @@ static int merge_file_one(struct merge_options *o,
1410 return merge_file_1(o, &one, &a, &b, path, branch1, branch2, mfi);
1411 }
1412
1413 -static int conflict_rename_via_dir(struct merge_options *o,
1414 - struct diff_filepair *pair,
1415 - const char *rename_branch,
1416 - const char *other_branch)
1413 +static int handle_rename_via_dir(struct merge_options *o,
1414 + struct diff_filepair *pair,
1415 + const char *rename_branch,
1416 + const char *other_branch)
1417 {
1418 /*
1419 * Handle file adds that need to be renamed due to directory rename
@@ -1515,10 +1515,10 @@ static int handle_change_delete(struct merge_options *o,
1515 return ret;
1516 }
1517
1518 -static int conflict_rename_delete(struct merge_options *o,
1519 - struct diff_filepair *pair,
1520 - const char *rename_branch,
1521 - const char *delete_branch)
1518 +static int handle_rename_delete(struct merge_options *o,
1519 + struct diff_filepair *pair,
1520 + const char *rename_branch,
1521 + const char *delete_branch)
1522 {
1523 const struct diff_filespec *orig = pair->one;
1524 const struct diff_filespec *dest = pair->two;
@@ -1620,8 +1620,8 @@ static int handle_file(struct merge_options *o,
1620 return ret;
1621 }
1622
1623 -static int conflict_rename_rename_1to2(struct merge_options *o,
1624 - struct rename_conflict_info *ci)
1623 +static int handle_rename_rename_1to2(struct merge_options *o,
1624 + struct rename_conflict_info *ci)
1625 {
1626 /* One file was renamed in both branches, but to different names. */
1627 struct diff_filespec *one = ci->pair1->one;
@@ -1682,8 +1682,8 @@ static int conflict_rename_rename_1to2(struct merge_options *o,
1682 return 0;
1683 }
1684
1685 -static int conflict_rename_rename_2to1(struct merge_options *o,
1686 - struct rename_conflict_info *ci)
1685 +static int handle_rename_rename_2to1(struct merge_options *o,
1686 + struct rename_conflict_info *ci)
1687 {
1688 /* Two files, a & b, were renamed to the same thing, c. */
1689 struct diff_filespec *a = ci->pair1->one;
@@ -2425,7 +2425,7 @@ static void apply_directory_rename_modifications(struct merge_options *o,
2425 * "NOTE" in update_stages(), doing so will modify the current
2426 * in-memory index which will break calls to would_lose_untracked()
2427 * that we need to make. Instead, we need to just make sure that
2428 - * the various conflict_rename_*() functions update the index
2428 + * the various handle_rename_*() functions update the index
2429 * explicitly rather than relying on unpack_trees() to have done it.
2430 */
2431 get_tree_entry(&tree->object.oid,
@@ -2829,12 +2829,12 @@ static void initial_cleanup_rename(struct diff_queue_struct *pairs,
2829 free(pairs);
2830 }
2831
2832 -static int handle_renames(struct merge_options *o,
2833 - struct tree *common,
2834 - struct tree *head,
2835 - struct tree *merge,
2836 - struct string_list *entries,
2837 - struct rename_info *ri)
2832 +static int detect_and_process_renames(struct merge_options *o,
2833 + struct tree *common,
2834 + struct tree *head,
2835 + struct tree *merge,
2836 + struct string_list *entries,
2837 + struct rename_info *ri)
2838 {
2839 struct diff_queue_struct *head_pairs, *merge_pairs;
2840 struct hashmap *dir_re_head, *dir_re_merge;
@@ -3105,12 +3105,12 @@ static int merge_content(struct merge_options *o,
3105 return !is_dirty && mfi.clean;
3106 }
3107
3108 -static int conflict_rename_normal(struct merge_options *o,
3109 - const char *path,
3110 - struct object_id *o_oid, unsigned int o_mode,
3111 - struct object_id *a_oid, unsigned int a_mode,
3112 - struct object_id *b_oid, unsigned int b_mode,
3113 - struct rename_conflict_info *ci)
3108 +static int handle_rename_normal(struct merge_options *o,
3109 + const char *path,
3110 + struct object_id *o_oid, unsigned int o_mode,
3111 + struct object_id *a_oid, unsigned int a_mode,
3112 + struct object_id *b_oid, unsigned int b_mode,
3113 + struct rename_conflict_info *ci)
3114 {
3115 /* Merge the content and write it out */
3116 return merge_content(o, path, was_dirty(o, path),
@@ -3137,37 +3137,37 @@ static int process_entry(struct merge_options *o,
3137 switch (conflict_info->rename_type) {
3138 case RENAME_NORMAL:
3139 case RENAME_ONE_FILE_TO_ONE:
3140 - clean_merge = conflict_rename_normal(o,
3141 - path,
3142 - o_oid, o_mode,
3143 - a_oid, a_mode,
3144 - b_oid, b_mode,
3145 - conflict_info);
3140 + clean_merge = handle_rename_normal(o,
3141 + path,
3142 + o_oid, o_mode,
3143 + a_oid, a_mode,
3144 + b_oid, b_mode,
3145 + conflict_info);
3146 break;
3147 case RENAME_VIA_DIR:
3148 clean_merge = 1;
3149 - if (conflict_rename_via_dir(o,
3150 - conflict_info->pair1,
3151 - conflict_info->branch1,
3152 - conflict_info->branch2))
3149 + if (handle_rename_via_dir(o,
3150 + conflict_info->pair1,
3151 + conflict_info->branch1,
3152 + conflict_info->branch2))
3153 clean_merge = -1;
3154 break;
3155 case RENAME_DELETE:
3156 clean_merge = 0;
3157 - if (conflict_rename_delete(o,
3158 - conflict_info->pair1,
3159 - conflict_info->branch1,
3160 - conflict_info->branch2))
3157 + if (handle_rename_delete(o,
3158 + conflict_info->pair1,
3159 + conflict_info->branch1,
3160 + conflict_info->branch2))
3161 clean_merge = -1;
3162 break;
3163 case RENAME_ONE_FILE_TO_TWO:
3164 clean_merge = 0;
3165 - if (conflict_rename_rename_1to2(o, conflict_info))
3165 + if (handle_rename_rename_1to2(o, conflict_info))
3166 clean_merge = -1;
3167 break;
3168 case RENAME_TWO_FILES_TO_ONE:
3169 clean_merge = 0;
3170 - if (conflict_rename_rename_2to1(o, conflict_info))
3170 + if (handle_rename_rename_2to1(o, conflict_info))
3171 clean_merge = -1;
3172 break;
3173 default:
@@ -3307,8 +3307,8 @@ int merge_trees(struct merge_options *o,
3307 get_files_dirs(o, merge);
3308
3309 entries = get_unmerged();
3310 - clean = handle_renames(o, common, head, merge, entries,
3311 - &re_info);
3310 + clean = detect_and_process_renames(o, common, head, merge,
3311 + entries, &re_info);
3312 record_df_conflict_files(o, entries);
3313 if (clean < 0)
3314 goto cleanup;