1
0
mirror of https://github.com/git/git.git synced 2024-10-20 23:58:49 +02:00

fast-export: fix regression skipping some merge-commits

7199203937 (object_array: add and use `object_array_pop()`, 2017-09-23)
noted that the pattern `object = array.objects[--array.nr].item` could
be abstracted as `object = object_array_pop(&array)`.

Unfortunately, one of the conversions was horribly wrong. Between
grabbing the last object (i.e., peeking at it) and decreasing the object
count, the original code would sometimes return early. The updated code
on the other hand, will always pop the last element, then maybe do the
early return without doing anything with the object.

The end result is that merge commits where all the parents have still
not been exported will simply be dropped, meaning that they will be
completely missing from the exported data.

Re-add a commit when it is not yet time to handle it. An alternative
that was considered was to peek-then-pop. That carries some risk with it
since the peeking and popping need to act on the same object, in a
concerted fashion.

Add a test that would have caught this.

Reported-by: Isaac Chou <Isaac.Chou@microfocus.com>
Analyzed-by: Isaac Chou <Isaac.Chou@microfocus.com>
Helped-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Martin Ågren <martin.agren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Martin Ågren 2018-04-21 00:12:31 +02:00 committed by Junio C Hamano
parent d32eb83c1d
commit be011bbe00
2 changed files with 22 additions and 1 deletions

@ -651,8 +651,11 @@ static void handle_tail(struct object_array *commits, struct rev_info *revs,
struct commit *commit;
while (commits->nr) {
commit = (struct commit *)object_array_pop(commits);
if (has_unshown_parent(commit))
if (has_unshown_parent(commit)) {
/* Queue again, to be handled later */
add_object_array(&commit->object, NULL, commits);
return;
}
handle_commit(commit, revs, paths_of_changed_objects);
}
}

@ -540,4 +540,22 @@ test_expect_success 'when using -C, do not declare copy when source of copy is a
test_cmp expected actual
'
test_expect_success 'merge commit gets exported with --import-marks' '
test_create_repo merging &&
(
cd merging &&
test_commit initial &&
git checkout -b topic &&
test_commit on-topic &&
git checkout master &&
test_commit on-master &&
test_tick &&
git merge --no-ff -m Yeah topic &&
echo ":1 $(git rev-parse HEAD^^)" >marks &&
git fast-export --import-marks=marks master >out &&
grep Yeah out
)
'
test_done