Commit Diff


commit - 04cdf6acc3e2bb972d4948a12406ab5d348d4760
commit + 7cd528337bab10d64ef73bb1a6e40c6203539e4d
blob - 37e87e60ed84e21e9d89ec1ffcd25be3693afafd
blob + 60476351c5599bd9549cccf48000ca54c8e8964e
--- got/got.c
+++ got/got.c
@@ -714,6 +714,7 @@ cmd_import(int argc, char *argv[])
 	struct got_pathlist_head ignores;
 	struct got_pathlist_entry *pe;
 	int preserve_logmsg = 0;
+	int *pack_fds = NULL;
 
 	TAILQ_INIT(&ignores);
 
@@ -772,7 +773,10 @@ 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_open(&pack_fds);
+	if (error != NULL)
+		goto done;
+	error = got_repo_open(&repo, repo_path, gitconfig_path, pack_fds);
 	if (error)
 		goto done;
 
@@ -899,6 +903,12 @@ cmd_import(int argc, char *argv[])
 	printf("Created branch %s with commit %s\n",
 	    got_ref_get_name(branch_ref), id_str);
 done:
+	if (pack_fds) {
+		const struct got_error *pack_err =
+		    got_repo_pack_fds_close(pack_fds);
+		if (error == NULL)
+			error = pack_err;
+	}
 	if (preserve_logmsg) {
 		fprintf(stderr, "%s: log message preserved in %s\n",
 		    getprogname(), logmsg_path);
@@ -1483,6 +1493,7 @@ 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 *pack_fds = NULL;
 
 	TAILQ_INIT(&refs);
 	TAILQ_INIT(&symrefs);
@@ -1627,7 +1638,10 @@ 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_open(&pack_fds);
+		if (error != NULL)
+			goto done;
+		error = got_repo_open(&repo, repo_path, NULL, pack_fds);
 		if (error)
 			goto done;
 	}
@@ -1805,6 +1819,12 @@ cmd_clone(int argc, char *argv[])
 		printf("Created %s repository '%s'\n",
 		    mirror_references ? "mirrored" : "cloned", repo_path);
 done:
+	if (pack_fds) {
+		const struct got_error *pack_err =
+		    got_repo_pack_fds_close(pack_fds);
+		if (error == NULL)
+			error = pack_err;
+	}
 	if (fetchpid > 0) {
 		if (kill(fetchpid, SIGTERM) == -1)
 			error = got_error_from_errno("kill");
@@ -2211,6 +2231,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, delete_remote = 0;
+	int *pack_fds = NULL;
 
 	TAILQ_INIT(&refs);
 	TAILQ_INIT(&symrefs);
@@ -2310,6 +2331,10 @@ cmd_fetch(int argc, char *argv[])
 		goto done;
 	}
 
+	error = got_repo_pack_fds_open(&pack_fds);
+	if (error != NULL)
+		goto done;
+
 	if (repo_path == NULL) {
 		error = got_worktree_open(&worktree, cwd);
 		if (error && error->code != GOT_ERR_NOT_WORKTREE)
@@ -2332,7 +2357,7 @@ cmd_fetch(int argc, char *argv[])
 		}
 	}
 
-	error = got_repo_open(&repo, repo_path, NULL);
+	error = got_repo_open(&repo, repo_path, NULL, pack_fds);
 	if (error)
 		goto done;
 
@@ -2620,6 +2645,12 @@ done:
 	}
 	if (worktree)
 		got_worktree_close(worktree);
+	if (pack_fds) {
+		const struct got_error *pack_err =
+		    got_repo_pack_fds_close(pack_fds);
+		if (error == NULL)
+			error = pack_err;
+	}
 	TAILQ_FOREACH(pe, &refs, entry) {
 		free((void *)pe->path);
 		free(pe->data);
@@ -2847,6 +2878,7 @@ 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 *pack_fds = NULL;
 
 	TAILQ_INIT(&paths);
 
@@ -2935,10 +2967,14 @@ 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_open(&pack_fds);
 	if (error != NULL)
 		goto done;
 
+	error = got_repo_open(&repo, repo_path, NULL, pack_fds);
+	if (error != NULL)
+		goto done;
+
 	/* Pre-create work tree path for unveil(2) */
 	error = got_path_mkdir(worktree_path);
 	if (error) {
@@ -3051,6 +3087,12 @@ cmd_checkout(int argc, char *argv[])
 	if (cpa.had_base_commit_ref_error)
 		show_worktree_base_ref_warning();
 done:
+	if (pack_fds) {
+		const struct got_error *pack_err =
+		    got_repo_pack_fds_close(pack_fds);
+		if (error == NULL)
+			error = pack_err;
+	}
 	if (head_ref)
 		got_ref_close(head_ref);
 	if (ref)
@@ -3280,8 +3322,13 @@ wrap_not_worktree_error(const struct got_error *orig_e
 	const struct got_error *err;
 	struct got_repository *repo;
 	static char msg[512];
+	int *pack_fds = NULL;
+
+	err = got_repo_pack_fds_open(&pack_fds);
+	if (err)
+		return err;
 
-	err = got_repo_open(&repo, path, NULL);
+	err = got_repo_open(&repo, path, NULL, pack_fds);
 	if (err)
 		return orig_err;
 
@@ -3292,6 +3339,12 @@ wrap_not_worktree_error(const struct got_error *orig_e
 	    "The got(1) manual page contains more information.", cmdname);
 	err = got_error_msg(GOT_ERR_NOT_WORKTREE, msg);
 	got_repo_close(repo);
+	if (pack_fds) {
+		const struct got_error *pack_err =
+		    got_repo_pack_fds_close(pack_fds);
+		if (err == NULL)
+			err = pack_err;
+	}
 	return err;
 }
 
@@ -3310,6 +3363,7 @@ cmd_update(int argc, char *argv[])
 	struct got_pathlist_entry *pe;
 	int ch, verbosity = 0;
 	struct got_update_progress_arg upa;
+	int *pack_fds = NULL;
 
 	TAILQ_INIT(&paths);
 
@@ -3345,6 +3399,11 @@ cmd_update(int argc, char *argv[])
 		error = got_error_from_errno("getcwd");
 		goto done;
 	}
+
+	error = got_repo_pack_fds_open(&pack_fds);
+	if (error != NULL)
+		goto done;
+
 	error = got_worktree_open(&worktree, worktree_path);
 	if (error) {
 		if (error->code == GOT_ERR_NOT_WORKTREE)
@@ -3358,7 +3417,7 @@ cmd_update(int argc, char *argv[])
 		goto done;
 
 	error = got_repo_open(&repo, got_worktree_get_repo_path(worktree),
-	    NULL);
+	    NULL, pack_fds);
 	if (error != NULL)
 		goto done;
 
@@ -3462,8 +3521,15 @@ cmd_update(int argc, char *argv[])
 		    got_worktree_get_head_ref_name(worktree), commit_id_str);
 	} else
 		printf("Already up-to-date\n");
+
 	print_update_progress_stats(&upa);
 done:
+	if (pack_fds) {
+		const struct got_error *pack_err =
+		    got_repo_pack_fds_close(pack_fds);
+		if (error == NULL)
+			error = pack_err;
+	}
 	free(worktree_path);
 	TAILQ_FOREACH(pe, &paths, entry)
 		free((char *)pe->path);
@@ -4249,6 +4315,7 @@ cmd_log(int argc, char *argv[])
 	struct got_reflist_head refs;
 	struct got_reflist_object_id_map *refs_idmap = NULL;
 	FILE *tmpfile = NULL;
+	int *pack_fds = NULL;
 
 	TAILQ_INIT(&refs);
 
@@ -4329,6 +4396,10 @@ cmd_log(int argc, char *argv[])
 		error = got_error_from_errno("getcwd");
 		goto done;
 	}
+
+	error = got_repo_pack_fds_open(&pack_fds);
+	if (error != NULL)
+		goto done;
 
 	if (repo_path == NULL) {
 		error = got_worktree_open(&worktree, cwd);
@@ -4362,7 +4433,7 @@ cmd_log(int argc, char *argv[])
 		goto done;
 	}
 
-	error = got_repo_open(&repo, repo_path, NULL);
+	error = got_repo_open(&repo, repo_path, NULL, pack_fds);
 	if (error != NULL)
 		goto done;
 
@@ -4462,6 +4533,12 @@ done:
 		const struct got_error *close_err = got_repo_close(repo);
 		if (error == NULL)
 			error = close_err;
+	}
+	if (pack_fds) {
+		const struct got_error *pack_err =
+		    got_repo_pack_fds_close(pack_fds);
+		if (error == NULL)
+			error = pack_err;
 	}
 	if (refs_idmap)
 		got_reflist_object_id_map_free(refs_idmap);
