merge: refuse to create too cool a merge by default
[gitweb.git] / builtin / blame.c
index 28c48bd4532c290a5345c6b65ff530164bfd2eab..0b4f0bbb531407f6003fe66cfe16a48785b1dcf3 100644 (file)
@@ -459,13 +459,11 @@ static void queue_blames(struct scoreboard *sb, struct origin *porigin,
 static struct origin *make_origin(struct commit *commit, const char *path)
 {
        struct origin *o;
-       size_t pathlen = strlen(path) + 1;
-       o = xcalloc(1, sizeof(*o) + pathlen);
+       FLEX_ALLOC_STR(o, path, path);
        o->commit = commit;
        o->refcnt = 1;
        o->next = commit->util;
        commit->util = o;
-       memcpy(o->path, path, pathlen); /* includes NUL */
        return o;
 }
 
@@ -506,7 +504,7 @@ static int fill_blob_sha1_and_mode(struct origin *origin)
 {
        if (!is_null_sha1(origin->blob_sha1))
                return 0;
-       if (get_tree_entry(get_object_hash(origin->commit->object),
+       if (get_tree_entry(origin->commit->object.oid.hash,
                           origin->path,
                           origin->blob_sha1, &origin->mode))
                goto error_out;
@@ -558,10 +556,10 @@ static struct origin *find_origin(struct scoreboard *sb,
        diff_setup_done(&diff_opts);
 
        if (is_null_oid(&origin->commit->object.oid))
-               do_diff_cache(get_object_hash(parent->tree->object), &diff_opts);
+               do_diff_cache(parent->tree->object.oid.hash, &diff_opts);
        else
-               diff_tree_sha1(get_object_hash(parent->tree->object),
-                              get_object_hash(origin->commit->tree->object),
+               diff_tree_sha1(parent->tree->object.oid.hash,
+                              origin->commit->tree->object.oid.hash,
                               "", &diff_opts);
        diffcore_std(&diff_opts);
 
@@ -628,10 +626,10 @@ static struct origin *find_rename(struct scoreboard *sb,
        diff_setup_done(&diff_opts);
 
        if (is_null_oid(&origin->commit->object.oid))
-               do_diff_cache(get_object_hash(parent->tree->object), &diff_opts);
+               do_diff_cache(parent->tree->object.oid.hash, &diff_opts);
        else
-               diff_tree_sha1(get_object_hash(parent->tree->object),
-                              get_object_hash(origin->commit->tree->object),
+               diff_tree_sha1(parent->tree->object.oid.hash,
+                              origin->commit->tree->object.oid.hash,
                               "", &diff_opts);
        diffcore_std(&diff_opts);
 
@@ -1276,10 +1274,10 @@ static void find_copy_in_parent(struct scoreboard *sb,
                DIFF_OPT_SET(&diff_opts, FIND_COPIES_HARDER);
 
        if (is_null_oid(&target->commit->object.oid))
-               do_diff_cache(get_object_hash(parent->tree->object), &diff_opts);
+               do_diff_cache(parent->tree->object.oid.hash, &diff_opts);
        else
-               diff_tree_sha1(get_object_hash(parent->tree->object),
-                              get_object_hash(target->commit->tree->object),
+               diff_tree_sha1(parent->tree->object.oid.hash,
+                              target->commit->tree->object.oid.hash,
                               "", &diff_opts);
 
        if (!DIFF_OPT_TST(&diff_opts, FIND_COPIES_HARDER))
@@ -2042,7 +2040,8 @@ static int prepare_lines(struct scoreboard *sb)
        for (p = buf; p < end; p = get_next_line(p, end))
                num++;
 
-       sb->lineno = lineno = xmalloc(sizeof(*sb->lineno) * (num + 1));
+       ALLOC_ARRAY(sb->lineno, num + 1);
+       lineno = sb->lineno;
 
        for (p = buf; p < end; p = get_next_line(p, end))
                *lineno++ = p - buf;
@@ -2077,7 +2076,7 @@ static int read_ancestry(const char *graft_file)
 
 static int update_auto_abbrev(int auto_abbrev, struct origin *suspect)
 {
-       const char *uniq = find_unique_abbrev(get_object_hash(suspect->commit->object),
+       const char *uniq = find_unique_abbrev(suspect->commit->object.oid.hash,
                                              auto_abbrev);
        int len = strlen(uniq);
        if (auto_abbrev < len)
@@ -2216,7 +2215,7 @@ static void verify_working_tree_path(struct commit *work_tree, const char *path)
        struct commit_list *parents;
 
        for (parents = work_tree->parents; parents; parents = parents->next) {
-               const unsigned char *commit_sha1 = get_object_hash(parents->item->object);
+               const unsigned char *commit_sha1 = parents->item->object.oid.hash;
                unsigned char blob_sha1[20];
                unsigned mode;
 
@@ -2392,20 +2391,17 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt,
        ce->ce_mode = create_ce_mode(mode);
        add_cache_entry(ce, ADD_CACHE_OK_TO_ADD|ADD_CACHE_OK_TO_REPLACE);
 
-       /*
-        * We are not going to write this out, so this does not matter
-        * right now, but someday we might optimize diff-index --cached
-        * with cache-tree information.
-        */
        cache_tree_invalidate_path(&the_index, path);
 
        return commit;
 }
 
-static struct object_array_entry *find_single_final(struct rev_info *revs)
+static struct commit *find_single_final(struct rev_info *revs,
+                                       const char **name_p)
 {
        int i;
-       struct object_array_entry *found = NULL;
+       struct commit *found = NULL;
+       const char *name = NULL;
 
        for (i = 0; i < revs->pending.nr; i++) {
                struct object *obj = revs->pending.objects[i].item;
@@ -2417,22 +2413,20 @@ static struct object_array_entry *find_single_final(struct rev_info *revs)
                        die("Non commit %s?", revs->pending.objects[i].name);
                if (found)
                        die("More than one commit to dig from %s and %s?",
-                           revs->pending.objects[i].name,
-                           found->name);
-               found = &(revs->pending.objects[i]);
+                           revs->pending.objects[i].name, name);
+               found = (struct commit *)obj;
+               name = revs->pending.objects[i].name;
        }
+       if (name_p)
+               *name_p = name;
        return found;
 }
 
 static char *prepare_final(struct scoreboard *sb)
 {
-       struct object_array_entry *found = find_single_final(sb->revs);
-       if (found) {
-               sb->final = (struct commit *) found->item;
-               return xstrdup(found->name);
-       } else {
-               return NULL;
-       }
+       const char *name;
+       sb->final = find_single_final(sb->revs, &name);
+       return xstrdup_or_null(name);
 }
 
 static char *prepare_initial(struct scoreboard *sb)
@@ -2720,11 +2714,9 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
                die("Cannot use --contents with final commit object name");
 
        if (reverse && revs.first_parent_only) {
-               struct object_array_entry *entry = find_single_final(sb.revs);
-               if (!entry)
+               final_commit = find_single_final(sb.revs, NULL);
+               if (!final_commit)
                        die("--reverse and --first-parent together require specified latest commit");
-               else
-                       final_commit = (struct commit*) entry->item;
        }
 
        /*