Avoid conflicts when merging branches with mixed normalization
[gitweb.git] / ll-merge.c
index f9b3d854a921ab6fa3eed6f4dbf01af1a8657602..5068fe069faeef07363407c622624264c5cf3a6c 100644 (file)
@@ -139,17 +139,17 @@ static int ll_ext_merge(const struct ll_merge_driver *fn,
 {
        char temp[4][50];
        struct strbuf cmd = STRBUF_INIT;
-       struct strbuf_expand_dict_entry dict[] = {
-               { "O", temp[0] },
-               { "A", temp[1] },
-               { "B", temp[2] },
-               { "L", temp[3] },
-               { NULL }
-       };
+       struct strbuf_expand_dict_entry dict[5];
        const char *args[] = { NULL, NULL };
        int status, fd, i;
        struct stat st;
 
+       dict[0].placeholder = "O"; dict[0].value = temp[0];
+       dict[1].placeholder = "A"; dict[1].value = temp[1];
+       dict[2].placeholder = "B"; dict[2].value = temp[2];
+       dict[3].placeholder = "L"; dict[3].value = temp[3];
+       dict[4].placeholder = NULL; dict[4].value = NULL;
+
        if (fn->cmdline == NULL)
                die("custom merge driver %s lacks command line.", fn->name);
 
@@ -321,6 +321,16 @@ static int git_path_check_merge(const char *path, struct git_attr_check check[2]
        return git_checkattr(path, 2, check);
 }
 
+static void normalize_file(mmfile_t *mm, const char *path)
+{
+       struct strbuf strbuf = STRBUF_INIT;
+       if (renormalize_buffer(path, mm->ptr, mm->size, &strbuf)) {
+               free(mm->ptr);
+               mm->size = strbuf.len;
+               mm->ptr = strbuf_detach(&strbuf, NULL);
+       }
+}
+
 int ll_merge(mmbuffer_t *result_buf,
             const char *path,
             mmfile_t *ancestor, const char *ancestor_label,
@@ -334,6 +344,11 @@ int ll_merge(mmbuffer_t *result_buf,
        const struct ll_merge_driver *driver;
        int virtual_ancestor = flag & 01;
 
+       if (merge_renormalize) {
+               normalize_file(ancestor, path);
+               normalize_file(ours, path);
+               normalize_file(theirs, path);
+       }
        if (!git_path_check_merge(path, check)) {
                ll_driver_name = check[0].value;
                if (check[1].value) {