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

From:
Mark Jamsek <mark@jamsek.com>
Subject:
tog: simplify log_move_cursor_down()
To:
Game of Trees <gameoftrees@openbsd.org>
Date:
Fri, 12 Aug 2022 21:20:10 +1000

Download raw body.

Thread
This stems from Mikhail's observation yesterday in the tog log 'd' key
map thread.

In the log view 'G' key map case, we would first check if the currently
displayed page already contains the last commit and, if so, jump to it.
Otherwise we would scroll down to the last page and then move the
selection cursor to the last commit. However, we were still handling the
'G' case when the commit history had already been loaded (i.e.,
thread_args.log_complete) in input_log_view(), which is always the case
when the last commit is already on the displayed page, so the check was
superfluous! The below diff moves the latter 'G' case into
log_move_cursor_down(), and simplifies this routine's handling of 'G' by
handling both cases the same: set the last displayed commit to the last
commit in the log and walk back. I think this reads nicer and
consolidates all downward log cursor movement into one place.

ok?

btw this diff applies on top of the other tog log diff that fixes the
'd' key map.

diff 81f0117808bf9687cb04c4100f92e956c99f7625 f29a25e264974e82f4868cdc25bfd4a3811a7ef2
commit - 81f0117808bf9687cb04c4100f92e956c99f7625
commit + f29a25e264974e82f4868cdc25bfd4a3811a7ef2
blob - 6ec38b4f4fb702fe582846031bfbd562ee40349a
blob + d36f81499f5b4ae7861ea0f9202c777e7c4787e8
--- tog/tog.c
+++ tog/tog.c
@@ -3165,28 +3165,35 @@ log_move_cursor_down(struct tog_view *view, int page)
 {
 	struct tog_log_view_state	*s = &view->state.log;
 	const struct got_error		*err = NULL;
+	int				 eos = view->nlines - 2;
 
 	if (s->thread_args.log_complete &&
 	    s->selected_entry->idx >= s->commits.ncommits - 1)
 		return NULL;
 
+	if (view_is_hsplit_top(view))
+		--eos;  /* border consumes the last line */
+
 	if (!page) {
-		int eos = view->nlines - 2;
-
-		if (view_is_hsplit_top(view))
-			--eos;  /* border consumes the last line */
 		if (s->selected < MIN(eos, s->commits.ncommits - 1))
 			++s->selected;
 		else
 			err = log_scroll_down(view, 1);
 	} else if (s->thread_args.load_all) {
-		if (s->last_displayed_entry->idx == s->commits.ncommits - 1)
-			s->selected += MIN(s->last_displayed_entry->idx -
-			    s->selected_entry->idx, page + 1);
-		else
-			err = log_scroll_down(view, MIN(page,
-			    s->commits.ncommits - s->selected_entry->idx - 1));
-		s->selected = MIN(view->nlines - 2, s->commits.ncommits - 1);
+		struct commit_queue_entry *entry;
+		int n;
+
+		s->selected = 0;
+		entry = TAILQ_LAST(&s->commits.head, commit_queue_head);
+		s->last_displayed_entry = entry;
+		for (n = 0; n <= eos; n++) {
+			if (entry == NULL)
+				break;
+			s->first_displayed_entry = entry;
+			entry = TAILQ_PREV(entry, commit_queue_head, entry);
+		}
+		if (n > 0)
+			s->selected = n - 1;
 	} else {
 		if (s->last_displayed_entry->idx == s->commits.ncommits - 1 &&
 		    s->thread_args.log_complete)
@@ -3295,8 +3302,7 @@ input_log_view(struct tog_view **new_view, struct tog_
 {
 	const struct got_error *err = NULL;
 	struct tog_log_view_state *s = &view->state.log;
-	struct commit_queue_entry *entry;
-	int eos, n, nscroll;
+	int eos, nscroll;
 
 	if (s->thread_args.load_all) {
 		if (ch == CTRL('g') || ch == KEY_BACKSPACE)
@@ -3375,22 +3381,11 @@ input_log_view(struct tog_view **new_view, struct tog_
 		/* We don't know yet how many commits, so we're forced to
 		 * traverse them all. */
 		view->count = 0;
-		if (!s->thread_args.log_complete) {
-			s->thread_args.load_all = 1;
+		s->thread_args.load_all = 1;
+		if (!s->thread_args.log_complete)
 			return trigger_log_thread(view, 0);
-		}
-
-		s->selected = 0;
-		entry = TAILQ_LAST(&s->commits.head, commit_queue_head);
-		for (n = 0; n < eos; n++) {
-			if (entry == NULL)
-				break;
-			s->first_displayed_entry = entry;
-			entry = TAILQ_PREV(entry, commit_queue_head, entry);
-		}
-		if (n > 0)
-			s->selected = n - 1;
-		select_commit(s);
+		err = log_move_cursor_down(view, s->commits.ncommits);
+		s->thread_args.load_all = 0;
 		break;
 	}
 	case CTRL('d'):

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