Sync with GIT 1.5.3.3
[gitweb.git] / merge-recursive.c
index 8f72b2c079a68ac5cb9d1c90bb7b72fa779efb5f..97dcf9bf02d8f382ba63cfeef9d6dcb792c62f76 100644 (file)
@@ -96,6 +96,7 @@ static struct path_list current_directory_set = {NULL, 0, 0, 1};
 
 static int call_depth = 0;
 static int verbosity = 2;
+static int rename_limit = -1;
 static int buffer_output = 1;
 static struct output_buffer *output_list, *output_end;
 
@@ -127,7 +128,7 @@ static void output(int v, const char *fmt, ...)
        va_end(args);
 }
 
-static void flush_output()
+static void flush_output(void)
 {
        struct output_buffer *b, *n;
        for (b = output_list; b; b = n) {
@@ -171,30 +172,6 @@ static void output_commit_title(struct commit *commit)
        }
 }
 
-static struct cache_entry *make_cache_entry(unsigned int mode,
-               const unsigned char *sha1, const char *path, int stage, int refresh)
-{
-       int size, len;
-       struct cache_entry *ce;
-
-       if (!verify_path(path))
-               return NULL;
-
-       len = strlen(path);
-       size = cache_entry_size(len);
-       ce = xcalloc(1, size);
-
-       hashcpy(ce->sha1, sha1);
-       memcpy(ce->name, path, len);
-       ce->ce_flags = create_ce_flags(len, stage);
-       ce->ce_mode = create_ce_mode(mode);
-
-       if (refresh)
-               return refresh_cache_entry(ce, 0);
-
-       return ce;
-}
-
 static int add_cacheinfo(unsigned int mode, const unsigned char *sha1,
                const char *path, int stage, int refresh, int options)
 {
@@ -216,13 +193,19 @@ static int add_cacheinfo(unsigned int mode, const unsigned char *sha1,
  */
 static int index_only = 0;
 
+static void init_tree_desc_from_tree(struct tree_desc *desc, struct tree *tree)
+{
+       parse_tree(tree);
+       init_tree_desc(desc, tree->buffer, tree->size);
+}
+
 static int git_merge_trees(int index_only,
                           struct tree *common,
                           struct tree *head,
                           struct tree *merge)
 {
        int rc;
-       struct object_list *trees = NULL;
+       struct tree_desc t[3];
        struct unpack_trees_options opts;
 
        memset(&opts, 0, sizeof(opts));
@@ -234,11 +217,11 @@ static int git_merge_trees(int index_only,
        opts.head_idx = 2;
        opts.fn = threeway_merge;
 
-       object_list_append(&common->object, &trees);
-       object_list_append(&head->object, &trees);
-       object_list_append(&merge->object, &trees);
+       init_tree_desc_from_tree(t+0, common);
+       init_tree_desc_from_tree(t+1, head);
+       init_tree_desc_from_tree(t+2, merge);
 
-       rc = unpack_trees(trees, &opts);
+       rc = unpack_trees(3, t, &opts);
        cache_tree_free(&active_cache_tree);
        return rc;
 }
@@ -390,6 +373,7 @@ static struct path_list *get_renames(struct tree *tree,
        diff_setup(&opts);
        opts.recursive = 1;
        opts.detect_rename = DIFF_DETECT_RENAME;
+       opts.rename_limit = rename_limit;
        opts.output_format = DIFF_FORMAT_NO_OUTPUT;
        if (diff_setup_done(&opts) < 0)
                die("diff setup failed");
@@ -671,6 +655,26 @@ struct ll_merge_driver {
 /*
  * Built-in low-levels
  */
+static int ll_binary_merge(const struct ll_merge_driver *drv_unused,
+                          const char *path_unused,
+                          mmfile_t *orig,
+                          mmfile_t *src1, const char *name1,
+                          mmfile_t *src2, const char *name2,
+                          mmbuffer_t *result)
+{
+       /*
+        * 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 = index_only ? orig : src1;
+
+       result->ptr = stolen->ptr;
+       result->size = stolen->size;
+       stolen->ptr = NULL;
+       return 1;
+}
+
 static int ll_xdl_merge(const struct ll_merge_driver *drv_unused,
                        const char *path_unused,
                        mmfile_t *orig,
@@ -680,6 +684,17 @@ static int ll_xdl_merge(const struct ll_merge_driver *drv_unused,
 {
        xpparam_t xpp;
 
+       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);
+               return ll_binary_merge(drv_unused, path_unused,
+                                      orig, src1, name1,
+                                      src2, name2,
+                                      result);
+       }
+
        memset(&xpp, 0, sizeof(xpp));
        return xdl_merge(orig,
                         src1, name1,
@@ -731,26 +746,6 @@ static int ll_union_merge(const struct ll_merge_driver *drv_unused,
        return 0;
 }
 
-static int ll_binary_merge(const struct ll_merge_driver *drv_unused,
-                          const char *path_unused,
-                          mmfile_t *orig,
-                          mmfile_t *src1, const char *name1,
-                          mmfile_t *src2, const char *name2,
-                          mmbuffer_t *result)
-{
-       /*
-        * 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 = index_only ? orig : src1;
-
-       result->ptr = stolen->ptr;
-       result->size = stolen->size;
-       stolen->ptr = NULL;
-       return 1;
-}
-
 #define LL_BINARY_MERGE 0
 #define LL_TEXT_MERGE 1
 #define LL_UNION_MERGE 2
@@ -765,9 +760,7 @@ static void create_temp(mmfile_t *src, char *path)
        int fd;
 
        strcpy(path, ".merge_file_XXXXXX");
-       fd = mkstemp(path);
-       if (fd < 0)
-               die("unable to create temp-file");
+       fd = xmkstemp(path);
        if (write_in_full(fd, src->ptr, src->size) != src->size)
                die("unable to write temp-file");
        close(fd);
@@ -1702,6 +1695,10 @@ static int merge_config(const char *var, const char *value)
                verbosity = git_config_int(var, value);
                return 0;
        }
+       if (!strcasecmp(var, "diff.renamelimit")) {
+               rename_limit = git_config_int(var, value);
+               return 0;
+       }
        return git_default_config(var, value);
 }