summaryrefslogtreecommitdiff
path: root/builtin/fast-export.c
diff options
context:
space:
mode:
authorElijah Newren <newren@gmail.com>2010-07-09 13:10:55 (GMT)
committerJunio C Hamano <gitster@pobox.com>2010-07-09 23:16:29 (GMT)
commit060df624228187c77ca53a437ae0e9896076f045 (patch)
treed95230936ae0662e6987e03e591ee43fb83d0caf /builtin/fast-export.c
parent5a2580d62f9aaa30f0acd10df9dbe7a581dd77d9 (diff)
downloadgit-060df624228187c77ca53a437ae0e9896076f045.zip
git-060df624228187c77ca53a437ae0e9896076f045.tar.gz
git-060df624228187c77ca53a437ae0e9896076f045.tar.bz2
fast-export: Fix output order of D/F changes
The fast-import stream format requires incremental changes which take place immediately, meaning that for D->F conversions all files below the relevant directory must be deleted before the resulting file of the same name is created. Reversing the order can result in fast-import silently deleting the file right after creating it, resulting in the file missing from the resulting repository. We correct this by first sorting the diff_queue_struct in depth-first order. Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/fast-export.c')
-rw-r--r--builtin/fast-export.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/builtin/fast-export.c b/builtin/fast-export.c
index c6dd71a..965e90e 100644
--- a/builtin/fast-export.c
+++ b/builtin/fast-export.c
@@ -147,10 +147,39 @@ static void handle_object(const unsigned char *sha1)
free(buf);
}
+static int depth_first(const void *a_, const void *b_)
+{
+ const struct diff_filepair *a = *((const struct diff_filepair **)a_);
+ const struct diff_filepair *b = *((const struct diff_filepair **)b_);
+ const char *name_a, *name_b;
+ int len_a, len_b, len;
+ int cmp;
+
+ name_a = a->one ? a->one->path : a->two->path;
+ name_b = b->one ? b->one->path : b->two->path;
+
+ len_a = strlen(name_a);
+ len_b = strlen(name_b);
+ len = (len_a < len_b) ? len_a : len_b;
+
+ /* strcmp will sort 'd' before 'd/e', we want 'd/e' before 'd' */
+ cmp = memcmp(name_a, name_b, len);
+ if (cmp)
+ return cmp;
+ return (len_b - len_a);
+}
+
static void show_filemodify(struct diff_queue_struct *q,
struct diff_options *options, void *data)
{
int i;
+
+ /*
+ * Handle files below a directory first, in case they are all deleted
+ * and the directory changes to a file or symlink.
+ */
+ qsort(q->queue, q->nr, sizeof(q->queue[0]), depth_first);
+
for (i = 0; i < q->nr; i++) {
struct diff_filespec *ospec = q->queue[i]->one;
struct diff_filespec *spec = q->queue[i]->two;