Don't reload the stash view when switching back to it
[tig.git] / src / stash.c
blobdcafe8c6430367913f88d90cbe86b1f929fe678f
1 /* Copyright (c) 2006-2015 Jonas Fonseca <jonas.fonseca@gmail.com>
3 * This program is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU General Public License as
5 * published by the Free Software Foundation; either version 2 of
6 * the License, or (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
14 #include "tig/display.h"
15 #include "tig/draw.h"
16 #include "tig/main.h"
17 #include "tig/diff.h"
19 static bool
20 stash_open(struct view *view, enum open_flags flags)
22 static const char *stash_argv[] = { "git", "stash", "list",
23 encoding_arg, "--no-color", "--pretty=raw", NULL };
24 struct main_state *state = view->private;
26 state->with_graph = false;
27 watch_register(&view->watch, WATCH_STASH);
28 return begin_update(view, NULL, stash_argv, flags | OPEN_RELOAD);
31 static void
32 stash_select(struct view *view, struct line *line)
34 main_select(view, line);
35 string_format(view->env->stash, "stash@{%d}", line->lineno - 1);
36 string_copy(view->ref, view->env->stash);
39 enum request
40 stash_request(struct view *view, enum request request, struct line *line)
42 enum open_flags flags = (view_is_displayed(view) && request != REQ_VIEW_DIFF)
43 ? OPEN_SPLIT : OPEN_DEFAULT;
44 struct view *diff = &diff_view;
46 switch (request) {
47 case REQ_VIEW_DIFF:
48 case REQ_ENTER:
49 if (view_is_displayed(view) && display[0] != view)
50 maximize_view(view, true);
52 if (!view_is_displayed(diff) ||
53 strcmp(view->env->stash, diff->ref)) {
54 const char *diff_argv[] = {
55 "git", "stash", "show", encoding_arg, "--pretty=fuller",
56 "--root", "--patch-with-stat", use_mailmap_arg(),
57 show_notes_arg(), diff_context_arg(),
58 ignore_space_arg(), "%(diffargs)",
59 "--no-color", "%(stash)", NULL
62 if (!argv_format(diff_view.env, &diff_view.argv, diff_argv, false, false))
63 report("Failed to format argument");
64 else
65 open_view(view, &diff_view, flags | OPEN_PREPARED);
67 return REQ_NONE;
69 default:
70 return main_request(view, request, line);
74 static struct view_ops stash_ops = {
75 "stash",
76 "",
77 VIEW_SEND_CHILD_ENTER | VIEW_REFRESH,
78 sizeof(struct main_state),
79 stash_open,
80 main_read,
81 view_column_draw,
82 stash_request,
83 view_column_grep,
84 stash_select,
85 main_done,
86 view_column_bit(AUTHOR) | view_column_bit(COMMIT_TITLE) |
87 view_column_bit(DATE) | view_column_bit(ID) |
88 view_column_bit(LINE_NUMBER),
89 main_get_column_data,
92 DEFINE_VIEW(stash);
94 /* vim: set ts=8 sw=8 noexpandtab: */