commit 603cdeb0c7bcddc1abea9ced622f6eaa82c00f35 from: Stefan Sperling date: Thu Oct 22 20:37:50 2020 UTC make 'got log' avoid got_repo_map_path() if run in a work tree ok naddy commit - 20b7abb3fa8e5b46bacd07df9f85cfd7edc5a4c9 commit + 603cdeb0c7bcddc1abea9ced622f6eaa82c00f35 blob - f7f14b9cb2d386242d73d208d79ef3e9df874bab blob + 5bfcaac31178afc5018d764b995989379c1ccfe7 --- got/got.c +++ 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; - } - error = got_repo_map_path(&in_repo_path, repo, p, 0); - free(p); + /* + * 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; + } + } } 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); blob - 74ce60ea201a8a353667c2d1ef50a71807cd2377 blob + 6d76d8908d8e38ade06083ff93a4b8757b7dab89 --- regress/cmdline/log.sh +++ regress/cmdline/log.sh @@ -138,10 +138,24 @@ 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="$?" + if [ "$ret" != "0" ]; then + test_done "$testroot" "$ret" + 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 @@ -149,7 +163,7 @@ test_log_in_worktree_with_path_prefix() { 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