Download raw body.
tog: worktree vs. -r repo
On Fri, Dec 18, 2020 at 12:45:26AM +0100, Christian Weisgerber wrote: > Stefan Sperling: > > > > $ cd got # work tree associated with got.git > > > $ tog log -r ~/src.git # OpenBSD src repository > > > tog: reference refs/heads/main not found > > > > Thanks! This fixes it for me: > > Hmm. > What purpose does got_worktree_open() serve in the -r case? > Maybe just skip got_worktree_open() completely, so worktree==NULL? Yes, you're right. The worktree is opened in order to lock it, but if we're never going to do anything with it, we might as well not open it in the first place. Is this better? diff refs/heads/main refs/heads/togrflag blob - 334d9a659f385c9de036c79d21a1a527807feeb6 blob + 56661ae5be6716b9260e567f082e935cf4d911ce --- tog/tog.c +++ tog/tog.c @@ -2706,21 +2706,20 @@ cmd_log(int argc, char *argv[]) if (cwd == NULL) return got_error_from_errno("getcwd"); - error = got_worktree_open(&worktree, cwd); - if (error && error->code != GOT_ERR_NOT_WORKTREE) - goto done; - if (repo_path == NULL) { + error = got_worktree_open(&worktree, cwd); + if (error && error->code != GOT_ERR_NOT_WORKTREE) + goto done; if (worktree) repo_path = strdup(got_worktree_get_repo_path(worktree)); else repo_path = strdup(cwd); + if (repo_path == NULL) { + error = got_error_from_errno("strdup"); + goto done; + } } - if (repo_path == NULL) { - error = got_error_from_errno("strdup"); - goto done; - } error = got_repo_open(&repo, repo_path, NULL); if (error != NULL) @@ -3803,11 +3802,11 @@ cmd_diff(int argc, char *argv[]) strdup(got_worktree_get_repo_path(worktree)); else repo_path = strdup(cwd); + if (repo_path == NULL) { + error = got_error_from_errno("strdup"); + goto done; + } } - if (repo_path == NULL) { - error = got_error_from_errno("strdup"); - goto done; - } error = got_repo_open(&repo, repo_path, NULL); if (error) @@ -4683,21 +4682,20 @@ cmd_blame(int argc, char *argv[]) if (cwd == NULL) return got_error_from_errno("getcwd"); - error = got_worktree_open(&worktree, cwd); - if (error && error->code != GOT_ERR_NOT_WORKTREE) - goto done; - if (repo_path == NULL) { + error = got_worktree_open(&worktree, cwd); + if (error && error->code != GOT_ERR_NOT_WORKTREE) + goto done; if (worktree) repo_path = strdup(got_worktree_get_repo_path(worktree)); else repo_path = strdup(cwd); + if (repo_path == NULL) { + error = got_error_from_errno("strdup"); + goto done; + } } - if (repo_path == NULL) { - error = got_error_from_errno("strdup"); - goto done; - } error = got_repo_open(&repo, repo_path, NULL); if (error != NULL) @@ -5495,21 +5493,20 @@ cmd_tree(int argc, char *argv[]) if (cwd == NULL) return got_error_from_errno("getcwd"); - error = got_worktree_open(&worktree, cwd); - if (error && error->code != GOT_ERR_NOT_WORKTREE) - goto done; - if (repo_path == NULL) { + error = got_worktree_open(&worktree, cwd); + if (error && error->code != GOT_ERR_NOT_WORKTREE) + goto done; if (worktree) repo_path = strdup(got_worktree_get_repo_path(worktree)); else repo_path = strdup(cwd); + if (repo_path == NULL) { + error = got_error_from_errno("strdup"); + goto done; + } } - if (repo_path == NULL) { - error = got_error_from_errno("strdup"); - goto done; - } error = got_repo_open(&repo, repo_path, NULL); if (error != NULL) @@ -6216,21 +6213,20 @@ cmd_ref(int argc, char *argv[]) if (cwd == NULL) return got_error_from_errno("getcwd"); - error = got_worktree_open(&worktree, cwd); - if (error && error->code != GOT_ERR_NOT_WORKTREE) - goto done; - if (repo_path == NULL) { + error = got_worktree_open(&worktree, cwd); + if (error && error->code != GOT_ERR_NOT_WORKTREE) + goto done; if (worktree) repo_path = strdup(got_worktree_get_repo_path(worktree)); else repo_path = strdup(cwd); + if (repo_path == NULL) { + error = got_error_from_errno("strdup"); + goto done; + } } - if (repo_path == NULL) { - error = got_error_from_errno("strdup"); - goto done; - } error = got_repo_open(&repo, repo_path, NULL); if (error != NULL)
tog: worktree vs. -r repo