| 571 | } |
| 572 | |
| 573 | static int get_common_commits(struct upload_pack_data *data, |
| 574 | struct packet_reader *reader) |
| 575 | { |
| 576 | struct object_id oid; |
| 577 | char last_hex[GIT_MAX_HEXSZ + 1]; |
| 578 | int got_common = 0; |
| 579 | int got_other = 0; |
| 580 | int sent_ready = 0; |
| 581 | |
| 582 | for (;;) { |
| 583 | const char *arg; |
| 584 | |
| 585 | reset_timeout(data->timeout); |
| 586 | |
| 587 | if (packet_reader_read(reader) != PACKET_READ_NORMAL) { |
| 588 | if (data->multi_ack == MULTI_ACK_DETAILED |
| 589 | && got_common |
| 590 | && !got_other |
| 591 | && ok_to_give_up(data)) { |
| 592 | sent_ready = 1; |
| 593 | packet_write_fmt(1, "ACK %s ready\n", last_hex); |
| 594 | } |
| 595 | if (data->have_obj.nr == 0 || data->multi_ack) |
| 596 | packet_write_fmt(1, "NAK\n"); |
| 597 | |
| 598 | if (data->no_done && sent_ready) { |
| 599 | packet_write_fmt(1, "ACK %s\n", last_hex); |
| 600 | return 0; |
| 601 | } |
| 602 | if (data->stateless_rpc) |
| 603 | exit(0); |
| 604 | got_common = 0; |
| 605 | got_other = 0; |
| 606 | continue; |
| 607 | } |
| 608 | if (skip_prefix(reader->line, "have ", &arg)) { |
| 609 | switch (got_oid(data, arg, &oid)) { |
| 610 | case -1: /* they have what we do not */ |
| 611 | got_other = 1; |
| 612 | if (data->multi_ack |
| 613 | && ok_to_give_up(data)) { |
| 614 | const char *hex = oid_to_hex(&oid); |
| 615 | if (data->multi_ack == MULTI_ACK_DETAILED) { |
| 616 | sent_ready = 1; |
| 617 | packet_write_fmt(1, "ACK %s ready\n", hex); |
| 618 | } else |
| 619 | packet_write_fmt(1, "ACK %s continue\n", hex); |
| 620 | } |
| 621 | break; |
| 622 | default: |
| 623 | got_common = 1; |
| 624 | oid_to_hex_r(last_hex, &oid); |
| 625 | if (data->multi_ack == MULTI_ACK_DETAILED) |
| 626 | packet_write_fmt(1, "ACK %s common\n", last_hex); |
| 627 | else if (data->multi_ack) |
| 628 | packet_write_fmt(1, "ACK %s continue\n", last_hex); |
| 629 | else if (data->have_obj.nr == 1) |
| 630 | packet_write_fmt(1, "ACK %s\n", last_hex); |
no test coverage detected