diff --git a/got/got.c b/got/got.c index e8cfb93a..a2cfacec 100644 --- a/got/got.c +++ b/got/got.c @@ -2007,6 +2007,7 @@ cmd_fetch(int argc, char *argv[]) struct got_fetch_progress_arg fpa; int verbosity = 0, fetch_all_branches = 0, list_refs_only = 0; int delete_refs = 0, replace_tags = 0; + int cwd_fd = -1; TAILQ_INIT(&refs); TAILQ_INIT(&symrefs); @@ -2088,9 +2089,14 @@ cmd_fetch(int argc, char *argv[]) error = got_error_from_errno("getcwd"); goto done; } + cwd_fd = open(cwd, O_DIRECTORY); + if (cwd_fd == -1) { + error = got_error_from_errno2("open", cwd); + goto done; + } if (repo_path == NULL) { - error = got_worktree_open(&worktree, cwd); + error = got_worktree_open(&worktree, cwd_fd, cwd); if (error && error->code != GOT_ERR_NOT_WORKTREE) goto done; else @@ -2740,7 +2746,7 @@ cmd_checkout(int argc, char *argv[]) if (error != NULL && !(error->code == GOT_ERR_ERRNO && errno == EEXIST)) goto done; - error = got_worktree_open(&worktree, worktree_path); + error = got_worktree_open(&worktree, worktree_fd, worktree_path); if (error != NULL) goto done; @@ -2983,7 +2989,7 @@ cmd_update(int argc, char *argv[]) const struct got_error *error = NULL; struct got_repository *repo = NULL; struct got_worktree *worktree = NULL; - char *worktree_path = NULL; + char *cwd = NULL; struct got_object_id *commit_id = NULL; char *commit_id_str = NULL; const char *branch_name = NULL; @@ -2991,6 +2997,7 @@ cmd_update(int argc, char *argv[]) struct got_pathlist_head paths; struct got_pathlist_entry *pe; int ch; + int cwd_fd = -1; struct got_update_progress_arg upa; TAILQ_INIT(&paths); @@ -3019,16 +3026,22 @@ cmd_update(int argc, char *argv[]) "unveil", NULL) == -1) err(1, "pledge"); #endif - worktree_path = getcwd(NULL, 0); - if (worktree_path == NULL) { + cwd = getcwd(NULL, 0); + if (cwd == NULL) { error = got_error_from_errno("getcwd"); goto done; } - error = got_worktree_open(&worktree, worktree_path); + cwd_fd = open(cwd, O_DIRECTORY); + if (cwd_fd == -1) { + error = got_error_from_errno2("open", cwd); + goto done; + } + + error = got_worktree_open(&worktree, cwd_fd, cwd); if (error) { if (error->code == GOT_ERR_NOT_WORKTREE) error = wrap_not_worktree_error(error, "update", - worktree_path); + cwd); goto done; } @@ -3130,7 +3143,7 @@ cmd_update(int argc, char *argv[]) printf("Already up-to-date\n"); print_update_progress_stats(&upa); done: - free(worktree_path); + free(cwd); TAILQ_FOREACH(pe, &paths, entry) free((char *)pe->path); got_pathlist_free(&paths); @@ -3711,6 +3724,7 @@ cmd_log(int argc, char *argv[]) int diff_context = -1, ch; int show_changed_paths = 0, show_patch = 0, limit = 0, log_branches = 0; int reverse_display_order = 0; + int cwd_fd = -1; const char *errstr; struct got_reflist_head refs; @@ -3785,9 +3799,13 @@ cmd_log(int argc, char *argv[]) error = got_error_from_errno("getcwd"); goto done; } - + cwd_fd = open(cwd, O_DIRECTORY); + if (cwd_fd == -1) { + error = got_error_from_errno2("open", cwd); + goto done; + } if (repo_path == NULL) { - error = got_worktree_open(&worktree, cwd); + error = got_worktree_open(&worktree, cwd_fd, cwd); if (error && error->code != GOT_ERR_NOT_WORKTREE) goto done; error = NULL; @@ -4124,6 +4142,7 @@ cmd_diff(int argc, char *argv[]) int type1, type2; int diff_context = 3, diff_staged = 0, ignore_whitespace = 0, ch; int force_text_diff = 0; + int cwd_fd = -1; const char *errstr; char *path = NULL; @@ -4171,11 +4190,16 @@ cmd_diff(int argc, char *argv[]) error = got_error_from_errno("getcwd"); goto done; } + cwd_fd = open(cwd, O_DIRECTORY); + if (cwd_fd == -1) { + error = got_error_from_errno2("open", cwd); + goto done; + } if (argc <= 1) { if (repo_path) errx(1, "-r option can't be used when diffing a work tree"); - error = got_worktree_open(&worktree, cwd); + error = got_worktree_open(&worktree, cwd_fd, cwd); if (error) { if (error->code == GOT_ERR_NOT_WORKTREE) error = wrap_not_worktree_error(error, "diff", @@ -4206,7 +4230,7 @@ cmd_diff(int argc, char *argv[]) id_str1 = argv[0]; id_str2 = argv[1]; if (repo_path == NULL) { - error = got_worktree_open(&worktree, cwd); + error = got_worktree_open(&worktree, cwd_fd, cwd); if (error && error->code != GOT_ERR_NOT_WORKTREE) goto done; if (worktree) { @@ -4467,6 +4491,7 @@ cmd_blame(int argc, char *argv[]) char *commit_id_str = NULL; struct blame_cb_args bca; int ch, obj_type, i; + int cwd_fd = -1; off_t filesize; memset(&bca, 0, sizeof(bca)); @@ -4508,8 +4533,13 @@ cmd_blame(int argc, char *argv[]) error = got_error_from_errno("getcwd"); goto done; } + cwd_fd = open(cwd, O_DIRECTORY); + if (cwd_fd == -1) { + error = got_error_from_errno2("open", cwd); + goto done; + } if (repo_path == NULL) { - error = got_worktree_open(&worktree, cwd); + error = got_worktree_open(&worktree, cwd_fd, cwd); if (error && error->code != GOT_ERR_NOT_WORKTREE) goto done; else @@ -4789,6 +4819,7 @@ cmd_tree(int argc, char *argv[]) struct got_object_id *commit_id = NULL; char *commit_id_str = NULL; int show_ids = 0, recurse = 0; + int cwd_fd = -1; int ch; #ifndef PROFILE @@ -4836,8 +4867,13 @@ cmd_tree(int argc, char *argv[]) error = got_error_from_errno("getcwd"); goto done; } + cwd_fd = open(cwd, O_DIRECTORY); + if (cwd_fd == -1) { + error = got_error_from_errno2("open", cwd); + goto done; + } if (repo_path == NULL) { - error = got_worktree_open(&worktree, cwd); + error = got_worktree_open(&worktree, cwd_fd, cwd); if (error && error->code != GOT_ERR_NOT_WORKTREE) goto done; else @@ -4973,6 +5009,7 @@ cmd_status(int argc, char *argv[]) struct got_pathlist_head paths; struct got_pathlist_entry *pe; int ch, i; + int cwd_fd = -1; TAILQ_INIT(&paths); @@ -5017,8 +5054,13 @@ cmd_status(int argc, char *argv[]) error = got_error_from_errno("getcwd"); goto done; } + cwd_fd = open(cwd, O_DIRECTORY); + if (cwd_fd == -1) { + error = got_error_from_errno2("open", cwd); + goto done; + } - error = got_worktree_open(&worktree, cwd); + error = got_worktree_open(&worktree, cwd_fd, cwd); if (error) { if (error->code == GOT_ERR_NOT_WORKTREE) error = wrap_not_worktree_error(error, "status", cwd); @@ -5182,6 +5224,7 @@ cmd_ref(int argc, char *argv[]) struct got_worktree *worktree = NULL; char *cwd = NULL, *repo_path = NULL; int ch, do_list = 0, do_delete = 0; + int cwd_fd = -1; const char *obj_arg = NULL, *symref_target= NULL; char *refname = NULL; @@ -5267,9 +5310,14 @@ cmd_ref(int argc, char *argv[]) error = got_error_from_errno("getcwd"); goto done; } + cwd_fd = open(cwd, O_DIRECTORY); + if (cwd_fd == -1) { + error = got_error_from_errno2("open", cwd); + goto done; + } if (repo_path == NULL) { - error = got_worktree_open(&worktree, cwd); + error = got_worktree_open(&worktree, cwd_fd, cwd); if (error && error->code != GOT_ERR_NOT_WORKTREE) goto done; else @@ -5512,6 +5560,7 @@ cmd_branch(int argc, char *argv[]) struct got_worktree *worktree = NULL; char *cwd = NULL, *repo_path = NULL; int ch, do_list = 0, do_show = 0, do_update = 1; + int cwd_fd = -1; const char *delref = NULL, *commit_id_arg = NULL; struct got_reference *ref = NULL; struct got_pathlist_head paths; @@ -5582,9 +5631,14 @@ cmd_branch(int argc, char *argv[]) error = got_error_from_errno("getcwd"); goto done; } + cwd_fd = open(cwd, O_DIRECTORY); + if (cwd_fd == -1) { + error = got_error_from_errno2("open", cwd); + goto done; + } if (repo_path == NULL) { - error = got_worktree_open(&worktree, cwd); + error = got_worktree_open(&worktree, cwd_fd, cwd); if (error && error->code != GOT_ERR_NOT_WORKTREE) goto done; else @@ -6052,6 +6106,7 @@ cmd_tag(int argc, char *argv[]) char *gitconfig_path = NULL; const char *tag_name, *commit_id_arg = NULL, *tagmsg = NULL; int ch, do_list = 0; + int cwd_fd = -1; while ((ch = getopt(argc, argv, "c:m:r:l")) != -1) { switch (ch) { @@ -6109,9 +6164,14 @@ cmd_tag(int argc, char *argv[]) error = got_error_from_errno("getcwd"); goto done; } + cwd_fd = open(cwd, O_DIRECTORY); + if (cwd_fd == -1) { + error = got_error_from_errno2("open", cwd); + goto done; + } if (repo_path == NULL) { - error = got_worktree_open(&worktree, cwd); + error = got_worktree_open(&worktree, cwd_fd, cwd); if (error && error->code != GOT_ERR_NOT_WORKTREE) goto done; else @@ -6214,6 +6274,7 @@ cmd_add(int argc, char *argv[]) struct got_pathlist_head paths; struct got_pathlist_entry *pe; int ch, can_recurse = 0, no_ignores = 0; + int cwd_fd = -1; TAILQ_INIT(&paths); @@ -6247,8 +6308,13 @@ cmd_add(int argc, char *argv[]) error = got_error_from_errno("getcwd"); goto done; } + cwd_fd = open(cwd, O_DIRECTORY); + if (cwd_fd == -1) { + error = got_error_from_errno2("open", cwd); + goto done; + } - error = got_worktree_open(&worktree, cwd); + error = got_worktree_open(&worktree, cwd_fd, cwd); if (error) { if (error->code == GOT_ERR_NOT_WORKTREE) error = wrap_not_worktree_error(error, "add", cwd); @@ -6352,6 +6418,7 @@ cmd_remove(int argc, char *argv[]) struct got_pathlist_head paths; struct got_pathlist_entry *pe; int ch, delete_local_mods = 0, can_recurse = 0, keep_on_disk = 0, i; + int cwd_fd = -1; TAILQ_INIT(&paths); @@ -6403,7 +6470,13 @@ cmd_remove(int argc, char *argv[]) error = got_error_from_errno("getcwd"); goto done; } - error = got_worktree_open(&worktree, cwd); + cwd_fd = open(cwd, O_DIRECTORY); + if (cwd_fd == -1) { + error = got_error_from_errno2("open", cwd); + goto done; + } + + error = got_worktree_open(&worktree, cwd_fd, cwd); if (error) { if (error->code == GOT_ERR_NOT_WORKTREE) error = wrap_not_worktree_error(error, "remove", cwd); @@ -6611,6 +6684,7 @@ cmd_revert(int argc, char *argv[]) struct got_pathlist_head paths; struct got_pathlist_entry *pe; int ch, can_recurse = 0, pflag = 0; + int cwd_fd = -1; FILE *patch_script_file = NULL; const char *patch_script_path = NULL; struct choose_patch_arg cpa; @@ -6652,7 +6726,13 @@ cmd_revert(int argc, char *argv[]) error = got_error_from_errno("getcwd"); goto done; } - error = got_worktree_open(&worktree, cwd); + cwd_fd = open(cwd, O_DIRECTORY); + if (cwd_fd == -1) { + error = got_error_from_errno2("open", cwd); + goto done; + } + + error = got_worktree_open(&worktree, cwd_fd, cwd); if (error) { if (error->code == GOT_ERR_NOT_WORKTREE) error = wrap_not_worktree_error(error, "revert", cwd); @@ -6825,6 +6905,7 @@ cmd_commit(int argc, char *argv[]) char *gitconfig_path = NULL, *editor = NULL, *author = NULL; int ch, rebase_in_progress, histedit_in_progress, preserve_logmsg = 0; int allow_bad_symlinks = 0; + int cwd_fd = -1; struct got_pathlist_head paths; TAILQ_INIT(&paths); @@ -6857,7 +6938,13 @@ cmd_commit(int argc, char *argv[]) error = got_error_from_errno("getcwd"); goto done; } - error = got_worktree_open(&worktree, cwd); + cwd_fd = open(cwd, O_DIRECTORY); + if (cwd_fd == -1) { + error = got_error_from_errno2("open", cwd); + goto done; + } + + error = got_worktree_open(&worktree, cwd_fd, cwd); if (error) { if (error->code == GOT_ERR_NOT_WORKTREE) error = wrap_not_worktree_error(error, "commit", cwd); @@ -6970,6 +7057,7 @@ cmd_cherrypick(int argc, char *argv[]) struct got_object_qid *pid; struct got_reference *head_ref = NULL; int ch; + int cwd_fd = -1; struct got_update_progress_arg upa; while ((ch = getopt(argc, argv, "")) != -1) { @@ -6996,7 +7084,13 @@ cmd_cherrypick(int argc, char *argv[]) error = got_error_from_errno("getcwd"); goto done; } - error = got_worktree_open(&worktree, cwd); + cwd_fd = open(cwd, O_DIRECTORY); + if (cwd_fd == -1) { + error = got_error_from_errno2("open", cwd); + goto done; + } + + error = got_worktree_open(&worktree, cwd_fd, cwd); if (error) { if (error->code == GOT_ERR_NOT_WORKTREE) error = wrap_not_worktree_error(error, "cherrypick", @@ -7093,6 +7187,7 @@ cmd_backout(int argc, char *argv[]) struct got_object_qid *pid; struct got_reference *head_ref = NULL; int ch; + int cwd_fd = -1; struct got_update_progress_arg upa; while ((ch = getopt(argc, argv, "")) != -1) { @@ -7119,7 +7214,13 @@ cmd_backout(int argc, char *argv[]) error = got_error_from_errno("getcwd"); goto done; } - error = got_worktree_open(&worktree, cwd); + cwd_fd = open(cwd, O_DIRECTORY); + if (cwd_fd == -1) { + error = got_error_from_errno2("open", cwd); + goto done; + } + + error = got_worktree_open(&worktree, cwd_fd, cwd); if (error) { if (error->code == GOT_ERR_NOT_WORKTREE) error = wrap_not_worktree_error(error, "backout", cwd); @@ -7483,6 +7584,7 @@ cmd_rebase(int argc, char *argv[]) struct got_commit_object *commit = NULL; int ch, rebase_in_progress = 0, abort_rebase = 0, continue_rebase = 0; int histedit_in_progress = 0; + int cwd_fd = -1; unsigned char rebase_status = GOT_STATUS_NO_CHANGE; struct got_object_id_queue commits; struct got_pathlist_head merged_paths; @@ -7527,7 +7629,13 @@ cmd_rebase(int argc, char *argv[]) error = got_error_from_errno("getcwd"); goto done; } - error = got_worktree_open(&worktree, cwd); + cwd_fd = open(cwd, O_DIRECTORY); + if (cwd_fd == -1) { + error = got_error_from_errno2("open", cwd); + goto done; + } + + error = got_worktree_open(&worktree, cwd_fd, cwd); if (error) { if (error->code == GOT_ERR_NOT_WORKTREE) error = wrap_not_worktree_error(error, "rebase", cwd); @@ -8593,6 +8701,7 @@ cmd_histedit(int argc, char *argv[]) struct got_update_progress_arg upa; int edit_in_progress = 0, abort_edit = 0, continue_edit = 0; int edit_logmsg_only = 0; + int cwd_fd = -1; const char *edit_script_path = NULL; unsigned char rebase_status = GOT_STATUS_NO_CHANGE; struct got_object_id_queue commits; @@ -8660,7 +8769,13 @@ cmd_histedit(int argc, char *argv[]) error = got_error_from_errno("getcwd"); goto done; } - error = got_worktree_open(&worktree, cwd); + cwd_fd = open(cwd, O_DIRECTORY); + if (cwd_fd == -1) { + error = got_error_from_errno2("open", cwd); + goto done; + } + + error = got_worktree_open(&worktree, cwd_fd, cwd); if (error) { if (error->code == GOT_ERR_NOT_WORKTREE) error = wrap_not_worktree_error(error, "histedit", cwd); @@ -9015,6 +9130,7 @@ cmd_integrate(int argc, char *argv[]) struct got_fileindex *fileindex = NULL; struct got_object_id *commit_id = NULL, *base_commit_id = NULL; int ch; + int cwd_fd = -1; struct got_update_progress_arg upa; while ((ch = getopt(argc, argv, "")) != -1) { @@ -9041,8 +9157,13 @@ cmd_integrate(int argc, char *argv[]) error = got_error_from_errno("getcwd"); goto done; } + cwd_fd = open(cwd, O_DIRECTORY); + if (cwd_fd == -1) { + error = got_error_from_errno2("open", cwd); + goto done; + } - error = got_worktree_open(&worktree, cwd); + error = got_worktree_open(&worktree, cwd_fd, cwd); if (error) { if (error->code == GOT_ERR_NOT_WORKTREE) error = wrap_not_worktree_error(error, "integrate", @@ -9182,6 +9303,7 @@ cmd_stage(int argc, char *argv[]) struct got_pathlist_head paths; struct got_pathlist_entry *pe; int ch, list_stage = 0, pflag = 0, allow_bad_symlinks = 0; + int cwd_fd = -1; FILE *patch_script_file = NULL; const char *patch_script_path = NULL; struct choose_patch_arg cpa; @@ -9226,8 +9348,13 @@ cmd_stage(int argc, char *argv[]) error = got_error_from_errno("getcwd"); goto done; } + cwd_fd = open(cwd, O_DIRECTORY); + if (cwd_fd == -1) { + error = got_error_from_errno2("open", cwd); + goto done; + } - error = got_worktree_open(&worktree, cwd); + error = got_worktree_open(&worktree, cwd_fd, cwd); if (error) { if (error->code == GOT_ERR_NOT_WORKTREE) error = wrap_not_worktree_error(error, "stage", cwd); @@ -9302,6 +9429,7 @@ cmd_unstage(int argc, char *argv[]) struct got_pathlist_head paths; struct got_pathlist_entry *pe; int ch, pflag = 0; + int cwd_fd = -1; struct got_update_progress_arg upa; FILE *patch_script_file = NULL; const char *patch_script_path = NULL; @@ -9339,8 +9467,13 @@ cmd_unstage(int argc, char *argv[]) error = got_error_from_errno("getcwd"); goto done; } + cwd_fd = open(cwd, O_DIRECTORY); + if (cwd_fd == -1) { + error = got_error_from_errno2("open", cwd); + goto done; + } - error = got_worktree_open(&worktree, cwd); + error = got_worktree_open(&worktree, cwd_fd, cwd); if (error) { if (error->code == GOT_ERR_NOT_WORKTREE) error = wrap_not_worktree_error(error, "unstage", cwd); @@ -9558,6 +9691,7 @@ cmd_cat(int argc, char *argv[]) const char *commit_id_str = NULL; struct got_object_id *id = NULL, *commit_id = NULL; int ch, obj_type, i, force_path = 0; + int cwd_fd = -1; #ifndef PROFILE if (pledge("stdio rpath wpath cpath flock proc exec sendfd unveil", @@ -9594,7 +9728,13 @@ cmd_cat(int argc, char *argv[]) error = got_error_from_errno("getcwd"); goto done; } - error = got_worktree_open(&worktree, cwd); + cwd_fd = open(cwd, O_DIRECTORY); + if (cwd_fd == -1) { + error = got_error_from_errno2("open", cwd); + goto done; + } + + error = got_worktree_open(&worktree, cwd_fd, cwd); if (error && error->code != GOT_ERR_NOT_WORKTREE) goto done; if (worktree) { @@ -9779,6 +9919,7 @@ cmd_info(int argc, char *argv[]) struct got_pathlist_entry *pe; char *uuidstr = NULL; int ch, show_files = 0; + int cwd_fd = -1; TAILQ_INIT(&paths); @@ -9803,8 +9944,13 @@ cmd_info(int argc, char *argv[]) error = got_error_from_errno("getcwd"); goto done; } + cwd_fd = open(cwd, O_DIRECTORY); + if (cwd_fd == -1) { + error = got_error_from_errno2("open", cwd); + goto done; + } - error = got_worktree_open(&worktree, cwd); + error = got_worktree_open(&worktree, cwd_fd, cwd); if (error) { if (error->code == GOT_ERR_NOT_WORKTREE) error = wrap_not_worktree_error(error, "status", cwd); diff --git a/include/got_worktree.h b/include/got_worktree.h index 13b13521..0e517bef 100644 --- a/include/got_worktree.h +++ b/include/got_worktree.h @@ -53,7 +53,7 @@ const struct got_error *got_worktree_init(int, const char *, struct got_referenc * Attempt to open a worktree at or above the specified path. * The caller must dispose of it with got_worktree_close(). */ -const struct got_error *got_worktree_open(struct got_worktree **, const char *); +const struct got_error *got_worktree_open(struct got_worktree **, int, const char *); /* Dispose of an open work tree. */ const struct got_error *got_worktree_close(struct got_worktree *); diff --git a/lib/worktree.c b/lib/worktree.c index 8bf4b7ff..f4670cfb 100644 --- a/lib/worktree.c +++ b/lib/worktree.c @@ -440,20 +440,16 @@ done: } const struct got_error * -got_worktree_open(struct got_worktree **worktree, const char *path) +got_worktree_open(struct got_worktree **worktree, + int worktree_fd, const char *path) { const struct got_error *err = NULL; char *worktree_path; - int worktree_fd; worktree_path = strdup(path); if (worktree_path == NULL) return got_error_from_errno("strdup"); - worktree_fd = open(worktree_path, O_DIRECTORY); - if (worktree_fd == -1) - return got_error_from_errno2("open", worktree_path); - for (;;) { char *parent_path; diff --git a/tog/tog.c b/tog/tog.c index 1bee4fa4..e47736b0 100644 --- a/tog/tog.c +++ b/tog/tog.c @@ -23,6 +23,7 @@ #define _XOPEN_SOURCE_EXTENDED #include #undef _XOPEN_SOURCE_EXTENDED +#include #include #include #include @@ -2707,6 +2708,7 @@ cmd_log(int argc, char *argv[]) char *in_repo_path = NULL, *repo_path = NULL, *cwd = NULL; char *start_commit = NULL, *head_ref_name = NULL; int ch, log_branches = 0; + int cwd_fd = -1; struct tog_view *view; #ifndef PROFILE @@ -2744,8 +2746,11 @@ cmd_log(int argc, char *argv[]) cwd = getcwd(NULL, 0); if (cwd == NULL) return got_error_from_errno("getcwd"); + cwd_fd = open(cwd, O_DIRECTORY); + if (cwd_fd == -1) + return got_error_from_errno2("open", cwd); - error = got_worktree_open(&worktree, cwd); + error = got_worktree_open(&worktree, cwd_fd, cwd); if (error && error->code != GOT_ERR_NOT_WORKTREE) goto done; @@ -3800,6 +3805,7 @@ cmd_diff(int argc, char *argv[]) char *label1 = NULL, *label2 = NULL; int diff_context = 3, ignore_whitespace = 0; int ch, force_text_diff = 0; + int cwd_fd = -1; const char *errstr; struct tog_view *view; @@ -3849,8 +3855,11 @@ cmd_diff(int argc, char *argv[]) cwd = getcwd(NULL, 0); if (cwd == NULL) return got_error_from_errno("getcwd"); + cwd_fd = open(cwd, O_DIRECTORY); + if (cwd_fd == -1) + return got_error_from_errno2("open", cwd); - error = got_worktree_open(&worktree, cwd); + error = got_worktree_open(&worktree, cwd_fd, cwd); if (error && error->code != GOT_ERR_NOT_WORKTREE) goto done; @@ -4721,6 +4730,7 @@ cmd_blame(int argc, char *argv[]) struct got_object_id *commit_id = NULL; char *commit_id_str = NULL; int ch; + int cwd_fd = -1; struct tog_view *view; #ifndef PROFILE @@ -4755,8 +4765,11 @@ cmd_blame(int argc, char *argv[]) cwd = getcwd(NULL, 0); if (cwd == NULL) return got_error_from_errno("getcwd"); + cwd_fd = open(cwd, O_DIRECTORY); + if (cwd_fd == -1) + return got_error_from_errno2("open", cwd); - error = got_worktree_open(&worktree, cwd); + error = got_worktree_open(&worktree, cwd_fd, cwd); if (error && error->code != GOT_ERR_NOT_WORKTREE) goto done; @@ -5541,6 +5554,7 @@ cmd_tree(int argc, char *argv[]) struct got_commit_object *commit = NULL; struct got_tree_object *tree = NULL; int ch; + int cwd_fd = -1; struct tog_view *view; #ifndef PROFILE @@ -5575,8 +5589,11 @@ cmd_tree(int argc, char *argv[]) cwd = getcwd(NULL, 0); if (cwd == NULL) return got_error_from_errno("getcwd"); + cwd_fd = open(cwd, O_DIRECTORY); + if (cwd_fd == -1) + return got_error_from_errno2("open", cwd); - error = got_worktree_open(&worktree, cwd); + error = got_worktree_open(&worktree, cwd_fd, cwd); if (error && error->code != GOT_ERR_NOT_WORKTREE) goto done; @@ -6280,6 +6297,7 @@ cmd_ref(int argc, char *argv[]) struct got_worktree *worktree = NULL; char *cwd = NULL, *repo_path = NULL; int ch; + int cwd_fd = -1; struct tog_view *view; #ifndef PROFILE @@ -6311,8 +6329,11 @@ cmd_ref(int argc, char *argv[]) cwd = getcwd(NULL, 0); if (cwd == NULL) return got_error_from_errno("getcwd"); + cwd_fd = open(cwd, O_DIRECTORY); + if (cwd_fd == -1) + return got_error_from_errno2("open", cwd); - error = got_worktree_open(&worktree, cwd); + error = got_worktree_open(&worktree, cwd_fd, cwd); if (error && error->code != GOT_ERR_NOT_WORKTREE) goto done; @@ -6428,12 +6449,16 @@ tog_log_with_path(int argc, char *argv[]) struct got_object_id *commit_id = NULL, *id = NULL; char *cwd = NULL, *repo_path = NULL, *in_repo_path = NULL; char *commit_id_str = NULL, **cmd_argv = NULL; + int cwd_fd = -1; cwd = getcwd(NULL, 0); if (cwd == NULL) return got_error_from_errno("getcwd"); + cwd_fd = open(cwd, O_DIRECTORY); + if (cwd_fd == -1) + return got_error_from_errno2("open", cwd); - error = got_worktree_open(&worktree, cwd); + error = got_worktree_open(&worktree, cwd_fd, cwd); if (error && error->code != GOT_ERR_NOT_WORKTREE) goto done;