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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
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) {