@matheusbsbs / matheus-bagliano / commits / ac7f0f436e
Fork 0

merge-recursive: do not barf on "to be removed" entries.

When update-trees::threeway_merge() decides that a path that exists in the current index (and HEAD) is to be removed, it leaves a stage 0 entry whose mode bits are set to 0. The code mistook it as "this stage wants the blob here", and proceeded to call update_file_flags() which ended up trying to put the mode=0 entry in the index, got very confused, and ended up barfing with "do not know what to do with 000000". Since threeway_merge() does not handle case #10 (one side removes while the other side does not do anything), this is not a problem while we refuse to merge branches that have D/F conflicts, but when we start resolving them, we would need to be able to remove cache entries, and at that point it starts to matter. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Apr 7, 2007 at 05:52 UTC ac7f0f436e4f45d616ca509f5163fddab104516b
1 file changed +11 -5
merge-recursive.c
+11 -5
@@ -1018,9 +1018,9 @@ static int process_renames(struct path_list *a_renames,
1018 return clean_merge;
1019 }
1020
1021 -static unsigned char *has_sha(const unsigned char *sha)
1021 +static unsigned char *stage_sha(const unsigned char *sha, unsigned mode)
1022 {
1023 - return is_null_sha1(sha) ? NULL: (unsigned char *)sha;
1023 + return (is_null_sha1(sha) || mode == 0) ? NULL: (unsigned char *)sha;
1024 }
1025
1026 /* Per entry merge function */
@@ -1033,12 +1033,12 @@ static int process_entry(const char *path, struct stage_data *entry,
1033 print_index_entry("\tpath: ", entry);
1034 */
1035 int clean_merge = 1;
1036 - unsigned char *o_sha = has_sha(entry->stages[1].sha);
1037 - unsigned char *a_sha = has_sha(entry->stages[2].sha);
1038 - unsigned char *b_sha = has_sha(entry->stages[3].sha);
1036 unsigned o_mode = entry->stages[1].mode;
1037 unsigned a_mode = entry->stages[2].mode;
1038 unsigned b_mode = entry->stages[3].mode;
1039 + unsigned char *o_sha = stage_sha(entry->stages[1].sha, o_mode);
1040 + unsigned char *a_sha = stage_sha(entry->stages[2].sha, a_mode);
1041 + unsigned char *b_sha = stage_sha(entry->stages[3].sha, b_mode);
1042
1043 if (o_sha && (!a_sha || !b_sha)) {
1044 /* Case A: Deleted in one */
@@ -1139,6 +1139,12 @@ static int process_entry(const char *path, struct stage_data *entry,
1139 update_file_flags(mfi.sha, mfi.mode, path,
1140 0 /* update_cache */, 1 /* update_working_directory */);
1141 }
1142 + } else if (!o_sha && !a_sha && !b_sha) {
1143 + /*
1144 + * this entry was deleted altogether. a_mode == 0 means
1145 + * we had that path and want to actively remove it.
1146 + */
1147 + remove_file(1, path, !a_mode);
1148 } else
1149 die("Fatal merge failure, shouldn't happen.");
1150