@@ -4725,6 +4802,7 @@ cmd_diff(int argc, char *argv[])
 	struct got_pathlist_head paths;
 	struct got_pathlist_entry *pe;
 	FILE *f1 = NULL, *f2 = NULL;
+	int *pack_fds = NULL;
 
 	TAILQ_INIT(&refs);
 	TAILQ_INIT(&paths);
@@ -4784,6 +4862,10 @@ cmd_diff(int argc, char *argv[])
 		goto done;
 	}
 
+	error = got_repo_pack_fds_open(&pack_fds);
+	if (error != NULL)
+		goto done;
+
 	if (repo_path == NULL) {
 		error = got_worktree_open(&worktree, cwd);
 		if (error && error->code != GOT_ERR_NOT_WORKTREE)
@@ -4806,7 +4888,7 @@ cmd_diff(int argc, char *argv[])
 		}
 	}
 
-	error = got_repo_open(&repo, repo_path, NULL);
+	error = got_repo_open(&repo, repo_path, NULL, pack_fds);
 	free(repo_path);
 	if (error != NULL)
 		goto done;
@@ -5060,6 +5142,12 @@ done:
 		const struct got_error *close_err = got_repo_close(repo);
 		if (error == NULL)
 			error = close_err;
+	}
+	if (pack_fds) {
+		const struct got_error *pack_err =
+		    got_repo_pack_fds_close(pack_fds);
+		if (error == NULL)
+			error = pack_err;
 	}
 	TAILQ_FOREACH(pe, &paths, entry)
 		free((char *)pe->path);
@@ -5207,6 +5295,7 @@ cmd_blame(int argc, char *argv[])
 	struct blame_cb_args bca;
 	int ch, obj_type, i;
 	off_t filesize;
+	int *pack_fds = NULL;
 
 	memset(&bca, 0, sizeof(bca));
 
@@ -5247,6 +5336,11 @@ cmd_blame(int argc, char *argv[])
 		error = got_error_from_errno("getcwd");
 		goto done;
 	}
+
+	error = got_repo_pack_fds_open(&pack_fds);
+	if (error != NULL)
+		goto done;
+
 	if (repo_path == NULL) {
 		error = got_worktree_open(&worktree, cwd);
 		if (error && error->code != GOT_ERR_NOT_WORKTREE)
@@ -5270,7 +5364,7 @@ cmd_blame(int argc, char *argv[])
 		}
 	}
 
-	error = got_repo_open(&repo, repo_path, NULL);
+	error = got_repo_open(&repo, repo_path, NULL, pack_fds);
 	if (error != NULL)
 		goto done;
 
@@ -5404,6 +5498,12 @@ done:
 		if (error == NULL)
 			error = close_err;
 	}
+	if (pack_fds) {
+		const struct got_error *pack_err =
+		    got_repo_pack_fds_close(pack_fds);
+		if (error == NULL)
+			error = pack_err;
+	}
 	if (bca.lines) {
 		for (i = 0; i < bca.nlines; i++) {
 			struct blame_line *bline = &bca.lines[i];
@@ -5548,6 +5648,7 @@ cmd_tree(int argc, char *argv[])
 	char *commit_id_str = NULL;
 	int show_ids = 0, recurse = 0;
 	int ch;
+	int *pack_fds = NULL;
 
 #ifndef PROFILE
 	if (pledge("stdio rpath wpath cpath flock proc exec sendfd unveil",
@@ -5594,6 +5695,11 @@ cmd_tree(int argc, char *argv[])
 		error = got_error_from_errno("getcwd");
 		goto done;
 	}
+
+	error = got_repo_pack_fds_open(&pack_fds);
+	if (error != NULL)
+		goto done;
+
 	if (repo_path == NULL) {
 		error = got_worktree_open(&worktree, cwd);
 		if (error && error->code != GOT_ERR_NOT_WORKTREE)
@@ -5616,7 +5722,7 @@ cmd_tree(int argc, char *argv[])
 		}
 	}
 
-	error = got_repo_open(&repo, repo_path, NULL);
+	error = got_repo_open(&repo, repo_path, NULL, pack_fds);
 	if (error != NULL)
 		goto done;
 
@@ -5703,6 +5809,12 @@ done:
 		const struct got_error *close_err = got_repo_close(repo);
 		if (error == NULL)
 			error = close_err;
+	}
+	if (pack_fds) {
+		const struct got_error *pack_err =
+		    got_repo_pack_fds_close(pack_fds);
+		if (error == NULL)
+			error = pack_err;
 	}
 	return error;
 }
@@ -5770,6 +5882,7 @@ cmd_status(int argc, char *argv[])
 	struct got_pathlist_head paths;
 	struct got_pathlist_entry *pe;
 	int ch, i, no_ignores = 0;
+	int *pack_fds = NULL;
 
 	TAILQ_INIT(&paths);
 
@@ -5829,6 +5942,10 @@ cmd_status(int argc, char *argv[])
 		goto done;
 	}
 
+	error = got_repo_pack_fds_open(&pack_fds);
+	if (error != NULL)
+		goto done;
+
 	error = got_worktree_open(&worktree, cwd);
 	if (error) {
 		if (error->code == GOT_ERR_NOT_WORKTREE)
@@ -5837,7 +5954,7 @@ cmd_status(int argc, char *argv[])
 	}
 
 	error = got_repo_open(&repo, got_worktree_get_repo_path(worktree),
-	    NULL);
+	    NULL, pack_fds);
 	if (error != NULL)
 		goto done;
 
@@ -5853,6 +5970,13 @@ cmd_status(int argc, char *argv[])
 	error = got_worktree_status(worktree, &paths, repo, no_ignores,
 	    print_status, &st, check_cancelled, NULL);
 done:
+	if (pack_fds) {
+		const struct got_error *pack_err =
+		    got_repo_pack_fds_close(pack_fds);
+		if (error == NULL)
+			error = pack_err;
+	}
+
 	TAILQ_FOREACH(pe, &paths, entry)
 		free((char *)pe->path);
 	got_pathlist_free(&paths);
@@ -5994,6 +6118,7 @@ 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 *pack_fds = NULL;
 
 	while ((ch = getopt(argc, argv, "c:dr:ls:t")) != -1) {
 		switch (ch) {
@@ -6077,6 +6202,10 @@ cmd_ref(int argc, char *argv[])
 		goto done;
 	}
 
+	error = got_repo_pack_fds_open(&pack_fds);
+	if (error != NULL)
+		goto done;
+
 	if (repo_path == NULL) {
 		error = got_worktree_open(&worktree, cwd);
 		if (error && error->code != GOT_ERR_NOT_WORKTREE)
@@ -6099,7 +6228,7 @@ cmd_ref(int argc, char *argv[])
 		}
 	}
 
-	error = got_repo_open(&repo, repo_path, NULL);
+	error = got_repo_open(&repo, repo_path, NULL, pack_fds);
 	if (error != NULL)
 		goto done;
 
@@ -6137,6 +6266,12 @@ done:
 	}
 	if (worktree)
 		got_worktree_close(worktree);
+	if (pack_fds) {
+		const struct got_error *pack_err =
+		    got_repo_pack_fds_close(pack_fds);
+		if (error == NULL)
+			error = pack_err;
+	}
 	free(cwd);
 	free(repo_path);
 	return error;
@@ -6384,6 +6519,7 @@ cmd_branch(int argc, char *argv[])
 	struct got_pathlist_entry *pe;
 	struct got_object_id *commit_id = NULL;
 	char *commit_id_str = NULL;
+	int *pack_fds = NULL;
 
 	TAILQ_INIT(&paths);
 
@@ -6448,6 +6584,10 @@ cmd_branch(int argc, char *argv[])
 		goto done;
 	}
 
+	error = got_repo_pack_fds_open(&pack_fds);
+	if (error != NULL)
+		goto done;
+
 	if (repo_path == NULL) {
 		error = got_worktree_open(&worktree, cwd);
 		if (error && error->code != GOT_ERR_NOT_WORKTREE)
@@ -6470,7 +6610,7 @@ cmd_branch(int argc, char *argv[])
 		}
 	}
 
-	error = got_repo_open(&repo, repo_path, NULL);
+	error = got_repo_open(&repo, repo_path, NULL, pack_fds);
 	if (error != NULL)
 		goto done;
 
@@ -6565,6 +6705,12 @@ done:
 	}
 	if (worktree)
 		got_worktree_close(worktree);
+	if (pack_fds) {
+		const struct got_error *pack_err =
+		    got_repo_pack_fds_close(pack_fds);
+		if (error == NULL)
+			error = pack_err;
+	}
 	free(cwd);
 	free(repo_path);
 	free(commit_id);
