Blob


1 /*
2 * Copyright (c) 2019 Ori Bernstein <ori@openbsd.org>
3 * Copyright (c) 2021 Stefan Sperling <stsp@openbsd.org>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
18 #include <sys/types.h>
19 #include <sys/queue.h>
20 #include <sys/uio.h>
21 #include <sys/time.h>
22 #include <sys/stat.h>
24 #include <stdint.h>
25 #include <errno.h>
26 #include <imsg.h>
27 #include <limits.h>
28 #include <signal.h>
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <string.h>
32 #include <ctype.h>
33 #include <sha1.h>
34 #include <sha2.h>
35 #include <fcntl.h>
36 #include <unistd.h>
37 #include <zlib.h>
38 #include <err.h>
40 #include "got_error.h"
41 #include "got_object.h"
42 #include "got_path.h"
43 #include "got_version.h"
44 #include "got_fetch.h"
45 #include "got_reference.h"
47 #include "got_lib_hash.h"
48 #include "got_lib_delta.h"
49 #include "got_lib_object.h"
50 #include "got_lib_object_parse.h"
51 #include "got_lib_privsep.h"
52 #include "got_lib_pack.h"
53 #include "got_lib_pkt.h"
54 #include "got_lib_gitproto.h"
55 #include "got_lib_ratelimit.h"
56 #include "got_lib_poll.h"
58 #ifndef nitems
59 #define nitems(_a) (sizeof((_a)) / sizeof((_a)[0]))
60 #endif
62 struct got_object *indexed;
63 static int chattygot;
65 static const struct got_capability got_capabilities[] = {
66 { GOT_CAPA_AGENT, "got/" GOT_VERSION_STR },
67 { GOT_CAPA_OFS_DELTA, NULL },
68 #if 0
69 { GOT_CAPA_SIDE_BAND_64K, NULL },
70 #endif
71 { GOT_CAPA_REPORT_STATUS, NULL },
72 { GOT_CAPA_DELETE_REFS, NULL },
73 };
75 static const struct got_error *
76 send_upload_progress(struct imsgbuf *ibuf, off_t bytes,
77 struct got_ratelimit *rl)
78 {
79 const struct got_error *err = NULL;
80 int elapsed = 0;
82 if (rl) {
83 err = got_ratelimit_check(&elapsed, rl);
84 if (err || !elapsed)
85 return err;
86 }
88 if (imsg_compose(ibuf, GOT_IMSG_SEND_UPLOAD_PROGRESS, 0, 0, -1,
89 &bytes, sizeof(bytes)) == -1)
90 return got_error_from_errno(
91 "imsg_compose SEND_UPLOAD_PROGRESS");
93 return got_privsep_flush_imsg(ibuf);
94 }
96 static const struct got_error *
97 send_pack_request(struct imsgbuf *ibuf)
98 {
99 if (imsg_compose(ibuf, GOT_IMSG_SEND_PACK_REQUEST, 0, 0, -1,
100 NULL, 0) == -1)
101 return got_error_from_errno("imsg_compose SEND_PACK_REQUEST");
102 return got_privsep_flush_imsg(ibuf);
105 static const struct got_error *
106 send_done(struct imsgbuf *ibuf)
108 if (imsg_compose(ibuf, GOT_IMSG_SEND_DONE, 0, 0, -1, NULL, 0) == -1)
109 return got_error_from_errno("imsg_compose SEND_DONE");
110 return got_privsep_flush_imsg(ibuf);
113 static const struct got_error *
114 recv_packfd(int *packfd, struct imsgbuf *ibuf)
116 const struct got_error *err;
117 struct imsg imsg;
119 *packfd = -1;
121 err = got_privsep_recv_imsg(&imsg, ibuf, 0);
122 if (err)
123 return err;
125 if (imsg.hdr.type == GOT_IMSG_STOP) {
126 err = got_error(GOT_ERR_CANCELLED);
127 goto done;
130 if (imsg.hdr.type != GOT_IMSG_SEND_PACKFD) {
131 err = got_error(GOT_ERR_PRIVSEP_MSG);
132 goto done;
135 if (imsg.hdr.len - IMSG_HEADER_SIZE != 0) {
136 err = got_error(GOT_ERR_PRIVSEP_LEN);
137 goto done;
140 *packfd = imsg.fd;
141 done:
142 imsg_free(&imsg);
143 return err;
146 static const struct got_error *
147 send_pack_file(int sendfd, int packfd, struct imsgbuf *ibuf)
149 const struct got_error *err;
150 unsigned char buf[8192];
151 ssize_t r;
152 off_t wtotal = 0;
153 struct got_ratelimit rl;
155 if (lseek(packfd, 0L, SEEK_SET) == -1)
156 return got_error_from_errno("lseek");
158 got_ratelimit_init(&rl, 0, 500);
160 for (;;) {
161 r = read(packfd, buf, sizeof(buf));
162 if (r == -1)
163 return got_error_from_errno("read");
164 if (r == 0)
165 break;
166 err = got_poll_write_full(sendfd, buf, r);
167 if (err)
168 return NULL;
169 wtotal += r;
170 err = send_upload_progress(ibuf, wtotal, &rl);
171 if (err)
172 return err;
175 return send_upload_progress(ibuf, wtotal, NULL);
178 static const struct got_error *
179 send_error(const char *buf, size_t len)
181 static char msg[1024];
182 size_t i;
184 for (i = 0; i < len && i < sizeof(msg) - 1; i++) {
185 if (!isprint((unsigned char)buf[i]))
186 return got_error_msg(GOT_ERR_BAD_PACKET,
187 "non-printable error message received from server");
188 msg[i] = buf[i];
190 msg[i] = '\0';
191 return got_error_msg(GOT_ERR_SEND_FAILED, msg);
194 static const struct got_error *
195 send_their_ref(struct imsgbuf *ibuf, struct got_object_id *refid,
196 const char *refname)
198 struct ibuf *wbuf;
199 size_t len, reflen = strlen(refname);
201 len = sizeof(struct got_imsg_send_remote_ref) + reflen;
202 if (len >= MAX_IMSGSIZE - IMSG_HEADER_SIZE)
203 return got_error(GOT_ERR_NO_SPACE);
205 wbuf = imsg_create(ibuf, GOT_IMSG_SEND_REMOTE_REF, 0, 0, len);
206 if (wbuf == NULL)
207 return got_error_from_errno("imsg_create SEND_REMOTE_REF");
209 /* Keep in sync with struct got_imsg_send_remote_ref definition! */
210 if (imsg_add(wbuf, refid, sizeof(*refid)) == -1)
211 return got_error_from_errno("imsg_add SEND_REMOTE_REF");
212 if (imsg_add(wbuf, &reflen, sizeof(reflen)) == -1)
213 return got_error_from_errno("imsg_add SEND_REMOTE_REF");
214 if (imsg_add(wbuf, refname, reflen) == -1)
215 return got_error_from_errno("imsg_add SEND_REMOTE_REF");
217 wbuf->fd = -1;
218 imsg_close(ibuf, wbuf);
219 return got_privsep_flush_imsg(ibuf);
222 static const struct got_error *
223 send_ref_status(struct imsgbuf *ibuf, const char *refname, int success,
224 struct got_pathlist_head *refs, struct got_pathlist_head *delete_refs)
226 struct ibuf *wbuf;
227 size_t i, len, reflen, errmsglen = 0;
228 struct got_pathlist_entry *pe;
229 int ref_valid = 0;
230 char *eol, *sp;
231 const char *errmsg = "";
233 eol = strchr(refname, '\n');
234 if (eol == NULL) {
235 return got_error_msg(GOT_ERR_BAD_PACKET,
236 "unexpected message from server");
238 *eol = '\0';
240 sp = strchr(refname, ' ');
241 if (sp != NULL) {
242 *sp++ = '\0';
243 errmsg = sp;
244 errmsglen = strlen(errmsg);
246 for (i = 0; i < errmsglen; ++i) {
247 if (!isprint((unsigned char)errmsg[i])) {
248 return got_error_msg(GOT_ERR_BAD_PACKET,
249 "non-printable error message received "
250 "from the server");
255 reflen = strlen(refname);
256 if (!got_ref_name_is_valid(refname)) {
257 return got_error_msg(GOT_ERR_BAD_PACKET,
258 "unexpected message from server");
261 TAILQ_FOREACH(pe, refs, entry) {
262 if (strcmp(refname, pe->path) == 0) {
263 ref_valid = 1;
264 break;
267 if (!ref_valid) {
268 TAILQ_FOREACH(pe, delete_refs, entry) {
269 if (strcmp(refname, pe->path) == 0) {
270 ref_valid = 1;
271 break;
275 if (!ref_valid) {
276 return got_error_msg(GOT_ERR_BAD_PACKET,
277 "unexpected message from server");
280 len = sizeof(struct got_imsg_send_ref_status) + reflen + errmsglen;
281 if (len >= MAX_IMSGSIZE - IMSG_HEADER_SIZE)
282 return got_error(GOT_ERR_NO_SPACE);
284 wbuf = imsg_create(ibuf, GOT_IMSG_SEND_REF_STATUS,
285 0, 0, len);
286 if (wbuf == NULL)
287 return got_error_from_errno("imsg_create SEND_REF_STATUS");
289 /* Keep in sync with struct got_imsg_send_ref_status definition! */
290 if (imsg_add(wbuf, &success, sizeof(success)) == -1)
291 return got_error_from_errno("imsg_add SEND_REF_STATUS");
292 if (imsg_add(wbuf, &reflen, sizeof(reflen)) == -1)
293 return got_error_from_errno("imsg_add SEND_REF_STATUS");
294 if (imsg_add(wbuf, &errmsglen, sizeof(errmsglen)) == -1)
295 return got_error_from_errno("imsg_add SEND_REF_STATUS");
296 if (imsg_add(wbuf, refname, reflen) == -1)
297 return got_error_from_errno("imsg_add SEND_REF_STATUS");
298 if (imsg_add(wbuf, errmsg, errmsglen) == -1)
299 return got_error_from_errno("imsg_add SEND_REF_STATUS");
301 wbuf->fd = -1;
302 imsg_close(ibuf, wbuf);
303 return got_privsep_flush_imsg(ibuf);
306 static const struct got_error *
307 describe_refchange(int *n, int *sent_my_capabilites,
308 const char *my_capabilities, char *buf, size_t bufsize,
309 const char *refname, const char *old_hashstr, const char *new_hashstr)
311 *n = snprintf(buf, bufsize, "%s %s %s",
312 old_hashstr, new_hashstr, refname);
313 if (*n < 0 || (size_t)*n >= bufsize)
314 return got_error(GOT_ERR_NO_SPACE);
316 /*
317 * We must announce our capabilities along with the first
318 * reference. Unfortunately, the protocol requires an embedded
319 * NUL as a separator between reference name and capabilities,
320 * which we have to deal with here.
321 * It also requires a linefeed for terminating packet data.
322 */
323 if (!*sent_my_capabilites && my_capabilities != NULL) {
324 int m;
325 if (*n >= bufsize - 1)
326 return got_error(GOT_ERR_NO_SPACE);
327 m = snprintf(buf + *n + 1, /* offset after '\0' */
328 bufsize - (*n + 1), "%s\n", my_capabilities);
329 if (m < 0 || *n + m >= bufsize)
330 return got_error(GOT_ERR_NO_SPACE);
331 *n += m;
332 *sent_my_capabilites = 1;
333 } else {
334 *n = strlcat(buf, "\n", bufsize);
335 if (*n >= bufsize)
336 return got_error(GOT_ERR_NO_SPACE);
339 return NULL;
342 static const struct got_error *
343 send_pack(int fd, struct got_pathlist_head *refs,
344 struct got_pathlist_head *delete_refs, struct imsgbuf *ibuf)
346 const struct got_error *err = NULL;
347 char buf[GOT_PKT_MAX];
348 const unsigned char zero_id[SHA1_DIGEST_LENGTH] = { 0 };
349 char old_hashstr[SHA1_DIGEST_STRING_LENGTH];
350 char new_hashstr[SHA1_DIGEST_STRING_LENGTH];
351 struct got_pathlist_head their_refs;
352 int is_firstpkt = 1;
353 int n, nsent = 0;
354 int packfd = -1;
355 char *id_str = NULL, *refname = NULL;
356 struct got_object_id *id = NULL;
357 char *server_capabilities = NULL, *my_capabilities = NULL;
358 struct got_pathlist_entry *pe;
359 int sent_my_capabilites = 0;
361 TAILQ_INIT(&their_refs);
363 if (TAILQ_EMPTY(refs) && TAILQ_EMPTY(delete_refs))
364 return got_error(GOT_ERR_SEND_EMPTY);
366 while (1) {
367 err = got_pkt_readpkt(&n, fd, buf, sizeof(buf), chattygot);
368 if (err)
369 goto done;
370 if (n == 0)
371 break;
372 if (n >= 4 && strncmp(buf, "ERR ", 4) == 0) {
373 err = send_error(&buf[4], n - 4);
374 goto done;
376 free(id_str);
377 free(refname);
378 err = got_gitproto_parse_refline(&id_str, &refname,
379 &server_capabilities, buf, n);
380 if (err)
381 goto done;
382 if (is_firstpkt) {
383 if (server_capabilities == NULL) {
384 server_capabilities = strdup("");
385 if (server_capabilities == NULL) {
386 err = got_error_from_errno("strdup");
387 goto done;
390 if (chattygot && server_capabilities[0] != '\0')
391 fprintf(stderr, "%s: server capabilities: %s\n",
392 getprogname(), server_capabilities);
393 err = got_gitproto_match_capabilities(&my_capabilities,
394 NULL, server_capabilities, got_capabilities,
395 nitems(got_capabilities));
396 if (err)
397 goto done;
398 if (chattygot)
399 fprintf(stderr, "%s: my capabilities:%s\n",
400 getprogname(),
401 my_capabilities ? my_capabilities : "");
402 is_firstpkt = 0;
404 if (strstr(refname, "^{}")) {
405 if (chattygot) {
406 fprintf(stderr, "%s: ignoring %s\n",
407 getprogname(), refname);
409 continue;
412 id = malloc(sizeof(*id));
413 if (id == NULL) {
414 err = got_error_from_errno("malloc");
415 goto done;
417 if (!got_parse_object_id(id, id_str, GOT_HASH_SHA1)) {
418 err = got_error(GOT_ERR_BAD_OBJ_ID_STR);
419 goto done;
421 err = send_their_ref(ibuf, id, refname);
422 if (err)
423 goto done;
425 err = got_pathlist_append(&their_refs, refname, id);
426 if (err)
427 goto done;
429 if (chattygot)
430 fprintf(stderr, "%s: remote has %s %s\n",
431 getprogname(), refname, id_str);
432 free(id_str);
433 id_str = NULL;
434 refname = NULL; /* do not free; owned by their_refs */
435 id = NULL; /* do not free; owned by their_refs */
438 if (!TAILQ_EMPTY(delete_refs)) {
439 if (my_capabilities == NULL ||
440 strstr(my_capabilities, GOT_CAPA_DELETE_REFS) == NULL) {
441 err = got_error(GOT_ERR_CAPA_DELETE_REFS);
442 goto done;
446 TAILQ_FOREACH(pe, delete_refs, entry) {
447 const char *refname = pe->path;
448 struct got_pathlist_entry *their_pe;
449 struct got_object_id *their_id = NULL;
451 TAILQ_FOREACH(their_pe, &their_refs, entry) {
452 const char *their_refname = their_pe->path;
453 if (got_path_cmp(refname, their_refname,
454 strlen(refname), strlen(their_refname)) == 0) {
455 their_id = their_pe->data;
456 break;
459 if (their_id == NULL) {
460 err = got_error_fmt(GOT_ERR_NOT_REF,
461 "%s does not exist in remote repository",
462 refname);
463 goto done;
466 got_sha1_digest_to_str(their_id->sha1, old_hashstr,
467 sizeof(old_hashstr));
468 got_sha1_digest_to_str(zero_id, new_hashstr,
469 sizeof(new_hashstr));
470 err = describe_refchange(&n, &sent_my_capabilites,
471 my_capabilities, buf, sizeof(buf), refname,
472 old_hashstr, new_hashstr);
473 if (err)
474 goto done;
475 err = got_pkt_writepkt(fd, buf, n, chattygot);
476 if (err)
477 goto done;
478 if (chattygot) {
479 fprintf(stderr, "%s: deleting %s %s\n",
480 getprogname(), refname, old_hashstr);
482 nsent++;
485 TAILQ_FOREACH(pe, refs, entry) {
486 const char *refname = pe->path;
487 struct got_object_id *id = pe->data;
488 struct got_object_id *their_id = NULL;
489 struct got_pathlist_entry *their_pe;
491 TAILQ_FOREACH(their_pe, &their_refs, entry) {
492 const char *their_refname = their_pe->path;
493 if (got_path_cmp(refname, their_refname,
494 strlen(refname), strlen(their_refname)) == 0) {
495 their_id = their_pe->data;
496 break;
499 if (their_id) {
500 if (got_object_id_cmp(id, their_id) == 0) {
501 if (chattygot) {
502 fprintf(stderr,
503 "%s: no change for %s\n",
504 getprogname(), refname);
506 continue;
508 got_sha1_digest_to_str(their_id->sha1, old_hashstr,
509 sizeof(old_hashstr));
510 } else {
511 got_sha1_digest_to_str(zero_id, old_hashstr,
512 sizeof(old_hashstr));
514 got_sha1_digest_to_str(id->sha1, new_hashstr,
515 sizeof(new_hashstr));
516 err = describe_refchange(&n, &sent_my_capabilites,
517 my_capabilities, buf, sizeof(buf), refname,
518 old_hashstr, new_hashstr);
519 if (err)
520 goto done;
521 err = got_pkt_writepkt(fd, buf, n, chattygot);
522 if (err)
523 goto done;
524 if (chattygot) {
525 if (their_id) {
526 fprintf(stderr, "%s: updating %s %s -> %s\n",
527 getprogname(), refname, old_hashstr,
528 new_hashstr);
529 } else {
530 fprintf(stderr, "%s: creating %s %s\n",
531 getprogname(), refname, new_hashstr);
534 nsent++;
536 err = got_pkt_flushpkt(fd, chattygot);
537 if (err)
538 goto done;
540 err = send_pack_request(ibuf);
541 if (err)
542 goto done;
544 err = recv_packfd(&packfd, ibuf);
545 if (err)
546 goto done;
548 if (packfd != -1) {
549 err = send_pack_file(fd, packfd, ibuf);
550 if (err)
551 goto done;
554 err = got_pkt_readpkt(&n, fd, buf, sizeof(buf), chattygot);
555 if (err)
556 goto done;
557 if (n >= 4 && strncmp(buf, "ERR ", 4) == 0) {
558 err = send_error(&buf[4], n - 4);
559 goto done;
560 } else if (n < 10 || strncmp(buf, "unpack ok\n", 10) != 0) {
561 err = got_error_msg(GOT_ERR_BAD_PACKET,
562 "unexpected message from server");
563 goto done;
566 while (nsent > 0) {
567 err = got_pkt_readpkt(&n, fd, buf, sizeof(buf), chattygot);
568 if (err)
569 goto done;
570 if (n < 3) {
571 err = got_error_msg(GOT_ERR_BAD_PACKET,
572 "unexpected message from server");
573 goto done;
574 } else if (n >= 4 && strncmp(buf, "ERR ", 4) == 0) {
575 err = send_error(&buf[4], n - 4);
576 goto done;
577 } else if (strncmp(buf, "ok ", 3) == 0) {
578 err = send_ref_status(ibuf, buf + 3, 1,
579 refs, delete_refs);
580 if (err)
581 goto done;
582 } else if (strncmp(buf, "ng ", 3) == 0) {
583 err = send_ref_status(ibuf, buf + 3, 0,
584 refs, delete_refs);
585 if (err)
586 goto done;
587 } else {
588 err = got_error_msg(GOT_ERR_BAD_PACKET,
589 "unexpected message from server");
590 goto done;
592 nsent--;
595 err = send_done(ibuf);
596 done:
597 got_pathlist_free(&their_refs, GOT_PATHLIST_FREE_ALL);
598 free(id_str);
599 free(id);
600 free(refname);
601 free(server_capabilities);
602 return err;
605 int
606 main(int argc, char **argv)
608 const struct got_error *err = NULL;
609 int sendfd = -1;
610 struct imsgbuf ibuf;
611 struct imsg imsg;
612 struct got_pathlist_head refs;
613 struct got_pathlist_head delete_refs;
614 struct got_imsg_send_request send_req;
615 struct got_imsg_send_ref href;
616 size_t datalen, i;
617 #if 0
618 static int attached;
619 while (!attached)
620 sleep (1);
621 #endif
623 TAILQ_INIT(&refs);
624 TAILQ_INIT(&delete_refs);
626 imsg_init(&ibuf, GOT_IMSG_FD_CHILD);
627 #ifndef PROFILE
628 /* revoke access to most system calls */
629 if (pledge("stdio recvfd", NULL) == -1) {
630 err = got_error_from_errno("pledge");
631 got_privsep_send_error(&ibuf, err);
632 return 1;
634 #endif
635 if ((err = got_privsep_recv_imsg(&imsg, &ibuf, 0)) != 0) {
636 if (err->code == GOT_ERR_PRIVSEP_PIPE)
637 err = NULL;
638 goto done;
640 if (imsg.hdr.type == GOT_IMSG_STOP)
641 goto done;
642 if (imsg.hdr.type != GOT_IMSG_SEND_REQUEST) {
643 err = got_error(GOT_ERR_PRIVSEP_MSG);
644 goto done;
646 datalen = imsg.hdr.len - IMSG_HEADER_SIZE;
647 if (datalen < sizeof(send_req)) {
648 err = got_error(GOT_ERR_PRIVSEP_LEN);
649 goto done;
651 memcpy(&send_req, imsg.data, sizeof(send_req));
652 sendfd = imsg.fd;
653 imsg_free(&imsg);
655 if (send_req.verbosity > 0)
656 chattygot += send_req.verbosity;
658 for (i = 0; i < send_req.nrefs; i++) {
659 struct got_object_id *id;
660 char *refname;
662 if ((err = got_privsep_recv_imsg(&imsg, &ibuf, 0)) != 0) {
663 if (err->code == GOT_ERR_PRIVSEP_PIPE)
664 err = NULL;
665 goto done;
667 if (imsg.hdr.type == GOT_IMSG_STOP)
668 goto done;
669 if (imsg.hdr.type != GOT_IMSG_SEND_REF) {
670 err = got_error(GOT_ERR_PRIVSEP_MSG);
671 goto done;
673 datalen = imsg.hdr.len - IMSG_HEADER_SIZE;
674 if (datalen < sizeof(href)) {
675 err = got_error(GOT_ERR_PRIVSEP_LEN);
676 goto done;
678 memcpy(&href, imsg.data, sizeof(href));
679 if (datalen - sizeof(href) < href.name_len) {
680 err = got_error(GOT_ERR_PRIVSEP_LEN);
681 goto done;
683 refname = malloc(href.name_len + 1);
684 if (refname == NULL) {
685 err = got_error_from_errno("malloc");
686 goto done;
688 memcpy(refname, imsg.data + sizeof(href), href.name_len);
689 refname[href.name_len] = '\0';
691 /*
692 * Prevent sending of references that won't make any
693 * sense outside the local repository's context.
694 */
695 if (strncmp(refname, "refs/got/", 9) == 0 ||
696 strncmp(refname, "refs/remotes/", 13) == 0) {
697 err = got_error_fmt(GOT_ERR_SEND_BAD_REF,
698 "%s", refname);
699 goto done;
702 id = malloc(sizeof(*id));
703 if (id == NULL) {
704 free(refname);
705 err = got_error_from_errno("malloc");
706 goto done;
708 memcpy(id, &href.id, sizeof(*id));
709 if (href.delete)
710 err = got_pathlist_append(&delete_refs, refname, id);
711 else
712 err = got_pathlist_append(&refs, refname, id);
713 if (err) {
714 free(refname);
715 free(id);
716 goto done;
719 imsg_free(&imsg);
722 err = send_pack(sendfd, &refs, &delete_refs, &ibuf);
723 done:
724 got_pathlist_free(&refs, GOT_PATHLIST_FREE_ALL);
725 got_pathlist_free(&delete_refs, GOT_PATHLIST_FREE_ALL);
726 if (sendfd != -1 && close(sendfd) == -1 && err == NULL)
727 err = got_error_from_errno("close");
728 if (err != NULL && err->code != GOT_ERR_CANCELLED) {
729 fprintf(stderr, "%s: %s\n", getprogname(), err->msg);
730 got_privsep_send_error(&ibuf, err);
733 exit(0);