xdl_fill_merge_buffer(): separate out a too deeply nested function

This simply moves code around to make a separate function that prepares
a single conflicted hunk with markers into the buffer.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Junio C Hamano 2008-08-28 01:04:00 -07:00
Родитель 53d1589ff6
Коммит f2b25dd81f
1 изменённых файлов: 69 добавлений и 50 удалений

Просмотреть файл

@ -113,65 +113,84 @@ static int xdl_recs_copy(xdfenv_t *xe, int i, int count, int add_nl, char *dest)
return size;
}
static int xdl_fill_merge_buffer(xdfenv_t *xe1, const char *name1,
xdfenv_t *xe2, const char *name2, xdmerge_t *m, char *dest)
static int fill_conflict_hunk(xdfenv_t *xe1, const char *name1,
xdfenv_t *xe2, const char *name2,
int size, int i,
xdmerge_t *m, char *dest)
{
const int marker_size = 7;
int marker1_size = (name1 ? strlen(name1) + 1 : 0);
int marker2_size = (name2 ? strlen(name2) + 1 : 0);
int conflict_marker_size = 3 * (marker_size + 1)
+ marker1_size + marker2_size;
int size, i1, j;
int j;
for (size = i1 = 0; m; m = m->next) {
if (m->mode == 0) {
size += xdl_recs_copy(xe1, i1, m->i1 - i1, 0,
dest ? dest + size : NULL);
if (dest) {
for (j = 0; j < marker_size; j++)
dest[size++] = '<';
if (marker1_size) {
dest[size] = ' ';
memcpy(dest + size + 1, name1,
marker1_size - 1);
size += marker1_size;
}
dest[size++] = '\n';
} else
size += conflict_marker_size;
size += xdl_recs_copy(xe1, m->i1, m->chg1, 1,
dest ? dest + size : NULL);
if (dest) {
for (j = 0; j < marker_size; j++)
dest[size++] = '=';
dest[size++] = '\n';
}
size += xdl_recs_copy(xe2, m->i2, m->chg2, 1,
dest ? dest + size : NULL);
if (dest) {
for (j = 0; j < marker_size; j++)
dest[size++] = '>';
if (marker2_size) {
dest[size] = ' ';
memcpy(dest + size + 1, name2,
marker2_size - 1);
size += marker2_size;
}
dest[size++] = '\n';
}
} else if (m->mode == 1)
size += xdl_recs_copy(xe1, i1, m->i1 + m->chg1 - i1, 0,
dest ? dest + size : NULL);
/* Before conflicting part */
size += xdl_recs_copy(xe1, i, m->i1 - i, 0,
dest ? dest + size : NULL);
if (!dest) {
size += marker_size + 1 + marker1_size;
} else {
for (j = 0; j < marker_size; j++)
dest[size++] = '<';
if (marker1_size) {
dest[size] = ' ';
memcpy(dest + size + 1, name1, marker1_size - 1);
size += marker1_size;
}
dest[size++] = '\n';
}
/* Postimage from side #1 */
size += xdl_recs_copy(xe1, m->i1, m->chg1, 1,
dest ? dest + size : NULL);
if (!dest) {
size += marker_size + 1;
} else {
for (j = 0; j < marker_size; j++)
dest[size++] = '=';
dest[size++] = '\n';
}
/* Postimage from side #2 */
size += xdl_recs_copy(xe2, m->i2, m->chg2, 1,
dest ? dest + size : NULL);
if (!dest) {
size += marker_size + 1 + marker2_size;
} else {
for (j = 0; j < marker_size; j++)
dest[size++] = '>';
if (marker2_size) {
dest[size] = ' ';
memcpy(dest + size + 1, name2, marker2_size - 1);
size += marker2_size;
}
dest[size++] = '\n';
}
return size;
}
static int xdl_fill_merge_buffer(xdfenv_t *xe1, const char *name1,
xdfenv_t *xe2, const char *name2, xdmerge_t *m, char *dest)
{
int size, i;
for (size = i = 0; m; m = m->next) {
if (m->mode == 0)
size = fill_conflict_hunk(xe1, name1, xe2, name2,
size, i, m, dest);
else if (m->mode == 1)
size += xdl_recs_copy(xe1, i, m->i1 + m->chg1 - i, 0,
dest ? dest + size : NULL);
else if (m->mode == 2)
size += xdl_recs_copy(xe2, m->i2 - m->i1 + i1,
m->i1 + m->chg2 - i1, 0,
dest ? dest + size : NULL);
size += xdl_recs_copy(xe2, m->i2 - m->i1 + i,
m->i1 + m->chg2 - i, 0,
dest ? dest + size : NULL);
else
continue;
i1 = m->i1 + m->chg1;
i = m->i1 + m->chg1;
}
size += xdl_recs_copy(xe1, i1, xe1->xdf2.nrec - i1, 0,
dest ? dest + size : NULL);
size += xdl_recs_copy(xe1, i, xe1->xdf2.nrec - i, 0,
dest ? dest + size : NULL);
return size;
}