@@ -6942,6 +7088,7 @@ 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 *pack_fds = NULL;
 
 	while ((ch = getopt(argc, argv, "c:m:r:l")) != -1) {
 		switch (ch) {
@@ -6994,6 +7141,10 @@ cmd_tag(int argc, char *argv[])
 		goto done;
 	}
 
+	error = got_repo_pack_fds_open(&pack_fds);
+	if (error != NULL)
+		goto done;
+
 	if (repo_path == NULL) {
 		error = got_worktree_open(&worktree, cwd);
 		if (error && error->code != GOT_ERR_NOT_WORKTREE)
@@ -7022,9 +7173,10 @@ cmd_tag(int argc, char *argv[])
 			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
 		/* Remove "cpath" promise. */
 		if (pledge("stdio rpath wpath flock proc exec sendfd unveil",
@@ -7039,7 +7191,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;
 
@@ -7087,6 +7240,12 @@ done:
 	}
 	if (worktree)
 		got_worktree_close(worktree);
+	if (pack_fds) {
+		const struct got_error *pack_err =
+		    got_repo_pack_fds_close(pack_fds);
+		if (error == NULL)
+			error = pack_err;
+	}
 	free(cwd);
 	free(repo_path);
 	free(gitconfig_path);
@@ -7122,6 +7281,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 *pack_fds = NULL;
 
 	TAILQ_INIT(&paths);
 
@@ -7156,6 +7316,10 @@ cmd_add(int argc, char *argv[])
 		goto done;
 	}
 
+	error = got_repo_pack_fds_open(&pack_fds);
+	if (error != NULL)
+		goto done;
+
 	error = got_worktree_open(&worktree, cwd);
 	if (error) {
 		if (error->code == GOT_ERR_NOT_WORKTREE)
@@ -7164,7 +7328,7 @@ cmd_add(int argc, char *argv[])
 	}
 
 	error = got_repo_open(&repo, got_worktree_get_repo_path(worktree),
-	    NULL);
+	    NULL, pack_fds);
 	if (error != NULL)
 		goto done;
 
@@ -7216,6 +7380,12 @@ done:
 	}
 	if (worktree)
 		got_worktree_close(worktree);
+	if (pack_fds) {
+		const struct got_error *pack_err =
+		    got_repo_pack_fds_close(pack_fds);
+		if (error == NULL)
+			error = pack_err;
+	}
 	TAILQ_FOREACH(pe, &paths, entry)
 		free((char *)pe->path);
 	got_pathlist_free(&paths);
@@ -7257,6 +7427,7 @@ 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 *pack_fds = NULL;
 
 	TAILQ_INIT(&paths);
 
@@ -7310,6 +7481,11 @@ cmd_remove(int argc, char *argv[])
 		error = got_error_from_errno("getcwd");
 		goto done;
 	}
+
+	error = got_repo_pack_fds_open(&pack_fds);
+	if (error != NULL)
+		goto done;
+
 	error = got_worktree_open(&worktree, cwd);
 	if (error) {
 		if (error->code == GOT_ERR_NOT_WORKTREE)
@@ -7318,7 +7494,7 @@ cmd_remove(int argc, char *argv[])
 	}
 
 	error = got_repo_open(&repo, got_worktree_get_repo_path(worktree),
-	    NULL);
+	    NULL, pack_fds);
 	if (error)
 		goto done;
 
@@ -7371,6 +7547,12 @@ done:
 	}
 	if (worktree)
 		got_worktree_close(worktree);
+	if (pack_fds) {
+		const struct got_error *pack_err =
+		    got_repo_pack_fds_close(pack_fds);
+		if (error == NULL)
+			error = pack_err;
+	}
 	TAILQ_FOREACH(pe, &paths, entry)
 		free((char *)pe->path);
 	got_pathlist_free(&paths);
@@ -7473,6 +7655,7 @@ cmd_patch(int argc, char *argv[])
 	char *cwd = NULL;
 	int ch, nop = 0, strip = -1, reverse = 0;
 	int patchfd;
+	int *pack_fds = NULL;
 
 	while ((ch = getopt(argc, argv, "np:R")) != -1) {
 		switch (ch) {
@@ -7515,12 +7698,16 @@ cmd_patch(int argc, char *argv[])
 		goto done;
 	}
 
+	error = got_repo_pack_fds_open(&pack_fds);
+	if (error != NULL)
+		goto done;
+
 	error = got_worktree_open(&worktree, cwd);
 	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;
 
@@ -7549,6 +7736,12 @@ done:
 		if (error == NULL)
 			error = close_error;
 	}
+	if (pack_fds) {
+		const struct got_error *pack_err =
+		    got_repo_pack_fds_close(pack_fds);
+		if (error == NULL)
+			error = pack_err;
+	}
 	free(cwd);
 	return error;
 }
@@ -7703,6 +7896,7 @@ cmd_revert(int argc, char *argv[])
 	FILE *patch_script_file = NULL;
 	const char *patch_script_path = NULL;
 	struct choose_patch_arg cpa;
+	int *pack_fds = NULL;
 
 	TAILQ_INIT(&paths);
 
@@ -7741,6 +7935,11 @@ cmd_revert(int argc, char *argv[])
 		error = got_error_from_errno("getcwd");
 		goto done;
 	}
+
+	error = got_repo_pack_fds_open(&pack_fds);
+	if (error != NULL)
+		goto done;
+
 	error = got_worktree_open(&worktree, cwd);
 	if (error) {
 		if (error->code == GOT_ERR_NOT_WORKTREE)
@@ -7749,7 +7948,7 @@ cmd_revert(int argc, char *argv[])
 	}
 
 	error = got_repo_open(&repo, got_worktree_get_repo_path(worktree),
-	    NULL);
+	    NULL, pack_fds);
 	if (error != NULL)
 		goto done;
 
@@ -7814,6 +8013,12 @@ done:
 	}
 	if (worktree)
 		got_worktree_close(worktree);
+	if (pack_fds) {
+		const struct got_error *pack_err =
+		    got_repo_pack_fds_close(pack_fds);
+		if (error == NULL)
+			error = pack_err;
+	}
 	free(path);
 	free(cwd);
 	return error;
@@ -7987,6 +8192,7 @@ 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 *pack_fds = NULL;
 
 	TAILQ_INIT(&paths);
 	cl_arg.logmsg_path = NULL;
@@ -8031,6 +8237,11 @@ cmd_commit(int argc, char *argv[])
 		error = got_error_from_errno("getcwd");
 		goto done;
 	}
+
+	error = got_repo_pack_fds_open(&pack_fds);
+	if (error != NULL)
+		goto done;
+
 	error = got_worktree_open(&worktree, cwd);
 	if (error) {
 		if (error->code == GOT_ERR_NOT_WORKTREE)
@@ -8055,7 +8266,7 @@ cmd_commit(int argc, char *argv[])
 	if (error)
 		goto done;
 	error = got_repo_open(&repo, got_worktree_get_repo_path(worktree),
-	    gitconfig_path);
+	    gitconfig_path, pack_fds);
 	if (error != NULL)
 		goto done;
 
@@ -8130,6 +8341,12 @@ done:
 	}
 	if (worktree)
 		got_worktree_close(worktree);
+	if (pack_fds) {
+		const struct got_error *pack_err =
+		    got_repo_pack_fds_close(pack_fds);
+		if (error == NULL)
+			error = pack_err;
+	}
 	free(cwd);
 	free(id_str);
 	free(gitconfig_path);
@@ -8366,6 +8583,7 @@ 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 *pack_fds = NULL;
 
 	TAILQ_INIT(&branches);
 	TAILQ_INIT(&tags);
@@ -8444,6 +8662,10 @@ cmd_send(int argc, char *argv[])
 		error = got_error_from_errno("getcwd");
 		goto done;
 	}
+
+	error = got_repo_pack_fds_open(&pack_fds);
+	if (error != NULL)
+		goto done;
 
 	if (repo_path == NULL) {
 		error = got_worktree_open(&worktree, cwd);
@@ -8467,7 +8689,7 @@ cmd_send(int argc, char *argv[])
 		}
 	}
 
-	error = got_repo_open(&repo, repo_path, NULL);
+	error = got_repo_open(&repo, repo_path, NULL, pack_fds);
 	if (error)
 		goto done;
 
@@ -8673,6 +8895,12 @@ done:
 	}
 	if (worktree)
 		got_worktree_close(worktree);
+	if (pack_fds) {
+		const struct got_error *pack_err =
+		    got_repo_pack_fds_close(pack_fds);
+		if (error == NULL)
+			error = pack_err;
+	}
 	if (ref)
 		got_ref_close(ref);
 	got_pathlist_free(&branches);
