Code

Documentation: receive.denyCurrentBranch defaults to 'refuse'
[git.git] / builtin-blame.c
index 0afdb16cb0e14367994fac99b60f36c292aeaac9..fc1586350f94ae48e7e48a51818517b465e7a40d 100644 (file)
@@ -1305,6 +1305,7 @@ static void get_ac_line(const char *inbuf, const char *what,
        error_out:
                /* Ugh */
                *tz = "(unknown)";
+               strcpy(person, *tz);
                strcpy(mail, *tz);
                *time = 0;
                return;
@@ -1314,20 +1315,26 @@ static void get_ac_line(const char *inbuf, const char *what,
        tmp = person;
        tmp += len;
        *tmp = 0;
-       while (*tmp != ' ')
+       while (person < tmp && *tmp != ' ')
                tmp--;
+       if (tmp <= person)
+               goto error_out;
        *tz = tmp+1;
        tzlen = (person+len)-(tmp+1);
 
        *tmp = 0;
-       while (*tmp != ' ')
+       while (person < tmp && *tmp != ' ')
                tmp--;
+       if (tmp <= person)
+               goto error_out;
        *time = strtoul(tmp, NULL, 10);
        timepos = tmp;
 
        *tmp = 0;
-       while (*tmp != ' ')
+       while (person < tmp && *tmp != ' ')
                tmp--;
+       if (tmp <= person)
+               return;
        mailpos = tmp + 1;
        *tmp = 0;
        maillen = timepos - tmp;
@@ -1348,7 +1355,7 @@ static void get_ac_line(const char *inbuf, const char *what,
        /*
         * Now, convert both name and e-mail using mailmap
         */
-       if(map_user(&mailmap, mail+1, mail_len-1, person, tmp-person-1)) {
+       if (map_user(&mailmap, mail+1, mail_len-1, person, tmp-person-1)) {
                /* Add a trailing '>' to email, since map_user returns plain emails
                   Note: It already has '<', since we replace from mail+1 */
                mailpos = memchr(mail, '\0', mail_len);
@@ -1604,6 +1611,9 @@ static void emit_porcelain(struct scoreboard *sb, struct blame_entry *ent)
                } while (ch != '\n' &&
                         cp < sb->final_buf + sb->final_buf_size);
        }
+
+       if (sb->final_buf_size && cp[-1] != '\n')
+               putchar('\n');
 }
 
 static void emit_other(struct scoreboard *sb, struct blame_entry *ent, int opt)
@@ -1667,6 +1677,9 @@ static void emit_other(struct scoreboard *sb, struct blame_entry *ent, int opt)
                } while (ch != '\n' &&
                         cp < sb->final_buf + sb->final_buf_size);
        }
+
+       if (sb->final_buf_size && cp[-1] != '\n')
+               putchar('\n');
 }
 
 static void output(struct scoreboard *sb, int option)
@@ -1759,7 +1772,7 @@ static int lineno_width(int lines)
 {
        int i, width;
 
-       for (width = 1, i = 10; i <= lines + 1; width++)
+       for (width = 1, i = 10; i <= lines; width++)
                i *= 10;
        return width;
 }
@@ -2008,23 +2021,23 @@ static struct commit *fake_working_tree_commit(const char *path, const char *con
 
                if (contents_from) {
                        if (stat(contents_from, &st) < 0)
-                               die("Cannot stat %s", contents_from);
+                               die_errno("Cannot stat '%s'", contents_from);
                        read_from = contents_from;
                }
                else {
                        if (lstat(path, &st) < 0)
-                               die("Cannot lstat %s", path);
+                               die_errno("Cannot lstat '%s'", path);
                        read_from = path;
                }
                mode = canon_mode(st.st_mode);
                switch (st.st_mode & S_IFMT) {
                case S_IFREG:
                        if (strbuf_read_file(&buf, read_from, st.st_size) != st.st_size)
-                               die("cannot open or read %s", read_from);
+                               die_errno("cannot open or read '%s'", read_from);
                        break;
                case S_IFLNK:
                        if (strbuf_readlink(&buf, read_from, st.st_size) < 0)
-                               die("cannot readlink %s", read_from);
+                               die_errno("cannot readlink '%s'", read_from);
                        break;
                default:
                        die("unsupported file type %s", read_from);
@@ -2035,7 +2048,7 @@ static struct commit *fake_working_tree_commit(const char *path, const char *con
                contents_from = "standard input";
                mode = 0;
                if (strbuf_read(&buf, 0, 0) < 0)
-                       die("read error %s from stdin", strerror(errno));
+                       die_errno("failed to read from stdin");
        }
        convert_to_git(path, buf.buf, buf.len, &buf, 0);
        origin->file.ptr = buf.buf;
@@ -2239,7 +2252,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
        save_commit_buffer = 0;
        dashdash_pos = 0;
 
-       parse_options_start(&ctx, argc, argv, PARSE_OPT_KEEP_DASHDASH |
+       parse_options_start(&ctx, argc, argv, prefix, PARSE_OPT_KEEP_DASHDASH |
                            PARSE_OPT_KEEP_ARGV0);
        for (;;) {
                switch (parse_options_step(&ctx, options, blame_opt_usage)) {
@@ -2261,8 +2274,7 @@ parse_done:
        argc = parse_options_end(&ctx);
 
        if (revs_file && read_ancestry(revs_file))
-               die("reading graft file %s failed: %s",
-                   revs_file, strerror(errno));
+               die_errno("reading graft file '%s' failed", revs_file);
 
        if (cmd_is_annotate) {
                output_option |= OUTPUT_ANNOTATE_COMPAT;
@@ -2350,9 +2362,10 @@ parse_done:
 
                setup_work_tree();
                if (!has_string_in_work_tree(path))
-                       die("cannot stat path %s: %s", path, strerror(errno));
+                       die_errno("cannot stat path '%s'", path);
        }
 
+       revs.disable_stdin = 1;
        setup_revisions(argc, argv, &revs, NULL);
        memset(&sb, 0, sizeof(sb));
 
@@ -2420,7 +2433,7 @@ parse_done:
        if (top < 1)
                top = lno;
        bottom--;
-       if (lno < top)
+       if (lno < top || lno < bottom)
                die("file %s has only %lu lines", path, lno);
 
        ent = xcalloc(1, sizeof(*ent));