Skip to content

Commit a257165

Browse files
rscharfegitster
authored andcommitted
merge-recursive: fix verbose output for multiple base trees
One of the indirect callers of make_virtual_commit() passes the result of oid_to_hex() as the name, i.e. a pointer to a static buffer. Since the function uses that string pointer directly in building a struct merge_remote_desc, multiple entries can end up sharing the same name inadvertently. Fix that by calling set_merge_remote_desc(), which creates a copy of the string, instead of building the struct by hand. Signed-off-by: Rene Scharfe <[email protected]> Reviewed-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent beb518c commit a257165

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

merge-recursive.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,9 @@ static struct tree *shift_tree_object(struct tree *one, struct tree *two,
4242
static struct commit *make_virtual_commit(struct tree *tree, const char *comment)
4343
{
4444
struct commit *commit = alloc_commit_node();
45-
struct merge_remote_desc *desc = xmalloc(sizeof(*desc));
4645

47-
desc->name = comment;
48-
desc->obj = (struct object *)commit;
46+
set_merge_remote_desc(commit, comment, (struct object *)commit);
4947
commit->tree = tree;
50-
commit->util = desc;
5148
commit->object.parsed = 1;
5249
return commit;
5350
}

t/t3030-merge-recursive.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,4 +660,22 @@ test_expect_success 'merging with triple rename across D/F conflict' '
660660
git merge other
661661
'
662662

663+
test_expect_success 'merge-recursive remembers the names of all base trees' '
664+
git reset --hard HEAD &&
665+
666+
# more trees than static slots used by oid_to_hex()
667+
for commit in $c0 $c2 $c4 $c5 $c6 $c7
668+
do
669+
git rev-parse "$commit^{tree}"
670+
done >trees &&
671+
672+
# ignore the return code -- it only fails because the input is weird
673+
test_must_fail git -c merge.verbosity=5 merge-recursive $(cat trees) -- $c1 $c3 >out &&
674+
675+
# merge-recursive prints in reverse order, but we do not care
676+
sort <trees >expect &&
677+
sed -n "s/^virtual //p" out | sort >actual &&
678+
test_cmp expect actual
679+
'
680+
663681
test_done

0 commit comments

Comments
 (0)