index c2417bfee168eb4b52c6287ee01bcc524a9bc635..a82a4686e4696316a00eeb9473d8deb934df6e4b 100644 (file)
--- a/tig.c
+++ b/tig.c
#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;
}
dst[size] = 0;
+ return pos;
}
static char *
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)
* 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;
}
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;
}
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;
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;
}
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 = {
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;
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;
}
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))) {
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