]> asedeno.scripts.mit.edu Git - git.git/blobdiff - builtin-blame.c
user-manual: minor rewording for clarity.
[git.git] / builtin-blame.c
index 1b1e6da85317200bd73e44071498fbf83d127487..ba80bf8942f1db42b8a132471ddbfc38e565f115 100644 (file)
@@ -18,7 +18,6 @@
 #include "cache-tree.h"
 #include "path-list.h"
 #include "mailmap.h"
-#include "strbuf.h"
 
 static char blame_usage[] =
 "git-blame [-c] [-b] [-l] [--root] [-t] [-f] [-n] [-s] [-p] [-w] [-L n,m] [-S <revs-file>] [-M] [-C] [-C] [--contents <filename>] [--incremental] [commit] [--] file\n"
@@ -1431,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');
 }
 
 /*
@@ -2004,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;
@@ -2023,7 +2020,7 @@ static struct commit *fake_working_tree_commit(const char *path, const char *con
 
        origin = make_origin(commit, path);
 
-       strbuf_init(&buf);
+       strbuf_init(&buf, 0);
        if (!contents_from || strcmp("-", contents_from)) {
                struct stat st;
                const char *read_from;
@@ -2043,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) != 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)
@@ -2062,9 +2056,10 @@ static struct commit *fake_working_tree_commit(const char *path, const char *con
                /* Reading from stdin */
                contents_from = "standard input";
                mode = 0;
-               if (strbuf_read(&buf, 0) < 0)
+               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);
@@ -2220,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)
@@ -2303,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));
@@ -2350,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), ":");
        }
@@ -2416,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)