submodule summary: do not fail before the first commit
[gitweb.git] / merge-file.c
index 69dc1ebbf7685f3dd30dcca64974eabba8ee137b..fd34d76e1516b2c944778a11a5670d382f245873 100644 (file)
@@ -1,18 +1,19 @@
 #include "cache.h"
 #include "run-command.h"
 #include "xdiff-interface.h"
+#include "ll-merge.h"
 #include "blob.h"
 
 static int fill_mmfile_blob(mmfile_t *f, struct blob *obj)
 {
        void *buf;
        unsigned long size;
-       char type[20];
+       enum object_type type;
 
-       buf = read_sha1_file(obj->object.sha1, type, &size);
+       buf = read_sha1_file(obj->object.sha1, &type, &size);
        if (!buf)
                return -1;
-       if (strcmp(type, blob_type))
+       if (type != OBJ_BLOB)
                return -1;
        f->ptr = buf;
        f->size = size;
@@ -24,16 +25,13 @@ static void free_mmfile(mmfile_t *f)
        free(f->ptr);
 }
 
-static void *three_way_filemerge(mmfile_t *base, mmfile_t *our, mmfile_t *their, unsigned long *size)
+static void *three_way_filemerge(const char *path, mmfile_t *base, mmfile_t *our, mmfile_t *their, unsigned long *size)
 {
-       mmbuffer_t res;
-       xpparam_t xpp;
        int merge_status;
+       mmbuffer_t res;
 
-       memset(&xpp, 0, sizeof(xpp));
-       merge_status = xdl_merge(base, our, ".our", their, ".their",
-               &xpp, XDL_MERGE_ZEALOUS, &res);
-
+       merge_status = ll_merge(&res, path, base,
+                               our, ".our", their, ".their", 0);
        if (merge_status < 0)
                return NULL;
 
@@ -61,7 +59,9 @@ static int generate_common_file(mmfile_t *res, mmfile_t *f1, mmfile_t *f2)
        xdemitconf_t xecfg;
        xdemitcb_t ecb;
 
+       memset(&xpp, 0, sizeof(xpp));
        xpp.flags = XDF_NEED_MINIMAL;
+       memset(&xecfg, 0, sizeof(xecfg));
        xecfg.ctxlen = 3;
        xecfg.flags = XDL_EMIT_COMMON;
        ecb.outf = common_outf;
@@ -70,10 +70,10 @@ static int generate_common_file(mmfile_t *res, mmfile_t *f1, mmfile_t *f2)
        res->size = 0;
 
        ecb.priv = res;
-       return xdl_diff(f1, f2, &xpp, &xecfg, &ecb);
+       return xdi_diff(f1, f2, &xpp, &xecfg, &ecb);
 }
 
-void *merge_file(struct blob *base, struct blob *our, struct blob *their, unsigned long *size)
+void *merge_file(const char *path, struct blob *base, struct blob *our, struct blob *their, unsigned long *size)
 {
        void *res = NULL;
        mmfile_t f1, f2, common;
@@ -86,12 +86,12 @@ void *merge_file(struct blob *base, struct blob *our, struct blob *their, unsign
         * modified in the other branch!
         */
        if (!our || !their) {
-               char type[20];
+               enum object_type type;
                if (base)
                        return NULL;
                if (!our)
                        our = their;
-               return read_sha1_file(our->object.sha1, type, size);
+               return read_sha1_file(our->object.sha1, &type, size);
        }
 
        if (fill_mmfile_blob(&f1, our) < 0)
@@ -106,7 +106,7 @@ void *merge_file(struct blob *base, struct blob *our, struct blob *their, unsign
                if (generate_common_file(&common, &f1, &f2) < 0)
                        goto out_free_f2_f1;
        }
-       res = three_way_filemerge(&common, &f1, &f2, size);
+       res = three_way_filemerge(path, &common, &f1, &f2, size);
        free_mmfile(&common);
 out_free_f2_f1:
        free_mmfile(&f2);