summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 7dfa0b2)
raw | patch | inline | side by side (parent: 7dfa0b2)
author | Jonas Fonseca <fonseca@diku.dk> | |
Fri, 11 Mar 2011 13:24:40 +0000 (08:24 -0500) | ||
committer | Jonas Fonseca <fonseca@diku.dk> | |
Thu, 17 Mar 2011 01:18:55 +0000 (21:18 -0400) |
tig.c | patch | blob | history |
index 8b46fa7f79629ed6bde86251f838530c05dcc071..199eb34b7cfc434e915bf9026114dafb68ca280d 100644 (file)
--- a/tig.c
+++ b/tig.c
@@ -2504,14 +2504,6 @@ prepare_io(struct view *view, const char *dir, const char *argv[], bool replace)
return format_argv(&view->argv, argv, replace, !view->prev);
}
-static bool
-prepare_update(struct view *view, const char *argv[], const char *dir)
-{
- if (view->pipe)
- end_update(view, TRUE);
- return prepare_io(view, dir, argv, FALSE);
-}
-
static bool
start_update(struct view *view, const char **argv, const char *dir)
{
io_run(&view->io, IO_RD, dir, view->argv);
}
-static bool
-prepare_update_file(struct view *view, const char *name)
-{
- const char *file_argv[] = { opt_cdup, name , NULL };
-
- if (view->pipe)
- end_update(view, TRUE);
- return argv_copy(&view->argv, file_argv);
-}
-
static bool
begin_update(struct view *view, const char *dir, const char **argv, enum open_flags flags)
{
}
}
+static void
+open_argv(struct view *prev, struct view *view, const char *argv[], const char *dir, enum open_flags flags)
+{
+ enum request request = view - views + REQ_OFFSET + 1;
+
+ if (view->pipe)
+ end_update(view, TRUE);
+ if (!prepare_io(view, dir, argv, FALSE)) {
+ report("Failed to open %s view: %s", view->name, io_strerror(&view->io));
+ } else {
+ open_view(prev, request, flags | OPEN_PREPARED);
+ }
+}
+
+static void
+open_file(struct view *prev, struct view *view, const char *file, enum open_flags flags)
+{
+ enum request request = view - views + REQ_OFFSET + 1;
+ const char *file_argv[] = { opt_cdup, file , NULL };
+
+ if (view->pipe)
+ end_update(view, TRUE);
+ if (!argv_copy(&view->argv, file_argv)) {
+ report("Failed to load %s: out of memory", file);
+ } else {
+ open_view(prev, request, flags | OPEN_PREPARED);
+ }
+}
+
static void
open_external_viewer(const char *argv[], const char *dir)
{
diff_index_argv[7] = "/dev/null";
}
- if (!prepare_update(diff, diff_index_argv, NULL)) {
- report("Failed to allocate diff command");
- break;
- }
- flags |= OPEN_PREPARED;
+ open_argv(view, diff, diff_index_argv, NULL, flags);
+ } else {
+ open_view(view, REQ_VIEW_DIFF, flags);
}
-
- open_view(view, REQ_VIEW_DIFF, flags);
if (VIEW(REQ_VIEW_DIFF)->pipe && !strcmp(blame->commit->id, NULL_ID))
string_copy_rev(VIEW(REQ_VIEW_DIFF)->ref, NULL_ID);
break;
};
struct view *main_view = VIEW(REQ_VIEW_MAIN);
- if (!prepare_update(main_view, all_branches_argv, NULL))
- report("Failed to load view of all branches");
- else
- open_view(view, REQ_VIEW_MAIN, OPEN_PREPARED | OPEN_SPLIT);
+ open_argv(view, main_view, all_branches_argv, NULL, OPEN_SPLIT);
return REQ_NONE;
}
default:
return TRUE;
}
-static enum request
-status_load_error(struct view *view, struct view *stage, const char *path)
-{
- if (displayed_views() == 2 || display[current_view] != view)
- maximize_view(view);
- report("Failed to load '%s': %s", path, io_strerror(&stage->io));
- return REQ_NONE;
-}
-
static enum request
status_enter(struct view *view, struct line *line)
{
* path, so leave it empty. */
const char *newpath = status && status->status != 'U' ? status->new.name : NULL;
const char *info;
- enum open_flags split;
+ enum open_flags flags = view_is_displayed(view) ? OPEN_SPLIT : OPEN_DEFAULT;
struct view *stage = VIEW(REQ_VIEW_STAGE);
if (line->type == LINE_STAT_NONE ||
"--", "/dev/null", newpath, NULL
};
- if (!prepare_update(stage, no_head_diff_argv, opt_cdup))
- return status_load_error(view, stage, newpath);
+ open_argv(view, stage, no_head_diff_argv, opt_cdup, flags);
} else {
const char *index_show_argv[] = {
"git", "diff-index", "--root", "--patch-with-stat",
oldpath, newpath, NULL
};
- if (!prepare_update(stage, index_show_argv, opt_cdup))
- return status_load_error(view, stage, newpath);
+ open_argv(view, stage, index_show_argv, opt_cdup, flags);
}
if (status)
"-C", "-M", "--", oldpath, newpath, NULL
};
- if (!prepare_update(stage, files_show_argv, opt_cdup))
- return status_load_error(view, stage, newpath);
+ open_argv(view, stage, files_show_argv, opt_cdup, flags);
if (status)
info = "Unstaged changes to %s";
else
return REQ_NONE;
}
- if (!prepare_update_file(stage, newpath))
- return status_load_error(view, stage, newpath);
+ open_file(view, stage, newpath, flags);
info = "Untracked file %s";
break;
die("line type %d not handled in switch", line->type);
}
- split = view_is_displayed(view) ? OPEN_SPLIT : OPEN_DEFAULT;
- open_view(view, REQ_VIEW_STAGE, OPEN_PREPARED | split);
if (view_is_displayed(VIEW(REQ_VIEW_STAGE))) {
if (status) {
stage_status = *status;
if (!argv_from_string(argv, &argc, cmd)) {
report("Too many arguments");
- } else if (!prepare_update(next, argv, NULL)) {
- report("Failed to format command");
} else {
- open_view(view, REQ_VIEW_PAGER, OPEN_PREPARED);
+ open_argv(view, next, argv, NULL, OPEN_DEFAULT);
}
}