merge-file: ensure that conflict sections match eol style
In the previous patch, we made sure that the conflict markers themselves
match the end-of-line style of the input files. However, this still left
out the conflicting text itself: if it lacks a trailing newline, we
add one, and should add a carriage return when appropriate, too.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
maint
Johannes Schindelin9 years agocommitted byJunio C Hamano
@ -346,13 +346,14 @@ test_expect_success 'conflict at EOF without LF resolved by --union' \
@@ -346,13 +346,14 @@ test_expect_success 'conflict at EOF without LF resolved by --union' \
@ -109,7 +109,7 @@ static int xdl_merge_cmp_lines(xdfenv_t *xe1, int i1, xdfenv_t *xe2, int i2,
@@ -109,7 +109,7 @@ static int xdl_merge_cmp_lines(xdfenv_t *xe1, int i1, xdfenv_t *xe2, int i2,
return 0;
}
static int xdl_recs_copy_0(int use_orig, xdfenv_t *xe, int i, int count, int add_nl, char *dest)
static int xdl_recs_copy_0(int use_orig, xdfenv_t *xe, int i, int count, int needs_cr, int add_nl, char *dest)
{
xrecord_t **recs;
int size = 0;
@ -125,6 +125,12 @@ static int xdl_recs_copy_0(int use_orig, xdfenv_t *xe, int i, int count, int add
@@ -125,6 +125,12 @@ static int xdl_recs_copy_0(int use_orig, xdfenv_t *xe, int i, int count, int add
if (add_nl) {
i = recs[count - 1]->size;
if (i == 0 || recs[count - 1]->ptr[i - 1] != '\n') {
if (needs_cr) {
if (dest)
dest[size] = '\r';
size++;
}
if (dest)
dest[size] = '\n';
size++;
@ -133,14 +139,14 @@ static int xdl_recs_copy_0(int use_orig, xdfenv_t *xe, int i, int count, int add
@@ -133,14 +139,14 @@ static int xdl_recs_copy_0(int use_orig, xdfenv_t *xe, int i, int count, int add
return size;
}
static int xdl_recs_copy(xdfenv_t *xe, int i, int count, int add_nl, char *dest)
static int xdl_recs_copy(xdfenv_t *xe, int i, int count, int needs_cr, int add_nl, char *dest)
{
return xdl_recs_copy_0(0, xe, i, count, add_nl, dest);
return xdl_recs_copy_0(0, xe, i, count, needs_cr, add_nl, dest);
}
static int xdl_orig_copy(xdfenv_t *xe, int i, int count, int add_nl, char *dest)
static int xdl_orig_copy(xdfenv_t *xe, int i, int count, int needs_cr, int add_nl, char *dest)
{
return xdl_recs_copy_0(1, xe, i, count, add_nl, dest);
return xdl_recs_copy_0(1, xe, i, count, needs_cr, add_nl, dest);