"GOT", but the "O" is a cute, smiling pufferfish. Index | Thread | Search

From:
Mark Jamsek <mark@jamsek.com>
Subject:
tog: open log view of annotated line
To:
gameoftrees@openbsd.org
Date:
Wed, 20 Jul 2022 00:07:16 +1000

Download raw body.

Thread
As per the TODO item: open a log view of the selected annotated line.

diff refs/heads/main refs/heads/dev/blamelog
commit - 314c3f148b7679296136b460ea9a8f0d4c74d437
commit + 1de4f1ca80d74e859beae5c3633adcf960c79938
blob - 765c5ecd53d258c8af195523d4fb1fea0c8f41d3
blob + 80d025e6069d90b874a54b9778401bf07c5b84b1
--- 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 - 82d0b3a26a196343c75bd02c869e612c75190979
blob + a777d670b3c050eeafd24ff9fa692c54e9c58415
--- tog/tog.c
+++ tog/tog.c
@@ -5725,10 +5725,49 @@ 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;
+	struct got_reference	*ref = NULL;
+	char			*id_str = NULL;
+	const char		*ref_str = NULL;
+	const struct got_error	*err = NULL;
+
+	*new_view = NULL;
+
+	err = got_object_id_str(&id_str, id);
+	if (err)
+		return err;
+
+	err = got_ref_open(&ref, repo, id_str, 0);
+	if (err == NULL)
+		ref_str = got_ref_get_name(ref);
+	else if (err->code != GOT_ERR_NOT_REF)
+		goto done;
+
+	log_view = view_open(0, 0, begin_y, begin_x, TOG_VIEW_LOG);
+	if (log_view == NULL) {
+		err = got_error_from_errno("view_open");
+		goto done;
+	}
+	err = open_log_view(log_view, id, repo, ref_str, "", 0);
+done:
+	free(id_str);
+	if (ref)
+		got_ref_close(ref);
+	if (err && log_view)
+		view_close(log_view);
+	else if (err == NULL)
+		*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;

@@ -5909,6 +5948,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;

-- 
Mark Jamsek <fnc.bsdbox.org>
GPG: F2FF 13DE 6A06 C471 CA80  E6E2 2930 DC66 86EE CF68