Exemple #1
0
static int xdl_fill_merge_buffer(size_t *out,
				 xdfenv_t *xe1, const char *name1,
				 xdfenv_t *xe2, const char *name2,
				 const char *ancestor_name,
				 int favor,
				 xdmerge_t *m, char *dest, int style,
				 int marker_size)
{
	size_t size, copied;
	int i;

	*out = 0;

	for (size = i = 0; m; m = m->next) {
		if (favor && !m->mode)
			m->mode = favor;

		if (m->mode == 0) {
			if (fill_conflict_hunk(&size, xe1, name1, xe2, name2,
						  ancestor_name,
						  size, i, style, m, dest,
						  marker_size) < 0)
				return -1;
		}
		else if (m->mode & 3) {
			/* Before conflicting part */
			if (xdl_recs_copy(&copied, xe1, i, m->i1 - i, 0,
					      dest ? dest + size : NULL) < 0)
				return -1;
			GITERR_CHECK_ALLOC_ADD(&size, size, copied);

			/* Postimage from side #1 */
			if (m->mode & 1) {
				if (xdl_recs_copy(&copied, xe1, m->i1, m->chg1, (m->mode & 2),
						      dest ? dest + size : NULL) < 0)
					return -1;
				GITERR_CHECK_ALLOC_ADD(&size, size, copied);
			}

			/* Postimage from side #2 */
			if (m->mode & 2) {
				if (xdl_recs_copy(&copied, xe2, m->i2, m->chg2, 0,
						      dest ? dest + size : NULL) < 0)
					return -1;
				GITERR_CHECK_ALLOC_ADD(&size, size, copied);
			}
		} else
			continue;
		i = m->i1 + m->chg1;
	}

	if (xdl_recs_copy(&copied, xe1, i, xe1->xdf2.nrec - i, 0,
			      dest ? dest + size : NULL) < 0)
		return -1;
	GITERR_CHECK_ALLOC_ADD(&size, size, copied);

	*out = size;
	return 0;
}
Exemple #2
0
static int xdl_fill_merge_buffer(xdfenv_t *xe1, const char *name1,
				 xdfenv_t *xe2, const char *name2,
				 const char *ancestor_name,
				 int favor,
				 xdmerge_t *m, char *dest, int style,
				 int marker_size, int mark_all)
{
	int size, i;

	for (size = i = 0; m; m = m->next) {
		if (favor && !m->mode)
			m->mode = favor;

		if (m->mode == 0)
			size = fill_conflict_hunk(xe1, name1, xe2, name2,
						  ancestor_name,
						  size, i, style, m, dest,
						  marker_size);
		else if (m->mode & 3) {
			if (mark_all) {
				/* Before conflicting part */
				size += xdl_recs_copy(xe1, i, m->i1 - i, 0,
						      dest ? dest + size : NULL);
				/* Postimage from side #1 */
				if (m->mode & 1)
					size += xdl_recs_copy(xe1, m->i1, m->chg1, (m->mode & 2),
							      dest ? dest + size : NULL);
				/* Postimage from side #2 */
				if (m->mode & 2)
					size += xdl_recs_copy(xe2, m->i2, m->chg2, 0,
							      dest ? dest + size : NULL);
			} else {
				if (m->mode & 1)
					size += fill_ours_hunk(xe1, name1,
			      	ancestor_name, size, i, style, m,
							dest, marker_size);
				if (m->mode & 2)
					size += fill_theirs_hunk(xe2, name2,
			      	ancestor_name, size, i, style, m,
							dest, marker_size);
			}
		} else
		continue;
		i = m->i1 + m->chg1;
	}
	size += xdl_recs_copy(xe1, i, xe1->xdf2.nrec - i, 0,
			      dest ? dest + size : NULL);
	return size;
}