From 1cd12926cedb340d176db607e087495381032ce2 Mon Sep 17 00:00:00 2001 From: Charles Bailey Date: Mon, 25 May 2009 01:21:13 +0100 Subject: t6023: merge-file fails to output anything for a degenerate merge In the case that merge-file is passed three files with identical contents it wipes the contents of the output file instead of leaving it unchanged. Althought merge-file is porcelain and this will never happen in normal usage, it is still wrong. Signed-off-by: Charles Bailey Signed-off-by: Junio C Hamano --- t/t6023-merge-file.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/t/t6023-merge-file.sh b/t/t6023-merge-file.sh index f674c48ca..19556350b 100755 --- a/t/t6023-merge-file.sh +++ b/t/t6023-merge-file.sh @@ -54,6 +54,12 @@ deduxit me super semitas jusitiae, EOF printf "propter nomen suum." >> new4.txt +test_expect_failure 'merge with no changes' ' + cp orig.txt test.txt && + git merge-file test.txt orig.txt orig.txt && + test_cmp test.txt orig.txt +' + cp new1.txt test.txt test_expect_success "merge without conflict" \ "git merge-file test.txt orig.txt new2.txt" -- cgit v1.2.1 From 5719db91ce5915ee07c50f1afdc94fe34e91529f Mon Sep 17 00:00:00 2001 From: Charles Bailey Date: Mon, 25 May 2009 01:21:14 +0100 Subject: Change xdl_merge to generate output even for null merges xdl_merge used to have a check to ensure that there was at least some change in one or other side being merged but this suppressed output for the degenerate case when base, local and remote contents were all identical. Removing this check enables correct output in the degenerate case and xdl_free_script handles freeing NULL scripts so there is no need to have the check for these calls. Signed-off-by: Charles Bailey Signed-off-by: Junio C Hamano --- t/t6023-merge-file.sh | 2 +- xdiff/xmerge.c | 31 +++++++++++++++---------------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/t/t6023-merge-file.sh b/t/t6023-merge-file.sh index 19556350b..796f2128d 100755 --- a/t/t6023-merge-file.sh +++ b/t/t6023-merge-file.sh @@ -54,7 +54,7 @@ deduxit me super semitas jusitiae, EOF printf "propter nomen suum." >> new4.txt -test_expect_failure 'merge with no changes' ' +test_expect_success 'merge with no changes' ' cp orig.txt test.txt && git merge-file test.txt orig.txt orig.txt && test_cmp test.txt orig.txt diff --git a/xdiff/xmerge.c b/xdiff/xmerge.c index 82b3573e7..1ef1d358c 100644 --- a/xdiff/xmerge.c +++ b/xdiff/xmerge.c @@ -470,23 +470,22 @@ int xdl_merge(mmfile_t *orig, mmfile_t *mf1, const char *name1, return -1; } status = 0; - if (xscr1 || xscr2) { - if (!xscr1) { - result->ptr = xdl_malloc(mf2->size); - memcpy(result->ptr, mf2->ptr, mf2->size); - result->size = mf2->size; - } else if (!xscr2) { - result->ptr = xdl_malloc(mf1->size); - memcpy(result->ptr, mf1->ptr, mf1->size); - result->size = mf1->size; - } else { - status = xdl_do_merge(&xe1, xscr1, name1, - &xe2, xscr2, name2, - level, xpp, result); - } - xdl_free_script(xscr1); - xdl_free_script(xscr2); + if (!xscr1) { + result->ptr = xdl_malloc(mf2->size); + memcpy(result->ptr, mf2->ptr, mf2->size); + result->size = mf2->size; + } else if (!xscr2) { + result->ptr = xdl_malloc(mf1->size); + memcpy(result->ptr, mf1->ptr, mf1->size); + result->size = mf1->size; + } else { + status = xdl_do_merge(&xe1, xscr1, name1, + &xe2, xscr2, name2, + level, xpp, result); } + xdl_free_script(xscr1); + xdl_free_script(xscr2); + xdl_free_env(&xe1); xdl_free_env(&xe2); -- cgit v1.2.1