index 8bed28e8b72fede7d1d476e571b7a00e03b2d9f7..7ad7fe741ce2b80ac74c58503b9529ed76ecb886 100644 (file)
--- a/tig.c
+++ b/tig.c
}
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))
}
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
#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)
{
}
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);
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);