Merge branch 'jk/test-send-sh-x-trace-elsewhere' into maint
[gitweb.git] / merge-recursive.c
index b446df9c1da0db2e21918f188b85536960d306f2..b880ae50e7ee4f8e88bda83618529ea30462e4ef 100644 (file)
 static struct tree *shift_tree_object(struct tree *one, struct tree *two,
                                      const char *subtree_shift)
 {
-       unsigned char shifted[20];
+       struct object_id shifted;
 
        if (!*subtree_shift) {
-               shift_tree(one->object.sha1, two->object.sha1, shifted, 0);
+               shift_tree(one->object.oid.hash, two->object.oid.hash, shifted.hash, 0);
        } else {
-               shift_tree_by(one->object.sha1, two->object.sha1, shifted,
+               shift_tree_by(one->object.oid.hash, two->object.oid.hash, shifted.hash,
                              subtree_shift);
        }
-       if (!hashcmp(two->object.sha1, shifted))
+       if (!oidcmp(&two->object.oid, &shifted))
                return two;
-       return lookup_tree(shifted);
+       return lookup_tree(shifted.hash);
 }
 
 static struct commit *make_virtual_commit(struct tree *tree, const char *comment)
@@ -184,7 +184,7 @@ static void output_commit_title(struct merge_options *o, struct commit *commit)
        if (commit->util)
                printf("virtual %s\n", merge_remote_util(commit)->name);
        else {
-               printf("%s ", find_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV));
+               printf("%s ", find_unique_abbrev(commit->object.oid.hash, DEFAULT_ABBREV));
                if (parse_commit(commit) != 0)
                        printf(_("(bad commit)\n"));
                else {
@@ -313,11 +313,11 @@ static struct stage_data *insert_stage_data(const char *path,
 {
        struct string_list_item *item;
        struct stage_data *e = xcalloc(1, sizeof(struct stage_data));
-       get_tree_entry(o->object.sha1, path,
+       get_tree_entry(o->object.oid.hash, path,
                        e->stages[1].sha, &e->stages[1].mode);
-       get_tree_entry(a->object.sha1, path,
+       get_tree_entry(a->object.oid.hash, path,
                        e->stages[2].sha, &e->stages[2].mode);
-       get_tree_entry(b->object.sha1, path,
+       get_tree_entry(b->object.oid.hash, path,
                        e->stages[3].sha, &e->stages[3].mode);
        item = string_list_insert(entries, path);
        item->util = e;
@@ -482,6 +482,9 @@ static struct string_list *get_renames(struct merge_options *o,
        struct diff_options opts;
 
        renames = xcalloc(1, sizeof(struct string_list));
+       if (!o->detect_rename)
+               return renames;
+
        diff_setup(&opts);
        DIFF_OPT_SET(&opts, RECURSIVE);
        DIFF_OPT_CLR(&opts, RENAME_EMPTY);
@@ -493,7 +496,7 @@ static struct string_list *get_renames(struct merge_options *o,
        opts.show_rename_progress = o->show_rename_progress;
        opts.output_format = DIFF_FORMAT_NO_OUTPUT;
        diff_setup_done(&opts);
-       diff_tree_sha1(o_tree->object.sha1, tree->object.sha1, "", &opts);
+       diff_tree_sha1(o_tree->object.oid.hash, tree->object.oid.hash, "", &opts);
        diffcore_std(&opts);
        if (opts.needed_rename_limit > o->needed_rename_limit)
                o->needed_rename_limit = opts.needed_rename_limit;
@@ -630,25 +633,24 @@ static char *unique_path(struct merge_options *o, const char *path, const char *
 
 static int dir_in_way(const char *path, int check_working_copy)
 {
-       int pos, pathlen = strlen(path);
-       char *dirpath = xmalloc(pathlen + 2);
+       int pos;
+       struct strbuf dirpath = STRBUF_INIT;
        struct stat st;
 
-       strcpy(dirpath, path);
-       dirpath[pathlen] = '/';
-       dirpath[pathlen+1] = '\0';
+       strbuf_addstr(&dirpath, path);
+       strbuf_addch(&dirpath, '/');
 
-       pos = cache_name_pos(dirpath, pathlen+1);
+       pos = cache_name_pos(dirpath.buf, dirpath.len);
 
        if (pos < 0)
                pos = -1 - pos;
        if (pos < active_nr &&
-           !strncmp(dirpath, active_cache[pos]->name, pathlen+1)) {
-               free(dirpath);
+           !strncmp(dirpath.buf, active_cache[pos]->name, dirpath.len)) {
+               strbuf_release(&dirpath);
                return 1;
        }
 
-       free(dirpath);
+       strbuf_release(&dirpath);
        return check_working_copy && !lstat(path, &st) && S_ISDIR(st.st_mode);
 }
 
@@ -1813,7 +1815,7 @@ int merge_trees(struct merge_options *o,
                common = shift_tree_object(head, common, o->subtree_shift);
        }
 
-       if (sha_eq(common->object.sha1, merge->object.sha1)) {
+       if (sha_eq(common->object.oid.hash, merge->object.oid.hash)) {
                output(o, 0, _("Already up-to-date!"));
                *result = head;
                return 1;
@@ -1824,8 +1826,8 @@ int merge_trees(struct merge_options *o,
        if (code != 0) {
                if (show(o, 4) || o->call_depth)
                        die(_("merging of trees %s and %s failed"),
-                           sha1_to_hex(head->object.sha1),
-                           sha1_to_hex(merge->object.sha1));
+                           oid_to_hex(&head->object.oid),
+                           oid_to_hex(&merge->object.oid));
                else
                        exit(128);
        }
@@ -2040,6 +2042,7 @@ void init_merge_options(struct merge_options *o)
        o->diff_rename_limit = -1;
        o->merge_rename_limit = -1;
        o->renormalize = 0;
+       o->detect_rename = 1;
        merge_recursive_config(o);
        if (getenv("GIT_MERGE_VERBOSITY"))
                o->verbosity =
@@ -2089,9 +2092,17 @@ int parse_merge_opt(struct merge_options *o, const char *s)
                o->renormalize = 1;
        else if (!strcmp(s, "no-renormalize"))
                o->renormalize = 0;
-       else if (skip_prefix(s, "rename-threshold=", &arg)) {
+       else if (!strcmp(s, "no-renames"))
+               o->detect_rename = 0;
+       else if (!strcmp(s, "find-renames")) {
+               o->detect_rename = 1;
+               o->rename_score = 0;
+       }
+       else if (skip_prefix(s, "find-renames=", &arg) ||
+                skip_prefix(s, "rename-threshold=", &arg)) {
                if ((o->rename_score = parse_rename_score(&arg)) == -1 || *arg != 0)
                        return -1;
+               o->detect_rename = 1;
        }
        else
                return -1;