]> asedeno.scripts.mit.edu Git - git.git/blobdiff - builtin-blame.c
Merge branch 'ds/checkout-upper'
[git.git] / builtin-blame.c
index e364b6c6c0efed272484718e502f2b5bc18e7946..c158d319dce78c6b1f0cfeffd91ee565a2d14eff 100644 (file)
@@ -335,7 +335,7 @@ static struct origin *find_origin(struct scoreboard *sb,
         * same and diff-tree is fairly efficient about this.
         */
        diff_setup(&diff_opts);
-       diff_opts.recursive = 1;
+       DIFF_OPT_SET(&diff_opts, RECURSIVE);
        diff_opts.detect_rename = 0;
        diff_opts.output_format = DIFF_FORMAT_NO_OUTPUT;
        paths[0] = origin->path;
@@ -409,7 +409,7 @@ static struct origin *find_rename(struct scoreboard *sb,
        const char *paths[2];
 
        diff_setup(&diff_opts);
-       diff_opts.recursive = 1;
+       DIFF_OPT_SET(&diff_opts, RECURSIVE);
        diff_opts.detect_rename = DIFF_DETECT_RENAME;
        diff_opts.output_format = DIFF_FORMAT_NO_OUTPUT;
        diff_opts.single_follow = origin->path;
@@ -1075,7 +1075,7 @@ static int find_copy_in_parent(struct scoreboard *sb,
                return 1; /* nothing remains for this target */
 
        diff_setup(&diff_opts);
-       diff_opts.recursive = 1;
+       DIFF_OPT_SET(&diff_opts, RECURSIVE);
        diff_opts.output_format = DIFF_FORMAT_NO_OUTPUT;
 
        paths[0] = NULL;
@@ -1093,7 +1093,7 @@ static int find_copy_in_parent(struct scoreboard *sb,
        if ((opt & PICKAXE_BLAME_COPY_HARDEST)
            || ((opt & PICKAXE_BLAME_COPY_HARDER)
                && (!porigin || strcmp(target->path, porigin->path))))
-               diff_opts.find_copies_harder = 1;
+               DIFF_OPT_SET(&diff_opts, FIND_COPIES_HARDER);
 
        if (is_null_sha1(target->commit->object.sha1))
                do_diff_cache(parent->tree->object.sha1, &diff_opts);
@@ -1102,7 +1102,7 @@ static int find_copy_in_parent(struct scoreboard *sb,
                               target->commit->tree->object.sha1,
                               "", &diff_opts);
 
-       if (!diff_opts.find_copies_harder)
+       if (!DIFF_OPT_TST(&diff_opts, FIND_COPIES_HARDER))
                diffcore_std(&diff_opts);
 
        retval = 0;
@@ -1430,8 +1430,7 @@ static void get_commit_info(struct commit *commit,
 static void write_filename_info(const char *path)
 {
        printf("filename ");
-       write_name_quoted(NULL, 0, path, 1, stdout);
-       putchar('\n');
+       write_name_quoted(path, stdout, '\n');
 }
 
 /*
@@ -2003,7 +2002,6 @@ static struct commit *fake_working_tree_commit(const char *path, const char *con
        unsigned char head_sha1[20];
        struct strbuf buf;
        const char *ident;
-       int fd;
        time_t now;
        int size, len;
        struct cache_entry *ce;
@@ -2042,11 +2040,8 @@ static struct commit *fake_working_tree_commit(const char *path, const char *con
                mode = canon_mode(st.st_mode);
                switch (st.st_mode & S_IFMT) {
                case S_IFREG:
-                       fd = open(read_from, O_RDONLY);
-                       if (fd < 0)
-                               die("cannot open %s", read_from);
-                       if (strbuf_read(&buf, fd, 0) != xsize_t(st.st_size))
-                               die("cannot read %s", read_from);
+                       if (strbuf_read_file(&buf, read_from, st.st_size) != st.st_size)
+                               die("cannot open or read %s", read_from);
                        break;
                case S_IFLNK:
                        if (readlink(read_from, buf.buf, buf.alloc) != fin_size)
@@ -2064,6 +2059,7 @@ static struct commit *fake_working_tree_commit(const char *path, const char *con
                if (strbuf_read(&buf, 0, 0) < 0)
                        die("read error %s from stdin", strerror(errno));
        }
+       convert_to_git(path, buf.buf, buf.len, &buf);
        origin->file.ptr = buf.buf;
        origin->file.size = buf.len;
        pretend_sha1_file(buf.buf, buf.len, OBJ_BLOB, origin->blob_sha1);
@@ -2219,9 +2215,6 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
                        argv[unk++] = arg;
        }
 
-       if (!incremental)
-               setup_pager();
-
        if (!blame_move_score)
                blame_move_score = BLAME_DEFAULT_MOVE_SCORE;
        if (!blame_copy_score)
@@ -2302,6 +2295,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
                        else if (i != argc - 1)
                                usage(blame_usage); /* garbage at end */
 
+                       setup_work_tree();
                        if (!has_path_in_work_tree(path))
                                die("cannot stat path %s: %s",
                                    path, strerror(errno));
@@ -2349,6 +2343,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
                 * do not default to HEAD, but use the working tree
                 * or "--contents".
                 */
+               setup_work_tree();
                sb.final = fake_working_tree_commit(path, contents_from);
                add_pending_object(&revs, &(sb.final->object), ":");
        }
@@ -2415,6 +2410,9 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
 
        read_mailmap(&mailmap, ".mailmap", NULL);
 
+       if (!incremental)
+               setup_pager();
+
        assign_blame(&sb, &revs, opt);
 
        if (incremental)