@@ -8712,6 +8940,7 @@ cmd_cherrypick(int argc, char *argv[])
 	struct got_object_qid *pid;
 	int ch;
 	struct got_update_progress_arg upa;
+	int *pack_fds = NULL;
 
 	while ((ch = getopt(argc, argv, "")) != -1) {
 		switch (ch) {
@@ -8737,6 +8966,11 @@ cmd_cherrypick(int argc, char *argv[])
 		error = got_error_from_errno("getcwd");
 		goto done;
 	}
+
+	error = got_repo_pack_fds_open(&pack_fds);
+	if (error != NULL)
+		goto done;
+
 	error = got_worktree_open(&worktree, cwd);
 	if (error) {
 		if (error->code == GOT_ERR_NOT_WORKTREE)
@@ -8746,7 +8980,7 @@ cmd_cherrypick(int argc, char *argv[])
 	}
 
 	error = got_repo_open(&repo, got_worktree_get_repo_path(worktree),
-	    NULL);
+	    NULL, pack_fds);
 	if (error != NULL)
 		goto done;
 
@@ -8787,7 +9021,14 @@ done:
 		const struct got_error *close_err = got_repo_close(repo);
 		if (error == NULL)
 			error = close_err;
+	}
+	if (pack_fds) {
+		const struct got_error *pack_err =
+		    got_repo_pack_fds_close(pack_fds);
+		if (error == NULL)
+			error = pack_err;
 	}
+
 	return error;
 }
 
@@ -8810,6 +9051,7 @@ cmd_backout(int argc, char *argv[])
 	struct got_object_qid *pid;
 	int ch;
 	struct got_update_progress_arg upa;
+	int *pack_fds = NULL;
 
 	while ((ch = getopt(argc, argv, "")) != -1) {
 		switch (ch) {
@@ -8835,6 +9077,11 @@ cmd_backout(int argc, char *argv[])
 		error = got_error_from_errno("getcwd");
 		goto done;
 	}
+
+	error = got_repo_pack_fds_open(&pack_fds);
+	if (error != NULL)
+		goto done;
+
 	error = got_worktree_open(&worktree, cwd);
 	if (error) {
 		if (error->code == GOT_ERR_NOT_WORKTREE)
@@ -8843,7 +9090,7 @@ cmd_backout(int argc, char *argv[])
 	}
 
 	error = got_repo_open(&repo, got_worktree_get_repo_path(worktree),
-	    NULL);
+	    NULL, pack_fds);
 	if (error != NULL)
 		goto done;
 
@@ -8888,6 +9135,12 @@ done:
 		const struct got_error *close_err = got_repo_close(repo);
 		if (error == NULL)
 			error = close_err;
+	}
+	if (pack_fds) {
+		const struct got_error *pack_err =
+		    got_repo_pack_fds_close(pack_fds);
+		if (error == NULL)
+			error = pack_err;
 	}
 	return error;
 }
@@ -9473,6 +9726,7 @@ 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 *pack_fds = NULL;
 
 	STAILQ_INIT(&commits);
 	TAILQ_INIT(&merged_paths);
@@ -9539,6 +9793,11 @@ cmd_rebase(int argc, char *argv[])
 		error = got_error_from_errno("getcwd");
 		goto done;
 	}
+
+	error = got_repo_pack_fds_open(&pack_fds);
+	if (error != NULL)
+		goto done;
+
 	error = got_worktree_open(&worktree, cwd);
 	if (error) {
 		if (list_backups || delete_backups) {
@@ -9553,7 +9812,8 @@ cmd_rebase(int argc, char *argv[])
 	}
 
 	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;
 
@@ -9838,6 +10098,12 @@ done:
 		if (error == NULL)
 			error = close_err;
 	}
+	if (pack_fds) {
+		const struct got_error *pack_err =
+		    got_repo_pack_fds_close(pack_fds);
+		if (error == NULL)
+			error = pack_err;
+	}
 	return error;
 }
 
@@ -10692,6 +10958,7 @@ cmd_histedit(int argc, char *argv[])
 	struct got_object_qid *pid;
 	struct got_histedit_list histedit_cmds;
 	struct got_histedit_list_entry *hle;
+	int *pack_fds = NULL;
 
 	STAILQ_INIT(&commits);
 	TAILQ_INIT(&histedit_cmds);
@@ -10813,6 +11080,11 @@ cmd_histedit(int argc, char *argv[])
 		error = got_error_from_errno("getcwd");
 		goto done;
 	}
+
+	error = got_repo_pack_fds_open(&pack_fds);
+	if (error != NULL)
+		goto done;
+
 	error = got_worktree_open(&worktree, cwd);
 	if (error) {
 		if (list_backups || delete_backups) {
@@ -10829,7 +11101,7 @@ cmd_histedit(int argc, char *argv[])
 	if (list_backups || delete_backups) {
 		error = got_repo_open(&repo,
 		    worktree ? got_worktree_get_repo_path(worktree) : cwd,
-		    NULL);
+		    NULL, pack_fds);
 		if (error != NULL)
 			goto done;
 		error = apply_unveil(got_repo_get_path(repo), 0,
@@ -10843,7 +11115,7 @@ 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;
 
@@ -11212,6 +11484,12 @@ done:
 		const struct got_error *close_err = got_repo_close(repo);
 		if (error == NULL)
 			error = close_err;
+	}
+	if (pack_fds) {
+		const struct got_error *pack_err =
+		    got_repo_pack_fds_close(pack_fds);
+		if (error == NULL)
+			error = pack_err;
 	}
 	return error;
 }
@@ -11236,6 +11514,7 @@ 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 *pack_fds = NULL;
 
 	while ((ch = getopt(argc, argv, "")) != -1) {
 		switch (ch) {
@@ -11262,6 +11541,10 @@ cmd_integrate(int argc, char *argv[])
 		goto done;
 	}
 
+	error = got_repo_pack_fds_open(&pack_fds);
+	if (error != NULL)
+		goto done;
+
 	error = got_worktree_open(&worktree, cwd);
 	if (error) {
 		if (error->code == GOT_ERR_NOT_WORKTREE)
@@ -11275,7 +11558,7 @@ cmd_integrate(int argc, char *argv[])
 		goto done;
 
 	error = got_repo_open(&repo, got_worktree_get_repo_path(worktree),
-	    NULL);
+	    NULL, pack_fds);
 	if (error != NULL)
 		goto done;
 
@@ -11355,6 +11638,12 @@ done:
 	}
 	if (worktree)
 		got_worktree_close(worktree);
+	if (pack_fds) {
+		const struct got_error *pack_err =
+		    got_repo_pack_fds_close(pack_fds);
+		if (error == NULL)
+			error = pack_err;
+	}
 	free(cwd);
 	free(base_commit_id);
 	free(commit_id);
@@ -11387,6 +11676,7 @@ 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 *pack_fds = NULL;
 
 	memset(&upa, 0, sizeof(upa));
 
@@ -11430,6 +11720,10 @@ cmd_merge(int argc, char *argv[])
 		goto done;
 	}
 
+	error = got_repo_pack_fds_open(&pack_fds);
+	if (error != NULL)
+		goto done;
+
 	error = got_worktree_open(&worktree, cwd);
 	if (error) {
 		if (error->code == GOT_ERR_NOT_WORKTREE)
@@ -11439,7 +11733,8 @@ cmd_merge(int argc, char *argv[])
 	}
 
 	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;
 
@@ -11625,6 +11920,12 @@ done:
 		if (error == NULL)
 			error = close_err;
 	}
+	if (pack_fds) {
+		const struct got_error *pack_err =
+		    got_repo_pack_fds_close(pack_fds);
+		if (error == NULL)
+			error = pack_err;
+	}
 	return error;
 }
 
@@ -11677,6 +11978,7 @@ cmd_stage(int argc, char *argv[])
 	FILE *patch_script_file = NULL;
 	const char *patch_script_path = NULL;
 	struct choose_patch_arg cpa;
+	int *pack_fds = NULL;
 
 	TAILQ_INIT(&paths);
 
@@ -11719,6 +12021,10 @@ cmd_stage(int argc, char *argv[])
 		goto done;
 	}
 
+	error = got_repo_pack_fds_open(&pack_fds);
+	if (error != NULL)
+		goto done;
+
 	error = got_worktree_open(&worktree, cwd);
 	if (error) {
 		if (error->code == GOT_ERR_NOT_WORKTREE)
@@ -11727,7 +12033,7 @@ cmd_stage(int argc, char *argv[])
 	}
 
 	error = got_repo_open(&repo, got_worktree_get_repo_path(worktree),
-	    NULL);
+	    NULL, pack_fds);
 	if (error != NULL)
 		goto done;
 
