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

From:
Christian Weisgerber <naddy@mips.inka.de>
Subject:
Re: got log and subdirectories?
To:
gameoftrees@openbsd.org
Date:
Sun, 23 Feb 2020 01:06:05 +0100

Download raw body.

Thread
Stefan Sperling:

> > And I just noticed that inside a work tree, "got tree" behaves like
> > "tog tree .", and "tog tree" like "got tree /".
> 
> Ye, this is inconsistent, unfortunately.
> In this case I would say we should fix got to match tog, for now, to
> conform to the "no implicit dot" rule.

Like this?
Shamelessly copied from tog.c:get_in_repo_path_from_argv0().

diff 29d623dc6f84c7b95ce80173b5837c0377d3ba68 /home/naddy/got
blob - 4a5d5fcafa19f89e6039addb90f3c1979ea584e3
file + got/got.c
--- got/got.c
+++ got/got.c
@@ -2902,27 +2902,33 @@ cmd_tree(int argc, char *argv[])
 		goto done;
 
 	if (path == NULL) {
-		if (worktree) {
-			char *p, *worktree_subdir = cwd +
-			    strlen(got_worktree_get_root_path(worktree));
-			if (asprintf(&p, "%s/%s",
-			    got_worktree_get_path_prefix(worktree),
-			    worktree_subdir) == -1) {
-				error = got_error_from_errno("asprintf");
-				goto done;
-			}
-			error = got_repo_map_path(&in_repo_path, repo, p, 0);
-			free(p);
-			if (error)
-				goto done;
-		} else
-			path = "/";
-	}
-	if (in_repo_path == NULL) {
-		error = got_repo_map_path(&in_repo_path, repo, path, 1);
-		if (error != NULL)
+		in_repo_path = strdup("/");
+		if (in_repo_path == NULL) {
+			error = got_error_from_errno("strdup");
 			goto done;
-	}
+		}
+	} else if (worktree) {
+		const char *prefix = got_worktree_get_path_prefix(worktree);
+		char *wt_path, *p;
+
+		error = got_worktree_resolve_path(&wt_path, worktree, path);
+		if (error)
+			goto done;
+
+		if (asprintf(&p, "%s%s%s", prefix,
+		    (strcmp(prefix, "/") != 0) ? "/" : "", wt_path) == -1) {
+			error = got_error_from_errno("asprintf");
+			free(wt_path);
+			goto done;
+		}
+		error = got_repo_map_path(&in_repo_path, repo, p, 0);
+		free(p);
+		free(wt_path);
+	} else
+		error = got_repo_map_path(&in_repo_path, repo, path, 1);
+
+	if (error != NULL)
+		goto done;
 
 	if (commit_id_str == NULL) {
 		struct got_reference *head_ref;
-- 
Christian "naddy" Weisgerber                          naddy@mips.inka.de