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

[PATCH v2 13/15] merge-recursive: track information associated with directory renames

From
Elijah Newren <newren@gmail.com>
Date
Mar 30, 2019, 00:33 UTC
Message-ID
<20190330003336.21940-14-newren@gmail.com>
In-Reply-To
<20190330003336.21940-1-newren@gmail.com>

Directory rename detection previously silently applied. In order to allow printing information about paths that changed or printing a conflict notification (and only doing so near other potential conflict messages associated with the paths), save this information inside the rename struct for later use. A subsequent patch will make use of the additional information.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 merge-recursive.c | 37 +++++++++++++++++++++++--------------
 1 file changed, 23 insertions(+), 14 deletions(-)
diff --git a/merge-recursive.c b/merge-recursive.c
index 1d2c9e1772..938a526b20 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -207,8 +207,16 @@ struct stage_data {
 };
 
 struct rename {
+	unsigned processed:1;
 	struct diff_filepair *pair;
 	const char *branch; /* branch that the rename occurred on */
+	/*
+	 * If directory rename detection affected this rename, what was its
+	 * original type ('A' or 'R') and it's original destination before
+	 * the directory rename (otherwise, '\0' and NULL for these two vars).
+	 */
+	char dir_rename_original_type;
+	char *dir_rename_original_dest;
 	/*
 	 * Purpose of src_entry and dst_entry:
 	 *
@@ -230,8 +238,6 @@ struct rename {
 	 */
 	struct stage_data *src_entry;
 	struct stage_data *dst_entry;
-	unsigned add_turned_into_rename:1;
-	unsigned processed:1;
 };
 
 struct rename_conflict_info {
@@ -2484,16 +2490,18 @@ static void apply_directory_rename_modifications(struct merge_options *opt,
 		       &re->dst_entry->stages[stage].oid,
 		       &re->dst_entry->stages[stage].mode);
 
-	/* Update pair status */
-	if (pair->status == 'A') {
-		/*
-		 * Recording rename information for this add makes it look
-		 * like a rename/delete conflict.  Make sure we can
-		 * correctly handle this as an add that was moved to a new
-		 * directory instead of reporting a rename/delete conflict.
-		 */
-		re->add_turned_into_rename = 1;
-	}
+	/*
+	 * Record the original change status (or 'type' of change).  If it
+	 * was originally an add ('A'), this lets us differentiate later
+	 * between a RENAME_DELETE conflict and RENAME_VIA_DIR (they
+	 * otherwise look the same).  If it was originally a rename ('R'),
+	 * this lets us remember and report accurately about the transitive
+	 * renaming that occurred via the directory rename detection.  Also,
+	 * record the original destination name.
+	 */
+	re->dir_rename_original_type = pair->status;
+	re->dir_rename_original_dest = pair->two->path;
+
 	/*
 	 * We don't actually look at pair->status again, but it seems
 	 * pedagogically correct to adjust it.
@@ -2556,9 +2564,10 @@ static struct string_list *get_renames(struct merge_options *opt,
 
 		re = xmalloc(sizeof(*re));
 		re->processed = 0;
-		re->add_turned_into_rename = 0;
 		re->pair = pair;
 		re->branch = branch;
+		re->dir_rename_original_type = '\0';
+		re->dir_rename_original_dest = NULL;
 		item = string_list_lookup(entries, re->pair->one->path);
 		if (!item)
 			re->src_entry = insert_stage_data(re->pair->one->path,
@@ -2726,7 +2735,7 @@ static int process_renames(struct merge_options *opt,
 			try_merge = 0;
 
 			if (oid_eq(&src_other.oid, &null_oid) &&
-			    ren1->add_turned_into_rename) {
+			    ren1->dir_rename_original_type == 'A') {
 				setup_rename_conflict_info(RENAME_VIA_DIR,
 							   opt, ren1, NULL);
 			} else if (oid_eq(&src_other.oid, &null_oid)) {
-- 
2.21.0.211.g078f4bef79.dirty
Previous: Elijah NewrenNext: Elijah Newren
Message 25 of 49 in “[BUG] All files in folder are moved when cherry-picking commit that moves fewer files”
  1. Linus NilssonFeb 27, 2019
  2. Phillip WoodFeb 27, 2019
  3. Elijah NewrenFeb 27, 2019
  4. Jeff KingFeb 27, 2019
  5. Elijah NewrenFeb 27, 2019
  6. Linus NilssonFeb 28, 2019
  7. Junio C HamanoMar 1, 2019
  8. Elijah NewrenMar 2, 2019
  9. Junio C HamanoMar 3, 2019
  10. Elijah NewrenMar 6, 2019
  11. Junio C HamanoMar 6, 2019
  12. Elijah NewrenMar 7, 2019
  13. Junio C HamanoMar 7, 2019
  14. Junio C HamanoMar 7, 2019
  15. 00/15 Switch directory rename detection defaultElijah Newren, Mar 30, 2019
  16. 08/15 merge-recursive: remove ren[12]_other fields from rename_conflict_infoElijah Newren, Mar 30, 2019
  17. 10/15 merge-recursive: cleanup handle_rename_* function signaturesElijah Newren, Mar 30, 2019
  18. 01/15 Use 'unsigned short' for mode, like diff_filespec doesElijah Newren, Mar 30, 2019
  19. 04/15 merge-recursive: rename locals 'o' and 'a' to 'obuf' and 'abuf'Elijah Newren, Mar 30, 2019
  20. 14/15 merge-recursive: give callers of handle_content_merge() access to contentsElijah Newren, Mar 30, 2019
  21. 11/15 merge-recursive: switch from (oid,mode) pairs to a diff_filespecElijah Newren, Mar 30, 2019
  22. 07/15 merge-recursive: shrink rename_conflict_infoElijah Newren, Mar 30, 2019
  23. 12/15 t6043: fix copied test description to match its purposeElijah Newren, Mar 30, 2019
  24. 09/15 merge-recursive: track branch where rename occurred in rename structElijah Newren, Mar 30, 2019
  25. 13/15 merge-recursive: track information associated with directory renamesElijah Newren, Mar 30, 2019
  26. 15/15 merge-recursive: switch directory rename detection defaultElijah Newren, Mar 30, 2019
  27. Ævar Arnfjörð BjarmasonMar 30, 2019
  28. Elijah NewrenApr 1, 2019
  29. 02/15 merge-recursive: rename merge_options argument from 'o' to 'opt'Elijah Newren, Mar 30, 2019
  30. 05/15 merge-recursive: use 'ci' for rename_conflict_info variable nameElijah Newren, Mar 30, 2019
  31. 03/15 merge-recursive: rename diff_filespec 'one' to 'o'Elijah Newren, Mar 30, 2019
  32. 06/15 merge-recursive: move some struct declarations togetherElijah Newren, Mar 30, 2019
  33. 00/15 Switch directory rename detection defaultElijah Newren, Apr 5, 2019
  34. 03/15 merge-recursive: rename diff_filespec 'one' to 'o'Elijah Newren, Apr 5, 2019
  35. 05/15 merge-recursive: use 'ci' for rename_conflict_info variable nameElijah Newren, Apr 5, 2019
  36. 09/15 merge-recursive: track branch where rename occurred in rename structElijah Newren, Apr 5, 2019
  37. 06/15 merge-recursive: move some struct declarations togetherElijah Newren, Apr 5, 2019
  38. 07/15 merge-recursive: shrink rename_conflict_infoElijah Newren, Apr 5, 2019
  39. 08/15 merge-recursive: remove ren[12]_other fields from rename_conflict_infoElijah Newren, Apr 5, 2019
  40. 04/15 merge-recursive: rename locals 'o' and 'a' to 'obuf' and 'abuf'Elijah Newren, Apr 5, 2019
  41. 15/15 merge-recursive: switch directory rename detection defaultElijah Newren, Apr 5, 2019
  42. 14/15 merge-recursive: give callers of handle_content_merge() access to contentsElijah Newren, Apr 5, 2019
  43. 12/15 t6043: fix copied test description to match its purposeElijah Newren, Apr 5, 2019
  44. 13/15 merge-recursive: track information associated with directory renamesElijah Newren, Apr 5, 2019
  45. 02/15 merge-recursive: rename merge_options argument from 'o' to 'opt'Elijah Newren, Apr 5, 2019
  46. 10/15 merge-recursive: cleanup handle_rename_* function signaturesElijah Newren, Apr 5, 2019
  47. 01/15 Use 'unsigned short' for mode, like diff_filespec doesElijah Newren, Apr 5, 2019
  48. 11/15 merge-recursive: switch from (oid,mode) pairs to a diff_filespecElijah Newren, Apr 5, 2019
  49. Jacob KellerApr 5, 2019

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.