merge-recursive: use xstrdup() instead of fixed buffer
[gitweb.git] / merge-recursive.c
index 03ff67bf8f2627ceae84bf8b83ab93de97f3a783..7ea70c4a9d11dea43ebdad1ba8718410793c263a 100644 (file)
@@ -1938,18 +1938,18 @@ static struct hashmap *get_directory_renames(struct diff_queue_struct *pairs,
 static struct dir_rename_entry *check_dir_renamed(const char *path,
                                                  struct hashmap *dir_renames)
 {
-       char temp[PATH_MAX];
+       char *temp = xstrdup(path);
        char *end;
-       struct dir_rename_entry *entry;
+       struct dir_rename_entry *entry = NULL;;
 
-       strcpy(temp, path);
        while ((end = strrchr(temp, '/'))) {
                *end = '\0';
                entry = dir_rename_find_entry(dir_renames, temp);
                if (entry)
-                       return entry;
+                       break;
        }
-       return NULL;
+       free(temp);
+       return entry;
 }
 
 static void compute_collisions(struct hashmap *collisions,
@@ -1982,7 +1982,7 @@ static void compute_collisions(struct hashmap *collisions,
                char *new_path;
                struct diff_filepair *pair = pairs->queue[i];
 
-               if (pair->status == 'D')
+               if (pair->status != 'A' && pair->status != 'R')
                        continue;
                dir_rename_ent = check_dir_renamed(pair->two->path,
                                                   dir_renames);
@@ -2209,7 +2209,7 @@ static struct string_list *get_renames(struct merge_options *o,
                struct diff_filepair *pair = pairs->queue[i];
                char *new_path; /* non-NULL only with directory renames */
 
-               if (pair->status == 'D') {
+               if (pair->status != 'A' && pair->status != 'R') {
                        diff_free_filepair(pair);
                        continue;
                }
@@ -2763,7 +2763,6 @@ static int merge_content(struct merge_options *o,
 
        if (mfi.clean && !df_conflict_remains &&
            oid_eq(&mfi.oid, a_oid) && mfi.mode == a_mode) {
-               int path_renamed_outside_HEAD;
                output(o, 3, _("Skipped %s (merged same as existing)"), path);
                /*
                 * The content merge resulted in the same file contents we
@@ -2771,8 +2770,7 @@ static int merge_content(struct merge_options *o,
                 * are recorded at the correct path (which may not be true
                 * if the merge involves a rename).
                 */
-               path_renamed_outside_HEAD = !path2 || !strcmp(path, path2);
-               if (!path_renamed_outside_HEAD) {
+               if (was_tracked(path)) {
                        add_cacheinfo(o, mfi.mode, &mfi.oid, path,
                                      0, (!o->call_depth), 0);
                        return mfi.clean;