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