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 <fcntl.h>
35 #include <unistd.h>
36 #include <zlib.h>
37 #include <err.h>
39 #include "got_error.h"
40 #include "got_object.h"
41 #include "got_path.h"
42 #include "got_version.h"
43 #include "got_fetch.h"
44 #include "got_reference.h"
46 #include "got_lib_sha1.h"
47 #include "got_lib_delta.h"
48 #include "got_lib_object.h"
49 #include "got_lib_object_parse.h"
50 #include "got_lib_privsep.h"
51 #include "got_lib_pack.h"
52 #include "got_lib_pkt.h"
53 #include "got_lib_gitproto.h"
54 #include "got_lib_ratelimit.h"
55 #include "got_lib_poll.h"
57 #ifndef nitems
58 #define nitems(_a) (sizeof((_a)) / sizeof((_a)[0]))
59 #endif
61 struct got_object *indexed;
62 static int chattygot;
64 static const struct got_capability got_capabilities[] = {
65 { GOT_CAPA_AGENT, "got/" GOT_VERSION_STR },
66 { GOT_CAPA_OFS_DELTA, NULL },
67 #if 0
68 { GOT_CAPA_SIDE_BAND_64K, NULL },
69 #endif
70 { GOT_CAPA_REPORT_STATUS, NULL },
71 { GOT_CAPA_DELETE_REFS, NULL },
72 };
74 static const struct got_error *
75 send_upload_progress(struct imsgbuf *ibuf, off_t bytes,
76 struct got_ratelimit *rl)
77 {
78 const struct got_error *err = NULL;
79 int elapsed = 0;
81 if (rl) {
82 err = got_ratelimit_check(&elapsed, rl);
83 if (err || !elapsed)
84 return err;
85 }
87 if (imsg_compose(ibuf, GOT_IMSG_SEND_UPLOAD_PROGRESS, 0, 0, -1,
88 &bytes, sizeof(bytes)) == -1)
89 return got_error_from_errno(
90 "imsg_compose SEND_UPLOAD_PROGRESS");
92 return got_privsep_flush_imsg(ibuf);
93 }
95 static const struct got_error *
96 send_pack_request(struct imsgbuf *ibuf)
97 {
98 if (imsg_compose(ibuf, GOT_IMSG_SEND_PACK_REQUEST, 0, 0, -1,
99 NULL, 0) == -1)
100 return got_error_from_errno("imsg_compose SEND_PACK_REQUEST");
101 return got_privsep_flush_imsg(ibuf);
104 static const struct got_error *
105 send_done(struct imsgbuf *ibuf)
107 if (imsg_compose(ibuf, GOT_IMSG_SEND_DONE, 0, 0, -1, NULL, 0) == -1)
108 return got_error_from_errno("imsg_compose SEND_DONE");
109 return got_privsep_flush_imsg(ibuf);
112 static const struct got_error *
113 recv_packfd(int *packfd, struct imsgbuf *ibuf)
115 const struct got_error *err;
116 struct imsg imsg;
118 *packfd = -1;
120 err = got_privsep_recv_imsg(&imsg, ibuf, 0);
121 if (err)
122 return err;
124 if (imsg.hdr.type == GOT_IMSG_STOP) {
125 err = got_error(GOT_ERR_CANCELLED);
126 goto done;
129 if (imsg.hdr.type != GOT_IMSG_SEND_PACKFD) {
130 err = got_error(GOT_ERR_PRIVSEP_MSG);
131 goto done;
134 if (imsg.hdr.len - IMSG_HEADER_SIZE != 0) {
135 err = got_error(GOT_ERR_PRIVSEP_LEN);
136 goto done;
139 *packfd = imsg.fd;
140 done:
141 imsg_free(&imsg);
142 return err;
145 static const struct got_error *
146 send_pack_file(int sendfd, int packfd, struct imsgbuf *ibuf)
148 const struct got_error *err;
149 unsigned char buf[8192];
150 ssize_t r;
151 off_t wtotal = 0;
152 struct got_ratelimit rl;
154 if (lseek(packfd, 0L, SEEK_SET) == -1)
155 return got_error_from_errno("lseek");
157 got_ratelimit_init(&rl, 0, 500);
159 for (;;) {
160 r = read(packfd, buf, sizeof(buf));
161 if (r == -1)
162 return got_error_from_errno("read");
163 if (r == 0)
164 break;
165 err = got_poll_write_full(sendfd, buf, r);
166 if (err)
167 return NULL;
168 wtotal += r;
169 err = send_upload_progress(ibuf, wtotal, &rl);
170 if (err)
171 return err;
174 return send_upload_progress(ibuf, wtotal, NULL);
177 static const struct got_error *
178 send_error(const char *buf, size_t len)
180 static char msg[1024];
181 size_t i;
183 for (i = 0; i < len && i < sizeof(msg) - 1; i++) {
184 if (!isprint((unsigned char)buf[i]))
185 return got_error_msg(GOT_ERR_BAD_PACKET,
186 "non-printable error message received from server");
187 msg[i] = buf[i];
189 msg[i] = '\0';
190 return got_error_msg(GOT_ERR_SEND_FAILED, msg);
193 static const struct got_error *
194 send_their_ref(struct imsgbuf *ibuf, struct got_object_id *refid,
195 const char *refname)
197 struct ibuf *wbuf;
198 size_t len, reflen = strlen(refname);
200 len = sizeof(struct got_imsg_send_remote_ref) + reflen;
201 if (len >= MAX_IMSGSIZE - IMSG_HEADER_SIZE)
202 return got_error(GOT_ERR_NO_SPACE);
204 wbuf = imsg_create(ibuf, GOT_IMSG_SEND_REMOTE_REF, 0, 0, len);
205 if (wbuf == NULL)
206 return got_error_from_errno("imsg_create SEND_REMOTE_REF");
208 /* Keep in sync with struct got_imsg_send_remote_ref definition! */
209 if (imsg_add(wbuf, refid->sha1, SHA1_DIGEST_LENGTH) == -1)
210 return got_error_from_errno("imsg_add SEND_REMOTE_REF");
211 if (imsg_add(wbuf, &reflen, sizeof(reflen)) == -1)
212 return got_error_from_errno("imsg_add SEND_REMOTE_REF");
213 if (imsg_add(wbuf, refname, reflen) == -1)
214 return got_error_from_errno("imsg_add SEND_REMOTE_REF");
216 wbuf->fd = -1;
217 imsg_close(ibuf, wbuf);
218 return got_privsep_flush_imsg(ibuf);
221 static const struct got_error *
222 send_ref_status(struct imsgbuf *ibuf, const char *refname, int success,
223 struct got_pathlist_head *refs, struct got_pathlist_head *delete_refs)
225 struct ibuf *wbuf;
226 size_t i, len, reflen, errmsglen = 0;
227 struct got_pathlist_entry *pe;
228 int ref_valid = 0;
229 char *eol, *sp;
230 const char *errmsg = "";
232 eol = strchr(refname, '\n');
233 if (eol == NULL) {
234 return got_error_msg(GOT_ERR_BAD_PACKET,
235 "unexpected message from server");
237 *eol = '\0';
239 sp = strchr(refname, ' ');
240 if (sp != NULL) {
241 *sp++ = '\0';
242 errmsg = sp;
243 errmsglen = strlen(errmsg);
245 for (i = 0; i < errmsglen; ++i) {
246 if (!isprint((unsigned char)errmsg[i])) {
247 return got_error_msg(GOT_ERR_BAD_PACKET,
248 "non-printable error message received "
249 "from the server");
254 reflen = strlen(refname);
255 if (!got_ref_name_is_valid(refname)) {
256 return got_error_msg(GOT_ERR_BAD_PACKET,
257 "unexpected message from server");
260 TAILQ_FOREACH(pe, refs, entry) {
261 if (strcmp(refname, pe->path) == 0) {
262 ref_valid = 1;
263 break;
266 if (!ref_valid) {
267 TAILQ_FOREACH(pe, delete_refs, entry) {
268 if (strcmp(refname, pe->path) == 0) {
269 ref_valid = 1;
270 break;
274 if (!ref_valid) {
275 return got_error_msg(GOT_ERR_BAD_PACKET,
276 "unexpected message from server");
279 len = sizeof(struct got_imsg_send_ref_status) + reflen + errmsglen;
280 if (len >= MAX_IMSGSIZE - IMSG_HEADER_SIZE)
281 return got_error(GOT_ERR_NO_SPACE);
283 wbuf = imsg_create(ibuf, GOT_IMSG_SEND_REF_STATUS,
284 0, 0, len);
285 if (wbuf == NULL)
286 return got_error_from_errno("imsg_create SEND_REF_STATUS");
288 /* Keep in sync with struct got_imsg_send_ref_status definition! */
289 if (imsg_add(wbuf, &success, sizeof(success)) == -1)
290 return got_error_from_errno("imsg_add SEND_REF_STATUS");
291 if (imsg_add(wbuf, &reflen, sizeof(reflen)) == -1)
292 return got_error_from_errno("imsg_add SEND_REF_STATUS");
293 if (imsg_add(wbuf, &errmsglen, sizeof(errmsglen)) == -1)
294 return got_error_from_errno("imsg_add SEND_REF_STATUS");
295 if (imsg_add(wbuf, refname, reflen) == -1)
296 return got_error_from_errno("imsg_add SEND_REF_STATUS");
297 if (imsg_add(wbuf, errmsg, errmsglen) == -1)
298 return got_error_from_errno("imsg_add SEND_REF_STATUS");
300 wbuf->fd = -1;
301 imsg_close(ibuf, wbuf);
302 return got_privsep_flush_imsg(ibuf);
305 static const struct got_error *
306 describe_refchange(int *n, int *sent_my_capabilites,
307 const char *my_capabilities, char *buf, size_t bufsize,
308 const char *refname, const char *old_hashstr, const char *new_hashstr)
310 *n = snprintf(buf, bufsize, "%s %s %s",
311 old_hashstr, new_hashstr, refname);
312 if (*n < 0 || (size_t)*n >= bufsize)
313 return got_error(GOT_ERR_NO_SPACE);
315 /*
316 * We must announce our capabilities along with the first
317 * reference. Unfortunately, the protocol requires an embedded
318 * NUL as a separator between reference name and capabilities,
319 * which we have to deal with here.
320 * It also requires a linefeed for terminating packet data.
321 */
322 if (!*sent_my_capabilites && my_capabilities != NULL) {
323 int m;
324 if (*n >= bufsize - 1)
325 return got_error(GOT_ERR_NO_SPACE);
326 m = snprintf(buf + *n + 1, /* offset after '\0' */
327 bufsize - (*n + 1), "%s\n", my_capabilities);
328 if (m < 0 || *n + m >= bufsize)
329 return got_error(GOT_ERR_NO_SPACE);
330 *n += m;
331 *sent_my_capabilites = 1;
332 } else {
333 *n = strlcat(buf, "\n", bufsize);
334 if (*n >= bufsize)
335 return got_error(GOT_ERR_NO_SPACE);
338 return NULL;
341 static const struct got_error *
342 send_pack(int fd, struct got_pathlist_head *refs,
343 struct got_pathlist_head *delete_refs, struct imsgbuf *ibuf)
345 const struct got_error *err = NULL;
346 char buf[GOT_PKT_MAX];
347 const unsigned char zero_id[SHA1_DIGEST_LENGTH] = { 0 };
348 char old_hashstr[SHA1_DIGEST_STRING_LENGTH];
349 char new_hashstr[SHA1_DIGEST_STRING_LENGTH];
350 struct got_pathlist_head their_refs;
351 int is_firstpkt = 1;
352 int n, nsent = 0;
353 int packfd = -1;
354 char *id_str = NULL, *refname = NULL;
355 struct got_object_id *id = NULL;
356 char *server_capabilities = NULL, *my_capabilities = NULL;
357 struct got_pathlist_entry *pe;
358 int sent_my_capabilites = 0;
360 TAILQ_INIT(&their_refs);
362 if (TAILQ_EMPTY(refs) && TAILQ_EMPTY(delete_refs))
363 return got_error(GOT_ERR_SEND_EMPTY);
365 while (1) {
366 err = got_pkt_readpkt(&n, fd, buf, sizeof(buf), chattygot);
367 if (err)
368 goto done;
369 if (n == 0)
370 break;
371 if (n >= 4 && strncmp(buf, "ERR ", 4) == 0) {
372 err = send_error(&buf[4], n - 4);
373 goto done;
375 free(id_str);
376 free(refname);
377 err = got_gitproto_parse_refline(&id_str, &refname,
378 &server_capabilities, buf, n);
379 if (err)
380 goto done;
381 if (is_firstpkt) {
382 if (server_capabilities == NULL) {
383 server_capabilities = strdup("");
384 if (server_capabilities == NULL) {
385 err = got_error_from_errno("strdup");
386 goto done;
389 if (chattygot && server_capabilities[0] != '\0')
390 fprintf(stderr, "%s: server capabilities: %s\n",
391 getprogname(), server_capabilities);
392 err = got_gitproto_match_capabilities(&my_capabilities,
393 NULL, server_capabilities, got_capabilities,
394 nitems(got_capabilities));
395 if (err)
396 goto done;
397 if (chattygot)
398 fprintf(stderr, "%s: my capabilities:%s\n",
399 getprogname(),
400 my_capabilities ? my_capabilities : "");
401 is_firstpkt = 0;
403 if (strstr(refname, "^{}")) {
404 if (chattygot) {
405 fprintf(stderr, "%s: ignoring %s\n",
406 getprogname(), refname);
408 continue;
411 id = malloc(sizeof(*id));
412 if (id == NULL) {
413 err = got_error_from_errno("malloc");
414 goto done;
416 if (!got_parse_sha1_digest(id->sha1, id_str)) {
417 err = got_error(GOT_ERR_BAD_OBJ_ID_STR);
418 goto done;
420 err = send_their_ref(ibuf, id, refname);
421 if (err)
422 goto done;
424 err = got_pathlist_append(&their_refs, refname, id);
425 if (err)
426 goto done;
428 if (chattygot)
429 fprintf(stderr, "%s: remote has %s %s\n",
430 getprogname(), refname, id_str);
431 free(id_str);
432 id_str = NULL;
433 refname = NULL; /* do not free; owned by their_refs */
434 id = NULL; /* do not free; owned by their_refs */
437 if (!TAILQ_EMPTY(delete_refs)) {
438 if (my_capabilities == NULL ||
439 strstr(my_capabilities, GOT_CAPA_DELETE_REFS) == NULL) {
440 err = got_error(GOT_ERR_CAPA_DELETE_REFS);
441 goto done;
445 TAILQ_FOREACH(pe, delete_refs, entry) {
446 const char *refname = pe->path;
447 struct got_pathlist_entry *their_pe;
448 struct got_object_id *their_id = NULL;
450 TAILQ_FOREACH(their_pe, &their_refs, entry) {
451 const char *their_refname = their_pe->path;
452 if (got_path_cmp(refname, their_refname,
453 strlen(refname), strlen(their_refname)) == 0) {
454 their_id = their_pe->data;
455 break;
458 if (their_id == NULL) {
459 err = got_error_fmt(GOT_ERR_NOT_REF,
460 "%s does not exist in remote repository",
461 refname);
462 goto done;
465 got_sha1_digest_to_str(their_id->sha1, old_hashstr,
466 sizeof(old_hashstr));
467 got_sha1_digest_to_str(zero_id, new_hashstr,
468 sizeof(new_hashstr));
469 err = describe_refchange(&n, &sent_my_capabilites,
470 my_capabilities, buf, sizeof(buf), refname,
471 old_hashstr, new_hashstr);
472 if (err)
473 goto done;
474 err = got_pkt_writepkt(fd, buf, n, chattygot);
475 if (err)
476 goto done;
477 if (chattygot) {
478 fprintf(stderr, "%s: deleting %s %s\n",
479 getprogname(), refname, old_hashstr);
481 nsent++;
484 TAILQ_FOREACH(pe, refs, entry) {
485 const char *refname = pe->path;
486 struct got_object_id *id = pe->data;
487 struct got_object_id *their_id = NULL;
488 struct got_pathlist_entry *their_pe;
490 TAILQ_FOREACH(their_pe, &their_refs, entry) {
491 const char *their_refname = their_pe->path;
492 if (got_path_cmp(refname, their_refname,
493 strlen(refname), strlen(their_refname)) == 0) {
494 their_id = their_pe->data;
495 break;
498 if (their_id) {
499 if (got_object_id_cmp(id, their_id) == 0) {
500 if (chattygot) {
501 fprintf(stderr,
502 "%s: no change for %s\n",
503 getprogname(), refname);
505 continue;
507 got_sha1_digest_to_str(their_id->sha1, old_hashstr,
508 sizeof(old_hashstr));
509 } else {
510 got_sha1_digest_to_str(zero_id, old_hashstr,
511 sizeof(old_hashstr));
513 got_sha1_digest_to_str(id->sha1, new_hashstr,
514 sizeof(new_hashstr));
515 err = describe_refchange(&n, &sent_my_capabilites,
516 my_capabilities, buf, sizeof(buf), refname,
517 old_hashstr, new_hashstr);
518 if (err)
519 goto done;
520 err = got_pkt_writepkt(fd, buf, n, chattygot);
521 if (err)
522 goto done;
523 if (chattygot) {
524 if (their_id) {
525 fprintf(stderr, "%s: updating %s %s -> %s\n",
526 getprogname(), refname, old_hashstr,
527 new_hashstr);
528 } else {
529 fprintf(stderr, "%s: creating %s %s\n",
530 getprogname(), refname, new_hashstr);
533 nsent++;
535 err = got_pkt_flushpkt(fd, chattygot);
536 if (err)
537 goto done;
539 err = send_pack_request(ibuf);
540 if (err)
541 goto done;
543 err = recv_packfd(&packfd, ibuf);
544 if (err)
545 goto done;
547 if (packfd != -1) {
548 err = send_pack_file(fd, packfd, ibuf);
549 if (err)
550 goto done;
553 err = got_pkt_readpkt(&n, fd, buf, sizeof(buf), chattygot);
554 if (err)
555 goto done;
556 if (n >= 4 && strncmp(buf, "ERR ", 4) == 0) {
557 err = send_error(&buf[4], n - 4);
558 goto done;
559 } else if (n < 10 || strncmp(buf, "unpack ok\n", 10) != 0) {
560 err = got_error_msg(GOT_ERR_BAD_PACKET,
561 "unexpected message from server");
562 goto done;
565 while (nsent > 0) {
566 err = got_pkt_readpkt(&n, fd, buf, sizeof(buf), chattygot);
567 if (err)
568 goto done;
569 if (n < 3) {
570 err = got_error_msg(GOT_ERR_BAD_PACKET,
571 "unexpected message from server");
572 goto done;
573 } else if (n >= 4 && strncmp(buf, "ERR ", 4) == 0) {
574 err = send_error(&buf[4], n - 4);
575 goto done;
576 } else if (strncmp(buf, "ok ", 3) == 0) {
577 err = send_ref_status(ibuf, buf + 3, 1,
578 refs, delete_refs);
579 if (err)
580 goto done;
581 } else if (strncmp(buf, "ng ", 3) == 0) {
582 err = send_ref_status(ibuf, buf + 3, 0,
583 refs, delete_refs);
584 if (err)
585 goto done;
586 } else {
587 err = got_error_msg(GOT_ERR_BAD_PACKET,
588 "unexpected message from server");
589 goto done;
591 nsent--;
594 err = send_done(ibuf);
595 done:
596 got_pathlist_free(&their_refs, GOT_PATHLIST_FREE_ALL);
597 free(id_str);
598 free(id);
599 free(refname);
600 free(server_capabilities);
601 return err;
604 int
605 main(int argc, char **argv)
607 const struct got_error *err = NULL;
608 int sendfd = -1;
609 struct imsgbuf ibuf;
610 struct imsg imsg;
611 struct got_pathlist_head refs;
612 struct got_pathlist_head delete_refs;
613 struct got_imsg_send_request send_req;
614 struct got_imsg_send_ref href;
615 size_t datalen, i;
616 #if 0
617 static int attached;
618 while (!attached)
619 sleep (1);
620 #endif
622 TAILQ_INIT(&refs);
623 TAILQ_INIT(&delete_refs);
625 imsg_init(&ibuf, GOT_IMSG_FD_CHILD);
626 #ifndef PROFILE
627 /* revoke access to most system calls */
628 if (pledge("stdio recvfd", NULL) == -1) {
629 err = got_error_from_errno("pledge");
630 got_privsep_send_error(&ibuf, err);
631 return 1;
633 #endif
634 if ((err = got_privsep_recv_imsg(&imsg, &ibuf, 0)) != 0) {
635 if (err->code == GOT_ERR_PRIVSEP_PIPE)
636 err = NULL;
637 goto done;
639 if (imsg.hdr.type == GOT_IMSG_STOP)
640 goto done;
641 if (imsg.hdr.type != GOT_IMSG_SEND_REQUEST) {
642 err = got_error(GOT_ERR_PRIVSEP_MSG);
643 goto done;
645 datalen = imsg.hdr.len - IMSG_HEADER_SIZE;
646 if (datalen < sizeof(send_req)) {
647 err = got_error(GOT_ERR_PRIVSEP_LEN);
648 goto done;
650 memcpy(&send_req, imsg.data, sizeof(send_req));
651 sendfd = imsg.fd;
652 imsg_free(&imsg);
654 if (send_req.verbosity > 0)
655 chattygot += send_req.verbosity;
657 for (i = 0; i < send_req.nrefs; i++) {
658 struct got_object_id *id;
659 char *refname;
661 if ((err = got_privsep_recv_imsg(&imsg, &ibuf, 0)) != 0) {
662 if (err->code == GOT_ERR_PRIVSEP_PIPE)
663 err = NULL;
664 goto done;
666 if (imsg.hdr.type == GOT_IMSG_STOP)
667 goto done;
668 if (imsg.hdr.type != GOT_IMSG_SEND_REF) {
669 err = got_error(GOT_ERR_PRIVSEP_MSG);
670 goto done;
672 datalen = imsg.hdr.len - IMSG_HEADER_SIZE;
673 if (datalen < sizeof(href)) {
674 err = got_error(GOT_ERR_PRIVSEP_LEN);
675 goto done;
677 memcpy(&href, imsg.data, sizeof(href));
678 if (datalen - sizeof(href) < href.name_len) {
679 err = got_error(GOT_ERR_PRIVSEP_LEN);
680 goto done;
682 refname = malloc(href.name_len + 1);
683 if (refname == NULL) {
684 err = got_error_from_errno("malloc");
685 goto done;
687 memcpy(refname, imsg.data + sizeof(href), href.name_len);
688 refname[href.name_len] = '\0';
690 /*
691 * Prevent sending of references that won't make any
692 * sense outside the local repository's context.
693 */
694 if (strncmp(refname, "refs/got/", 9) == 0 ||
695 strncmp(refname, "refs/remotes/", 13) == 0) {
696 err = got_error_fmt(GOT_ERR_SEND_BAD_REF,
697 "%s", refname);
698 goto done;
701 id = malloc(sizeof(*id));
702 if (id == NULL) {
703 free(refname);
704 err = got_error_from_errno("malloc");
705 goto done;
707 memcpy(id->sha1, href.id, SHA1_DIGEST_LENGTH);
708 if (href.delete)
709 err = got_pathlist_append(&delete_refs, refname, id);
710 else
711 err = got_pathlist_append(&refs, refname, id);
712 if (err) {
713 free(refname);
714 free(id);
715 goto done;
718 imsg_free(&imsg);
721 err = send_pack(sendfd, &refs, &delete_refs, &ibuf);
722 done:
723 got_pathlist_free(&refs, GOT_PATHLIST_FREE_ALL);
724 got_pathlist_free(&delete_refs, GOT_PATHLIST_FREE_ALL);
725 if (sendfd != -1 && close(sendfd) == -1 && err == NULL)
726 err = got_error_from_errno("close");
727 if (err != NULL && err->code != GOT_ERR_CANCELLED) {
728 fprintf(stderr, "%s: %s\n", getprogname(), err->msg);
729 got_privsep_send_error(&ibuf, err);
732 exit(0);