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

From:
Mark Jamsek <mark@jamsek.com>
Subject:
tog: fix ref/log hsplit
To:
gameoftrees@openbsd.org
Date:
Mon, 11 Jul 2022 02:34:25 +1000

Download raw body.

Thread
This fixes two bugs introduced with the recent commit to resize splits.

We account for an increase in the top split and request more commits to
populate the view, but we fail to do this in the bottom split as we
increase its size. Relatedly, after closing the resized log split, we
then incorrectly call request_log_commits() from view_resize_split() when
reopening the log view, and overwrite thread_args.commits_needed with 0,
so the log thread isn't triggered and no commits are loaded.

repro:

$ TOG_VIEW_SPLIT_MODE=h tog ref
return  # open log view in bottom split
4+  # increase log (child/bottom) split
*new log lines are not populated*
q  # close log view
return
*commits are not loaded*

The fix is to only call request_log_commits() when actually needed.

-----------------------------------------------
commit d5e96e0da90686eceddee8ab243f73dcaecdc267 (fix/refsplit)
from: Mark Jamsek <mark@jamsek.dev>
date: Sun Jul 10 15:57:17 2022 UTC

 tog: only request commits when child hsplit increases

 $ TOG_VIEW_SPLIT_MODE=h tog ref
 return
 4+
 *new log lines are not populated*
 q
 return
 *commits are not loaded*

diff 3c1dfe12b3f3eae6dc7ef4762772e849794296c5 d5e96e0da90686eceddee8ab243f73dcaecdc267
commit - 3c1dfe12b3f3eae6dc7ef4762772e849794296c5
commit + d5e96e0da90686eceddee8ab243f73dcaecdc267
blob - 310eb39a0776dd5fb11adc30d6c50fba6d7de13b
blob + 7e4ac1da8895ed15c5333d6897ef3692b6790c53
--- tog/tog.c
+++ tog/tog.c
@@ -944,6 +944,8 @@ view_resize_split(struct tog_view *view, int resize)
 	v->resize = v->child->resize = resize;  /* lock for resize event */

 	if (view->mode == TOG_VIEW_SPLIT_HRZN) {
+		int y = v->child->begin_y;
+
 		if (v->child->resized_y)
 			v->child->begin_y = v->child->resized_y;
 		if (view->parent)
@@ -963,6 +965,8 @@ view_resize_split(struct tog_view *view, int resize)
 		if (err)
 			return err;
 		v->child->resized_y = v->child->begin_y;
+		if (y > v->child->begin_y)  /* split increased */
+			v->child->nscrolled = y - v->child->begin_y;
 	} else {
 		if (v->child->resized_x)
 			v->child->begin_x = v->child->resized_x;
@@ -998,9 +1002,9 @@ view_resize_split(struct tog_view *view, int resize)
 			return err;
 	}

-	if (v->type == TOG_VIEW_LOG)
+	if (v->type == TOG_VIEW_LOG && v->nscrolled)
 		err = request_log_commits(v);
-	else if (v->child->type == TOG_VIEW_LOG)
+	else if (v->child->type == TOG_VIEW_LOG && v->child->nscrolled)
 		err = request_log_commits(v->child);

 	v->resize = v->child->resize = 0;
@@ -1168,9 +1172,9 @@ switch_split(struct tog_view *view)
 	if (v->mode == TOG_VIEW_SPLIT_HRZN)
 		err = offset_selection_down(v->child);
 	else if (v->mode == TOG_VIEW_SPLIT_VERT) {
-		if (v->type == TOG_VIEW_LOG)
+		if (v->type == TOG_VIEW_LOG && v->nscrolled)
 			err = request_log_commits(v);
-		else if (v->child->type == TOG_VIEW_LOG)
+		else if (v->child->type == TOG_VIEW_LOG && v->child->nscrolled)
 			err = request_log_commits(v->child);
 	}

@@ -2371,7 +2375,7 @@ request_log_commits(struct tog_view *view)
 	struct tog_log_view_state	*state = &view->state.log;
 	const struct got_error		*err = NULL;

-	state->thread_args.commits_needed = view->nscrolled;
+	state->thread_args.commits_needed += view->nscrolled;
 	err = trigger_log_thread(view, 1);
 	view->nscrolled = 0;

@@ -3091,11 +3095,15 @@ view_get_split(struct tog_view *view, int *y, int *x)
 	if (view->mode == TOG_VIEW_SPLIT_HRZN) {
 		if (view->child && view->child->resized_y)
 			*y = view->child->resized_y;
+		else if (view->resized_y)
+			*y = view->resized_y;
 		else
 			*y = view_split_begin_y(view->lines);
 	} else {
 		if (view->child && view->child->resized_x)
 			*x = view->child->resized_x;
+		else if (view->resized_x)
+			*y = view->resized_x;
 		else
 			*x = view_split_begin_x(view->begin_x);
 	}

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