#include "cache.h"
#include "string-list.h"
#include "rerere.h"
-#include "xdiff/xdiff.h"
#include "xdiff-interface.h"
#include "dir.h"
#include "resolve-undo.h"
#include "ll-merge.h"
+#include "attr.h"
/* if rerere_enabled == -1, fall back to detection of .git/rr-cache */
static int rerere_enabled = -1;
ferr_puts(str, io->output, &io->wrerror);
}
+static void rerere_io_putconflict(int ch, int size, struct rerere_io *io)
+{
+ char buf[64];
+
+ while (size) {
+ if (size < sizeof(buf) - 2) {
+ memset(buf, ch, size);
+ buf[size] = '\n';
+ buf[size + 1] = '\0';
+ size = 0;
+ } else {
+ int sz = sizeof(buf) - 1;
+ if (size <= sz)
+ sz -= (sz - size) + 1;
+ memset(buf, ch, sz);
+ buf[sz] = '\0';
+ size -= sz;
+ }
+ rerere_io_putstr(buf, io);
+ }
+}
+
static void rerere_io_putmem(const char *mem, size_t sz, struct rerere_io *io)
{
if (io->output)
return strbuf_getwholeline(sb, io->input, '\n');
}
-static int handle_path(unsigned char *sha1, struct rerere_io *io)
+static int is_cmarker(char *buf, int marker_char, int marker_size, int want_sp)
+{
+ while (marker_size--)
+ if (*buf++ != marker_char)
+ return 0;
+ if (want_sp && *buf != ' ')
+ return 0;
+ return isspace(*buf);
+}
+
+static int handle_path(unsigned char *sha1, struct rerere_io *io, int marker_size)
{
git_SHA_CTX ctx;
int hunk_no = 0;
git_SHA1_Init(&ctx);
while (!io->getline(&buf, io)) {
- if (!prefixcmp(buf.buf, "<<<<<<< ")) {
+ if (is_cmarker(buf.buf, '<', marker_size, 1)) {
if (hunk != RR_CONTEXT)
goto bad;
hunk = RR_SIDE_1;
- } else if (!prefixcmp(buf.buf, "|||||||") && isspace(buf.buf[7])) {
+ } else if (is_cmarker(buf.buf, '|', marker_size, 0)) {
if (hunk != RR_SIDE_1)
goto bad;
hunk = RR_ORIGINAL;
- } else if (!prefixcmp(buf.buf, "=======") && isspace(buf.buf[7])) {
+ } else if (is_cmarker(buf.buf, '=', marker_size, 0)) {
if (hunk != RR_SIDE_1 && hunk != RR_ORIGINAL)
goto bad;
hunk = RR_SIDE_2;
- } else if (!prefixcmp(buf.buf, ">>>>>>> ")) {
+ } else if (is_cmarker(buf.buf, '>', marker_size, 1)) {
if (hunk != RR_SIDE_2)
goto bad;
if (strbuf_cmp(&one, &two) > 0)
strbuf_swap(&one, &two);
hunk_no++;
hunk = RR_CONTEXT;
- rerere_io_putstr("<<<<<<<\n", io);
+ rerere_io_putconflict('<', marker_size, io);
rerere_io_putmem(one.buf, one.len, io);
- rerere_io_putstr("=======\n", io);
+ rerere_io_putconflict('=', marker_size, io);
rerere_io_putmem(two.buf, two.len, io);
- rerere_io_putstr(">>>>>>>\n", io);
+ rerere_io_putconflict('>', marker_size, io);
if (sha1) {
git_SHA1_Update(&ctx, one.buf ? one.buf : "",
one.len + 1);
{
int hunk_no = 0;
struct rerere_io_file io;
+ int marker_size = ll_merge_marker_size(path);
memset(&io, 0, sizeof(io));
io.io.getline = rerere_file_getline;
}
}
- hunk_no = handle_path(sha1, (struct rerere_io *)&io);
+ hunk_no = handle_path(sha1, (struct rerere_io *)&io, marker_size);
fclose(io.input);
if (io.io.wrerror)
struct cache_entry *ce;
int pos, len, i, hunk_no;
struct rerere_io_mem io;
+ int marker_size = ll_merge_marker_size(path);
/*
* Reproduce the conflicted merge in-core
strbuf_init(&io.input, 0);
strbuf_attach(&io.input, result.ptr, result.size, result.size);
- hunk_no = handle_path(sha1, (struct rerere_io *)&io);
+ hunk_no = handle_path(sha1, (struct rerere_io *)&io, marker_size);
strbuf_release(&io.input);
if (io.io.output)
fclose(io.io.output);
int ret;
mmfile_t cur, base, other;
mmbuffer_t result = {NULL, 0};
- xpparam_t xpp = {XDF_NEED_MINIMAL};
if (handle_file(path, NULL, rerere_path(name, "thisimage")) < 0)
return 1;
read_mmfile(&base, rerere_path(name, "preimage")) ||
read_mmfile(&other, rerere_path(name, "postimage")))
return 1;
- ret = xdl_merge(&base, &cur, "", &other, "",
- &xpp, XDL_MERGE_ZEALOUS, &result);
+ ret = ll_merge(&result, path, &base, &cur, "", &other, "", 0);
if (!ret) {
FILE *f = fopen(path, "w");
if (!f)