From: Tracey Emery Subject: Move got_opentempfd out of got_repo_open To: gameoftrees@openbsd.org Date: Wed, 1 Jun 2022 10:22:49 -0600 Hello, Here is a first attempt to move got_opentempfd out of got_repo_open. Is this direction ok? I am not asking for a commit ok yet, just starting a conversation about the direction. This creates an array of fds twice the size of GOT_PACK_CACHE_SIZE to pass to got_repo_open by the caller. Thoughts? This move will remove the need for gotwebd to have /var/www/got/tmp finally. Here's the problem: ==== tag ==== ./tag.sh -q -r "/tmp" git tag command succeeded unexpectedly test failed; leaving test data in /tmp/got-test-tag_create-zt1vzkb1 I'm not sure why this is failing yet, hence, why I'm not asking for commit ok. It's the only test that does. -- Tracey Emery diff 2497f032fa6bc06264d8990fdd57a9ffbaf1429b /home/tracey/src/got blob - cf96009500ac33bb3b660dd7e99902801b0cb975 file + got/got.c --- got/got.c +++ got/got.c @@ -715,6 +715,8 @@ cmd_import(int argc, char *argv[]) struct got_pathlist_head ignores; struct got_pathlist_entry *pe; int preserve_logmsg = 0; + int cs = got_repo_get_pack_cache_size(); + int pack_fds[cs]; TAILQ_INIT(&ignores); @@ -773,9 +775,15 @@ cmd_import(int argc, char *argv[]) error = get_gitconfig_path(&gitconfig_path); if (error) goto done; - error = got_repo_open(&repo, repo_path, gitconfig_path); + error = got_repo_pack_fds_init(pack_fds); + if (error != NULL) + goto done; + error = got_repo_open(&repo, repo_path, gitconfig_path, pack_fds); if (error) goto done; + error = got_repo_pack_fds_close(pack_fds); + if (error != NULL) + goto done; error = get_author(&author, repo, NULL); if (error) @@ -1484,6 +1492,8 @@ cmd_clone(int argc, char *argv[]) char *git_url = NULL; int verbosity = 0, fetch_all_branches = 0, mirror_references = 0; int list_refs_only = 0; + int cs = got_repo_get_pack_cache_size(); + int pack_fds[cs]; TAILQ_INIT(&refs); TAILQ_INIT(&symrefs); @@ -1628,9 +1638,15 @@ cmd_clone(int argc, char *argv[]) error = got_repo_init(repo_path); if (error) goto done; - error = got_repo_open(&repo, repo_path, NULL); + error = got_repo_pack_fds_init(pack_fds); + if (error != NULL) + goto done; + error = got_repo_open(&repo, repo_path, NULL, pack_fds); if (error) goto done; + error = got_repo_pack_fds_close(pack_fds); + if (error != NULL) + goto done; } fpa.last_scaled_size[0] = '\0'; @@ -2212,6 +2228,8 @@ 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, delete_remote = 0; + int cs = got_repo_get_pack_cache_size(); + int pack_fds[cs]; TAILQ_INIT(&refs); TAILQ_INIT(&symrefs); @@ -2333,10 +2351,18 @@ cmd_fetch(int argc, char *argv[]) } } - error = got_repo_open(&repo, repo_path, NULL); + error = got_repo_pack_fds_init(pack_fds); + if (error != NULL) + goto done; + + error = got_repo_open(&repo, repo_path, NULL, pack_fds); if (error) goto done; + error = got_repo_pack_fds_close(pack_fds); + if (error != NULL) + goto done; + if (delete_remote) { error = delete_refs_for_remote(repo, remote_name); goto done; /* nothing else to do */ @@ -2848,6 +2874,8 @@ cmd_checkout(int argc, char *argv[]) int ch, same_path_prefix, allow_nonempty = 0, verbosity = 0; struct got_pathlist_head paths; struct got_checkout_progress_arg cpa; + int cs = got_repo_get_pack_cache_size(); + int pack_fds[cs]; TAILQ_INIT(&paths); @@ -2936,10 +2964,18 @@ cmd_checkout(int argc, char *argv[]) got_path_strip_trailing_slashes(repo_path); got_path_strip_trailing_slashes(worktree_path); - error = got_repo_open(&repo, repo_path, NULL); + error = got_repo_pack_fds_init(pack_fds); if (error != NULL) goto done; + error = got_repo_open(&repo, repo_path, NULL, pack_fds); + if (error != NULL) + goto done; + + error = got_repo_pack_fds_close(pack_fds); + if (error != NULL) + goto done; + /* Pre-create work tree path for unveil(2) */ error = got_path_mkdir(worktree_path); if (error) { @@ -3281,11 +3317,21 @@ wrap_not_worktree_error(const struct got_error *orig_e const struct got_error *err; struct got_repository *repo; static char msg[512]; + int cs = got_repo_get_pack_cache_size(); + int pack_fds[cs]; - err = got_repo_open(&repo, path, NULL); + err = got_repo_pack_fds_init(pack_fds); if (err) + return err; + + err = got_repo_open(&repo, path, NULL, pack_fds); + if (err) return orig_err; + err = got_repo_pack_fds_close(pack_fds); + if (err != NULL) + return err; + snprintf(msg, sizeof(msg), "'got %s' needs a work tree in addition to a git repository\n" "Work trees can be checked out from this Git repository with " @@ -3311,6 +3357,8 @@ cmd_update(int argc, char *argv[]) struct got_pathlist_entry *pe; int ch, verbosity = 0; struct got_update_progress_arg upa; + int cs = got_repo_get_pack_cache_size(); + int pack_fds[cs]; TAILQ_INIT(&paths); @@ -3358,11 +3406,19 @@ cmd_update(int argc, char *argv[]) if (error) goto done; + error = got_repo_pack_fds_init(pack_fds); + if (error != NULL) + goto done; + error = got_repo_open(&repo, got_worktree_get_repo_path(worktree), - NULL); + NULL, pack_fds); if (error != NULL) goto done; + error = got_repo_pack_fds_close(pack_fds); + if (error != NULL) + goto done; + error = apply_unveil(got_repo_get_path(repo), 0, got_worktree_get_root_path(worktree)); if (error) @@ -4088,6 +4144,8 @@ cmd_log(int argc, char *argv[]) const char *errstr; struct got_reflist_head refs; struct got_reflist_object_id_map *refs_idmap = NULL; + int cs = got_repo_get_pack_cache_size(); + int pack_fds[cs]; TAILQ_INIT(&refs); @@ -4195,10 +4253,18 @@ cmd_log(int argc, char *argv[]) goto done; } - error = got_repo_open(&repo, repo_path, NULL); + error = got_repo_pack_fds_init(pack_fds); if (error != NULL) goto done; + error = got_repo_open(&repo, repo_path, NULL, pack_fds); + if (error != NULL) + goto done; + + error = got_repo_pack_fds_close(pack_fds); + if (error != NULL) + goto done; + error = apply_unveil(got_repo_get_path(repo), 1, worktree ? got_worktree_get_root_path(worktree) : NULL); if (error) @@ -4519,6 +4585,8 @@ cmd_diff(int argc, char *argv[]) struct got_reflist_head refs; struct got_pathlist_head paths; struct got_pathlist_entry *pe; + int cs = got_repo_get_pack_cache_size(); + int pack_fds[cs]; TAILQ_INIT(&refs); TAILQ_INIT(&paths); @@ -4600,11 +4668,19 @@ cmd_diff(int argc, char *argv[]) } } - error = got_repo_open(&repo, repo_path, NULL); + error = got_repo_pack_fds_init(pack_fds); + if (error != NULL) + goto done; + + error = got_repo_open(&repo, repo_path, NULL, pack_fds); free(repo_path); if (error != NULL) goto done; + error = got_repo_pack_fds_close(pack_fds); + if (error != NULL) + goto done; + if (rflag || worktree == NULL || ncommit_args > 0) { if (force_path) { error = got_error_msg(GOT_ERR_NOT_IMPL, @@ -4985,6 +5061,8 @@ cmd_blame(int argc, char *argv[]) struct blame_cb_args bca; int ch, obj_type, i; off_t filesize; + int cs = got_repo_get_pack_cache_size(); + int pack_fds[cs]; memset(&bca, 0, sizeof(bca)); @@ -5048,10 +5126,18 @@ cmd_blame(int argc, char *argv[]) } } - error = got_repo_open(&repo, repo_path, NULL); + error = got_repo_pack_fds_init(pack_fds); if (error != NULL) goto done; + error = got_repo_open(&repo, repo_path, NULL, pack_fds); + if (error != NULL) + goto done; + + error = got_repo_pack_fds_close(pack_fds); + if (error != NULL) + goto done; + if (worktree) { const char *prefix = got_worktree_get_path_prefix(worktree); char *p; @@ -5326,6 +5412,8 @@ cmd_tree(int argc, char *argv[]) char *commit_id_str = NULL; int show_ids = 0, recurse = 0; int ch; + int cs = got_repo_get_pack_cache_size(); + int pack_fds[cs]; #ifndef PROFILE if (pledge("stdio rpath wpath cpath flock proc exec sendfd unveil", @@ -5394,10 +5482,18 @@ cmd_tree(int argc, char *argv[]) } } - error = got_repo_open(&repo, repo_path, NULL); + error = got_repo_pack_fds_init(pack_fds); if (error != NULL) goto done; + error = got_repo_open(&repo, repo_path, NULL, pack_fds); + if (error != NULL) + goto done; + + error = got_repo_pack_fds_close(pack_fds); + if (error != NULL) + goto done; + if (worktree) { const char *prefix = got_worktree_get_path_prefix(worktree); char *p; @@ -5548,6 +5644,8 @@ cmd_status(int argc, char *argv[]) struct got_pathlist_head paths; struct got_pathlist_entry *pe; int ch, i, no_ignores = 0; + int cs = got_repo_get_pack_cache_size(); + int pack_fds[cs]; TAILQ_INIT(&paths); @@ -5614,11 +5712,19 @@ cmd_status(int argc, char *argv[]) goto done; } + error = got_repo_pack_fds_init(pack_fds); + if (error != NULL) + goto done; + error = got_repo_open(&repo, got_worktree_get_repo_path(worktree), - NULL); + NULL, pack_fds); if (error != NULL) goto done; + error = got_repo_pack_fds_close(pack_fds); + if (error != NULL) + goto done; + error = apply_unveil(got_repo_get_path(repo), 1, got_worktree_get_root_path(worktree)); if (error) @@ -5772,6 +5878,8 @@ cmd_ref(int argc, char *argv[]) int ch, do_list = 0, do_delete = 0, sort_by_time = 0; const char *obj_arg = NULL, *symref_target= NULL; char *refname = NULL; + int cs = got_repo_get_pack_cache_size(); + int pack_fds[cs]; while ((ch = getopt(argc, argv, "c:dr:ls:t")) != -1) { switch (ch) { @@ -5877,10 +5985,18 @@ cmd_ref(int argc, char *argv[]) } } - error = got_repo_open(&repo, repo_path, NULL); + error = got_repo_pack_fds_init(pack_fds); if (error != NULL) goto done; + error = got_repo_open(&repo, repo_path, NULL, pack_fds); + if (error != NULL) + goto done; + + error = got_repo_pack_fds_close(pack_fds); + if (error != NULL) + goto done; + #ifndef PROFILE if (do_list) { /* Remove "cpath" promise. */ @@ -6162,6 +6278,8 @@ cmd_branch(int argc, char *argv[]) struct got_pathlist_entry *pe; struct got_object_id *commit_id = NULL; char *commit_id_str = NULL; + int cs = got_repo_get_pack_cache_size(); + int pack_fds[cs]; TAILQ_INIT(&paths); @@ -6248,10 +6366,18 @@ cmd_branch(int argc, char *argv[]) } } - error = got_repo_open(&repo, repo_path, NULL); + error = got_repo_pack_fds_init(pack_fds); if (error != NULL) goto done; + error = got_repo_open(&repo, repo_path, NULL, pack_fds); + if (error != NULL) + goto done; + + error = got_repo_pack_fds_close(pack_fds); + if (error != NULL) + goto done; + #ifndef PROFILE if (do_list || do_show) { /* Remove "cpath" promise. */ @@ -6720,6 +6846,8 @@ cmd_tag(int argc, char *argv[]) char *gitconfig_path = NULL, *tagger = NULL; const char *tag_name, *commit_id_arg = NULL, *tagmsg = NULL; int ch, do_list = 0; + int cs = got_repo_get_pack_cache_size(); + int pack_fds[cs]; while ((ch = getopt(argc, argv, "c:m:r:l")) != -1) { switch (ch) { @@ -6794,13 +6922,17 @@ cmd_tag(int argc, char *argv[]) } } + error = got_repo_pack_fds_init(pack_fds); + if (error != NULL) + goto done; + if (do_list) { if (worktree) { /* Release work tree lock. */ got_worktree_close(worktree); worktree = NULL; } - error = got_repo_open(&repo, repo_path, NULL); + error = got_repo_open(&repo, repo_path, NULL, pack_fds); if (error != NULL) goto done; #ifndef PROFILE @@ -6817,7 +6949,8 @@ cmd_tag(int argc, char *argv[]) error = get_gitconfig_path(&gitconfig_path); if (error) goto done; - error = got_repo_open(&repo, repo_path, gitconfig_path); + error = got_repo_open(&repo, repo_path, gitconfig_path, + pack_fds); if (error != NULL) goto done; @@ -6857,6 +6990,10 @@ cmd_tag(int argc, char *argv[]) error = add_tag(repo, tagger, tag_name, commit_id_str ? commit_id_str : commit_id_arg, tagmsg); } + + error = got_repo_pack_fds_close(pack_fds); + if (error != NULL) + goto done; done: if (repo) { const struct got_error *close_err = got_repo_close(repo); @@ -6900,6 +7037,8 @@ 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 cs = got_repo_get_pack_cache_size(); + int pack_fds[cs]; TAILQ_INIT(&paths); @@ -6941,11 +7080,19 @@ cmd_add(int argc, char *argv[]) goto done; } + error = got_repo_pack_fds_init(pack_fds); + if (error != NULL) + goto done; + error = got_repo_open(&repo, got_worktree_get_repo_path(worktree), - NULL); + NULL, pack_fds); if (error != NULL) goto done; + error = got_repo_pack_fds_close(pack_fds); + if (error != NULL) + goto done; + error = apply_unveil(got_repo_get_path(repo), 1, got_worktree_get_root_path(worktree)); if (error) @@ -7035,6 +7182,8 @@ cmd_remove(int argc, char *argv[]) struct got_pathlist_entry *pe; int ch, delete_local_mods = 0, can_recurse = 0, keep_on_disk = 0, i; int ignore_missing_paths = 0; + int cs = got_repo_get_pack_cache_size(); + int pack_fds[cs]; TAILQ_INIT(&paths); @@ -7095,11 +7244,19 @@ cmd_remove(int argc, char *argv[]) goto done; } + error = got_repo_pack_fds_init(pack_fds); + if (error != NULL) + goto done; + error = got_repo_open(&repo, got_worktree_get_repo_path(worktree), - NULL); + NULL, pack_fds); if (error) goto done; + error = got_repo_pack_fds_close(pack_fds); + if (error != NULL) + goto done; + error = apply_unveil(got_repo_get_path(repo), 1, got_worktree_get_root_path(worktree)); if (error) @@ -7251,6 +7408,8 @@ cmd_patch(int argc, char *argv[]) char *cwd = NULL; int ch, nop = 0, strip = -1, reverse = 0; int patchfd; + int cs = got_repo_get_pack_cache_size(); + int pack_fds[cs]; while ((ch = getopt(argc, argv, "np:R")) != -1) { switch (ch) { @@ -7297,11 +7456,19 @@ cmd_patch(int argc, char *argv[]) if (error != NULL) goto done; + error = got_repo_pack_fds_init(pack_fds); + if (error != NULL) + goto done; + const char *repo_path = got_worktree_get_repo_path(worktree); - error = got_repo_open(&repo, repo_path, NULL); + error = got_repo_open(&repo, repo_path, NULL, pack_fds); if (error != NULL) goto done; + error = got_repo_pack_fds_close(pack_fds); + if (error != NULL) + goto done; + error = apply_unveil(got_repo_get_path(repo), 0, got_worktree_get_root_path(worktree)); if (error != NULL) @@ -7476,6 +7643,8 @@ cmd_revert(int argc, char *argv[]) FILE *patch_script_file = NULL; const char *patch_script_path = NULL; struct choose_patch_arg cpa; + int cs = got_repo_get_pack_cache_size(); + int pack_fds[cs]; TAILQ_INIT(&paths); @@ -7521,11 +7690,19 @@ cmd_revert(int argc, char *argv[]) goto done; } + error = got_repo_pack_fds_init(pack_fds); + if (error != NULL) + goto done; + error = got_repo_open(&repo, got_worktree_get_repo_path(worktree), - NULL); + NULL, pack_fds); if (error != NULL) goto done; + error = got_repo_pack_fds_close(pack_fds); + if (error != NULL) + goto done; + if (patch_script_path) { patch_script_file = fopen(patch_script_path, "re"); if (patch_script_file == NULL) { @@ -7760,6 +7937,8 @@ cmd_commit(int argc, char *argv[]) int ch, rebase_in_progress, histedit_in_progress, preserve_logmsg = 0; int allow_bad_symlinks = 0, non_interactive = 0, merge_in_progress = 0; struct got_pathlist_head paths; + int cs = got_repo_get_pack_cache_size(); + int pack_fds[cs]; TAILQ_INIT(&paths); cl_arg.logmsg_path = NULL; @@ -7827,11 +8006,20 @@ cmd_commit(int argc, char *argv[]) error = get_gitconfig_path(&gitconfig_path); if (error) goto done; + + error = got_repo_pack_fds_init(pack_fds); + if (error != NULL) + goto done; + error = got_repo_open(&repo, got_worktree_get_repo_path(worktree), - gitconfig_path); + gitconfig_path, pack_fds); if (error != NULL) goto done; + error = got_repo_pack_fds_close(pack_fds); + if (error != NULL) + goto done; + error = got_worktree_merge_in_progress(&merge_in_progress, worktree, repo); if (error) goto done; @@ -8139,6 +8327,8 @@ cmd_send(int argc, char *argv[]) int verbosity = 0, overwrite_refs = 0; int send_all_branches = 0, send_all_tags = 0; struct got_reference *ref = NULL; + int cs = got_repo_get_pack_cache_size(); + int pack_fds[cs]; TAILQ_INIT(&branches); TAILQ_INIT(&tags); @@ -8240,10 +8430,18 @@ cmd_send(int argc, char *argv[]) } } - error = got_repo_open(&repo, repo_path, NULL); + error = got_repo_pack_fds_init(pack_fds); + if (error != NULL) + goto done; + + error = got_repo_open(&repo, repo_path, NULL, pack_fds); if (error) goto done; + error = got_repo_pack_fds_close(pack_fds); + if (error != NULL) + goto done; + if (worktree) { worktree_conf = got_worktree_get_gotconfig(worktree); if (worktree_conf) { @@ -8485,6 +8683,8 @@ cmd_cherrypick(int argc, char *argv[]) struct got_object_qid *pid; int ch; struct got_update_progress_arg upa; + int cs = got_repo_get_pack_cache_size(); + int pack_fds[cs]; while ((ch = getopt(argc, argv, "")) != -1) { switch (ch) { @@ -8518,11 +8718,19 @@ cmd_cherrypick(int argc, char *argv[]) goto done; } + error = got_repo_pack_fds_init(pack_fds); + if (error != NULL) + goto done; + error = got_repo_open(&repo, got_worktree_get_repo_path(worktree), - NULL); + NULL, pack_fds); if (error != NULL) goto done; + error = got_repo_pack_fds_close(pack_fds); + if (error != NULL) + goto done; + error = apply_unveil(got_repo_get_path(repo), 0, got_worktree_get_root_path(worktree)); if (error) @@ -8583,6 +8791,8 @@ cmd_backout(int argc, char *argv[]) struct got_object_qid *pid; int ch; struct got_update_progress_arg upa; + int cs = got_repo_get_pack_cache_size(); + int pack_fds[cs]; while ((ch = getopt(argc, argv, "")) != -1) { switch (ch) { @@ -8615,11 +8825,19 @@ cmd_backout(int argc, char *argv[]) goto done; } + error = got_repo_pack_fds_init(pack_fds); + if (error != NULL) + goto done; + error = got_repo_open(&repo, got_worktree_get_repo_path(worktree), - NULL); + NULL, pack_fds); if (error != NULL) goto done; + error = got_repo_pack_fds_close(pack_fds); + if (error != NULL) + goto done; + error = apply_unveil(got_repo_get_path(repo), 0, got_worktree_get_root_path(worktree)); if (error) @@ -9245,6 +9463,8 @@ cmd_rebase(int argc, char *argv[]) const struct got_object_id_queue *parent_ids; struct got_object_qid *qid, *pid; struct got_update_progress_arg upa; + int cs = got_repo_get_pack_cache_size(); + int pack_fds[cs]; STAILQ_INIT(&commits); TAILQ_INIT(&merged_paths); @@ -9324,11 +9544,20 @@ cmd_rebase(int argc, char *argv[]) } } + error = got_repo_pack_fds_init(pack_fds); + if (error != NULL) + goto done; + error = got_repo_open(&repo, - worktree ? got_worktree_get_repo_path(worktree) : cwd, NULL); + worktree ? got_worktree_get_repo_path(worktree) : cwd, NULL, + pack_fds); if (error != NULL) goto done; + error = got_repo_pack_fds_close(pack_fds); + if (error != NULL) + goto done; + error = apply_unveil(got_repo_get_path(repo), 0, worktree ? got_worktree_get_root_path(worktree) : NULL); if (error) @@ -10464,6 +10693,8 @@ cmd_histedit(int argc, char *argv[]) struct got_object_qid *pid; struct got_histedit_list histedit_cmds; struct got_histedit_list_entry *hle; + int cs = got_repo_get_pack_cache_size(); + int pack_fds[cs]; STAILQ_INIT(&commits); TAILQ_INIT(&histedit_cmds); @@ -10598,12 +10829,19 @@ cmd_histedit(int argc, char *argv[]) } } + error = got_repo_pack_fds_init(pack_fds); + if (error != NULL) + goto done; + if (list_backups || delete_backups) { error = got_repo_open(&repo, worktree ? got_worktree_get_repo_path(worktree) : cwd, - NULL); + NULL, pack_fds); + error = got_repo_pack_fds_close(pack_fds); if (error != NULL) goto done; + if (error != NULL) + goto done; error = apply_unveil(got_repo_get_path(repo), 0, worktree ? got_worktree_get_root_path(worktree) : NULL); if (error) @@ -10615,10 +10853,14 @@ cmd_histedit(int argc, char *argv[]) } error = got_repo_open(&repo, got_worktree_get_repo_path(worktree), - NULL); + NULL, pack_fds); if (error != NULL) goto done; + error = got_repo_pack_fds_close(pack_fds); + if (error != NULL) + goto done; + error = got_worktree_rebase_in_progress(&rebase_in_progress, worktree); if (error) goto done; @@ -11008,6 +11250,8 @@ cmd_integrate(int argc, char *argv[]) struct got_object_id *commit_id = NULL, *base_commit_id = NULL; int ch; struct got_update_progress_arg upa; + int cs = got_repo_get_pack_cache_size(); + int pack_fds[cs]; while ((ch = getopt(argc, argv, "")) != -1) { switch (ch) { @@ -11046,11 +11290,19 @@ cmd_integrate(int argc, char *argv[]) if (error) goto done; + error = got_repo_pack_fds_init(pack_fds); + if (error != NULL) + goto done; + error = got_repo_open(&repo, got_worktree_get_repo_path(worktree), - NULL); + NULL, pack_fds); if (error != NULL) goto done; + error = got_repo_pack_fds_close(pack_fds); + if (error != NULL) + goto done; + error = apply_unveil(got_repo_get_path(repo), 0, got_worktree_get_root_path(worktree)); if (error) @@ -11159,6 +11411,8 @@ cmd_merge(int argc, char *argv[]) struct got_update_progress_arg upa; struct got_object_id *merge_commit_id = NULL; char *branch_name = NULL; + int cs = got_repo_get_pack_cache_size(); + int pack_fds[cs]; memset(&upa, 0, sizeof(upa)); @@ -11210,11 +11464,20 @@ cmd_merge(int argc, char *argv[]) goto done; } + error = got_repo_pack_fds_init(pack_fds); + if (error != NULL) + goto done; + error = got_repo_open(&repo, - worktree ? got_worktree_get_repo_path(worktree) : cwd, NULL); + worktree ? got_worktree_get_repo_path(worktree) : cwd, NULL, + pack_fds); if (error != NULL) goto done; + error = got_repo_pack_fds_close(pack_fds); + if (error != NULL) + goto done; + error = apply_unveil(got_repo_get_path(repo), 0, worktree ? got_worktree_get_root_path(worktree) : NULL); if (error) @@ -11449,6 +11712,8 @@ cmd_stage(int argc, char *argv[]) FILE *patch_script_file = NULL; const char *patch_script_path = NULL; struct choose_patch_arg cpa; + int cs = got_repo_get_pack_cache_size(); + int pack_fds[cs]; TAILQ_INIT(&paths); @@ -11498,11 +11763,19 @@ cmd_stage(int argc, char *argv[]) goto done; } + error = got_repo_pack_fds_init(pack_fds); + if (error != NULL) + goto done; + error = got_repo_open(&repo, got_worktree_get_repo_path(worktree), - NULL); + NULL, pack_fds); if (error != NULL) goto done; + error = got_repo_pack_fds_close(pack_fds); + if (error != NULL) + goto done; + if (patch_script_path) { patch_script_file = fopen(patch_script_path, "re"); if (patch_script_file == NULL) { @@ -11577,6 +11850,8 @@ cmd_unstage(int argc, char *argv[]) FILE *patch_script_file = NULL; const char *patch_script_path = NULL; struct choose_patch_arg cpa; + int cs = got_repo_get_pack_cache_size(); + int pack_fds[cs]; TAILQ_INIT(&paths); @@ -11618,11 +11893,19 @@ cmd_unstage(int argc, char *argv[]) goto done; } + error = got_repo_pack_fds_init(pack_fds); + if (error != NULL) + goto done; + error = got_repo_open(&repo, got_worktree_get_repo_path(worktree), - NULL); + NULL, pack_fds); if (error != NULL) goto done; + error = got_repo_pack_fds_close(pack_fds); + if (error != NULL) + goto done; + if (patch_script_path) { patch_script_file = fopen(patch_script_path, "re"); if (patch_script_file == NULL) { @@ -11861,6 +12144,8 @@ cmd_cat(int argc, char *argv[]) struct got_commit_object *commit = NULL; int ch, obj_type, i, force_path = 0; struct got_reflist_head refs; + int cs = got_repo_get_pack_cache_size(); + int pack_fds[cs]; TAILQ_INIT(&refs); @@ -11924,11 +12209,19 @@ cmd_cat(int argc, char *argv[]) return got_error_from_errno("strdup"); } - error = got_repo_open(&repo, repo_path, NULL); + error = got_repo_pack_fds_init(pack_fds); + if (error != NULL) + goto done; + + error = got_repo_open(&repo, repo_path, NULL, pack_fds); free(repo_path); if (error != NULL) goto done; + error = got_repo_pack_fds_close(pack_fds); + if (error != NULL) + goto done; + error = apply_unveil(got_repo_get_path(repo), 1, NULL); if (error) goto done; blob - 59c11d1ab01684d8a2f16d934fb1d6870d7ac871 file + gotadmin/gotadmin.c --- gotadmin/gotadmin.c +++ gotadmin/gotadmin.c @@ -275,6 +275,8 @@ cmd_info(int argc, char *argv[]) int ch, npackfiles, npackedobj, nobj; off_t packsize, loose_size; char scaled[FMT_SCALED_STRSIZE]; + int cs = got_repo_get_pack_cache_size(); + int pack_fds[cs]; while ((ch = getopt(argc, argv, "r:")) != -1) { switch (ch) { @@ -304,9 +306,15 @@ cmd_info(int argc, char *argv[]) if (error) goto done; } - error = got_repo_open(&repo, repo_path, NULL); + error = got_repo_pack_fds_init(pack_fds); + if (error != NULL) + goto done; + error = got_repo_open(&repo, repo_path, NULL, pack_fds); if (error) goto done; + error = got_repo_pack_fds_close(pack_fds); + if (error != NULL) + goto done; #ifndef PROFILE /* Remove "cpath" promise. */ if (pledge("stdio rpath wpath flock proc exec sendfd unveil", @@ -629,6 +637,8 @@ cmd_pack(int argc, char *argv[]) struct got_reflist_head exclude_refs; struct got_reflist_head include_refs; struct got_reflist_entry *re, *new; + int cs = got_repo_get_pack_cache_size(); + int pack_fds[cs]; TAILQ_INIT(&exclude_args); TAILQ_INIT(&exclude_refs); @@ -675,9 +685,15 @@ cmd_pack(int argc, char *argv[]) if (error) goto done; } - error = got_repo_open(&repo, repo_path, NULL); + error = got_repo_pack_fds_init(pack_fds); + if (error != NULL) + goto done; + error = got_repo_open(&repo, repo_path, NULL, pack_fds); if (error) goto done; + error = got_repo_pack_fds_close(pack_fds); + if (error != NULL) + goto done; error = apply_unveil(got_repo_get_path_git_dir(repo), 0); if (error) @@ -775,6 +791,8 @@ cmd_indexpack(int argc, char *argv[]) char *id_str = NULL; struct got_pack_progress_arg ppa; FILE *packfile = NULL; + int cs = got_repo_get_pack_cache_size(); + int pack_fds[cs]; while ((ch = getopt(argc, argv, "")) != -1) { switch (ch) { @@ -800,9 +818,15 @@ cmd_indexpack(int argc, char *argv[]) err(1, "pledge"); #endif - error = got_repo_open(&repo, packfile_path, NULL); + error = got_repo_pack_fds_init(pack_fds); + if (error != NULL) + goto done; + error = got_repo_open(&repo, packfile_path, NULL, pack_fds); if (error) goto done; + error = got_repo_pack_fds_close(pack_fds); + if (error != NULL) + goto done; error = apply_unveil(got_repo_get_path_git_dir(repo), 0); if (error) @@ -943,6 +967,8 @@ cmd_listpack(int argc, char *argv[]) struct gotadmin_list_pack_cb_args lpa; FILE *packfile = NULL; int show_stats = 0, human_readable = 0; + int cs = got_repo_get_pack_cache_size(); + int pack_fds[cs]; while ((ch = getopt(argc, argv, "hs")) != -1) { switch (ch) { @@ -972,9 +998,15 @@ cmd_listpack(int argc, char *argv[]) NULL) == -1) err(1, "pledge"); #endif - error = got_repo_open(&repo, packfile_path, NULL); + error = got_repo_pack_fds_init(pack_fds); + if (error != NULL) + goto done; + error = got_repo_open(&repo, packfile_path, NULL, pack_fds); if (error) goto done; + error = got_repo_pack_fds_close(pack_fds); + if (error != NULL) + goto done; #ifndef PROFILE /* Remove "cpath" promise. */ if (pledge("stdio rpath wpath flock proc exec sendfd unveil", @@ -1120,6 +1152,8 @@ cmd_cleanup(int argc, char *argv[]) char scaled_diff[FMT_SCALED_STRSIZE]; char **extensions; int nextensions, i; + int cs = got_repo_get_pack_cache_size(); + int pack_fds[cs]; while ((ch = getopt(argc, argv, "apr:nq")) != -1) { switch (ch) { @@ -1161,9 +1195,15 @@ cmd_cleanup(int argc, char *argv[]) if (error) goto done; } - error = got_repo_open(&repo, repo_path, NULL); + error = got_repo_pack_fds_init(pack_fds); + if (error != NULL) + goto done; + error = got_repo_open(&repo, repo_path, NULL, pack_fds); if (error) goto done; + error = got_repo_pack_fds_close(pack_fds); + if (error != NULL) + goto done; error = apply_unveil(got_repo_get_path_git_dir(repo), 0); if (error) blob - b6e44e8b40b8476a471c53fd10cffd4a7ff3b32d file + include/got_repository.h --- include/got_repository.h +++ include/got_repository.h @@ -20,7 +20,7 @@ struct got_tag_object; /* Open and close repositories. */ const struct got_error *got_repo_open(struct got_repository**, const char *, - const char *); + const char *, int []); const struct got_error *got_repo_close(struct got_repository*); /* Obtain the on-disk path to the repository. */ @@ -177,3 +177,12 @@ const struct got_error *got_repo_get_loose_object_info /* Obtain the number and size of packed objects in the repository. */ const struct got_error *got_repo_get_packfile_info(int *npackfiles, int *nobjects, off_t *total_packsize, struct got_repository *); + +/* Obtain our pack cache size */ +int got_repo_get_pack_cache_size(void); + +/* Create an array of file descriptors to hand over to got_repo_open for pack */ +const struct got_error *got_repo_pack_fds_init(int []); + +/* Close the array of file descriptors handed over to got_repo_open for pack */ +const struct got_error *got_repo_pack_fds_close(int []); blob - 66dce96b54785bf451b150d44880b57fab657b42 file + lib/repository.c --- lib/repository.c +++ lib/repository.c @@ -89,6 +89,12 @@ got_repo_get_fd(struct got_repository *repo) return repo->gitdir_fd; } +int +got_repo_get_pack_cache_size(void) +{ + return GOT_PACK_CACHE_SIZE * 2; +} + const char * got_repo_get_gitconfig_author_name(struct got_repository *repo) { @@ -247,6 +253,39 @@ done: } const struct got_error * +got_repo_pack_fds_init(int pack_fds[]) +{ + const struct got_error *err = NULL; + size_t cs = got_repo_get_pack_cache_size(); + int i; + + for (i = 0; i < cs; i++) { + pack_fds[i] = got_opentempfd(); + if (pack_fds[i] == -1) { + err = got_error_from_errno("got_opentempfd"); + break; + } + } + return err; +} + +const struct got_error * +got_repo_pack_fds_close(int pack_fds[]) +{ + const struct got_error *err = NULL; + size_t cs = got_repo_get_pack_cache_size(); + int i; + + for (i = 0; i < cs; i++) { + if (close(pack_fds[i]) == -1) { + err = got_error_from_errno("close"); + break; + } + } + return err; +} + +const struct got_error * got_repo_cache_object(struct got_repository *repo, struct got_object_id *id, struct got_object *obj) { @@ -651,12 +690,12 @@ static const char *const repo_extensions[] = { const struct got_error * got_repo_open(struct got_repository **repop, const char *path, - const char *global_gitconfig_path) + const char *global_gitconfig_path, int pack_fds[]) { struct got_repository *repo = NULL; const struct got_error *err = NULL; char *repo_path = NULL; - size_t i; + size_t i, j = 0; struct rlimit rl; *repop = NULL; @@ -703,12 +742,12 @@ got_repo_open(struct got_repository **repop, const cha repo->pack_cache_size = rl.rlim_cur / 8; for (i = 0; i < nitems(repo->packs); i++) { if (i < repo->pack_cache_size) { - repo->packs[i].basefd = got_opentempfd(); + repo->packs[i].basefd = dup(pack_fds[j++]); if (repo->packs[i].basefd == -1) - return got_error_from_errno("got_opentempfd"); - repo->packs[i].accumfd = got_opentempfd(); + return got_error_from_errno("dup"); + repo->packs[i].accumfd = dup(pack_fds[j++]); if (repo->packs[i].accumfd == -1) - return got_error_from_errno("got_opentempfd"); + return got_error_from_errno("dup"); } else { repo->packs[i].basefd = -1; repo->packs[i].accumfd = -1; @@ -796,21 +835,6 @@ got_repo_close(struct got_repository *repo) free(bf); } - for (i = 0; i < repo->pack_cache_size; i++) { - if (repo->packs[i].path_packfile) - got_pack_close(&repo->packs[i]); - if (repo->packs[i].basefd != -1) { - if (close(repo->packs[i].basefd) == -1 && err == NULL) - err = got_error_from_errno("close"); - repo->packs[i].basefd = -1; - } - if (repo->packs[i].accumfd != -1) { - if (close(repo->packs[i].accumfd) == -1 && err == NULL) - err = got_error_from_errno("close"); - repo->packs[i].accumfd = -1; - } - } - free(repo->path); free(repo->path_git_dir); blob - 673cbeb89c705904097774881d38ef9d51751939 file + lib/worktree_open.c --- lib/worktree_open.c +++ lib/worktree_open.c @@ -117,6 +117,8 @@ open_worktree(struct got_worktree **worktree, const ch const char *errstr; struct got_repository *repo = NULL; uint32_t uuid_status; + int cs = got_repo_get_pack_cache_size(); + int pack_fds[cs]; *worktree = NULL; @@ -190,10 +192,18 @@ open_worktree(struct got_worktree **worktree, const ch goto done; } - err = got_repo_open(&repo, (*worktree)->repo_path, NULL); + err = got_repo_pack_fds_init(pack_fds); + if (err != NULL) + goto done; + + err = got_repo_open(&repo, (*worktree)->repo_path, NULL, pack_fds); if (err) goto done; + err = got_repo_pack_fds_close(pack_fds); + if (err != NULL) + goto done; + err = got_object_resolve_id_str(&(*worktree)->base_commit_id, repo, base_commit_id_str); if (err) blob - 0b71fb34c2bb552a0ccbb6848d023911e8d34c72 file + tog/tog.c --- tog/tog.c +++ tog/tog.c @@ -2317,6 +2317,8 @@ open_log_view(struct tog_view *view, struct got_object struct got_repository *thread_repo = NULL; struct got_commit_graph *thread_graph = NULL; int errcode; + int cs = got_repo_get_pack_cache_size(); + int pack_fds[cs]; if (in_repo_path != s->in_repo_path) { free(s->in_repo_path); @@ -2370,9 +2372,16 @@ open_log_view(struct tog_view *view, struct got_object view->search_start = search_start_log_view; view->search_next = search_next_log_view; - err = got_repo_open(&thread_repo, got_repo_get_path(repo), NULL); + err = got_repo_pack_fds_init(pack_fds); if (err) goto done; + err = got_repo_open(&thread_repo, got_repo_get_path(repo), NULL, + pack_fds); + if (err) + goto done; + err = got_repo_pack_fds_close(pack_fds); + if (err) + goto done; err = got_commit_graph_open(&thread_graph, s->in_repo_path, !s->log_branches); if (err) @@ -2442,6 +2451,8 @@ input_log_view(struct tog_view **new_view, struct tog_ struct tog_view *ref_view = NULL; struct commit_queue_entry *entry; int begin_x = 0, n; + int cs = got_repo_get_pack_cache_size(); + int pack_fds[cs]; if (s->thread_args.load_all) { if (ch == KEY_BACKSPACE) @@ -2634,10 +2645,16 @@ input_log_view(struct tog_view **new_view, struct tog_ } else /* 'B' */ s->log_branches = !s->log_branches; + err = got_repo_pack_fds_init(pack_fds); + if (err) + return err; err = got_repo_open(&s->thread_args.repo, - got_repo_get_path(s->repo), NULL); + got_repo_get_path(s->repo), NULL, pack_fds); if (err) return err; + err = got_repo_pack_fds_close(pack_fds); + if (err) + return err; tog_free_refs(); err = tog_load_refs(s->repo, 0); if (err) @@ -2791,6 +2808,8 @@ cmd_log(int argc, char *argv[]) const char *head_ref_name = NULL; int ch, log_branches = 0; struct tog_view *view; + int cs = got_repo_get_pack_cache_size(); + int pack_fds[cs]; while ((ch = getopt(argc, argv, "bc:r:")) != -1) { switch (ch) { @@ -2836,9 +2855,15 @@ cmd_log(int argc, char *argv[]) } } - error = got_repo_open(&repo, repo_path, NULL); + error = got_repo_pack_fds_init(pack_fds); if (error != NULL) goto done; + error = got_repo_open(&repo, repo_path, NULL, pack_fds); + if (error != NULL) + goto done; + error = got_repo_pack_fds_close(pack_fds); + if (error != NULL) + goto done; error = get_in_repo_path_from_argv0(&in_repo_path, argc, argv, repo, worktree); @@ -3909,6 +3934,8 @@ cmd_diff(int argc, char *argv[]) int ch, force_text_diff = 0; const char *errstr; struct tog_view *view; + int cs = got_repo_get_pack_cache_size(); + int pack_fds[cs]; while ((ch = getopt(argc, argv, "aC:r:w")) != -1) { switch (ch) { @@ -3967,9 +3994,15 @@ cmd_diff(int argc, char *argv[]) } } - error = got_repo_open(&repo, repo_path, NULL); + error = got_repo_pack_fds_init(pack_fds); if (error) goto done; + error = got_repo_open(&repo, repo_path, NULL, pack_fds); + if (error) + goto done; + error = got_repo_pack_fds_close(pack_fds); + if (error) + goto done; init_curses(); @@ -4370,6 +4403,8 @@ run_blame(struct tog_view *view) struct got_repository *thread_repo = NULL; struct got_object_id *obj_id = NULL; int obj_type; + int cs = got_repo_get_pack_cache_size(); + int pack_fds[cs]; err = got_object_open_as_commit(&commit, s->repo, &s->blamed_commit->id); @@ -4416,9 +4451,16 @@ run_blame(struct tog_view *view) goto done; } - err = got_repo_open(&thread_repo, got_repo_get_path(s->repo), NULL); + err = got_repo_pack_fds_init(pack_fds); if (err) goto done; + err = got_repo_open(&thread_repo, got_repo_get_path(s->repo), NULL, + pack_fds); + if (err) + goto done; + err = got_repo_pack_fds_close(pack_fds); + if (err) + goto done; blame->cb_args.view = view; blame->cb_args.lines = blame->lines; @@ -4859,6 +4901,8 @@ cmd_blame(int argc, char *argv[]) char *commit_id_str = NULL; int ch; struct tog_view *view; + int cs = got_repo_get_pack_cache_size(); + int pack_fds[cs]; while ((ch = getopt(argc, argv, "c:r:")) != -1) { switch (ch) { @@ -4901,9 +4945,15 @@ cmd_blame(int argc, char *argv[]) } } - error = got_repo_open(&repo, repo_path, NULL); + error = got_repo_pack_fds_init(pack_fds); if (error != NULL) goto done; + error = got_repo_open(&repo, repo_path, NULL, pack_fds); + if (error != NULL) + goto done; + error = got_repo_pack_fds_close(pack_fds); + if (error != NULL) + goto done; error = get_in_repo_path_from_argv0(&in_repo_path, argc, argv, repo, worktree); @@ -5721,6 +5771,8 @@ cmd_tree(int argc, char *argv[]) const char *head_ref_name = NULL; int ch; struct tog_view *view; + int cs = got_repo_get_pack_cache_size(); + int pack_fds[cs]; while ((ch = getopt(argc, argv, "c:r:")) != -1) { switch (ch) { @@ -5763,9 +5815,15 @@ cmd_tree(int argc, char *argv[]) } } - error = got_repo_open(&repo, repo_path, NULL); + error = got_repo_pack_fds_init(pack_fds); if (error != NULL) goto done; + error = got_repo_open(&repo, repo_path, NULL, pack_fds); + if (error != NULL) + goto done; + error = got_repo_pack_fds_close(pack_fds); + if (error != NULL) + goto done; error = get_in_repo_path_from_argv0(&in_repo_path, argc, argv, repo, worktree); @@ -6474,6 +6532,8 @@ cmd_ref(int argc, char *argv[]) char *cwd = NULL, *repo_path = NULL; int ch; struct tog_view *view; + int cs = got_repo_get_pack_cache_size(); + int pack_fds[cs]; while ((ch = getopt(argc, argv, "r:")) != -1) { switch (ch) { @@ -6513,9 +6573,15 @@ cmd_ref(int argc, char *argv[]) } } - error = got_repo_open(&repo, repo_path, NULL); + error = got_repo_pack_fds_init(pack_fds); if (error != NULL) goto done; + error = got_repo_open(&repo, repo_path, NULL, pack_fds); + if (error != NULL) + goto done; + error = got_repo_pack_fds_close(pack_fds); + if (error != NULL) + goto done; init_curses(); @@ -6622,6 +6688,8 @@ tog_log_with_path(int argc, char *argv[]) struct got_commit_object *commit = NULL; char *cwd = NULL, *repo_path = NULL, *in_repo_path = NULL; char *commit_id_str = NULL, **cmd_argv = NULL; + int cs = got_repo_get_pack_cache_size(); + int pack_fds[cs]; cwd = getcwd(NULL, 0); if (cwd == NULL) @@ -6640,9 +6708,15 @@ tog_log_with_path(int argc, char *argv[]) goto done; } - error = got_repo_open(&repo, repo_path, NULL); + error = got_repo_pack_fds_init(pack_fds); if (error != NULL) goto done; + error = got_repo_open(&repo, repo_path, NULL, pack_fds); + if (error != NULL) + goto done; + error = got_repo_pack_fds_close(pack_fds); + if (error != NULL) + goto done; error = get_in_repo_path_from_argv0(&in_repo_path, argc, argv, repo, worktree);