git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 3/5] merge-recursive: do not barf on "to be removed" entries.

From
Junio C Hamano <junkio@cox.net>
Date
Apr 7, 2007, 14:40 UTC
Message-ID
<7v8xd4ckne.fsf@assigned-by-dhcp.cox.net>

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>
---
 merge-recursive.c |   16 +++++++++++-----
 1 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/merge-recursive.c b/merge-recursive.c
index e1aebd7..aa3d913 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -1002,9 +1002,9 @@ static int process_renames(struct path_list *a_renames,
 	return clean_merge;
 }
 
-static unsigned char *has_sha(const unsigned char *sha)
+static unsigned char *stage_sha(const unsigned char *sha, unsigned mode)
 {
-	return is_null_sha1(sha) ? NULL: (unsigned char *)sha;
+	return (is_null_sha1(sha) || mode == 0) ? NULL: (unsigned char *)sha;
 }
 
 /* Per entry merge function */
@@ -1017,12 +1017,12 @@ static int process_entry(const char *path, struct stage_data *entry,
 	print_index_entry("\tpath: ", entry);
 	*/
 	int clean_merge = 1;
-	unsigned char *o_sha = has_sha(entry->stages[1].sha);
-	unsigned char *a_sha = has_sha(entry->stages[2].sha);
-	unsigned char *b_sha = has_sha(entry->stages[3].sha);
 	unsigned o_mode = entry->stages[1].mode;
 	unsigned a_mode = entry->stages[2].mode;
 	unsigned b_mode = entry->stages[3].mode;
+	unsigned char *o_sha = stage_sha(entry->stages[1].sha, o_mode);
+	unsigned char *a_sha = stage_sha(entry->stages[2].sha, a_mode);
+	unsigned char *b_sha = stage_sha(entry->stages[3].sha, b_mode);
 
 	if (o_sha && (!a_sha || !b_sha)) {
 		/* Case A: Deleted in one */
@@ -1123,6 +1123,12 @@ static int process_entry(const char *path, struct stage_data *entry,
 				update_file_flags(mfi.sha, mfi.mode, path,
 					      0 /* update_cache */, 1 /* update_working_directory */);
 		}
+	} else if (!o_sha && !a_sha && !b_sha) {
+		/*
+		 * this entry was deleted altogether. a_mode == 0 means
+		 * we had that path and want to actively remove it.
+		 */
+		remove_file(1, path, !a_mode);
 	} else
 		die("Fatal merge failure, shouldn't happen.");
 
-- 
1.5.1.81.gee969
Message 1 of 1 in “merge-recursive: do not barf on "to be removed" entries.”
  1. 3/5 merge-recursive: do not barf on "to be removed" entries.Junio C Hamano, Apr 7, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.