X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=tig.c;h=7ad7fe741ce2b80ac74c58503b9529ed76ecb886;hb=2fa792e814f533b95124fef2eac6b556a8db392a;hp=8bed28e8b72fede7d1d476e571b7a00e03b2d9f7;hpb=8f2046c514645767395d2ee735a99ab2358d42b9;p=tig.git diff --git a/tig.c b/tig.c index 8bed28e..7ad7fe7 100644 --- a/tig.c +++ b/tig.c @@ -2390,7 +2390,7 @@ format_arg(const char *name) } static bool -format_argv(const char ***dst_argv, const char *src_argv[], bool replace, bool first) +format_argv(const char ***dst_argv, const char *src_argv[], bool first) { char buf[SIZEOF_STR]; int argc; @@ -2428,7 +2428,7 @@ format_argv(const char ***dst_argv, const char *src_argv[], bool replace, bool f int len = next - arg; const char *value; - if (!next || !replace) { + if (!next) { len = strlen(arg); value = ""; @@ -2443,7 +2443,7 @@ format_argv(const char ***dst_argv, const char *src_argv[], bool replace, bool f if (!string_format_from(buf, &bufpos, "%.*s%s", len, arg, value)) return FALSE; - arg = next && replace ? strchr(next, ')') + 1 : NULL; + arg = next ? strchr(next, ')') + 1 : NULL; } if (!argv_append(dst_argv, buf)) @@ -2500,18 +2500,18 @@ setup_update(struct view *view, const char *vid) } static bool -prepare_io(struct view *view, const char *dir, const char *argv[], bool replace) +prepare_update(struct view *view, const char *dir, const char *argv[]) { + if (view->pipe) + io_done(view->pipe); view->dir = dir; - return format_argv(&view->argv, argv, replace, !view->prev); + return argv_copy(&view->argv, argv); } static bool start_update(struct view *view, const char **argv, const char *dir) { - if (view->pipe) - io_done(view->pipe); - return prepare_io(view, dir, argv, FALSE) && + return prepare_update(view, dir, argv) && io_run(&view->io, IO_RD, dir, view->argv); } @@ -2528,7 +2528,8 @@ begin_update(struct view *view, const char *dir, const char **argv, enum open_fl end_update(view, TRUE); if (!refresh) { - if (!prepare_io(view, dir, argv, TRUE)) + view->dir = dir; + if (!format_argv(&view->argv, argv, !view->prev)) return FALSE; /* Put the current ref_* value to the view title ref @@ -2717,6 +2718,29 @@ load_view(struct view *view, enum open_flags flags) #define refresh_view(view) load_view(view, OPEN_REFRESH) +static void +split_view(struct view *prev, struct view *view) +{ + display[1] = view; + current_view = 1; + view->parent = prev; + resize_display(); + + if (prev->lineno - prev->offset >= prev->height) { + /* Take the title line into account. */ + int lines = prev->lineno - prev->offset - prev->height + 1; + + /* Scroll the view that was split if the current line is + * outside the new limited view. */ + do_scroll_view(prev, lines); + } + + if (view != prev && view_is_displayed(prev)) { + /* "Blur" the previous view. */ + update_view_title(prev); + } +} + static void open_view(struct view *prev, enum request request, enum open_flags flags) { @@ -2738,24 +2762,7 @@ open_view(struct view *prev, enum request request, enum open_flags flags) } if (split) { - display[1] = view; - current_view = 1; - view->parent = prev; - resize_display(); - - if (prev->lineno - prev->offset >= prev->height) { - /* Take the title line into account. */ - int lines = prev->lineno - prev->offset - prev->height + 1; - - /* Scroll the view that was split if the current line is - * outside the new limited view. */ - do_scroll_view(prev, lines); - } - - if (view != prev && view_is_displayed(prev)) { - /* "Blur" the previous view. */ - update_view_title(prev); - } + split_view(prev, view); } else { maximize_view(view, FALSE); } @@ -2773,9 +2780,7 @@ open_argv(struct view *prev, struct view *view, const char *argv[], const char * { enum request request = view - views + REQ_OFFSET + 1; - if (view->pipe) - end_update(view, TRUE); - if (!prepare_io(view, dir, argv, FALSE)) { + if (!prepare_update(view, dir, argv)) { report("Failed to open %s view: %s", view->name, io_strerror(&view->io)); } else { open_view(prev, request, flags | OPEN_PREPARED); @@ -2848,7 +2853,7 @@ open_run_request(enum request request) return; } - if (format_argv(&argv, req->argv, TRUE, FALSE)) + if (format_argv(&argv, req->argv, FALSE)) open_external_viewer(argv, NULL); if (argv) argv_free(argv);