Commit f43793a4e6eda593d67d4872bc7f03398fbd65d9

Stefan Sperling 2020-01-27T22:14:23

fix a bug where 'got log PATH' failed to map PATH into the repository The problem occured inside /usr/src/sys due to the /sys symlink, where /usr/src was a got work tree. If a work tree is present we already have the right path so checking the disk is pointless.

diff --git a/got/got.c b/got/got.c
index addb2d0..7d06061 100644
--- a/got/got.c
+++ b/got/got.c
@@ -2010,7 +2010,7 @@ cmd_log(int argc, char *argv[])
 			error = got_error_from_errno("asprintf");
 			goto done;
 		}
-		error = got_repo_map_path(&in_repo_path, repo, p, 1);
+		error = got_repo_map_path(&in_repo_path, repo, p, 0);
 		free(p);
 	} else
 		error = got_repo_map_path(&in_repo_path, repo, path, 1);
@@ -2909,7 +2909,7 @@ cmd_tree(int argc, char *argv[])
 				error = got_error_from_errno("asprintf");
 				goto done;
 			}
-			error = got_repo_map_path(&in_repo_path, repo, p, 1);
+			error = got_repo_map_path(&in_repo_path, repo, p, 0);
 			free(p);
 			if (error)
 				goto done;
diff --git a/regress/cmdline/log.sh b/regress/cmdline/log.sh
index 3d29186..62d97e2 100755
--- a/regress/cmdline/log.sh
+++ b/regress/cmdline/log.sh
@@ -71,8 +71,14 @@ function test_log_in_bare_repo {
 }
 
 function test_log_in_worktree {
-	local testroot=`test_init log_in_worktree`
-	local head_rev=`git_show_head $testroot/repo`
+	local testroot=`test_init log_in_worktree 1`
+
+	make_test_tree $testroot/repo
+	mkdir -p $testroot/repo/epsilon/d
+	echo foo > $testroot/repo/epsilon/d/foo
+	(cd $testroot/repo && git add .)
+	git_commit $testroot/repo -m "adding the test tree"
+	local head_commit=`git_show_head $testroot/repo`
 
 	got checkout $testroot/repo $testroot/wt > /dev/null
 	ret="$?"
@@ -81,7 +87,7 @@ function test_log_in_worktree {
 		return 1
 	fi
 
-	echo "commit $head_rev (master)" > $testroot/stdout.expected
+	echo "commit $head_commit (master)" > $testroot/stdout.expected
 
 	for p in "" "." alpha epsilon; do
 		(cd $testroot/wt && got log $p | \
@@ -107,6 +113,18 @@ function test_log_in_worktree {
 		fi
 	done
 
+	for p in "" "." foo; do
+		(cd $testroot/wt/epsilon && got log d/$p | \
+			grep ^commit > $testroot/stdout)
+		cmp -s $testroot/stdout.expected $testroot/stdout
+		ret="$?"
+		if [ "$ret" != "0" ]; then
+			diff -u $testroot/stdout.expected $testroot/stdout
+			test_done "$testroot" "$ret"
+			return 1
+		fi
+	done
+
 	test_done "$testroot" "0"
 }
 
diff --git a/tog/tog.c b/tog/tog.c
index ddf4b1a..57bbc95 100644
--- a/tog/tog.c
+++ b/tog/tog.c
@@ -2483,7 +2483,7 @@ cmd_log(int argc, char *argv[])
 	struct got_object_id *start_id = NULL;
 	char *path = NULL, *repo_path = NULL, *cwd = NULL;
 	char *start_commit = NULL, *head_ref_name = NULL;
-	int ch, log_branches = 0;
+	int ch, log_branches = 0, check_disk = 1;
 	struct tog_view *view;
 
 	SIMPLEQ_INIT(&refs);
@@ -2592,6 +2592,17 @@ cmd_log(int argc, char *argv[])
 		goto done;
 	}
 	if (worktree) {
+		const char *prefix = got_worktree_get_path_prefix(worktree);
+		char *p;
+		if (asprintf(&p, "%s%s%s", prefix,
+		    (strcmp(prefix, "/") != 0) ? "/" : "", path) == -1) {
+			error = got_error_from_errno("asprintf");
+			goto done;
+		}
+		free(path);
+		path = p;
+		check_disk = 0;
+
 		head_ref_name = strdup(
 		    got_worktree_get_head_ref_name(worktree));
 		if (head_ref_name == NULL) {
@@ -2600,7 +2611,7 @@ cmd_log(int argc, char *argv[])
 		}
 	}
 	error = open_log_view(view, start_id, &refs, repo, head_ref_name,
-	    path, 1, log_branches);
+	    path, check_disk, log_branches);
 	if (error)
 		goto done;
 	if (worktree) {