]> git.ipfire.org Git - thirdparty/git.git/blame - builtin-send-pack.c
Increase the size of the die/warning buffer to avoid truncation
[thirdparty/git.git] / builtin-send-pack.c
CommitLineData
61221472 1#include "cache.h"
2a9c3fe8 2#include "commit.h"
37fde874 3#include "tag.h"
584c6cc9 4#include "refs.h"
f3a3214e 5#include "pkt-line.h"
38b1c662 6#include "run-command.h"
6b62816c 7#include "remote.h"
96249c04 8#include "send-pack.h"
61221472 9
2a245013 10static const char send_pack_usage[] =
1b1dd23f 11"git send-pack [--all | --mirror] [--dry-run] [--force] [--receive-pack=<git-receive-pack>] [--verbose] [--thin] [<host>:]<directory> [<ref>...]\n"
18bd8821 12" --all and explicit <ref> specification are mutually exclusive.";
96249c04
DB
13
14static struct send_pack_args args = {
15 /* .receivepack = */ "git-receive-pack",
16};
61221472 17
02322e16
JH
18static int feed_object(const unsigned char *sha1, int fd, int negative)
19{
20 char buf[42];
21
22 if (negative && !has_sha1_file(sha1))
23 return 1;
24
25 memcpy(buf + negative, sha1_to_hex(sha1), 40);
26 if (negative)
27 buf[0] = '^';
28 buf[40 + negative] = '\n';
29 return write_or_whine(fd, buf, 41 + negative, "send-pack: send refs");
30}
31
c727fe2a 32/*
0ae5f98c 33 * Make a pack stream and spit it out into file descriptor fd
c727fe2a 34 */
40c155ff 35static int pack_objects(int fd, struct ref *refs, struct extra_have_objects *extra)
c727fe2a 36{
38b1c662
SP
37 /*
38 * The child becomes pack-objects --revs; we feed
39 * the revision parameters to it via its stdin and
40 * let its stdout go back to the other end.
41 */
96249c04 42 const char *argv[] = {
38b1c662
SP
43 "pack-objects",
44 "--all-progress",
45 "--revs",
46 "--stdout",
47 NULL,
48 NULL,
49 };
50 struct child_process po;
40c155ff 51 int i;
c727fe2a 52
96249c04
DB
53 if (args.use_thin_pack)
54 argv[4] = "--thin";
38b1c662 55 memset(&po, 0, sizeof(po));
96249c04 56 po.argv = argv;
38b1c662
SP
57 po.in = -1;
58 po.out = fd;
59 po.git_cmd = 1;
60 if (start_command(&po))
f18d244a 61 die("git pack-objects failed (%s)", strerror(errno));
c727fe2a 62
0ae5f98c
JH
63 /*
64 * We feed the pack-objects we just spawned with revision
65 * parameters by writing to the pipe.
c727fe2a 66 */
02322e16
JH
67 for (i = 0; i < extra->nr; i++)
68 if (!feed_object(extra->array[i], po.in, 1))
40c155ff 69 break;
c727fe2a 70
40c155ff 71 while (refs) {
c727fe2a 72 if (!is_null_sha1(refs->old_sha1) &&
02322e16
JH
73 !feed_object(refs->old_sha1, po.in, 1))
74 break;
75 if (!is_null_sha1(refs->new_sha1) &&
76 !feed_object(refs->new_sha1, po.in, 0))
77 break;
c727fe2a
AW
78 refs = refs->next;
79 }
c727fe2a 80
e72ae288 81 close(po.in);
38b1c662
SP
82 if (finish_command(&po))
83 return error("pack-objects died with strange error");
84 return 0;
94fdb7aa 85}
e4b5c7ff 86
51b0fca0
JH
87static void unmark_and_free(struct commit_list *list, unsigned int mark)
88{
89 while (list) {
90 struct commit_list *temp = list;
91 temp->item->object.flags &= ~mark;
92 list = temp->next;
93 free(temp);
94 }
95}
96
37fde874
JH
97static int ref_newer(const unsigned char *new_sha1,
98 const unsigned char *old_sha1)
584c6cc9 99{
37fde874
JH
100 struct object *o;
101 struct commit *old, *new;
51b0fca0
JH
102 struct commit_list *list, *used;
103 int found = 0;
2a9c3fe8 104
37fde874
JH
105 /* Both new and old must be commit-ish and new is descendant of
106 * old. Otherwise we require --force.
107 */
9534f40b 108 o = deref_tag(parse_object(old_sha1), NULL, 0);
1974632c 109 if (!o || o->type != OBJ_COMMIT)
584c6cc9 110 return 0;
37fde874
JH
111 old = (struct commit *) o;
112
9534f40b 113 o = deref_tag(parse_object(new_sha1), NULL, 0);
1974632c 114 if (!o || o->type != OBJ_COMMIT)
2a9c3fe8 115 return 0;
37fde874
JH
116 new = (struct commit *) o;
117
2a9c3fe8
LT
118 if (parse_commit(new) < 0)
119 return 0;
51b0fca0
JH
120
121 used = list = NULL;
2a9c3fe8 122 commit_list_insert(new, &list);
bdf25142
LT
123 while (list) {
124 new = pop_most_recent_commit(&list, 1);
51b0fca0
JH
125 commit_list_insert(new, &used);
126 if (new == old) {
127 found = 1;
128 break;
129 }
2a9c3fe8 130 }
51b0fca0
JH
131 unmark_and_free(list, 1);
132 unmark_and_free(used, 1);
133 return found;
584c6cc9
LT
134}
135
f88395ac
JH
136static struct ref *local_refs, **local_tail;
137static struct ref *remote_refs, **remote_tail;
584c6cc9 138
8da19775 139static int one_local_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data)
584c6cc9
LT
140{
141 struct ref *ref;
30affa1e
JK
142 int len;
143
144 /* we already know it starts with refs/ to get here */
145 if (check_ref_format(refname + 5))
146 return 0;
147
148 len = strlen(refname) + 1;
f88395ac 149 ref = xcalloc(1, sizeof(*ref) + len);
e702496e 150 hashcpy(ref->new_sha1, sha1);
584c6cc9 151 memcpy(ref->name, refname, len);
f88395ac
JH
152 *local_tail = ref;
153 local_tail = &ref->next;
584c6cc9
LT
154 return 0;
155}
156
f88395ac
JH
157static void get_local_heads(void)
158{
159 local_tail = &local_refs;
cb5d709f 160 for_each_ref(one_local_ref, NULL);
f88395ac
JH
161}
162
ca74c458
JK
163static int receive_status(int in, struct ref *refs)
164{
165 struct ref *hint;
cfee10a7
JH
166 char line[1000];
167 int ret = 0;
168 int len = packet_read_line(in, line, sizeof(line));
2a0fe89a
JK
169 if (len < 10 || memcmp(line, "unpack ", 7))
170 return error("did not receive remote status");
cfee10a7 171 if (memcmp(line, "unpack ok\n", 10)) {
2a0fe89a
JK
172 char *p = line + strlen(line) - 1;
173 if (*p == '\n')
174 *p = '\0';
175 error("unpack failed: %s", line + 7);
cfee10a7
JH
176 ret = -1;
177 }
ca74c458 178 hint = NULL;
cfee10a7 179 while (1) {
2a0fe89a
JK
180 char *refname;
181 char *msg;
cfee10a7
JH
182 len = packet_read_line(in, line, sizeof(line));
183 if (!len)
184 break;
185 if (len < 3 ||
2a0fe89a 186 (memcmp(line, "ok ", 3) && memcmp(line, "ng ", 3))) {
cfee10a7
JH
187 fprintf(stderr, "protocol error: %s\n", line);
188 ret = -1;
189 break;
190 }
2a0fe89a
JK
191
192 line[strlen(line)-1] = '\0';
193 refname = line + 3;
194 msg = strchr(refname, ' ');
195 if (msg)
196 *msg++ = '\0';
197
198 /* first try searching at our hint, falling back to all refs */
ca74c458 199 if (hint)
2a0fe89a 200 hint = find_ref_by_name(hint, refname);
ca74c458 201 if (!hint)
2a0fe89a
JK
202 hint = find_ref_by_name(refs, refname);
203 if (!hint) {
204 warning("remote reported status on unknown ref: %s",
205 refname);
206 continue;
207 }
208 if (hint->status != REF_STATUS_EXPECTING_REPORT) {
209 warning("remote reported status on unexpected ref: %s",
210 refname);
211 continue;
212 }
213
214 if (line[0] == 'o' && line[1] == 'k')
215 hint->status = REF_STATUS_OK;
216 else {
217 hint->status = REF_STATUS_REMOTE_REJECT;
218 ret = -1;
219 }
220 if (msg)
221 hint->remote_status = xstrdup(msg);
222 /* start our next search from the next ref */
223 hint = hint->next;
cfee10a7
JH
224 }
225 return ret;
226}
227
334f4831
JK
228static void update_tracking_ref(struct remote *remote, struct ref *ref)
229{
230 struct refspec rs;
334f4831 231
16ed2f48 232 if (ref->status != REF_STATUS_OK && ref->status != REF_STATUS_UPTODATE)
334f4831
JK
233 return;
234
1f0e2a1a
JK
235 rs.src = ref->name;
236 rs.dst = NULL;
334f4831
JK
237
238 if (!remote_find_tracking(remote, &rs)) {
b50fa2bd
JK
239 if (args.verbose)
240 fprintf(stderr, "updating local tracking ref '%s'\n", rs.dst);
1f0e2a1a 241 if (ref->deletion) {
eca35a25 242 delete_ref(rs.dst, NULL, 0);
334f4831
JK
243 } else
244 update_ref("update by push", rs.dst,
245 ref->new_sha1, NULL, 0, 0);
246 free(rs.dst);
247 }
248}
249
8736a848 250static const char *prettify_ref(const struct ref *ref)
f7673490 251{
8736a848 252 const char *name = ref->name;
f7673490
JK
253 return name + (
254 !prefixcmp(name, "refs/heads/") ? 11 :
255 !prefixcmp(name, "refs/tags/") ? 10 :
256 !prefixcmp(name, "refs/remotes/") ? 13 :
257 0);
258}
259
260#define SUMMARY_WIDTH (2 * DEFAULT_ABBREV + 3)
261
8736a848
JK
262static void print_ref_status(char flag, const char *summary, struct ref *to, struct ref *from, const char *msg)
263{
264 fprintf(stderr, " %c %-*s ", flag, SUMMARY_WIDTH, summary);
265 if (from)
266 fprintf(stderr, "%s -> %s", prettify_ref(from), prettify_ref(to));
267 else
268 fputs(prettify_ref(to), stderr);
269 if (msg) {
270 fputs(" (", stderr);
271 fputs(msg, stderr);
272 fputc(')', stderr);
273 }
274 fputc('\n', stderr);
275}
276
277static const char *status_abbrev(unsigned char sha1[20])
278{
2efb3b06 279 return find_unique_abbrev(sha1, DEFAULT_ABBREV);
8736a848
JK
280}
281
282static void print_ok_ref_status(struct ref *ref)
283{
284 if (ref->deletion)
285 print_ref_status('-', "[deleted]", ref, NULL, NULL);
286 else if (is_null_sha1(ref->old_sha1))
287 print_ref_status('*',
288 (!prefixcmp(ref->name, "refs/tags/") ? "[new tag]" :
289 "[new branch]"),
290 ref, ref->peer_ref, NULL);
291 else {
292 char quickref[84];
293 char type;
294 const char *msg;
295
296 strcpy(quickref, status_abbrev(ref->old_sha1));
297 if (ref->nonfastforward) {
298 strcat(quickref, "...");
299 type = '+';
300 msg = "forced update";
301 } else {
302 strcat(quickref, "..");
303 type = ' ';
304 msg = NULL;
305 }
306 strcat(quickref, status_abbrev(ref->new_sha1));
307
308 print_ref_status(type, quickref, ref, ref->peer_ref, msg);
309 }
310}
311
07f50715
JK
312static int print_one_push_status(struct ref *ref, const char *dest, int count)
313{
314 if (!count)
315 fprintf(stderr, "To %s\n", dest);
316
317 switch(ref->status) {
318 case REF_STATUS_NONE:
319 print_ref_status('X', "[no match]", ref, NULL, NULL);
320 break;
321 case REF_STATUS_REJECT_NODELETE:
322 print_ref_status('!', "[rejected]", ref, NULL,
323 "remote does not support deleting refs");
324 break;
325 case REF_STATUS_UPTODATE:
326 print_ref_status('=', "[up to date]", ref,
327 ref->peer_ref, NULL);
328 break;
329 case REF_STATUS_REJECT_NONFASTFORWARD:
330 print_ref_status('!', "[rejected]", ref, ref->peer_ref,
331 "non-fast forward");
332 break;
333 case REF_STATUS_REMOTE_REJECT:
334 print_ref_status('!', "[remote rejected]", ref,
335 ref->deletion ? NULL : ref->peer_ref,
336 ref->remote_status);
337 break;
338 case REF_STATUS_EXPECTING_REPORT:
339 print_ref_status('!', "[remote failure]", ref,
340 ref->deletion ? NULL : ref->peer_ref,
341 "remote failed to report status");
342 break;
343 case REF_STATUS_OK:
344 print_ok_ref_status(ref);
345 break;
346 }
347
348 return 1;
349}
350
8736a848
JK
351static void print_push_status(const char *dest, struct ref *refs)
352{
353 struct ref *ref;
07f50715 354 int n = 0;
8736a848 355
07f50715
JK
356 if (args.verbose) {
357 for (ref = refs; ref; ref = ref->next)
358 if (ref->status == REF_STATUS_UPTODATE)
359 n += print_one_push_status(ref, dest, n);
360 }
8736a848 361
07f50715
JK
362 for (ref = refs; ref; ref = ref->next)
363 if (ref->status == REF_STATUS_OK)
364 n += print_one_push_status(ref, dest, n);
8736a848 365
07f50715
JK
366 for (ref = refs; ref; ref = ref->next) {
367 if (ref->status != REF_STATUS_NONE &&
368 ref->status != REF_STATUS_UPTODATE &&
369 ref->status != REF_STATUS_OK)
370 n += print_one_push_status(ref, dest, n);
8736a848
JK
371 }
372}
373
73fa0b44
JK
374static int refs_pushed(struct ref *ref)
375{
376 for (; ref; ref = ref->next) {
377 switch(ref->status) {
378 case REF_STATUS_NONE:
379 case REF_STATUS_UPTODATE:
380 break;
381 default:
382 return 1;
383 }
384 }
385 return 0;
386}
387
f7673490 388static int do_send_pack(int in, int out, struct remote *remote, const char *dest, int nr_refspec, const char **refspec)
61221472 389{
7f8e9828 390 struct ref *ref;
584c6cc9 391 int new_refs;
cfee10a7 392 int ask_for_status_report = 0;
d4f694ba 393 int allow_deleting_refs = 0;
cfee10a7 394 int expect_status_report = 0;
28b9d6e5 395 int flags = MATCH_REFS_NONE;
ca74c458 396 int ret;
40c155ff 397 struct extra_have_objects extra_have;
28b9d6e5 398
40c155ff 399 memset(&extra_have, 0, sizeof(extra_have));
28b9d6e5
AW
400 if (args.send_all)
401 flags |= MATCH_REFS_ALL;
402 if (args.send_mirror)
403 flags |= MATCH_REFS_MIRROR;
7f8e9828 404
f88395ac 405 /* No funny business with the matcher */
40c155ff
JH
406 remote_tail = get_remote_heads(in, &remote_refs, 0, NULL, REF_NORMAL,
407 &extra_have);
f88395ac 408 get_local_heads();
584c6cc9 409
cfee10a7
JH
410 /* Does the other end support the reporting? */
411 if (server_supports("report-status"))
412 ask_for_status_report = 1;
d4f694ba
JH
413 if (server_supports("delete-refs"))
414 allow_deleting_refs = 1;
cfee10a7 415
f88395ac
JH
416 /* match them up */
417 if (!remote_tail)
418 remote_tail = &remote_refs;
419 if (match_refs(local_refs, remote_refs, &remote_tail,
c20181e3
JS
420 nr_refspec, refspec, flags)) {
421 close(out);
f88395ac 422 return -1;
c20181e3 423 }
4c353e89
DB
424
425 if (!remote_refs) {
7e23b06d
AC
426 fprintf(stderr, "No refs in common and none specified; doing nothing.\n"
427 "Perhaps you should specify a branch such as 'master'.\n");
c20181e3 428 close(out);
4c353e89
DB
429 return 0;
430 }
431
584c6cc9 432 /*
f88395ac 433 * Finally, tell the other end!
584c6cc9 434 */
f88395ac
JH
435 new_refs = 0;
436 for (ref = remote_refs; ref; ref = ref->next) {
d4f694ba 437
16ed2f48
CB
438 if (ref->peer_ref)
439 hashcpy(ref->new_sha1, ref->peer_ref->new_sha1);
440 else if (!args.send_mirror)
441 continue;
28b9d6e5 442
16ed2f48 443 ref->deletion = is_null_sha1(ref->new_sha1);
8736a848
JK
444 if (ref->deletion && !allow_deleting_refs) {
445 ref->status = REF_STATUS_REJECT_NODELETE;
d4f694ba
JH
446 continue;
447 }
8736a848 448 if (!ref->deletion &&
16ed2f48 449 !hashcmp(ref->old_sha1, ref->new_sha1)) {
8736a848 450 ref->status = REF_STATUS_UPTODATE;
37fde874
JH
451 continue;
452 }
453
454 /* This part determines what can overwrite what.
455 * The rules are:
456 *
ff27adf3
JH
457 * (0) you can always use --force or +A:B notation to
458 * selectively force individual ref pairs.
37fde874
JH
459 *
460 * (1) if the old thing does not exist, it is OK.
461 *
462 * (2) if you do not have the old thing, you are not allowed
463 * to overwrite it; you would not know what you are losing
464 * otherwise.
465 *
466 * (3) if both new and old are commit-ish, and new is a
467 * descendant of old, it is OK.
d4f694ba
JH
468 *
469 * (4) regardless of all of the above, removing :B is
470 * always allowed.
37fde874
JH
471 */
472
8736a848
JK
473 ref->nonfastforward =
474 !ref->deletion &&
4b4ee90e 475 !is_null_sha1(ref->old_sha1) &&
8736a848 476 (!has_sha1_file(ref->old_sha1)
16ed2f48 477 || !ref_newer(ref->new_sha1, ref->old_sha1));
8736a848
JK
478
479 if (ref->nonfastforward && !ref->force && !args.force_update) {
480 ref->status = REF_STATUS_REJECT_NONFASTFORWARD;
481 continue;
e4b5c7ff 482 }
8736a848 483
8736a848 484 if (!ref->deletion)
d4f694ba 485 new_refs++;
cfee10a7 486
96249c04 487 if (!args.dry_run) {
8736a848
JK
488 char *old_hex = sha1_to_hex(ref->old_sha1);
489 char *new_hex = sha1_to_hex(ref->new_sha1);
490
a63103ae
BE
491 if (ask_for_status_report) {
492 packet_write(out, "%s %s %s%c%s",
493 old_hex, new_hex, ref->name, 0,
494 "report-status");
495 ask_for_status_report = 0;
496 expect_status_report = 1;
497 }
498 else
499 packet_write(out, "%s %s %s",
500 old_hex, new_hex, ref->name);
cfee10a7 501 }
2a0fe89a
JK
502 ref->status = expect_status_report ?
503 REF_STATUS_EXPECTING_REPORT :
504 REF_STATUS_OK;
61221472 505 }
f88395ac 506
f3a3214e 507 packet_flush(out);
8736a848 508 if (new_refs && !args.dry_run) {
40c155ff 509 if (pack_objects(out, remote_refs, &extra_have) < 0)
8736a848 510 return -1;
8736a848 511 }
c20181e3
JS
512 else
513 close(out);
cfee10a7 514
2a0fe89a 515 if (expect_status_report)
ca74c458 516 ret = receive_status(in, remote_refs);
ca74c458
JK
517 else
518 ret = 0;
519
520 print_push_status(dest, remote_refs);
cfee10a7 521
8736a848 522 if (!args.dry_run && remote) {
334f4831 523 for (ref = remote_refs; ref; ref = ref->next)
1f0e2a1a 524 update_tracking_ref(remote, ref);
334f4831
JK
525 }
526
73fa0b44 527 if (!refs_pushed(remote_refs))
cfee10a7 528 fprintf(stderr, "Everything up-to-date\n");
ca74c458
JK
529 if (ret < 0)
530 return ret;
8736a848
JK
531 for (ref = remote_refs; ref; ref = ref->next) {
532 switch (ref->status) {
533 case REF_STATUS_NONE:
534 case REF_STATUS_UPTODATE:
535 case REF_STATUS_OK:
536 break;
537 default:
538 return -1;
539 }
540 }
541 return 0;
61221472
LT
542}
543
4577370e 544static void verify_remote_names(int nr_heads, const char **heads)
37adac76
JH
545{
546 int i;
547
548 for (i = 0; i < nr_heads; i++) {
a83619d6 549 const char *local = heads[i];
46220ca1 550 const char *remote = strrchr(heads[i], ':');
37adac76 551
a83619d6
PB
552 if (*local == '+')
553 local++;
554
555 /* A matching refspec is okay. */
556 if (remote == local && remote[1] == '\0')
557 continue;
558
559 remote = remote ? (remote + 1) : local;
37adac76
JH
560 switch (check_ref_format(remote)) {
561 case 0: /* ok */
257f3020
JH
562 case CHECK_REF_FORMAT_ONELEVEL:
563 /* ok but a single level -- that is fine for
564 * a match pattern.
565 */
566 case CHECK_REF_FORMAT_WILDCARD:
567 /* ok but ends with a pattern-match character */
37adac76
JH
568 continue;
569 }
570 die("remote part of refspec is not a valid name in %s",
571 heads[i]);
572 }
573}
f88395ac 574
96249c04 575int cmd_send_pack(int argc, const char **argv, const char *prefix)
61221472
LT
576{
577 int i, nr_heads = 0;
4577370e 578 const char **heads = NULL;
96249c04 579 const char *remote_name = NULL;
b516968f 580 struct remote *remote = NULL;
96249c04 581 const char *dest = NULL;
84a9b58c 582
61221472 583 argv++;
d089391c 584 for (i = 1; i < argc; i++, argv++) {
96249c04 585 const char *arg = *argv;
61221472
LT
586
587 if (*arg == '-') {
cc44c765 588 if (!prefixcmp(arg, "--receive-pack=")) {
96249c04 589 args.receivepack = arg + 15;
d23842fd
UKK
590 continue;
591 }
cc44c765 592 if (!prefixcmp(arg, "--exec=")) {
96249c04 593 args.receivepack = arg + 7;
61221472
LT
594 continue;
595 }
b516968f
DB
596 if (!prefixcmp(arg, "--remote=")) {
597 remote_name = arg + 9;
598 continue;
599 }
d089391c 600 if (!strcmp(arg, "--all")) {
96249c04 601 args.send_all = 1;
d089391c
LT
602 continue;
603 }
a63103ae 604 if (!strcmp(arg, "--dry-run")) {
96249c04 605 args.dry_run = 1;
a63103ae
BE
606 continue;
607 }
28b9d6e5
AW
608 if (!strcmp(arg, "--mirror")) {
609 args.send_mirror = 1;
610 continue;
611 }
2a9c3fe8 612 if (!strcmp(arg, "--force")) {
96249c04 613 args.force_update = 1;
2a9c3fe8
LT
614 continue;
615 }
41f93a2c 616 if (!strcmp(arg, "--verbose")) {
96249c04 617 args.verbose = 1;
41f93a2c
LT
618 continue;
619 }
2245be3e 620 if (!strcmp(arg, "--thin")) {
96249c04 621 args.use_thin_pack = 1;
2245be3e
JH
622 continue;
623 }
61221472
LT
624 usage(send_pack_usage);
625 }
d089391c
LT
626 if (!dest) {
627 dest = arg;
628 continue;
629 }
4577370e 630 heads = (const char **) argv;
d089391c 631 nr_heads = argc - i;
61221472
LT
632 break;
633 }
634 if (!dest)
635 usage(send_pack_usage);
28b9d6e5
AW
636 /*
637 * --all and --mirror are incompatible; neither makes sense
638 * with any refspecs.
639 */
640 if ((heads && (args.send_all || args.send_mirror)) ||
641 (args.send_all && args.send_mirror))
0bc3cdfc 642 usage(send_pack_usage);
37adac76 643
b516968f
DB
644 if (remote_name) {
645 remote = remote_get(remote_name);
28b91f8a 646 if (!remote_has_url(remote, dest)) {
b516968f
DB
647 die("Destination %s is not a uri for %s",
648 dest, remote_name);
649 }
650 }
651
96249c04
DB
652 return send_pack(&args, dest, remote, nr_heads, heads);
653}
654
655int send_pack(struct send_pack_args *my_args,
656 const char *dest, struct remote *remote,
657 int nr_heads, const char **heads)
658{
659 int fd[2], ret;
660 struct child_process *conn;
661
662 memcpy(&args, my_args, sizeof(args));
663
664 verify_remote_names(nr_heads, heads);
665
666 conn = git_connect(fd, dest, args.receivepack, args.verbose ? CONNECT_VERBOSE : 0);
f7673490 667 ret = do_send_pack(fd[0], fd[1], remote, dest, nr_heads, heads);
7f8e9828 668 close(fd[0]);
c20181e3 669 /* do_send_pack always closes fd[1] */
98158e9c 670 ret |= finish_connect(conn);
8a5dbef8 671 return !!ret;
61221472 672}