delay creation of secondary threads in tog until view is shown
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 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
diff --git a/tog/tog.c b/tog/tog.c
index 1b742e6..67c3cc4 100644
--- a/tog/tog.c
+++ b/tog/tog.c
@@ -1439,14 +1439,6 @@ open_log_view(struct tog_view *view, struct got_object_id *start_id,
s->thread_args.view = view;
s->thread_args.first_displayed_entry = &s->first_displayed_entry;
s->thread_args.selected_entry = &s->selected_entry;
-
- errcode = pthread_create(&s->thread, NULL, log_thread,
- &s->thread_args);
- if (errcode) {
- err = got_error_set_errno(errcode);
- goto done;
- }
-
done:
if (err)
close_log_view(view);
@@ -1458,6 +1450,13 @@ show_log_view(struct tog_view *view)
{
struct tog_log_view_state *s = &view->state.log;
+ if (s->thread == NULL) {
+ int errcode = pthread_create(&s->thread, NULL, log_thread,
+ &s->thread_args);
+ if (errcode)
+ return got_error_set_errno(errcode);
+ }
+
return draw_commits(view, &s->last_displayed_entry,
&s->selected_entry, s->first_displayed_entry,
&s->commits, s->selected, view->nlines,
@@ -1480,6 +1479,8 @@ input_log_view(struct tog_view **new_view, struct tog_view **dead_view,
break;
case 'k':
case KEY_UP:
+ if (s->first_displayed_entry == NULL)
+ break;
if (s->selected > 0)
s->selected--;
if (s->selected > 0)
@@ -1488,6 +1489,8 @@ input_log_view(struct tog_view **new_view, struct tog_view **dead_view,
&s->commits);
break;
case KEY_PPAGE:
+ if (s->first_displayed_entry == NULL)
+ break;
if (TAILQ_FIRST(&s->commits.head) ==
s->first_displayed_entry) {
s->selected = 0;
@@ -1498,6 +1501,8 @@ input_log_view(struct tog_view **new_view, struct tog_view **dead_view,
break;
case 'j':
case KEY_DOWN:
+ if (s->first_displayed_entry == NULL)
+ break;
if (s->selected < MIN(view->nlines - 2,
s->commits.ncommits - 1)) {
s->selected++;
@@ -1512,6 +1517,8 @@ input_log_view(struct tog_view **new_view, struct tog_view **dead_view,
case KEY_NPAGE: {
struct commit_queue_entry *first;
first = s->first_displayed_entry;
+ if (first == NULL)
+ break;
err = scroll_down(&s->first_displayed_entry,
view->nlines, &s->last_displayed_entry,
&s->commits, &s->thread_args.log_complete,
@@ -1535,6 +1542,8 @@ input_log_view(struct tog_view **new_view, struct tog_view **dead_view,
break;
case KEY_ENTER:
case '\r':
+ if (s->selected_entry == NULL)
+ break;
if (view_is_parent_view(view))
begin_x = view_split_begin_x(view->begin_x);
err = open_diff_view_for_commit(&diff_view, begin_x,
@@ -1559,6 +1568,8 @@ input_log_view(struct tog_view **new_view, struct tog_view **dead_view,
*new_view = diff_view;
break;
case 't':
+ if (s->selected_entry == NULL)
+ break;
if (view_is_parent_view(view))
begin_x = view_split_begin_x(view->begin_x);
err = browse_commit(&tree_view, begin_x,
@@ -2379,7 +2390,6 @@ run_blame(struct tog_blame *blame, struct tog_view *view, int *blame_complete,
struct got_repository *thread_repo = NULL;
struct got_object_id *obj_id = NULL;
struct got_object *obj = NULL;
- int errcode;
err = got_object_id_by_path(&obj_id, repo, commit_id, path);
if (err)
@@ -2433,13 +2443,6 @@ run_blame(struct tog_blame *blame, struct tog_view *view, int *blame_complete,
blame->thread_args.complete = blame_complete;
*blame_complete = 0;
- errcode = pthread_create(&blame->thread, NULL, blame_thread,
- &blame->thread_args);
- if (errcode) {
- err = got_error_set_errno(errcode);
- goto done;
- }
-
done:
if (blob)
got_object_blob_close(blob);
@@ -2512,6 +2515,14 @@ show_blame_view(struct tog_view *view)
{
const struct got_error *err = NULL;
struct tog_blame_view_state *s = &view->state.blame;
+ int errcode;
+
+ if (s->blame.thread == NULL) {
+ errcode = pthread_create(&s->blame.thread, NULL, blame_thread,
+ &s->blame.thread_args);
+ if (errcode)
+ return got_error_set_errno(errcode);
+ }
err = draw_blame(view, s->blamed_commit->id, s->blame.f,
s->path, s->blame.lines, s->blame.nlines, s->blame_complete,