static int get_common_commits(void) { static char line[1000]; unsigned char sha1[20]; char last_hex[41]; save_commit_buffer = 0; for (;;) { int len = packet_read_line(0, line, sizeof(line)); reset_timeout(); if (!len) { if (have_obj.nr == 0 || multi_ack) packet_write(1, "NAK\n"); if (stateless_rpc) exit(0); continue; } strip(line, len); if (!prefixcmp(line, "have ")) { switch (got_sha1(line+5, sha1)) { case -1: /* they have what we do not */ if (multi_ack && ok_to_give_up()) { const char *hex = sha1_to_hex(sha1); if (multi_ack == 2) packet_write(1, "ACK %s ready\n", hex); else packet_write(1, "ACK %s continue\n", hex); } break; default: memcpy(last_hex, sha1_to_hex(sha1), 41); if (multi_ack == 2) packet_write(1, "ACK %s common\n", last_hex); else if (multi_ack) packet_write(1, "ACK %s continue\n", last_hex); else if (have_obj.nr == 1) packet_write(1, "ACK %s\n", last_hex); break; } continue; } if (!strcmp(line, "done")) { if (have_obj.nr > 0) { if (multi_ack) packet_write(1, "ACK %s\n", last_hex); return 0; } packet_write(1, "NAK\n"); return -1; } die("git upload-pack: expected SHA1 list, got '%s'", line); } }
static int send_acks(struct oid_array *acks, struct strbuf *response) { int i; packet_buf_write(response, "acknowledgments\n"); /* Send Acks */ if (!acks->nr) packet_buf_write(response, "NAK\n"); for (i = 0; i < acks->nr; i++) { packet_buf_write(response, "ACK %s\n", oid_to_hex(&acks->oid[i])); } if (ok_to_give_up()) { /* Send Ready */ packet_buf_write(response, "ready\n"); return 1; } return 0; }
static int get_common_commits(void) { unsigned char sha1[20]; char last_hex[41]; int got_common = 0; int got_other = 0; int sent_ready = 0; save_commit_buffer = 0; for (;;) { char *line = packet_read_line(0, NULL); reset_timeout(); if (!line) { if (multi_ack == 2 && got_common && !got_other && ok_to_give_up()) { sent_ready = 1; packet_write(1, "ACK %s ready\n", last_hex); } if (have_obj.nr == 0 || multi_ack) packet_write(1, "NAK\n"); if (no_done && sent_ready) { packet_write(1, "ACK %s\n", last_hex); return 0; } if (stateless_rpc) exit(0); got_common = 0; got_other = 0; continue; } if (starts_with(line, "have ")) { switch (got_sha1(line+5, sha1)) { case -1: /* they have what we do not */ got_other = 1; if (multi_ack && ok_to_give_up()) { const char *hex = sha1_to_hex(sha1); if (multi_ack == 2) { sent_ready = 1; packet_write(1, "ACK %s ready\n", hex); } else packet_write(1, "ACK %s continue\n", hex); } break; default: got_common = 1; memcpy(last_hex, sha1_to_hex(sha1), 41); if (multi_ack == 2) packet_write(1, "ACK %s common\n", last_hex); else if (multi_ack) packet_write(1, "ACK %s continue\n", last_hex); else if (have_obj.nr == 1) packet_write(1, "ACK %s\n", last_hex); break; } continue; } if (!strcmp(line, "done")) { if (have_obj.nr > 0) { if (multi_ack) packet_write(1, "ACK %s\n", last_hex); return 0; } packet_write(1, "NAK\n"); return -1; } die("git upload-pack: expected SHA1 list, got '%s'", line); } }
static int get_common_commits(void) { struct object_id oid; char last_hex[GIT_MAX_HEXSZ + 1]; int got_common = 0; int got_other = 0; int sent_ready = 0; save_commit_buffer = 0; for (;;) { char *line = packet_read_line(0, NULL); const char *arg; reset_timeout(); if (!line) { if (multi_ack == 2 && got_common && !got_other && ok_to_give_up()) { sent_ready = 1; packet_write_fmt(1, "ACK %s ready\n", last_hex); } if (have_obj.nr == 0 || multi_ack) packet_write_fmt(1, "NAK\n"); if (no_done && sent_ready) { packet_write_fmt(1, "ACK %s\n", last_hex); return 0; } if (stateless_rpc) exit(0); got_common = 0; got_other = 0; continue; } if (skip_prefix(line, "have ", &arg)) { switch (got_oid(arg, &oid)) { case -1: /* they have what we do not */ got_other = 1; if (multi_ack && ok_to_give_up()) { const char *hex = oid_to_hex(&oid); if (multi_ack == 2) { sent_ready = 1; packet_write_fmt(1, "ACK %s ready\n", hex); } else packet_write_fmt(1, "ACK %s continue\n", hex); } break; default: got_common = 1; oid_to_hex_r(last_hex, &oid); if (multi_ack == 2) packet_write_fmt(1, "ACK %s common\n", last_hex); else if (multi_ack) packet_write_fmt(1, "ACK %s continue\n", last_hex); else if (have_obj.nr == 1) packet_write_fmt(1, "ACK %s\n", last_hex); break; } continue; } if (!strcmp(line, "done")) { if (have_obj.nr > 0) { if (multi_ack) packet_write_fmt(1, "ACK %s\n", last_hex); return 0; } packet_write_fmt(1, "NAK\n"); return -1; } die("git upload-pack: expected SHA1 list, got '%s'", line); } }