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

From:
Stefan Sperling <stsp@stsp.name>
Subject:
Re: fix tog log view -> tree view switching
To:
gameoftrees@openbsd.org, naddy@openbsd.org
Date:
Sun, 12 Jan 2020 17:17:17 +0100

Download raw body.

Thread
On Sun, Jan 12, 2020 at 05:11:55PM +0100, Stefan Sperling wrote:
> naddy@ noticed that this throws an error:
> 
>  $ tog log usr.bin/ssh
>  hit 't' for tree view
>  tog: : no such entry found in tre
> 
> The patch below fixes the issue for me. Makes sense?

Fixed version which doesn't error when displaying the root tree.

Can anyone find another problem with this diff?
tog doesn't have automated tests I'm afraid :-/

diff 6a91d28331c6c2bf720d27325d5655cfbc8b9248 /home/stsp/src/got
blob - c1f1819aab4eca2209fa34a6d51e81350c702c96
file + tog/tog.c
--- tog/tog.c
+++ tog/tog.c
@@ -1793,21 +1793,25 @@ browse_commit_tree(struct tog_view **new_view, int beg
 
 	*new_view = tree_view;
 
+	if (got_path_is_root_dir(path))
+		return NULL;
+		
 	/* Walk the path and open corresponding tree objects. */
 	p = path;
-	while (p[0] == '/')
-		p++;
 	while (*p) {
 		struct got_tree_entry *te;
 		struct got_object_id *tree_id;
 		char *te_name;
 
+		while (p[0] == '/')
+			p++;
+
 		/* Ensure the correct subtree entry is selected. */
 		slash = strchr(p, '/');
 		if (slash == NULL)
-			slash = strchr(p, '\0');
-
-		te_name = strndup(p, slash -p);
+			te_name = strdup(p);
+		else
+			te_name = strndup(p, slash - p);
 		if (te_name == NULL) {
 			err = got_error_from_errno("strndup");
 			break;