Merge branch 'sg/test-BUG'
[gitweb.git] / blame.c
diff --git a/blame.c b/blame.c
index aca06f4b1227a4930a2dbb13b87068a618a76f97..d84c937780801f51b8eb98b7e367c8017701ba5c 100644 (file)
--- a/blame.c
+++ b/blame.c
@@ -90,7 +90,7 @@ static struct blame_origin *get_origin(struct commit *commit, const char *path)
 
 
 
-static void verify_working_tree_path(struct repository *repo,
+static void verify_working_tree_path(struct repository *r,
                                     struct commit *work_tree, const char *path)
 {
        struct commit_list *parents;
@@ -102,15 +102,15 @@ static void verify_working_tree_path(struct repository *repo,
                unsigned mode;
 
                if (!get_tree_entry(commit_oid, path, &blob_oid, &mode) &&
-                   oid_object_info(repo, &blob_oid, NULL) == OBJ_BLOB)
+                   oid_object_info(r, &blob_oid, NULL) == OBJ_BLOB)
                        return;
        }
 
-       pos = index_name_pos(repo->index, path, strlen(path));
+       pos = index_name_pos(r->index, path, strlen(path));
        if (pos >= 0)
                ; /* path is in the index */
-       else if (-1 - pos < repo->index->cache_nr &&
-                !strcmp(repo->index->cache[-1 - pos]->name, path))
+       else if (-1 - pos < r->index->cache_nr &&
+                !strcmp(r->index->cache[-1 - pos]->name, path))
                ; /* path is in the index, unmerged */
        else
                die("no such path '%s' in HEAD", path);
@@ -166,7 +166,7 @@ static void set_commit_buffer_from_strbuf(struct commit *c, struct strbuf *sb)
  * Prepare a dummy commit that represents the work tree (or staged) item.
  * Note that annotating work tree item never works in the reverse.
  */
-static struct commit *fake_working_tree_commit(struct repository *repo,
+static struct commit *fake_working_tree_commit(struct repository *r,
                                               struct diff_options *opt,
                                               const char *path,
                                               const char *contents_from)
@@ -183,7 +183,7 @@ static struct commit *fake_working_tree_commit(struct repository *repo,
        unsigned mode;
        struct strbuf msg = STRBUF_INIT;
 
-       read_index(repo->index);
+       read_index(r->index);
        time(&now);
        commit = alloc_commit_node(the_repository);
        commit->object.parsed = 1;
@@ -195,7 +195,7 @@ static struct commit *fake_working_tree_commit(struct repository *repo,
 
        parent_tail = append_parent(parent_tail, &head_oid);
        append_merge_parents(parent_tail);
-       verify_working_tree_path(repo, commit, path);
+       verify_working_tree_path(r, commit, path);
 
        origin = make_origin(commit, path);
 
@@ -234,7 +234,7 @@ static struct commit *fake_working_tree_commit(struct repository *repo,
                switch (st.st_mode & S_IFMT) {
                case S_IFREG:
                        if (opt->flags.allow_textconv &&
-                           textconv_object(read_from, mode, &null_oid, 0, &buf_ptr, &buf_len))
+                           textconv_object(r, read_from, mode, &null_oid, 0, &buf_ptr, &buf_len))
                                strbuf_attach(&buf, buf_ptr, buf_len, buf_len + 1);
                        else if (strbuf_read_file(&buf, read_from, st.st_size) != st.st_size)
                                die_errno("cannot open or read '%s'", read_from);
@@ -253,7 +253,7 @@ static struct commit *fake_working_tree_commit(struct repository *repo,
                if (strbuf_read(&buf, 0, 0) < 0)
                        die_errno("failed to read from stdin");
        }
-       convert_to_git(repo->index, path, buf.buf, buf.len, &buf, 0);
+       convert_to_git(r->index, path, buf.buf, buf.len, &buf, 0);
        origin->file.ptr = buf.buf;
        origin->file.size = buf.len;
        pretend_object_file(buf.buf, buf.len, OBJ_BLOB, &origin->blob_oid);
@@ -264,28 +264,28 @@ static struct commit *fake_working_tree_commit(struct repository *repo,
         * bits; we are not going to write this index out -- we just
         * want to run "diff-index --cached".
         */
-       discard_index(repo->index);
-       read_index(repo->index);
+       discard_index(r->index);
+       read_index(r->index);
 
        len = strlen(path);
        if (!mode) {
-               int pos = index_name_pos(repo->index, path, len);
+               int pos = index_name_pos(r->index, path, len);
                if (0 <= pos)
-                       mode = repo->index->cache[pos]->ce_mode;
+                       mode = r->index->cache[pos]->ce_mode;
                else
                        /* Let's not bother reading from HEAD tree */
                        mode = S_IFREG | 0644;
        }
-       ce = make_empty_cache_entry(repo->index, len);
+       ce = make_empty_cache_entry(r->index, len);
        oidcpy(&ce->oid, &origin->blob_oid);
        memcpy(ce->name, path, len);
        ce->ce_flags = create_ce_flags(0);
        ce->ce_namelen = len;
        ce->ce_mode = create_ce_mode(mode);
-       add_index_entry(repo->index, ce,
+       add_index_entry(r->index, ce,
                        ADD_CACHE_OK_TO_ADD | ADD_CACHE_OK_TO_REPLACE);
 
-       cache_tree_invalidate_path(repo->index, path);
+       cache_tree_invalidate_path(r->index, path);
 
        return commit;
 }
@@ -318,7 +318,8 @@ static void fill_origin_blob(struct diff_options *opt,
 
                (*num_read_blob)++;
                if (opt->flags.allow_textconv &&
-                   textconv_object(o->path, o->mode, &o->blob_oid, 1, &file->ptr, &file_size))
+                   textconv_object(opt->repo, o->path, o->mode,
+                                   &o->blob_oid, 1, &file->ptr, &file_size))
                        ;
                else
                        file->ptr = read_object_file(&o->blob_oid, &type,
@@ -520,14 +521,14 @@ static void queue_blames(struct blame_scoreboard *sb, struct blame_origin *porig
  *
  * This also fills origin->mode for corresponding tree path.
  */
-static int fill_blob_sha1_and_mode(struct repository *repo,
+static int fill_blob_sha1_and_mode(struct repository *r,
                                   struct blame_origin *origin)
 {
        if (!is_null_oid(&origin->blob_oid))
                return 0;
        if (get_tree_entry(&origin->commit->object.oid, origin->path, &origin->blob_oid, &origin->mode))
                goto error_out;
-       if (oid_object_info(repo, &origin->blob_oid, NULL) != OBJ_BLOB)
+       if (oid_object_info(r, &origin->blob_oid, NULL) != OBJ_BLOB)
                goto error_out;
        return 0;
  error_out:
@@ -540,8 +541,9 @@ static int fill_blob_sha1_and_mode(struct repository *repo,
  * We have an origin -- check if the same path exists in the
  * parent and return an origin structure to represent it.
  */
-static struct blame_origin *find_origin(struct commit *parent,
-                                 struct blame_origin *origin)
+static struct blame_origin *find_origin(struct repository *r,
+                                       struct commit *parent,
+                                       struct blame_origin *origin)
 {
        struct blame_origin *porigin;
        struct diff_options diff_opts;
@@ -561,7 +563,7 @@ static struct blame_origin *find_origin(struct commit *parent,
         * and origin first.  Most of the time they are the
         * same and diff-tree is fairly efficient about this.
         */
-       diff_setup(&diff_opts);
+       repo_diff_setup(r, &diff_opts);
        diff_opts.flags.recursive = 1;
        diff_opts.detect_rename = 0;
        diff_opts.output_format = DIFF_FORMAT_NO_OUTPUT;
@@ -628,14 +630,15 @@ static struct blame_origin *find_origin(struct commit *parent,
  * We have an origin -- find the path that corresponds to it in its
  * parent and return an origin structure to represent it.
  */
-static struct blame_origin *find_rename(struct commit *parent,
-                                 struct blame_origin *origin)
+static struct blame_origin *find_rename(struct repository *r,
+                                       struct commit *parent,
+                                       struct blame_origin *origin)
 {
        struct blame_origin *porigin = NULL;
        struct diff_options diff_opts;
        int i;
 
-       diff_setup(&diff_opts);
+       repo_diff_setup(r, &diff_opts);
        diff_opts.flags.recursive = 1;
        diff_opts.detect_rename = DIFF_DETECT_RENAME;
        diff_opts.output_format = DIFF_FORMAT_NO_OUTPUT;
@@ -1259,7 +1262,7 @@ static void find_copy_in_parent(struct blame_scoreboard *sb,
        if (!unblamed)
                return; /* nothing remains for this target */
 
-       diff_setup(&diff_opts);
+       repo_diff_setup(sb->repo, &diff_opts);
        diff_opts.flags.recursive = 1;
        diff_opts.output_format = DIFF_FORMAT_NO_OUTPUT;
 
@@ -1441,7 +1444,7 @@ static void pass_blame(struct blame_scoreboard *sb, struct blame_origin *origin,
         * common cases, then we look for renames in the second pass.
         */
        for (pass = 0; pass < 2 - sb->no_whole_file_rename; pass++) {
-               struct blame_origin *(*find)(struct commit *, struct blame_origin *);
+               struct blame_origin *(*find)(struct repository *, struct commit *, struct blame_origin *);
                find = pass ? find_rename : find_origin;
 
                for (i = 0, sg = first_scapegoat(revs, commit, sb->reverse);
@@ -1454,17 +1457,17 @@ static void pass_blame(struct blame_scoreboard *sb, struct blame_origin *origin,
                                continue;
                        if (parse_commit(p))
                                continue;
-                       porigin = find(p, origin);
+                       porigin = find(sb->repo, p, origin);
                        if (!porigin)
                                continue;
-                       if (!oidcmp(&porigin->blob_oid, &origin->blob_oid)) {
+                       if (oideq(&porigin->blob_oid, &origin->blob_oid)) {
                                pass_whole_blame(sb, origin, porigin);
                                blame_origin_decref(porigin);
                                goto finish;
                        }
                        for (j = same = 0; j < i; j++)
                                if (sg_origin[j] &&
-                                   !oidcmp(&sg_origin[j]->blob_oid, &porigin->blob_oid)) {
+                                   oideq(&sg_origin[j]->blob_oid, &porigin->blob_oid)) {
                                        same = 1;
                                        break;
                                }
@@ -1832,7 +1835,7 @@ void setup_scoreboard(struct blame_scoreboard *sb,
 
                sb->revs->children.name = "children";
                while (c->parents &&
-                      oidcmp(&c->object.oid, &sb->final->object.oid)) {
+                      !oideq(&c->object.oid, &sb->final->object.oid)) {
                        struct commit_list *l = xcalloc(1, sizeof(*l));
 
                        l->item = c;
@@ -1842,7 +1845,7 @@ void setup_scoreboard(struct blame_scoreboard *sb,
                        c = c->parents->item;
                }
 
-               if (oidcmp(&c->object.oid, &sb->final->object.oid))
+               if (!oideq(&c->object.oid, &sb->final->object.oid))
                        die(_("--reverse --first-parent together require range along first-parent chain"));
        }
 
@@ -1857,7 +1860,7 @@ void setup_scoreboard(struct blame_scoreboard *sb,
                        die(_("no such path %s in %s"), path, final_commit_name);
 
                if (sb->revs->diffopt.flags.allow_textconv &&
-                   textconv_object(path, o->mode, &o->blob_oid, 1, (char **) &sb->final_buf,
+                   textconv_object(sb->repo, path, o->mode, &o->blob_oid, 1, (char **) &sb->final_buf,
                                    &sb->final_buf_size))
                        ;
                else