@@ -11774,6 +12080,12 @@ done:
 	}
 	if (worktree)
 		got_worktree_close(worktree);
+	if (pack_fds) {
+		const struct got_error *pack_err =
+		    got_repo_pack_fds_close(pack_fds);
+		if (error == NULL)
+			error = pack_err;
+	}
 	TAILQ_FOREACH(pe, &paths, entry)
 		free((char *)pe->path);
 	got_pathlist_free(&paths);
@@ -11805,6 +12117,7 @@ cmd_unstage(int argc, char *argv[])
 	FILE *patch_script_file = NULL;
 	const char *patch_script_path = NULL;
 	struct choose_patch_arg cpa;
+	int *pack_fds = NULL;
 
 	TAILQ_INIT(&paths);
 
@@ -11839,6 +12152,10 @@ cmd_unstage(int argc, char *argv[])
 		goto done;
 	}
 
+	error = got_repo_pack_fds_open(&pack_fds);
+	if (error != NULL)
+		goto done;
+
 	error = got_worktree_open(&worktree, cwd);
 	if (error) {
 		if (error->code == GOT_ERR_NOT_WORKTREE)
@@ -11847,7 +12164,7 @@ cmd_unstage(int argc, char *argv[])
 	}
 
 	error = got_repo_open(&repo, got_worktree_get_repo_path(worktree),
-	    NULL);
+	    NULL, pack_fds);
 	if (error != NULL)
 		goto done;
 
@@ -11887,6 +12204,12 @@ done:
 	}
 	if (worktree)
 		got_worktree_close(worktree);
+	if (pack_fds) {
+		const struct got_error *pack_err =
+		    got_repo_pack_fds_close(pack_fds);
+		if (error == NULL)
+			error = pack_err;
+	}
 	TAILQ_FOREACH(pe, &paths, entry)
 		free((char *)pe->path);
 	got_pathlist_free(&paths);
@@ -12089,6 +12412,7 @@ 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 *pack_fds = NULL;
 
 	TAILQ_INIT(&refs);
 
@@ -12128,6 +12452,10 @@ cmd_cat(int argc, char *argv[])
 		goto done;
 	}
 
+	error = got_repo_pack_fds_open(&pack_fds);
+	if (error != NULL)
+		goto done;
+
 	if (repo_path == NULL) {
 		error = got_worktree_open(&worktree, cwd);
 		if (error && error->code != GOT_ERR_NOT_WORKTREE)
@@ -12152,7 +12480,7 @@ cmd_cat(int argc, char *argv[])
 			return got_error_from_errno("strdup");
 	}
 
-	error = got_repo_open(&repo, repo_path, NULL);
+	error = got_repo_open(&repo, repo_path, NULL, pack_fds);
 	free(repo_path);
 	if (error != NULL)
 		goto done;
@@ -12238,6 +12566,13 @@ done:
 		if (error == NULL)
 			error = close_err;
 	}
+	if (pack_fds) {
+		const struct got_error *pack_err =
+		    got_repo_pack_fds_close(pack_fds);
+		if (error == NULL)
+			error = pack_err;
+	}
+
 	got_ref_list_free(&refs);
 	return error;
 }
@@ -12328,6 +12663,7 @@ cmd_info(int argc, char *argv[])
 	struct got_pathlist_entry *pe;
 	char *uuidstr = NULL;
 	int ch, show_files = 0;
+	int *pack_fds = NULL;
 
 	TAILQ_INIT(&paths);
 
@@ -12353,6 +12689,10 @@ cmd_info(int argc, char *argv[])
 		goto done;
 	}
 
+	error = got_repo_pack_fds_open(&pack_fds);
+	if (error != NULL)
+		goto done;
+
 	error = got_worktree_open(&worktree, cwd);
 	if (error) {
 		if (error->code == GOT_ERR_NOT_WORKTREE)
@@ -12420,6 +12760,12 @@ cmd_info(int argc, char *argv[])
 		}
 	}
 done:
+	if (pack_fds) {
+		const struct got_error *pack_err =
+		    got_repo_pack_fds_close(pack_fds);
+		if (error == NULL)
+			error = pack_err;
+	}
 	TAILQ_FOREACH(pe, &paths, entry)
 		free((char *)pe->path);
 	got_pathlist_free(&paths);
blob - 46dde67bc1a81fb350b49f982708b80abf6294ec
blob + b88d54df494f629ad336256ee0db5595bf370946
--- gotadmin/gotadmin.c
+++ gotadmin/gotadmin.c
@@ -274,6 +274,7 @@ cmd_info(int argc, char *argv[])
 	int ch, npackfiles, npackedobj, nobj;
 	off_t packsize, loose_size;
 	char scaled[FMT_SCALED_STRSIZE];
+	int *pack_fds = NULL;
 
 	while ((ch = getopt(argc, argv, "r:")) != -1) {
 		switch (ch) {
@@ -303,7 +304,10 @@ cmd_info(int argc, char *argv[])
 		if (error)
 			goto done;
 	}
-	error = got_repo_open(&repo, repo_path, NULL);
+	error = got_repo_pack_fds_open(&pack_fds);
+	if (error != NULL)
+		goto done;
+	error = got_repo_open(&repo, repo_path, NULL, pack_fds);
 	if (error)
 		goto done;
 #ifndef PROFILE
@@ -370,6 +374,13 @@ cmd_info(int argc, char *argv[])
 done:
 	if (repo)
 		got_repo_close(repo);
+	if (pack_fds) {
+		const struct got_error *pack_err =
+		    got_repo_pack_fds_close(pack_fds);
+		if (error == NULL)
+			error = pack_err;
+	}
+
 	free(repo_path);
 	return error;
 }
@@ -628,6 +639,7 @@ 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 *pack_fds = NULL;
 
 	TAILQ_INIT(&exclude_args);
 	TAILQ_INIT(&exclude_refs);
@@ -674,7 +686,10 @@ cmd_pack(int argc, char *argv[])
 		if (error)
 			goto done;
 	}
-	error = got_repo_open(&repo, repo_path, NULL);
+	error = got_repo_pack_fds_open(&pack_fds);
+	if (error != NULL)
+		goto done;
+	error = got_repo_open(&repo, repo_path, NULL, pack_fds);
 	if (error)
 		goto done;
 
@@ -746,6 +761,12 @@ cmd_pack(int argc, char *argv[])
 done:
 	if (repo)
 		got_repo_close(repo);
+	if (pack_fds) {
+		const struct got_error *pack_err =
+		    got_repo_pack_fds_close(pack_fds);
+		if (error == NULL)
+			error = pack_err;
+	}
 	got_pathlist_free(&exclude_args);
 	got_ref_list_free(&exclude_refs);
 	got_ref_list_free(&include_refs);
@@ -774,6 +795,7 @@ cmd_indexpack(int argc, char *argv[])
 	char *id_str = NULL;
 	struct got_pack_progress_arg ppa;
 	FILE *packfile = NULL;
