@matheusbsbs / matheus-bagliano / commits / 4ce6fb8058
Fork 0

fast-export: ensure that a renamed file is printed after all references

t9350 sets up a commit where a file is both copied and renamed. The output of fast-export for this commit should look like this: author ... committer ... from :19 C "file2" "file4" R "file2" "file5" The order of the two modification lines is derived from the result that the diff machinery produces. 060df62 (fast-export: Fix output order of D/F changes) inserted a qsort call that modifies the order of the diff result. Unfortunately, qsort need not be stable. Therefore, it is possible that the 'R' line appears before the 'C' line and the resulting fast-import stream is incorrect. Fix it by forcing that the rename entry is printed after all other modification lines with the same file name. Signed-off-by: Johannes Sixt <j6t@kdbg.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Sixt committed Sep 7, 2010 at 21:33 UTC 4ce6fb805803cd9bf82c08c84a2fdc8cd6bae8ef
1 file changed +9 -1
builtin/fast-export.c
+9 -1
@@ -166,7 +166,15 @@ static int depth_first(const void *a_, const void *b_)
166 cmp = memcmp(name_a, name_b, len);
167 if (cmp)
168 return cmp;
169 - return (len_b - len_a);
169 + cmp = len_b - len_a;
170 + if (cmp)
171 + return cmp;
172 + /*
173 + * Move 'R'ename entries last so that all references of the file
174 + * appear in the output before it is renamed (e.g., when a file
175 + * was copied and renamed in the same commit).
176 + */
177 + return (a->status == 'R') - (b->status == 'R');
178 }
179
180 static void show_filemodify(struct diff_queue_struct *q,