@matheusbsbs / matheus-bagliano / commits / 060df62422
Fork 0

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>

Elijah Newren committed Jul 9, 2010 at 07:10 UTC 060df624228187c77ca53a437ae0e9896076f045
2 files changed +30 -1
builtin/fast-export.c
+29
@@ -147,10 +147,39 @@ static void handle_object(const unsigned char *sha1)
147 free(buf);
148 }
149
150 +static int depth_first(const void *a_, const void *b_)
151 +{
152 + const struct diff_filepair *a = *((const struct diff_filepair **)a_);
153 + const struct diff_filepair *b = *((const struct diff_filepair **)b_);
154 + const char *name_a, *name_b;
155 + int len_a, len_b, len;
156 + int cmp;
157 +
158 + name_a = a->one ? a->one->path : a->two->path;
159 + name_b = b->one ? b->one->path : b->two->path;
160 +
161 + len_a = strlen(name_a);
162 + len_b = strlen(name_b);
163 + len = (len_a < len_b) ? len_a : len_b;
164 +
165 + /* strcmp will sort 'd' before 'd/e', we want 'd/e' before 'd' */
166 + cmp = memcmp(name_a, name_b, len);
167 + if (cmp)
168 + return cmp;
169 + return (len_b - len_a);
170 +}
171 +
172 static void show_filemodify(struct diff_queue_struct *q,
173 struct diff_options *options, void *data)
174 {
175 int i;
176 +
177 + /*
178 + * Handle files below a directory first, in case they are all deleted
179 + * and the directory changes to a file or symlink.
180 + */
181 + qsort(q->queue, q->nr, sizeof(q->queue[0]), depth_first);
182 +
183 for (i = 0; i < q->nr; i++) {
184 struct diff_filespec *ospec = q->queue[i]->one;
185 struct diff_filespec *spec = q->queue[i]->two;
t/t9350-fast-export.sh
+1 -1
@@ -376,7 +376,7 @@ test_expect_success 'tree_tag-obj' 'git fast-export tree_tag-obj'
376 test_expect_success 'tag-obj_tag' 'git fast-export tag-obj_tag'
377 test_expect_success 'tag-obj_tag-obj' 'git fast-export tag-obj_tag-obj'
378
379 -test_expect_failure 'directory becomes symlink' '
379 +test_expect_success 'directory becomes symlink' '
380 git init dirtosymlink &&
381 git init result &&
382 (