+	int *pack_fds = NULL;
 
 	while ((ch = getopt(argc, argv, "")) != -1) {
 		switch (ch) {
@@ -799,7 +821,10 @@ cmd_indexpack(int argc, char *argv[])
 		err(1, "pledge");
 #endif
 
-	error = got_repo_open(&repo, packfile_path, NULL);
+	error = got_repo_pack_fds_open(&pack_fds);
+	if (error != NULL)
+		goto done;
+	error = got_repo_open(&repo, packfile_path, NULL, pack_fds);
 	if (error)
 		goto done;
 
@@ -829,6 +854,12 @@ cmd_indexpack(int argc, char *argv[])
 done:
 	if (repo)
 		got_repo_close(repo);
+	if (pack_fds) {
+		const struct got_error *pack_err =
+		    got_repo_pack_fds_close(pack_fds);
+		if (error == NULL)
+			error = pack_err;
+	}
 	free(id_str);
 	free(pack_hash);
 	return error;
@@ -861,7 +892,7 @@ list_pack_cb(void *arg, struct got_object_id *id, int 
 	char *id_str, *delta_str = NULL, *base_id_str = NULL;
 	const char *type_str;
 
-	err = got_object_id_str(&id_str, id);	
+	err = got_object_id_str(&id_str, id);
 	if (err)
 		return err;
 
@@ -942,6 +973,7 @@ cmd_listpack(int argc, char *argv[])
 	struct gotadmin_list_pack_cb_args lpa;
 	FILE *packfile = NULL;
 	int show_stats = 0, human_readable = 0;
+	int *pack_fds = NULL;
 
 	while ((ch = getopt(argc, argv, "hs")) != -1) {
 		switch (ch) {
@@ -971,7 +1003,10 @@ 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_open(&pack_fds);
+	if (error != NULL)
+		goto done;
+	error = got_repo_open(&repo, packfile_path, NULL, pack_fds);
 	if (error)
 		goto done;
 #ifndef PROFILE
@@ -1009,6 +1044,12 @@ cmd_listpack(int argc, char *argv[])
 done:
 	if (repo)
 		got_repo_close(repo);
+	if (pack_fds) {
+		const struct got_error *pack_err =
+		    got_repo_pack_fds_close(pack_fds);
+		if (error == NULL)
+			error = pack_err;
+	}
 	free(id_str);
 	free(pack_hash);
 	free(packfile_path);
@@ -1119,6 +1160,7 @@ cmd_cleanup(int argc, char *argv[])
 	char scaled_diff[FMT_SCALED_STRSIZE];
 	char **extensions;
 	int nextensions, i;
+	int *pack_fds = NULL;
 
 	while ((ch = getopt(argc, argv, "apr:nq")) != -1) {
 		switch (ch) {
@@ -1160,7 +1202,10 @@ cmd_cleanup(int argc, char *argv[])
 		if (error)
 			goto done;
 	}
-	error = got_repo_open(&repo, repo_path, NULL);
+	error = got_repo_pack_fds_open(&pack_fds);
+	if (error != NULL)
+		goto done;
+	error = got_repo_open(&repo, repo_path, NULL, pack_fds);
 	if (error)
 		goto done;
 
@@ -1225,6 +1270,12 @@ cmd_cleanup(int argc, char *argv[])
 done:
 	if (repo)
 		got_repo_close(repo);
+	if (pack_fds) {
+		const struct got_error *pack_err =
+		    got_repo_pack_fds_close(pack_fds);
+		if (error == NULL)
+			error = pack_err;
+	}
 	free(repo_path);
 	return error;
 }
blob - 1b013ef433cce2c4c403b87e246b5ad07d01eae0
blob + 3fa69ecef924d75ae4215263539eaa966f634034
--- gotweb/gotweb.c
+++ gotweb/gotweb.c
@@ -567,7 +567,7 @@ gw_index(struct gw_trans *gw_trans)
 	enum kcgi_err kerr = KCGI_OK;
 
 #ifndef PROFILE
-	if (pledge("stdio rpath proc exec sendfd unveil",
+	if (pledge("stdio rpath wpath cpath proc exec sendfd unveil",
 	    NULL) == -1) {
 		error = got_error_from_errno("pledge");
 		return error;
@@ -971,7 +971,7 @@ gw_commits(struct gw_trans *gw_trans)
 		return got_error_from_errno("malloc");
 
 #ifndef PROFILE
-	if (pledge("stdio rpath proc exec sendfd unveil",
+	if (pledge("stdio rpath wpath cpath proc exec sendfd unveil",
 	    NULL) == -1) {
 		error = got_error_from_errno("pledge");
 		goto done;
@@ -1198,7 +1198,7 @@ gw_briefs(struct gw_trans *gw_trans)
 		return got_error_from_errno("malloc");
 
 #ifndef PROFILE
-	if (pledge("stdio rpath proc exec sendfd unveil",
+	if (pledge("stdio rpath wpath cpath proc exec sendfd unveil",
 	    NULL) == -1) {
 		error = got_error_from_errno("pledge");
 		goto done;
@@ -1458,7 +1458,8 @@ gw_summary(struct gw_trans *gw_trans)
 	enum kcgi_err kerr = KCGI_OK;
 
 #ifndef PROFILE
-	if (pledge("stdio rpath proc exec sendfd unveil", NULL) == -1)
+	if (pledge("stdio rpath wpath cpath proc exec sendfd unveil",
+	    NULL) == -1)
 		return got_error_from_errno("pledge");
 #endif
 	error = gw_apply_unveil(gw_trans->gw_dir->path);
@@ -1621,7 +1622,8 @@ gw_tree(struct gw_trans *gw_trans)
 	enum kcgi_err kerr = KCGI_OK;
 
 #ifndef PROFILE
-	if (pledge("stdio rpath proc exec sendfd unveil", NULL) == -1)
+	if (pledge("stdio rpath wpath cpath proc exec sendfd unveil",
+	    NULL) == -1)
 		return got_error_from_errno("pledge");
 #endif
 	if ((header = gw_init_header()) == NULL)
@@ -1696,7 +1698,8 @@ gw_tags(struct gw_trans *gw_trans)
 	enum kcgi_err kerr = KCGI_OK;
 
 #ifndef PROFILE
-	if (pledge("stdio rpath proc exec sendfd unveil", NULL) == -1)
+	if (pledge("stdio rpath wpath cpath proc exec sendfd unveil",
+	    NULL) == -1)
 		return got_error_from_errno("pledge");
 #endif
 	if ((header = gw_init_header()) == NULL)
@@ -1812,7 +1815,7 @@ gw_tag(struct gw_trans *gw_trans)
 	enum kcgi_err kerr = KCGI_OK;
 
 #ifndef PROFILE
-	if (pledge("stdio rpath proc exec sendfd unveil", NULL) == -1)
+	if (pledge("stdio rpath wpath cpath proc exec sendfd unveil", NULL) == -1)
 		return got_error_from_errno("pledge");
 #endif
 	if ((header = gw_init_header()) == NULL)
@@ -2783,6 +2786,7 @@ gw_get_repo_age(char **repo_age, struct gw_trans *gw_t
 	struct got_reflist_head refs;
 	struct got_reflist_entry *re;
 	time_t committer_time = 0, cmp_time = 0;
+	int *pack_fds = NULL;
 
 	*repo_age = NULL;
 	TAILQ_INIT(&refs);
@@ -2793,7 +2797,10 @@ gw_get_repo_age(char **repo_age, struct gw_trans *gw_t
 	if (gw_trans->repo)
 		repo = gw_trans->repo;
 	else {
-		error = got_repo_open(&repo, dir, NULL);
+		error = got_repo_pack_fds_open(&pack_fds);
+		if (error != NULL)
+			goto done;
+		error = got_repo_open(&repo, dir, NULL, pack_fds);
 		if (error)
 			return error;
 	}
@@ -2843,6 +2850,12 @@ done:
 		if (error == NULL)
 			error = close_err;
 	}
+	if (pack_fds) {
+		const struct got_error *pack_err =
+		    got_repo_pack_fds_close(pack_fds);
+		if (error == NULL)
+			error = pack_err;
+	}
 	return error;
 }
 
@@ -2954,15 +2967,20 @@ gw_get_repo_owner(char **owner, struct gw_trans *gw_tr
 	const struct got_error *error = NULL, *close_err;
 	struct got_repository *repo;
 	const char *gitconfig_owner;
+	int *pack_fds = NULL;
 
 	*owner = NULL;
 
 	if (gw_trans->gw_conf->got_show_repo_owner == 0)
 		return NULL;
 
-	error = got_repo_open(&repo, dir, NULL);
+	error = got_repo_pack_fds_open(&pack_fds);
+	if (error != NULL)
+		return error;
+	error = got_repo_open(&repo, dir, NULL, pack_fds);
 	if (error)
 		return error;
+
 	gitconfig_owner = got_repo_get_gitconfig_owner(repo);
 	if (gitconfig_owner) {
 		*owner = strdup(gitconfig_owner);
@@ -2972,6 +2990,12 @@ gw_get_repo_owner(char **owner, struct gw_trans *gw_tr
 	close_err = got_repo_close(repo);
 	if (error == NULL)
 		error = close_err;
+	if (pack_fds) {
+		const struct got_error *pack_err =
+		    got_repo_pack_fds_close(pack_fds);
+		if (error == NULL)
+			error = pack_err;
+	}
 	return error;
 }
 
@@ -3771,8 +3795,13 @@ gw_get_header(struct gw_trans *gw_trans, struct gw_hea
 	char *in_repo_path = NULL;
 	struct got_object_id *id = NULL;
 	struct got_reference *ref;
+	int *pack_fds = NULL;
 
-	error = got_repo_open(&gw_trans->repo, gw_trans->repo_path, NULL);
+	error = got_repo_pack_fds_open(&pack_fds);
+	if (error != NULL)
+		goto done;
+	error = got_repo_open(&gw_trans->repo, gw_trans->repo_path, NULL,
+	    pack_fds);
 	if (error)
 		return error;
 
@@ -3854,7 +3883,12 @@ gw_get_header(struct gw_trans *gw_trans, struct gw_hea
 
 	error = gw_get_commits(gw_trans, header, limit, id);
 done:
-	got_ref_list_free(&header->refs);
+	if (pack_fds) {
+		const struct got_error *pack_err =
+		    got_repo_pack_fds_close(pack_fds);
+		if (error == NULL)
+			error = pack_err;
+	}
 	free(id);
 	free(in_repo_path);
 	return error;
@@ -4846,17 +4880,17 @@ main(int argc, char *argv[])
 	if (error)
 		goto done;
 
-	if (gw_trans->action == GW_BLOB)
-		error = gw_blob(gw_trans);
-	else
-		error = gw_display_index(gw_trans);
-done:
 	if (gw_trans->repo) {
 		const struct got_error *close_err;
 		close_err = got_repo_close(gw_trans->repo);
 		if (error == NULL)
 			error = close_err;
 	}
+	if (gw_trans->action == GW_BLOB)
+		error = gw_blob(gw_trans);
+	else
+		error = gw_display_index(gw_trans);
+done:
 	if (error) {
 		gw_trans->error = error;
 		gw_trans->action = GW_ERR;
blob - b6e44e8b40b8476a471c53fd10cffd4a7ff3b32d
blob + dea6dd81d267dfa92571a33f5c7559726bab8d8b
--- 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,9 @@ 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 *);
+
+/* Create an array of file descriptors to hand over to got_repo_open for pack */
+const struct got_error *got_repo_pack_fds_open(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 - a35884552cf66d678f0db623e1dd92d976a7014e
blob + 414cf45f495487020f948b4b0c3e6a45ef730da9
--- lib/got_lib_worktree.h
+++ lib/got_lib_worktree.h
@@ -22,6 +22,7 @@ struct got_worktree {
 	struct got_object_id *base_commit_id;
 	char *head_ref_name;
 	uuid_t uuid;
+	int *pack_fds;
 
 	/*
 	 * File descriptor for the lock file, open while a work tree is open.
blob - 873467bcc9388aac56c737347130ba38ef7f9564
blob + d9cf5cc0bdf4ecba2e571c9eb958fe80af948507
--- lib/repository.c
+++ lib/repository.c
@@ -62,6 +62,8 @@
 #define nitems(_a) (sizeof(_a) / sizeof((_a)[0]))
 #endif
 
+#define GOT_PACK_NUM_TEMPFILES		GOT_PACK_CACHE_SIZE * 2
+
 RB_PROTOTYPE(got_packidx_bloom_filter_tree, got_packidx_bloom_filter, entry,
     got_packidx_bloom_filter_cmp);
 
@@ -241,6 +243,49 @@ done:
 }
 
 const struct got_error *
+got_repo_pack_fds_open(int **pack_fds)
+{
+	const struct got_error *err = NULL;
+	int i, pack_fds_tmp[GOT_PACK_NUM_TEMPFILES];
+
+	*pack_fds = calloc(GOT_PACK_NUM_TEMPFILES, sizeof(**pack_fds));
+	if (*pack_fds == NULL)
+		return got_error_from_errno("calloc");
+
+	for (i = 0; i < GOT_PACK_NUM_TEMPFILES; i++) {
+		pack_fds_tmp[i] = got_opentempfd();
+		if (pack_fds_tmp[i] == -1) {
+			err = got_repo_pack_fds_close(pack_fds_tmp);
+			if (err)
+				return err;
+			else
+				return got_error_from_errno("got_opentempfd");
+		}
+	}
+	memcpy(*pack_fds, pack_fds_tmp, sizeof(pack_fds_tmp));
+	return err;
+}
+
+const struct got_error *
+got_repo_pack_fds_close(int *pack_fds)
+{
+	const struct got_error *err = NULL;
+	int i;
+
+	for (i = 0; i < GOT_PACK_NUM_TEMPFILES; i++) {
+		if (pack_fds[i] == -1)
+			continue;
+		if (close(pack_fds[i]) == -1) {
+			err = got_error_from_errno("close");
+			break;
+		}
+	}
+	free(pack_fds);
+	pack_fds = NULL;
+	return err;
+}
+
+const struct got_error *
 got_repo_cache_object(struct got_repository *repo, struct got_object_id *id,
     struct got_object *obj)
 {
@@ -645,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;
@@ -697,12 +742,8 @@ 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();
-			if (repo->packs[i].basefd == -1)
-				return got_error_from_errno("got_opentempfd");
-			repo->packs[i].accumfd = got_opentempfd();
-			if (repo->packs[i].accumfd == -1)
-				return got_error_from_errno("got_opentempfd");
+			repo->packs[i].basefd = pack_fds[j++];
+			repo->packs[i].accumfd = pack_fds[j++];
 		} else {
 			repo->packs[i].basefd = -1;
 			repo->packs[i].accumfd = -1;
@@ -790,20 +831,10 @@ got_repo_close(struct got_repository *repo)
 		free(bf);
 	}
 
-	for (i = 0; i < repo->pack_cache_size; i++) {
+	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;
-		}
-	}
+			if (repo->packs[i].path_packfile)
+				got_pack_close(&repo->packs[i]);
 
 	free(repo->path);
 	free(repo->path_git_dir);
blob - 6d61529dcbf140930872d1c171b6edf9fea13692
blob + 5fc7f5e5959e0265169d48886312a51c11944edb
--- lib/worktree_open.c
+++ lib/worktree_open.c
@@ -187,10 +187,15 @@ open_worktree(struct got_worktree **worktree, const ch
 		goto done;
 	}
 
-	err = got_repo_open(&repo, (*worktree)->repo_path, NULL);
+	err = got_repo_pack_fds_open(&(*worktree)->pack_fds);
 	if (err)
 		goto done;
 
+	err = got_repo_open(&repo, (*worktree)->repo_path, NULL,
+	    (*worktree)->pack_fds);
+	if (err)
+		goto done;
+
 	err = got_object_resolve_id_str(&(*worktree)->base_commit_id, repo,
 	    base_commit_id_str);
 	if (err)
@@ -293,6 +298,12 @@ got_worktree_close(struct got_worktree *worktree)
 	if (close(worktree->root_fd) == -1 && err == NULL)
 		err = got_error_from_errno2("close",
 		    got_worktree_get_root_path(worktree));
+	if (worktree->pack_fds) {
+		const struct got_error *pack_err =
+		    got_repo_pack_fds_close(worktree->pack_fds);
+		if (err == NULL)
+			err = pack_err;
+	}
 	free(worktree->repo_path);
 	free(worktree->path_prefix);
 	free(worktree->base_commit_id);
blob - 7eb0998939a609baf348fc765cad19951439bcd9
blob + df00bf13e3f2baf15f30f3aec764842953fb213d
--- tog/tog.c
+++ tog/tog.c
@@ -417,6 +417,7 @@ struct tog_blame {
 	struct tog_blame_thread_args thread_args;
 	struct tog_blame_cb_args cb_args;
 	const char *path;
+	int *pack_fds;
 };
 
 struct tog_blame_view_state {
@@ -1132,7 +1133,7 @@ view_loop(struct tog_view *view)
 			}
 			TAILQ_INSERT_TAIL(&views, new_view, entry);
 			view = new_view;
-		} 
+		}
 		if (view) {
 			if (view_is_parent_view(view)) {
 				if (view->child && view->child->focussed)
@@ -2326,6 +2327,7 @@ 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 *pack_fds = NULL;
 
 	if (in_repo_path != s->in_repo_path) {
 		free(s->in_repo_path);
@@ -2379,9 +2381,13 @@ 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_open(&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_commit_graph_open(&thread_graph, s->in_repo_path,
 	    !s->log_branches);
 	if (err)
@@ -2416,6 +2422,12 @@ open_log_view(struct tog_view *view, struct got_object
 	s->thread_args.search_next_done = &view->search_next_done;
 	s->thread_args.regex = &view->regex;
 done:
+	if (pack_fds) {
+		const struct got_error *pack_err =
+		    got_repo_pack_fds_close(pack_fds);
+		if (err == NULL)
+			err = pack_err;
+	}
 	if (err)
 		close_log_view(view);
 	return err;
@@ -2451,6 +2463,7 @@ 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, nscroll = view->nlines - 1;
+	int *pack_fds = NULL;
 
 	if (s->thread_args.load_all) {
 		if (ch == KEY_BACKSPACE)
@@ -2651,8 +2664,14 @@ input_log_view(struct tog_view **new_view, struct tog_
 		} else /* 'B' */
 			s->log_branches = !s->log_branches;
 
+		err = got_repo_pack_fds_open(&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();
@@ -2808,6 +2827,7 @@ cmd_log(int argc, char *argv[])
 	const char *head_ref_name = NULL;
 	int ch, log_branches = 0;
 	struct tog_view *view;
+	int *pack_fds = NULL;
 
 	while ((ch = getopt(argc, argv, "bc:r:")) != -1) {
 		switch (ch) {
@@ -2835,6 +2855,10 @@ cmd_log(int argc, char *argv[])
 	if (argc > 1)
 		usage_log();
 
+	error = got_repo_pack_fds_open(&pack_fds);
+	if (error != NULL)
+		goto done;
+
 	if (repo_path == NULL) {
 		cwd = getcwd(NULL, 0);
 		if (cwd == NULL)
@@ -2853,7 +2877,7 @@ cmd_log(int argc, char *argv[])
 		}
 	}
 
-	error = got_repo_open(&repo, repo_path, NULL);
+	error = got_repo_open(&repo, repo_path, NULL, pack_fds);
 	if (error != NULL)
 		goto done;
 
@@ -2925,6 +2949,12 @@ done:
 	}
 	if (worktree)
 		got_worktree_close(worktree);
+	if (pack_fds) {
+		const struct got_error *pack_err =
+		    got_repo_pack_fds_close(pack_fds);
+		if (error == NULL)
+			error = pack_err;
+	}
 	tog_free_refs();
 	return error;
 }
@@ -3935,6 +3965,7 @@ cmd_diff(int argc, char *argv[])
 	int ch, force_text_diff = 0;
 	const char *errstr;
 	struct tog_view *view;
+	int *pack_fds = NULL;
 
 	while ((ch = getopt(argc, argv, "aC:r:w")) != -1) {
 		switch (ch) {
@@ -3975,6 +4006,10 @@ cmd_diff(int argc, char *argv[])
 	} else
 		usage_diff();
 
+	error = got_repo_pack_fds_open(&pack_fds);
+	if (error)
+		goto done;
+
 	if (repo_path == NULL) {
 		cwd = getcwd(NULL, 0);
 		if (cwd == NULL)
@@ -3993,7 +4028,7 @@ cmd_diff(int argc, char *argv[])
 		}
 	}
 
-	error = got_repo_open(&repo, repo_path, NULL);
+	error = got_repo_open(&repo, repo_path, NULL, pack_fds);
 	if (error)
 		goto done;
 
@@ -4039,6 +4074,12 @@ done:
 	}
 	if (worktree)
 		got_worktree_close(worktree);
+	if (pack_fds) {
+		const struct got_error *pack_err =
+		    got_repo_pack_fds_close(pack_fds);
+		if (error == NULL)
+			error = pack_err;
+	}
 	tog_free_refs();
 	return error;
 }
@@ -4358,7 +4399,12 @@ stop_blame(struct tog_blame *blame)
 	}
 	free(blame->cb_args.commit_id);
 	blame->cb_args.commit_id = NULL;
-
+	if (blame->pack_fds) {
+		const struct got_error *pack_err =
+		    got_repo_pack_fds_close(blame->pack_fds);
+		if (err == NULL)
+			err = pack_err;
+	}
 	return err;
 }
 
@@ -4396,6 +4442,7 @@ run_blame(struct tog_view *view)
 	struct got_repository *thread_repo = NULL;
 	struct got_object_id *obj_id = NULL;
 	int obj_type;
+	int *pack_fds = NULL;
 
 	err = got_object_open_as_commit(&commit, s->repo,
 	    &s->blamed_commit->id);
@@ -4442,10 +4489,15 @@ 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_open(&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;
 
+	blame->pack_fds = pack_fds;
 	blame->cb_args.view = view;
 	blame->cb_args.lines = blame->lines;
 	blame->cb_args.nlines = blame->nlines;
@@ -4545,7 +4597,6 @@ close_blame_view(struct tog_view *view)
 
 	free(s->path);
 	free_colors(&s->colors);
-
 	return err;
 }
 
@@ -4889,6 +4940,7 @@ cmd_blame(int argc, char *argv[])
 	char *commit_id_str = NULL;
 	int ch;
 	struct tog_view *view;
+	int *pack_fds = NULL;
 
 	while ((ch = getopt(argc, argv, "c:r:")) != -1) {
 		switch (ch) {
@@ -4913,6 +4965,10 @@ cmd_blame(int argc, char *argv[])
 	if (argc != 1)
 		usage_blame();
 
+	error = got_repo_pack_fds_open(&pack_fds);
+	if (error != NULL)
+		goto done;
+
 	if (repo_path == NULL) {
 		cwd = getcwd(NULL, 0);
 		if (cwd == NULL)
@@ -4931,7 +4987,7 @@ cmd_blame(int argc, char *argv[])
 		}
 	}
 
-	error = got_repo_open(&repo, repo_path, NULL);
+	error = got_repo_open(&repo, repo_path, NULL, pack_fds);
 	if (error != NULL)
 		goto done;
 
@@ -5005,6 +5061,12 @@ done:
 		if (error == NULL)
 			error = close_err;
 	}
+	if (pack_fds) {
+		const struct got_error *pack_err =
+		    got_repo_pack_fds_close(pack_fds);
+		if (error == NULL)
+			error = pack_err;
+	}
 	tog_free_refs();
 	return error;
 }
@@ -5760,6 +5822,7 @@ cmd_tree(int argc, char *argv[])
 	const char *head_ref_name = NULL;
 	int ch;
 	struct tog_view *view;
+	int *pack_fds = NULL;
 
 	while ((ch = getopt(argc, argv, "c:r:")) != -1) {
 		switch (ch) {
@@ -5783,6 +5846,10 @@ cmd_tree(int argc, char *argv[])
 
 	if (argc > 1)
 		usage_tree();
+
+	error = got_repo_pack_fds_open(&pack_fds);
+	if (error != NULL)
+		goto done;
 
 	if (repo_path == NULL) {
 		cwd = getcwd(NULL, 0);
@@ -5802,7 +5869,7 @@ cmd_tree(int argc, char *argv[])
 		}
 	}
 
-	error = got_repo_open(&repo, repo_path, NULL);
+	error = got_repo_open(&repo, repo_path, NULL, pack_fds);
 	if (error != NULL)
 		goto done;
 
@@ -5877,6 +5944,12 @@ done:
 		if (error == NULL)
 			error = close_err;
 	}
+	if (pack_fds) {
+		const struct got_error *pack_err =
+		    got_repo_pack_fds_close(pack_fds);
+		if (error == NULL)
+			error = pack_err;
+	}
 	tog_free_refs();
 	return error;
 }
@@ -6522,6 +6595,7 @@ cmd_ref(int argc, char *argv[])
 	char *cwd = NULL, *repo_path = NULL;
 	int ch;
 	struct tog_view *view;
+	int *pack_fds = NULL;
 
 	while ((ch = getopt(argc, argv, "r:")) != -1) {
 		switch (ch) {
@@ -6542,6 +6616,10 @@ cmd_ref(int argc, char *argv[])
 
 	if (argc > 1)
 		usage_ref();
+
+	error = got_repo_pack_fds_open(&pack_fds);
+	if (error != NULL)
+		goto done;
 
 	if (repo_path == NULL) {
 		cwd = getcwd(NULL, 0);
@@ -6561,7 +6639,7 @@ cmd_ref(int argc, char *argv[])
 		}
 	}
 
-	error = got_repo_open(&repo, repo_path, NULL);
+	error = got_repo_open(&repo, repo_path, NULL, pack_fds);
 	if (error != NULL)
 		goto done;
 
@@ -6599,6 +6677,12 @@ done:
 		if (close_err)
 			error = close_err;
 	}
+	if (pack_fds) {
+		const struct got_error *pack_err =
+		    got_repo_pack_fds_close(pack_fds);
+		if (error == NULL)
+			error = pack_err;
+	}
 	tog_free_refs();
 	return error;
 }
@@ -6670,11 +6754,16 @@ 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 *pack_fds = NULL;
 
 	cwd = getcwd(NULL, 0);
 	if (cwd == NULL)
 		return got_error_from_errno("getcwd");
 
+	error = got_repo_pack_fds_open(&pack_fds);
+	if (error != NULL)
+		goto done;
+
 	error = got_worktree_open(&worktree, cwd);
 	if (error && error->code != GOT_ERR_NOT_WORKTREE)
 		goto done;
@@ -6688,7 +6777,7 @@ tog_log_with_path(int argc, char *argv[])
 		goto done;
 	}
 
-	error = got_repo_open(&repo, repo_path, NULL);
+	error = got_repo_open(&repo, repo_path, NULL, pack_fds);
 	if (error != NULL)
 		goto done;
 
@@ -6748,6 +6837,12 @@ done:
 		got_object_commit_close(commit);
 	if (worktree)
 		got_worktree_close(worktree);
+	if (pack_fds) {
+		const struct got_error *pack_err =
+		    got_repo_pack_fds_close(pack_fds);
+		if (error == NULL)
+			error = pack_err;
+	}
 	free(id);
 	free(commit_id_str);
 	free(commit_id);