Blob


1 /*
2 * Copyright (c) 2018, 2019 Ori Bernstein <ori@openbsd.org>
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
17 #include <sys/types.h>
18 #include <sys/stat.h>
19 #include <sys/queue.h>
20 #include <sys/uio.h>
21 #include <sys/socket.h>
22 #include <sys/wait.h>
23 #include <sys/syslimits.h>
24 #include <sys/resource.h>
25 #include <sys/socket.h>
27 #include <errno.h>
28 #include <err.h>
29 #include <fcntl.h>
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <string.h>
33 #include <stdint.h>
34 #include <sha1.h>
35 #include <zlib.h>
36 #include <ctype.h>
37 #include <limits.h>
38 #include <imsg.h>
39 #include <time.h>
40 #include <uuid.h>
41 #include <netdb.h>
42 #include <netinet/in.h>
44 #include "got_error.h"
45 #include "got_reference.h"
46 #include "got_repository.h"
47 #include "got_path.h"
48 #include "got_cancel.h"
49 #include "got_worktree.h"
50 #include "got_object.h"
51 #include "got_opentemp.h"
52 #include "got_fetch.h"
54 #include "got_lib_delta.h"
55 #include "got_lib_inflate.h"
56 #include "got_lib_object.h"
57 #include "got_lib_object_parse.h"
58 #include "got_lib_object_create.h"
59 #include "got_lib_pack.h"
60 #include "got_lib_sha1.h"
61 #include "got_lib_privsep.h"
62 #include "got_lib_object_cache.h"
63 #include "got_lib_repository.h"
65 #ifndef nitems
66 #define nitems(_a) (sizeof((_a)) / sizeof((_a)[0]))
67 #endif
69 #ifndef MIN
70 #define MIN(_a,_b) ((_a) < (_b) ? (_a) : (_b))
71 #endif
73 static int
74 hassuffix(char *base, char *suf)
75 {
76 int nb, ns;
78 nb = strlen(base);
79 ns = strlen(suf);
80 if (ns <= nb && strcmp(base + (nb - ns), suf) == 0)
81 return 1;
82 return 0;
83 }
85 static const struct got_error *
86 dial_ssh(int *fetchfd, const char *host, const char *port, const char *path,
87 const char *direction, int verbosity)
88 {
89 const struct got_error *error = NULL;
90 int pid, pfd[2];
91 char cmd[64];
92 char *argv[9];
93 int i = 0;
95 *fetchfd = -1;
97 argv[0] = GOT_FETCH_PATH_SSH;
98 if (verbosity == -1) {
99 argv[1 + i++] = "-q";
100 } else {
101 /* ssh(1) allows up to 3 "-v" options. */
102 for (i = 0; i < MIN(3, verbosity); i++)
103 argv[1 + i] = "-v";
105 argv[1 + i] = "--";
106 argv[2 + i] = (char *)host;
107 argv[3 + i] = (char *)cmd;
108 argv[4 + i] = (char *)path;
109 argv[5 + i] = NULL;
111 if (pipe(pfd) == -1)
112 return got_error_from_errno("pipe");
114 pid = fork();
115 if (pid == -1) {
116 error = got_error_from_errno("fork");
117 close(pfd[0]);
118 close(pfd[1]);
119 return error;
120 } else if (pid == 0) {
121 int n;
122 close(pfd[1]);
123 dup2(pfd[0], 0);
124 dup2(pfd[0], 1);
125 n = snprintf(cmd, sizeof(cmd), "git-%s-pack", direction);
126 if (n < 0 || n >= sizeof(cmd))
127 err(1, "snprintf");
128 if (execv(GOT_FETCH_PATH_SSH, argv) == -1)
129 err(1, "execl");
130 abort(); /* not reached */
131 } else {
132 close(pfd[0]);
133 *fetchfd = pfd[1];
134 return NULL;
138 static const struct got_error *
139 dial_git(int *fetchfd, const char *host, const char *port, const char *path,
140 const char *direction)
142 const struct got_error *err = NULL;
143 struct addrinfo hints, *servinfo, *p;
144 char *cmd = NULL, *pkt = NULL;
145 int fd = -1, totlen, r, eaicode;
147 *fetchfd = -1;
149 memset(&hints, 0, sizeof hints);
150 hints.ai_family = AF_UNSPEC;
151 hints.ai_socktype = SOCK_STREAM;
152 eaicode = getaddrinfo(host, port, &hints, &servinfo);
153 if (eaicode) {
154 char msg[512];
155 snprintf(msg, sizeof(msg), "%s: %s", host,
156 gai_strerror(eaicode));
157 return got_error_msg(GOT_ERR_ADDRINFO, msg);
160 for (p = servinfo; p != NULL; p = p->ai_next) {
161 if ((fd = socket(p->ai_family, p->ai_socktype,
162 p->ai_protocol)) == -1)
163 continue;
164 if (connect(fd, p->ai_addr, p->ai_addrlen) == 0)
165 break;
166 err = got_error_from_errno("connect");
167 close(fd);
169 if (p == NULL)
170 goto done;
172 if (asprintf(&cmd, "git-%s-pack %s", direction, path) == -1) {
173 err = got_error_from_errno("asprintf");
174 goto done;
176 totlen = 4 + strlen(cmd) + 1 + strlen("host=") + strlen(host) + 1;
177 if (asprintf(&pkt, "%04x%s", totlen, cmd) == -1) {
178 err = got_error_from_errno("asprintf");
179 goto done;
181 r = write(fd, pkt, strlen(pkt) + 1);
182 if (r == -1) {
183 err = got_error_from_errno("write");
184 goto done;
186 if (asprintf(&pkt, "host=%s", host) == -1) {
187 err = got_error_from_errno("asprintf");
188 goto done;
190 r = write(fd, pkt, strlen(pkt) + 1);
191 if (r == -1) {
192 err = got_error_from_errno("write");
193 goto done;
195 done:
196 free(cmd);
197 free(pkt);
198 if (err) {
199 if (fd != -1)
200 close(fd);
201 } else
202 *fetchfd = fd;
203 return err;
206 const struct got_error *
207 got_fetch_connect(int *fetchfd, const char *proto, const char *host,
208 const char *port, const char *server_path, int verbosity)
210 const struct got_error *err = NULL;
212 *fetchfd = -1;
214 if (strcmp(proto, "ssh") == 0 || strcmp(proto, "git+ssh") == 0)
215 err = dial_ssh(fetchfd, host, port, server_path, "upload",
216 verbosity);
217 else if (strcmp(proto, "git") == 0)
218 err = dial_git(fetchfd, host, port, server_path, "upload");
219 else if (strcmp(proto, "http") == 0 || strcmp(proto, "git+http") == 0)
220 err = got_error_path(proto, GOT_ERR_NOT_IMPL);
221 else
222 err = got_error_path(proto, GOT_ERR_BAD_PROTO);
223 return err;
226 const struct got_error *
227 got_fetch_parse_uri(char **proto, char **host, char **port,
228 char **server_path, char **repo_name, const char *uri)
230 const struct got_error *err = NULL;
231 char *s, *p, *q;
232 int n;
234 *proto = *host = *port = *server_path = *repo_name = NULL;
236 p = strstr(uri, "://");
237 if (!p) {
238 /* Try parsing Git's "scp" style URL syntax. */
239 *proto = strdup("ssh");
240 if (proto == NULL) {
241 err = got_error_from_errno("strdup");
242 goto done;
244 *port = strdup("22");
245 if (*port == NULL) {
246 err = got_error_from_errno("strdup");
247 goto done;
249 s = (char *)uri;
250 q = strchr(s, ':');
251 if (q == NULL) {
252 err = got_error(GOT_ERR_PARSE_URI);
253 goto done;
255 /* No slashes allowed before first colon. */
256 p = strchr(s, '/');
257 if (p && q > p) {
258 err = got_error(GOT_ERR_PARSE_URI);
259 goto done;
261 *host = strndup(s, q - s);
262 if (*host == NULL) {
263 err = got_error_from_errno("strndup");
264 goto done;
266 p = q + 1;
267 } else {
268 *proto = strndup(uri, p - uri);
269 if (proto == NULL) {
270 err = got_error_from_errno("strndup");
271 goto done;
273 s = p + 3;
275 p = strstr(s, "/");
276 if (p == NULL || strlen(p) == 1) {
277 err = got_error(GOT_ERR_PARSE_URI);
278 goto done;
281 q = memchr(s, ':', p - s);
282 if (q) {
283 *host = strndup(s, q - s);
284 if (*host == NULL) {
285 err = got_error_from_errno("strndup");
286 goto done;
288 *port = strndup(q + 1, p - (q + 1));
289 if (*port == NULL) {
290 err = got_error_from_errno("strndup");
291 goto done;
293 } else {
294 *host = strndup(s, p - s);
295 if (*host == NULL) {
296 err = got_error_from_errno("strndup");
297 goto done;
299 if (asprintf(port, "%u", GOT_DEFAULT_GIT_PORT) == -1) {
300 err = got_error_from_errno("asprintf");
301 goto done;
306 *server_path = strdup(p);
307 if (*server_path == NULL) {
308 err = got_error_from_errno("strdup");
309 goto done;
312 p = strrchr(p, '/');
313 if (!p || strlen(p) <= 1) {
314 err = got_error(GOT_ERR_PARSE_URI);
315 goto done;
317 p++;
318 n = strlen(p);
319 if (n == 0) {
320 err = got_error(GOT_ERR_PARSE_URI);
321 goto done;
323 if (hassuffix(p, ".git"))
324 n -= 4;
325 *repo_name = strndup(p, (p + n) - p);
326 if (*repo_name == NULL) {
327 err = got_error_from_errno("strndup");
328 goto done;
330 done:
331 if (err) {
332 free(*proto);
333 *proto = NULL;
334 free(*host);
335 *host = NULL;
336 free(*port);
337 *port = NULL;
338 free(*server_path);
339 *server_path = NULL;
340 free(*repo_name);
341 *repo_name = NULL;
343 return err;
346 static const struct got_error *
347 check_pack_hash(int fd, size_t sz, uint8_t *hcomp)
349 SHA1_CTX ctx;
350 uint8_t hexpect[SHA1_DIGEST_LENGTH];
351 uint8_t buf[32 * 1024];
352 ssize_t n, r, nr;
354 if (sz < sizeof(struct got_packfile_hdr) + SHA1_DIGEST_LENGTH)
355 return got_error_msg(GOT_ERR_BAD_PACKFILE, "short packfile");
357 n = 0;
358 SHA1Init(&ctx);
359 while (n < sz - 20) {
360 nr = sizeof(buf);
361 if (sz - n - 20 < sizeof(buf))
362 nr = sz - n - 20;
363 r = read(fd, buf, nr);
364 if (r == -1)
365 return got_error_from_errno("read");
366 if (r != nr)
367 return got_error_msg(GOT_ERR_BAD_PACKFILE,
368 "short pack file");
369 SHA1Update(&ctx, buf, nr);
370 n += r;
372 SHA1Final(hcomp, &ctx);
374 r = read(fd, hexpect, sizeof(hexpect));
375 if (r == -1)
376 return got_error_from_errno("read");
377 if (r != sizeof(hexpect))
378 return got_error_msg(GOT_ERR_BAD_PACKFILE,
379 "short pack file");
381 if (memcmp(hcomp, hexpect, SHA1_DIGEST_LENGTH) != 0)
382 return got_error_msg(GOT_ERR_BAD_PACKFILE,
383 "packfile checksum mismatch");
385 return NULL;
388 const struct got_error*
389 got_fetch_pack(struct got_object_id **pack_hash, struct got_pathlist_head *refs,
390 struct got_pathlist_head *symrefs, const char *remote_name, int fetchfd,
391 struct got_repository *repo, got_fetch_progress_cb progress_cb,
392 void *progress_arg)
394 int imsg_fetchfds[2], imsg_idxfds[2];
395 int packfd = -1, npackfd = -1, idxfd = -1, nidxfd = -1, nfetchfd = -1;
396 int tmpfds[3], i;
397 int fetchstatus, idxstatus, done = 0;
398 const struct got_error *err;
399 struct imsgbuf fetchibuf, idxibuf;
400 pid_t fetchpid, idxpid;
401 char *tmppackpath = NULL, *tmpidxpath = NULL;
402 char *packpath = NULL, *idxpath = NULL, *id_str = NULL;
403 const char *repo_path = got_repo_get_path_git_dir(repo);
404 struct got_pathlist_head have_refs;
405 struct got_pathlist_entry *pe;
406 struct got_reflist_head my_refs;
407 struct got_reflist_entry *re;
408 off_t packfile_size = 0;
409 char *ref_prefix = NULL;
410 size_t ref_prefixlen = 0;
411 char *path;
412 char *progress = NULL;
414 *pack_hash = NULL;
415 for (i = 0; i < nitems(tmpfds); i++)
416 tmpfds[i] = -1;
418 TAILQ_INIT(&have_refs);
419 SIMPLEQ_INIT(&my_refs);
421 if (asprintf(&ref_prefix, "refs/remotes/%s/", remote_name) == -1)
422 return got_error_from_errno("asprintf");
423 ref_prefixlen = strlen(ref_prefix);
425 err = got_ref_list(&my_refs, repo, NULL, got_ref_cmp_by_name, NULL);
426 if (err)
427 goto done;
429 SIMPLEQ_FOREACH(re, &my_refs, entry) {
430 struct got_object_id *id;
431 const char *refname;
433 if (got_ref_is_symbolic(re->ref))
434 continue;
436 refname = got_ref_get_name(re->ref);
437 if (strncmp("refs/tags/", refname, 10) == 0) {
438 char *tagname;
440 err = got_ref_resolve(&id, repo, re->ref);
441 if (err)
442 goto done;
443 tagname = strdup(refname);
444 if (tagname == NULL) {
445 err = got_error_from_errno("strdup");
446 goto done;
448 err = got_pathlist_append(&have_refs, tagname, id);
449 if (err) {
450 free(tagname);
451 goto done;
455 if (strncmp(ref_prefix, refname, ref_prefixlen) == 0) {
456 char *branchname;
458 err = got_ref_resolve(&id, repo, re->ref);
459 if (err)
460 goto done;
462 if (asprintf(&branchname, "refs/heads/%s",
463 refname + ref_prefixlen) == -1) {
464 err = got_error_from_errno("asprintf");
465 goto done;
467 err = got_pathlist_append(&have_refs, branchname, id);
468 if (err) {
469 free(branchname);
470 goto done;
475 if (asprintf(&path, "%s/%s/fetching.pack",
476 repo_path, GOT_OBJECTS_PACK_DIR) == -1) {
477 err = got_error_from_errno("asprintf");
478 goto done;
480 err = got_opentemp_named_fd(&tmppackpath, &packfd, path);
481 free(path);
482 if (err)
483 goto done;
484 npackfd = dup(packfd);
485 if (npackfd == -1) {
486 err = got_error_from_errno("dup");
487 goto done;
489 if (asprintf(&path, "%s/%s/fetching.idx",
490 repo_path, GOT_OBJECTS_PACK_DIR) == -1) {
491 err = got_error_from_errno("asprintf");
492 goto done;
494 err = got_opentemp_named_fd(&tmpidxpath, &idxfd, path);
495 free(path);
496 if (err)
497 goto done;
498 nidxfd = dup(idxfd);
499 if (nidxfd == -1) {
500 err = got_error_from_errno("dup");
501 goto done;
504 for (i = 0; i < nitems(tmpfds); i++) {
505 tmpfds[i] = got_opentempfd();
506 if (tmpfds[i] == -1) {
507 err = got_error_from_errno("got_opentempfd");
508 goto done;
512 if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, imsg_fetchfds) == -1) {
513 err = got_error_from_errno("socketpair");
514 goto done;
517 fetchpid = fork();
518 if (fetchpid == -1) {
519 err = got_error_from_errno("fork");
520 goto done;
521 } else if (fetchpid == 0){
522 got_privsep_exec_child(imsg_fetchfds,
523 GOT_PATH_PROG_FETCH_PACK, tmppackpath);
526 if (close(imsg_fetchfds[1]) != 0) {
527 err = got_error_from_errno("close");
528 goto done;
530 imsg_init(&fetchibuf, imsg_fetchfds[0]);
531 nfetchfd = dup(fetchfd);
532 if (nfetchfd == -1) {
533 err = got_error_from_errno("dup");
534 goto done;
536 err = got_privsep_send_fetch_req(&fetchibuf, nfetchfd, &have_refs);
537 if (err != NULL)
538 goto done;
539 nfetchfd = -1;
540 err = got_privsep_send_fetch_outfd(&fetchibuf, npackfd);
541 if (err != NULL)
542 goto done;
543 npackfd = dup(packfd);
544 if (npackfd == -1) {
545 err = got_error_from_errno("dup");
546 goto done;
549 packfile_size = 0;
550 progress = calloc(GOT_FETCH_PKTMAX, 1);
551 if (progress == NULL) {
552 err = got_error_from_errno("calloc");
553 goto done;
555 while (!done) {
556 struct got_object_id *id = NULL;
557 char *refname = NULL;
558 char *server_progress = NULL;
559 off_t packfile_size_cur = 0;
561 err = got_privsep_recv_fetch_progress(&done,
562 &id, &refname, symrefs, &server_progress,
563 &packfile_size_cur, &fetchibuf);
564 if (err != NULL)
565 goto done;
566 if (done) {
567 if (packfile_size > 0)
568 *pack_hash = id;
569 else
570 free(id);
571 } else if (refname && id) {
572 err = got_pathlist_append(refs, refname, id);
573 if (err)
574 goto done;
575 } else if (server_progress) {
576 char *p;
577 /*
578 * XXX git-daemon tends to send batched output with
579 * lines spanning separate packets. Buffer progress
580 * output until we see a CR or LF to avoid giving
581 * partial lines of progress output to the callback.
582 */
583 if (strlcat(progress, server_progress,
584 GOT_FETCH_PKTMAX) >= GOT_FETCH_PKTMAX) {
585 progress[0] = '\0'; /* discard */
586 continue;
588 while ((p = strchr(progress, '\r')) != NULL ||
589 (p = strchr(progress, '\n')) != NULL) {
590 char *s;
591 size_t n;
592 char c = *p;
593 *p = '\0';
594 if (asprintf(&s, "%s%s", progress,
595 c == '\n' ? "\n" : "") == -1) {
596 err = got_error_from_errno("asprintf");
597 goto done;
599 err = progress_cb(progress_arg, s,
600 packfile_size_cur, 0, 0, 0, 0);
601 free(s);
602 if (err)
603 break;
604 n = strlen(progress);
605 if (n < GOT_FETCH_PKTMAX - 1) {
606 memmove(progress, &progress[n + 1],
607 GOT_FETCH_PKTMAX - n - 1);
608 } else
609 progress[0] = '\0';
611 free(server_progress);
612 if (err)
613 goto done;
614 } else if (packfile_size_cur != packfile_size) {
615 err = progress_cb(progress_arg, NULL,
616 packfile_size_cur, 0, 0, 0, 0);
617 if (err)
618 break;
619 packfile_size = packfile_size_cur;
622 if (waitpid(fetchpid, &fetchstatus, 0) == -1) {
623 err = got_error_from_errno("waitpid");
624 goto done;
627 /* If zero data was fetched without error we are already up-to-date. */
628 if (packfile_size == 0)
629 goto done;
631 if (lseek(packfd, 0, SEEK_SET) == -1) {
632 err = got_error_from_errno("lseek");
633 goto done;
635 err = check_pack_hash(packfd, packfile_size, (*pack_hash)->sha1);
636 if (err)
637 goto done;
639 if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, imsg_idxfds) == -1) {
640 err = got_error_from_errno("socketpair");
641 goto done;
643 idxpid = fork();
644 if (idxpid == -1) {
645 err= got_error_from_errno("fork");
646 goto done;
647 } else if (idxpid == 0)
648 got_privsep_exec_child(imsg_idxfds,
649 GOT_PATH_PROG_INDEX_PACK, tmppackpath);
650 if (close(imsg_idxfds[1]) != 0) {
651 err = got_error_from_errno("close");
652 goto done;
654 imsg_init(&idxibuf, imsg_idxfds[0]);
656 err = got_privsep_send_index_pack_req(&idxibuf, (*pack_hash)->sha1,
657 npackfd);
658 if (err != NULL)
659 goto done;
660 npackfd = -1;
661 err = got_privsep_send_index_pack_outfd(&idxibuf, nidxfd);
662 if (err != NULL)
663 goto done;
664 nidxfd = -1;
665 for (i = 0; i < nitems(tmpfds); i++) {
666 err = got_privsep_send_tmpfd(&idxibuf, tmpfds[i]);
667 if (err != NULL)
668 goto done;
669 tmpfds[i] = -1;
671 done = 0;
672 while (!done) {
673 int nobj_total, nobj_indexed, nobj_loose, nobj_resolved;
675 err = got_privsep_recv_index_progress(&done, &nobj_total,
676 &nobj_indexed, &nobj_loose, &nobj_resolved,
677 &idxibuf);
678 if (err != NULL)
679 goto done;
680 if (nobj_indexed != 0) {
681 err = progress_cb(progress_arg, NULL,
682 packfile_size, nobj_total,
683 nobj_indexed, nobj_loose, nobj_resolved);
684 if (err)
685 break;
687 imsg_clear(&idxibuf);
689 if (close(imsg_idxfds[0]) == -1) {
690 err = got_error_from_errno("close");
691 goto done;
693 if (waitpid(idxpid, &idxstatus, 0) == -1) {
694 err = got_error_from_errno("waitpid");
695 goto done;
698 err = got_object_id_str(&id_str, *pack_hash);
699 if (err)
700 goto done;
701 if (asprintf(&packpath, "%s/%s/pack-%s.pack",
702 repo_path, GOT_OBJECTS_PACK_DIR, id_str) == -1) {
703 err = got_error_from_errno("asprintf");
704 goto done;
707 if (asprintf(&idxpath, "%s/%s/pack-%s.idx",
708 repo_path, GOT_OBJECTS_PACK_DIR, id_str) == -1) {
709 err = got_error_from_errno("asprintf");
710 goto done;
713 if (rename(tmppackpath, packpath) == -1) {
714 err = got_error_from_errno3("rename", tmppackpath, packpath);
715 goto done;
717 free(tmppackpath);
718 tmppackpath = NULL;
719 if (rename(tmpidxpath, idxpath) == -1) {
720 err = got_error_from_errno3("rename", tmpidxpath, idxpath);
721 goto done;
723 free(tmpidxpath);
724 tmpidxpath = NULL;
726 done:
727 if (tmppackpath && unlink(tmppackpath) == -1 && err == NULL)
728 err = got_error_from_errno2("unlink", tmppackpath);
729 if (tmpidxpath && unlink(tmpidxpath) == -1 && err == NULL)
730 err = got_error_from_errno2("unlink", tmpidxpath);
731 if (nfetchfd != -1 && close(nfetchfd) == -1 && err == NULL)
732 err = got_error_from_errno("close");
733 if (npackfd != -1 && close(npackfd) == -1 && err == NULL)
734 err = got_error_from_errno("close");
735 if (packfd != -1 && close(packfd) == -1 && err == NULL)
736 err = got_error_from_errno("close");
737 if (idxfd != -1 && close(idxfd) == -1 && err == NULL)
738 err = got_error_from_errno("close");
739 for (i = 0; i < nitems(tmpfds); i++) {
740 if (tmpfds[i] != -1 && close(tmpfds[i]) == -1 && err == NULL)
741 err = got_error_from_errno("close");
743 free(tmppackpath);
744 free(tmpidxpath);
745 free(idxpath);
746 free(packpath);
747 free(ref_prefix);
748 free(progress);
750 TAILQ_FOREACH(pe, &have_refs, entry) {
751 free((char *)pe->path);
752 free(pe->data);
754 got_pathlist_free(&have_refs);
755 got_ref_list_free(&my_refs);
756 if (err) {
757 free(*pack_hash);
758 *pack_hash = NULL;
759 TAILQ_FOREACH(pe, refs, entry) {
760 free((void *)pe->path);
761 free(pe->data);
763 got_pathlist_free(refs);
764 TAILQ_FOREACH(pe, symrefs, entry) {
765 free((void *)pe->path);
766 free(pe->data);
768 got_pathlist_free(symrefs);
770 return err;