blame: move no_whole_file_rename flag to scoreboard
[gitweb.git] / builtin / blame.c
index f0c9ab873780d5874a941325a71433b8f8af8f95..90c643c7da671235ad51b563d93db7e5fa56b431 100644 (file)
@@ -66,10 +66,6 @@ static struct string_list mailmap = STRING_LIST_INIT_NODUP;
 #define PICKAXE_BLAME_COPY_HARDER      04
 #define PICKAXE_BLAME_COPY_HARDEST     010
 
-/*
- * blame for a blame_entry with score lower than these thresholds
- * is not passed to the parent using move/copy logic.
- */
 static unsigned blame_move_score;
 static unsigned blame_copy_score;
 #define BLAME_DEFAULT_MOVE_SCORE       20
@@ -129,7 +125,7 @@ struct progress_info {
 };
 
 static int diff_hunks(mmfile_t *file_a, mmfile_t *file_b,
-                     xdl_emit_hunk_consume_func_t hunk_func, void *cb_data)
+                     xdl_emit_hunk_consume_func_t hunk_func, void *cb_data, int xdl_opts)
 {
        xpparam_t xpp = {0};
        xdemitconf_t xecfg = {0};
@@ -375,6 +371,22 @@ struct blame_scoreboard {
        int num_read_blob;
        int num_get_patch;
        int num_commits;
+
+       /*
+        * blame for a blame_entry with score lower than these thresholds
+        * is not passed to the parent using move/copy logic.
+        */
+       unsigned move_score;
+       unsigned copy_score;
+
+       /* use this file's contents as the final image */
+       const char *contents_from;
+
+       /* flags */
+       int reverse;
+       int show_root;
+       int xdl_opts;
+       int no_whole_file_rename;
 };
 
 static void sanity_check_refcnt(struct blame_scoreboard *);
@@ -938,7 +950,7 @@ static void pass_blame_to_parent(struct blame_scoreboard *sb,
        fill_origin_blob(&sb->revs->diffopt, target, &file_o, &sb->num_read_blob);
        sb->num_get_patch++;
 
-       if (diff_hunks(&file_p, &file_o, blame_chunk_cb, &d))
+       if (diff_hunks(&file_p, &file_o, blame_chunk_cb, &d, sb->xdl_opts))
                die("unable to generate diff (%s -> %s)",
                    oid_to_hex(&parent->commit->object.oid),
                    oid_to_hex(&target->commit->object.oid));
@@ -1087,7 +1099,7 @@ static void find_copy_in_blob(struct blame_scoreboard *sb,
         * file_p partially may match that image.
         */
        memset(split, 0, sizeof(struct blame_entry [3]));
-       if (diff_hunks(file_p, &file_o, handle_split_cb, &d))
+       if (diff_hunks(file_p, &file_o, handle_split_cb, &d, sb->xdl_opts))
                die("unable to generate diff (%s)",
                    oid_to_hex(&parent->commit->object.oid));
        /* remainder, if any, all match the preimage */
@@ -1156,7 +1168,7 @@ static void find_move_in_parent(struct blame_scoreboard *sb,
                        next = e->next;
                        find_copy_in_blob(sb, e, parent, split, &file_p);
                        if (split[1].suspect &&
-                           blame_move_score < blame_entry_score(sb, &split[1])) {
+                           sb->move_score < blame_entry_score(sb, &split[1])) {
                                split_blame(blamed, &unblamedtail, split, e);
                        } else {
                                e->next = leftover;
@@ -1165,7 +1177,7 @@ static void find_move_in_parent(struct blame_scoreboard *sb,
                        decref_split(split);
                }
                *unblamedtail = NULL;
-               toosmall = filter_small(sb, toosmall, &unblamed, blame_move_score);
+               toosmall = filter_small(sb, toosmall, &unblamed, sb->move_score);
        } while (unblamed);
        target->suspects = reverse_blame(leftover, NULL);
 }
@@ -1286,7 +1298,7 @@ static void find_copy_in_parent(struct blame_scoreboard *sb,
                for (j = 0; j < num_ents; j++) {
                        struct blame_entry *split = blame_list[j].split;
                        if (split[1].suspect &&
-                           blame_copy_score < blame_entry_score(sb, &split[1])) {
+                           sb->copy_score < blame_entry_score(sb, &split[1])) {
                                split_blame(blamed, &unblamedtail, split,
                                            blame_list[j].ent);
                        } else {
@@ -1297,7 +1309,7 @@ static void find_copy_in_parent(struct blame_scoreboard *sb,
                }
                free(blame_list);
                *unblamedtail = NULL;
-               toosmall = filter_small(sb, toosmall, &unblamed, blame_copy_score);
+               toosmall = filter_small(sb, toosmall, &unblamed, sb->copy_score);
        } while (unblamed);
        target->suspects = reverse_blame(leftover, NULL);
        diff_flush(&diff_opts);
@@ -1333,7 +1345,8 @@ static void pass_whole_blame(struct blame_scoreboard *sb,
  * "parent" (and "porigin"), but what we mean is to find scapegoat to
  * exonerate ourselves.
  */
-static struct commit_list *first_scapegoat(struct rev_info *revs, struct commit *commit)
+static struct commit_list *first_scapegoat(struct rev_info *revs, struct commit *commit,
+                                          int reverse)
 {
        if (!reverse) {
                if (revs->first_parent_only &&
@@ -1347,9 +1360,9 @@ static struct commit_list *first_scapegoat(struct rev_info *revs, struct commit
        return lookup_decoration(&revs->children, &commit->object);
 }
 
-static int num_scapegoats(struct rev_info *revs, struct commit *commit)
+static int num_scapegoats(struct rev_info *revs, struct commit *commit, int reverse)
 {
-       struct commit_list *l = first_scapegoat(revs, commit);
+       struct commit_list *l = first_scapegoat(revs, commit, reverse);
        return commit_list_count(l);
 }
 
@@ -1387,7 +1400,7 @@ static void pass_blame(struct blame_scoreboard *sb, struct blame_origin *origin,
        struct blame_entry *toosmall = NULL;
        struct blame_entry *blames, **blametail = &blames;
 
-       num_sg = num_scapegoats(revs, commit);
+       num_sg = num_scapegoats(revs, commit, sb->reverse);
        if (!num_sg)
                goto finish;
        else if (num_sg < ARRAY_SIZE(sg_buf))
@@ -1399,11 +1412,11 @@ static void pass_blame(struct blame_scoreboard *sb, struct blame_origin *origin,
         * The first pass looks for unrenamed path to optimize for
         * common cases, then we look for renames in the second pass.
         */
-       for (pass = 0; pass < 2 - no_whole_file_rename; pass++) {
+       for (pass = 0; pass < 2 - sb->no_whole_file_rename; pass++) {
                struct blame_origin *(*find)(struct commit *, struct blame_origin *);
                find = pass ? find_rename : find_origin;
 
-               for (i = 0, sg = first_scapegoat(revs, commit);
+               for (i = 0, sg = first_scapegoat(revs, commit, sb->reverse);
                     i < num_sg && sg;
                     sg = sg->next, i++) {
                        struct commit *p = sg->item;
@@ -1435,7 +1448,7 @@ static void pass_blame(struct blame_scoreboard *sb, struct blame_origin *origin,
        }
 
        sb->num_commits++;
-       for (i = 0, sg = first_scapegoat(revs, commit);
+       for (i = 0, sg = first_scapegoat(revs, commit, sb->reverse);
             i < num_sg && sg;
             sg = sg->next, i++) {
                struct blame_origin *porigin = sg_origin[i];
@@ -1454,9 +1467,9 @@ static void pass_blame(struct blame_scoreboard *sb, struct blame_origin *origin,
         * Optionally find moves in parents' files.
         */
        if (opt & PICKAXE_BLAME_MOVE) {
-               filter_small(sb, &toosmall, &origin->suspects, blame_move_score);
+               filter_small(sb, &toosmall, &origin->suspects, sb->move_score);
                if (origin->suspects) {
-                       for (i = 0, sg = first_scapegoat(revs, commit);
+                       for (i = 0, sg = first_scapegoat(revs, commit, sb->reverse);
                             i < num_sg && sg;
                             sg = sg->next, i++) {
                                struct blame_origin *porigin = sg_origin[i];
@@ -1473,17 +1486,17 @@ static void pass_blame(struct blame_scoreboard *sb, struct blame_origin *origin,
         * Optionally find copies from parents' files.
         */
        if (opt & PICKAXE_BLAME_COPY) {
-               if (blame_copy_score > blame_move_score)
-                       filter_small(sb, &toosmall, &origin->suspects, blame_copy_score);
-               else if (blame_copy_score < blame_move_score) {
+               if (sb->copy_score > sb->move_score)
+                       filter_small(sb, &toosmall, &origin->suspects, sb->copy_score);
+               else if (sb->copy_score < sb->move_score) {
                        origin->suspects = blame_merge(origin->suspects, toosmall);
                        toosmall = NULL;
-                       filter_small(sb, &toosmall, &origin->suspects, blame_copy_score);
+                       filter_small(sb, &toosmall, &origin->suspects, sb->copy_score);
                }
                if (!origin->suspects)
                        goto finish;
 
-               for (i = 0, sg = first_scapegoat(revs, commit);
+               for (i = 0, sg = first_scapegoat(revs, commit, sb->reverse);
                     i < num_sg && sg;
                     sg = sg->next, i++) {
                        struct blame_origin *porigin = sg_origin[i];
@@ -1764,7 +1777,7 @@ static void assign_blame(struct blame_scoreboard *sb, int opt)
                 */
                blame_origin_incref(suspect);
                parse_commit(commit);
-               if (reverse ||
+               if (sb->reverse ||
                    (!(commit->object.flags & UNINTERESTING) &&
                     !(revs->max_age != -1 && commit->date < revs->max_age)))
                        pass_blame(sb, suspect, opt);
@@ -1774,7 +1787,7 @@ static void assign_blame(struct blame_scoreboard *sb, int opt)
                                mark_parents_uninteresting(commit);
                }
                /* treat root commit as boundary */
-               if (!commit->parents && !show_root)
+               if (!commit->parents && !sb->show_root)
                        commit->object.flags |= UNINTERESTING;
 
                /* Take responsibility for the remaining entries */
@@ -2675,11 +2688,6 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
                opt |= (PICKAXE_BLAME_COPY | PICKAXE_BLAME_MOVE |
                        PICKAXE_BLAME_COPY_HARDER);
 
-       if (!blame_move_score)
-               blame_move_score = BLAME_DEFAULT_MOVE_SCORE;
-       if (!blame_copy_score)
-               blame_copy_score = BLAME_DEFAULT_COPY_SCORE;
-
        /*
         * We have collected options unknown to us in argv[1..unk]
         * which are to be passed to revision machinery if we are
@@ -2733,8 +2741,12 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
        revs.disable_stdin = 1;
        setup_revisions(argc, argv, &revs, NULL);
        memset(&sb, 0, sizeof(sb));
+       sb.move_score = BLAME_DEFAULT_MOVE_SCORE;
+       sb.copy_score = BLAME_DEFAULT_COPY_SCORE;
 
        sb.revs = &revs;
+       sb.contents_from = contents_from;
+       sb.reverse = reverse;
        if (!reverse) {
                final_commit_name = prepare_final(&sb);
                sb.commits.compare = compare_commits_by_commit_date;
@@ -2871,6 +2883,15 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
        sb.ent = NULL;
        sb.path = path;
 
+       if (blame_move_score)
+               sb.move_score = blame_move_score;
+       if (blame_copy_score)
+               sb.copy_score = blame_copy_score;
+
+       sb.show_root = show_root;
+       sb.xdl_opts = xdl_opts;
+       sb.no_whole_file_rename = no_whole_file_rename;
+
        read_mailmap(&mailmap, NULL);
 
        assign_blame(&sb, opt);