index a7dd9154dd5f609da7f65e44746230d73197f199..a4b27db47f2b7f52d7bab7d9a23f6e7f4db187c1 100644 (file)
--- a/tig.c
+++ b/tig.c
time_t update_secs;
};
+enum open_flags {
+ OPEN_DEFAULT = 0, /* Use default view switching. */
+ OPEN_SPLIT = 1, /* Split current view. */
+ OPEN_RELOAD = 4, /* Reload view even if it is the current. */
+ OPEN_REFRESH = 16, /* Refresh view using previous command. */
+ OPEN_PREPARED = 32, /* Open already prepared command. */
+};
+
struct view_ops {
/* What type of content being displayed. Used in the title bar. */
const char *type;
/* Default command arguments. */
const char **argv;
/* Open and reads in all view content. */
- bool (*open)(struct view *view);
+ bool (*open)(struct view *view, enum open_flags flags);
/* Read one line; updates view->line. */
bool (*read)(struct view *view, char *data);
/* Draw one line; @lineno must be < view->height. */
}
static bool
-begin_update(struct view *view, bool refresh)
+view_open(struct view *view, enum open_flags flags)
{
+ bool reload = !!(flags & (OPEN_RELOAD | OPEN_REFRESH | OPEN_PREPARED));
+ bool refresh = flags & (OPEN_REFRESH | OPEN_PREPARED);
+
+ if (!reload && !strcmp(view->vid, view->id))
+ return TRUE;
+
if (view->pipe)
end_update(view, TRUE);
@@ -2687,14 +2701,6 @@ add_line_format(struct view *view, enum line_type type, const char *fmt, ...)
* View opening
*/
-enum open_flags {
- OPEN_DEFAULT = 0, /* Use default view switching. */
- OPEN_SPLIT = 1, /* Split current view. */
- OPEN_RELOAD = 4, /* Reload view even if it is the current. */
- OPEN_REFRESH = 16, /* Refresh view using previous command. */
- OPEN_PREPARED = 32, /* Open already prepared command. */
-};
-
static void
open_view(struct view *prev, enum request request, enum open_flags flags)
{
if (view->ops->open) {
if (view->pipe)
end_update(view, TRUE);
- if (!view->ops->open(view)) {
+ if (!view->ops->open(view, flags)) {
report("Failed to load %s view", view->name);
return;
}
restore_view_position(view);
-
- } else if ((reload || strcmp(view->vid, view->id)) &&
- !begin_update(view, flags & (OPEN_REFRESH | OPEN_PREPARED))) {
- report("Failed to load %s view", view->name);
- return;
}
if (split && prev->lineno - prev->offset >= prev->height) {
static struct view_ops pager_ops = {
"line",
NULL,
- NULL,
+ view_open,
pager_read,
pager_draw,
pager_request,
static struct view_ops log_ops = {
"line",
log_argv,
- NULL,
+ view_open,
pager_read,
pager_draw,
log_request,
static struct view_ops diff_ops = {
"line",
diff_argv,
- NULL,
+ view_open,
diff_read,
pager_draw,
pager_request,
}
static bool
-help_open(struct view *view)
+help_open(struct view *view, enum open_flags flags)
{
enum keymap keymap;
static struct view_ops tree_ops = {
"file",
tree_argv,
- NULL,
+ view_open,
tree_read,
tree_draw,
tree_request,
static struct view_ops blob_ops = {
"line",
blob_argv,
- NULL,
+ view_open,
blob_read,
pager_draw,
blob_request,
};
static bool
-blame_open(struct view *view)
+blame_open(struct view *view, enum open_flags flags)
{
char path[SIZEOF_STR];
size_t i;
}
static bool
-branch_open(struct view *view)
+branch_open(struct view *view, enum open_flags flags)
{
const char *branch_log[] = {
"git", "log", "--no-color", "--pretty=raw",
* info using git-diff-files(1), and finally untracked files using
* git-ls-files(1). */
static bool
-status_open(struct view *view)
+status_open(struct view *view, enum open_flags flags)
{
reset_view(view);
static struct view_ops stage_ops = {
"line",
NULL,
- NULL,
+ view_open,
pager_read,
pager_draw,
stage_request,
static struct view_ops main_ops = {
"commit",
main_argv,
- NULL,
+ view_open,
main_read,
main_draw,
main_request,