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