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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Mark Nauwelaerts <mnauw@xxxxxxxxxxxxxxxxxxxxx>

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@xxxxxxxxxxxxxxxxxxxxx>
---
 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




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux