make tog's tree view data structure non-global
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
diff --git a/tog/tog.c b/tog/tog.c
index e53bce1..4688ed6 100644
--- a/tog/tog.c
+++ b/tog/tog.c
@@ -82,10 +82,10 @@ static struct tog_cmd tog_commands[] = {
"browse trees in repository" },
};
-static struct tog_view {
+struct tog_view {
WINDOW *window;
PANEL *panel;
-} tog_tree_view;
+};
static const struct got_error *
show_diff_view(struct tog_view *, struct got_object *, struct got_object *,
@@ -2186,6 +2186,7 @@ show_tree_view(struct got_tree_object *root, struct got_object_id *commit_id,
char *commit_id_str = NULL, *tree_label = NULL;
int nentries, ndisplayed;
struct tog_parent_trees parents;
+ struct tog_view *view = NULL;
TAILQ_INIT(&parents);
@@ -2198,18 +2199,12 @@ show_tree_view(struct got_tree_object *root, struct got_object_id *commit_id,
goto done;
}
- if (tog_tree_view.window == NULL) {
- tog_tree_view.window = newwin(0, 0, 0, 0);
- if (tog_tree_view.window == NULL)
- return got_error_from_errno();
- keypad(tog_tree_view.window, TRUE);
+ view = open_view();
+ if (view == NULL) {
+ err = got_error_from_errno();
+ goto done;
}
- if (tog_tree_view.panel == NULL) {
- tog_tree_view.panel = new_panel(tog_tree_view.window);
- if (tog_tree_view.panel == NULL)
- return got_error_from_errno();
- } else
- show_panel(tog_tree_view.panel);
+ show_panel(view->panel);
entries = got_object_tree_get_entries(root);
first_displayed_entry = SIMPLEQ_FIRST(&entries->head);
@@ -2226,14 +2221,14 @@ show_tree_view(struct got_tree_object *root, struct got_object_id *commit_id,
err = draw_tree_entries(&first_displayed_entry,
&last_displayed_entry, &selected_entry, &ndisplayed,
- tog_tree_view.window, tree_label, show_ids,
+ view->window, tree_label, show_ids,
parent_path, entries, selected, LINES, tree == root);
free(parent_path);
if (err)
break;
nodelay(stdscr, FALSE);
- ch = wgetch(tog_tree_view.window);
+ ch = wgetch(view->window);
nodelay(stdscr, TRUE);
switch (ch) {
case 'q':
@@ -2343,6 +2338,8 @@ show_tree_view(struct got_tree_object *root, struct got_object_id *commit_id,
}
}
done:
+ if (view)
+ close_view(view);
free(tree_label);
free(commit_id_str);
while (!TAILQ_EMPTY(&parents)) {