xdiff-merge: optionally show conflicts in "diff3 -m" style

When showing conflicting merges, we traditionally followed RCS's merge
output format.  The output shows:

 <<<<<<<
 postimage from one side;
 =======
 postimage of the other side; and
 >>>>>>>

Some poeple find it easier to be able to understand what is going on when
they can view the common ancestor's version, which is used by "diff3 -m",
which shows:

 <<<<<<<
 postimage from one side;
 |||||||
 shared preimage;
 =======
 postimage of the other side; and
 >>>>>>>

This is an initial step to bring that as an optional feature to git.
Only "git merge-file" has been converted, with "--diff3" option.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Junio C Hamano
2008-08-28 01:10:04 -07:00
parent f2b25dd81f
commit e0af48e496
4 changed files with 135 additions and 21 deletions

View File

@ -4,7 +4,7 @@
#include "xdiff-interface.h"
static const char merge_file_usage[] =
"git merge-file [-p | --stdout] [-q | --quiet] [-L name1 [-L orig [-L name2]]] file1 orig_file file2";
"git merge-file [-p | --stdout] [--diff3] [-q | --quiet] [-L name1 [-L orig [-L name2]]] file1 orig_file file2";
int cmd_merge_file(int argc, const char **argv, const char *prefix)
{
@ -13,6 +13,8 @@ int cmd_merge_file(int argc, const char **argv, const char *prefix)
mmbuffer_t result = {NULL, 0};
xpparam_t xpp = {XDF_NEED_MINIMAL};
int ret = 0, i = 0, to_stdout = 0;
int merge_level = XDL_MERGE_ZEALOUS_ALNUM;
int merge_style = 0;
while (argc > 4) {
if (!strcmp(argv[1], "-L") && i < 3) {
@ -25,6 +27,10 @@ int cmd_merge_file(int argc, const char **argv, const char *prefix)
else if (!strcmp(argv[1], "-q") ||
!strcmp(argv[1], "--quiet"))
freopen("/dev/null", "w", stderr);
else if (!strcmp(argv[1], "--diff3")) {
merge_style = XDL_MERGE_DIFF3;
merge_level = XDL_MERGE_EAGER;
}
else
usage(merge_file_usage);
argc--;
@ -46,7 +52,7 @@ int cmd_merge_file(int argc, const char **argv, const char *prefix)
}
ret = xdl_merge(mmfs + 1, mmfs + 0, names[0], mmfs + 2, names[2],
&xpp, XDL_MERGE_ZEALOUS_ALNUM, &result);
&xpp, merge_level | merge_style, &result);
for (i = 0; i < 3; i++)
free(mmfs[i].ptr);