2 20662ea0 2021-04-10 stsp * Copyright (c) 2021 Stefan Sperling <stsp@openbsd.org>
4 20662ea0 2021-04-10 stsp * Permission to use, copy, modify, and distribute this software for any
5 20662ea0 2021-04-10 stsp * purpose with or without fee is hereby granted, provided that the above
6 20662ea0 2021-04-10 stsp * copyright notice and this permission notice appear in all copies.
8 20662ea0 2021-04-10 stsp * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 20662ea0 2021-04-10 stsp * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 20662ea0 2021-04-10 stsp * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 20662ea0 2021-04-10 stsp * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 20662ea0 2021-04-10 stsp * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 20662ea0 2021-04-10 stsp * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 20662ea0 2021-04-10 stsp * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 8b925c6c 2022-07-16 thomas #include <sys/queue.h>
18 05118f5a 2021-06-22 stsp #include <sys/types.h>
20 05118f5a 2021-06-22 stsp #include <ctype.h>
21 20662ea0 2021-04-10 stsp #include <getopt.h>
22 20662ea0 2021-04-10 stsp #include <err.h>
23 20662ea0 2021-04-10 stsp #include <errno.h>
24 20662ea0 2021-04-10 stsp #include <locale.h>
25 05118f5a 2021-06-22 stsp #include <inttypes.h>
26 20662ea0 2021-04-10 stsp #include <stdio.h>
27 20662ea0 2021-04-10 stsp #include <stdlib.h>
28 20662ea0 2021-04-10 stsp #include <signal.h>
29 20662ea0 2021-04-10 stsp #include <string.h>
30 20662ea0 2021-04-10 stsp #include <unistd.h>
32 2b0eee35 2021-09-21 thomas.ad #include "got_compat.h"
34 20662ea0 2021-04-10 stsp #include "got_version.h"
35 20662ea0 2021-04-10 stsp #include "got_error.h"
36 20662ea0 2021-04-10 stsp #include "got_object.h"
37 20662ea0 2021-04-10 stsp #include "got_reference.h"
38 05118f5a 2021-06-22 stsp #include "got_cancel.h"
39 20662ea0 2021-04-10 stsp #include "got_repository.h"
40 05118f5a 2021-06-22 stsp #include "got_repository_admin.h"
41 20662ea0 2021-04-10 stsp #include "got_gotconfig.h"
42 20662ea0 2021-04-10 stsp #include "got_path.h"
43 20662ea0 2021-04-10 stsp #include "got_privsep.h"
44 20662ea0 2021-04-10 stsp #include "got_opentemp.h"
45 1ea7ccc6 2021-11-15 thomas #include "got_worktree.h"
47 20662ea0 2021-04-10 stsp #ifndef nitems
48 20662ea0 2021-04-10 stsp #define nitems(_a) (sizeof((_a)) / sizeof((_a)[0]))
51 20662ea0 2021-04-10 stsp static volatile sig_atomic_t sigint_received;
52 20662ea0 2021-04-10 stsp static volatile sig_atomic_t sigpipe_received;
55 20662ea0 2021-04-10 stsp catch_sigint(int signo)
57 20662ea0 2021-04-10 stsp sigint_received = 1;
61 20662ea0 2021-04-10 stsp catch_sigpipe(int signo)
63 20662ea0 2021-04-10 stsp sigpipe_received = 1;
66 05118f5a 2021-06-22 stsp static const struct got_error *
67 05118f5a 2021-06-22 stsp check_cancelled(void *arg)
69 05118f5a 2021-06-22 stsp if (sigint_received || sigpipe_received)
70 05118f5a 2021-06-22 stsp return got_error(GOT_ERR_CANCELLED);
71 05118f5a 2021-06-22 stsp return NULL;
74 20662ea0 2021-04-10 stsp struct gotadmin_cmd {
75 20662ea0 2021-04-10 stsp const char *cmd_name;
76 20662ea0 2021-04-10 stsp const struct got_error *(*cmd_main)(int, char *[]);
77 20662ea0 2021-04-10 stsp void (*cmd_usage)(void);
78 20662ea0 2021-04-10 stsp const char *cmd_alias;
81 20662ea0 2021-04-10 stsp __dead static void usage(int, int);
82 27b10c3c 2022-07-04 thomas __dead static void usage_init(void);
83 20662ea0 2021-04-10 stsp __dead static void usage_info(void);
84 05118f5a 2021-06-22 stsp __dead static void usage_pack(void);
85 05118f5a 2021-06-22 stsp __dead static void usage_indexpack(void);
86 05118f5a 2021-06-22 stsp __dead static void usage_listpack(void);
87 b3d68e7f 2021-07-03 stsp __dead static void usage_cleanup(void);
89 27b10c3c 2022-07-04 thomas static const struct got_error* cmd_init(int, char *[]);
90 20662ea0 2021-04-10 stsp static const struct got_error* cmd_info(int, char *[]);
91 05118f5a 2021-06-22 stsp static const struct got_error* cmd_pack(int, char *[]);
92 05118f5a 2021-06-22 stsp static const struct got_error* cmd_indexpack(int, char *[]);
93 05118f5a 2021-06-22 stsp static const struct got_error* cmd_listpack(int, char *[]);
94 b3d68e7f 2021-07-03 stsp static const struct got_error* cmd_cleanup(int, char *[]);
96 641a8ee6 2022-02-16 thomas static const struct gotadmin_cmd gotadmin_commands[] = {
97 27b10c3c 2022-07-04 thomas { "init", cmd_init, usage_init, "" },
98 20662ea0 2021-04-10 stsp { "info", cmd_info, usage_info, "" },
99 05118f5a 2021-06-22 stsp { "pack", cmd_pack, usage_pack, "" },
100 05118f5a 2021-06-22 stsp { "indexpack", cmd_indexpack, usage_indexpack,"ix" },
101 05118f5a 2021-06-22 stsp { "listpack", cmd_listpack, usage_listpack, "ls" },
102 b3d68e7f 2021-07-03 stsp { "cleanup", cmd_cleanup, usage_cleanup, "cl" },
105 20662ea0 2021-04-10 stsp static void
106 20662ea0 2021-04-10 stsp list_commands(FILE *fp)
110 20662ea0 2021-04-10 stsp fprintf(fp, "commands:");
111 20662ea0 2021-04-10 stsp for (i = 0; i < nitems(gotadmin_commands); i++) {
112 641a8ee6 2022-02-16 thomas const struct gotadmin_cmd *cmd = &gotadmin_commands[i];
113 20662ea0 2021-04-10 stsp fprintf(fp, " %s", cmd->cmd_name);
115 20662ea0 2021-04-10 stsp fputc('\n', fp);
119 20662ea0 2021-04-10 stsp main(int argc, char *argv[])
121 641a8ee6 2022-02-16 thomas const struct gotadmin_cmd *cmd;
124 20662ea0 2021-04-10 stsp int hflag = 0, Vflag = 0;
125 641a8ee6 2022-02-16 thomas static const struct option longopts[] = {
126 20662ea0 2021-04-10 stsp { "version", no_argument, NULL, 'V' },
127 20662ea0 2021-04-10 stsp { NULL, 0, NULL, 0 }
130 20662ea0 2021-04-10 stsp setlocale(LC_CTYPE, "");
132 20662ea0 2021-04-10 stsp while ((ch = getopt_long(argc, argv, "+hV", longopts, NULL)) != -1) {
133 20662ea0 2021-04-10 stsp switch (ch) {
141 20662ea0 2021-04-10 stsp usage(hflag, 1);
142 20662ea0 2021-04-10 stsp /* NOTREACHED */
146 20662ea0 2021-04-10 stsp argc -= optind;
147 20662ea0 2021-04-10 stsp argv += optind;
148 20662ea0 2021-04-10 stsp optind = 1;
149 20662ea0 2021-04-10 stsp optreset = 1;
151 20662ea0 2021-04-10 stsp if (Vflag) {
152 20662ea0 2021-04-10 stsp got_version_print_str();
156 20662ea0 2021-04-10 stsp if (argc <= 0)
157 20662ea0 2021-04-10 stsp usage(hflag, hflag ? 0 : 1);
159 20662ea0 2021-04-10 stsp signal(SIGINT, catch_sigint);
160 20662ea0 2021-04-10 stsp signal(SIGPIPE, catch_sigpipe);
162 20662ea0 2021-04-10 stsp for (i = 0; i < nitems(gotadmin_commands); i++) {
163 20662ea0 2021-04-10 stsp const struct got_error *error;
165 20662ea0 2021-04-10 stsp cmd = &gotadmin_commands[i];
167 20662ea0 2021-04-10 stsp if (strcmp(cmd->cmd_name, argv[0]) != 0 &&
168 20662ea0 2021-04-10 stsp strcmp(cmd->cmd_alias, argv[0]) != 0)
172 641a8ee6 2022-02-16 thomas cmd->cmd_usage();
174 641a8ee6 2022-02-16 thomas error = cmd->cmd_main(argc, argv);
175 20662ea0 2021-04-10 stsp if (error && error->code != GOT_ERR_CANCELLED &&
176 20662ea0 2021-04-10 stsp error->code != GOT_ERR_PRIVSEP_EXIT &&
177 20662ea0 2021-04-10 stsp !(sigpipe_received &&
178 20662ea0 2021-04-10 stsp error->code == GOT_ERR_ERRNO && errno == EPIPE) &&
179 20662ea0 2021-04-10 stsp !(sigint_received &&
180 20662ea0 2021-04-10 stsp error->code == GOT_ERR_ERRNO && errno == EINTR)) {
181 20662ea0 2021-04-10 stsp fprintf(stderr, "%s: %s\n", getprogname(), error->msg);
188 20662ea0 2021-04-10 stsp fprintf(stderr, "%s: unknown command '%s'\n", getprogname(), argv[0]);
189 20662ea0 2021-04-10 stsp list_commands(stderr);
193 20662ea0 2021-04-10 stsp __dead static void
194 20662ea0 2021-04-10 stsp usage(int hflag, int status)
196 20662ea0 2021-04-10 stsp FILE *fp = (status == 0) ? stdout : stderr;
198 0a58e722 2022-10-04 thomas fprintf(fp, "usage: %s [-hV] command [arg ...]\n",
199 20662ea0 2021-04-10 stsp getprogname());
201 20662ea0 2021-04-10 stsp list_commands(fp);
202 20662ea0 2021-04-10 stsp exit(status);
205 20662ea0 2021-04-10 stsp static const struct got_error *
206 20662ea0 2021-04-10 stsp apply_unveil(const char *repo_path, int repo_read_only)
208 20662ea0 2021-04-10 stsp const struct got_error *err;
210 20662ea0 2021-04-10 stsp #ifdef PROFILE
211 20662ea0 2021-04-10 stsp if (unveil("gmon.out", "rwc") != 0)
212 20662ea0 2021-04-10 stsp return got_error_from_errno2("unveil", "gmon.out");
214 20662ea0 2021-04-10 stsp if (repo_path && unveil(repo_path, repo_read_only ? "r" : "rwc") != 0)
215 20662ea0 2021-04-10 stsp return got_error_from_errno2("unveil", repo_path);
217 20662ea0 2021-04-10 stsp if (unveil(GOT_TMPDIR_STR, "rwc") != 0)
218 20662ea0 2021-04-10 stsp return got_error_from_errno2("unveil", GOT_TMPDIR_STR);
220 20662ea0 2021-04-10 stsp err = got_privsep_unveil_exec_helpers();
221 20662ea0 2021-04-10 stsp if (err != NULL)
222 20662ea0 2021-04-10 stsp return err;
224 20662ea0 2021-04-10 stsp if (unveil(NULL, NULL) != 0)
225 20662ea0 2021-04-10 stsp return got_error_from_errno("unveil");
227 20662ea0 2021-04-10 stsp return NULL;
230 20662ea0 2021-04-10 stsp __dead static void
231 20662ea0 2021-04-10 stsp usage_info(void)
233 20662ea0 2021-04-10 stsp fprintf(stderr, "usage: %s info [-r repository-path]\n",
234 20662ea0 2021-04-10 stsp getprogname());
238 20662ea0 2021-04-10 stsp static const struct got_error *
239 1ea7ccc6 2021-11-15 thomas get_repo_path(char **repo_path)
241 1ea7ccc6 2021-11-15 thomas const struct got_error *err = NULL;
242 1ea7ccc6 2021-11-15 thomas struct got_worktree *worktree = NULL;
243 1ea7ccc6 2021-11-15 thomas char *cwd;
245 1ea7ccc6 2021-11-15 thomas *repo_path = NULL;
247 1ea7ccc6 2021-11-15 thomas cwd = getcwd(NULL, 0);
248 1ea7ccc6 2021-11-15 thomas if (cwd == NULL)
249 1ea7ccc6 2021-11-15 thomas return got_error_from_errno("getcwd");
251 1ea7ccc6 2021-11-15 thomas err = got_worktree_open(&worktree, cwd);
252 1ea7ccc6 2021-11-15 thomas if (err) {
253 1ea7ccc6 2021-11-15 thomas if (err->code != GOT_ERR_NOT_WORKTREE)
254 1ea7ccc6 2021-11-15 thomas goto done;
255 1ea7ccc6 2021-11-15 thomas err = NULL;
258 1ea7ccc6 2021-11-15 thomas if (worktree)
259 1ea7ccc6 2021-11-15 thomas *repo_path = strdup(got_worktree_get_repo_path(worktree));
261 1ea7ccc6 2021-11-15 thomas *repo_path = strdup(cwd);
262 1ea7ccc6 2021-11-15 thomas if (*repo_path == NULL)
263 1ea7ccc6 2021-11-15 thomas err = got_error_from_errno("strdup");
265 1ea7ccc6 2021-11-15 thomas if (worktree)
266 1ea7ccc6 2021-11-15 thomas got_worktree_close(worktree);
267 1ea7ccc6 2021-11-15 thomas free(cwd);
268 1ea7ccc6 2021-11-15 thomas return err;
271 27b10c3c 2022-07-04 thomas __dead static void
272 27b10c3c 2022-07-04 thomas usage_init(void)
274 e9424ba1 2022-09-20 thomas fprintf(stderr, "usage: %s init [-b branch] repository-path\n",
275 e9424ba1 2022-09-20 thomas getprogname());
279 27b10c3c 2022-07-04 thomas static const struct got_error *
280 27b10c3c 2022-07-04 thomas cmd_init(int argc, char *argv[])
282 27b10c3c 2022-07-04 thomas const struct got_error *error = NULL;
283 e9424ba1 2022-09-20 thomas const char *head_name = NULL;
284 27b10c3c 2022-07-04 thomas char *repo_path = NULL;
287 a0abeae5 2023-02-17 thomas #ifndef PROFILE
288 a0abeae5 2023-02-17 thomas if (pledge("stdio rpath wpath cpath unveil", NULL) == -1)
289 a0abeae5 2023-02-17 thomas err(1, "pledge");
292 e9424ba1 2022-09-20 thomas while ((ch = getopt(argc, argv, "b:")) != -1) {
293 27b10c3c 2022-07-04 thomas switch (ch) {
294 e9424ba1 2022-09-20 thomas case 'b':
295 e9424ba1 2022-09-20 thomas head_name = optarg;
298 27b10c3c 2022-07-04 thomas usage_init();
299 27b10c3c 2022-07-04 thomas /* NOTREACHED */
303 27b10c3c 2022-07-04 thomas argc -= optind;
304 27b10c3c 2022-07-04 thomas argv += optind;
306 27b10c3c 2022-07-04 thomas if (argc != 1)
307 27b10c3c 2022-07-04 thomas usage_init();
309 27b10c3c 2022-07-04 thomas repo_path = strdup(argv[0]);
310 27b10c3c 2022-07-04 thomas if (repo_path == NULL)
311 27b10c3c 2022-07-04 thomas return got_error_from_errno("strdup");
313 27b10c3c 2022-07-04 thomas got_path_strip_trailing_slashes(repo_path);
315 27b10c3c 2022-07-04 thomas error = got_path_mkdir(repo_path);
316 27b10c3c 2022-07-04 thomas if (error &&
317 27b10c3c 2022-07-04 thomas !(error->code == GOT_ERR_ERRNO && errno == EEXIST))
318 27b10c3c 2022-07-04 thomas goto done;
320 27b10c3c 2022-07-04 thomas error = apply_unveil(repo_path, 0);
321 27b10c3c 2022-07-04 thomas if (error)
322 27b10c3c 2022-07-04 thomas goto done;
324 e9424ba1 2022-09-20 thomas error = got_repo_init(repo_path, head_name);
326 27b10c3c 2022-07-04 thomas free(repo_path);
327 27b10c3c 2022-07-04 thomas return error;
330 1ea7ccc6 2021-11-15 thomas static const struct got_error *
331 20662ea0 2021-04-10 stsp cmd_info(int argc, char *argv[])
333 20662ea0 2021-04-10 stsp const struct got_error *error = NULL;
334 1ea7ccc6 2021-11-15 thomas char *repo_path = NULL;
335 20662ea0 2021-04-10 stsp struct got_repository *repo = NULL;
336 20662ea0 2021-04-10 stsp const struct got_gotconfig *gotconfig = NULL;
337 20662ea0 2021-04-10 stsp int ch, npackfiles, npackedobj, nobj;
338 20662ea0 2021-04-10 stsp off_t packsize, loose_size;
339 20662ea0 2021-04-10 stsp char scaled[FMT_SCALED_STRSIZE];
340 7cd52833 2022-06-23 thomas int *pack_fds = NULL;
342 a0abeae5 2023-02-17 thomas #ifndef PROFILE
343 a0abeae5 2023-02-17 thomas if (pledge("stdio rpath wpath cpath flock proc exec sendfd unveil",
344 a0abeae5 2023-02-17 thomas NULL) == -1)
345 a0abeae5 2023-02-17 thomas err(1, "pledge");
348 20662ea0 2021-04-10 stsp while ((ch = getopt(argc, argv, "r:")) != -1) {
349 20662ea0 2021-04-10 stsp switch (ch) {
351 20662ea0 2021-04-10 stsp repo_path = realpath(optarg, NULL);
352 20662ea0 2021-04-10 stsp if (repo_path == NULL)
353 20662ea0 2021-04-10 stsp return got_error_from_errno2("realpath",
355 20662ea0 2021-04-10 stsp got_path_strip_trailing_slashes(repo_path);
358 20662ea0 2021-04-10 stsp usage_info();
359 20662ea0 2021-04-10 stsp /* NOTREACHED */
363 20662ea0 2021-04-10 stsp argc -= optind;
364 20662ea0 2021-04-10 stsp argv += optind;
366 1ea7ccc6 2021-11-15 thomas if (repo_path == NULL) {
367 1ea7ccc6 2021-11-15 thomas error = get_repo_path(&repo_path);
368 1ea7ccc6 2021-11-15 thomas if (error)
369 1ea7ccc6 2021-11-15 thomas goto done;
371 7cd52833 2022-06-23 thomas error = got_repo_pack_fds_open(&pack_fds);
372 7cd52833 2022-06-23 thomas if (error != NULL)
373 7cd52833 2022-06-23 thomas goto done;
374 7cd52833 2022-06-23 thomas error = got_repo_open(&repo, repo_path, NULL, pack_fds);
377 bfb5ee0b 2022-05-31 thomas #ifndef PROFILE
378 bfb5ee0b 2022-05-31 thomas /* Remove "cpath" promise. */
379 bfb5ee0b 2022-05-31 thomas if (pledge("stdio rpath wpath flock proc exec sendfd unveil",
380 bfb5ee0b 2022-05-31 thomas NULL) == -1)
381 bfb5ee0b 2022-05-31 thomas err(1, "pledge");
383 20662ea0 2021-04-10 stsp error = apply_unveil(got_repo_get_path_git_dir(repo), 1);
387 20662ea0 2021-04-10 stsp printf("repository: %s\n", got_repo_get_path_git_dir(repo));
389 20662ea0 2021-04-10 stsp gotconfig = got_repo_get_gotconfig(repo);
390 20662ea0 2021-04-10 stsp if (gotconfig) {
391 20662ea0 2021-04-10 stsp const struct got_remote_repo *remotes;
392 20662ea0 2021-04-10 stsp int i, nremotes;
393 20662ea0 2021-04-10 stsp if (got_gotconfig_get_author(gotconfig)) {
394 20662ea0 2021-04-10 stsp printf("default author: %s\n",
395 20662ea0 2021-04-10 stsp got_gotconfig_get_author(gotconfig));
397 20662ea0 2021-04-10 stsp got_gotconfig_get_remotes(&nremotes, &remotes, gotconfig);
398 20662ea0 2021-04-10 stsp for (i = 0; i < nremotes; i++) {
399 13b2084e 2021-09-06 stsp const char *fetch_url = remotes[i].fetch_url;
400 13b2084e 2021-09-06 stsp const char *send_url = remotes[i].send_url;
401 13b2084e 2021-09-06 stsp if (strcmp(fetch_url, send_url) == 0) {
402 13b2084e 2021-09-06 stsp printf("remote \"%s\": %s\n", remotes[i].name,
403 13b2084e 2021-09-06 stsp remotes[i].fetch_url);
405 13b2084e 2021-09-06 stsp printf("remote \"%s\" (fetch): %s\n",
406 13b2084e 2021-09-06 stsp remotes[i].name, remotes[i].fetch_url);
407 13b2084e 2021-09-06 stsp printf("remote \"%s\" (send): %s\n",
408 13b2084e 2021-09-06 stsp remotes[i].name, remotes[i].send_url);
413 20662ea0 2021-04-10 stsp error = got_repo_get_packfile_info(&npackfiles, &npackedobj,
414 20662ea0 2021-04-10 stsp &packsize, repo);
417 20662ea0 2021-04-10 stsp printf("pack files: %d\n", npackfiles);
418 20662ea0 2021-04-10 stsp if (npackfiles > 0) {
419 20662ea0 2021-04-10 stsp if (fmt_scaled(packsize, scaled) == -1) {
420 20662ea0 2021-04-10 stsp error = got_error_from_errno("fmt_scaled");
423 20662ea0 2021-04-10 stsp printf("packed objects: %d\n", npackedobj);
424 20662ea0 2021-04-10 stsp printf("packed total size: %s\n", scaled);
427 20662ea0 2021-04-10 stsp error = got_repo_get_loose_object_info(&nobj, &loose_size, repo);
430 20662ea0 2021-04-10 stsp printf("loose objects: %d\n", nobj);
431 20662ea0 2021-04-10 stsp if (nobj > 0) {
432 20662ea0 2021-04-10 stsp if (fmt_scaled(loose_size, scaled) == -1) {
433 20662ea0 2021-04-10 stsp error = got_error_from_errno("fmt_scaled");
436 20662ea0 2021-04-10 stsp printf("loose total size: %s\n", scaled);
440 20662ea0 2021-04-10 stsp got_repo_close(repo);
441 7cd52833 2022-06-23 thomas if (pack_fds) {
442 7cd52833 2022-06-23 thomas const struct got_error *pack_err =
443 7cd52833 2022-06-23 thomas got_repo_pack_fds_close(pack_fds);
444 7cd52833 2022-06-23 thomas if (error == NULL)
445 7cd52833 2022-06-23 thomas error = pack_err;
448 1ea7ccc6 2021-11-15 thomas free(repo_path);
449 20662ea0 2021-04-10 stsp return error;
452 05118f5a 2021-06-22 stsp __dead static void
453 05118f5a 2021-06-22 stsp usage_pack(void)
455 d6506a3d 2022-08-16 thomas fprintf(stderr, "usage: %s pack [-aq] [-r repository-path] "
456 d6506a3d 2022-08-16 thomas "[-x reference] [reference ...]\n", getprogname());
460 05118f5a 2021-06-22 stsp struct got_pack_progress_arg {
461 05118f5a 2021-06-22 stsp char last_scaled_size[FMT_SCALED_STRSIZE];
462 85220b0e 2022-03-22 thomas int last_ncolored;
463 85220b0e 2022-03-22 thomas int last_nfound;
464 85220b0e 2022-03-22 thomas int last_ntrees;
465 85220b0e 2022-03-22 thomas int loading_done;
466 05118f5a 2021-06-22 stsp int last_ncommits;
467 05118f5a 2021-06-22 stsp int last_nobj_total;
468 05118f5a 2021-06-22 stsp int last_p_deltify;
469 05118f5a 2021-06-22 stsp int last_p_written;
470 05118f5a 2021-06-22 stsp int last_p_indexed;
471 05118f5a 2021-06-22 stsp int last_p_resolved;
472 05118f5a 2021-06-22 stsp int verbosity;
473 05118f5a 2021-06-22 stsp int printed_something;
476 85220b0e 2022-03-22 thomas static void
477 85220b0e 2022-03-22 thomas print_load_info(int print_colored, int print_found, int print_trees,
478 85220b0e 2022-03-22 thomas int ncolored, int nfound, int ntrees)
480 85220b0e 2022-03-22 thomas if (print_colored) {
481 85220b0e 2022-03-22 thomas printf("%d commit%s colored", ncolored,
482 85220b0e 2022-03-22 thomas ncolored == 1 ? "" : "s");
484 85220b0e 2022-03-22 thomas if (print_found) {
485 85220b0e 2022-03-22 thomas printf("%s%d object%s found",
486 85220b0e 2022-03-22 thomas ncolored > 0 ? "; " : "",
487 85220b0e 2022-03-22 thomas nfound, nfound == 1 ? "" : "s");
489 85220b0e 2022-03-22 thomas if (print_trees) {
490 85220b0e 2022-03-22 thomas printf("; %d tree%s scanned", ntrees,
491 85220b0e 2022-03-22 thomas ntrees == 1 ? "" : "s");
495 05118f5a 2021-06-22 stsp static const struct got_error *
496 85220b0e 2022-03-22 thomas pack_progress(void *arg, int ncolored, int nfound, int ntrees,
497 85220b0e 2022-03-22 thomas off_t packfile_size, int ncommits, int nobj_total, int nobj_deltify,
498 85220b0e 2022-03-22 thomas int nobj_written)
500 05118f5a 2021-06-22 stsp struct got_pack_progress_arg *a = arg;
501 05118f5a 2021-06-22 stsp char scaled_size[FMT_SCALED_STRSIZE];
502 05118f5a 2021-06-22 stsp int p_deltify, p_written;
503 85220b0e 2022-03-22 thomas int print_colored = 0, print_found = 0, print_trees = 0;
504 05118f5a 2021-06-22 stsp int print_searching = 0, print_total = 0;
505 05118f5a 2021-06-22 stsp int print_deltify = 0, print_written = 0;
507 05118f5a 2021-06-22 stsp if (a->verbosity < 0)
508 85220b0e 2022-03-22 thomas return NULL;
510 85220b0e 2022-03-22 thomas if (a->last_ncolored != ncolored) {
511 85220b0e 2022-03-22 thomas print_colored = 1;
512 85220b0e 2022-03-22 thomas a->last_ncolored = ncolored;
515 85220b0e 2022-03-22 thomas if (a->last_nfound != nfound) {
516 85220b0e 2022-03-22 thomas print_colored = 1;
517 85220b0e 2022-03-22 thomas print_found = 1;
518 85220b0e 2022-03-22 thomas a->last_nfound = nfound;
521 85220b0e 2022-03-22 thomas if (a->last_ntrees != ntrees) {
522 85220b0e 2022-03-22 thomas print_colored = 1;
523 85220b0e 2022-03-22 thomas print_found = 1;
524 85220b0e 2022-03-22 thomas print_trees = 1;
525 85220b0e 2022-03-22 thomas a->last_ntrees = ntrees;
528 85220b0e 2022-03-22 thomas if ((print_colored || print_found || print_trees) &&
529 85220b0e 2022-03-22 thomas !a->loading_done) {
530 85220b0e 2022-03-22 thomas printf("\r");
531 85220b0e 2022-03-22 thomas print_load_info(print_colored, print_found, print_trees,
532 85220b0e 2022-03-22 thomas ncolored, nfound, ntrees);
533 85220b0e 2022-03-22 thomas a->printed_something = 1;
534 85220b0e 2022-03-22 thomas fflush(stdout);
535 05118f5a 2021-06-22 stsp return NULL;
536 85220b0e 2022-03-22 thomas } else if (!a->loading_done) {
537 85220b0e 2022-03-22 thomas printf("\r");
538 85220b0e 2022-03-22 thomas print_load_info(1, 1, 1, ncolored, nfound, ntrees);
539 85220b0e 2022-03-22 thomas printf("\n");
540 85220b0e 2022-03-22 thomas a->loading_done = 1;
543 05118f5a 2021-06-22 stsp if (fmt_scaled(packfile_size, scaled_size) == -1)
544 05118f5a 2021-06-22 stsp return got_error_from_errno("fmt_scaled");
546 05118f5a 2021-06-22 stsp if (a->last_ncommits != ncommits) {
547 05118f5a 2021-06-22 stsp print_searching = 1;
548 05118f5a 2021-06-22 stsp a->last_ncommits = ncommits;
551 05118f5a 2021-06-22 stsp if (a->last_nobj_total != nobj_total) {
552 05118f5a 2021-06-22 stsp print_searching = 1;
553 05118f5a 2021-06-22 stsp print_total = 1;
554 05118f5a 2021-06-22 stsp a->last_nobj_total = nobj_total;
557 05118f5a 2021-06-22 stsp if (packfile_size > 0 && (a->last_scaled_size[0] == '\0' ||
558 05118f5a 2021-06-22 stsp strcmp(scaled_size, a->last_scaled_size)) != 0) {
559 05118f5a 2021-06-22 stsp if (strlcpy(a->last_scaled_size, scaled_size,
560 05118f5a 2021-06-22 stsp FMT_SCALED_STRSIZE) >= FMT_SCALED_STRSIZE)
561 05118f5a 2021-06-22 stsp return got_error(GOT_ERR_NO_SPACE);
564 05118f5a 2021-06-22 stsp if (nobj_deltify > 0 || nobj_written > 0) {
565 05118f5a 2021-06-22 stsp if (nobj_deltify > 0) {
566 05118f5a 2021-06-22 stsp p_deltify = (nobj_deltify * 100) / nobj_total;
567 05118f5a 2021-06-22 stsp if (p_deltify != a->last_p_deltify) {
568 05118f5a 2021-06-22 stsp a->last_p_deltify = p_deltify;
569 05118f5a 2021-06-22 stsp print_searching = 1;
570 05118f5a 2021-06-22 stsp print_total = 1;
571 05118f5a 2021-06-22 stsp print_deltify = 1;
574 05118f5a 2021-06-22 stsp if (nobj_written > 0) {
575 05118f5a 2021-06-22 stsp p_written = (nobj_written * 100) / nobj_total;
576 05118f5a 2021-06-22 stsp if (p_written != a->last_p_written) {
577 05118f5a 2021-06-22 stsp a->last_p_written = p_written;
578 05118f5a 2021-06-22 stsp print_searching = 1;
579 05118f5a 2021-06-22 stsp print_total = 1;
580 05118f5a 2021-06-22 stsp print_deltify = 1;
581 05118f5a 2021-06-22 stsp print_written = 1;
586 05118f5a 2021-06-22 stsp if (print_searching || print_total || print_deltify || print_written)
587 05118f5a 2021-06-22 stsp printf("\r");
588 05118f5a 2021-06-22 stsp if (print_searching)
589 05118f5a 2021-06-22 stsp printf("packing %d reference%s", ncommits,
590 05118f5a 2021-06-22 stsp ncommits == 1 ? "" : "s");
591 05118f5a 2021-06-22 stsp if (print_total)
592 05118f5a 2021-06-22 stsp printf("; %d object%s", nobj_total,
593 05118f5a 2021-06-22 stsp nobj_total == 1 ? "" : "s");
594 05118f5a 2021-06-22 stsp if (print_deltify)
595 05118f5a 2021-06-22 stsp printf("; deltify: %d%%", p_deltify);
596 05118f5a 2021-06-22 stsp if (print_written)
597 d2f35ef7 2022-02-13 thomas printf("; writing pack: %*s %d%%", FMT_SCALED_STRSIZE - 2,
598 05118f5a 2021-06-22 stsp scaled_size, p_written);
599 05118f5a 2021-06-22 stsp if (print_searching || print_total || print_deltify ||
600 05118f5a 2021-06-22 stsp print_written) {
601 05118f5a 2021-06-22 stsp a->printed_something = 1;
602 05118f5a 2021-06-22 stsp fflush(stdout);
604 05118f5a 2021-06-22 stsp return NULL;
607 05118f5a 2021-06-22 stsp static const struct got_error *
608 05118f5a 2021-06-22 stsp pack_index_progress(void *arg, off_t packfile_size, int nobj_total,
609 05118f5a 2021-06-22 stsp int nobj_indexed, int nobj_loose, int nobj_resolved)
611 05118f5a 2021-06-22 stsp struct got_pack_progress_arg *a = arg;
612 05118f5a 2021-06-22 stsp char scaled_size[FMT_SCALED_STRSIZE];
613 05118f5a 2021-06-22 stsp int p_indexed, p_resolved;
614 05118f5a 2021-06-22 stsp int print_size = 0, print_indexed = 0, print_resolved = 0;
616 05118f5a 2021-06-22 stsp if (a->verbosity < 0)
617 05118f5a 2021-06-22 stsp return NULL;
619 05118f5a 2021-06-22 stsp if (packfile_size > 0 || nobj_indexed > 0) {
620 05118f5a 2021-06-22 stsp if (fmt_scaled(packfile_size, scaled_size) == 0 &&
621 05118f5a 2021-06-22 stsp (a->last_scaled_size[0] == '\0' ||
622 05118f5a 2021-06-22 stsp strcmp(scaled_size, a->last_scaled_size)) != 0) {
623 05118f5a 2021-06-22 stsp print_size = 1;
624 05118f5a 2021-06-22 stsp if (strlcpy(a->last_scaled_size, scaled_size,
625 05118f5a 2021-06-22 stsp FMT_SCALED_STRSIZE) >= FMT_SCALED_STRSIZE)
626 05118f5a 2021-06-22 stsp return got_error(GOT_ERR_NO_SPACE);
628 05118f5a 2021-06-22 stsp if (nobj_indexed > 0) {
629 05118f5a 2021-06-22 stsp p_indexed = (nobj_indexed * 100) / nobj_total;
630 05118f5a 2021-06-22 stsp if (p_indexed != a->last_p_indexed) {
631 05118f5a 2021-06-22 stsp a->last_p_indexed = p_indexed;
632 05118f5a 2021-06-22 stsp print_indexed = 1;
633 05118f5a 2021-06-22 stsp print_size = 1;
636 05118f5a 2021-06-22 stsp if (nobj_resolved > 0) {
637 05118f5a 2021-06-22 stsp p_resolved = (nobj_resolved * 100) /
638 05118f5a 2021-06-22 stsp (nobj_total - nobj_loose);
639 05118f5a 2021-06-22 stsp if (p_resolved != a->last_p_resolved) {
640 05118f5a 2021-06-22 stsp a->last_p_resolved = p_resolved;
641 05118f5a 2021-06-22 stsp print_resolved = 1;
642 05118f5a 2021-06-22 stsp print_indexed = 1;
643 05118f5a 2021-06-22 stsp print_size = 1;
648 05118f5a 2021-06-22 stsp if (print_size || print_indexed || print_resolved)
649 05118f5a 2021-06-22 stsp printf("\r");
650 05118f5a 2021-06-22 stsp if (print_size)
651 d2f35ef7 2022-02-13 thomas printf("%*s packed", FMT_SCALED_STRSIZE - 2, scaled_size);
652 05118f5a 2021-06-22 stsp if (print_indexed)
653 05118f5a 2021-06-22 stsp printf("; indexing %d%%", p_indexed);
654 05118f5a 2021-06-22 stsp if (print_resolved)
655 05118f5a 2021-06-22 stsp printf("; resolving deltas %d%%", p_resolved);
656 05118f5a 2021-06-22 stsp if (print_size || print_indexed || print_resolved)
657 05118f5a 2021-06-22 stsp fflush(stdout);
659 05118f5a 2021-06-22 stsp return NULL;
662 05118f5a 2021-06-22 stsp static const struct got_error *
663 05118f5a 2021-06-22 stsp add_ref(struct got_reflist_entry **new, struct got_reflist_head *refs,
664 05118f5a 2021-06-22 stsp const char *refname, struct got_repository *repo)
666 05118f5a 2021-06-22 stsp const struct got_error *err;
667 05118f5a 2021-06-22 stsp struct got_reference *ref;
669 05118f5a 2021-06-22 stsp *new = NULL;
671 05118f5a 2021-06-22 stsp err = got_ref_open(&ref, repo, refname, 0);
673 05118f5a 2021-06-22 stsp if (err->code != GOT_ERR_NOT_REF)
674 05118f5a 2021-06-22 stsp return err;
676 05118f5a 2021-06-22 stsp /* Treat argument as a reference prefix. */
677 05118f5a 2021-06-22 stsp err = got_ref_list(refs, repo, refname,
678 05118f5a 2021-06-22 stsp got_ref_cmp_by_name, NULL);
680 72acb3d8 2021-08-06 stsp err = got_reflist_insert(new, refs, ref,
681 05118f5a 2021-06-22 stsp got_ref_cmp_by_name, NULL);
682 05118f5a 2021-06-22 stsp if (err || *new == NULL /* duplicate */)
683 05118f5a 2021-06-22 stsp got_ref_close(ref);
686 05118f5a 2021-06-22 stsp return err;
689 05118f5a 2021-06-22 stsp static const struct got_error *
690 05118f5a 2021-06-22 stsp cmd_pack(int argc, char *argv[])
692 05118f5a 2021-06-22 stsp const struct got_error *error = NULL;
693 1ea7ccc6 2021-11-15 thomas char *repo_path = NULL;
694 05118f5a 2021-06-22 stsp struct got_repository *repo = NULL;
695 c8fc6d14 2022-04-16 thomas int ch, i, loose_obj_only = 1, verbosity = 0;
696 05118f5a 2021-06-22 stsp struct got_object_id *pack_hash = NULL;
697 05118f5a 2021-06-22 stsp char *id_str = NULL;
698 05118f5a 2021-06-22 stsp struct got_pack_progress_arg ppa;
699 05118f5a 2021-06-22 stsp FILE *packfile = NULL;
700 05118f5a 2021-06-22 stsp struct got_pathlist_head exclude_args;
701 05118f5a 2021-06-22 stsp struct got_pathlist_entry *pe;
702 05118f5a 2021-06-22 stsp struct got_reflist_head exclude_refs;
703 05118f5a 2021-06-22 stsp struct got_reflist_head include_refs;
704 05118f5a 2021-06-22 stsp struct got_reflist_entry *re, *new;
705 7cd52833 2022-06-23 thomas int *pack_fds = NULL;
707 05118f5a 2021-06-22 stsp TAILQ_INIT(&exclude_args);
708 05118f5a 2021-06-22 stsp TAILQ_INIT(&exclude_refs);
709 05118f5a 2021-06-22 stsp TAILQ_INIT(&include_refs);
711 a0abeae5 2023-02-17 thomas #ifndef PROFILE
712 a0abeae5 2023-02-17 thomas if (pledge("stdio rpath wpath cpath fattr flock proc exec sendfd unveil",
713 a0abeae5 2023-02-17 thomas NULL) == -1)
714 a0abeae5 2023-02-17 thomas err(1, "pledge");
717 f7065961 2022-10-27 thomas while ((ch = getopt(argc, argv, "aqr:x:")) != -1) {
718 05118f5a 2021-06-22 stsp switch (ch) {
720 05118f5a 2021-06-22 stsp loose_obj_only = 0;
722 f7065961 2022-10-27 thomas case 'q':
723 f7065961 2022-10-27 thomas verbosity = -1;
726 05118f5a 2021-06-22 stsp repo_path = realpath(optarg, NULL);
727 05118f5a 2021-06-22 stsp if (repo_path == NULL)
728 05118f5a 2021-06-22 stsp return got_error_from_errno2("realpath",
730 05118f5a 2021-06-22 stsp got_path_strip_trailing_slashes(repo_path);
733 05118f5a 2021-06-22 stsp got_path_strip_trailing_slashes(optarg);
734 05118f5a 2021-06-22 stsp error = got_pathlist_append(&exclude_args,
735 05118f5a 2021-06-22 stsp optarg, NULL);
737 05118f5a 2021-06-22 stsp return error;
740 05118f5a 2021-06-22 stsp usage_pack();
741 05118f5a 2021-06-22 stsp /* NOTREACHED */
745 05118f5a 2021-06-22 stsp argc -= optind;
746 05118f5a 2021-06-22 stsp argv += optind;
748 1ea7ccc6 2021-11-15 thomas if (repo_path == NULL) {
749 1ea7ccc6 2021-11-15 thomas error = get_repo_path(&repo_path);
750 1ea7ccc6 2021-11-15 thomas if (error)
751 1ea7ccc6 2021-11-15 thomas goto done;
753 7cd52833 2022-06-23 thomas error = got_repo_pack_fds_open(&pack_fds);
754 7cd52833 2022-06-23 thomas if (error != NULL)
755 7cd52833 2022-06-23 thomas goto done;
756 7cd52833 2022-06-23 thomas error = got_repo_open(&repo, repo_path, NULL, pack_fds);
760 bb5126ea 2021-06-22 stsp error = apply_unveil(got_repo_get_path_git_dir(repo), 0);
764 05118f5a 2021-06-22 stsp TAILQ_FOREACH(pe, &exclude_args, entry) {
765 05118f5a 2021-06-22 stsp const char *refname = pe->path;
766 05118f5a 2021-06-22 stsp error = add_ref(&new, &exclude_refs, refname, repo);
771 05118f5a 2021-06-22 stsp if (argc == 0) {
772 05118f5a 2021-06-22 stsp error = got_ref_list(&include_refs, repo, "",
773 05118f5a 2021-06-22 stsp got_ref_cmp_by_name, NULL);
777 05118f5a 2021-06-22 stsp for (i = 0; i < argc; i++) {
778 05118f5a 2021-06-22 stsp const char *refname;
779 05118f5a 2021-06-22 stsp got_path_strip_trailing_slashes(argv[i]);
780 05118f5a 2021-06-22 stsp refname = argv[i];
781 05118f5a 2021-06-22 stsp error = add_ref(&new, &include_refs, refname, repo);
787 05118f5a 2021-06-22 stsp /* Ignore references in the refs/got/ namespace. */
788 05118f5a 2021-06-22 stsp TAILQ_FOREACH_SAFE(re, &include_refs, entry, new) {
789 05118f5a 2021-06-22 stsp const char *refname = got_ref_get_name(re->ref);
790 05118f5a 2021-06-22 stsp if (strncmp("refs/got/", refname, 9) != 0)
792 05118f5a 2021-06-22 stsp TAILQ_REMOVE(&include_refs, re, entry);
793 05118f5a 2021-06-22 stsp got_ref_close(re->ref);
797 05118f5a 2021-06-22 stsp memset(&ppa, 0, sizeof(ppa));
798 05118f5a 2021-06-22 stsp ppa.last_scaled_size[0] = '\0';
799 05118f5a 2021-06-22 stsp ppa.last_p_indexed = -1;
800 05118f5a 2021-06-22 stsp ppa.last_p_resolved = -1;
801 c8fc6d14 2022-04-16 thomas ppa.verbosity = verbosity;
803 05118f5a 2021-06-22 stsp error = got_repo_pack_objects(&packfile, &pack_hash,
804 05118f5a 2021-06-22 stsp &include_refs, &exclude_refs, repo, loose_obj_only,
805 05118f5a 2021-06-22 stsp pack_progress, &ppa, check_cancelled, NULL);
806 05118f5a 2021-06-22 stsp if (error) {
807 05118f5a 2021-06-22 stsp if (ppa.printed_something)
808 05118f5a 2021-06-22 stsp printf("\n");
812 05118f5a 2021-06-22 stsp error = got_object_id_str(&id_str, pack_hash);
815 c8fc6d14 2022-04-16 thomas if (verbosity >= 0)
816 c8fc6d14 2022-04-16 thomas printf("\nWrote %s.pack\n", id_str);
818 05118f5a 2021-06-22 stsp error = got_repo_index_pack(packfile, pack_hash, repo,
819 05118f5a 2021-06-22 stsp pack_index_progress, &ppa, check_cancelled, NULL);
822 c8fc6d14 2022-04-16 thomas if (verbosity >= 0)
823 c8fc6d14 2022-04-16 thomas printf("\nIndexed %s.pack\n", id_str);
825 c75a6067 2021-10-15 thomas if (repo)
826 c75a6067 2021-10-15 thomas got_repo_close(repo);
827 7cd52833 2022-06-23 thomas if (pack_fds) {
828 7cd52833 2022-06-23 thomas const struct got_error *pack_err =
829 7cd52833 2022-06-23 thomas got_repo_pack_fds_close(pack_fds);
830 7cd52833 2022-06-23 thomas if (error == NULL)
831 7cd52833 2022-06-23 thomas error = pack_err;
833 21c2d8be 2023-01-10 thomas got_pathlist_free(&exclude_args, GOT_PATHLIST_FREE_NONE);
834 05118f5a 2021-06-22 stsp got_ref_list_free(&exclude_refs);
835 05118f5a 2021-06-22 stsp got_ref_list_free(&include_refs);
836 05118f5a 2021-06-22 stsp free(id_str);
837 05118f5a 2021-06-22 stsp free(pack_hash);
838 1ea7ccc6 2021-11-15 thomas free(repo_path);
839 05118f5a 2021-06-22 stsp return error;
842 05118f5a 2021-06-22 stsp __dead static void
843 05118f5a 2021-06-22 stsp usage_indexpack(void)
845 05118f5a 2021-06-22 stsp fprintf(stderr, "usage: %s indexpack packfile-path\n",
846 05118f5a 2021-06-22 stsp getprogname());
850 05118f5a 2021-06-22 stsp static const struct got_error *
851 05118f5a 2021-06-22 stsp cmd_indexpack(int argc, char *argv[])
853 05118f5a 2021-06-22 stsp const struct got_error *error = NULL;
854 05118f5a 2021-06-22 stsp struct got_repository *repo = NULL;
856 05118f5a 2021-06-22 stsp struct got_object_id *pack_hash = NULL;
857 05118f5a 2021-06-22 stsp char *packfile_path = NULL;
858 05118f5a 2021-06-22 stsp char *id_str = NULL;
859 05118f5a 2021-06-22 stsp struct got_pack_progress_arg ppa;
860 05118f5a 2021-06-22 stsp FILE *packfile = NULL;
861 7cd52833 2022-06-23 thomas int *pack_fds = NULL;
863 05118f5a 2021-06-22 stsp while ((ch = getopt(argc, argv, "")) != -1) {
864 05118f5a 2021-06-22 stsp switch (ch) {
866 05118f5a 2021-06-22 stsp usage_indexpack();
867 05118f5a 2021-06-22 stsp /* NOTREACHED */
871 05118f5a 2021-06-22 stsp argc -= optind;
872 05118f5a 2021-06-22 stsp argv += optind;
874 05118f5a 2021-06-22 stsp if (argc != 1)
875 05118f5a 2021-06-22 stsp usage_indexpack();
877 05118f5a 2021-06-22 stsp packfile_path = realpath(argv[0], NULL);
878 05118f5a 2021-06-22 stsp if (packfile_path == NULL)
879 05118f5a 2021-06-22 stsp return got_error_from_errno2("realpath", argv[0]);
881 05118f5a 2021-06-22 stsp #ifndef PROFILE
882 05118f5a 2021-06-22 stsp if (pledge("stdio rpath wpath cpath fattr flock proc exec sendfd unveil",
883 05118f5a 2021-06-22 stsp NULL) == -1)
884 05118f5a 2021-06-22 stsp err(1, "pledge");
887 7cd52833 2022-06-23 thomas error = got_repo_pack_fds_open(&pack_fds);
888 7cd52833 2022-06-23 thomas if (error != NULL)
889 7cd52833 2022-06-23 thomas goto done;
890 7cd52833 2022-06-23 thomas error = got_repo_open(&repo, packfile_path, NULL, pack_fds);
894 001a95cd 2021-10-15 thomas error = apply_unveil(got_repo_get_path_git_dir(repo), 0);
898 05118f5a 2021-06-22 stsp memset(&ppa, 0, sizeof(ppa));
899 05118f5a 2021-06-22 stsp ppa.last_scaled_size[0] = '\0';
900 05118f5a 2021-06-22 stsp ppa.last_p_indexed = -1;
901 05118f5a 2021-06-22 stsp ppa.last_p_resolved = -1;
903 05118f5a 2021-06-22 stsp error = got_repo_find_pack(&packfile, &pack_hash, repo,
904 05118f5a 2021-06-22 stsp packfile_path);
908 05118f5a 2021-06-22 stsp error = got_object_id_str(&id_str, pack_hash);
912 05118f5a 2021-06-22 stsp error = got_repo_index_pack(packfile, pack_hash, repo,
913 05118f5a 2021-06-22 stsp pack_index_progress, &ppa, check_cancelled, NULL);
916 05118f5a 2021-06-22 stsp printf("\nIndexed %s.pack\n", id_str);
918 c75a6067 2021-10-15 thomas if (repo)
919 c75a6067 2021-10-15 thomas got_repo_close(repo);
920 7cd52833 2022-06-23 thomas if (pack_fds) {
921 7cd52833 2022-06-23 thomas const struct got_error *pack_err =
922 7cd52833 2022-06-23 thomas got_repo_pack_fds_close(pack_fds);
923 7cd52833 2022-06-23 thomas if (error == NULL)
924 7cd52833 2022-06-23 thomas error = pack_err;
926 05118f5a 2021-06-22 stsp free(id_str);
927 05118f5a 2021-06-22 stsp free(pack_hash);
928 05118f5a 2021-06-22 stsp return error;
931 05118f5a 2021-06-22 stsp __dead static void
932 05118f5a 2021-06-22 stsp usage_listpack(void)
934 d6506a3d 2022-08-16 thomas fprintf(stderr, "usage: %s listpack [-hs] packfile-path\n",
935 05118f5a 2021-06-22 stsp getprogname());
939 05118f5a 2021-06-22 stsp struct gotadmin_list_pack_cb_args {
940 05118f5a 2021-06-22 stsp int nblobs;
941 05118f5a 2021-06-22 stsp int ntrees;
942 05118f5a 2021-06-22 stsp int ncommits;
944 05118f5a 2021-06-22 stsp int noffdeltas;
945 05118f5a 2021-06-22 stsp int nrefdeltas;
946 05118f5a 2021-06-22 stsp int human_readable;
949 05118f5a 2021-06-22 stsp static const struct got_error *
950 05118f5a 2021-06-22 stsp list_pack_cb(void *arg, struct got_object_id *id, int type, off_t offset,
951 05118f5a 2021-06-22 stsp off_t size, off_t base_offset, struct got_object_id *base_id)
953 05118f5a 2021-06-22 stsp const struct got_error *err;
954 05118f5a 2021-06-22 stsp struct gotadmin_list_pack_cb_args *a = arg;
955 05118f5a 2021-06-22 stsp char *id_str, *delta_str = NULL, *base_id_str = NULL;
956 05118f5a 2021-06-22 stsp const char *type_str;
958 7cd52833 2022-06-23 thomas err = got_object_id_str(&id_str, id);
960 05118f5a 2021-06-22 stsp return err;
962 05118f5a 2021-06-22 stsp switch (type) {
963 05118f5a 2021-06-22 stsp case GOT_OBJ_TYPE_BLOB:
964 05118f5a 2021-06-22 stsp type_str = GOT_OBJ_LABEL_BLOB;
965 05118f5a 2021-06-22 stsp a->nblobs++;
967 05118f5a 2021-06-22 stsp case GOT_OBJ_TYPE_TREE:
968 05118f5a 2021-06-22 stsp type_str = GOT_OBJ_LABEL_TREE;
969 05118f5a 2021-06-22 stsp a->ntrees++;
971 05118f5a 2021-06-22 stsp case GOT_OBJ_TYPE_COMMIT:
972 05118f5a 2021-06-22 stsp type_str = GOT_OBJ_LABEL_COMMIT;
973 05118f5a 2021-06-22 stsp a->ncommits++;
975 05118f5a 2021-06-22 stsp case GOT_OBJ_TYPE_TAG:
976 05118f5a 2021-06-22 stsp type_str = GOT_OBJ_LABEL_TAG;
977 05118f5a 2021-06-22 stsp a->ntags++;
979 05118f5a 2021-06-22 stsp case GOT_OBJ_TYPE_OFFSET_DELTA:
980 05118f5a 2021-06-22 stsp type_str = "offset-delta";
981 c414a013 2021-09-25 thomas.ad if (asprintf(&delta_str, " base-offset %lld",
982 c414a013 2021-09-25 thomas.ad (long long)base_offset) == -1) {
983 05118f5a 2021-06-22 stsp err = got_error_from_errno("asprintf");
986 05118f5a 2021-06-22 stsp a->noffdeltas++;
988 05118f5a 2021-06-22 stsp case GOT_OBJ_TYPE_REF_DELTA:
989 05118f5a 2021-06-22 stsp type_str = "ref-delta";
990 b6b86fd1 2022-08-30 thomas err = got_object_id_str(&base_id_str, base_id);
993 05118f5a 2021-06-22 stsp if (asprintf(&delta_str, " base-id %s", base_id_str) == -1) {
994 05118f5a 2021-06-22 stsp err = got_error_from_errno("asprintf");
997 05118f5a 2021-06-22 stsp a->nrefdeltas++;
1000 05118f5a 2021-06-22 stsp err = got_error(GOT_ERR_OBJ_TYPE);
1001 05118f5a 2021-06-22 stsp goto done;
1003 05118f5a 2021-06-22 stsp if (a->human_readable) {
1004 05118f5a 2021-06-22 stsp char scaled[FMT_SCALED_STRSIZE];
1006 05118f5a 2021-06-22 stsp if (fmt_scaled(size, scaled) == -1) {
1007 05118f5a 2021-06-22 stsp err = got_error_from_errno("fmt_scaled");
1008 05118f5a 2021-06-22 stsp goto done;
1010 05118f5a 2021-06-22 stsp s = scaled;
1011 05118f5a 2021-06-22 stsp while (isspace((unsigned char)*s))
1013 c414a013 2021-09-25 thomas.ad printf("%s %s at %lld size %s%s\n", id_str, type_str,
1014 c414a013 2021-09-25 thomas.ad (long long)offset, s, delta_str ? delta_str : "");
1016 c414a013 2021-09-25 thomas.ad printf("%s %s at %lld size %lld%s\n", id_str, type_str,
1017 c414a013 2021-09-25 thomas.ad (long long)offset, (long long)size,
1018 c414a013 2021-09-25 thomas.ad delta_str ? delta_str : "");
1021 05118f5a 2021-06-22 stsp free(id_str);
1022 05118f5a 2021-06-22 stsp free(base_id_str);
1023 05118f5a 2021-06-22 stsp free(delta_str);
1024 05118f5a 2021-06-22 stsp return err;
1027 05118f5a 2021-06-22 stsp static const struct got_error *
1028 05118f5a 2021-06-22 stsp cmd_listpack(int argc, char *argv[])
1030 05118f5a 2021-06-22 stsp const struct got_error *error = NULL;
1031 05118f5a 2021-06-22 stsp struct got_repository *repo = NULL;
1033 05118f5a 2021-06-22 stsp struct got_object_id *pack_hash = NULL;
1034 05118f5a 2021-06-22 stsp char *packfile_path = NULL;
1035 05118f5a 2021-06-22 stsp char *id_str = NULL;
1036 05118f5a 2021-06-22 stsp struct gotadmin_list_pack_cb_args lpa;
1037 05118f5a 2021-06-22 stsp FILE *packfile = NULL;
1038 05118f5a 2021-06-22 stsp int show_stats = 0, human_readable = 0;
1039 7cd52833 2022-06-23 thomas int *pack_fds = NULL;
1041 a0abeae5 2023-02-17 thomas #ifndef PROFILE
1042 a0abeae5 2023-02-17 thomas if (pledge("stdio rpath wpath cpath flock proc exec sendfd unveil",
1043 a0abeae5 2023-02-17 thomas NULL) == -1)
1044 a0abeae5 2023-02-17 thomas err(1, "pledge");
1047 05118f5a 2021-06-22 stsp while ((ch = getopt(argc, argv, "hs")) != -1) {
1048 05118f5a 2021-06-22 stsp switch (ch) {
1050 05118f5a 2021-06-22 stsp human_readable = 1;
1053 05118f5a 2021-06-22 stsp show_stats = 1;
1056 05118f5a 2021-06-22 stsp usage_listpack();
1057 05118f5a 2021-06-22 stsp /* NOTREACHED */
1061 05118f5a 2021-06-22 stsp argc -= optind;
1062 05118f5a 2021-06-22 stsp argv += optind;
1064 05118f5a 2021-06-22 stsp if (argc != 1)
1065 05118f5a 2021-06-22 stsp usage_listpack();
1066 05118f5a 2021-06-22 stsp packfile_path = realpath(argv[0], NULL);
1067 05118f5a 2021-06-22 stsp if (packfile_path == NULL)
1068 05118f5a 2021-06-22 stsp return got_error_from_errno2("realpath", argv[0]);
1070 7cd52833 2022-06-23 thomas error = got_repo_pack_fds_open(&pack_fds);
1071 7cd52833 2022-06-23 thomas if (error != NULL)
1072 7cd52833 2022-06-23 thomas goto done;
1073 7cd52833 2022-06-23 thomas error = got_repo_open(&repo, packfile_path, NULL, pack_fds);
1074 05118f5a 2021-06-22 stsp if (error)
1075 05118f5a 2021-06-22 stsp goto done;
1076 bfb5ee0b 2022-05-31 thomas #ifndef PROFILE
1077 bfb5ee0b 2022-05-31 thomas /* Remove "cpath" promise. */
1078 bfb5ee0b 2022-05-31 thomas if (pledge("stdio rpath wpath flock proc exec sendfd unveil",
1079 bfb5ee0b 2022-05-31 thomas NULL) == -1)
1080 bfb5ee0b 2022-05-31 thomas err(1, "pledge");
1082 05118f5a 2021-06-22 stsp error = apply_unveil(got_repo_get_path_git_dir(repo), 1);
1083 05118f5a 2021-06-22 stsp if (error)
1084 05118f5a 2021-06-22 stsp goto done;
1086 05118f5a 2021-06-22 stsp error = got_repo_find_pack(&packfile, &pack_hash, repo,
1087 05118f5a 2021-06-22 stsp packfile_path);
1088 05118f5a 2021-06-22 stsp if (error)
1089 05118f5a 2021-06-22 stsp goto done;
1090 05118f5a 2021-06-22 stsp error = got_object_id_str(&id_str, pack_hash);
1091 05118f5a 2021-06-22 stsp if (error)
1092 05118f5a 2021-06-22 stsp goto done;
1094 05118f5a 2021-06-22 stsp memset(&lpa, 0, sizeof(lpa));
1095 05118f5a 2021-06-22 stsp lpa.human_readable = human_readable;
1096 05118f5a 2021-06-22 stsp error = got_repo_list_pack(packfile, pack_hash, repo,
1097 05118f5a 2021-06-22 stsp list_pack_cb, &lpa, check_cancelled, NULL);
1098 05118f5a 2021-06-22 stsp if (error)
1099 05118f5a 2021-06-22 stsp goto done;
1100 05118f5a 2021-06-22 stsp if (show_stats) {
1101 05118f5a 2021-06-22 stsp printf("objects: %d\n blobs: %d\n trees: %d\n commits: %d\n"
1102 05118f5a 2021-06-22 stsp " tags: %d\n offset-deltas: %d\n ref-deltas: %d\n",
1103 05118f5a 2021-06-22 stsp lpa.nblobs + lpa.ntrees + lpa.ncommits + lpa.ntags +
1104 05118f5a 2021-06-22 stsp lpa.noffdeltas + lpa.nrefdeltas,
1105 05118f5a 2021-06-22 stsp lpa.nblobs, lpa.ntrees, lpa.ncommits, lpa.ntags,
1106 05118f5a 2021-06-22 stsp lpa.noffdeltas, lpa.nrefdeltas);
1109 c75a6067 2021-10-15 thomas if (repo)
1110 c75a6067 2021-10-15 thomas got_repo_close(repo);
1111 7cd52833 2022-06-23 thomas if (pack_fds) {
1112 7cd52833 2022-06-23 thomas const struct got_error *pack_err =
1113 7cd52833 2022-06-23 thomas got_repo_pack_fds_close(pack_fds);
1114 7cd52833 2022-06-23 thomas if (error == NULL)
1115 7cd52833 2022-06-23 thomas error = pack_err;
1117 05118f5a 2021-06-22 stsp free(id_str);
1118 05118f5a 2021-06-22 stsp free(pack_hash);
1119 05118f5a 2021-06-22 stsp free(packfile_path);
1120 05118f5a 2021-06-22 stsp return error;
1123 b3d68e7f 2021-07-03 stsp __dead static void
1124 b3d68e7f 2021-07-03 stsp usage_cleanup(void)
1126 d6506a3d 2022-08-16 thomas fprintf(stderr, "usage: %s cleanup [-anpq] [-r repository-path]\n",
1127 d6506a3d 2022-08-16 thomas getprogname());
1131 b3d68e7f 2021-07-03 stsp struct got_cleanup_progress_arg {
1132 b3d68e7f 2021-07-03 stsp int last_nloose;
1133 b3d68e7f 2021-07-03 stsp int last_ncommits;
1134 b3d68e7f 2021-07-03 stsp int last_npurged;
1135 b3d68e7f 2021-07-03 stsp int verbosity;
1136 b3d68e7f 2021-07-03 stsp int printed_something;
1137 b3d68e7f 2021-07-03 stsp int dry_run;
1140 b3d68e7f 2021-07-03 stsp static const struct got_error *
1141 b3d68e7f 2021-07-03 stsp cleanup_progress(void *arg, int nloose, int ncommits, int npurged)
1143 b3d68e7f 2021-07-03 stsp struct got_cleanup_progress_arg *a = arg;
1144 b3d68e7f 2021-07-03 stsp int print_loose = 0, print_commits = 0, print_purged = 0;
1146 b3d68e7f 2021-07-03 stsp if (a->last_nloose != nloose) {
1147 b3d68e7f 2021-07-03 stsp print_loose = 1;
1148 b3d68e7f 2021-07-03 stsp a->last_nloose = nloose;
1150 b3d68e7f 2021-07-03 stsp if (a->last_ncommits != ncommits) {
1151 b3d68e7f 2021-07-03 stsp print_loose = 1;
1152 b3d68e7f 2021-07-03 stsp print_commits = 1;
1153 b3d68e7f 2021-07-03 stsp a->last_ncommits = ncommits;
1155 b3d68e7f 2021-07-03 stsp if (a->last_npurged != npurged) {
1156 b3d68e7f 2021-07-03 stsp print_loose = 1;
1157 b3d68e7f 2021-07-03 stsp print_commits = 1;
1158 b3d68e7f 2021-07-03 stsp print_purged = 1;
1159 b3d68e7f 2021-07-03 stsp a->last_npurged = npurged;
1162 b3d68e7f 2021-07-03 stsp if (a->verbosity < 0)
1163 b3d68e7f 2021-07-03 stsp return NULL;
1165 b3d68e7f 2021-07-03 stsp if (print_loose || print_commits || print_purged)
1166 b3d68e7f 2021-07-03 stsp printf("\r");
1167 b3d68e7f 2021-07-03 stsp if (print_loose)
1168 b3d68e7f 2021-07-03 stsp printf("%d loose object%s", nloose, nloose == 1 ? "" : "s");
1169 b3d68e7f 2021-07-03 stsp if (print_commits)
1170 b3d68e7f 2021-07-03 stsp printf("; %d commit%s scanned", ncommits,
1171 b3d68e7f 2021-07-03 stsp ncommits == 1 ? "" : "s");
1172 b3d68e7f 2021-07-03 stsp if (print_purged) {
1173 b3d68e7f 2021-07-03 stsp if (a->dry_run) {
1174 b3d68e7f 2021-07-03 stsp printf("; %d object%s could be purged", npurged,
1175 b3d68e7f 2021-07-03 stsp npurged == 1 ? "" : "s");
1177 b3d68e7f 2021-07-03 stsp printf("; %d object%s purged", npurged,
1178 b3d68e7f 2021-07-03 stsp npurged == 1 ? "" : "s");
1181 b3d68e7f 2021-07-03 stsp if (print_loose || print_commits || print_purged) {
1182 b3d68e7f 2021-07-03 stsp a->printed_something = 1;
1183 b3d68e7f 2021-07-03 stsp fflush(stdout);
1185 b3d68e7f 2021-07-03 stsp return NULL;
1188 1124fe40 2021-07-07 stsp struct got_lonely_packidx_progress_arg {
1189 1124fe40 2021-07-07 stsp int verbosity;
1190 1124fe40 2021-07-07 stsp int printed_something;
1191 1124fe40 2021-07-07 stsp int dry_run;
1194 b3d68e7f 2021-07-03 stsp static const struct got_error *
1195 1124fe40 2021-07-07 stsp lonely_packidx_progress(void *arg, const char *path)
1197 1124fe40 2021-07-07 stsp struct got_lonely_packidx_progress_arg *a = arg;
1199 1124fe40 2021-07-07 stsp if (a->verbosity < 0)
1200 1124fe40 2021-07-07 stsp return NULL;
1202 1124fe40 2021-07-07 stsp if (a->dry_run)
1203 1124fe40 2021-07-07 stsp printf("%s could be removed\n", path);
1205 1124fe40 2021-07-07 stsp printf("%s removed\n", path);
1207 1124fe40 2021-07-07 stsp a->printed_something = 1;
1208 1124fe40 2021-07-07 stsp return NULL;
1211 1124fe40 2021-07-07 stsp static const struct got_error *
1212 b3d68e7f 2021-07-03 stsp cmd_cleanup(int argc, char *argv[])
1214 b3d68e7f 2021-07-03 stsp const struct got_error *error = NULL;
1215 1ea7ccc6 2021-11-15 thomas char *repo_path = NULL;
1216 b3d68e7f 2021-07-03 stsp struct got_repository *repo = NULL;
1217 b3d68e7f 2021-07-03 stsp int ch, dry_run = 0, npacked = 0, verbosity = 0;
1218 ef8ec606 2021-07-27 stsp int remove_lonely_packidx = 0, ignore_mtime = 0;
1219 b3d68e7f 2021-07-03 stsp struct got_cleanup_progress_arg cpa;
1220 1124fe40 2021-07-07 stsp struct got_lonely_packidx_progress_arg lpa;
1221 b3d68e7f 2021-07-03 stsp off_t size_before, size_after;
1222 b3d68e7f 2021-07-03 stsp char scaled_before[FMT_SCALED_STRSIZE];
1223 b3d68e7f 2021-07-03 stsp char scaled_after[FMT_SCALED_STRSIZE];
1224 b3d68e7f 2021-07-03 stsp char scaled_diff[FMT_SCALED_STRSIZE];
1225 7cd52833 2022-06-23 thomas int *pack_fds = NULL;
1227 a0abeae5 2023-02-17 thomas #ifndef PROFILE
1228 a0abeae5 2023-02-17 thomas if (pledge("stdio rpath wpath cpath flock proc exec sendfd unveil",
1229 a0abeae5 2023-02-17 thomas NULL) == -1)
1230 a0abeae5 2023-02-17 thomas err(1, "pledge");
1233 f7065961 2022-10-27 thomas while ((ch = getopt(argc, argv, "anpqr:")) != -1) {
1234 b3d68e7f 2021-07-03 stsp switch (ch) {
1236 ef8ec606 2021-07-27 stsp ignore_mtime = 1;
1238 f7065961 2022-10-27 thomas case 'n':
1239 f7065961 2022-10-27 thomas dry_run = 1;
1242 1124fe40 2021-07-07 stsp remove_lonely_packidx = 1;
1244 f7065961 2022-10-27 thomas case 'q':
1245 f7065961 2022-10-27 thomas verbosity = -1;
1248 b3d68e7f 2021-07-03 stsp repo_path = realpath(optarg, NULL);
1249 b3d68e7f 2021-07-03 stsp if (repo_path == NULL)
1250 b3d68e7f 2021-07-03 stsp return got_error_from_errno2("realpath",
1252 b3d68e7f 2021-07-03 stsp got_path_strip_trailing_slashes(repo_path);
1255 b3d68e7f 2021-07-03 stsp usage_cleanup();
1256 b3d68e7f 2021-07-03 stsp /* NOTREACHED */
1260 b3d68e7f 2021-07-03 stsp argc -= optind;
1261 b3d68e7f 2021-07-03 stsp argv += optind;
1263 1ea7ccc6 2021-11-15 thomas if (repo_path == NULL) {
1264 1ea7ccc6 2021-11-15 thomas error = get_repo_path(&repo_path);
1265 1ea7ccc6 2021-11-15 thomas if (error)
1266 1ea7ccc6 2021-11-15 thomas goto done;
1268 7cd52833 2022-06-23 thomas error = got_repo_pack_fds_open(&pack_fds);
1269 7cd52833 2022-06-23 thomas if (error != NULL)
1270 7cd52833 2022-06-23 thomas goto done;
1271 7cd52833 2022-06-23 thomas error = got_repo_open(&repo, repo_path, NULL, pack_fds);
1272 b3d68e7f 2021-07-03 stsp if (error)
1273 b3d68e7f 2021-07-03 stsp goto done;
1275 b3d68e7f 2021-07-03 stsp error = apply_unveil(got_repo_get_path_git_dir(repo), 0);
1276 b3d68e7f 2021-07-03 stsp if (error)
1277 b3d68e7f 2021-07-03 stsp goto done;
1279 2624d165 2023-02-07 thomas if (got_repo_has_extension(repo, "preciousObjects")) {
1280 2624d165 2023-02-07 thomas error = got_error_msg(GOT_ERR_GIT_REPO_EXT,
1281 2624d165 2023-02-07 thomas "the preciousObjects Git extension is enabled; "
1282 2624d165 2023-02-07 thomas "this implies that objects must not be deleted");
1283 2624d165 2023-02-07 thomas goto done;
1286 1124fe40 2021-07-07 stsp if (remove_lonely_packidx) {
1287 1124fe40 2021-07-07 stsp memset(&lpa, 0, sizeof(lpa));
1288 1124fe40 2021-07-07 stsp lpa.dry_run = dry_run;
1289 1124fe40 2021-07-07 stsp lpa.verbosity = verbosity;
1290 1124fe40 2021-07-07 stsp error = got_repo_remove_lonely_packidx(repo, dry_run,
1291 1124fe40 2021-07-07 stsp lonely_packidx_progress, &lpa, check_cancelled, NULL);
1292 1124fe40 2021-07-07 stsp goto done;
1295 b3d68e7f 2021-07-03 stsp memset(&cpa, 0, sizeof(cpa));
1296 b3d68e7f 2021-07-03 stsp cpa.last_ncommits = -1;
1297 b3d68e7f 2021-07-03 stsp cpa.last_npurged = -1;
1298 b3d68e7f 2021-07-03 stsp cpa.dry_run = dry_run;
1299 b3d68e7f 2021-07-03 stsp cpa.verbosity = verbosity;
1300 b3d68e7f 2021-07-03 stsp error = got_repo_purge_unreferenced_loose_objects(repo,
1301 abc59930 2021-09-05 naddy &size_before, &size_after, &npacked, dry_run, ignore_mtime,
1302 abc59930 2021-09-05 naddy cleanup_progress, &cpa, check_cancelled, NULL);
1303 b3d68e7f 2021-07-03 stsp if (cpa.printed_something)
1304 b3d68e7f 2021-07-03 stsp printf("\n");
1305 b3d68e7f 2021-07-03 stsp if (error)
1306 b3d68e7f 2021-07-03 stsp goto done;
1307 b3d68e7f 2021-07-03 stsp if (cpa.printed_something) {
1308 b3d68e7f 2021-07-03 stsp if (fmt_scaled(size_before, scaled_before) == -1) {
1309 b3d68e7f 2021-07-03 stsp error = got_error_from_errno("fmt_scaled");
1310 b3d68e7f 2021-07-03 stsp goto done;
1312 b3d68e7f 2021-07-03 stsp if (fmt_scaled(size_after, scaled_after) == -1) {
1313 b3d68e7f 2021-07-03 stsp error = got_error_from_errno("fmt_scaled");
1314 b3d68e7f 2021-07-03 stsp goto done;
1316 b3d68e7f 2021-07-03 stsp if (fmt_scaled(size_before - size_after, scaled_diff) == -1) {
1317 b3d68e7f 2021-07-03 stsp error = got_error_from_errno("fmt_scaled");
1318 b3d68e7f 2021-07-03 stsp goto done;
1320 b3d68e7f 2021-07-03 stsp printf("loose total size before: %s\n", scaled_before);
1321 b3d68e7f 2021-07-03 stsp printf("loose total size after: %s\n", scaled_after);
1322 b3d68e7f 2021-07-03 stsp if (dry_run) {
1323 b3d68e7f 2021-07-03 stsp printf("disk space which would be freed: %s\n",
1324 b3d68e7f 2021-07-03 stsp scaled_diff);
1326 b3d68e7f 2021-07-03 stsp printf("disk space freed: %s\n", scaled_diff);
1327 b3d68e7f 2021-07-03 stsp printf("loose objects also found in pack files: %d\n", npacked);
1331 b3d68e7f 2021-07-03 stsp got_repo_close(repo);
1332 7cd52833 2022-06-23 thomas if (pack_fds) {
1333 7cd52833 2022-06-23 thomas const struct got_error *pack_err =
1334 7cd52833 2022-06-23 thomas got_repo_pack_fds_close(pack_fds);
1335 7cd52833 2022-06-23 thomas if (error == NULL)
1336 7cd52833 2022-06-23 thomas error = pack_err;
1338 1ea7ccc6 2021-11-15 thomas free(repo_path);
1339 b3d68e7f 2021-07-03 stsp return error;