Code

tig-0.16
[tig.git] / tig.c
diff --git a/tig.c b/tig.c
index c2417bfee168eb4b52c6287ee01bcc524a9bc635..a82a4686e4696316a00eeb9473d8deb934df6e4b 100644 (file)
--- a/tig.c
+++ b/tig.c
@@ -209,7 +209,7 @@ string_ncopy_do(char *dst, size_t dstlen, const char *src, size_t srclen)
 #define string_add(dst, from, src) \
        string_ncopy_do(dst + (from), sizeof(dst) - (from), src, sizeof(src))
 
-static void
+static size_t
 string_expand(char *dst, size_t dstlen, const char *src, int tabsize)
 {
        size_t size, pos;
@@ -228,6 +228,7 @@ string_expand(char *dst, size_t dstlen, const char *src, int tabsize)
        }
 
        dst[size] = 0;
+       return pos;
 }
 
 static char *
@@ -2134,6 +2135,7 @@ load_options(void)
        const char *home = getenv("HOME");
        const char *tigrc_user = getenv("TIGRC_USER");
        const char *tigrc_system = getenv("TIGRC_SYSTEM");
+       const char *tig_diff_opts = getenv("TIG_DIFF_OPTS");
        char buf[SIZEOF_STR];
 
        if (!tigrc_system)
@@ -2151,6 +2153,17 @@ load_options(void)
         * that conflict with keybindings. */
        add_builtin_run_requests();
 
+       if (!opt_diff_args && tig_diff_opts && *tig_diff_opts) {
+               static const char *diff_opts[SIZEOF_ARG] = { NULL };
+               int argc = 0;
+
+               if (!string_format(buf, "%s", tig_diff_opts) ||
+                   !argv_from_string(diff_opts, &argc, buf))
+                       die("TIG_DIFF_OPTS contains too many arguments");
+               else if (!argv_copy(&opt_diff_args, diff_opts))
+                       die("Failed to format TIG_DIFF_OPTS arguments");
+       }
+
        return OK;
 }
 
@@ -2396,7 +2409,15 @@ draw_space(struct view *view, enum line_type type, int max, int spaces)
 static bool
 draw_text(struct view *view, enum line_type type, const char *string, bool trim)
 {
-       view->col += draw_chars(view, type, string, view->width + view->yoffset - view->col, trim);
+       char text[SIZEOF_STR];
+
+       do {
+               size_t pos = string_expand(text, sizeof(text), string, opt_tab_size);
+
+               view->col += draw_chars(view, type, text, view->width + view->yoffset - view->col, trim);
+               string += pos;
+       } while (*string && view->width + view->yoffset > view->col);
+
        return view->width + view->yoffset <= view->col;
 }
 
@@ -3179,17 +3200,17 @@ format_argv(const char ***dst_argv, const char *src_argv[], bool replace)
                const char *arg = src_argv[argc];
                size_t bufpos = 0;
 
-               if (!strcmp(arg, "%(file-args)")) {
+               if (!strcmp(arg, "%(fileargs)")) {
                        if (!argv_append_array(dst_argv, opt_file_args))
                                break;
                        continue;
 
-               } else if (!strcmp(arg, "%(diff-args)")) {
+               } else if (!strcmp(arg, "%(diffargs)")) {
                        if (!argv_append_array(dst_argv, opt_diff_args))
                                break;
                        continue;
 
-               } else if (!strcmp(arg, "%(rev-args)")) {
+               } else if (!strcmp(arg, "%(revargs)")) {
                        if (!argv_append_array(dst_argv, opt_rev_args))
                                break;
                        continue;
@@ -3984,13 +4005,10 @@ parse_author_line(char *ident, const char **author, struct time *time)
 static bool
 pager_draw(struct view *view, struct line *line, unsigned int lineno)
 {
-       char text[SIZEOF_STR];
-
        if (opt_line_number && draw_lineno(view, lineno))
                return TRUE;
 
-       string_expand(text, sizeof(text), line->data, opt_tab_size);
-       draw_text(view, line->type, text, TRUE);
+       draw_text(view, line->type, line->data, TRUE);
        return TRUE;
 }
 
@@ -4165,7 +4183,7 @@ static struct view_ops log_ops = {
 static const char *diff_argv[SIZEOF_ARG] = {
        "git", "show", "--pretty=fuller", "--no-color", "--root",
                "--patch-with-stat", "--find-copies-harder", "-C",
-               "%(diff-args)", "%(commit)", "--", "%(file-args)", NULL
+               "%(diffargs)", "%(commit)", "--", "%(fileargs)", NULL
 };
 
 static struct view_ops diff_ops = {
@@ -5070,7 +5088,6 @@ blame_draw(struct view *view, struct line *line, unsigned int lineno)
        struct blame *blame = line->data;
        struct time *time = NULL;
        const char *id = NULL, *author = NULL;
-       char text[SIZEOF_STR];
 
        if (blame->commit && *blame->commit->filename) {
                id = blame->commit->id;
@@ -5090,8 +5107,7 @@ blame_draw(struct view *view, struct line *line, unsigned int lineno)
        if (draw_lineno(view, lineno))
                return TRUE;
 
-       string_expand(text, sizeof(text), blame->text, opt_tab_size);
-       draw_text(view, LINE_DEFAULT, text, TRUE);
+       draw_text(view, LINE_DEFAULT, blame->text, TRUE);
        return TRUE;
 }
 
@@ -5110,16 +5126,20 @@ check_blame_commit(struct blame *blame, bool check_null_id)
 static void
 setup_blame_parent_line(struct view *view, struct blame *blame)
 {
+       char from[SIZEOF_REF + SIZEOF_STR];
+       char to[SIZEOF_REF + SIZEOF_STR];
        const char *diff_tree_argv[] = {
-               "git", "diff-tree", "-U0", blame->commit->id,
-                       "--", blame->commit->filename, NULL
+               "git", "diff", "--no-textconv", "--no-extdiff", "--no-color",
+                       "-U0", from, to, "--", NULL
        };
        struct io io;
        int parent_lineno = -1;
        int blamed_lineno = -1;
        char *line;
 
-       if (!io_run(&io, IO_RD, NULL, diff_tree_argv))
+       if (!string_format(from, "%s:%s", opt_ref, opt_file) ||
+           !string_format(to, "%s:%s", blame->commit->id, blame->commit->filename) ||
+           !io_run(&io, IO_RD, NULL, diff_tree_argv))
                return;
 
        while ((line = io_get(&io, '\n', TRUE))) {
@@ -6687,8 +6707,8 @@ update_rev_graph(struct view *view, struct rev_graph *graph)
 
 static const char *main_argv[SIZEOF_ARG] = {
        "git", "log", "--no-color", "--pretty=raw", "--parents",
-               "--topo-order", "%(diff-args)", "%(rev-args)",
-               "--", "%(file-args)", NULL
+               "--topo-order", "%(diffargs)", "%(revargs)",
+               "--", "%(fileargs)", NULL
 };
 
 static bool