make 'got log' avoid got_repo_map_path() if run in a work tree ok naddy
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 f7f14b9..5bfcaac 100644
--- a/got/got.c
+++ b/got/got.c
@@ -3816,13 +3816,7 @@ cmd_log(int argc, char *argv[])
error = NULL;
}
- if (argc == 0) {
- path = strdup("");
- if (path == NULL) {
- error = got_error_from_errno("strdup");
- goto done;
- }
- } else if (argc == 1) {
+ if (argc == 1) {
if (worktree) {
error = got_worktree_resolve_path(&path, worktree,
argv[0]);
@@ -3835,7 +3829,7 @@ cmd_log(int argc, char *argv[])
goto done;
}
}
- } else
+ } else if (argc != 0)
usage_log();
if (repo_path == NULL) {
@@ -3885,17 +3879,23 @@ cmd_log(int argc, char *argv[])
}
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;
+ /*
+ * If a path was specified on the command line it was resolved
+ * to a path in the work tree above. Prepend the work tree's
+ * path prefix to obtain the corresponding in-repository path.
+ */
+ if (path) {
+ const char *prefix;
+ prefix = got_worktree_get_path_prefix(worktree);
+ if (asprintf(&in_repo_path, "%s%s%s", prefix,
+ (path[0] != '\0') ? "/" : "", path) == -1) {
+ error = got_error_from_errno("asprintf");
+ goto done;
+ }
}
- 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);
+ error = got_repo_map_path(&in_repo_path, repo,
+ path ? path : "", 1);
if (error != NULL)
goto done;
if (in_repo_path) {
@@ -3907,9 +3907,9 @@ cmd_log(int argc, char *argv[])
if (error)
goto done;
- error = print_commits(start_id, end_id, repo, path, show_changed_paths,
- show_patch, search_pattern, diff_context, limit, log_branches,
- reverse_display_order, &refs);
+ error = print_commits(start_id, end_id, repo, path ? path : "",
+ show_changed_paths, show_patch, search_pattern, diff_context,
+ limit, log_branches, reverse_display_order, &refs);
done:
free(path);
free(repo_path);
diff --git a/regress/cmdline/log.sh b/regress/cmdline/log.sh
index 74ce60e..6d76d89 100755
--- a/regress/cmdline/log.sh
+++ b/regress/cmdline/log.sh
@@ -138,6 +138,7 @@ test_log_in_worktree_with_path_prefix() {
echo "modified delta" > $testroot/repo/gamma/delta
git_commit $testroot/repo -m "modified delta"
+ local delta_rev=`git_show_head $testroot/repo`
got checkout -p epsilon $testroot/repo $testroot/wt > /dev/null
ret="$?"
@@ -146,10 +147,23 @@ test_log_in_worktree_with_path_prefix() {
return 1
fi
+ echo "commit $delta_rev (master)" > $testroot/stdout.expected
+ echo "commit $zeta_rev" >> $testroot/stdout.expected
+ echo "commit $head_rev" >> $testroot/stdout.expected
+
+ (cd $testroot/wt && got log | 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
+
echo "commit $zeta_rev" > $testroot/stdout.expected
echo "commit $head_rev" >> $testroot/stdout.expected
- for p in "" "." zeta; do
+ for p in "." zeta; do
(cd $testroot/wt && got log $p | \
grep ^commit > $testroot/stdout)
cmp -s $testroot/stdout.expected $testroot/stdout