refactor merge flags into xmparam_t
[gitweb.git] / ll-merge.c
index 0dcaae0dd166205e6d17a523789b4b82e5a01f18..82c7742e41f4645e7d6086bb277437a84ff4f03b 100644 (file)
@@ -18,7 +18,7 @@ typedef int (*ll_merge_fn)(const struct ll_merge_driver *,
                           mmfile_t *orig,
                           mmfile_t *src1, const char *name1,
                           mmfile_t *src2, const char *name2,
-                          int virtual_ancestor,
+                          int flag,
                           int marker_size);
 
 struct ll_merge_driver {
@@ -39,14 +39,14 @@ static int ll_binary_merge(const struct ll_merge_driver *drv_unused,
                           mmfile_t *orig,
                           mmfile_t *src1, const char *name1,
                           mmfile_t *src2, const char *name2,
-                          int virtual_ancestor, int marker_size)
+                          int flag, int marker_size)
 {
        /*
         * The tentative merge result is "ours" for the final round,
         * or common ancestor for an internal merge.  Still return
         * "conflicted merge" status.
         */
-       mmfile_t *stolen = virtual_ancestor ? orig : src1;
+       mmfile_t *stolen = (flag & 01) ? orig : src1;
 
        result->ptr = stolen->ptr;
        result->size = stolen->size;
@@ -60,10 +60,9 @@ static int ll_xdl_merge(const struct ll_merge_driver *drv_unused,
                        mmfile_t *orig,
                        mmfile_t *src1, const char *name1,
                        mmfile_t *src2, const char *name2,
-                       int virtual_ancestor, int marker_size)
+                       int flag, int marker_size)
 {
        xmparam_t xmp;
-       int style = 0;
 
        if (buffer_is_binary(orig->ptr, orig->size) ||
            buffer_is_binary(src1->ptr, src1->size) ||
@@ -74,19 +73,17 @@ static int ll_xdl_merge(const struct ll_merge_driver *drv_unused,
                                       path,
                                       orig, src1, name1,
                                       src2, name2,
-                                      virtual_ancestor, marker_size);
+                                      flag, marker_size);
        }
 
        memset(&xmp, 0, sizeof(xmp));
+       xmp.level = XDL_MERGE_ZEALOUS;
+       xmp.favor= (flag >> 1) & 03;
        if (git_xmerge_style >= 0)
-               style = git_xmerge_style;
+               xmp.style = git_xmerge_style;
        if (marker_size > 0)
                xmp.marker_size = marker_size;
-       return xdl_merge(orig,
-                        src1, name1,
-                        src2, name2,
-                        &xmp, XDL_MERGE_ZEALOUS | style,
-                        result);
+       return xdl_merge(orig, src1, name1, src2, name2, &xmp, result);
 }
 
 static int ll_union_merge(const struct ll_merge_driver *drv_unused,
@@ -95,46 +92,13 @@ static int ll_union_merge(const struct ll_merge_driver *drv_unused,
                          mmfile_t *orig,
                          mmfile_t *src1, const char *name1,
                          mmfile_t *src2, const char *name2,
-                         int virtual_ancestor, int marker_size)
+                         int flag, int marker_size)
 {
-       char *src, *dst;
-       long size;
-       int status, saved_style;
-
-       /* We have to force the RCS "merge" style */
-       saved_style = git_xmerge_style;
-       git_xmerge_style = 0;
-       status = ll_xdl_merge(drv_unused, result, path_unused,
-                             orig, src1, NULL, src2, NULL,
-                             virtual_ancestor, marker_size);
-       git_xmerge_style = saved_style;
-       if (status <= 0)
-               return status;
-       size = result->size;
-       src = dst = result->ptr;
-       while (size) {
-               char ch;
-               if ((marker_size < size) &&
-                   (*src == '<' || *src == '=' || *src == '>')) {
-                       int i;
-                       ch = *src;
-                       for (i = 0; i < marker_size; i++)
-                               if (src[i] != ch)
-                                       goto not_a_marker;
-                       if (src[marker_size] != '\n')
-                               goto not_a_marker;
-                       src += marker_size + 1;
-                       size -= marker_size + 1;
-                       continue;
-               }
-       not_a_marker:
-               do {
-                       ch = *src++;
-                       *dst++ = ch;
-                       size--;
-               } while (ch != '\n' && size);
-       }
-       result->size = dst - result->ptr;
+       /* Use union favor */
+       flag = (flag & 1) | (XDL_MERGE_FAVOR_UNION << 1);
+       return ll_xdl_merge(drv_unused, result, path_unused,
+                           orig, src1, NULL, src2, NULL,
+                           flag, marker_size);
        return 0;
 }
 
@@ -167,7 +131,7 @@ static int ll_ext_merge(const struct ll_merge_driver *fn,
                        mmfile_t *orig,
                        mmfile_t *src1, const char *name1,
                        mmfile_t *src2, const char *name2,
-                       int virtual_ancestor, int marker_size)
+                       int flag, int marker_size)
 {
        char temp[4][50];
        struct strbuf cmd = STRBUF_INIT;
@@ -178,7 +142,7 @@ static int ll_ext_merge(const struct ll_merge_driver *fn,
                { "L", temp[3] },
                { NULL }
        };
-       const char *args[] = { "sh", "-c", NULL, NULL };
+       const char *args[] = { NULL, NULL };
        int status, fd, i;
        struct stat st;
 
@@ -194,8 +158,8 @@ static int ll_ext_merge(const struct ll_merge_driver *fn,
 
        strbuf_expand(&cmd, fn->cmdline, strbuf_expand_dict_cb, &dict);
 
-       args[2] = cmd.buf;
-       status = run_command_v_opt(args, 0);
+       args[0] = cmd.buf;
+       status = run_command_v_opt(args, RUN_USING_SHELL);
        fd = open(temp[1], O_RDONLY);
        if (fd < 0)
                goto bad;
@@ -358,12 +322,13 @@ int ll_merge(mmbuffer_t *result_buf,
             mmfile_t *ancestor,
             mmfile_t *ours, const char *our_label,
             mmfile_t *theirs, const char *their_label,
-            int virtual_ancestor)
+            int flag)
 {
        static struct git_attr_check check[2];
        const char *ll_driver_name = NULL;
        int marker_size = DEFAULT_CONFLICT_MARKER_SIZE;
        const struct ll_merge_driver *driver;
+       int virtual_ancestor = flag & 01;
 
        if (!git_path_check_merge(path, check)) {
                ll_driver_name = check[0].value;
@@ -378,7 +343,7 @@ int ll_merge(mmbuffer_t *result_buf,
                driver = find_ll_merge_driver(driver->recursive);
        return driver->fn(driver, result_buf, path, ancestor,
                          ours, our_label, theirs, their_label,
-                         virtual_ancestor, marker_size);
+                         flag, marker_size);
 }
 
 int ll_merge_marker_size(const char *path)