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

[PATCH 1/2] fast-export: ensure proper order of modify, copy and rename entries

From
MNMark Nauwelaerts <mark.nauwelaerts@gmail.com>
Date
Dec 24, 2017, 10:52 UTC
Message-ID
<1514112729-31647-2-git-send-email-mark.nauwelaerts@gmail.com>
In-Reply-To
<1514112729-31647-1-git-send-email-mark.nauwelaerts@gmail.com>
From: Mark Nauwelaerts <mnauw@users.sourceforge.net>

As b3e8ca8 ("fast-export: do not copy from modified file", 2017-09-20) indicates, if a commit both modifies a file and uses it as a source for a copy, then the specifications of git-fast-import require that the copy should be reported first followed by the modification to the source file.

The commit above addressed the problem by never reporting the copy. However, the copy can still be reported if the entries are sorted properly. That can be achieved by adjusting the order of the sort that is performed anyway for other reasons of consistency. This is merely an extra order condition.

Furthermore, when using fast-export to export or bridge to another version control system which explicitly tracks copies, then the 'C' commands in the output are quite useful and necessary.

Signed-off-by: Mark Nauwelaerts <mnauw@users.sourceforge.net>
---
 builtin/fast-export.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/builtin/fast-export.c b/builtin/fast-export.c
index 2fb60d6..1b3e250 100644
--- a/builtin/fast-export.c
+++ b/builtin/fast-export.c
@@ -262,6 +262,14 @@ static void export_blob(const struct object_id *oid)
 		free(buf);
 }
 
+static int order_status(const char status)
+{
+	if (status == 'R')
+		return 2;
+	else
+		return status == 'M' ? 1 : 0;
+}
+
 static int depth_first(const void *a_, const void *b_)
 {
 	const struct diff_filepair *a = *((const struct diff_filepair **)a_);
@@ -288,8 +296,12 @@ static int depth_first(const void *a_, const void *b_)
 	 * Move 'R'ename entries last so that all references of the file
 	 * appear in the output before it is renamed (e.g., when a file
 	 * was copied and renamed in the same commit).
+	 * Moreover, 'C' needs to go before 'M' if the file was copied
+	 * and then modified a bit, as it should be done that way as well
+	 * at import time (also recall that 'C' is calculated on the
+	 * original content).
 	 */
-	return (a->status == 'R') - (b->status == 'R');
+	return order_status(a->status) - order_status(b->status);
 }
 
 static void print_path_1(const char *path)
-- 
2.7.4
Previous: Mark NauwelaertsNext: Mark Nauwelaerts
Message 3 of 4 in “restore fast-export full filecopy detection”
  1. 0/2 restore fast-export full filecopy detectionMark Nauwelaerts, Dec 24, 2017
  2. 2/2 fast-export: remove now obsolete filtering of modified filesMark Nauwelaerts, Dec 24, 2017
  3. 1/2 fast-export: ensure proper order of modify, copy and rename entriesMark Nauwelaerts, Dec 24, 2017
  4. Mark NauwelaertsJan 7, 2018

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.