Skip to content

Commit

Permalink
merge: teach -Xours/-Xtheirs to binary ll-merge driver
Browse files Browse the repository at this point in the history
The (discouraged) -Xours/-Xtheirs modes of merge are supposed to
give a quick and dirty way to come up with a random mixture of
cleanly merged parts and punted conflict resolution to take contents
from one side in conflicting parts.  These options however were only
passed down to the low level merge driver for text.

Teach the built-in binary merge driver to notice them as well.

Signed-off-by: Junio C Hamano <[email protected]>
  • Loading branch information
gitster committed Sep 9, 2012
1 parent d0f1ea6 commit a944af1
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 7 deletions.
3 changes: 2 additions & 1 deletion Documentation/merge-strategies.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@ ours;;
This option forces conflicting hunks to be auto-resolved cleanly by
favoring 'our' version. Changes from the other tree that do not
conflict with our side are reflected to the merge result.
For a binary file, the entire contents are taken from our side.
+
This should not be confused with the 'ours' merge strategy, which does not
even look at what the other tree contains at all. It discards everything
the other tree did, declaring 'our' history contains all that happened in it.

theirs;;
This is opposite of 'ours'.
This is the opposite of 'ours'.

patience;;
With this option, 'merge-recursive' spends a little extra time
Expand Down
25 changes: 20 additions & 5 deletions ll-merge.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,31 @@ static int ll_binary_merge(const struct ll_merge_driver *drv_unused,
assert(opts);

/*
* The tentative merge result is "ours" for the final round,
* or common ancestor for an internal merge. Still return
* "conflicted merge" status.
* The tentative merge result is the or common ancestor for an internal merge.
*/
stolen = opts->virtual_ancestor ? orig : src1;
if (opts->virtual_ancestor) {
stolen = orig;
} else {
switch (opts->variant) {
default:
case XDL_MERGE_FAVOR_OURS:
stolen = src1;
break;
case XDL_MERGE_FAVOR_THEIRS:
stolen = src2;
break;
}
}

result->ptr = stolen->ptr;
result->size = stolen->size;
stolen->ptr = NULL;
return 1;

/*
* With -Xtheirs or -Xours, we have cleanly merged;
* otherwise we got a conflict.
*/
return (opts->variant ? 0 : 1);
}

static int ll_xdl_merge(const struct ll_merge_driver *drv_unused,
Expand Down
14 changes: 13 additions & 1 deletion t/t6037-merge-ours-theirs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,19 @@ test_expect_success 'recursive favouring ours' '
! grep 1 file
'

test_expect_success 'pull with -X' '
test_expect_success 'binary file with -Xours/-Xtheirs' '
echo "file -merge" >.gitattributes &&
git reset --hard master &&
git merge -s recursive -X theirs side &&
git diff --exit-code side HEAD -- file &&
git reset --hard master &&
git merge -s recursive -X ours side &&
git diff --exit-code master HEAD -- file
'

test_expect_success 'pull passes -X to underlying merge' '
git reset --hard master && git pull -s recursive -Xours . side &&
git reset --hard master && git pull -s recursive -X ours . side &&
git reset --hard master && git pull -s recursive -Xtheirs . side &&
Expand Down

0 comments on commit a944af1

Please sign in to comment.