Download raw body.
tog ref -> log -> diff: < > fails to follow branch
On Sat, Dec 05, 2020 at 12:49:47AM +0100, Stefan Sperling wrote: > On Fri, Dec 04, 2020 at 04:56:12PM +0100, Christian Weisgerber wrote: > > Stefan Sperling: > > > > > The following works for me. Not sure if this is the best possible fix, > > > perhaps we'd want to decouple the diff/log views a bit more. But I am > > > happy enough with this approach for now: > > > > Unfortunately, this introduces two bugs: > > > > * In the log view header line, the commit number n "[n/m]" is no > > longer correctly updated. > > > > * When additional commits need to be requested from the log thread, > > '>' doesn't advance any longer. > > E.g. tog log, move to bottom line, enter, hit '>'. > > Thanks! I will take a look. This version fixes the above issues for me. diff 3de29130c7ee88da6e0dd01d356a346c78659921 b3796c3623d628cac6cf2e78b080d7bb9ad3e341 blob - 71243c7850ea1be2a41ea376e63e2b384bf06df0 blob + 72c43370d57131de5f87eef084c18dc57532981b --- tog/tog.c +++ tog/tog.c @@ -1520,12 +1520,31 @@ queue_commits(struct got_commit_graph *graph, struct c return err; } +static void +select_displayed_commit(struct tog_log_view_state *s, int selected_idx) +{ + struct commit_queue_entry *entry; + int ncommits = 0; + + s->selected = selected_idx; + + entry = s->first_displayed_entry; + while (entry) { + if (ncommits == s->selected) { + s->selected_entry = entry; + break; + } + entry = TAILQ_NEXT(entry, entry); + ncommits++; + } +} + static const struct got_error * draw_commits(struct tog_view *view) { const struct got_error *err = NULL; struct tog_log_view_state *s = &view->state.log; - struct commit_queue_entry *entry; + struct commit_queue_entry *entry = s->selected_entry; const int limit = view->nlines; int width; int ncommits, author_cols = 4; @@ -1535,17 +1554,6 @@ draw_commits(struct tog_view *view) struct tog_color *tc; static const size_t date_display_cols = 12; - entry = s->first_displayed_entry; - ncommits = 0; - while (entry) { - if (ncommits == s->selected) { - s->selected_entry = entry; - break; - } - entry = TAILQ_NEXT(entry, entry); - ncommits++; - } - if (s->selected_entry && !(view->searching && view->search_next_done == 0)) { err = got_object_id_str(&id_str, s->selected_entry->id); @@ -1700,6 +1708,8 @@ log_scroll_up(struct tog_log_view_state *s, int maxscr nscrolled++; } } + + select_displayed_commit(s, s->selected); } static const struct got_error * @@ -1783,6 +1793,9 @@ log_scroll_down(struct tog_view *view, int maxscroll) s->first_displayed_entry = pentry; } while (++nscrolled < maxscroll); + if (err == NULL) + select_displayed_commit(s, s->selected); + return err; } @@ -2358,7 +2371,7 @@ input_log_view(struct tog_view **new_view, struct tog_ if (s->first_displayed_entry == NULL) break; if (s->selected > 0) - s->selected--; + select_displayed_commit(s, s->selected - 1); else log_scroll_up(s, 1); break; @@ -2368,7 +2381,7 @@ input_log_view(struct tog_view **new_view, struct tog_ break; if (TAILQ_FIRST(&s->commits.head) == s->first_displayed_entry) { - s->selected = 0; + select_displayed_commit(s, 0); break; } log_scroll_up(s, view->nlines - 1); @@ -2381,7 +2394,7 @@ input_log_view(struct tog_view **new_view, struct tog_ break; if (s->selected < MIN(view->nlines - 2, s->commits.ncommits - 1)) { - s->selected++; + select_displayed_commit(s, s->selected + 1); break; } err = log_scroll_down(view, 1); @@ -2399,17 +2412,16 @@ input_log_view(struct tog_view **new_view, struct tog_ s->selected < MIN(view->nlines - 2, s->commits.ncommits - 1)) { /* can't scroll further down */ - s->selected = MIN(view->nlines - 2, - s->commits.ncommits - 1); + select_displayed_commit(s, + MIN(view->nlines - 2, s->commits.ncommits - 1)); } - err = NULL; break; } case KEY_RESIZE: if (s->selected > view->nlines - 2) - s->selected = view->nlines - 2; + select_displayed_commit(s, view->nlines - 2); if (s->selected > s->commits.ncommits - 1) - s->selected = s->commits.ncommits - 1; + select_displayed_commit(s, s->commits.ncommits - 1); if (s->commits.ncommits < view->nlines - 1 && !s->thread_args.log_complete) { s->thread_args.commits_needed += (view->nlines - 1) - @@ -3598,7 +3610,6 @@ input_diff_view(struct tog_view **new_view, struct tog const struct got_error *err = NULL; struct tog_diff_view_state *s = &view->state.diff; struct tog_log_view_state *ls; - struct commit_queue_entry *entry; int i; switch (ch) { @@ -3671,16 +3682,12 @@ input_diff_view(struct tog_view **new_view, struct tog if (s->log_view == NULL) break; ls = &s->log_view->state.log; - entry = TAILQ_PREV(ls->selected_entry, - commit_queue_head, entry); - if (entry == NULL) - break; err = input_log_view(NULL, s->log_view, KEY_UP); if (err) break; - err = set_selected_commit(s, entry); + err = set_selected_commit(s, ls->selected_entry); if (err) break; @@ -3696,21 +3703,11 @@ input_diff_view(struct tog_view **new_view, struct tog break; ls = &s->log_view->state.log; - if (TAILQ_NEXT(ls->selected_entry, entry) == NULL) { - ls->thread_args.commits_needed++; - err = trigger_log_thread(s->log_view, 1); - if (err) - break; - } err = input_log_view(NULL, s->log_view, KEY_DOWN); if (err) break; - entry = TAILQ_NEXT(ls->selected_entry, entry); - if (entry == NULL) - break; - - err = set_selected_commit(s, entry); + err = set_selected_commit(s, ls->selected_entry); if (err) break;
tog ref -> log -> diff: < > fails to follow branch