commit 05f04cdf3fa9619d7055f098b55f1633dbbf12c0 from: Mark Jamsek date: Wed Jul 20 13:31:20 2022 UTC tog: blame view keymap to open log of annotated line As per stsp's TODO item: open a log view of the selected line with 'L'. helped by and ok stsp@ commit - 97f28afb9820967508ab57f5ed6a5c75f49464b4 commit + 05f04cdf3fa9619d7055f098b55f1633dbbf12c0 blob - 8a0e89a859e5cbbaffbc78116d37c7899a3468c5 blob + f73c13e4ee7be77816a5e17af55d718bc8289519 --- tog/tog.1 +++ tog/tog.1 @@ -406,6 +406,10 @@ currently selected line's commit. Reload the .Cm blame view with the previously blamed commit. +.It Cm L +Open a +.Cm log +view for the currently selected annotated line. .It Cm / Prompt for a search pattern and start searching for matching lines. The search pattern is an extended regular expression. blob - 06904690d55cf85511a04f4c4f979303e9baf5f2 blob + f05786c2a00509ae1a6a3159214d55188847d9c9 --- tog/tog.c +++ tog/tog.c @@ -5727,10 +5727,32 @@ show_blame_view(struct tog_view *view) } static const struct got_error * +log_annotated_line(struct tog_view **new_view, int begin_y, int begin_x, + struct got_repository *repo, struct got_object_id *id) +{ + struct tog_view *log_view; + const struct got_error *err = NULL; + + *new_view = NULL; + + log_view = view_open(0, 0, begin_y, begin_x, TOG_VIEW_LOG); + if (log_view == NULL) + return got_error_from_errno("view_open"); + + err = open_log_view(log_view, id, repo, GOT_REF_HEAD, "", 0); + if (err) + view_close(log_view); + else + *new_view = log_view; + + return err; +} + +static const struct got_error * input_blame_view(struct tog_view **new_view, struct tog_view *view, int ch) { const struct got_error *err = NULL, *thread_err = NULL; - struct tog_view *diff_view; + struct tog_view *diff_view, *log_view; struct tog_blame_view_state *s = &view->state.blame; int eos, nscroll, begin_y = 0, begin_x = 0; @@ -5911,6 +5933,45 @@ input_blame_view(struct tog_view **new_view, struct to break; break; } + case 'L': { + struct got_object_id *id = NULL; + + view->count = 0; + id = get_selected_commit_id(s->blame.lines, s->blame.nlines, + s->first_displayed_line, s->selected_line); + if (id == NULL) + break; + + if (view_is_parent_view(view)) + view_get_split(view, &begin_y, &begin_x); + err = log_annotated_line(&log_view, begin_y, begin_x, + s->repo, id); + if (err) + break; + if (view_is_parent_view(view) && + view->mode == TOG_VIEW_SPLIT_HRZN) { + err = view_init_hsplit(view, begin_y); + if (err) + break; + } + + view->focussed = 0; + log_view->focussed = 1; + log_view->mode = view->mode; + log_view->nlines = view->lines - begin_y; + if (view_is_parent_view(view)) { + view_transfer_size(log_view, view); + err = view_close_child(view); + if (err) + return err; + err = view_set_child(view, log_view); + if (err) + return err; + view->focus_child = 1; + } else + *new_view = log_view; + break; + } case KEY_ENTER: case '\r': { struct got_object_id *id = NULL;