Re-implement 'git remote update' using 'git fetch'
[gitweb.git] / ll-merge.c
index e339b8cfaca7c3a08fae4b9c54b76c0351101a2b..2d6b6d6cb1d2bc2d334bf058feb3444e94b5a781 100644 (file)
@@ -8,7 +8,6 @@
 #include "attr.h"
 #include "xdiff-interface.h"
 #include "run-command.h"
-#include "interpolate.h"
 #include "ll-merge.h"
 
 struct ll_merge_driver;
@@ -56,31 +55,34 @@ static int ll_binary_merge(const struct ll_merge_driver *drv_unused,
 
 static int ll_xdl_merge(const struct ll_merge_driver *drv_unused,
                        mmbuffer_t *result,
-                       const char *path_unused,
+                       const char *path,
                        mmfile_t *orig,
                        mmfile_t *src1, const char *name1,
                        mmfile_t *src2, const char *name2,
                        int virtual_ancestor)
 {
        xpparam_t xpp;
+       int style = 0;
 
        if (buffer_is_binary(orig->ptr, orig->size) ||
            buffer_is_binary(src1->ptr, src1->size) ||
            buffer_is_binary(src2->ptr, src2->size)) {
-               warning("Cannot merge binary files: %s vs. %s\n",
-                       name1, name2);
+               warning("Cannot merge binary files: %s (%s vs. %s)\n",
+                       path, name1, name2);
                return ll_binary_merge(drv_unused, result,
-                                      path_unused,
+                                      path,
                                       orig, src1, name1,
                                       src2, name2,
                                       virtual_ancestor);
        }
 
        memset(&xpp, 0, sizeof(xpp));
+       if (git_xmerge_style >= 0)
+               style = git_xmerge_style;
        return xdl_merge(orig,
                         src1, name1,
                         src2, name2,
-                        &xpp, XDL_MERGE_ZEALOUS,
+                        &xpp, XDL_MERGE_ZEALOUS | style,
                         result);
 }
 
@@ -95,10 +97,15 @@ static int ll_union_merge(const struct ll_merge_driver *drv_unused,
        char *src, *dst;
        long size;
        const int marker_size = 7;
-
-       int status = ll_xdl_merge(drv_unused, result, path_unused,
-                                 orig, src1, NULL, src2, NULL,
-                                 virtual_ancestor);
+       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);
+       git_xmerge_style = saved_style;
        if (status <= 0)
                return status;
        size = result->size;
@@ -145,7 +152,7 @@ static void create_temp(mmfile_t *src, char *path)
        strcpy(path, ".merge_file_XXXXXX");
        fd = xmkstemp(path);
        if (write_in_full(fd, src->ptr, src->size) != src->size)
-               die("unable to write temp-file");
+               die_errno("unable to write temp-file");
        close(fd);
 }
 
@@ -161,14 +168,14 @@ static int ll_ext_merge(const struct ll_merge_driver *fn,
                        int virtual_ancestor)
 {
        char temp[3][50];
-       char cmdbuf[2048];
-       struct interp table[] = {
-               { "%O" },
-               { "%A" },
-               { "%B" },
+       struct strbuf cmd = STRBUF_INIT;
+       struct strbuf_expand_dict_entry dict[] = {
+               { "O", temp[0] },
+               { "A", temp[1] },
+               { "B", temp[2] },
+               { NULL }
        };
-       struct child_process child;
-       const char *args[20];
+       const char *args[] = { "sh", "-c", NULL, NULL };
        int status, fd, i;
        struct stat st;
 
@@ -181,24 +188,10 @@ static int ll_ext_merge(const struct ll_merge_driver *fn,
        create_temp(src1, temp[1]);
        create_temp(src2, temp[2]);
 
-       interp_set_entry(table, 0, temp[0]);
-       interp_set_entry(table, 1, temp[1]);
-       interp_set_entry(table, 2, temp[2]);
-
-       interpolate(cmdbuf, sizeof(cmdbuf), fn->cmdline, table, 3);
+       strbuf_expand(&cmd, fn->cmdline, strbuf_expand_dict_cb, &dict);
 
-       memset(&child, 0, sizeof(child));
-       child.argv = args;
-       args[0] = "sh";
-       args[1] = "-c";
-       args[2] = cmdbuf;
-       args[3] = NULL;
-
-       status = run_command(&child);
-       if (status < -ERR_RUN_COMMAND_FORK)
-               ; /* failure in run-command */
-       else
-               status = -status;
+       args[2] = cmd.buf;
+       status = run_command_v_opt(args, 0);
        fd = open(temp[1], O_RDONLY);
        if (fd < 0)
                goto bad;
@@ -215,7 +208,8 @@ static int ll_ext_merge(const struct ll_merge_driver *fn,
        close(fd);
  bad:
        for (i = 0; i < 3; i++)
-               unlink(temp[i]);
+               unlink_or_warn(temp[i]);
+       strbuf_release(&cmd);
        return status;
 }