git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mark Nauwelaerts <mark.nauwelaerts@gmail.com>
To: git@vger.kernel.org
Cc: Mark Nauwelaerts <mnauw@users.sourceforge.net>
Subject: [PATCH 1/2] fast-export: ensure proper order of modify, copy and rename entries
Date: Sun, 24 Dec 2017 11:52:08 +0100	[thread overview]
Message-ID: <1514112729-31647-2-git-send-email-mark.nauwelaerts@gmail.com> (raw)
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


  reply	other threads:[~2017-12-24 10:55 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-24 10:52 [PATCH 0/2] restore fast-export full filecopy detection Mark Nauwelaerts
2017-12-24 10:52 ` Mark Nauwelaerts [this message]
2017-12-24 10:52 ` [PATCH 2/2] fast-export: remove now obsolete filtering of modified files Mark Nauwelaerts
2018-01-07 16:56 ` [PATCH 0/2] restore fast-export full filecopy detection Mark Nauwelaerts

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1514112729-31647-2-git-send-email-mark.nauwelaerts@gmail.com \
    --to=mark.nauwelaerts@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=mnauw@users.sourceforge.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).