commit fb280deb15e67b1bd8ef0f722a7430b8e9312871 from: Stefan Sperling date: Mon Aug 30 18:48:21 2021 UTC Allow commit loading trigged by the End/G keys to be cancelled with Backspace. ok jasper commit - 93f8a3371abdcbfdc9e411ff44942acb0198ca47 commit + fb280deb15e67b1bd8ef0f722a7430b8e9312871 blob - f19156ff60b8708acea73670fd8fd33b02ae8c31 blob + c79cf3b9c8bf97b4a0385e233df94c3f431f24d0 --- tog/tog.c +++ tog/tog.c @@ -304,6 +304,7 @@ struct tog_log_thread_args { pthread_cond_t need_commits; pthread_cond_t commit_loaded; int commits_needed; + int load_all; struct got_commit_graph *graph; struct commit_queue *commits; const char *in_repo_path; @@ -885,8 +886,6 @@ view_input(struct tog_view **new, int *done, struct to } switch (ch) { - case ERR: - break; case '\t': if (view->child) { view->focussed = 0; @@ -1612,7 +1611,7 @@ draw_commits(struct tog_view *view) if (s->thread_args.commits_needed == 0) halfdelay(10); /* disable fast refresh */ - if (s->thread_args.commits_needed > 0) { + if (s->thread_args.commits_needed > 0 || s->thread_args.load_all) { if (asprintf(&ncommits_str, " [%d/%d] %s", entry ? entry->idx + 1 : 0, s->commits.ncommits, (view->searching && !view->search_next_done) ? @@ -1762,7 +1761,7 @@ trigger_log_thread(struct tog_view *view, int wait) halfdelay(1); /* fast refresh while loading commits */ - while (ta->commits_needed > 0) { + while (ta->commits_needed > 0 || ta->load_all) { if (ta->log_complete) break; @@ -2028,7 +2027,7 @@ log_thread(void *arg) return (void *)err; err = NULL; done = 1; - } else if (a->commits_needed > 0) + } else if (a->commits_needed > 0 && !a->load_all) a->commits_needed--; errcode = pthread_mutex_lock(&tog_mutex); @@ -2055,7 +2054,7 @@ log_thread(void *arg) if (done) a->commits_needed = 0; else { - if (a->commits_needed == 0) { + if (a->commits_needed == 0 && !a->load_all) { errcode = pthread_cond_wait(&a->need_commits, &tog_mutex); if (errcode) @@ -2391,6 +2390,15 @@ input_log_view(struct tog_view **new_view, struct tog_ int begin_x = 0; switch (ch) { + case ERR: /* no user input from wgetch() */ + if (s->thread_args.load_all && s->thread_args.log_complete) { + s->thread_args.load_all = 0; + log_scroll_down(view, s->commits.ncommits); + s->selected = MIN(view->nlines - 2, + s->commits.ncommits - 1); + select_commit(s); + } + break; case 'q': s->quit = 1; break; @@ -2446,14 +2454,9 @@ input_log_view(struct tog_view **new_view, struct tog_ case KEY_END: { /* We don't know yet how many commits, so we're forced to * traverse them all. */ - while (1) { - if (s->thread_args.log_complete) - break; - - s->thread_args.commits_needed++; - err = trigger_log_thread(view, 1); - if (err) - return err; + if (!s->thread_args.log_complete) { + s->thread_args.load_all = 1; + return trigger_log_thread(view, 0); } log_scroll_down(view, s->commits.ncommits); @@ -2540,6 +2543,10 @@ input_log_view(struct tog_view **new_view, struct tog_ case KEY_BACKSPACE: case CTRL('l'): case 'B': + if (ch == KEY_BACKSPACE && s->thread_args.load_all) { + s->thread_args.load_all = 0; + break; + } if (ch == KEY_BACKSPACE && got_path_is_root_dir(s->in_repo_path)) break;