| 2901 | /*** Function Grouping: functions related to regular rename detection ***/ |
| 2902 | |
| 2903 | static int process_renames(struct merge_options *opt, |
| 2904 | struct diff_queue_struct *renames) |
| 2905 | { |
| 2906 | int clean_merge = 1, i; |
| 2907 | |
| 2908 | for (i = 0; i < renames->nr; ++i) { |
| 2909 | const char *oldpath = NULL, *newpath; |
| 2910 | struct diff_filepair *pair = renames->queue[i]; |
| 2911 | struct conflict_info *oldinfo = NULL, *newinfo = NULL; |
| 2912 | struct strmap_entry *old_ent, *new_ent; |
| 2913 | unsigned int old_sidemask; |
| 2914 | int target_index, other_source_index; |
| 2915 | int source_deleted, collision, type_changed; |
| 2916 | const char *rename_branch = NULL, *delete_branch = NULL; |
| 2917 | |
| 2918 | old_ent = strmap_get_entry(&opt->priv->paths, pair->one->path); |
| 2919 | new_ent = strmap_get_entry(&opt->priv->paths, pair->two->path); |
| 2920 | if (old_ent) { |
| 2921 | oldpath = old_ent->key; |
| 2922 | oldinfo = old_ent->value; |
| 2923 | } |
| 2924 | newpath = pair->two->path; |
| 2925 | if (new_ent) { |
| 2926 | newpath = new_ent->key; |
| 2927 | newinfo = new_ent->value; |
| 2928 | } |
| 2929 | |
| 2930 | /* |
| 2931 | * Directory renames can result in rename-to-self; the code |
| 2932 | * below assumes we have A->B with different A & B, and tries |
| 2933 | * to move all entries to path B. If A & B are the same path, |
| 2934 | * the logic can get confused, so skip further processing when |
| 2935 | * A & B are already the same path. |
| 2936 | * |
| 2937 | * As a reminder, we can avoid strcmp here because all paths |
| 2938 | * are interned in opt->priv->paths; see the comment above |
| 2939 | * "paths" in struct merge_options_internal. |
| 2940 | */ |
| 2941 | if (oldpath == newpath) |
| 2942 | continue; |
| 2943 | |
| 2944 | /* |
| 2945 | * If pair->one->path isn't in opt->priv->paths, that means |
| 2946 | * that either directory rename detection removed that |
| 2947 | * path, or a parent directory of oldpath was resolved and |
| 2948 | * we don't even need the rename; in either case, we can |
| 2949 | * skip it. If oldinfo->merged.clean, then the other side |
| 2950 | * of history had no changes to oldpath and we don't need |
| 2951 | * the rename and can skip it. |
| 2952 | */ |
| 2953 | if (!oldinfo || oldinfo->merged.clean) |
| 2954 | continue; |
| 2955 | |
| 2956 | /* |
| 2957 | * diff_filepairs have copies of pathnames, thus we have to |
| 2958 | * use standard 'strcmp()' (negated) instead of '=='. |
| 2959 | */ |
| 2960 | if (i + 1 < renames->nr && |
no test coverage detected