Commit Diff


commit - 13bc6832b964af6431e0b8c6c8586405474e3e71
commit + a184c764f00351d113f3c015e7b794e48e162e50
blob - eca41169193af38a1320fdb788385993cd078872
blob + 03259147951700e81a8aef5359da33d889dc0a6e
--- regress/tog/Makefile
+++ regress/tog/Makefile
@@ -1,4 +1,4 @@
-REGRESS_TARGETS=log diff blame
+REGRESS_TARGETS=log diff blame tree
 NOOBJ=Yes
 
 GOT_TEST_ROOT=/tmp
@@ -12,4 +12,7 @@ diff:
 blame:
 	./blame.sh -q -r "$(GOT_TEST_ROOT)"
 
+tree:
+	./tree.sh -q -r "$(GOT_TEST_ROOT)"
+
 .include <bsd.regress.mk>
blob - /dev/null
blob + 767a816949acdc89e85319bb9909f115024b5579 (mode 755)
--- /dev/null
+++ regress/tog/tree.sh
@@ -0,0 +1,148 @@
+#!/bin/sh
+#
+# Copyright (c) 2023 Mark Jamsek <mark@jamsek.dev>
+#
+# Permission to use, copy, modify, and distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+. ./common.sh
+
+test_tree_basic()
+{
+	test_init tree_basic 48 8
+
+	local head_id=`git_show_head $testroot/repo`
+
+	cat <<EOF >$TOG_TEST_SCRIPT
+SCREENDUMP
+EOF
+
+	cat <<EOF >$testroot/view.expected
+commit $head_id
+[1/4] /
+
+  alpha
+  beta
+  epsilon/
+  gamma/
+
+EOF
+
+	cd $testroot/repo && tog tree
+	cmp -s $testroot/view.expected $testroot/view
+	ret=$?
+	if [ $ret -ne 0 ]; then
+		diff -u $testroot/view.expected $testroot/view
+		test_done "$testroot" "$ret"
+		return 1
+	fi
+
+	test_done "$testroot" "$ret"
+}
+
+test_tree_vsplit_blame()
+{
+	test_init tree_vsplit_blame 120 8
+
+	local head_id=`git_show_head $testroot/repo`
+	local head_id_truncated=`trim_obj_id 8 $head_id`
+	local head_id_short=`trim_obj_id 32 $head_id`
+
+	cat <<EOF >$TOG_TEST_SCRIPT
+KEY_ENTER
+WAIT_FOR_UI	wait for blame to finish
+SCREENDUMP
+EOF
+
+	cat <<EOF >$testroot/view.expected
+commit $head_id_truncated|commit $head_id
+[1/4] /                                |[1/1] /alpha
+                                       |$head_id_short alpha
+  alpha                                |
+  beta                                 |
+  epsilon/                             |
+  gamma/                               |
+                                       |
+EOF
+
+	cd $testroot/repo && tog tree
+	cmp -s $testroot/view.expected $testroot/view
+	ret=$?
+	if [ $ret -ne 0 ]; then
+		diff -u $testroot/view.expected $testroot/view
+		test_done "$testroot" "$ret"
+		return 1
+	fi
+
+	test_done "$testroot" "$ret"
+}
+
+test_tree_hsplit_blame()
+{
+	test_init tree_hsplit_blame 48 24
+
+	local head_id=`git_show_head $testroot/repo`
+	local head_id_truncated=`trim_obj_id 8 $head_id`
+	local head_id_short=`trim_obj_id 32 $head_id`
+
+	cat <<EOF >$TOG_TEST_SCRIPT
+j
+KEY_ENTER
+S		toggle horizontal split
+4-		4x decrease blame split
+WAIT_FOR_UI	wait for blame to finish
+SCREENDUMP
+EOF
+
+	cat <<EOF >$testroot/view.expected
+commit $head_id
+[2/4] /
+
+  alpha
+  beta
+  epsilon/
+  gamma/
+
+
+
+------------------------------------------------
+commit $head_id
+[1/1] /beta
+$head_id_short beta
+
+
+
+
+
+
+
+
+
+
+EOF
+
+	cd $testroot/repo && tog tree
+	cmp -s $testroot/view.expected $testroot/view
+	ret=$?
+	if [ $ret -ne 0 ]; then
+		diff -u $testroot/view.expected $testroot/view
+		test_done "$testroot" "$ret"
+		return 1
+	fi
+
+	test_done "$testroot" "$ret"
+}
+
+test_parseargs "$@"
+run_test test_tree_basic
+run_test test_tree_vsplit_blame
+run_test test_tree_hsplit_blame
blob - 3700f7273b4957614715d370d0453f195ef84da0
blob + f541c5ed0435dfb44886c0e9d622d5787fc534fc
--- tog/tog.c
+++ tog/tog.c
@@ -1627,13 +1627,17 @@ action_report(struct tog_view *view)
  * key instruction to *ch. If at EOF, set the *done flag.
  */
 static const struct got_error *
-tog_read_script_key(FILE *script, int *ch, int *done)
+tog_read_script_key(FILE *script, struct tog_view *view, int *ch, int *done)
 {
 	const struct got_error	*err = NULL;
 	char			*line = NULL;
 	size_t			 linesz = 0;
 
-	*ch = -1;
+	if (view->count && --view->count) {
+		*ch = view->ch;
+		return NULL;
+	} else
+		*ch = -1;
 
 	if (getline(&line, &linesz, script) == -1) {
 		if (feof(script)) {
@@ -1659,7 +1663,16 @@ tog_read_script_key(FILE *script, int *ch, int *done)
 		*ch = KEY_UP;
 	else if (strncasecmp(line, "SCREENDUMP", 10) == 0)
 		*ch = TOG_KEY_SCRDUMP;
-	else
+	else if (isdigit((unsigned char)*line)) {
+		char *t = line;
+
+		while (isdigit((unsigned char)*t))
+			++t;
+		view->ch = *ch = *t;
+		*t = '\0';
+		/* ignore error, view->count is 0 if instruction is invalid */
+		view->count = strtonum(line, 0, INT_MAX, NULL);
+	} else
 		*ch = *line;
 
 done:
@@ -1707,7 +1720,7 @@ view_input(struct tog_view **new, int *done, struct to
 		return got_error_set_errno(errcode, "pthread_mutex_unlock");
 
 	if (using_mock_io) {
-		err = tog_read_script_key(tog_io.f, &ch, done);
+		err = tog_read_script_key(tog_io.f, view, &ch, done);
 		if (err) {
 			errcode = pthread_mutex_lock(&tog_mutex);
 			return err;