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

[PATCH 23/37] merge-recursive: Structure process_df_entry() to handle more cases

From
Elijah Newren <newren@gmail.com>
Date
Sep 20, 2010, 08:28 UTC
Message-ID
<1284971350-30590-24-git-send-email-newren@gmail.com>
In-Reply-To
<1284971350-30590-1-git-send-email-newren@gmail.com>

Modify process_df_entry() (mostly just indentation level changes) to get it ready for handling more D/F conflict type cases.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 merge-recursive.c |   83 ++++++++++++++++++++++++++++++-----------------------
 1 files changed, 47 insertions(+), 36 deletions(-)
diff --git a/merge-recursive.c b/merge-recursive.c
index 5326f5e..b8222ad 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -1336,13 +1336,19 @@ static int process_entry(struct merge_options *o,
 }
 
 /*
- * Per entry merge function for D/F conflicts, to be called only after
- * all files below dir have been processed.  We do this because in the
- * cases we can cleanly resolve D/F conflicts, process_entry() can clean
- * out all the files below the directory for us.
+ * Per entry merge function for D/F (and/or rename) conflicts.  In the
+ * cases we can cleanly resolve D/F conflicts, process_entry() can
+ * clean out all the files below the directory for us.  All D/F
+ * conflict cases must be handled here at the end to make sure any
+ * directories that can be cleaned out, are.
+ *
+ * Some rename conflicts may also be handled here that don't necessarily
+ * involve D/F conflicts, since the code to handle them is generic enough
+ * to handle those rename conflicts with or without D/F conflicts also
+ * being involved.
  */
 static int process_df_entry(struct merge_options *o,
-			 const char *path, struct stage_data *entry)
+			    const char *path, struct stage_data *entry)
 {
 	int clean_merge = 1;
 	unsigned o_mode = entry->stages[1].mode;
@@ -1351,42 +1357,47 @@ static int process_df_entry(struct merge_options *o,
 	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);
-	const char *add_branch;
-	const char *other_branch;
-	unsigned mode;
-	const unsigned char *sha;
-	const char *conf;
 	struct stat st;
 
-	if (! ((!o_sha && a_sha && !b_sha) || (!o_sha && !a_sha && b_sha)))
-		return 1; /* we don't handle non D-F cases */
-
 	entry->processed = 1;
+	if (entry->rename_df_conflict_info) {
+		die ("Not yet implemented.");
+	} else if (!o_sha && !!a_sha != !!b_sha) {
+		/* directory -> (directory, file) */
+		const char *add_branch;
+		const char *other_branch;
+		unsigned mode;
+		const unsigned char *sha;
+		const char *conf;
 
-	if (a_sha) {
-		add_branch = o->branch1;
-		other_branch = o->branch2;
-		mode = a_mode;
-		sha = a_sha;
-		conf = "file/directory";
-	} else {
-		add_branch = o->branch2;
-		other_branch = o->branch1;
-		mode = b_mode;
-		sha = b_sha;
-		conf = "directory/file";
-	}
-	if (lstat(path, &st) == 0 && S_ISDIR(st.st_mode)) {
-		const char *new_path = unique_path(o, path, add_branch);
-		clean_merge = 0;
-		output(o, 1, "CONFLICT (%s): There is a directory with name %s in %s. "
-		       "Adding %s as %s",
-		       conf, path, other_branch, path, new_path);
-		remove_file(o, 0, path, 0);
-		update_file(o, 0, sha, mode, new_path);
+		if (a_sha) {
+			add_branch = o->branch1;
+			other_branch = o->branch2;
+			mode = a_mode;
+			sha = a_sha;
+			conf = "file/directory";
+		} else {
+			add_branch = o->branch2;
+			other_branch = o->branch1;
+			mode = b_mode;
+			sha = b_sha;
+			conf = "directory/file";
+		}
+		if (lstat(path, &st) == 0 && S_ISDIR(st.st_mode)) {
+			const char *new_path = unique_path(o, path, add_branch);
+			clean_merge = 0;
+			output(o, 1, "CONFLICT (%s): There is a directory with name %s in %s. "
+			       "Adding %s as %s",
+			       conf, path, other_branch, path, new_path);
+			remove_file(o, 0, path, 0);
+			update_file(o, 0, sha, mode, new_path);
+		} else {
+			output(o, 2, "Adding %s", path);
+			update_file(o, 1, sha, mode, path);
+		}
 	} else {
-		output(o, 2, "Adding %s", path);
-		update_file(o, 1, sha, mode, path);
+		entry->processed = 0;
+		return 1; /* not handled; assume clean until processed */
 	}
 
 	return clean_merge;
-- 
1.7.3.271.g16009
Previous: Elijah NewrenNext: Elijah Newren
Message 30 of 46 in “Audit and fix corner case bugs in recursive merge”
  1. 00/37 Audit and fix corner case bugs in recursive mergeElijah Newren, Sep 20, 2010
  2. 01/37 t3030: Add a testcase for resolvable rename/add conflict with symlinksElijah Newren, Sep 20, 2010
  3. Johannes SixtSep 20, 2010
  4. Jakub NarebskiSep 20, 2010
  5. 02/37 merge-recursive: Restructure showing how to chain more process_* functionsElijah Newren, Sep 20, 2010
  6. 03/37 t6032: Add a test checking for excessive output from mergeElijah Newren, Sep 20, 2010
  7. 04/37 t6022: Add test combinations of {content conflict?, D/F conflict remains?}Elijah Newren, Sep 20, 2010
  8. 05/37 t6022: Add tests for reversing order of merges when D/F conflicts presentElijah Newren, Sep 20, 2010
  9. 06/37 t6022: Add tests with both rename source & dest involved in D/F conflictsElijah Newren, Sep 20, 2010
  10. 07/37 t6022: Add paired rename+D/F conflict: (two/file, one/file) -> (one, two)Elijah Newren, Sep 20, 2010
  11. 08/37 t6022: Add tests for rename/rename combined with D/F conflictsElijah Newren, Sep 20, 2010
  12. 09/37 t6020: Modernize style a bitElijah Newren, Sep 20, 2010
  13. Johannes SixtSep 20, 2010
  14. Elijah NewrenSep 20, 2010
  15. Junio C HamanoSep 22, 2010
  16. Elijah NewrenSep 22, 2010
  17. 10/37 t6020: Add a testcase for modify/delete + directory/file conflictElijah Newren, Sep 20, 2010
  18. 11/37 t6036: Test index and worktree state, not just that merge failsElijah Newren, Sep 20, 2010
  19. 12/37 t6036: Add a second testcase similar to the first but with content changesElijah Newren, Sep 20, 2010
  20. 13/37 t6036: Add testcase for undetected conflictElijah Newren, Sep 20, 2010
  21. 14/37 merge-recursive: Small code clarification -- variable name and commentsElijah Newren, Sep 20, 2010
  22. 15/37 merge-recursive: Rename conflict_rename_rename*() for clarityElijah Newren, Sep 20, 2010
  23. 16/37 merge-recursive: Nuke rename/directory conflict detectionElijah Newren, Sep 20, 2010
  24. 17/37 merge-recursive: Move rename/delete handling into dedicated functionElijah Newren, Sep 20, 2010
  25. 18/37 merge-recursive: Move delete/modify handling into dedicated functionElijah Newren, Sep 20, 2010
  26. 19/37 merge-recursive: Move process_entry's content merging into a functionElijah Newren, Sep 20, 2010
  27. 20/37 merge-recursive: New data structures for deferring of D/F conflictsElijah Newren, Sep 20, 2010
  28. 21/37 merge-recursive: New function to assist resolving renames in-core onlyElijah Newren, Sep 20, 2010
  29. 22/37 merge-recursive: Have process_entry() skip D/F or rename entriesElijah Newren, Sep 20, 2010
  30. 23/37 merge-recursive: Structure process_df_entry() to handle more casesElijah Newren, Sep 20, 2010
  31. 24/37 merge-recursive: Update conflict_rename_rename_1to2() call signatureElijah Newren, Sep 20, 2010
  32. 25/37 merge-recursive: Update merge_content() call signatureElijah Newren, Sep 20, 2010
  33. 26/37 merge-recursive: Avoid doubly merging rename/add conflict contentsElijah Newren, Sep 20, 2010
  34. 27/37 merge-recursive: Move handling of double rename of one file to twoElijah Newren, Sep 20, 2010
  35. 28/37 merge-recursive: Move handling of double rename of one file to other fileElijah Newren, Sep 20, 2010
  36. 29/37 merge-recursive: Delay handling of rename/delete conflictsElijah Newren, Sep 20, 2010
  37. 30/37 merge-recursive: Delay content merging for renamesElijah Newren, Sep 20, 2010
  38. 31/37 merge-recursive: Delay modify/delete conflicts if D/F conflict presentElijah Newren, Sep 20, 2010
  39. 32/37 conflict_rename_delete(): Check whether D/F conflicts are still presentElijah Newren, Sep 20, 2010
  40. 33/37 conflict_rename_rename_1to2(): Fix checks for presence of D/F conflictsElijah Newren, Sep 20, 2010
  41. 34/37 merge_content(): Check whether D/F conflicts are still presentElijah Newren, Sep 20, 2010
  42. 35/37 handle_delete_modify(): Check whether D/F conflicts are still presentElijah Newren, Sep 20, 2010
  43. 36/37 merge-recursive: Make room for directories in D/F conflictsElijah Newren, Sep 20, 2010
  44. Johannes SixtSep 20, 2010
  45. Elijah NewrenSep 20, 2010
  46. 37/37 merge-recursive: Remove redundant path clearing for D/F conflictsElijah Newren, Sep 20, 2010

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.