@matheusbsbs / matheus-bagliano / commits / ebeec7dbc5
Fork 0

fast-export: Avoid dropping files from commits

When exporting a subset of commits on a branch that do not go back to a root commit (e.g. master~2..master), we still want each exported commit to have the same files in the exported tree as in the original tree. Previously, when given such a range, we would omit master~2 as a parent of master~1, but we would still diff against master~2 when selecting the list of files to include in master~1. This would result in only files that had changed in the given range showing up in the resulting export. In such cases, we should diff master~1 against the root instead (i.e. use diff_root_tree_sha1 instead of diff_tree_sha1). There's a special case to consider here: incremental exports (i.e. exports where the --import-marks flag is specified). If master~2 is an imported mark, then we still want to diff master~1 against master~2 when selecting the list of files to include. We can handle all cases, including the special case, by just checking whether master~2 corresponds to a known object mark when deciding what to diff against. Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Elijah Newren committed Mar 25, 2009 at 17:53 UTC ebeec7dbc564cb83edd8faee87890c47b6f0da43
2 files changed +7 -3
builtin-fast-export.c
+2 -1
@@ -221,7 +221,8 @@ static void handle_commit(struct commit *commit, struct rev_info *rev)
221 if (message)
222 message += 2;
223
224 - if (commit->parents) {
224 + if (commit->parents &&
225 + get_object_mark(&commit->parents->item->object) != 0) {
226 parse_commit(commit->parents->item);
227 diff_tree_sha1(commit->parents->item->tree->object.sha1,
228 commit->tree->object.sha1, "", &rev->diffopt);
t/t9301-fast-export.sh
+5 -2
@@ -8,6 +8,9 @@ test_description='git fast-export'
8
9 test_expect_success 'setup' '
10
11 + echo break it > file0 &&
12 + git add file0 &&
13 + test_tick &&
14 echo Wohlauf > file &&
15 git add file &&
16 test_tick &&
@@ -57,8 +60,8 @@ test_expect_success 'fast-export master~2..master' '
60 (cd new &&
61 git fast-import &&
62 test $MASTER != $(git rev-parse --verify refs/heads/partial) &&
60 - git diff master..partial &&
61 - git diff master^..partial^ &&
63 + git diff --exit-code master partial &&
64 + git diff --exit-code master^ partial^ &&
65 test_must_fail git rev-parse partial~2)
66
67 '